roms-tools 1.7.0__py3-none-any.whl → 2.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- roms_tools/__init__.py +2 -1
- roms_tools/setup/boundary_forcing.py +246 -146
- roms_tools/setup/datasets.py +229 -69
- roms_tools/setup/download.py +13 -17
- roms_tools/setup/grid.py +777 -614
- roms_tools/setup/initial_conditions.py +168 -32
- roms_tools/setup/mask.py +115 -0
- roms_tools/setup/nesting.py +575 -0
- roms_tools/setup/plot.py +218 -63
- roms_tools/setup/regrid.py +4 -2
- roms_tools/setup/river_forcing.py +125 -29
- roms_tools/setup/surface_forcing.py +31 -25
- roms_tools/setup/tides.py +29 -14
- roms_tools/setup/topography.py +250 -153
- roms_tools/setup/utils.py +174 -44
- roms_tools/setup/vertical_coordinate.py +5 -16
- roms_tools/tests/test_setup/test_boundary_forcing.py +10 -5
- roms_tools/tests/test_setup/test_data/grid.zarr/.zattrs +0 -1
- roms_tools/tests/test_setup/test_data/grid.zarr/.zmetadata +56 -201
- roms_tools/tests/test_setup/test_data/grid.zarr/Cs_r/.zattrs +1 -1
- roms_tools/tests/test_setup/test_data/grid.zarr/Cs_w/.zattrs +1 -1
- roms_tools/tests/test_setup/test_data/grid.zarr/{layer_depth_rho → sigma_r}/.zarray +2 -6
- roms_tools/tests/test_setup/test_data/grid.zarr/sigma_r/.zattrs +7 -0
- roms_tools/tests/test_setup/test_data/grid.zarr/sigma_r/0 +0 -0
- roms_tools/tests/test_setup/test_data/grid.zarr/sigma_w/.zarray +20 -0
- roms_tools/tests/test_setup/test_data/grid.zarr/sigma_w/.zattrs +7 -0
- roms_tools/tests/test_setup/test_data/grid.zarr/sigma_w/0 +0 -0
- roms_tools/tests/test_setup/test_data/grid_that_straddles_dateline.zarr/.zattrs +1 -2
- roms_tools/tests/test_setup/test_data/grid_that_straddles_dateline.zarr/.zmetadata +58 -203
- roms_tools/tests/test_setup/test_data/grid_that_straddles_dateline.zarr/Cs_r/.zattrs +1 -1
- roms_tools/tests/test_setup/test_data/grid_that_straddles_dateline.zarr/Cs_w/.zattrs +1 -1
- roms_tools/tests/test_setup/test_data/grid_that_straddles_dateline.zarr/h/.zattrs +1 -1
- roms_tools/tests/test_setup/test_data/grid_that_straddles_dateline.zarr/h/0.0 +0 -0
- roms_tools/tests/test_setup/test_data/grid_that_straddles_dateline.zarr/mask_coarse/0.0 +0 -0
- roms_tools/tests/test_setup/test_data/grid_that_straddles_dateline.zarr/mask_rho/0.0 +0 -0
- roms_tools/tests/test_setup/test_data/grid_that_straddles_dateline.zarr/mask_u/0.0 +0 -0
- roms_tools/tests/test_setup/test_data/grid_that_straddles_dateline.zarr/mask_v/0.0 +0 -0
- roms_tools/tests/test_setup/test_data/grid_that_straddles_dateline.zarr/sigma_r/.zarray +20 -0
- roms_tools/tests/test_setup/test_data/grid_that_straddles_dateline.zarr/sigma_r/.zattrs +7 -0
- roms_tools/tests/test_setup/test_data/grid_that_straddles_dateline.zarr/sigma_r/0 +0 -0
- roms_tools/tests/test_setup/test_data/grid_that_straddles_dateline.zarr/sigma_w/.zarray +20 -0
- roms_tools/tests/test_setup/test_data/grid_that_straddles_dateline.zarr/sigma_w/.zattrs +7 -0
- roms_tools/tests/test_setup/test_data/grid_that_straddles_dateline.zarr/sigma_w/0 +0 -0
- roms_tools/tests/test_setup/test_data/river_forcing_no_climatology.zarr/.zmetadata +2 -3
- roms_tools/tests/test_setup/test_data/river_forcing_no_climatology.zarr/river_tracer/.zattrs +1 -2
- roms_tools/tests/test_setup/test_data/river_forcing_no_climatology.zarr/tracer_name/.zarray +1 -1
- roms_tools/tests/test_setup/test_data/river_forcing_no_climatology.zarr/tracer_name/0 +0 -0
- roms_tools/tests/test_setup/test_data/{river_forcing.zarr → river_forcing_with_bgc.zarr}/.zmetadata +5 -6
- roms_tools/tests/test_setup/test_data/{river_forcing.zarr → river_forcing_with_bgc.zarr}/river_tracer/.zarray +2 -2
- roms_tools/tests/test_setup/test_data/{river_forcing.zarr → river_forcing_with_bgc.zarr}/river_tracer/.zattrs +1 -2
- roms_tools/tests/test_setup/test_data/river_forcing_with_bgc.zarr/river_tracer/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/{river_forcing.zarr → river_forcing_with_bgc.zarr}/tracer_name/.zarray +2 -2
- roms_tools/tests/test_setup/test_data/river_forcing_with_bgc.zarr/tracer_name/0 +0 -0
- roms_tools/tests/test_setup/test_datasets.py +2 -2
- roms_tools/tests/test_setup/test_grid.py +110 -12
- roms_tools/tests/test_setup/test_initial_conditions.py +2 -1
- roms_tools/tests/test_setup/test_nesting.py +489 -0
- roms_tools/tests/test_setup/test_river_forcing.py +53 -15
- roms_tools/tests/test_setup/test_surface_forcing.py +3 -22
- roms_tools/tests/test_setup/test_tides.py +2 -1
- roms_tools/tests/test_setup/test_topography.py +106 -1
- roms_tools/tests/test_setup/test_validation.py +2 -2
- {roms_tools-1.7.0.dist-info → roms_tools-2.1.0.dist-info}/LICENSE +1 -1
- {roms_tools-1.7.0.dist-info → roms_tools-2.1.0.dist-info}/METADATA +9 -4
- {roms_tools-1.7.0.dist-info → roms_tools-2.1.0.dist-info}/RECORD +85 -108
- {roms_tools-1.7.0.dist-info → roms_tools-2.1.0.dist-info}/WHEEL +1 -1
- roms_tools/_version.py +0 -2
- roms_tools/tests/test_setup/test_data/grid.zarr/interface_depth_rho/.zarray +0 -24
- roms_tools/tests/test_setup/test_data/grid.zarr/interface_depth_rho/.zattrs +0 -9
- roms_tools/tests/test_setup/test_data/grid.zarr/interface_depth_rho/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/grid.zarr/interface_depth_u/.zarray +0 -24
- roms_tools/tests/test_setup/test_data/grid.zarr/interface_depth_u/.zattrs +0 -9
- roms_tools/tests/test_setup/test_data/grid.zarr/interface_depth_u/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/grid.zarr/interface_depth_v/.zarray +0 -24
- roms_tools/tests/test_setup/test_data/grid.zarr/interface_depth_v/.zattrs +0 -9
- roms_tools/tests/test_setup/test_data/grid.zarr/interface_depth_v/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/grid.zarr/layer_depth_rho/.zattrs +0 -9
- roms_tools/tests/test_setup/test_data/grid.zarr/layer_depth_rho/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/grid.zarr/layer_depth_u/.zarray +0 -24
- roms_tools/tests/test_setup/test_data/grid.zarr/layer_depth_u/.zattrs +0 -9
- roms_tools/tests/test_setup/test_data/grid.zarr/layer_depth_u/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/grid.zarr/layer_depth_v/.zarray +0 -24
- roms_tools/tests/test_setup/test_data/grid.zarr/layer_depth_v/.zattrs +0 -9
- roms_tools/tests/test_setup/test_data/grid.zarr/layer_depth_v/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/grid_that_straddles_dateline.zarr/interface_depth_rho/.zarray +0 -24
- roms_tools/tests/test_setup/test_data/grid_that_straddles_dateline.zarr/interface_depth_rho/.zattrs +0 -9
- roms_tools/tests/test_setup/test_data/grid_that_straddles_dateline.zarr/interface_depth_rho/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/grid_that_straddles_dateline.zarr/interface_depth_u/.zarray +0 -24
- roms_tools/tests/test_setup/test_data/grid_that_straddles_dateline.zarr/interface_depth_u/.zattrs +0 -9
- roms_tools/tests/test_setup/test_data/grid_that_straddles_dateline.zarr/interface_depth_u/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/grid_that_straddles_dateline.zarr/interface_depth_v/.zarray +0 -24
- roms_tools/tests/test_setup/test_data/grid_that_straddles_dateline.zarr/interface_depth_v/.zattrs +0 -9
- roms_tools/tests/test_setup/test_data/grid_that_straddles_dateline.zarr/interface_depth_v/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/grid_that_straddles_dateline.zarr/layer_depth_rho/.zarray +0 -24
- roms_tools/tests/test_setup/test_data/grid_that_straddles_dateline.zarr/layer_depth_rho/.zattrs +0 -9
- roms_tools/tests/test_setup/test_data/grid_that_straddles_dateline.zarr/layer_depth_rho/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/grid_that_straddles_dateline.zarr/layer_depth_u/.zarray +0 -24
- roms_tools/tests/test_setup/test_data/grid_that_straddles_dateline.zarr/layer_depth_u/.zattrs +0 -9
- roms_tools/tests/test_setup/test_data/grid_that_straddles_dateline.zarr/layer_depth_u/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/grid_that_straddles_dateline.zarr/layer_depth_v/.zarray +0 -24
- roms_tools/tests/test_setup/test_data/grid_that_straddles_dateline.zarr/layer_depth_v/.zattrs +0 -9
- roms_tools/tests/test_setup/test_data/grid_that_straddles_dateline.zarr/layer_depth_v/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/river_forcing.zarr/river_tracer/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/river_forcing.zarr/tracer_name/0 +0 -0
- roms_tools/tests/test_setup/test_vertical_coordinate.py +0 -91
- /roms_tools/tests/test_setup/test_data/{river_forcing.zarr → river_forcing_with_bgc.zarr}/.zattrs +0 -0
- /roms_tools/tests/test_setup/test_data/{river_forcing.zarr → river_forcing_with_bgc.zarr}/.zgroup +0 -0
- /roms_tools/tests/test_setup/test_data/{river_forcing.zarr → river_forcing_with_bgc.zarr}/abs_time/.zarray +0 -0
- /roms_tools/tests/test_setup/test_data/{river_forcing.zarr → river_forcing_with_bgc.zarr}/abs_time/.zattrs +0 -0
- /roms_tools/tests/test_setup/test_data/{river_forcing.zarr → river_forcing_with_bgc.zarr}/abs_time/0 +0 -0
- /roms_tools/tests/test_setup/test_data/{river_forcing.zarr → river_forcing_with_bgc.zarr}/month/.zarray +0 -0
- /roms_tools/tests/test_setup/test_data/{river_forcing.zarr → river_forcing_with_bgc.zarr}/month/.zattrs +0 -0
- /roms_tools/tests/test_setup/test_data/{river_forcing.zarr → river_forcing_with_bgc.zarr}/month/0 +0 -0
- /roms_tools/tests/test_setup/test_data/{river_forcing.zarr → river_forcing_with_bgc.zarr}/river_name/.zarray +0 -0
- /roms_tools/tests/test_setup/test_data/{river_forcing.zarr → river_forcing_with_bgc.zarr}/river_name/.zattrs +0 -0
- /roms_tools/tests/test_setup/test_data/{river_forcing.zarr → river_forcing_with_bgc.zarr}/river_name/0 +0 -0
- /roms_tools/tests/test_setup/test_data/{river_forcing.zarr → river_forcing_with_bgc.zarr}/river_time/.zarray +0 -0
- /roms_tools/tests/test_setup/test_data/{river_forcing.zarr → river_forcing_with_bgc.zarr}/river_time/.zattrs +0 -0
- /roms_tools/tests/test_setup/test_data/{river_forcing.zarr → river_forcing_with_bgc.zarr}/river_time/0 +0 -0
- /roms_tools/tests/test_setup/test_data/{river_forcing.zarr → river_forcing_with_bgc.zarr}/river_volume/.zarray +0 -0
- /roms_tools/tests/test_setup/test_data/{river_forcing.zarr → river_forcing_with_bgc.zarr}/river_volume/.zattrs +0 -0
- /roms_tools/tests/test_setup/test_data/{river_forcing.zarr → river_forcing_with_bgc.zarr}/river_volume/0.0 +0 -0
- /roms_tools/tests/test_setup/test_data/{river_forcing.zarr → river_forcing_with_bgc.zarr}/tracer_name/.zattrs +0 -0
- {roms_tools-1.7.0.dist-info → roms_tools-2.1.0.dist-info}/top_level.txt +0 -0
|
@@ -12,13 +12,13 @@ from roms_tools.setup.datasets import (
|
|
|
12
12
|
CESMBGCSurfaceForcingDataset,
|
|
13
13
|
)
|
|
14
14
|
from roms_tools.setup.utils import (
|
|
15
|
+
get_target_coords,
|
|
15
16
|
nan_check,
|
|
16
17
|
substitute_nans_by_fillvalue,
|
|
17
18
|
interpolate_from_climatology,
|
|
18
19
|
get_variable_metadata,
|
|
19
20
|
group_dataset,
|
|
20
21
|
save_datasets,
|
|
21
|
-
get_target_coords,
|
|
22
22
|
rotate_velocities,
|
|
23
23
|
convert_to_roms_time,
|
|
24
24
|
_to_yaml,
|
|
@@ -66,6 +66,10 @@ class SurfaceForcing:
|
|
|
66
66
|
Reference date for the model. Default is January 1, 2000.
|
|
67
67
|
use_dask: bool, optional
|
|
68
68
|
Indicates whether to use dask for processing. If True, data is processed with dask; if False, data is processed eagerly. Defaults to False.
|
|
69
|
+
bypass_validation: bool, optional
|
|
70
|
+
Indicates whether to skip validation checks in the processed data. When set to True,
|
|
71
|
+
the validation process that ensures no NaN values exist at wet points
|
|
72
|
+
in the processed dataset is bypassed. Defaults to False.
|
|
69
73
|
|
|
70
74
|
Examples
|
|
71
75
|
--------
|
|
@@ -88,6 +92,7 @@ class SurfaceForcing:
|
|
|
88
92
|
use_coarse_grid: bool = False
|
|
89
93
|
model_reference_date: datetime = datetime(2000, 1, 1)
|
|
90
94
|
use_dask: bool = False
|
|
95
|
+
bypass_validation: bool = False
|
|
91
96
|
|
|
92
97
|
ds: xr.Dataset = field(init=False, repr=False)
|
|
93
98
|
|
|
@@ -105,8 +110,8 @@ class SurfaceForcing:
|
|
|
105
110
|
|
|
106
111
|
data.apply_lateral_fill()
|
|
107
112
|
|
|
108
|
-
|
|
109
|
-
var_names = variable_info.keys()
|
|
113
|
+
self._set_variable_info(data)
|
|
114
|
+
var_names = self.variable_info.keys()
|
|
110
115
|
|
|
111
116
|
processed_fields = {}
|
|
112
117
|
# lateral regridding
|
|
@@ -117,8 +122,8 @@ class SurfaceForcing:
|
|
|
117
122
|
data.ds[data.var_names[var_name]]
|
|
118
123
|
)
|
|
119
124
|
|
|
120
|
-
# rotation of velocities
|
|
121
|
-
if "uwnd" in variable_info and "vwnd" in variable_info:
|
|
125
|
+
# rotation of velocities
|
|
126
|
+
if "uwnd" in self.variable_info and "vwnd" in self.variable_info:
|
|
122
127
|
processed_fields["uwnd"], processed_fields["vwnd"] = rotate_velocities(
|
|
123
128
|
processed_fields["uwnd"],
|
|
124
129
|
processed_fields["vwnd"],
|
|
@@ -134,7 +139,8 @@ class SurfaceForcing:
|
|
|
134
139
|
|
|
135
140
|
ds = self._write_into_dataset(processed_fields, data, d_meta)
|
|
136
141
|
|
|
137
|
-
self.
|
|
142
|
+
if not self.bypass_validation:
|
|
143
|
+
self._validate(ds)
|
|
138
144
|
|
|
139
145
|
# substitute NaNs over land by a fill value to avoid blow-up of ROMS
|
|
140
146
|
for var_name in ds.data_vars:
|
|
@@ -213,9 +219,8 @@ class SurfaceForcing:
|
|
|
213
219
|
|
|
214
220
|
Returns
|
|
215
221
|
-------
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
about each variable, including 'location', 'is_vector', 'vector_pair', and 'is_3d'.
|
|
222
|
+
None
|
|
223
|
+
This method updates the instance attribute `variable_info` with the metadata dictionary for the variables.
|
|
219
224
|
"""
|
|
220
225
|
default_info = {
|
|
221
226
|
"location": "rho",
|
|
@@ -256,17 +261,15 @@ class SurfaceForcing:
|
|
|
256
261
|
else:
|
|
257
262
|
variable_info[var_name] = {**default_info, "validate": False}
|
|
258
263
|
|
|
259
|
-
|
|
264
|
+
object.__setattr__(self, "variable_info", variable_info)
|
|
260
265
|
|
|
261
266
|
def _apply_correction(self, processed_fields, data):
|
|
262
267
|
|
|
263
268
|
correction_data = self._get_correction_data()
|
|
264
269
|
# choose same subdomain as forcing data so that we can use same mask
|
|
265
270
|
coords_correction = {
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
data.dim_names["longitude"]
|
|
269
|
-
],
|
|
271
|
+
"lat": data.ds[data.dim_names["latitude"]],
|
|
272
|
+
"lon": data.ds[data.dim_names["longitude"]],
|
|
270
273
|
}
|
|
271
274
|
correction_data.choose_subdomain(
|
|
272
275
|
coords_correction, straddle=self.target_coords["straddle"]
|
|
@@ -329,7 +332,7 @@ class SurfaceForcing:
|
|
|
329
332
|
|
|
330
333
|
return ds
|
|
331
334
|
|
|
332
|
-
def _validate(self, ds
|
|
335
|
+
def _validate(self, ds):
|
|
333
336
|
"""Validates the dataset by checking for NaN values at wet points, which would
|
|
334
337
|
indicate missing raw data coverage over the target domain.
|
|
335
338
|
|
|
@@ -337,12 +340,6 @@ class SurfaceForcing:
|
|
|
337
340
|
----------
|
|
338
341
|
ds : xarray.Dataset
|
|
339
342
|
The dataset to validate.
|
|
340
|
-
mask : xarray.DataArray
|
|
341
|
-
Land mask (1=ocean, 0=land) to determine wet points in the domain.
|
|
342
|
-
variable_info : dict
|
|
343
|
-
A dictionary containing metadata about each variable (e.g., location,
|
|
344
|
-
whether it's a 3D variable, etc.). Used to retrieve information for
|
|
345
|
-
validating each variable.
|
|
346
343
|
|
|
347
344
|
Raises
|
|
348
345
|
------
|
|
@@ -357,8 +354,8 @@ class SurfaceForcing:
|
|
|
357
354
|
|
|
358
355
|
for var_name in ds.data_vars:
|
|
359
356
|
# Only validate variables based on "validate" flag if use_dask is False
|
|
360
|
-
if not self.use_dask or variable_info[var_name]["validate"]:
|
|
361
|
-
nan_check(ds[var_name].isel(time=0), mask)
|
|
357
|
+
if not self.use_dask or self.variable_info[var_name]["validate"]:
|
|
358
|
+
nan_check(ds[var_name].isel(time=0), self.target_coords["mask"])
|
|
362
359
|
|
|
363
360
|
def _add_global_metadata(self, ds=None):
|
|
364
361
|
|
|
@@ -548,7 +545,10 @@ class SurfaceForcing:
|
|
|
548
545
|
|
|
549
546
|
@classmethod
|
|
550
547
|
def from_yaml(
|
|
551
|
-
cls,
|
|
548
|
+
cls,
|
|
549
|
+
filepath: Union[str, Path],
|
|
550
|
+
use_dask: bool = False,
|
|
551
|
+
bypass_validation: bool = False,
|
|
552
552
|
) -> "SurfaceForcing":
|
|
553
553
|
"""Create an instance of the SurfaceForcing class from a YAML file.
|
|
554
554
|
|
|
@@ -558,6 +558,10 @@ class SurfaceForcing:
|
|
|
558
558
|
The path to the YAML file from which the parameters will be read.
|
|
559
559
|
use_dask: bool, optional
|
|
560
560
|
Indicates whether to use dask for processing. If True, data is processed with dask; if False, data is processed eagerly. Defaults to False.
|
|
561
|
+
bypass_validation: bool, optional
|
|
562
|
+
Indicates whether to skip validation checks in the processed data. When set to True,
|
|
563
|
+
the validation process that ensures no NaN values exist at wet points
|
|
564
|
+
in the processed dataset is bypassed. Defaults to False.
|
|
561
565
|
|
|
562
566
|
Returns
|
|
563
567
|
-------
|
|
@@ -569,4 +573,6 @@ class SurfaceForcing:
|
|
|
569
573
|
grid = Grid.from_yaml(filepath)
|
|
570
574
|
params = _from_yaml(cls, filepath)
|
|
571
575
|
|
|
572
|
-
return cls(
|
|
576
|
+
return cls(
|
|
577
|
+
grid=grid, **params, use_dask=use_dask, bypass_validation=bypass_validation
|
|
578
|
+
)
|
roms_tools/setup/tides.py
CHANGED
|
@@ -51,6 +51,10 @@ class TidalForcing:
|
|
|
51
51
|
The reference date for the ROMS simulation. Default is datetime(2000, 1, 1).
|
|
52
52
|
use_dask: bool, optional
|
|
53
53
|
Indicates whether to use dask for processing. If True, data is processed with dask; if False, data is processed eagerly. Defaults to False.
|
|
54
|
+
bypass_validation: bool, optional
|
|
55
|
+
Indicates whether to skip validation checks in the processed data. When set to True,
|
|
56
|
+
the validation process that ensures no NaN values exist at wet points
|
|
57
|
+
in the processed dataset is bypassed. Defaults to False.
|
|
54
58
|
|
|
55
59
|
Examples
|
|
56
60
|
--------
|
|
@@ -65,6 +69,7 @@ class TidalForcing:
|
|
|
65
69
|
allan_factor: float = 2.0
|
|
66
70
|
model_reference_date: datetime = datetime(2000, 1, 1)
|
|
67
71
|
use_dask: bool = False
|
|
72
|
+
bypass_validation: bool = False
|
|
68
73
|
|
|
69
74
|
ds: xr.Dataset = field(init=False, repr=False)
|
|
70
75
|
|
|
@@ -85,8 +90,8 @@ class TidalForcing:
|
|
|
85
90
|
|
|
86
91
|
data.apply_lateral_fill()
|
|
87
92
|
|
|
88
|
-
|
|
89
|
-
var_names = variable_info.keys()
|
|
93
|
+
self._set_variable_info()
|
|
94
|
+
var_names = self.variable_info.keys()
|
|
90
95
|
|
|
91
96
|
processed_fields = {}
|
|
92
97
|
# lateral regridding
|
|
@@ -98,7 +103,7 @@ class TidalForcing:
|
|
|
98
103
|
)
|
|
99
104
|
|
|
100
105
|
# rotation of velocities and interpolation to u/v points
|
|
101
|
-
vector_pairs = get_vector_pairs(variable_info)
|
|
106
|
+
vector_pairs = get_vector_pairs(self.variable_info)
|
|
102
107
|
for pair in vector_pairs:
|
|
103
108
|
u_component = pair[0]
|
|
104
109
|
v_component = pair[1]
|
|
@@ -129,7 +134,8 @@ class TidalForcing:
|
|
|
129
134
|
|
|
130
135
|
ds = self._add_global_metadata(ds)
|
|
131
136
|
|
|
132
|
-
self.
|
|
137
|
+
if not self.bypass_validation:
|
|
138
|
+
self._validate(ds)
|
|
133
139
|
|
|
134
140
|
# substitute NaNs over land by a fill value to avoid blow-up of ROMS
|
|
135
141
|
for var_name in ds.data_vars:
|
|
@@ -163,9 +169,8 @@ class TidalForcing:
|
|
|
163
169
|
|
|
164
170
|
Returns
|
|
165
171
|
-------
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
about each variable, including 'location', 'is_vector', 'vector_pair', and 'is_3d'.
|
|
172
|
+
None
|
|
173
|
+
This method updates the instance attribute `variable_info` with the metadata dictionary for the variables.
|
|
169
174
|
"""
|
|
170
175
|
default_info = {
|
|
171
176
|
"location": "rho",
|
|
@@ -210,7 +215,7 @@ class TidalForcing:
|
|
|
210
215
|
},
|
|
211
216
|
}
|
|
212
217
|
|
|
213
|
-
|
|
218
|
+
object.__setattr__(self, "variable_info", variable_info)
|
|
214
219
|
|
|
215
220
|
def _write_into_dataset(self, processed_fields, d_meta):
|
|
216
221
|
|
|
@@ -243,7 +248,7 @@ class TidalForcing:
|
|
|
243
248
|
|
|
244
249
|
return ds
|
|
245
250
|
|
|
246
|
-
def _validate(self, ds
|
|
251
|
+
def _validate(self, ds):
|
|
247
252
|
"""Validates the dataset by checking for NaN values at wet points for specified
|
|
248
253
|
variables, which would indicate missing raw data coverage over the target
|
|
249
254
|
domain.
|
|
@@ -252,8 +257,6 @@ class TidalForcing:
|
|
|
252
257
|
----------
|
|
253
258
|
ds : xarray.Dataset
|
|
254
259
|
The dataset to validate, containing tidal variables and a mask for wet points.
|
|
255
|
-
variable_info : dict
|
|
256
|
-
A dictionary containing metadata about the variables, including whether to validate them.
|
|
257
260
|
|
|
258
261
|
Raises
|
|
259
262
|
------
|
|
@@ -268,7 +271,7 @@ class TidalForcing:
|
|
|
268
271
|
"""
|
|
269
272
|
for var_name in ds.data_vars:
|
|
270
273
|
# only validate variables based on "validate" flag if use_dask is false
|
|
271
|
-
if not self.use_dask or variable_info[var_name]["validate"]:
|
|
274
|
+
if not self.use_dask or self.variable_info[var_name]["validate"]:
|
|
272
275
|
nan_check(ds[var_name].isel(ntides=0), self.grid.ds.mask_rho)
|
|
273
276
|
|
|
274
277
|
def plot(self, var_name, ntides=0) -> None:
|
|
@@ -423,7 +426,10 @@ class TidalForcing:
|
|
|
423
426
|
|
|
424
427
|
@classmethod
|
|
425
428
|
def from_yaml(
|
|
426
|
-
cls,
|
|
429
|
+
cls,
|
|
430
|
+
filepath: Union[str, Path],
|
|
431
|
+
use_dask: bool = False,
|
|
432
|
+
bypass_validation: bool = False,
|
|
427
433
|
) -> "TidalForcing":
|
|
428
434
|
"""Create an instance of the TidalForcing class from a YAML file.
|
|
429
435
|
|
|
@@ -433,6 +439,10 @@ class TidalForcing:
|
|
|
433
439
|
The path to the YAML file from which the parameters will be read.
|
|
434
440
|
use_dask: bool, optional
|
|
435
441
|
Indicates whether to use dask for processing. If True, data is processed with dask; if False, data is processed eagerly. Defaults to False.
|
|
442
|
+
bypass_validation: bool, optional
|
|
443
|
+
Indicates whether to skip validation checks in the processed data. When set to True,
|
|
444
|
+
the validation process that ensures no NaN values exist at wet points
|
|
445
|
+
in the processed dataset is bypassed. Defaults to False.
|
|
436
446
|
|
|
437
447
|
Returns
|
|
438
448
|
-------
|
|
@@ -443,7 +453,12 @@ class TidalForcing:
|
|
|
443
453
|
|
|
444
454
|
grid = Grid.from_yaml(filepath)
|
|
445
455
|
tidal_forcing_params = _from_yaml(cls, filepath)
|
|
446
|
-
return cls(
|
|
456
|
+
return cls(
|
|
457
|
+
grid=grid,
|
|
458
|
+
**tidal_forcing_params,
|
|
459
|
+
use_dask=use_dask,
|
|
460
|
+
bypass_validation=bypass_validation
|
|
461
|
+
)
|
|
447
462
|
|
|
448
463
|
def _correct_tides(self, data):
|
|
449
464
|
"""Apply tidal corrections to the dataset. This method corrects the dataset for
|