roms-tools 2.0.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 +21 -30
- roms_tools/setup/datasets.py +13 -21
- roms_tools/setup/grid.py +253 -139
- roms_tools/setup/initial_conditions.py +21 -3
- 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 +21 -8
- roms_tools/setup/tides.py +21 -3
- roms_tools/setup/topography.py +168 -35
- roms_tools/setup/utils.py +127 -21
- 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_nesting.py +489 -0
- roms_tools/tests/test_setup/test_river_forcing.py +50 -13
- roms_tools/tests/test_setup/test_surface_forcing.py +1 -0
- roms_tools/tests/test_setup/test_validation.py +2 -2
- {roms_tools-2.0.0.dist-info → roms_tools-2.1.0.dist-info}/METADATA +8 -4
- {roms_tools-2.0.0.dist-info → roms_tools-2.1.0.dist-info}/RECORD +51 -50
- {roms_tools-2.0.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/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.1.0.dist-info}/LICENSE +0 -0
- {roms_tools-2.0.0.dist-info → roms_tools-2.1.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:
|
|
@@ -882,7 +888,10 @@ class InitialConditions:
|
|
|
882
888
|
|
|
883
889
|
@classmethod
|
|
884
890
|
def from_yaml(
|
|
885
|
-
cls,
|
|
891
|
+
cls,
|
|
892
|
+
filepath: Union[str, Path],
|
|
893
|
+
use_dask: bool = False,
|
|
894
|
+
bypass_validation: bool = False,
|
|
886
895
|
) -> "InitialConditions":
|
|
887
896
|
"""Create an instance of the InitialConditions class from a YAML file.
|
|
888
897
|
|
|
@@ -892,6 +901,10 @@ class InitialConditions:
|
|
|
892
901
|
The path to the YAML file from which the parameters will be read.
|
|
893
902
|
use_dask: bool, optional
|
|
894
903
|
Indicates whether to use dask for processing. If True, data is processed with dask; if False, data is processed eagerly. Defaults to False.
|
|
904
|
+
bypass_validation: bool, optional
|
|
905
|
+
Indicates whether to skip validation checks in the processed data. When set to True,
|
|
906
|
+
the validation process that ensures no NaN values exist at wet points
|
|
907
|
+
in the processed dataset is bypassed. Defaults to False.
|
|
895
908
|
|
|
896
909
|
Returns
|
|
897
910
|
-------
|
|
@@ -902,4 +915,9 @@ class InitialConditions:
|
|
|
902
915
|
|
|
903
916
|
grid = Grid.from_yaml(filepath)
|
|
904
917
|
initial_conditions_params = _from_yaml(cls, filepath)
|
|
905
|
-
return cls(
|
|
918
|
+
return cls(
|
|
919
|
+
grid=grid,
|
|
920
|
+
**initial_conditions_params,
|
|
921
|
+
use_dask=use_dask,
|
|
922
|
+
bypass_validation=bypass_validation,
|
|
923
|
+
)
|
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"
|