roms-tools 0.1.0__py3-none-any.whl → 1.0.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.
@@ -0,0 +1,337 @@
1
+ import pytest
2
+ import numpy as np
3
+ import tempfile
4
+ import os
5
+ from roms_tools import Grid, VerticalCoordinate
6
+ import textwrap
7
+
8
+
9
+ @pytest.fixture
10
+ def example_grid():
11
+ """
12
+ Fixture for creating a Grid object.
13
+ """
14
+ grid = Grid(
15
+ nx=2, ny=2, size_x=500, size_y=1000, center_lon=0, center_lat=55, rot=10
16
+ )
17
+
18
+ return grid
19
+
20
+
21
+ def test_invalid_theta_s_value(example_grid):
22
+ """
23
+ Test the validation of the theta_s value.
24
+ """
25
+ with pytest.raises(ValueError):
26
+
27
+ VerticalCoordinate(
28
+ grid=example_grid,
29
+ N=3,
30
+ theta_s=11.0, # Invalid value, should be 0 < theta_s <= 10
31
+ theta_b=2.0,
32
+ hc=250.0,
33
+ )
34
+
35
+
36
+ def test_invalid_theta_b_value(example_grid):
37
+ """
38
+ Test the validation of the theta_b value.
39
+ """
40
+ with pytest.raises(ValueError):
41
+
42
+ VerticalCoordinate(
43
+ grid=example_grid,
44
+ N=3,
45
+ theta_s=5.0,
46
+ theta_b=5.0, # Invalid value, should be 0 < theta_b <= 4
47
+ hc=250.0,
48
+ )
49
+
50
+
51
+ @pytest.fixture
52
+ def vertical_coordinate(example_grid):
53
+
54
+ return VerticalCoordinate(
55
+ grid=example_grid, N=3, theta_s=5.0, theta_b=2.0, hc=250.0
56
+ )
57
+
58
+
59
+ def test_vertical_coordinate_data_consistency(vertical_coordinate, tmp_path):
60
+ """
61
+ Test that the data within the VerticalCoordinate object remains consistent.
62
+ """
63
+
64
+ # Define the expected data
65
+ expected_sc_r = np.array([-0.8333333, -0.5, -0.16666667], dtype=np.float32)
66
+ expected_Cs_r = np.array([-0.6641397, -0.15129805, -0.01156188], dtype=np.float32)
67
+ expected_layer_depth_rho = np.array(
68
+ [
69
+ [
70
+ [17.235603, 9.938617, 3.2495391],
71
+ [17.235603, 9.938617, 3.2495391],
72
+ [24.206884, 13.7451725, 4.4592304],
73
+ [24.206884, 13.7451725, 4.4592304],
74
+ ],
75
+ [
76
+ [17.235603, 9.938617, 3.2495391],
77
+ [17.235603, 9.938617, 3.2495391],
78
+ [24.206884, 13.7451725, 4.4592304],
79
+ [24.206884, 13.7451725, 4.4592304],
80
+ ],
81
+ [
82
+ [25.667452, 14.528268, 4.7055993],
83
+ [25.667452, 14.528268, 4.7055993],
84
+ [35.966946, 19.916193, 6.377065],
85
+ [35.966946, 19.916193, 6.377065],
86
+ ],
87
+ [
88
+ [25.667452, 14.528268, 4.7055993],
89
+ [25.667452, 14.528268, 4.7055993],
90
+ [35.966946, 19.916193, 6.377065],
91
+ [35.966946, 19.916193, 6.377065],
92
+ ],
93
+ ],
94
+ dtype=np.float32,
95
+ )
96
+ expected_layer_depth_u = np.array(
97
+ [
98
+ [
99
+ [17.235603, 9.938617, 3.2495391],
100
+ [20.721243, 11.841895, 3.854385],
101
+ [24.206884, 13.7451725, 4.4592304],
102
+ ],
103
+ [
104
+ [17.235603, 9.938617, 3.2495391],
105
+ [20.721243, 11.841895, 3.854385],
106
+ [24.206884, 13.7451725, 4.4592304],
107
+ ],
108
+ [
109
+ [25.667452, 14.528268, 4.7055993],
110
+ [30.817198, 17.22223, 5.5413322],
111
+ [35.966946, 19.916193, 6.377065],
112
+ ],
113
+ [
114
+ [25.667452, 14.528268, 4.7055993],
115
+ [30.817198, 17.22223, 5.5413322],
116
+ [35.966946, 19.916193, 6.377065],
117
+ ],
118
+ ],
119
+ dtype=np.float32,
120
+ )
121
+ expected_layer_depth_v = np.array(
122
+ [
123
+ [
124
+ [17.235603, 9.938617, 3.2495391],
125
+ [17.235603, 9.938617, 3.2495391],
126
+ [24.206884, 13.7451725, 4.4592304],
127
+ [24.206884, 13.7451725, 4.4592304],
128
+ ],
129
+ [
130
+ [21.451529, 12.233442, 3.977569],
131
+ [21.451529, 12.233442, 3.977569],
132
+ [30.086914, 16.830683, 5.418148],
133
+ [30.086914, 16.830683, 5.418148],
134
+ ],
135
+ [
136
+ [25.667452, 14.528268, 4.7055993],
137
+ [25.667452, 14.528268, 4.7055993],
138
+ [35.966946, 19.916193, 6.377065],
139
+ [35.966946, 19.916193, 6.377065],
140
+ ],
141
+ ],
142
+ dtype=np.float32,
143
+ )
144
+ expected_interface_depth_rho = np.array(
145
+ [
146
+ [
147
+ [21.013529, 13.487298, 6.5489607, -0.0],
148
+ [21.013529, 13.487298, 6.5489607, -0.0],
149
+ [29.688076, 18.78298, 9.014939, -0.0],
150
+ [29.688076, 18.78298, 9.014939, -0.0],
151
+ ],
152
+ [
153
+ [21.013529, 13.487298, 6.5489607, -0.0],
154
+ [21.013529, 13.487298, 6.5489607, -0.0],
155
+ [29.688076, 18.78298, 9.014939, -0.0],
156
+ [29.688076, 18.78298, 9.014939, -0.0],
157
+ ],
158
+ [
159
+ [31.51735, 19.881702, 9.519225, -0.0],
160
+ [31.51735, 19.881702, 9.519225, -0.0],
161
+ [44.52708, 27.529188, 12.960222, -0.0],
162
+ [44.52708, 27.529188, 12.960222, -0.0],
163
+ ],
164
+ [
165
+ [31.51735, 19.881702, 9.519225, -0.0],
166
+ [31.51735, 19.881702, 9.519225, -0.0],
167
+ [44.52708, 27.529188, 12.960222, -0.0],
168
+ [44.52708, 27.529188, 12.960222, -0.0],
169
+ ],
170
+ ],
171
+ dtype=np.float32,
172
+ )
173
+ expected_interface_depth_u = np.array(
174
+ [
175
+ [
176
+ [21.013529, 13.487298, 6.5489607, -0.0],
177
+ [25.350803, 16.13514, 7.78195, -0.0],
178
+ [29.688076, 18.78298, 9.014939, -0.0],
179
+ ],
180
+ [
181
+ [21.013529, 13.487298, 6.5489607, -0.0],
182
+ [25.350803, 16.13514, 7.78195, -0.0],
183
+ [29.688076, 18.78298, 9.014939, -0.0],
184
+ ],
185
+ [
186
+ [31.51735, 19.881702, 9.519225, -0.0],
187
+ [38.022217, 23.705446, 11.239724, -0.0],
188
+ [44.52708, 27.529188, 12.960222, -0.0],
189
+ ],
190
+ [
191
+ [31.51735, 19.881702, 9.519225, -0.0],
192
+ [38.022217, 23.705446, 11.239724, -0.0],
193
+ [44.52708, 27.529188, 12.960222, -0.0],
194
+ ],
195
+ ],
196
+ dtype=np.float32,
197
+ )
198
+ expected_interface_depth_v = np.array(
199
+ [
200
+ [
201
+ [21.013529, 13.487298, 6.5489607, -0.0],
202
+ [21.013529, 13.487298, 6.5489607, -0.0],
203
+ [29.688076, 18.78298, 9.014939, -0.0],
204
+ [29.688076, 18.78298, 9.014939, -0.0],
205
+ ],
206
+ [
207
+ [26.26544, 16.684502, 8.034093, -0.0],
208
+ [26.26544, 16.684502, 8.034093, -0.0],
209
+ [37.10758, 23.156084, 10.987581, -0.0],
210
+ [37.10758, 23.156084, 10.987581, -0.0],
211
+ ],
212
+ [
213
+ [31.51735, 19.881702, 9.519225, -0.0],
214
+ [31.51735, 19.881702, 9.519225, -0.0],
215
+ [44.52708, 27.529188, 12.960222, -0.0],
216
+ [44.52708, 27.529188, 12.960222, -0.0],
217
+ ],
218
+ ],
219
+ dtype=np.float32,
220
+ )
221
+ # Check the values in the dataset
222
+ assert np.allclose(vertical_coordinate.ds["sc_r"].values, expected_sc_r)
223
+ assert np.allclose(vertical_coordinate.ds["Cs_r"].values, expected_Cs_r)
224
+ assert np.allclose(
225
+ vertical_coordinate.ds["layer_depth_rho"].values, expected_layer_depth_rho
226
+ )
227
+ assert np.allclose(
228
+ vertical_coordinate.ds["layer_depth_u"].values, expected_layer_depth_u
229
+ )
230
+ assert np.allclose(
231
+ vertical_coordinate.ds["layer_depth_v"].values, expected_layer_depth_v
232
+ )
233
+ assert np.allclose(
234
+ vertical_coordinate.ds["interface_depth_rho"].values,
235
+ expected_interface_depth_rho,
236
+ )
237
+ assert np.allclose(
238
+ vertical_coordinate.ds["interface_depth_u"].values, expected_interface_depth_u
239
+ )
240
+ assert np.allclose(
241
+ vertical_coordinate.ds["interface_depth_v"].values, expected_interface_depth_v
242
+ )
243
+
244
+
245
+ def test_plot(vertical_coordinate):
246
+ vertical_coordinate.plot("layer_depth_u", s=0)
247
+ vertical_coordinate.plot("layer_depth_rho", s=-1)
248
+ vertical_coordinate.plot("interface_depth_v", s=-1)
249
+ vertical_coordinate.plot("layer_depth_rho", eta=0)
250
+ vertical_coordinate.plot("layer_depth_u", eta=0)
251
+ vertical_coordinate.plot("layer_depth_v", eta=0)
252
+ vertical_coordinate.plot("interface_depth_rho", eta=0)
253
+ vertical_coordinate.plot("interface_depth_u", eta=0)
254
+ vertical_coordinate.plot("interface_depth_v", eta=0)
255
+ vertical_coordinate.plot("layer_depth_rho", xi=0)
256
+ vertical_coordinate.plot("layer_depth_u", xi=0)
257
+ vertical_coordinate.plot("layer_depth_v", xi=0)
258
+ vertical_coordinate.plot("interface_depth_rho", xi=0)
259
+ vertical_coordinate.plot("interface_depth_u", xi=0)
260
+ vertical_coordinate.plot("interface_depth_v", xi=0)
261
+
262
+
263
+ def test_save(vertical_coordinate, tmp_path):
264
+ filepath = tmp_path / "vertical_coordinate.nc"
265
+ vertical_coordinate.save(filepath)
266
+ assert filepath.exists()
267
+
268
+
269
+ def test_roundtrip(vertical_coordinate):
270
+ """Test that creating a vertical_coordinate, saving it to file, and re-opening it is the same as just creating it."""
271
+
272
+ # Create a temporary file
273
+ with tempfile.NamedTemporaryFile(delete=False) as tmpfile:
274
+ filepath = tmpfile.name
275
+
276
+ try:
277
+ vertical_coordinate.save(filepath)
278
+
279
+ vertical_coordinate_from_file = VerticalCoordinate.from_file(filepath)
280
+
281
+ assert vertical_coordinate.ds == vertical_coordinate_from_file.ds
282
+
283
+ finally:
284
+ os.remove(filepath)
285
+
286
+
287
+ def test_roundtrip_yaml(vertical_coordinate):
288
+ """Test that creating a VerticalCoordinate object, saving its parameters to yaml file, and re-opening yaml file creates the same object."""
289
+
290
+ # Create a temporary file
291
+ with tempfile.NamedTemporaryFile(delete=False) as tmpfile:
292
+ filepath = tmpfile.name
293
+
294
+ try:
295
+ vertical_coordinate.to_yaml(filepath)
296
+
297
+ vertical_coordinate_from_file = VerticalCoordinate.from_yaml(filepath)
298
+
299
+ assert vertical_coordinate == vertical_coordinate_from_file
300
+
301
+ finally:
302
+ os.remove(filepath)
303
+
304
+
305
+ def test_from_yaml_missing_vertical_coordinate():
306
+ yaml_content = textwrap.dedent(
307
+ """\
308
+ ---
309
+ roms_tools_version: 0.0.0
310
+ ---
311
+ Grid:
312
+ nx: 100
313
+ ny: 100
314
+ size_x: 1800
315
+ size_y: 2400
316
+ center_lon: -10
317
+ center_lat: 61
318
+ rot: -20
319
+ topography_source: ETOPO5
320
+ smooth_factor: 8
321
+ hmin: 5.0
322
+ rmax: 0.2
323
+ """
324
+ )
325
+
326
+ with tempfile.NamedTemporaryFile(delete=False) as tmp_file:
327
+ yaml_filepath = tmp_file.name
328
+ tmp_file.write(yaml_content.encode())
329
+
330
+ try:
331
+ with pytest.raises(
332
+ ValueError,
333
+ match="No VerticalCoordinate configuration found in the YAML file.",
334
+ ):
335
+ VerticalCoordinate.from_yaml(yaml_filepath)
336
+ finally:
337
+ os.remove(yaml_filepath)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: roms-tools
3
- Version: 0.1.0
3
+ Version: 1.0.0
4
4
  Summary: Tools for running and analysing UCLA-ROMS simulations
