-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdataloader.py
645 lines (515 loc) · 26.8 KB
/
dataloader.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
import logging
import pandas as pd
import xarray
import xarray as xr
from stdeephydro import config
from stdeephydro import dataset
from stdeephydro import ioutils
logger = logging.getLogger(__name__)
class AbstractDatasetLoader:
"""
Abstract dataset loader base class, which should be used to implement subclasses for loading certain datasets.
Parameters
----------
data_dir: str
Path to the root dir that contains the datasets
variables: list of str
List of names for variables that should be loaded as part of the dataset
basins: list of str
List of IDs that indicate for which basins the dataset should be loaded. If not set, datasets for all basins
within the root data_dir will be loaded
"""
def __init__(self, data_dir: str, variables: list, basins: list = None):
self.__data_dir = data_dir
self.__variables = variables
self.__basins = basins
@classmethod
def from_config(cls, data_cfg: config.DataTypeConfig, basins):
return cls(data_cfg.data_dir, data_cfg.variables, basins)
@property
def data_dir(self):
return self.__data_dir
@property
def variables(self):
return self.__variables
@property
def basins(self):
return self.__basins
def load_full_dataset(self, start_date: str, end_date: str) -> xr.Dataset:
pass
def load_single_dataset(self, start_date: str, end_date: str, basin: str) -> xr.Dataset:
pass
def load_joined_dataset(self, start_date: str, end_date: str) -> xr.Dataset:
pass
class CamelsUsStreamflowDataLoader(AbstractDatasetLoader):
"""
Data loader for streamflow timeseries data from the CAMELS-US dataset
This class loads CAMELS-US streamflow timeseries data as xarray.Dataset. For this purpose, the data loader assumes
the standard CAMELS-US folder structure when downloading the NCAR CAMELS-US dataset. This dataset contains
streamflow timeseries as separate files for each basin within the directory
'basin_dataset_public_v1p2/usgs_streamflow'.
The resulting xarray.Dataset contains the streamflow variable with dimensions (basin, time).
Parameters
----------
data_dir: str
Path to the 'usgs_streamflow' CAMELS-US directory
variables: list of str
List of CAMELS-US variables to load (i.e. only 'streamflow')
basins:
List of basin IDs
forcings_dir:
Path to a CAMELS-US forcings directory. If set, basin attributes will be read from the forcings files to
normalize streamflow by using the basin area.
as_dask:
Indicates whether to load the dataset as Dask Array. Should be set to True if datasets does not fit into memory.
Note, this is still an experimental feature, since timeseries window generation is not optimized for Dask
Arrays, so far.
"""
def __init__(self, data_dir: str, variables: list, basins: list = None, forcings_dir: str = None,
as_dask: bool = False):
super().__init__(data_dir, variables, basins)
self.__forcings_dir = forcings_dir
self.__as_dask = as_dask
def load_single_dataset(self, start_date: str, end_date: str, basin: str) -> xr.Dataset:
"""
Loads Camels-US streamflow timeseries data as xarray.Dataset for a single basin and the specified start and end
date.
Note, that streamflow will be converted from cubic feet per second to cubic meters per second.
Parameters
----------
start_date: str
String that represents a date. It will be used as start date for subsetting the timeseries datasets.
end_date: str
String that represents a date. It will be used as end date for subsetting the timeseries datasets.
basin: str
ID of the basin to load streamflow data for.
Returns
-------
xarray.Dataset:
A time and basin indexed xarray.Dataset for streamflow timeseries data.
"""
return self._load_xarray_dataset(start_date, end_date, basin)
def load_full_dataset(self, start_date: str, end_date: str) -> xr.Dataset:
"""
Loads Camels-US streamflow timeseries data as either as xarray.Dataset for the specified start and end date.
The method will load streamflow data for all basins that have been specified for instantiating this
data loader.
Note, that streamflow will be normalized if the data loader has been initialized with a given forcings directory.
This means streamflow will be divided by the basin area and converted into meters per day. For loading basin
area information you have to instantiate this data loader by additionally passing the forcings directory.
Parameters
----------
start_date: str
String that represents a date. It will be used as start date for subsetting the timeseries datasets.
end_date: str
String that represents a date. It will be used as end date for subsetting the timeseries datasets.
Returns
-------
xarray.Dataset:
A time and basin indexed xarray.Dataset for streamflow timeseries data.
"""
ds_list = []
for basin in self.basins:
if self.__forcings_dir is None:
ds = self._load_xarray_dataset(start_date, end_date, basin, False)
else:
ds = self._load_xarray_dataset(start_date, end_date, basin, True)
if self.__as_dask:
ds = ds.chunk()
ds_list.append(ds)
ds_timeseries = xr.concat(ds_list, dim="basin")
if self.__as_dask:
ds_timeseries = ds_timeseries.chunk({"basin": len(ds_timeseries.basin)})
return ds_timeseries
def _load_xarray_dataset(self, start_date: str, end_date: str, basin: str, normalize: bool = False) -> xr.Dataset:
streamflow_path = ioutils.discover_single_camels_us_streamflow_file(self.data_dir, basin)
df_streamflow = ioutils.load_streamflow_camels_us(streamflow_path)
date_range = pd.date_range(start=start_date, end=end_date, freq="1D")
df_streamflow = df_streamflow[start_date:end_date][self.variables].reindex(date_range)
if normalize:
forcings_path = ioutils.discover_single_camels_us_forcings_file(self.__forcings_dir, "daymet", basin)
latitude, elevation, area = ioutils.load_forcings_gauge_metadata(forcings_path)
df_streamflow[self.variables] = normalize_streamflow(df_streamflow[self.variables], area)
else:
df_streamflow[self.variables] = streamflow_to_metric(df_streamflow[self.variables])
ds_timeseries = xr.Dataset.from_dataframe(df_streamflow)
ds_timeseries = ds_timeseries.rename({"index": "time"})
ds_timeseries = ds_timeseries.assign_coords({"basin": basin})
ds_timeseries = ds_timeseries.expand_dims("basin")
return ds_timeseries
class CamelsUsForcingsDataLoader(AbstractDatasetLoader):
"""
Data loader for forcings timeseries data from the CAMELS-US dataset
This class loads CAMELS-US forcings timeseries data as xarray.Dataset. For this purpose, the data loader assumes
the standard CAMELS-US folder structure when downloading the NCAR CAMELS-US dataset. This dataset contains
forcings timeseries from three different sources (Daymet, Maurer, NLDAS) as separate files for each basin. Forcing
files for each source are stored within separate subdirectories of 'basin_dataset_public_v1p2/basin_mean_forcing'.
The resulting xarray.Dataset contains the forcings variables with dimensions (basin, time).
Parameters
----------
data_dir: str
Path to the forcings CAMELS-US subdirectory (daymet, maurer or nldas)
variables: list of str
List of CAMELS-US forcing variables to load
basins:
List of basin IDs
as_dask:
Indicates whether to load the dataset as Dask Array. Should be set to True if datasets does not fit into memory.
Notes
-----
Loading datasets as Dask Array is still an experimental feature. Some dataset processing routines, such as
timeseries window generation, are not optimized for Dask Arrays. Therefore, the run_training command line script
does not support this option.
"""
def __init__(self, data_dir: str, variables: list, basins: list = None, as_dask: bool = False):
super().__init__(data_dir, variables, basins)
self.__as_dask = as_dask
def load_single_dataset(self, start_date: str, end_date: str, basin: str) -> xr.Dataset:
"""
Loads Camels-US forcings timeseries data as xarray.Dataset for a single basin and the specified start and end
date.
Parameters
----------
start_date: str
String that represents a date. It will be used as start date for subsetting the timeseries datasets.
end_date: str
String that represents a date. It will be used as end date for subsetting the timeseries datasets.
basin: str
ID of the basin to load forcings data for.
Returns
-------
xarray.Dataset:
A time and basin indexed xarray.Dataset for forcings timeseries data.
"""
ds_timeseries = self._load_xarray_dataset(start_date, end_date, basin)
return ds_timeseries
def load_full_dataset(self, start_date: str, end_date: str) -> xr.Dataset:
"""
Loads Camels-US forcings timeseries data as xarray.Dataset for the specified start and end date. The method will
load forcings data for all basins that have been specified for instantiating this data loader.
Parameters
----------
start_date: str
String that represents a date. It will be used as start date for subsetting the timeseries datasets.
end_date: str
String that represents a date. It will be used as end date for subsetting the timeseries datasets.
Returns
-------
xarray.Dataset:
A time and basin indexed xarray.Dataset for forcings timeseries data.
"""
ds_list = []
for basin in self.basins:
ds = self._load_xarray_dataset(start_date, end_date, basin)
if self.__as_dask:
ds = ds.chunk()
ds_list.append(ds)
ds_timeseries = xr.concat(ds_list, dim="basin")
if self.__as_dask:
ds_timeseries = ds_timeseries.chunk({"basin": len(ds_timeseries.basin)})
return ds_timeseries
def _load_xarray_dataset(self, start_date: str, end_date: str, basin: str) -> xr.Dataset:
forcings_path = ioutils.discover_single_camels_us_forcings_file(self.data_dir, "daymet", basin)
df_forcings = ioutils.load_forcings_camels_us(forcings_path)
date_range = pd.date_range(start=start_date, end=end_date, freq="1D")
df_forcings = df_forcings[start_date:end_date][self.variables].reindex(date_range)
ds_timeseries = xr.Dataset.from_dataframe(df_forcings)
ds_timeseries = ds_timeseries.rename({"index": "time"})
ds_timeseries = ds_timeseries.assign_coords({"basin": basin})
ds_timeseries = ds_timeseries.expand_dims("basin")
return ds_timeseries
class DaymetDataLoader(AbstractDatasetLoader):
"""
Data loader for raster-based and aggregated Daymet forcings stored in NetCDF file format.
The data loader loads ORNL DAAC Daymet NetCDF data as xarray.Dataset. For this purpose the data loader expects that
separate NetCDF files for each basin exists within a root data_dir. Each NetCDF file must contain a unique basin ID
as part of the filename. Discovery of NetCDF files for specified basins will be performed using the pattern
'{data_dir}/*{basin}*.nc', i.e. the basin ID has to be present in any file name within the directory.
This data loader is able to read temporal distributed NetCDF data as well as spatio-temporally distributed data.
Temporal distributed NetCDF files must contain forcing variables, which are only indexed by 'time' (e.g. basin
aggregated forcings). Spatio-temporally NetCDF files must contain forcing variables which are indexed by 'time',
'x' and 'y'.
The resulting xarray.Dataset contains Daymet variables with either with dimensions (basin, time) for aggregated
forcings or (basin, time, x, y) for raster-based forcings.
Parameters
----------
data_dir: str
Path to the data directory that
variables: list of str
List of CAMELS-US forcing variables to load
basins:
List of basin IDs
from_zarr: bool
Indicates that datasets should be loaded from a Zarr store
"""
def __init__(self, data_dir: str, variables: list, basins: list = None, from_zarr: bool = False):
super().__init__(data_dir, variables, basins)
self.__from_zarr = from_zarr
def load_single_dataset(self, start_date: str, end_date: str, basin: str) -> xr.Dataset:
"""
Loads raster-based Daymet forcings as xarray.Dataset for a single basin and the specified start and end date.
The xarray.Dataset is indexed by time, basin ID and a spatial dimension by means of 'x' and 'y' coordinates.
Parameters
----------
start_date: str
String that represents a date. It will be used as start date for subsetting the timeseries datasets.
end_date: str
String that represents a date. It will be used as end date for subsetting the timeseries datasets.
basin: str
Basin ID
Returns
-------
xarray.Dataset
A xarray.Dataset that holds forcing and streamflow variables.
"""
ds_timeseries = self._discover_and_load_xarray_dataset(start_date, end_date, basin)
return ds_timeseries
def load_joined_dataset(self, start_date: str, end_date: str) -> xr.Dataset:
"""
Loads raster-based Daymet forcings from the data_dir for the specified start and end date as a joined xarray.Dataset.
If from_zarr is set to be true, it is assumed that data_dir points to a Zarr store and Daymet forcings will be
loaded as Dask Array. Otherwise, all single NetCDF forcings files will be discovered from data_dir and loaded
as Dask Array.
The xarray.Dataset is indexed by time, and a spatial dimension by means of 'x' and 'y' coordinates.
The dataset is meant to be valid for multiple basins e.g., if streamflow should be predicted for multiple
basins, the joined Daymet forcings dataset covers all basins.
Notes
-----
Loading joined data is still an experimental feature and may not be supported across the whole package.
Therefore, it can't be used with the run_training command line script.
Parameters
----------
start_date: str
String that represents a date. It will be used as start date for subsetting the timeseries datasets.
end_date: str
String that represents a date. It will be used as end date for subsetting the timeseries datasets.
Returns
-------
xarray.Dataset
A xarray.Dataset that holds forcing and streamflow variables.
"""
if self.__from_zarr:
ds_forcings = ioutils.load_forcings_daymet_2d_from_zarr(self.data_dir)
else:
daymet_files = ioutils.discover_daymet_files(self.data_dir, self.variables)
ds_forcings = ioutils.load_multiple_forcings_daymet_2d(daymet_files)
ds_forcings = ds_forcings.sel(time=slice(start_date, end_date))[self.variables]
ds_forcings["time"] = ds_forcings.indexes["time"].normalize()
return ds_forcings
def _discover_and_load_xarray_dataset(self, start_date: str, end_date: str, basin: str) -> xr.Dataset:
forcings_path = ioutils.discover_single_daymet_file_for_basin(self.data_dir, basin)
return self._load_xarray_dataset(forcings_path, start_date, end_date, basin)
def _load_xarray_dataset(self, path: str, start_date: str, end_date: str, basin: str = None) -> xr.Dataset:
if self.__from_zarr:
ds_forcings = ioutils.load_forcings_daymet_2d_from_zarr(path)
else:
ds_forcings = ioutils.load_forcings_daymet_2d(path)
ds_forcings = ds_forcings.sel(time=slice(start_date, end_date))[self.variables]
if basin is not None:
ds_forcings = ds_forcings.assign_coords({"basin": basin})
ds_forcings = ds_forcings.expand_dims("basin")
ds_forcings["time"] = ds_forcings.indexes["time"].normalize()
return ds_forcings
class HydroDataLoader:
"""
Data loader class for loading forcings and streamflow data from arbitrary data sources as combined
dataset.HydroDataset.
This class holds certain forcings and streamflow data loader instances in order to load hydro-meteorological
timeseries data as combined xarray.Datasets which comprises, basin indexed forcings and streamflow timeseries data.
Parameters
----------
forcings_data_loader: AbstractDatasetLoader
Instance for loading forcings timeseries data as xarray.Dataset
streamflow_data_loader: AbstractDatasetLoader
Instance for loading streamflow timeseries data as xarray.Dataset
forcings_vars: list
List of forcings variable names. The variables will be used for subsetting the forcings dataset.
streamflow_var: str
Streamflow variable name. The variable will be used for subsetting the streamflow dataset.
"""
def __init__(self, forcings_data_loader: AbstractDatasetLoader, streamflow_data_loader: AbstractDatasetLoader,
forcings_vars: list, streamflow_var: str):
self.__forcings_dataloader = forcings_data_loader
self.__streamflow_dataloader = streamflow_data_loader
self.__forcings_variables = forcings_vars
self.__streamflow_variable = streamflow_var
@classmethod
def from_config(cls, basins_file, forcings_cfg: config.DataTypeConfig, streamflow_cfg: config.DataTypeConfig):
"""
Creates a HydroDataLoader instance from configurations.
Note, that although the configuration file may contain a list of streamflow variables, the HydroDataLoader only
support a single streamflow variable. Thus, only the first variable of the list will be considered.
Parameters
----------
basins_file
forcings_cfg
streamflow_cfg
Returns
-------
HydroDataLoader
A HydroDataLoader instance
"""
with open(basins_file, 'r') as file:
basins = [line.strip() for line in file.readlines()]
forcings_dl = forcings_factory(forcings_cfg.data_type, basins, forcings_cfg.data_dir,
forcings_cfg.variables)
streamflow_dl = streamflow_factory(streamflow_cfg.data_type, basins, streamflow_cfg.data_dir,
streamflow_cfg.variables)
if len(streamflow_cfg.variables) > 0:
logger.warning(f"Configuration contains {len(streamflow_cfg.variables)} streamflow variables,"
f" but only one is supported for training. Therefore, only the first variable"
f" '{streamflow_cfg.variables[0]}' will be considered.")
return cls(forcings_dl, streamflow_dl, forcings_cfg.variables, streamflow_cfg.variables[0])
@property
def forcings_variables(self):
return self.__forcings_variables
@property
def streamflow_variable(self):
return self.__streamflow_variable
def load_single_dataset(self, start_date: str, end_date: str, basin: str) -> dataset.HydroDataset:
"""
Uses the forcings and streamflow DatasetsLoader to load a single timeseries dataset as xarray.Dataset which
contains merged forcings and streamflow data.
The resulting xarray.Dataset will be wrapped by a dataset.HydroDataset.
Parameters
----------
start_date: str
String that represents a date. It will be used as start date for subsetting the timeseries datasets.
end_date: str
String that represents a date. It will be used as end date for subsetting the timeseries datasets.
basin: str
Basin ID
Returns
-------
dataset.HydroDataset
Dataset which wraps forcings and streamflow timeseries data
"""
ds_forcings = self.__forcings_dataloader.load_single_dataset(start_date, end_date, basin)
ds_streamflow = self.__streamflow_dataloader.load_single_dataset(start_date, end_date, basin)
ds_timeseries = xr.merge([ds_forcings, ds_streamflow], join="left")
return dataset.HydroDataset(ds_timeseries, self.forcings_variables, self.streamflow_variable,
start_date, end_date)
def load_full_dataset(self, start_date: str, end_date: str):
"""
Uses the forcings and streamflow DataLoaders to load forcings and streamflow for the specified start and
end date as a joined xarray.Dataset. The method will load forcings and streamflow data for all basins that have
been specified for instantiating the data loaders.
The resulting xarray.Dataset will be wrapped by a dataset.HydroDataset.
Parameters
----------
start_date: str
String that represents a date. It will be used as start date for subsetting the timeseries datasets.
end_date: str
String that represents a date. It will be used as end date for subsetting the timeseries datasets.
Returns
-------
dataset.HydroDataset
Dataset which wraps forcings and streamflow timeseries data
"""
ds_forcings = self.__forcings_dataloader.load_full_dataset(start_date, end_date)
ds_streamflow = self.__streamflow_dataloader.load_full_dataset(start_date, end_date)
ds_timeseries = xr.merge([ds_forcings, ds_streamflow], join="left")
return dataset.HydroDataset(ds_timeseries, self.forcings_variables, self.streamflow_variable,
start_date, end_date)
def load_joined_dataset(self, start_date: str, end_date: str):
"""
Uses the forcings and streamflow DataLoaders to load forcings and streamflow for the specified
start and end date as a joined xarray.Dataset. Forcings are loaded as a joined xarray.Datasets and streamflow as
full xarray.Dataset and both merged.
The forcings xarray.Dataset is indexed by time, and a spatial dimension by means of 'x' and 'y' coordinates.
The streamflow xarray.Dataset is indexed by time, basin and a spatial dimension by means of 'x' and 'y'
coordinates.
The dataset is meant to be valid for multiple basins e.g., if streamflow should be predicted for multiple basins,
the joined Daymet forcings dataset covers all basins.
The resulting xarray.Dataset will be wrapped by a dataset.HydroDataset.
Parameters
----------
start_date: str
String that represents a date. It will be used as start date for subsetting the timeseries datasets.
end_date: str
String that represents a date. It will be used as end date for subsetting the timeseries datasets.
Returns
-------
dataset.HydroDataset
Dataset which wraps forcings and streamflow timeseries data
"""
ds_forcings = self.__forcings_dataloader.load_joined_dataset(start_date, end_date)
ds_streamflow = self.__streamflow_dataloader.load_full_dataset(start_date, end_date)
ds_timeseries = xr.merge([ds_forcings, ds_streamflow], join="left")
return dataset.HydroDataset(ds_timeseries, self.forcings_variables, self.streamflow_variable,
start_date, end_date)
def streamflow_to_metric(streamflow: xarray.DataArray) -> xarray.DataArray:
"""
Converts streamflow from cubic feet per second to cubic meters per second
Parameters
----------
streamflow: xarray.DataArray
Streamflow timeseries in cubic feet per second
Returns
-------
xarray.DataArray
Streamflow timeseries in cubic meters per second
"""
return streamflow * 0.028316846592 # [m³/s]
def normalize_streamflow(streamflow: xarray.DataArray, area: float):
"""
Normalizes streamflow, which has unit cubic feet per second [ft³/s], by dividing it by the basin area [m²] and
converting into millimeters per day (mm/d).
Parameters
----------
streamflow: xarray.DataArray
Streamflow timeseries in cubic feet per second [ft³/s]
area: float
Basin area in square meters [m²]
Returns
-------
Streamflow timeseries in meters per day (mm/d)
"""
streamflow = streamflow * 0.028316846592 # [m³/s]
streamflow = streamflow / area # [m/s]
streamflow = streamflow * 86400 # [m/d]
return streamflow * 10 ** 3 # [mm/d]
def forcings_factory(forcings_type: str, basins: list, forcings_dir: str, forcings_vars: list) -> AbstractDatasetLoader:
"""
Creates a certain DataLoader instance for loading forcings timeseries for the specified forcings type.
Parameters
----------
forcings_type: str
Forcings type. Supported: 'camels-us', 'daymet'
basins: List of str
List of basin IDs to load forcings for
forcings_dir: str
Path to the directory that contains forcings data files
forcings_vars: List of str
List of variable names to load forcings for
Returns
-------
AbstractDatasetLoader
A DatasetLoader instance that load forcings data
"""
if forcings_type == "camels-us":
return CamelsUsForcingsDataLoader(forcings_dir, forcings_vars, basins)
if forcings_type == "daymet":
return DaymetDataLoader(forcings_dir, forcings_vars, basins)
raise ValueError("No forcings data loader exists for the specified dataset type '{}.".format(forcings_type))
def streamflow_factory(streamflow_type: str, basins: list, streamflow_dir: str, streamflow_vars: list) -> AbstractDatasetLoader:
"""
Creates a certain DataLoader instance for loading streamflow timeseries for the specified streamflow type.
Parameters
----------
streamflow_type: str
Streamflow type. Supported: 'camels-us'
basins: List of str
List of basin IDs to load streamflow for
streamflow_dir: str
Path to the directory that contains streamflow data files
streamflow_vars: List of str
List of variable names to load streamflow for
Returns
-------
AbstractDatasetLoader
A DatasetLoader instance that loads streamflow data
"""
if streamflow_type == "camels-us":
return CamelsUsStreamflowDataLoader(streamflow_dir, streamflow_vars, basins)
raise ValueError("No streamflow data loader exists for the specified dataset type '{}.".format(streamflow_type))