Skip to content

Commit de8bb29

Browse files
committed
Specify input directory as global variable on top
1 parent 1e239ff commit de8bb29

File tree

3 files changed

+52
-15
lines changed

3 files changed

+52
-15
lines changed

blob_detection/README.md

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ Here are the arguments:
4646
- Time interval in hours (optional, default = 1), e.g., `-dt 3` for every 3 h.
4747
- Number of CPUs to use (optional, default = 1), e.g., `-np 8` for 8 CPUs.
4848

49-
As an __example__, to run the script for 0000 UTC 1 January 2020, run it like this:
49+
As an __example__, to run the script for 0000 UTC 1 January 2020,
50+
run it like this:
5051
```
5152
python generate_ar_object_masks.era5.py 2020010100 2020010100
5253
```
@@ -73,6 +74,7 @@ If this is successful, you should be able to run it on any time range.
7374
## Input and Output
7475

7576
### Input
77+
7678
ERA-5 data were obtained using the NSF NCAR/UCAR Research Data Archive
7779
([RDA](https://rda.ucar.edu/)), dataset number 633.0.
7880
The files needed start with `e5.oper.an.sfc.128_137_tcwv.ll025sc`
@@ -83,8 +85,25 @@ by the RDA web application to download the data.
8385
The input directory is to be set in the script
8486
`generate_ar_object_masks.era5.py`.
8587

88+
The function `retrieve_era5_fields_nc.py` reads in the data. It takes
89+
a main data directory as in input. The main data directory is specified
90+
as the global variable DATA_DIRECTORY at the top of
91+
`retrieve_era5_fields_nc.py`. You need to edit this for your system.
92+
```
93+
## You need to set this for your system.
94+
DATA_DIRECTORY='/home/orca/data/model_anal/era5/from_rda'
95+
```
96+
Under the main data directory, it expects
97+
the following sub directories underneath the main data directory:
98+
- `tcwv/`: contains the TPW files
99+
- `viwve/`: eastward component of IVT
100+
- `viwvn/`: northward component of IVT
101+
- `invariant/`: Topography file
102+
`e5.oper.invariant.128_129_z.ll025sc.1979010100_1979010100.nc`
103+
86104

87105
### Output
106+
88107
Running this code will generate the outputs under the `mask_data/` directory.
89108
Subdirectories will be created by year, month, and day.
90109

blob_detection/generate_ar_object_masks.era5.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
from retrieve_era5_fields_nc import retrieve_era5_fields_nc
1111
from ar_objects_mask import *
1212

13+
## You need to set this for your system.
14+
DATA_DIRECTORY='/home/orca/data/model_anal/era5/from_rda'
1315

1416
# Command line args:
1517
# Must specify at least YYYYMMDDHH_start and YYYYMMDDHH_end
@@ -53,7 +55,8 @@ def process_a_time(time_to_process, verbose=False):
5355
- Save the output
5456
"""
5557

56-
F = retrieve_era5_fields_nc(time_to_process, verbose=verbose)
58+
F = retrieve_era5_fields_nc(time_to_process, DATA_DIRECTORY,
59+
verbose=verbose)
5760

5861
# Initialize mask object
5962
mask = ar_object_mask(time_to_process)

blob_detection/retrieve_era5_fields_nc.py

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,27 @@
66
import glob
77
import 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

Comments
 (0)