5
5
  Author-email: Nora Loose <nora.loose@gmail.com>, Thomas Nicholas <tom@cworthy.org>
6
6
  License: Apache-2
@@ -18,7 +18,8 @@ Classifier: Programming Language :: Python :: 3.12
18
18
  Requires-Python: >=3.10
19
19
  Description-Content-Type: text/markdown
20
20
  License-File: LICENSE
21
- Requires-Dist: xarray >=2022.6.0
21
+ Requires-Dist: xarray>=2022.6.0
22
+ Requires-Dist: xarray-datatree
22
23
  Requires-Dist: numpy
23
24
  Requires-Dist: netcdf4
24
25
  Requires-Dist: pooch
@@ -31,8 +32,12 @@ Requires-Dist: numba
31
32
 
32
33
  # ROMS-Tools
33
34
 
34
- [![Documentation Status](https://readthedocs.org/projects/roms-tools/badge/?version=latest)](https://roms-tools.readthedocs.io/en/latest/?badge=latest)
35
35
  [![PyPI version](https://badge.fury.io/py/roms-tools.svg)](https://badge.fury.io/py/roms-tools)
36
+ [![codecov](https://codecov.io/gh/CWorthy-ocean/roms-tools/graph/badge.svg?token=5S1oNu39xE)](https://codecov.io/gh/CWorthy-ocean/roms-tools)
37
+ [![Documentation Status](https://readthedocs.org/projects/roms-tools/badge/?version=latest)](https://roms-tools.readthedocs.io/en/latest/?badge=latest)
38
+ ![Run Tests](https://github.com/CWorthy-ocean/roms-tools/actions/workflows/tests.yaml/badge.svg)
39
+ ![Supported Python Versions](https://img.shields.io/pypi/pyversions/roms-tools)
40
+
36
41
 
37
42
  ## Overview
38
43
 
@@ -59,7 +64,7 @@ pip install -e .
59
64
 
60
65
  ### Run the tests
61
66
 
62
- Before running the tests you can install and activate the following conda environment:
67
+ Before running the tests, you can install and activate the following conda environment:
63
68
 
64
69
  ```bash
65
70
  cd roms-tools
@@ -0,0 +1,31 @@
1
+ ci/environment.yml,sha256=tjoIEUdPWfJBO4ijsJYhq7ay8_QfJKxRtq8Z0r8rHTI,427
2
+ roms_tools/__init__.py,sha256=v0fXc7jON8jbXD1zIxuC5dEqIa30PkMzTVe0bLGMrhY,642
3
+ roms_tools/_version.py,sha256=TDFyBsBYj5dQ4UQBcf-o9xaD5eD4cemY65tpAOJYk5Y,72
4
+ roms_tools/setup/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
+ roms_tools/setup/boundary_forcing.py,sha256=ulif6YOZX-RzoJ-HotNlWSb3z3g-7E2qIR_mzv-F8Q4,33179
6
+ roms_tools/setup/datasets.py,sha256=3PJ0JCQUcNVHd4Xl7dodJ6lZJmV5cRkCxH-vOuZtrZ4,41478
7
+ roms_tools/setup/download.py,sha256=SapK5GIx-ykBrqqj0S_dgMxBBDGVKTfgIdbaiiOohhY,4280
8
+ roms_tools/setup/fill.py,sha256=45Ro5oN-n-n_qKZq3qTHn27ZKpTKWhr_9AWw6gUJ-9I,13291
9
+ roms_tools/setup/grid.py,sha256=V3vVOrkmlHM4CfhIGGlGTCw2OvZ62MGnrUHJepDylsA,30848
10
+ roms_tools/setup/initial_conditions.py,sha256=CzoGLzQiJKRw2V_HChX3XACJU-2uEVD279H_b2PvfIw,21588
11
+ roms_tools/setup/mixins.py,sha256=EDaIbRCPVE2aJkGekh99sAeiSmyl-SUMfiTaCcHGVyg,16808
12
+ roms_tools/setup/plot.py,sha256=vpOoAHE5HvnmeAPyhr-GijGLLlqkEple5hfr_f3Nfn8,6331
13
+ roms_tools/setup/surface_forcing.py,sha256=fZGn93qzPgCJNKPUSjZH3rIfVL2nqXr4OJ7YtR5Tzro,22143
14
+ roms_tools/setup/tides.py,sha256=PP-R4mqMI_RpVOAg0hH3dAAaUjB6C3rSR_JyvJ1zODw,22907
15
+ roms_tools/setup/topography.py,sha256=yNJn9KW9m7UB6nxh5bUQzllt6z22AQahUwWIIUwHz_Y,8557
16
+ roms_tools/setup/utils.py,sha256=6_rNPWSP1Q5PjRlMAKS3GunBWySzPcnj6xYAFaFbqfY,12678
17
+ roms_tools/setup/vertical_coordinate.py,sha256=IqZN3vDW4DyeaQSr-Di5O8qH2cLJE__XKmf4lROgF8s,16122
18
+ roms_tools/tests/test_boundary_forcing.py,sha256=wLhX9UOZ6cfR-c3gw7bvM6ttwMCH8LpZlqXlLrQsvWM,24438
19
+ roms_tools/tests/test_datasets.py,sha256=RPpnKa4kUrXgCUCc3ca7SdHnFs7qQmOwQYQnPEN6T_g,11743
20
+ roms_tools/tests/test_grid.py,sha256=Dhci5NXOQsASM9mdNCmqyxVXcSasjjlNvcYxKZoah6E,5587
21
+ roms_tools/tests/test_initial_conditions.py,sha256=xY-QkpGUEMeO1R076Ww0bSa3p8-qtTLVl1bTFUrv7kw,16701
22
+ roms_tools/tests/test_surface_forcing.py,sha256=CBLOOuA0LxLQwyedbN0idtnl2wVjT5mDq4nR5LH1DxA,78007
23
+ roms_tools/tests/test_tides.py,sha256=wcH8WAvzb-FqJmr_VLTwldV8XalyntZANhy-FRMQ7e4,11133
24
+ roms_tools/tests/test_topography.py,sha256=Nwzor5ciOZfV7Y7fDazE1JH1qxotmJilOpZUcHxAypI,1945
25
+ roms_tools/tests/test_utils.py,sha256=Ey5jrsdd7B9kL5ijqr9CLQNguPlxVMTybIneihdefN8,560
26
+ roms_tools/tests/test_vertical_coordinate.py,sha256=GshM5l1e9bl4RT0HATQJg9YJ9asGK4beqIKbZxr9j7U,10843
27
+ roms_tools-1.0.0.dist-info/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
28
+ roms_tools-1.0.0.dist-info/METADATA,sha256=gi-rdZeU47LyWqXw-Xn_KrYpteCjYqVlmQz9lNLccAA,2918
29
+ roms_tools-1.0.0.dist-info/WHEEL,sha256=nCVcAvsfA9TDtwGwhYaRrlPhTLV9m-Ga6mdyDtuwK18,91
30
+ roms_tools-1.0.0.dist-info/top_level.txt,sha256=aAf4T4nYQSkay5iKJ9kmTjlDgd4ETdp9OSlB4sJdt8Y,19
31
+ roms_tools-1.0.0.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (70.3.0)
2
+ Generator: setuptools (73.0.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5