roms-tools 2.2.1__py3-none-any.whl → 2.4.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.
- ci/environment.yml +1 -0
- roms_tools/__init__.py +2 -0
- roms_tools/analysis/roms_output.py +590 -0
- roms_tools/{setup/download.py → download.py} +3 -0
- roms_tools/{setup/plot.py → plot.py} +34 -28
- roms_tools/setup/boundary_forcing.py +199 -203
- roms_tools/setup/datasets.py +60 -136
- roms_tools/setup/grid.py +40 -67
- roms_tools/setup/initial_conditions.py +249 -247
- roms_tools/setup/nesting.py +6 -27
- roms_tools/setup/river_forcing.py +41 -76
- roms_tools/setup/surface_forcing.py +125 -75
- roms_tools/setup/tides.py +31 -51
- roms_tools/setup/topography.py +1 -1
- roms_tools/setup/utils.py +44 -224
- roms_tools/tests/test_analysis/test_roms_output.py +269 -0
- roms_tools/tests/{test_setup/test_regrid.py → test_regrid.py} +1 -1
- roms_tools/tests/test_setup/test_boundary_forcing.py +221 -58
- roms_tools/tests/test_setup/test_data/boundary_forcing.zarr/.zattrs +5 -3
- roms_tools/tests/test_setup/test_data/boundary_forcing.zarr/.zmetadata +156 -121
- roms_tools/tests/test_setup/test_data/boundary_forcing.zarr/abs_time/.zarray +2 -2
- roms_tools/tests/test_setup/test_data/boundary_forcing.zarr/abs_time/.zattrs +2 -1
- roms_tools/tests/test_setup/test_data/boundary_forcing.zarr/abs_time/0 +0 -0
- roms_tools/tests/test_setup/test_data/boundary_forcing.zarr/bry_time/.zarray +2 -2
- roms_tools/tests/test_setup/test_data/boundary_forcing.zarr/bry_time/.zattrs +1 -1
- roms_tools/tests/test_setup/test_data/boundary_forcing.zarr/bry_time/0 +0 -0
- roms_tools/tests/test_setup/test_data/boundary_forcing.zarr/salt_east/.zarray +4 -4
- roms_tools/tests/test_setup/test_data/boundary_forcing.zarr/salt_east/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/boundary_forcing.zarr/salt_north/.zarray +4 -4
- roms_tools/tests/test_setup/test_data/boundary_forcing.zarr/salt_north/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/boundary_forcing.zarr/salt_south/.zarray +4 -4
- roms_tools/tests/test_setup/test_data/boundary_forcing.zarr/salt_south/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/boundary_forcing.zarr/salt_west/.zarray +4 -4
- roms_tools/tests/test_setup/test_data/boundary_forcing.zarr/salt_west/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/boundary_forcing.zarr/temp_east/.zarray +4 -4
- roms_tools/tests/test_setup/test_data/boundary_forcing.zarr/temp_east/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/boundary_forcing.zarr/temp_north/.zarray +4 -4
- roms_tools/tests/test_setup/test_data/boundary_forcing.zarr/temp_north/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/boundary_forcing.zarr/temp_south/.zarray +4 -4
- roms_tools/tests/test_setup/test_data/boundary_forcing.zarr/temp_south/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/boundary_forcing.zarr/temp_west/.zarray +4 -4
- roms_tools/tests/test_setup/test_data/boundary_forcing.zarr/temp_west/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/boundary_forcing.zarr/u_east/.zarray +4 -4
- roms_tools/tests/test_setup/test_data/boundary_forcing.zarr/u_east/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/boundary_forcing.zarr/u_north/.zarray +4 -4
- roms_tools/tests/test_setup/test_data/boundary_forcing.zarr/u_north/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/boundary_forcing.zarr/u_south/.zarray +4 -4
- roms_tools/tests/test_setup/test_data/boundary_forcing.zarr/u_south/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/boundary_forcing.zarr/u_west/.zarray +4 -4
- roms_tools/tests/test_setup/test_data/boundary_forcing.zarr/u_west/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/boundary_forcing.zarr/ubar_east/.zarray +4 -4
- roms_tools/tests/test_setup/test_data/boundary_forcing.zarr/ubar_east/0.0 +0 -0
- roms_tools/tests/test_setup/test_data/boundary_forcing.zarr/ubar_north/.zarray +4 -4
- roms_tools/tests/test_setup/test_data/boundary_forcing.zarr/ubar_north/0.0 +0 -0
- roms_tools/tests/test_setup/test_data/boundary_forcing.zarr/ubar_south/.zarray +4 -4
- roms_tools/tests/test_setup/test_data/boundary_forcing.zarr/ubar_south/0.0 +0 -0
- roms_tools/tests/test_setup/test_data/boundary_forcing.zarr/ubar_west/.zarray +4 -4
- roms_tools/tests/test_setup/test_data/boundary_forcing.zarr/ubar_west/0.0 +0 -0
- roms_tools/tests/test_setup/test_data/boundary_forcing.zarr/v_east/.zarray +4 -4
- roms_tools/tests/test_setup/test_data/boundary_forcing.zarr/v_east/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/boundary_forcing.zarr/v_north/.zarray +4 -4
- roms_tools/tests/test_setup/test_data/boundary_forcing.zarr/v_north/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/boundary_forcing.zarr/v_south/.zarray +4 -4
- roms_tools/tests/test_setup/test_data/boundary_forcing.zarr/v_south/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/boundary_forcing.zarr/v_west/.zarray +4 -4
- roms_tools/tests/test_setup/test_data/boundary_forcing.zarr/v_west/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/boundary_forcing.zarr/vbar_east/.zarray +4 -4
- roms_tools/tests/test_setup/test_data/boundary_forcing.zarr/vbar_east/0.0 +0 -0
- roms_tools/tests/test_setup/test_data/boundary_forcing.zarr/vbar_north/.zarray +4 -4
- roms_tools/tests/test_setup/test_data/boundary_forcing.zarr/vbar_north/0.0 +0 -0
- roms_tools/tests/test_setup/test_data/boundary_forcing.zarr/vbar_south/.zarray +4 -4
- roms_tools/tests/test_setup/test_data/boundary_forcing.zarr/vbar_south/0.0 +0 -0
- roms_tools/tests/test_setup/test_data/boundary_forcing.zarr/vbar_west/.zarray +4 -4
- roms_tools/tests/test_setup/test_data/boundary_forcing.zarr/vbar_west/0.0 +0 -0
- roms_tools/tests/test_setup/test_data/boundary_forcing.zarr/zeta_east/.zarray +4 -4
- roms_tools/tests/test_setup/test_data/boundary_forcing.zarr/zeta_east/.zattrs +8 -0
- roms_tools/tests/test_setup/test_data/boundary_forcing.zarr/zeta_east/0.0 +0 -0
- roms_tools/tests/test_setup/test_data/boundary_forcing.zarr/zeta_north/.zarray +4 -4
- roms_tools/tests/test_setup/test_data/boundary_forcing.zarr/zeta_north/.zattrs +8 -0
- roms_tools/tests/test_setup/test_data/boundary_forcing.zarr/zeta_north/0.0 +0 -0
- roms_tools/tests/test_setup/test_data/boundary_forcing.zarr/zeta_south/.zarray +4 -4
- roms_tools/tests/test_setup/test_data/boundary_forcing.zarr/zeta_south/.zattrs +8 -0
- roms_tools/tests/test_setup/test_data/boundary_forcing.zarr/zeta_south/0.0 +0 -0
- roms_tools/tests/test_setup/test_data/boundary_forcing.zarr/zeta_west/.zarray +4 -4
- roms_tools/tests/test_setup/test_data/boundary_forcing.zarr/zeta_west/.zattrs +8 -0
- roms_tools/tests/test_setup/test_data/boundary_forcing.zarr/zeta_west/0.0 +0 -0
- roms_tools/tests/test_setup/test_data/grid_that_straddles_dateline.zarr/.zattrs +4 -4
- roms_tools/tests/test_setup/test_data/grid_that_straddles_dateline.zarr/.zmetadata +4 -4
- roms_tools/tests/test_setup/test_data/grid_that_straddles_dateline.zarr/angle/0.0 +0 -0
- roms_tools/tests/test_setup/test_data/grid_that_straddles_dateline.zarr/angle_coarse/0.0 +0 -0
- roms_tools/tests/test_setup/test_data/grid_that_straddles_dateline.zarr/f/0.0 +0 -0
- 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/lat_coarse/0.0 +0 -0
- roms_tools/tests/test_setup/test_data/grid_that_straddles_dateline.zarr/lat_rho/0.0 +0 -0
- roms_tools/tests/test_setup/test_data/grid_that_straddles_dateline.zarr/lat_u/0.0 +0 -0
- roms_tools/tests/test_setup/test_data/grid_that_straddles_dateline.zarr/lat_v/0.0 +0 -0
- roms_tools/tests/test_setup/test_data/grid_that_straddles_dateline.zarr/lon_coarse/0.0 +0 -0
- roms_tools/tests/test_setup/test_data/grid_that_straddles_dateline.zarr/lon_rho/0.0 +0 -0
- roms_tools/tests/test_setup/test_data/grid_that_straddles_dateline.zarr/lon_u/0.0 +0 -0
- roms_tools/tests/test_setup/test_data/grid_that_straddles_dateline.zarr/lon_v/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/pm/0.0 +0 -0
- roms_tools/tests/test_setup/test_data/grid_that_straddles_dateline.zarr/pn/0.0 +0 -0
- roms_tools/tests/test_setup/test_data/initial_conditions_with_bgc_from_climatology.zarr/.zattrs +2 -1
- roms_tools/tests/test_setup/test_data/initial_conditions_with_bgc_from_climatology.zarr/.zmetadata +6 -4
- roms_tools/tests/test_setup/test_data/initial_conditions_with_bgc_from_climatology.zarr/Cs_r/.zattrs +1 -1
- roms_tools/tests/test_setup/test_data/initial_conditions_with_bgc_from_climatology.zarr/Cs_w/.zattrs +1 -1
- roms_tools/tests/test_setup/test_data/initial_conditions_with_bgc_from_climatology.zarr/NH4/0.0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/initial_conditions_with_bgc_from_climatology.zarr/NO3/0.0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/initial_conditions_with_bgc_from_climatology.zarr/PO4/0.0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/initial_conditions_with_bgc_from_climatology.zarr/abs_time/.zattrs +1 -0
- roms_tools/tests/test_setup/test_data/initial_conditions_with_bgc_from_climatology.zarr/diatSi/0.0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/initial_conditions_with_bgc_from_climatology.zarr/ocean_time/.zattrs +1 -1
- roms_tools/tests/test_setup/test_data/initial_conditions_with_bgc_from_climatology.zarr/spC/0.0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/initial_conditions_with_bgc_from_climatology.zarr/spCaCO3/0.0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/initial_conditions_with_bgc_from_climatology.zarr/spFe/0.0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/initial_conditions_with_bgc_from_climatology.zarr/temp/0.0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/initial_conditions_with_bgc_from_climatology.zarr/u/0.0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/initial_conditions_with_bgc_from_climatology.zarr/ubar/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/initial_conditions_with_bgc_from_climatology.zarr/v/0.0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/initial_conditions_with_bgc_from_climatology.zarr/vbar/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/river_forcing_no_climatology.zarr/.zmetadata +30 -0
- roms_tools/tests/test_setup/test_data/river_forcing_no_climatology.zarr/river_location/.zarray +22 -0
- roms_tools/tests/test_setup/test_data/river_forcing_no_climatology.zarr/river_location/.zattrs +8 -0
- roms_tools/tests/test_setup/test_data/river_forcing_no_climatology.zarr/river_location/0.0 +0 -0
- roms_tools/tests/test_setup/test_data/river_forcing_with_bgc.zarr/.zmetadata +30 -0
- roms_tools/tests/test_setup/test_data/river_forcing_with_bgc.zarr/river_location/.zarray +22 -0
- roms_tools/tests/test_setup/test_data/river_forcing_with_bgc.zarr/river_location/.zattrs +8 -0
- roms_tools/tests/test_setup/test_data/river_forcing_with_bgc.zarr/river_location/0.0 +0 -0
- roms_tools/tests/test_setup/test_datasets.py +1 -1
- roms_tools/tests/test_setup/test_grid.py +1 -14
- roms_tools/tests/test_setup/test_initial_conditions.py +205 -67
- roms_tools/tests/test_setup/test_nesting.py +0 -16
- roms_tools/tests/test_setup/test_river_forcing.py +9 -37
- roms_tools/tests/test_setup/test_surface_forcing.py +103 -74
- roms_tools/tests/test_setup/test_tides.py +5 -17
- roms_tools/tests/test_setup/test_topography.py +1 -1
- roms_tools/tests/test_setup/test_utils.py +57 -1
- roms_tools/tests/{test_utils.py → test_tiling/test_partition.py} +1 -1
- roms_tools/tiling/partition.py +338 -0
- roms_tools/utils.py +310 -276
- roms_tools/vertical_coordinate.py +227 -0
- {roms_tools-2.2.1.dist-info → roms_tools-2.4.0.dist-info}/METADATA +1 -1
- {roms_tools-2.2.1.dist-info → roms_tools-2.4.0.dist-info}/RECORD +151 -142
- roms_tools/setup/vertical_coordinate.py +0 -109
- /roms_tools/{setup/regrid.py → regrid.py} +0 -0
- {roms_tools-2.2.1.dist-info → roms_tools-2.4.0.dist-info}/LICENSE +0 -0
- {roms_tools-2.2.1.dist-info → roms_tools-2.4.0.dist-info}/WHEEL +0 -0
- {roms_tools-2.2.1.dist-info → roms_tools-2.4.0.dist-info}/top_level.txt +0 -0
|
@@ -4,17 +4,20 @@ from roms_tools import InitialConditions, Grid
|
|
|
4
4
|
import xarray as xr
|
|
5
5
|
import numpy as np
|
|
6
6
|
import textwrap
|
|
7
|
-
|
|
7
|
+
import logging
|
|
8
|
+
from roms_tools.download import download_test_data
|
|
8
9
|
from roms_tools.setup.datasets import CESMBGCDataset
|
|
9
10
|
from pathlib import Path
|
|
10
|
-
from conftest import
|
|
11
|
+
from conftest import calculate_data_hash
|
|
11
12
|
|
|
12
13
|
|
|
13
14
|
@pytest.mark.parametrize(
|
|
14
15
|
"ic_fixture",
|
|
15
16
|
[
|
|
16
17
|
"initial_conditions",
|
|
18
|
+
"initial_conditions_adjusted_for_zeta",
|
|
17
19
|
"initial_conditions_with_bgc",
|
|
20
|
+
"initial_conditions_with_bgc_adjusted_for_zeta",
|
|
18
21
|
"initial_conditions_with_bgc_from_climatology",
|
|
19
22
|
],
|
|
20
23
|
)
|
|
@@ -29,6 +32,7 @@ def test_initial_conditions_creation(ic_fixture, request):
|
|
|
29
32
|
"path": Path(download_test_data("GLORYS_coarse_test_data.nc")),
|
|
30
33
|
"climatology": False,
|
|
31
34
|
}
|
|
35
|
+
assert hasattr(ic.ds, "adjust_depth_for_sea_surface_height")
|
|
32
36
|
assert isinstance(ic.ds, xr.Dataset)
|
|
33
37
|
assert "temp" in ic.ds
|
|
34
38
|
assert "salt" in ic.ds
|
|
@@ -144,6 +148,128 @@ def test_initial_conditions_default_bgc_climatology(example_grid, use_dask):
|
|
|
144
148
|
assert initial_conditions.bgc_source["climatology"] is False
|
|
145
149
|
|
|
146
150
|
|
|
151
|
+
def test_info_depth(caplog, use_dask):
|
|
152
|
+
|
|
153
|
+
grid = Grid(
|
|
154
|
+
nx=2,
|
|
155
|
+
ny=2,
|
|
156
|
+
size_x=500,
|
|
157
|
+
size_y=1000,
|
|
158
|
+
center_lon=0,
|
|
159
|
+
center_lat=55,
|
|
160
|
+
rot=10,
|
|
161
|
+
N=3, # number of vertical levels
|
|
162
|
+
theta_s=5.0, # surface control parameter
|
|
163
|
+
theta_b=2.0, # bottom control parameter
|
|
164
|
+
hc=250.0, # critical depth
|
|
165
|
+
)
|
|
166
|
+
|
|
167
|
+
fname = Path(download_test_data("GLORYS_coarse_test_data.nc"))
|
|
168
|
+
|
|
169
|
+
with caplog.at_level(logging.INFO):
|
|
170
|
+
|
|
171
|
+
InitialConditions(
|
|
172
|
+
grid=grid,
|
|
173
|
+
ini_time=datetime(2021, 6, 29),
|
|
174
|
+
source={"path": fname, "name": "GLORYS"},
|
|
175
|
+
adjust_depth_for_sea_surface_height=True,
|
|
176
|
+
use_dask=use_dask,
|
|
177
|
+
)
|
|
178
|
+
# Verify the warning message in the log
|
|
179
|
+
assert "Sea surface height will be used to adjust depth coordinates." in caplog.text
|
|
180
|
+
|
|
181
|
+
# Clear the log before the next test
|
|
182
|
+
caplog.clear()
|
|
183
|
+
|
|
184
|
+
with caplog.at_level(logging.INFO):
|
|
185
|
+
|
|
186
|
+
InitialConditions(
|
|
187
|
+
grid=grid,
|
|
188
|
+
ini_time=datetime(2021, 6, 29),
|
|
189
|
+
source={"path": fname, "name": "GLORYS"},
|
|
190
|
+
adjust_depth_for_sea_surface_height=False,
|
|
191
|
+
use_dask=use_dask,
|
|
192
|
+
)
|
|
193
|
+
# Verify the warning message in the log
|
|
194
|
+
assert (
|
|
195
|
+
"Sea surface height will NOT be used to adjust depth coordinates."
|
|
196
|
+
in caplog.text
|
|
197
|
+
)
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
@pytest.mark.parametrize(
|
|
201
|
+
"initial_conditions_fixture",
|
|
202
|
+
[
|
|
203
|
+
"initial_conditions_adjusted_for_zeta",
|
|
204
|
+
"initial_conditions_with_bgc_adjusted_for_zeta",
|
|
205
|
+
],
|
|
206
|
+
)
|
|
207
|
+
def test_correct_depth_coords_adjusted_for_zeta(
|
|
208
|
+
initial_conditions_fixture, request, use_dask
|
|
209
|
+
):
|
|
210
|
+
|
|
211
|
+
initial_conditions = request.getfixturevalue(initial_conditions_fixture)
|
|
212
|
+
|
|
213
|
+
# compute interface depth at rho-points and write it into .ds_depth_coords
|
|
214
|
+
zeta = initial_conditions.ds.zeta
|
|
215
|
+
initial_conditions._get_depth_coordinates(
|
|
216
|
+
zeta, location="rho", depth_type="interface"
|
|
217
|
+
)
|
|
218
|
+
# Test that lowermost interface coincides with topography
|
|
219
|
+
assert np.allclose(
|
|
220
|
+
initial_conditions.ds_depth_coords["interface_depth_rho"]
|
|
221
|
+
.isel(s_w=0)
|
|
222
|
+
.squeeze()
|
|
223
|
+
.values, # Extract raw NumPy array
|
|
224
|
+
initial_conditions.grid.ds.h.values,
|
|
225
|
+
atol=1e-6, # Adjust tolerance as needed
|
|
226
|
+
)
|
|
227
|
+
|
|
228
|
+
# Test that uppermost interface coincides with sea surface height
|
|
229
|
+
assert np.allclose(
|
|
230
|
+
initial_conditions.ds_depth_coords["interface_depth_rho"]
|
|
231
|
+
.isel(s_w=-1)
|
|
232
|
+
.squeeze()
|
|
233
|
+
.values,
|
|
234
|
+
-zeta.values,
|
|
235
|
+
atol=1e-6,
|
|
236
|
+
)
|
|
237
|
+
|
|
238
|
+
|
|
239
|
+
@pytest.mark.parametrize(
|
|
240
|
+
"initial_conditions_fixture",
|
|
241
|
+
[
|
|
242
|
+
"initial_conditions",
|
|
243
|
+
"initial_conditions",
|
|
244
|
+
],
|
|
245
|
+
)
|
|
246
|
+
def test_correct_depth_coords_zero_zeta(initial_conditions_fixture, request, use_dask):
|
|
247
|
+
|
|
248
|
+
initial_conditions = request.getfixturevalue(initial_conditions_fixture)
|
|
249
|
+
|
|
250
|
+
# compute interface depth at rho-points and write it into .ds_depth_coords
|
|
251
|
+
initial_conditions._get_depth_coordinates(0, location="rho", depth_type="interface")
|
|
252
|
+
# Test that lowermost interface coincides with topography
|
|
253
|
+
assert np.allclose(
|
|
254
|
+
initial_conditions.ds_depth_coords["interface_depth_rho"]
|
|
255
|
+
.isel(s_w=0)
|
|
256
|
+
.squeeze()
|
|
257
|
+
.values, # Extract raw NumPy array
|
|
258
|
+
initial_conditions.grid.ds.h.values,
|
|
259
|
+
atol=1e-6, # Adjust tolerance as needed
|
|
260
|
+
)
|
|
261
|
+
|
|
262
|
+
# Test that uppermost interface coincides with sea surface height
|
|
263
|
+
assert np.allclose(
|
|
264
|
+
initial_conditions.ds_depth_coords["interface_depth_rho"]
|
|
265
|
+
.isel(s_w=-1)
|
|
266
|
+
.squeeze()
|
|
267
|
+
.values,
|
|
268
|
+
0 * initial_conditions.grid.ds.h.values,
|
|
269
|
+
atol=1e-6,
|
|
270
|
+
)
|
|
271
|
+
|
|
272
|
+
|
|
147
273
|
def test_interpolation_from_climatology(
|
|
148
274
|
initial_conditions_with_bgc_from_climatology, use_dask
|
|
149
275
|
):
|
|
@@ -176,47 +302,61 @@ def test_interpolation_from_climatology(
|
|
|
176
302
|
)
|
|
177
303
|
|
|
178
304
|
|
|
179
|
-
|
|
305
|
+
@pytest.mark.parametrize(
|
|
306
|
+
"initial_conditions_fixture",
|
|
307
|
+
[
|
|
308
|
+
"initial_conditions_with_bgc_adjusted_for_zeta",
|
|
309
|
+
"initial_conditions_with_bgc_from_climatology",
|
|
310
|
+
],
|
|
311
|
+
)
|
|
312
|
+
def test_initial_conditions_plot(initial_conditions_fixture, request):
|
|
180
313
|
"""Test plot method."""
|
|
181
314
|
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
var_name="
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
var_name="u",
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
)
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
315
|
+
initial_conditions = request.getfixturevalue(initial_conditions_fixture)
|
|
316
|
+
|
|
317
|
+
# horizontal slices plots
|
|
318
|
+
for depth_contours in [True, False]:
|
|
319
|
+
initial_conditions.plot(var_name="temp", s=0, depth_contours=depth_contours)
|
|
320
|
+
initial_conditions.plot(var_name="u", s=0, depth_contours=depth_contours)
|
|
321
|
+
initial_conditions.plot(var_name="v", s=0, depth_contours=depth_contours)
|
|
322
|
+
initial_conditions.plot(var_name="ALK", s=0, depth_contours=depth_contours)
|
|
323
|
+
|
|
324
|
+
# section plots
|
|
325
|
+
for layer_contours in [True, False]:
|
|
326
|
+
initial_conditions.plot(var_name="temp", eta=0, layer_contours=layer_contours)
|
|
327
|
+
initial_conditions.plot(var_name="temp", xi=0, layer_contours=layer_contours)
|
|
328
|
+
initial_conditions.plot(var_name="ALK", eta=0, layer_contours=layer_contours)
|
|
329
|
+
initial_conditions.plot(var_name="ALK", xi=0, layer_contours=layer_contours)
|
|
330
|
+
initial_conditions.plot(var_name="u", eta=0, layer_contours=layer_contours)
|
|
331
|
+
initial_conditions.plot(var_name="u", xi=0, layer_contours=layer_contours)
|
|
332
|
+
initial_conditions.plot(var_name="v", eta=0, layer_contours=layer_contours)
|
|
333
|
+
initial_conditions.plot(var_name="v", xi=0, layer_contours=layer_contours)
|
|
334
|
+
|
|
335
|
+
# 1D plot in horizontal
|
|
336
|
+
initial_conditions.plot(var_name="temp", s=0, xi=0)
|
|
337
|
+
initial_conditions.plot(var_name="ALK", s=0, xi=0)
|
|
338
|
+
|
|
339
|
+
# 1D plot in vertical
|
|
340
|
+
initial_conditions.plot(var_name="temp", eta=0, xi=0)
|
|
341
|
+
initial_conditions.plot(var_name="ALK", eta=0, xi=0)
|
|
342
|
+
|
|
343
|
+
initial_conditions.plot(var_name="zeta")
|
|
344
|
+
initial_conditions.plot(var_name="ubar")
|
|
345
|
+
initial_conditions.plot(var_name="vbar")
|
|
346
|
+
|
|
347
|
+
|
|
348
|
+
@pytest.mark.parametrize(
|
|
349
|
+
"initial_conditions_fixture",
|
|
350
|
+
[
|
|
351
|
+
"initial_conditions",
|
|
352
|
+
"initial_conditions_adjusted_for_zeta",
|
|
353
|
+
],
|
|
354
|
+
)
|
|
355
|
+
def test_initial_conditions_save(initial_conditions_fixture, request, tmp_path):
|
|
218
356
|
"""Test save method."""
|
|
219
357
|
|
|
358
|
+
initial_conditions = request.getfixturevalue(initial_conditions_fixture)
|
|
359
|
+
|
|
220
360
|
for file_str in ["test_ic", "test_ic.nc"]:
|
|
221
361
|
# Create a temporary filepath using the tmp_path fixture
|
|
222
362
|
for filepath in [
|
|
@@ -224,10 +364,7 @@ def test_initial_conditions_save(
|
|
|
224
364
|
str(tmp_path / file_str),
|
|
225
365
|
]: # test for Path object and str
|
|
226
366
|
|
|
227
|
-
|
|
228
|
-
saved_filenames = initial_conditions_with_bgc_from_climatology.save(
|
|
229
|
-
filepath
|
|
230
|
-
)
|
|
367
|
+
saved_filenames = initial_conditions.save(filepath)
|
|
231
368
|
# Check if the .nc file was created
|
|
232
369
|
filepath = Path(filepath).with_suffix(".nc")
|
|
233
370
|
assert saved_filenames == [filepath]
|
|
@@ -235,27 +372,20 @@ def test_initial_conditions_save(
|
|
|
235
372
|
# Clean up the .nc file
|
|
236
373
|
filepath.unlink()
|
|
237
374
|
|
|
238
|
-
# Test saving with partitioning
|
|
239
|
-
saved_filenames = initial_conditions_with_bgc_from_climatology.save(
|
|
240
|
-
filepath, np_eta=2
|
|
241
|
-
)
|
|
242
|
-
|
|
243
|
-
filepath_str = str(filepath.with_suffix(""))
|
|
244
|
-
expected_filepath_list = [
|
|
245
|
-
Path(filepath_str + f".{index}.nc") for index in range(2)
|
|
246
|
-
]
|
|
247
|
-
assert saved_filenames == expected_filepath_list
|
|
248
|
-
for expected_filepath in expected_filepath_list:
|
|
249
|
-
assert expected_filepath.exists()
|
|
250
|
-
expected_filepath.unlink()
|
|
251
375
|
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
376
|
+
@pytest.mark.parametrize(
|
|
377
|
+
"initial_conditions_fixture",
|
|
378
|
+
[
|
|
379
|
+
"initial_conditions",
|
|
380
|
+
"initial_conditions_adjusted_for_zeta",
|
|
381
|
+
],
|
|
382
|
+
)
|
|
383
|
+
def test_roundtrip_yaml(initial_conditions_fixture, request, tmp_path, use_dask):
|
|
256
384
|
"""Test that creating an InitialConditions object, saving its parameters to yaml
|
|
257
385
|
file, and re-opening yaml file creates the same object."""
|
|
258
386
|
|
|
387
|
+
initial_conditions = request.getfixturevalue(initial_conditions_fixture)
|
|
388
|
+
|
|
259
389
|
# Create a temporary filepath using the tmp_path fixture
|
|
260
390
|
file_str = "test_yaml"
|
|
261
391
|
for filepath in [
|
|
@@ -263,21 +393,28 @@ def test_roundtrip_yaml(
|
|
|
263
393
|
str(tmp_path / file_str),
|
|
264
394
|
]: # test for Path object and str
|
|
265
395
|
|
|
266
|
-
|
|
396
|
+
initial_conditions.to_yaml(filepath)
|
|
267
397
|
|
|
268
398
|
initial_conditions_from_file = InitialConditions.from_yaml(
|
|
269
399
|
filepath, use_dask=use_dask
|
|
270
400
|
)
|
|
271
401
|
|
|
272
|
-
assert
|
|
273
|
-
initial_conditions_with_bgc_from_climatology == initial_conditions_from_file
|
|
274
|
-
)
|
|
402
|
+
assert initial_conditions == initial_conditions_from_file
|
|
275
403
|
|
|
276
404
|
filepath = Path(filepath)
|
|
277
405
|
filepath.unlink()
|
|
278
406
|
|
|
279
407
|
|
|
280
|
-
|
|
408
|
+
@pytest.mark.parametrize(
|
|
409
|
+
"initial_conditions_fixture",
|
|
410
|
+
[
|
|
411
|
+
"initial_conditions",
|
|
412
|
+
"initial_conditions_adjusted_for_zeta",
|
|
413
|
+
],
|
|
414
|
+
)
|
|
415
|
+
def test_files_have_same_hash(initial_conditions_fixture, request, tmp_path, use_dask):
|
|
416
|
+
|
|
417
|
+
initial_conditions = request.getfixturevalue(initial_conditions_fixture)
|
|
281
418
|
|
|
282
419
|
yaml_filepath = tmp_path / "test_yaml.yaml"
|
|
283
420
|
filepath1 = tmp_path / "test1.nc"
|
|
@@ -288,8 +425,9 @@ def test_files_have_same_hash(initial_conditions, tmp_path, use_dask):
|
|
|
288
425
|
ic_from_file = InitialConditions.from_yaml(yaml_filepath, use_dask)
|
|
289
426
|
ic_from_file.save(filepath2)
|
|
290
427
|
|
|
291
|
-
|
|
292
|
-
|
|
428
|
+
# Only compare hash of datasets because metadata is non-deterministic with dask
|
|
429
|
+
hash1 = calculate_data_hash(filepath1)
|
|
430
|
+
hash2 = calculate_data_hash(filepath2)
|
|
293
431
|
|
|
294
432
|
assert hash1 == hash2, f"Hashes do not match: {hash1} != {hash2}"
|
|
295
433
|
|
|
@@ -417,7 +417,6 @@ class TestNesting:
|
|
|
417
417
|
[tmp_path / grid_file_str, str(tmp_path / grid_file_str)],
|
|
418
418
|
): # test for Path object and str
|
|
419
419
|
|
|
420
|
-
# Test saving without partitioning
|
|
421
420
|
saved_filenames = nesting.save(filepath, grid_filepath)
|
|
422
421
|
# Check if the .nc file was created
|
|
423
422
|
filepath = Path(filepath).with_suffix(".nc")
|
|
@@ -429,21 +428,6 @@ class TestNesting:
|
|
|
429
428
|
filepath.unlink()
|
|
430
429
|
grid_filepath.unlink()
|
|
431
430
|
|
|
432
|
-
# Test saving with partitioning
|
|
433
|
-
saved_filenames = nesting.save(
|
|
434
|
-
filepath, grid_filepath, np_eta=5, np_xi=5
|
|
435
|
-
)
|
|
436
|
-
|
|
437
|
-
filepath_str = str(filepath.with_suffix(""))
|
|
438
|
-
grid_filepath_str = str(grid_filepath.with_suffix(""))
|
|
439
|
-
expected_filepath_list = [
|
|
440
|
-
Path(filepath_str + f".{index}.nc") for index in range(25)
|
|
441
|
-
] + [Path(grid_filepath_str + f".{index}.nc") for index in range(25)]
|
|
442
|
-
assert saved_filenames == expected_filepath_list
|
|
443
|
-
for expected_filepath in expected_filepath_list:
|
|
444
|
-
assert expected_filepath.exists()
|
|
445
|
-
expected_filepath.unlink()
|
|
446
|
-
|
|
447
431
|
def test_roundtrip_yaml(self, nesting, tmp_path):
|
|
448
432
|
"""Test that creating a Nesting object, saving its parameters to yaml file, and
|
|
449
433
|
re-opening yaml file creates the same object."""
|
|
@@ -6,7 +6,7 @@ import textwrap
|
|
|
6
6
|
from pathlib import Path
|
|
7
7
|
import pytest
|
|
8
8
|
from conftest import calculate_file_hash
|
|
9
|
-
from roms_tools.
|
|
9
|
+
from roms_tools.download import download_river_data
|
|
10
10
|
|
|
11
11
|
|
|
12
12
|
@pytest.fixture
|
|
@@ -170,7 +170,7 @@ def test_river_locations_are_along_coast(river_forcing_fixture, request):
|
|
|
170
170
|
eta_rho = indices["eta_rho"][i]
|
|
171
171
|
xi_rho = indices["xi_rho"][i]
|
|
172
172
|
assert coast[eta_rho, xi_rho]
|
|
173
|
-
assert river_forcing.
|
|
173
|
+
assert river_forcing.ds["river_location"][eta_rho, xi_rho] > 0
|
|
174
174
|
|
|
175
175
|
|
|
176
176
|
def test_missing_source_name():
|
|
@@ -224,7 +224,7 @@ def test_reproducibility_same_grid(river_forcing):
|
|
|
224
224
|
assert river_forcing == the_same_river_forcing
|
|
225
225
|
|
|
226
226
|
|
|
227
|
-
def
|
|
227
|
+
def test_update_river_location_variable_without_conflicts(river_forcing, tmp_path):
|
|
228
228
|
|
|
229
229
|
fname = download_river_data("dai_trenberth_may2019.nc")
|
|
230
230
|
ds = xr.open_dataset(fname, decode_times=False)
|
|
@@ -257,41 +257,17 @@ def test_river_forcing_plot(river_forcing_with_bgc):
|
|
|
257
257
|
def test_river_forcing_save(river_forcing_with_bgc, tmp_path):
|
|
258
258
|
"""Test save method."""
|
|
259
259
|
|
|
260
|
-
for file_str
|
|
261
|
-
["test_rivers", "test_rivers.nc"], ["test_grid", "test_grid.nc"]
|
|
262
|
-
):
|
|
260
|
+
for file_str in ["test_rivers", "test_rivers.nc"]:
|
|
263
261
|
# Create a temporary filepath using the tmp_path fixture
|
|
264
|
-
for filepath,
|
|
265
|
-
[tmp_path / file_str, str(tmp_path / file_str)],
|
|
266
|
-
[tmp_path / grid_file_str, str(tmp_path / grid_file_str)],
|
|
267
|
-
): # test for Path object and str
|
|
262
|
+
for filepath in [tmp_path / file_str, str(tmp_path / file_str)]:
|
|
268
263
|
|
|
269
|
-
|
|
270
|
-
saved_filenames = river_forcing_with_bgc.save(filepath, grid_filepath)
|
|
264
|
+
saved_filenames = river_forcing_with_bgc.save(filepath)
|
|
271
265
|
# Check if the .nc file was created
|
|
272
266
|
filepath = Path(filepath).with_suffix(".nc")
|
|
273
|
-
|
|
274
|
-
assert saved_filenames == [filepath, grid_filepath]
|
|
267
|
+
assert saved_filenames == [filepath]
|
|
275
268
|
assert filepath.exists()
|
|
276
|
-
assert grid_filepath.exists()
|
|
277
269
|
# Clean up the .nc file
|
|
278
270
|
filepath.unlink()
|
|
279
|
-
grid_filepath.unlink()
|
|
280
|
-
|
|
281
|
-
# Test saving with partitioning
|
|
282
|
-
saved_filenames = river_forcing_with_bgc.save(
|
|
283
|
-
filepath, grid_filepath, np_eta=3, np_xi=3
|
|
284
|
-
)
|
|
285
|
-
|
|
286
|
-
filepath_str = str(filepath.with_suffix(""))
|
|
287
|
-
grid_filepath_str = str(grid_filepath.with_suffix(""))
|
|
288
|
-
expected_filepath_list = [
|
|
289
|
-
Path(filepath_str + f".{index}.nc") for index in range(9)
|
|
290
|
-
] + [Path(grid_filepath_str + f".{index}.nc") for index in range(9)]
|
|
291
|
-
assert saved_filenames == expected_filepath_list
|
|
292
|
-
for expected_filepath in expected_filepath_list:
|
|
293
|
-
assert expected_filepath.exists()
|
|
294
|
-
expected_filepath.unlink()
|
|
295
271
|
|
|
296
272
|
|
|
297
273
|
@pytest.mark.parametrize(
|
|
@@ -340,13 +316,11 @@ def test_files_have_same_hash(river_forcing_fixture, request, tmp_path):
|
|
|
340
316
|
yaml_filepath = tmp_path / "test_yaml.yaml"
|
|
341
317
|
filepath1 = tmp_path / "test1.nc"
|
|
342
318
|
filepath2 = tmp_path / "test2.nc"
|
|
343
|
-
grid_filepath1 = tmp_path / "grid_test1.nc"
|
|
344
|
-
grid_filepath2 = tmp_path / "grid_test2.nc"
|
|
345
319
|
|
|
346
320
|
river_forcing.to_yaml(yaml_filepath)
|
|
347
|
-
river_forcing.save(filepath1
|
|
321
|
+
river_forcing.save(filepath1)
|
|
348
322
|
rf_from_file = RiverForcing.from_yaml(yaml_filepath)
|
|
349
|
-
rf_from_file.save(filepath2
|
|
323
|
+
rf_from_file.save(filepath2)
|
|
350
324
|
|
|
351
325
|
hash1 = calculate_file_hash(filepath1)
|
|
352
326
|
hash2 = calculate_file_hash(filepath2)
|
|
@@ -356,8 +330,6 @@ def test_files_have_same_hash(river_forcing_fixture, request, tmp_path):
|
|
|
356
330
|
yaml_filepath.unlink()
|
|
357
331
|
filepath1.unlink()
|
|
358
332
|
filepath2.unlink()
|
|
359
|
-
grid_filepath1.unlink()
|
|
360
|
-
grid_filepath2.unlink()
|
|
361
333
|
|
|
362
334
|
|
|
363
335
|
def test_from_yaml_missing_river_forcing(tmp_path):
|