66import glob
77import os
88
9- def retrieve_era5_fields_nc (dt_this , verbose = True , uv200 = False ):
9+ def retrieve_era5_fields_nc (dt_this , data_directory , verbose = True , uv200 = False ):
1010 """
1111 retrieve_era5_fields_nc(dt_this, verbose=True, uv200=False)
1212
1313 Read in the data fields from ERA5 for ARLiD.
14+
15+ Inputs:
16+ - dt_this: A Python datetime-like object
17+ - data_directory: The parent directory for ERA5 data.
18+ The function expects the data files to be in subdirectories:
19+ tcwv, viwve, and viwvn. (Also u_200mb and v_200mb if uv200=True).
20+ It will also look under the invarient subdirectory for the topo file:
21+ e5.oper.invariant.128_129_z.ll025sc.1979010100_1979010100.nc
1422 """
1523
16- end_of_month_DD = calendar .monthrange (dt_this .year , dt_this .month )[1 ] # output is (day_of_week, day_of_month)
17- fmt_tpw = ('/home/orca/data/model_anal/era5/from_rda/tcwv/'
18- + 'e5.oper.an.sfc.128_137_tcwv.ll025sc.%Y%m0100_%Y%m' + str (end_of_month_DD ).zfill (2 )+ '23.nc' )
24+ # output is (day_of_week, day_of_month)
25+ end_of_month_DD = calendar .monthrange (dt_this .year , dt_this .month )[1 ]
26+
27+ fmt_tpw = (f'{ data_directory } /tcwv/'
28+ + 'e5.oper.an.sfc.128_137_tcwv.ll025sc.%Y%m0100_%Y%m'
29+ + str (end_of_month_DD ).zfill (2 )+ '23.nc' )
1930 fn_tpw = dt_this .strftime (fmt_tpw )
2031 if verbose :
2132 print (fn_tpw )
@@ -27,17 +38,19 @@ def retrieve_era5_fields_nc(dt_this, verbose=True, uv200=False):
2738 tpw = DS ['TCWV' ].data
2839
2940 ## IVT
30- fmt_viwve = ('/home/orca/data/model_anal/era5/from_rda/viwve/'
31- + 'e5.oper.an.vinteg.162_071_viwve.ll025sc.%Y%m0100_%Y%m' + str (end_of_month_DD ).zfill (2 )+ '23.nc' )
41+ fmt_viwve = (f'{ data_directory } /viwve/'
42+ + 'e5.oper.an.vinteg.162_071_viwve.ll025sc.%Y%m0100_%Y%m'
43+ + str (end_of_month_DD ).zfill (2 )+ '23.nc' )
3244 fn_viwve = dt_this .strftime (fmt_viwve )
3345 if verbose :
3446 print (fn_viwve )
3547 with xr .open_dataset (fn_viwve ) as DS0 :
3648 DS = DS0 .sel (time = dt_this )
3749 viwve = DS ['VIWVE' ].data
3850
39- fmt_viwvn = ('/home/orca/data/model_anal/era5/from_rda/viwvn/'
40- + 'e5.oper.an.vinteg.162_072_viwvn.ll025sc.%Y%m0100_%Y%m' + str (end_of_month_DD ).zfill (2 )+ '23.nc' )
51+ fmt_viwvn = (f'{ data_directory } /viwvn/'
52+ + 'e5.oper.an.vinteg.162_072_viwvn.ll025sc.%Y%m0100_%Y%m'
53+ + str (end_of_month_DD ).zfill (2 )+ '23.nc' )
4154 fn_viwvn = dt_this .strftime (fmt_viwvn )
4255 if verbose :
4356 print (fn_viwvn )
@@ -46,8 +59,9 @@ def retrieve_era5_fields_nc(dt_this, verbose=True, uv200=False):
4659 viwvn = DS ['VIWVN' ].data
4760
4861 if uv200 :
49- fmt_v200 = ('/home/orca/data/model_anal/era5/from_rda/v_200mb/%Y/%m/'
50- + 'e5.oper.an.pl.128_132_v.ll025uv.%Y%m%d00_%Y%m%d23.lev200mb.6hr.nc' )
62+ fmt_v200 = (f'{ data_directory } /v_200mb/%Y/%m/'
63+ + 'e5.oper.an.pl.128_132_v.ll025uv.%Y%m%d00_%Y%m%d23'
64+ + '.lev200mb.6hr.nc' )
5165 fn_v200 = dt_this .strftime (fmt_v200 )
5266 if verbose :
5367 print (fn_v200 )
@@ -59,8 +73,9 @@ def retrieve_era5_fields_nc(dt_this, verbose=True, uv200=False):
5973 print (f'File not found: { fn_v200 } .' )
6074 v200 = np .nan * tpw
6175
62- fmt_u200 = ('/home/orca/data/model_anal/era5/from_rda/u_200mb/%Y/%m/'
63- + 'e5.oper.an.pl.128_131_u.ll025uv.%Y%m%d00_%Y%m%d23.lev200mb.6hr.nc' )
76+ fmt_u200 = (f'{ data_directory } /u_200mb/%Y/%m/'
77+ + 'e5.oper.an.pl.128_131_u.ll025uv.%Y%m%d00_%Y%m%d23'
78+ + '.lev200mb.6hr.nc' )
6479 fn_u200 = dt_this .strftime (fmt_u200 )
6580 if verbose :
6681 print (fn_u200 )
@@ -73,7 +88,7 @@ def retrieve_era5_fields_nc(dt_this, verbose=True, uv200=False):
7388 u200 = np .nan * tpw
7489
7590 ## Orography
76- fn_orog = ('/home/orca/data/model_anal/era5/from_rda /invariant/'
91+ fn_orog = (f' { data_directory } /invariant/'
7792 + 'e5.oper.invariant.128_129_z.ll025sc.1979010100_1979010100.nc' )
7893 if verbose :
7994 print (fn_orog )
0 commit comments