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.
- ci/environment.yml +2 -0
- roms_tools/__init__.py +4 -2
- roms_tools/_version.py +1 -1
- roms_tools/setup/boundary_forcing.py +757 -0
- roms_tools/setup/datasets.py +1141 -35
- roms_tools/setup/download.py +118 -0
- roms_tools/setup/fill.py +118 -5
- roms_tools/setup/grid.py +145 -19
- roms_tools/setup/initial_conditions.py +557 -0
- roms_tools/setup/mixins.py +395 -0
- roms_tools/setup/plot.py +149 -4
- roms_tools/setup/surface_forcing.py +596 -0
- roms_tools/setup/tides.py +472 -437
- roms_tools/setup/topography.py +18 -3
- roms_tools/setup/utils.py +352 -0
- roms_tools/setup/vertical_coordinate.py +494 -0
- roms_tools/tests/test_boundary_forcing.py +706 -0
- roms_tools/tests/test_datasets.py +370 -0
- roms_tools/tests/test_grid.py +226 -0
- roms_tools/tests/test_initial_conditions.py +520 -0
- roms_tools/tests/test_surface_forcing.py +2622 -0
- roms_tools/tests/test_tides.py +365 -0
- roms_tools/tests/test_topography.py +78 -0
- roms_tools/tests/test_utils.py +16 -0
- roms_tools/tests/test_vertical_coordinate.py +337 -0
- {roms_tools-0.1.0.dist-info → roms_tools-1.0.0.dist-info}/METADATA +9 -4
- roms_tools-1.0.0.dist-info/RECORD +31 -0
- {roms_tools-0.1.0.dist-info → roms_tools-1.0.0.dist-info}/WHEEL +1 -1
- roms_tools/setup/atmospheric_forcing.py +0 -993
- roms_tools/tests/test_setup.py +0 -181
- roms_tools-0.1.0.dist-info/RECORD +0 -17
- {roms_tools-0.1.0.dist-info → roms_tools-1.0.0.dist-info}/LICENSE +0 -0
- {roms_tools-0.1.0.dist-info → roms_tools-1.0.0.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,706 @@
|
|
|
1
|
+
import pytest
|
|
2
|
+
from datetime import datetime
|
|
3
|
+
from roms_tools import BoundaryForcing, Grid, VerticalCoordinate
|
|
4
|
+
import numpy as np
|
|
5
|
+
import tempfile
|
|
6
|
+
import os
|
|
7
|
+
import textwrap
|
|
8
|
+
from roms_tools.setup.download import download_test_data
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
@pytest.fixture
|
|
12
|
+
def example_grid():
|
|
13
|
+
"""
|
|
14
|
+
Fixture for creating a Grid object.
|
|
15
|
+
"""
|
|
16
|
+
grid = Grid(
|
|
17
|
+
nx=2, ny=2, size_x=500, size_y=1000, center_lon=0, center_lat=55, rot=10
|
|
18
|
+
)
|
|
19
|
+
|
|
20
|
+
return grid
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
@pytest.fixture
|
|
24
|
+
def example_vertical_coordinate(example_grid):
|
|
25
|
+
"""
|
|
26
|
+
Fixture for creating a VerticalCoordinate object.
|
|
27
|
+
"""
|
|
28
|
+
vertical_coordinate = VerticalCoordinate(
|
|
29
|
+
grid=example_grid,
|
|
30
|
+
N=3, # number of vertical levels
|
|
31
|
+
theta_s=5.0, # surface control parameter
|
|
32
|
+
theta_b=2.0, # bottom control parameter
|
|
33
|
+
hc=250.0, # critical depth
|
|
34
|
+
)
|
|
35
|
+
|
|
36
|
+
return vertical_coordinate
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
@pytest.fixture
|
|
40
|
+
def boundary_forcing(example_grid, example_vertical_coordinate):
|
|
41
|
+
"""
|
|
42
|
+
Fixture for creating a BoundaryForcing object.
|
|
43
|
+
"""
|
|
44
|
+
|
|
45
|
+
fname = download_test_data("GLORYS_test_data.nc")
|
|
46
|
+
|
|
47
|
+
return BoundaryForcing(
|
|
48
|
+
grid=example_grid,
|
|
49
|
+
vertical_coordinate=example_vertical_coordinate,
|
|
50
|
+
start_time=datetime(2021, 6, 29),
|
|
51
|
+
end_time=datetime(2021, 6, 30),
|
|
52
|
+
physics_source={"name": "GLORYS", "path": fname},
|
|
53
|
+
)
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
@pytest.fixture
|
|
57
|
+
def boundary_forcing_with_bgc_from_climatology(
|
|
58
|
+
example_grid, example_vertical_coordinate
|
|
59
|
+
):
|
|
60
|
+
"""
|
|
61
|
+
Fixture for creating a BoundaryForcing object.
|
|
62
|
+
"""
|
|
63
|
+
|
|
64
|
+
fname = download_test_data("GLORYS_test_data.nc")
|
|
65
|
+
fname_bgc = download_test_data("CESM_regional_test_data_climatology.nc")
|
|
66
|
+
|
|
67
|
+
return BoundaryForcing(
|
|
68
|
+
grid=example_grid,
|
|
69
|
+
vertical_coordinate=example_vertical_coordinate,
|
|
70
|
+
start_time=datetime(2021, 6, 29),
|
|
71
|
+
end_time=datetime(2021, 6, 30),
|
|
72
|
+
physics_source={"name": "GLORYS", "path": fname},
|
|
73
|
+
bgc_source={"path": fname_bgc, "name": "CESM_REGRIDDED", "climatology": True},
|
|
74
|
+
)
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
@pytest.mark.parametrize(
|
|
78
|
+
"bdry_forcing_fixture",
|
|
79
|
+
[
|
|
80
|
+
"boundary_forcing",
|
|
81
|
+
"boundary_forcing_with_bgc_from_climatology",
|
|
82
|
+
],
|
|
83
|
+
)
|
|
84
|
+
def test_boundary_forcing_creation(bdry_forcing_fixture, request):
|
|
85
|
+
"""
|
|
86
|
+
Test the creation of the BoundaryForcing object.
|
|
87
|
+
"""
|
|
88
|
+
|
|
89
|
+
bdry_forcing = request.getfixturevalue(bdry_forcing_fixture)
|
|
90
|
+
|
|
91
|
+
assert bdry_forcing.start_time == datetime(2021, 6, 29)
|
|
92
|
+
assert bdry_forcing.end_time == datetime(2021, 6, 30)
|
|
93
|
+
|
|
94
|
+
assert bdry_forcing.ds["physics"].physics_source == "GLORYS"
|
|
95
|
+
for direction in ["south", "east", "north", "west"]:
|
|
96
|
+
assert f"temp_{direction}" in bdry_forcing.ds["physics"]
|
|
97
|
+
assert f"salt_{direction}" in bdry_forcing.ds["physics"]
|
|
98
|
+
assert f"u_{direction}" in bdry_forcing.ds["physics"]
|
|
99
|
+
assert f"v_{direction}" in bdry_forcing.ds["physics"]
|
|
100
|
+
assert f"zeta_{direction}" in bdry_forcing.ds["physics"]
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
def test_boundary_forcing_creation_with_bgc(boundary_forcing_with_bgc_from_climatology):
|
|
104
|
+
"""
|
|
105
|
+
Test the creation of the BoundaryForcing object.
|
|
106
|
+
"""
|
|
107
|
+
|
|
108
|
+
assert (
|
|
109
|
+
boundary_forcing_with_bgc_from_climatology.ds["bgc"].bgc_source
|
|
110
|
+
== "CESM_REGRIDDED"
|
|
111
|
+
)
|
|
112
|
+
for direction in ["south", "east", "north", "west"]:
|
|
113
|
+
for var in ["ALK", "PO4"]:
|
|
114
|
+
assert (
|
|
115
|
+
f"{var}_{direction}"
|
|
116
|
+
in boundary_forcing_with_bgc_from_climatology.ds["bgc"]
|
|
117
|
+
)
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
def test_boundary_forcing_data_consistency_plot_save(
|
|
121
|
+
boundary_forcing_with_bgc_from_climatology,
|
|
122
|
+
):
|
|
123
|
+
"""
|
|
124
|
+
Test that the data within the BoundaryForcing object remains consistent.
|
|
125
|
+
Also test plot and save methods in the same test since we dask arrays are already computed.
|
|
126
|
+
"""
|
|
127
|
+
# Define the expected data
|
|
128
|
+
expected_zeta_south = np.array(
|
|
129
|
+
[[-0.30468762, -0.29416865, -0.30391693, -0.32985148]], dtype=np.float32
|
|
130
|
+
)
|
|
131
|
+
expected_zeta_east = np.array(
|
|
132
|
+
[[-0.32985148, -0.36176518, -0.40663475, -0.40699923]], dtype=np.float32
|
|
133
|
+
)
|
|
134
|
+
expected_zeta_north = np.array(
|
|
135
|
+
[[-0.5534979, -0.5270749, -0.45107934, -0.40699923]], dtype=np.float32
|
|
136
|
+
)
|
|
137
|
+
expected_zeta_west = np.array(
|
|
138
|
+
[[-0.30468762, -0.34336275, -0.3699948, -0.5534979]], dtype=np.float32
|
|
139
|
+
)
|
|
140
|
+
|
|
141
|
+
expected_temp_south = np.array(
|
|
142
|
+
[
|
|
143
|
+
[
|
|
144
|
+
[16.84414, 16.905312, 16.967817],
|
|
145
|
+
[18.088203, 18.121834, 18.315424],
|
|
146
|
+
[18.431192, 18.496748, 18.718002],
|
|
147
|
+
[19.294329, 19.30358, 19.439777],
|
|
148
|
+
]
|
|
149
|
+
],
|
|
150
|
+
dtype=np.float32,
|
|
151
|
+
)
|
|
152
|
+
expected_temp_east = np.array(
|
|
153
|
+
[
|
|
154
|
+
[
|
|
155
|
+
[19.294329, 19.30358, 19.439777],
|
|
156
|
+
[18.633307, 18.637077, 18.667465],
|
|
157
|
+
[8.710737, 11.25943, 13.111585],
|
|
158
|
+
[9.20282, 10.667074, 11.752404],
|
|
159
|
+
]
|
|
160
|
+
],
|
|
161
|
+
dtype=np.float32,
|
|
162
|
+
)
|
|
163
|
+
expected_temp_north = np.array(
|
|
164
|
+
[
|
|
165
|
+
[
|
|
166
|
+
[10.233599, 10.546486, 10.671082],
|
|
167
|
+
[10.147332, 10.502733, 10.68275],
|
|
168
|
+
[10.458557, 11.209945, 11.377164],
|
|
169
|
+
[9.20282, 10.667074, 11.752404],
|
|
170
|
+
]
|
|
171
|
+
],
|
|
172
|
+
dtype=np.float32,
|
|
173
|
+
)
|
|
174
|
+
expected_temp_west = np.array(
|
|
175
|
+
[
|
|
176
|
+
[
|
|
177
|
+
[16.84414, 16.905312, 16.967817],
|
|
178
|
+
[12.639833, 13.479691, 14.426711],
|
|
179
|
+
[11.027701, 11.650267, 12.200586],
|
|
180
|
+
[10.233599, 10.546486, 10.671082],
|
|
181
|
+
]
|
|
182
|
+
],
|
|
183
|
+
dtype=np.float32,
|
|
184
|
+
)
|
|
185
|
+
|
|
186
|
+
expected_u_south = np.array(
|
|
187
|
+
[[[-0.0, -0.0, -0.0], [-0.0, -0.0, -0.0], [0.0, -0.0, -0.0]]], dtype=np.float32
|
|
188
|
+
)
|
|
189
|
+
expected_u_east = np.array(
|
|
190
|
+
[
|
|
191
|
+
[
|
|
192
|
+
[0.0, -0.0, -0.0],
|
|
193
|
+
[-0.0, -0.0, -0.0],
|
|
194
|
+
[0.06979556, 0.06167743, -0.02247071],
|
|
195
|
+
[0.0211786, 0.03679834, 0.0274788],
|
|
196
|
+
]
|
|
197
|
+
],
|
|
198
|
+
dtype=np.float32,
|
|
199
|
+
)
|
|
200
|
+
expected_u_north = np.array(
|
|
201
|
+
[
|
|
202
|
+
[
|
|
203
|
+
[0.04268532, 0.03889201, 0.03351666],
|
|
204
|
+
[0.04645353, 0.04914769, 0.03673013],
|
|
205
|
+
[0.0211786, 0.03679834, 0.0274788],
|
|
206
|
+
]
|
|
207
|
+
],
|
|
208
|
+
dtype=np.float32,
|
|
209
|
+
)
|
|
210
|
+
expected_u_west = np.array(
|
|
211
|
+
[
|
|
212
|
+
[
|
|
213
|
+
[-0.0, -0.0, -0.0],
|
|
214
|
+
[0.0, -0.0, -0.0],
|
|
215
|
+
[0.0, 0.0, -0.0],
|
|
216
|
+
[0.04268532, 0.03889201, 0.03351666],
|
|
217
|
+
]
|
|
218
|
+
],
|
|
219
|
+
dtype=np.float32,
|
|
220
|
+
)
|
|
221
|
+
|
|
222
|
+
expected_v_south = np.array(
|
|
223
|
+
[[[0.0, 0.0, 0.0], [0.0, 0.0, -0.0], [-0.0, -0.0, -0.0], [-0.0, -0.0, -0.0]]],
|
|
224
|
+
dtype=np.float32,
|
|
225
|
+
)
|
|
226
|
+
expected_v_east = np.array(
|
|
227
|
+
[
|
|
228
|
+
[
|
|
229
|
+
[-0.0, -0.0, -0.0],
|
|
230
|
+
[-0.0, -0.0, -0.0],
|
|
231
|
+
[-0.06720348, -0.08354441, -0.13835917],
|
|
232
|
+
]
|
|
233
|
+
],
|
|
234
|
+
dtype=np.float32,
|
|
235
|
+
)
|
|
236
|
+
expected_v_north = np.array(
|
|
237
|
+
[
|
|
238
|
+
[
|
|
239
|
+
[-0.00951457, -0.00576979, -0.02147919],
|
|
240
|
+
[-0.0, -0.0, -0.0],
|
|
241
|
+
[0.01915873, 0.02625698, 0.01757628],
|
|
242
|
+
[-0.06720348, -0.08354441, -0.13835917],
|
|
243
|
+
]
|
|
244
|
+
],
|
|
245
|
+
dtype=np.float32,
|
|
246
|
+
)
|
|
247
|
+
expected_v_west = np.array(
|
|
248
|
+
[
|
|
249
|
+
[
|
|
250
|
+
[0.0, 0.0, 0.0],
|
|
251
|
+
[-0.0, -0.0, -0.0],
|
|
252
|
+
[-0.00951457, -0.00576979, -0.02147919],
|
|
253
|
+
]
|
|
254
|
+
],
|
|
255
|
+
dtype=np.float32,
|
|
256
|
+
)
|
|
257
|
+
|
|
258
|
+
expected_ubar_south = np.array([[0.0, 0.0, 0.0]], dtype=np.float32)
|
|
259
|
+
expected_ubar_east = np.array(
|
|
260
|
+
[[0.0, 0.0, 0.04028399, 0.02812303]], dtype=np.float32
|
|
261
|
+
)
|
|
262
|
+
expected_ubar_north = np.array(
|
|
263
|
+
[[0.03866891, 0.04446249, 0.02812303]], dtype=np.float32
|
|
264
|
+
)
|
|
265
|
+
expected_ubar_west = np.array([[0.0, 0.0, 0.0, 0.03866891]], dtype=np.float32)
|
|
266
|
+
|
|
267
|
+
expected_vbar_south = np.array([[0.0, 0.0, 0.0, 0.0]], dtype=np.float32)
|
|
268
|
+
expected_vbar_east = np.array([[0.0, 0.0, -0.09326097]], dtype=np.float32)
|
|
269
|
+
expected_vbar_north = np.array(
|
|
270
|
+
[[-0.01189703, 0.0, 0.02102064, -0.09326097]], dtype=np.float32
|
|
271
|
+
)
|
|
272
|
+
expected_vbar_west = np.array([[0.0, 0.0, -0.01189703]], dtype=np.float32)
|
|
273
|
+
|
|
274
|
+
expected_alk_south = np.array(
|
|
275
|
+
[
|
|
276
|
+
[
|
|
277
|
+
[2352.1636, 2352.128, 2352.091],
|
|
278
|
+
[2333.1094, 2332.9932, 2332.8738],
|
|
279
|
+
[2308.618, 2308.4705, 2308.3032],
|
|
280
|
+
[2286.2327, 2286.0442, 2285.8623],
|
|
281
|
+
],
|
|
282
|
+
[
|
|
283
|
+
[2354.7297, 2354.6863, 2354.6414],
|
|
284
|
+
[2337.391, 2337.259, 2337.1223],
|
|
285
|
+
[2314.0232, 2313.8638, 2313.6616],
|
|
286
|
+
[2294.0876, 2293.8918, 2293.6626],
|
|
287
|
+
],
|
|
288
|
+
[
|
|
289
|
+
[2355.02, 2354.9158, 2354.817],
|
|
290
|
+
[2336.321, 2336.117, 2335.9214],
|
|
291
|
+
[2312.7905, 2312.4849, 2312.2444],
|
|
292
|
+
[2292.2637, 2291.8752, 2291.6702],
|
|
293
|
+
],
|
|
294
|
+
[
|
|
295
|
+
[2355.2583, 2355.052, 2354.9163],
|
|
296
|
+
[2334.3098, 2333.913, 2333.651],
|
|
297
|
+
[2309.5273, 2308.292, 2307.8772],
|
|
298
|
+
[2287.4226, 2285.5466, 2285.0479],
|
|
299
|
+
],
|
|
300
|
+
[
|
|
301
|
+
[2354.1216, 2353.7737, 2353.6316],
|
|
302
|
+
[2330.6604, 2329.948, 2329.6023],
|
|
303
|
+
[2304.88, 2302.105, 2301.4136],
|
|
304
|
+
[2280.6, 2276.278, 2275.2761],
|
|
305
|
+
],
|
|
306
|
+
[
|
|
307
|
+
[2346.881, 2345.7993, 2345.4675],
|
|
308
|
+
[2322.218, 2320.3225, 2319.691],
|
|
309
|
+
[2301.2046, 2291.6438, 2290.308],
|
|
310
|
+
[2279.729, 2265.0488, 2263.0654],
|
|
311
|
+
],
|
|
312
|
+
[
|
|
313
|
+
[2336.2632, 2335.273, 2334.9324],
|
|
314
|
+
[2312.938, 2310.7412, 2310.055],
|
|
315
|
+
[2293.6711, 2279.314, 2277.593],
|
|
316
|
+
[2272.6418, 2250.8848, 2248.0718],
|
|
317
|
+
],
|
|
318
|
+
[
|
|
319
|
+
[2333.8801, 2333.265, 2333.0667],
|
|
320
|
+
[2311.3232, 2309.5337, 2309.034],
|
|
321
|
+
[2289.1548, 2276.1438, 2274.885],
|
|
322
|
+
[2266.9172, 2246.1714, 2244.1096],
|
|
323
|
+
],
|
|
324
|
+
[
|
|
325
|
+
[2336.8193, 2336.5115, 2336.4402],
|
|
326
|
+
[2314.2544, 2313.1343, 2312.9004],
|
|
327
|
+
[2288.887, 2280.0654, 2279.546],
|
|
328
|
+
[2263.7944, 2249.8926, 2249.0842],
|
|
329
|
+
],
|
|
330
|
+
[
|
|
331
|
+
[2341.18, 2341.0679, 2341.025],
|
|
332
|
+
[2317.8801, 2317.4556, 2317.3325],
|
|
333
|
+
[2289.4714, 2286.2214, 2285.9263],
|
|
334
|
+
[2262.6213, 2257.4502, 2256.9663],
|
|
335
|
+
],
|
|
336
|
+
[
|
|
337
|
+
[2344.9026, 2344.86, 2344.8218],
|
|
338
|
+
[2323.6404, 2323.5337, 2323.442],
|
|
339
|
+
[2297.1284, 2296.8164, 2296.6846],
|
|
340
|
+
[2273.7996, 2273.2507, 2273.0938],
|
|
341
|
+
],
|
|
342
|
+
[
|
|
343
|
+
[2349.1636, 2349.1338, 2349.1035],
|
|
344
|
+
[2329.3665, 2329.2893, 2329.2102],
|
|
345
|
+
[2304.1536, 2304.0178, 2303.9006],
|
|
346
|
+
[2281.6301, 2281.4062, 2281.269],
|
|
347
|
+
],
|
|
348
|
+
],
|
|
349
|
+
dtype=np.float32,
|
|
350
|
+
)
|
|
351
|
+
|
|
352
|
+
expected_alk_east = np.array(
|
|
353
|
+
[
|
|
354
|
+
[
|
|
355
|
+
[2286.2327, 2286.0442, 2285.8623],
|
|
356
|
+
[2268.2373, 2268.162, 2268.0366],
|
|
357
|
+
[2297.2825, 2296.5747, 2296.2695],
|
|
358
|
+
[2349.247, 2349.1697, 2349.0938],
|
|
359
|
+
],
|
|
360
|
+
[
|
|
361
|
+
[2294.0876, 2293.8918, 2293.6626],
|
|
362
|
+
[2272.6245, 2272.5269, 2272.3384],
|
|
363
|
+
[2301.072, 2300.6504, 2300.4255],
|
|
364
|
+
[2352.814, 2352.756, 2352.6907],
|
|
365
|
+
],
|
|
366
|
+
[
|
|
367
|
+
[2292.2637, 2291.8752, 2291.6702],
|
|
368
|
+
[2272.901, 2272.7153, 2272.5413],
|
|
369
|
+
[2304.492, 2303.8516, 2303.6313],
|
|
370
|
+
[2352.8616, 2352.795, 2352.7444],
|
|
371
|
+
],
|
|
372
|
+
[
|
|
373
|
+
[2287.4226, 2285.5466, 2285.0479],
|
|
374
|
+
[2269.8926, 2269.2112, 2268.8284],
|
|
375
|
+
[2310.2466, 2307.2576, 2306.0806],
|
|
376
|
+
[2350.9084, 2350.3499, 2350.0247],
|
|
377
|
+
],
|
|
378
|
+
[
|
|
379
|
+
[2280.6, 2276.278, 2275.2761],
|
|
380
|
+
[2266.4937, 2264.7148, 2263.8596],
|
|
381
|
+
[2309.5537, 2297.2288, 2293.6697],
|
|
382
|
+
[2350.1707, 2348.5422, 2347.7415],
|
|
383
|
+
],
|
|
384
|
+
[
|
|
385
|
+
[2279.729, 2265.0488, 2263.0654],
|
|
386
|
+
[2263.0278, 2254.806, 2253.1594],
|
|
387
|
+
[2311.0305, 2290.098, 2284.9631],
|
|
388
|
+
[2350.3872, 2345.0693, 2342.4902],
|
|
389
|
+
],
|
|
390
|
+
[
|
|
391
|
+
[2272.6418, 2250.8848, 2248.0718],
|
|
392
|
+
[2256.4866, 2239.6753, 2237.9412],
|
|
393
|
+
[2309.7383, 2284.9133, 2277.729],
|
|
394
|
+
[2349.7207, 2339.6501, 2335.4924],
|
|
395
|
+
],
|
|
396
|
+
[
|
|
397
|
+
[2266.9172, 2246.1714, 2244.1096],
|
|
398
|
+
[2249.1013, 2234.224, 2232.722],
|
|
399
|
+
[2307.639, 2275.4429, 2266.299],
|
|
400
|
+
[2347.7605, 2330.1702, 2325.427],
|
|
401
|
+
],
|
|
402
|
+
[
|
|
403
|
+
[2263.7944, 2249.8926, 2249.0842],
|
|
404
|
+
[2246.2002, 2236.0933, 2235.4578],
|
|
405
|
+
[2301.0461, 2269.4448, 2263.889],
|
|
406
|
+
[2338.5127, 2321.7393, 2316.971],
|
|
407
|
+
],
|
|
408
|
+
[
|
|
409
|
+
[2262.6213, 2257.4502, 2256.9663],
|
|
410
|
+
[2244.3662, 2241.8052, 2241.589],
|
|
411
|
+
[2292.1316, 2274.763, 2272.2124],
|
|
412
|
+
[2331.162, 2322.5522, 2320.8901],
|
|
413
|
+
],
|
|
414
|
+
[
|
|
415
|
+
[2273.7996, 2273.2507, 2273.0938],
|
|
416
|
+
[2254.6848, 2254.4407, 2254.3308],
|
|
417
|
+
[2290.5637, 2286.885, 2286.088],
|
|
418
|
+
[2333.583, 2332.7646, 2332.3955],
|
|
419
|
+
],
|
|
420
|
+
[
|
|
421
|
+
[2281.6301, 2281.4062, 2281.269],
|
|
422
|
+
[2262.4211, 2262.3313, 2262.2532],
|
|
423
|
+
[2296.095, 2293.6157, 2293.1213],
|
|
424
|
+
[2340.852, 2340.6072, 2340.4978],
|
|
425
|
+
],
|
|
426
|
+
],
|
|
427
|
+
dtype=np.float32,
|
|
428
|
+
)
|
|
429
|
+
|
|
430
|
+
expected_alk_north = np.array(
|
|
431
|
+
[
|
|
432
|
+
[
|
|
433
|
+
[2376.7993, 2376.7961, 2376.7932],
|
|
434
|
+
[2375.0688, 2375.0647, 2375.0596],
|
|
435
|
+
[2372.2307, 2372.2188, 2372.201],
|
|
436
|
+
[2349.247, 2349.1697, 2349.0938],
|
|
437
|
+
],
|
|
438
|
+
[
|
|
439
|
+
[2376.757, 2376.7537, 2376.7478],
|
|
440
|
+
[2374.8325, 2374.8286, 2374.825],
|
|
441
|
+
[2371.8342, 2371.8257, 2371.814],
|
|
442
|
+
[2352.814, 2352.756, 2352.6907],
|
|
443
|
+
],
|
|
444
|
+
[
|
|
445
|
+
[2377.0188, 2377.0137, 2377.0073],
|
|
446
|
+
[2374.9753, 2374.9707, 2374.9666],
|
|
447
|
+
[2371.7104, 2371.7085, 2371.707],
|
|
448
|
+
[2352.8616, 2352.795, 2352.7444],
|
|
449
|
+
],
|
|
450
|
+
[
|
|
451
|
+
[2377.3914, 2377.383, 2377.3792],
|
|
452
|
+
[2375.5757, 2375.5718, 2375.57],
|
|
453
|
+
[2371.869, 2371.8706, 2371.8743],
|
|
454
|
+
[2350.9084, 2350.3499, 2350.0247],
|
|
455
|
+
],
|
|
456
|
+
[
|
|
457
|
+
[2378.4722, 2378.5, 2378.5017],
|
|
458
|
+
[2377.151, 2377.2292, 2377.2666],
|
|
459
|
+
[2373.7805, 2373.9, 2374.0066],
|
|
460
|
+
[2350.1707, 2348.5422, 2347.7415],
|
|
461
|
+
],
|
|
462
|
+
[
|
|
463
|
+
[2381.3555, 2383.3838, 2383.9692],
|
|
464
|
+
[2380.8108, 2382.6125, 2383.3374],
|
|
465
|
+
[2378.7131, 2379.7717, 2380.4094],
|
|
466
|
+
[2350.3872, 2345.0693, 2342.4902],
|
|
467
|
+
],
|
|
468
|
+
[
|
|
469
|
+
[2388.7502, 2389.4453, 2389.6758],
|
|
470
|
+
[2387.0815, 2388.0613, 2388.3323],
|
|
471
|
+
[2381.9631, 2383.4429, 2383.521],
|
|
472
|
+
[2349.7207, 2339.6501, 2335.4924],
|
|
473
|
+
],
|
|
474
|
+
[
|
|
475
|
+
[2386.29, 2385.9524, 2385.863],
|
|
476
|
+
[2383.9194, 2383.5654, 2383.4429],
|
|
477
|
+
[2380.237, 2377.2883, 2376.6057],
|
|
478
|
+
[2347.7605, 2330.1702, 2325.427],
|
|
479
|
+
],
|
|
480
|
+
[
|
|
481
|
+
[2375.1409, 2373.7124, 2373.2695],
|
|
482
|
+
[2370.7205, 2368.2014, 2367.7415],
|
|
483
|
+
[2371.8071, 2365.7, 2365.1226],
|
|
484
|
+
[2338.5127, 2321.7393, 2316.971],
|
|
485
|
+
],
|
|
486
|
+
[
|
|
487
|
+
[2371.951, 2371.8308, 2371.786],
|
|
488
|
+
[2365.2358, 2364.598, 2364.4639],
|
|
489
|
+
[2365.8464, 2362.7102, 2362.5464],
|
|
490
|
+
[2331.162, 2322.5522, 2320.8901],
|
|
491
|
+
],
|
|
492
|
+
[
|
|
493
|
+
[2373.2239, 2373.2004, 2373.1711],
|
|
494
|
+
[2370.007, 2369.9714, 2369.9507],
|
|
495
|
+
[2367.3286, 2367.2654, 2367.2217],
|
|
496
|
+
[2333.583, 2332.7646, 2332.3955],
|
|
497
|
+
],
|
|
498
|
+
[
|
|
499
|
+
[2374.99, 2374.9817, 2374.9717],
|
|
500
|
+
[2373.9058, 2373.8901, 2373.8748],
|
|
501
|
+
[2370.9688, 2370.9421, 2370.907],
|
|
502
|
+
[2340.852, 2340.6072, 2340.4978],
|
|
503
|
+
],
|
|
504
|
+
],
|
|
505
|
+
dtype=np.float32,
|
|
506
|
+
)
|
|
507
|
+
|
|
508
|
+
expected_alk_west = np.array(
|
|
509
|
+
[
|
|
510
|
+
[
|
|
511
|
+
[2352.1636, 2352.128, 2352.091],
|
|
512
|
+
[2335.311, 2335.1162, 2334.924],
|
|
513
|
+
[2362.5132, 2362.5088, 2362.4663],
|
|
514
|
+
[2376.7993, 2376.7961, 2376.7932],
|
|
515
|
+
],
|
|
516
|
+
[
|
|
517
|
+
[2354.7297, 2354.6863, 2354.6414],
|
|
518
|
+
[2335.165, 2334.9695, 2334.78],
|
|
519
|
+
[2363.018, 2363.0068, 2362.965],
|
|
520
|
+
[2376.757, 2376.7537, 2376.7478],
|
|
521
|
+
],
|
|
522
|
+
[
|
|
523
|
+
[2355.02, 2354.9158, 2354.817],
|
|
524
|
+
[2334.8015, 2334.5276, 2334.272],
|
|
525
|
+
[2365.7913, 2365.8025, 2365.7432],
|
|
526
|
+
[2377.0188, 2377.0137, 2377.0073],
|
|
527
|
+
],
|
|
528
|
+
[
|
|
529
|
+
[2355.2583, 2355.052, 2354.9163],
|
|
530
|
+
[2335.5789, 2335.267, 2335.0227],
|
|
531
|
+
[2370.7808, 2370.754, 2370.6836],
|
|
532
|
+
[2377.3914, 2377.383, 2377.3792],
|
|
533
|
+
],
|
|
534
|
+
[
|
|
535
|
+
[2354.1216, 2353.7737, 2353.6316],
|
|
536
|
+
[2335.7122, 2335.1372, 2334.8125],
|
|
537
|
+
[2375.5793, 2375.3132, 2375.1387],
|
|
538
|
+
[2378.4722, 2378.5, 2378.5017],
|
|
539
|
+
],
|
|
540
|
+
[
|
|
541
|
+
[2346.881, 2345.7993, 2345.4675],
|
|
542
|
+
[2332.2158, 2331.5295, 2331.2346],
|
|
543
|
+
[2378.4954, 2376.4001, 2375.9187],
|
|
544
|
+
[2381.3555, 2383.3838, 2383.9692],
|
|
545
|
+
],
|
|
546
|
+
[
|
|
547
|
+
[2336.2632, 2335.273, 2334.9324],
|
|
548
|
+
[2328.7188, 2327.8726, 2327.576],
|
|
549
|
+
[2374.763, 2370.0576, 2369.491],
|
|
550
|
+
[2388.7502, 2389.4453, 2389.6758],
|
|
551
|
+
],
|
|
552
|
+
[
|
|
553
|
+
[2333.8801, 2333.265, 2333.0667],
|
|
554
|
+
[2326.699, 2326.0037, 2325.771],
|
|
555
|
+
[2356.8801, 2352.0618, 2351.4526],
|
|
556
|
+
[2386.29, 2385.9524, 2385.863],
|
|
557
|
+
],
|
|
558
|
+
[
|
|
559
|
+
[2336.8193, 2336.5115, 2336.4402],
|
|
560
|
+
[2325.9893, 2325.512, 2325.2942],
|
|
561
|
+
[2346.735, 2344.9722, 2344.6653],
|
|
562
|
+
[2375.1409, 2373.7124, 2373.2695],
|
|
563
|
+
],
|
|
564
|
+
[
|
|
565
|
+
[2341.18, 2341.0679, 2341.025],
|
|
566
|
+
[2328.2231, 2327.9817, 2327.8281],
|
|
567
|
+
[2352.159, 2351.6226, 2351.4314],
|
|
568
|
+
[2371.951, 2371.8308, 2371.786],
|
|
569
|
+
],
|
|
570
|
+
[
|
|
571
|
+
[2344.9026, 2344.86, 2344.8218],
|
|
572
|
+
[2331.0703, 2330.9097, 2330.7537],
|
|
573
|
+
[2356.0095, 2355.9424, 2355.8538],
|
|
574
|
+
[2373.2239, 2373.2004, 2373.1711],
|
|
575
|
+
],
|
|
576
|
+
[
|
|
577
|
+
[2349.1636, 2349.1338, 2349.1035],
|
|
578
|
+
[2334.3328, 2334.043, 2333.749],
|
|
579
|
+
[2359.3823, 2359.3276, 2359.2634],
|
|
580
|
+
[2374.99, 2374.9817, 2374.9717],
|
|
581
|
+
],
|
|
582
|
+
],
|
|
583
|
+
dtype=np.float32,
|
|
584
|
+
)
|
|
585
|
+
|
|
586
|
+
ds = boundary_forcing_with_bgc_from_climatology.ds["physics"]
|
|
587
|
+
ds_bgc = boundary_forcing_with_bgc_from_climatology.ds["bgc"]
|
|
588
|
+
|
|
589
|
+
# Check the values in the dataset
|
|
590
|
+
assert np.allclose(ds["zeta_south"].values, expected_zeta_south)
|
|
591
|
+
assert np.allclose(ds["zeta_east"].values, expected_zeta_east)
|
|
592
|
+
assert np.allclose(ds["zeta_north"].values, expected_zeta_north)
|
|
593
|
+
assert np.allclose(ds["zeta_west"].values, expected_zeta_west)
|
|
594
|
+
assert np.allclose(ds["temp_south"].values, expected_temp_south)
|
|
595
|
+
assert np.allclose(ds["temp_east"].values, expected_temp_east)
|
|
596
|
+
assert np.allclose(ds["temp_north"].values, expected_temp_north)
|
|
597
|
+
assert np.allclose(ds["temp_west"].values, expected_temp_west)
|
|
598
|
+
assert np.allclose(ds["u_south"].values, expected_u_south)
|
|
599
|
+
assert np.allclose(ds["u_east"].values, expected_u_east)
|
|
600
|
+
assert np.allclose(ds["u_north"].values, expected_u_north)
|
|
601
|
+
assert np.allclose(ds["u_west"].values, expected_u_west)
|
|
602
|
+
assert np.allclose(ds["v_south"].values, expected_v_south)
|
|
603
|
+
assert np.allclose(ds["v_east"].values, expected_v_east)
|
|
604
|
+
assert np.allclose(ds["v_north"].values, expected_v_north)
|
|
605
|
+
assert np.allclose(ds["v_west"].values, expected_v_west)
|
|
606
|
+
assert np.allclose(ds["ubar_south"].values, expected_ubar_south)
|
|
607
|
+
assert np.allclose(ds["ubar_east"].values, expected_ubar_east)
|
|
608
|
+
assert np.allclose(ds["ubar_north"].values, expected_ubar_north)
|
|
609
|
+
assert np.allclose(ds["ubar_west"].values, expected_ubar_west)
|
|
610
|
+
assert np.allclose(ds["vbar_south"].values, expected_vbar_south)
|
|
611
|
+
assert np.allclose(ds["vbar_east"].values, expected_vbar_east)
|
|
612
|
+
assert np.allclose(ds["vbar_north"].values, expected_vbar_north)
|
|
613
|
+
assert np.allclose(ds["vbar_west"].values, expected_vbar_west)
|
|
614
|
+
assert np.allclose(ds_bgc["ALK_south"].values, expected_alk_south)
|
|
615
|
+
assert np.allclose(ds_bgc["ALK_east"].values, expected_alk_east)
|
|
616
|
+
assert np.allclose(ds_bgc["ALK_north"].values, expected_alk_north)
|
|
617
|
+
assert np.allclose(ds_bgc["ALK_west"].values, expected_alk_west)
|
|
618
|
+
|
|
619
|
+
boundary_forcing_with_bgc_from_climatology.plot(varname="temp_south")
|
|
620
|
+
boundary_forcing_with_bgc_from_climatology.plot(varname="temp_east")
|
|
621
|
+
boundary_forcing_with_bgc_from_climatology.plot(varname="temp_north")
|
|
622
|
+
boundary_forcing_with_bgc_from_climatology.plot(varname="temp_west")
|
|
623
|
+
boundary_forcing_with_bgc_from_climatology.plot(varname="zeta_south")
|
|
624
|
+
boundary_forcing_with_bgc_from_climatology.plot(varname="zeta_east")
|
|
625
|
+
boundary_forcing_with_bgc_from_climatology.plot(varname="zeta_north")
|
|
626
|
+
boundary_forcing_with_bgc_from_climatology.plot(varname="zeta_west")
|
|
627
|
+
boundary_forcing_with_bgc_from_climatology.plot(varname="ALK_south")
|
|
628
|
+
boundary_forcing_with_bgc_from_climatology.plot(varname="ALK_east")
|
|
629
|
+
boundary_forcing_with_bgc_from_climatology.plot(varname="ALK_north")
|
|
630
|
+
boundary_forcing_with_bgc_from_climatology.plot(varname="ALK_west")
|
|
631
|
+
|
|
632
|
+
# Create a temporary file
|
|
633
|
+
with tempfile.NamedTemporaryFile(delete=True) as tmpfile:
|
|
634
|
+
filepath = tmpfile.name
|
|
635
|
+
|
|
636
|
+
boundary_forcing_with_bgc_from_climatology.save(filepath)
|
|
637
|
+
physics_filepath = filepath + "_physics_20210629-29.nc"
|
|
638
|
+
bgc_filepath = filepath + "_bgc_clim.nc"
|
|
639
|
+
|
|
640
|
+
try:
|
|
641
|
+
assert os.path.exists(physics_filepath)
|
|
642
|
+
assert os.path.exists(bgc_filepath)
|
|
643
|
+
finally:
|
|
644
|
+
os.remove(physics_filepath)
|
|
645
|
+
os.remove(bgc_filepath)
|
|
646
|
+
|
|
647
|
+
|
|
648
|
+
@pytest.mark.parametrize(
|
|
649
|
+
"bdry_forcing_fixture",
|
|
650
|
+
[
|
|
651
|
+
"boundary_forcing",
|
|
652
|
+
"boundary_forcing_with_bgc_from_climatology",
|
|
653
|
+
],
|
|
654
|
+
)
|
|
655
|
+
def test_roundtrip_yaml(bdry_forcing_fixture, request):
|
|
656
|
+
"""Test that creating a BoundaryForcing object, saving its parameters to yaml file, and re-opening yaml file creates the same object."""
|
|
657
|
+
|
|
658
|
+
bdry_forcing = request.getfixturevalue(bdry_forcing_fixture)
|
|
659
|
+
|
|
660
|
+
# Create a temporary file
|
|
661
|
+
with tempfile.NamedTemporaryFile(delete=False) as tmpfile:
|
|
662
|
+
filepath = tmpfile.name
|
|
663
|
+
|
|
664
|
+
try:
|
|
665
|
+
bdry_forcing.to_yaml(filepath)
|
|
666
|
+
|
|
667
|
+
boundary_forcing_from_file = BoundaryForcing.from_yaml(filepath)
|
|
668
|
+
|
|
669
|
+
assert bdry_forcing == boundary_forcing_from_file
|
|
670
|
+
|
|
671
|
+
finally:
|
|
672
|
+
os.remove(filepath)
|
|
673
|
+
|
|
674
|
+
|
|
675
|
+
def test_from_yaml_missing_boundary_forcing():
|
|
676
|
+
yaml_content = textwrap.dedent(
|
|
677
|
+
"""\
|
|
678
|
+
---
|
|
679
|
+
roms_tools_version: 0.0.0
|
|
680
|
+
---
|
|
681
|
+
Grid:
|
|
682
|
+
nx: 100
|
|
683
|
+
ny: 100
|
|
684
|
+
size_x: 1800
|
|
685
|
+
size_y: 2400
|
|
686
|
+
center_lon: -10
|
|
687
|
+
center_lat: 61
|
|
688
|
+
rot: -20
|
|
689
|
+
topography_source: ETOPO5
|
|
690
|
+
smooth_factor: 8
|
|
691
|
+
hmin: 5.0
|
|
692
|
+
rmax: 0.2
|
|
693
|
+
"""
|
|
694
|
+
)
|
|
695
|
+
|
|
696
|
+
with tempfile.NamedTemporaryFile(delete=False) as tmp_file:
|
|
697
|
+
yaml_filepath = tmp_file.name
|
|
698
|
+
tmp_file.write(yaml_content.encode())
|
|
699
|
+
|
|
700
|
+
try:
|
|
701
|
+
with pytest.raises(
|
|
702
|
+
ValueError, match="No BoundaryForcing configuration found in the YAML file."
|
|
703
|
+
):
|
|
704
|
+
BoundaryForcing.from_yaml(yaml_filepath)
|
|
705
|
+
finally:
|
|
706
|
+
os.remove(yaml_filepath)
|