Skip to content

Commit 6c74bfd

Browse files
committed
Add hour selection option
1 parent 4cd1d3b commit 6c74bfd

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

adjust.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@ def main(args):
227227
args.infiles,
228228
args.var,
229229
time_bounds=args.adjustment_tbounds,
230+
isel_hour=args.isel_hour,
230231
input_units=args.input_units,
231232
output_units=args.output_units,
232233
use_cftime=False,
@@ -288,6 +289,12 @@ def main(args):
288289

289290
parser.add_argument("--input_units", type=str, default=None, help="input data units")
290291
parser.add_argument("--output_units", type=str, default=None, help="output data units")
292+
parser.add_argument(
293+
"--isel_hour",
294+
type=int,
295+
default=None,
296+
help="select a single hour from the infiles"
297+
)
291298
parser.add_argument(
292299
"--adjustment_tbounds",
293300
type=str,

train.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ def main(args):
125125
args.hist_files,
126126
args.hist_var,
127127
time_bounds=args.hist_time_bounds,
128+
isel_hour=args.isel_hour,
128129
input_units=args.input_hist_units,
129130
output_units=args.output_units,
130131
valid_min=args.valid_min,
@@ -135,6 +136,7 @@ def main(args):
135136
args.ref_files,
136137
args.ref_var,
137138
time_bounds=args.ref_time_bounds,
139+
isel_hour=args.isel_hour,
138140
lat_bounds=args.lat_bounds,
139141
lon_bounds=args.lon_bounds,
140142
input_units=args.input_ref_units,
@@ -196,6 +198,12 @@ def main(args):
196198
required=True,
197199
help="reference data files"
198200
)
201+
parser.add_argument(
202+
"--isel_hour",
203+
type=int,
204+
default=None,
205+
help="select a single hour from the input files"
206+
)
199207
parser.add_argument(
200208
"--hist_time_bounds",
201209
type=str,

utils.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ def read_data(
204204
time_bounds=None,
205205
lat_bounds=None,
206206
lon_bounds=None,
207+
isel_hour=None,
207208
input_units=None,
208209
output_units=None,
209210
lon_chunk_size=None,
@@ -225,6 +226,8 @@ def read_data(
225226
Rename var to value of rename_var
226227
time_bounds : list, optional
227228
Time period to extract from infiles [YYYY-MM-DD, YYYY-MM-DD]
229+
isel_hour : int, optional
230+
Select a single hour from the infiles
228231
lat_bnds : list, optional
229232
Latitude bounds: [south bound, north bound]
230233
lon_bnds : list, optional
@@ -278,7 +281,11 @@ def read_data(
278281

279282
if time_bounds:
280283
start_date, end_date = time_bounds
281-
ds = ds.sel({'time': slice(start_date, end_date)})
284+
ds = ds.sel({'time': slice(start_date, end_date)})
285+
286+
if type(isel_hour) == int:
287+
ds = ds.isel(time=(ds.time.dt.hour == isel_hour))
288+
282289
if lat_bounds:
283290
ds = subset_lat(ds, lat_bounds)
284291
if lon_bounds:

0 commit comments

Comments
 (0)