roms-tools 2.0.0__py3-none-any.whl → 2.2.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 +22 -32
- roms_tools/setup/datasets.py +19 -21
- roms_tools/setup/grid.py +253 -139
- roms_tools/setup/initial_conditions.py +29 -6
- roms_tools/setup/mask.py +50 -4
- roms_tools/setup/nesting.py +575 -0
- roms_tools/setup/plot.py +214 -55
- roms_tools/setup/river_forcing.py +125 -29
- roms_tools/setup/surface_forcing.py +33 -12
- roms_tools/setup/tides.py +31 -6
- roms_tools/setup/topography.py +168 -35
- roms_tools/setup/utils.py +137 -21
- roms_tools/tests/test_setup/test_boundary_forcing.py +7 -5
- 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_initial_conditions.py +6 -6
- roms_tools/tests/test_setup/test_nesting.py +489 -0
- roms_tools/tests/test_setup/test_river_forcing.py +50 -13
- roms_tools/tests/test_setup/test_surface_forcing.py +9 -8
- roms_tools/tests/test_setup/test_tides.py +5 -5
- roms_tools/tests/test_setup/test_validation.py +2 -2
- {roms_tools-2.0.0.dist-info → roms_tools-2.2.0.dist-info}/METADATA +9 -5
- {roms_tools-2.0.0.dist-info → roms_tools-2.2.0.dist-info}/RECORD +54 -53
- {roms_tools-2.0.0.dist-info → roms_tools-2.2.0.dist-info}/WHEEL +1 -1
- roms_tools/_version.py +0 -2
- 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_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-2.0.0.dist-info → roms_tools-2.2.0.dist-info}/LICENSE +0 -0
- {roms_tools-2.0.0.dist-info → roms_tools-2.2.0.dist-info}/top_level.txt +0 -0
|
@@ -66,6 +66,10 @@ class InitialConditions:
|
|
|
66
66
|
The reference date for the model. Defaults to 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
|
--------
|
|
@@ -87,6 +91,7 @@ class InitialConditions:
|
|
|
87
91
|
bgc_source: Optional[Dict[str, Union[str, Path, List[Union[str, Path]]]]] = None
|
|
88
92
|
model_reference_date: datetime = datetime(2000, 1, 1)
|
|
89
93
|
use_dask: bool = False
|
|
94
|
+
bypass_validation: bool = False
|
|
90
95
|
|
|
91
96
|
ds: xr.Dataset = field(init=False, repr=False)
|
|
92
97
|
|
|
@@ -105,7 +110,8 @@ class InitialConditions:
|
|
|
105
110
|
|
|
106
111
|
ds = self._add_global_metadata(ds)
|
|
107
112
|
|
|
108
|
-
self.
|
|
113
|
+
if not self.bypass_validation:
|
|
114
|
+
self._validate(ds)
|
|
109
115
|
|
|
110
116
|
# substitute NaNs over land by a fill value to avoid blow-up of ROMS
|
|
111
117
|
for var_name in ds.data_vars:
|
|
@@ -527,10 +533,15 @@ class InitialConditions:
|
|
|
527
533
|
variable_info = self.variable_info_physics
|
|
528
534
|
|
|
529
535
|
for var_name in variable_info:
|
|
530
|
-
|
|
531
|
-
|
|
536
|
+
if variable_info[var_name]["validate"]:
|
|
537
|
+
if variable_info[var_name]["location"] == "rho":
|
|
538
|
+
mask = self.grid.ds.mask_rho
|
|
539
|
+
elif variable_info[var_name]["location"] == "u":
|
|
540
|
+
mask = self.grid.ds.mask_u
|
|
541
|
+
elif variable_info[var_name]["location"] == "v":
|
|
542
|
+
mask = self.grid.ds.mask_v
|
|
532
543
|
ds[var_name].load()
|
|
533
|
-
nan_check(ds[var_name].squeeze(),
|
|
544
|
+
nan_check(ds[var_name].squeeze(), mask)
|
|
534
545
|
|
|
535
546
|
def _add_global_metadata(self, ds):
|
|
536
547
|
|
|
@@ -882,7 +893,10 @@ class InitialConditions:
|
|
|
882
893
|
|
|
883
894
|
@classmethod
|
|
884
895
|
def from_yaml(
|
|
885
|
-
cls,
|
|
896
|
+
cls,
|
|
897
|
+
filepath: Union[str, Path],
|
|
898
|
+
use_dask: bool = False,
|
|
899
|
+
bypass_validation: bool = False,
|
|
886
900
|
) -> "InitialConditions":
|
|
887
901
|
"""Create an instance of the InitialConditions class from a YAML file.
|
|
888
902
|
|
|
@@ -892,6 +906,10 @@ class InitialConditions:
|
|
|
892
906
|
The path to the YAML file from which the parameters will be read.
|
|
893
907
|
use_dask: bool, optional
|
|
894
908
|
Indicates whether to use dask for processing. If True, data is processed with dask; if False, data is processed eagerly. Defaults to False.
|
|
909
|
+
bypass_validation: bool, optional
|
|
910
|
+
Indicates whether to skip validation checks in the processed data. When set to True,
|
|
911
|
+
the validation process that ensures no NaN values exist at wet points
|
|
912
|
+
in the processed dataset is bypassed. Defaults to False.
|
|
895
913
|
|
|
896
914
|
Returns
|
|
897
915
|
-------
|
|
@@ -902,4 +920,9 @@ class InitialConditions:
|
|
|
902
920
|
|
|
903
921
|
grid = Grid.from_yaml(filepath)
|
|
904
922
|
initial_conditions_params = _from_yaml(cls, filepath)
|
|
905
|
-
return cls(
|
|
923
|
+
return cls(
|
|
924
|
+
grid=grid,
|
|
925
|
+
**initial_conditions_params,
|
|
926
|
+
use_dask=use_dask,
|
|
927
|
+
bypass_validation=bypass_validation,
|
|
928
|
+
)
|
roms_tools/setup/mask.py
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import xarray as xr
|
|
2
2
|
import numpy as np
|
|
3
3
|
import regionmask
|
|
4
|
+
import warnings
|
|
4
5
|
from scipy.ndimage import label
|
|
5
6
|
from roms_tools.setup.utils import (
|
|
6
7
|
interpolate_from_rho_to_u,
|
|
@@ -10,10 +11,26 @@ from roms_tools.setup.utils import (
|
|
|
10
11
|
|
|
11
12
|
|
|
12
13
|
def _add_mask(ds):
|
|
13
|
-
|
|
14
|
+
"""Adds a land/water mask to the dataset at rho-points.
|
|
15
|
+
|
|
16
|
+
Parameters
|
|
17
|
+
----------
|
|
18
|
+
ds : xarray.Dataset
|
|
19
|
+
Input dataset containing latitude and longitude coordinates at rho-points.
|
|
20
|
+
|
|
21
|
+
Returns
|
|
22
|
+
-------
|
|
23
|
+
xarray.Dataset
|
|
24
|
+
The original dataset with an added 'mask_rho' variable, representing land/water mask.
|
|
25
|
+
"""
|
|
14
26
|
land = regionmask.defined_regions.natural_earth_v5_0_0.land_10
|
|
15
27
|
|
|
16
|
-
|
|
28
|
+
# Suppress specific warning
|
|
29
|
+
with warnings.catch_warnings():
|
|
30
|
+
warnings.filterwarnings(
|
|
31
|
+
"ignore", message="No gridpoint belongs to any region.*"
|
|
32
|
+
)
|
|
33
|
+
land_mask = land.mask(ds["lon_rho"], ds["lat_rho"])
|
|
17
34
|
mask = land_mask.isnull()
|
|
18
35
|
|
|
19
36
|
# fill enclosed basins with land
|
|
@@ -32,7 +49,21 @@ def _add_mask(ds):
|
|
|
32
49
|
|
|
33
50
|
|
|
34
51
|
def _fill_enclosed_basins(mask) -> np.ndarray:
|
|
35
|
-
"""Fills
|
|
52
|
+
"""Fills enclosed basins in the mask with land (value = 1).
|
|
53
|
+
|
|
54
|
+
This function identifies the largest connected region in the mask, which is assumed to represent
|
|
55
|
+
the land, and sets all other regions to water (value = 0).
|
|
56
|
+
|
|
57
|
+
Parameters
|
|
58
|
+
----------
|
|
59
|
+
mask : np.ndarray
|
|
60
|
+
A binary array representing the land/water mask (land = 1, water = 0).
|
|
61
|
+
|
|
62
|
+
Returns
|
|
63
|
+
-------
|
|
64
|
+
np.ndarray
|
|
65
|
+
The modified mask with enclosed basins filled with land (1).
|
|
66
|
+
"""
|
|
36
67
|
|
|
37
68
|
# Label connected regions in the mask
|
|
38
69
|
reg, nreg = label(mask)
|
|
@@ -54,7 +85,22 @@ def _fill_enclosed_basins(mask) -> np.ndarray:
|
|
|
54
85
|
|
|
55
86
|
|
|
56
87
|
def _add_velocity_masks(ds):
|
|
57
|
-
|
|
88
|
+
"""Adds velocity masks for u- and v-points based on the rho-point mask.
|
|
89
|
+
|
|
90
|
+
This function generates masks for u- and v-points by interpolating the rho-point land/water mask.
|
|
91
|
+
The interpolation method used is "multiplicative", which scales the rho-point mask to the respective
|
|
92
|
+
u- and v-points.
|
|
93
|
+
|
|
94
|
+
Parameters
|
|
95
|
+
----------
|
|
96
|
+
ds : xarray.Dataset
|
|
97
|
+
The dataset containing the land/water mask at rho-points (`mask_rho`).
|
|
98
|
+
|
|
99
|
+
Returns
|
|
100
|
+
-------
|
|
101
|
+
xarray.Dataset
|
|
102
|
+
The input dataset with added velocity masks (`mask_u` and `mask_v`) for u- and v-points.
|
|
103
|
+
"""
|
|
58
104
|
# add u- and v-masks
|
|
59
105
|
ds["mask_u"] = interpolate_from_rho_to_u(
|
|
60
106
|
ds["mask_rho"], method="multiplicative"
|