From ea73ea413c576a0b0553371439c99b8caa898f25 Mon Sep 17 00:00:00 2001 From: Paolo Veglio <paolo.veglio@ssec.wisc.edu> Date: Thu, 15 Dec 2022 16:50:49 +0000 Subject: [PATCH] created function to get filenames for (almost) all inputs from VNP02MOD --- .gitignore | 1 + sort_inputs.py | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 sort_inputs.py diff --git a/.gitignore b/.gitignore index fbe75cf..bc2e71f 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 0000000..5f547d2 --- /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 -- GitLab