diff --git a/.gitignore b/.gitignore index fbe75cf7eca557150c62dcfece25ad234b6365cf..bc2e71fb1f4189182e2ca8d579fd69086f682d38 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ *.png *.npy *.npz +*.nc *.vscode diff --git a/sort_inputs.py b/sort_inputs.py new file mode 100644 index 0000000000000000000000000000000000000000..5f547d27b5aa4c573cb4ad876f618c3fa4e22d75 --- /dev/null +++ b/sort_inputs.py @@ -0,0 +1,57 @@ +import os.path + +import numpy as np + +from datetime import datetime +from glob import glob + + +def main(vnp02mod_fname): + + datapath = os.path.dirname(vnp02mod_fname) + filename = os.path.basename(vnp02mod_fname) + + vnpdate = filename.split('.')[1] + vnptime = filename.split('.')[2] + + geos_times = ['0000', '0300', '0600', '0900', '1200', '1500', '1800', '2100'] + geos_date_from_viirs = datetime.strftime(datetime.strptime(vnpdate, 'A%Y%j'), '%Y%m%d') + geos_flist = glob(f'{datapath}/ancillary/GEOS.fpit.asm.inst3_2d_asm_Nx.GEOS5124.{geos_date_from_viirs}*.nc4') + + fmt = '%H%M' + diff_times = [(datetime.strptime(gt, fmt) - datetime.strptime(vnptime, fmt)).total_seconds() + for gt in geos_times] + + file_index = np.argmin(np.abs(diff_times)) + if diff_times[file_index] <= 0: + geos_file1 = geos_flist[file_index] + geos_file2 = geos_flist[file_index + 1] + else: + geos_file1 = geos_flist[file_index - 1] + geos_file2 = geos_flist[file_index] + + land_ocean_fnames = glob(f'{datapath}/ancillary/GEOS.fpit.asm.tavg1_2d_lnd_Nx.GEOS5124.{geos_date_from_viirs}*.nc4') + land_ocean_timelist = [t.split('.')[5].split('_')[1] for t in land_ocean_fnames] + + diff_times = [(datetime.strptime(gt, fmt) - datetime.strptime(vnptime, fmt)).total_seconds() + for gt in land_ocean_timelist] + + land_ocean_index = np.argmin(np.abs(diff_times)) + + geos_land_file = glob(f'{datapath}/ancillary/GEOS.fpit.asm.tavg1_2d_lnd_Nx.GEOS5124.{geos_date_from_viirs}*.nc4')[land_ocean_index] + geos_ocean_file = glob(f'{datapath}/ancillary/GEOS.fpit.asm.tavg1_2d_ocn_Nx.GEOS5124.{geos_date_from_viirs}*.nc4')[land_ocean_index] + + vnp03mod = glob(f'{datapath}/VNP03MOD.{vnpdate}.{vnptime}*.nc')[0] + vnp02img = glob(f'{datapath}/VNP02IMG.{vnpdate}.{vnptime}*_bowtie_restored.nc')[0] + vnp03img = glob(f'{datapath}/VNP03IMG.{vnpdate}.{vnptime}*.nc')[0] + + out_fnames = {'VNP03MOD': vnp03mod, + 'VNP02IMG': vnp02img, + 'VNP03IMG': vnp03img, + 'GEOS_atm_1': geos_file1, + 'GEOS_atm_2': geos_file2, + 'GEOS_land': geos_land_file, + 'GEOS_ocean': geos_ocean_file, + } + + return out_fnames