Skip to content
Snippets Groups Projects
Commit ea73ea41 authored by Paolo Veglio's avatar Paolo Veglio
Browse files

created function to get filenames for (almost) all inputs from VNP02MOD

parent afa0bc20
No related branches found
No related tags found
No related merge requests found
......@@ -3,6 +3,7 @@
*.png
*.npy
*.npz
*.nc
*.vscode
......
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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment