roms-tools 2.6.2__py3-none-any.whl → 2.7.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.
Files changed (51) hide show
  1. roms_tools/__init__.py +1 -0
  2. roms_tools/analysis/roms_output.py +11 -77
  3. roms_tools/analysis/utils.py +0 -66
  4. roms_tools/constants.py +2 -0
  5. roms_tools/download.py +46 -3
  6. roms_tools/plot.py +22 -5
  7. roms_tools/setup/cdr_forcing.py +1126 -0
  8. roms_tools/setup/datasets.py +742 -87
  9. roms_tools/setup/grid.py +42 -4
  10. roms_tools/setup/river_forcing.py +11 -84
  11. roms_tools/setup/tides.py +81 -411
  12. roms_tools/setup/utils.py +241 -37
  13. roms_tools/tests/test_setup/test_cdr_forcing.py +772 -0
  14. roms_tools/tests/test_setup/test_data/river_forcing_no_climatology.zarr/.zmetadata +53 -1
  15. roms_tools/tests/test_setup/test_data/river_forcing_no_climatology.zarr/river_tracer/.zattrs +1 -1
  16. roms_tools/tests/test_setup/test_data/river_forcing_no_climatology.zarr/tracer_long_name/.zarray +20 -0
  17. roms_tools/tests/test_setup/test_data/river_forcing_no_climatology.zarr/tracer_long_name/.zattrs +6 -0
  18. roms_tools/tests/test_setup/test_data/river_forcing_no_climatology.zarr/tracer_long_name/0 +0 -0
  19. roms_tools/tests/test_setup/test_data/river_forcing_no_climatology.zarr/tracer_unit/.zarray +20 -0
  20. roms_tools/tests/test_setup/test_data/river_forcing_no_climatology.zarr/tracer_unit/.zattrs +6 -0
  21. roms_tools/tests/test_setup/test_data/river_forcing_no_climatology.zarr/tracer_unit/0 +0 -0
  22. roms_tools/tests/test_setup/test_data/river_forcing_with_bgc.zarr/.zmetadata +53 -1
  23. roms_tools/tests/test_setup/test_data/river_forcing_with_bgc.zarr/river_tracer/.zattrs +1 -1
  24. roms_tools/tests/test_setup/test_data/river_forcing_with_bgc.zarr/tracer_long_name/.zarray +20 -0
  25. roms_tools/tests/test_setup/test_data/river_forcing_with_bgc.zarr/tracer_long_name/.zattrs +6 -0
  26. roms_tools/tests/test_setup/test_data/river_forcing_with_bgc.zarr/tracer_long_name/0 +0 -0
  27. roms_tools/tests/test_setup/test_data/river_forcing_with_bgc.zarr/tracer_unit/.zarray +20 -0
  28. roms_tools/tests/test_setup/test_data/river_forcing_with_bgc.zarr/tracer_unit/.zattrs +6 -0
  29. roms_tools/tests/test_setup/test_data/river_forcing_with_bgc.zarr/tracer_unit/0 +0 -0
  30. roms_tools/tests/test_setup/test_data/tidal_forcing.zarr/.zattrs +1 -2
  31. roms_tools/tests/test_setup/test_data/tidal_forcing.zarr/.zmetadata +27 -5
  32. roms_tools/tests/test_setup/test_data/tidal_forcing.zarr/ntides/.zarray +20 -0
  33. roms_tools/tests/test_setup/test_data/tidal_forcing.zarr/ntides/.zattrs +5 -0
  34. roms_tools/tests/test_setup/test_data/tidal_forcing.zarr/ntides/0 +0 -0
  35. roms_tools/tests/test_setup/test_data/tidal_forcing.zarr/omega/.zattrs +1 -3
  36. roms_tools/tests/test_setup/test_data/tidal_forcing.zarr/pot_Im/0.0.0 +0 -0
  37. roms_tools/tests/test_setup/test_data/tidal_forcing.zarr/pot_Re/0.0.0 +0 -0
  38. roms_tools/tests/test_setup/test_data/tidal_forcing.zarr/ssh_Im/0.0.0 +0 -0
  39. roms_tools/tests/test_setup/test_data/tidal_forcing.zarr/ssh_Re/0.0.0 +0 -0
  40. roms_tools/tests/test_setup/test_data/tidal_forcing.zarr/u_Im/0.0.0 +0 -0
  41. roms_tools/tests/test_setup/test_data/tidal_forcing.zarr/u_Re/0.0.0 +0 -0
  42. roms_tools/tests/test_setup/test_data/tidal_forcing.zarr/v_Im/0.0.0 +0 -0
  43. roms_tools/tests/test_setup/test_data/tidal_forcing.zarr/v_Re/0.0.0 +0 -0
  44. roms_tools/tests/test_setup/test_datasets.py +103 -1
  45. roms_tools/tests/test_setup/test_tides.py +112 -47
  46. roms_tools/utils.py +115 -1
  47. {roms_tools-2.6.2.dist-info → roms_tools-2.7.0.dist-info}/METADATA +1 -1
  48. {roms_tools-2.6.2.dist-info → roms_tools-2.7.0.dist-info}/RECORD +51 -33
  49. {roms_tools-2.6.2.dist-info → roms_tools-2.7.0.dist-info}/WHEEL +1 -1
  50. {roms_tools-2.6.2.dist-info → roms_tools-2.7.0.dist-info}/licenses/LICENSE +0 -0
  51. {roms_tools-2.6.2.dist-info → roms_tools-2.7.0.dist-info}/top_level.txt +0 -0
@@ -205,7 +205,7 @@
205
205
  "ntracers",
206
206
  "nriver"
207
207
  ],
208
- "coordinates": "abs_time river_name tracer_name",
208
+ "coordinates": "abs_time river_name tracer_long_name tracer_name tracer_unit",
209
209
  "long_name": "River tracer data"
210
210
  },
211
211
  "river_volume/.zarray": {
@@ -239,6 +239,32 @@
239
239
  "long_name": "River volume flux",
240
240
  "units": "m^3/s"
241
241
  },
242
+ "tracer_long_name/.zarray": {
243
+ "chunks": [
244
+ 2
245
+ ],
246
+ "compressor": {
247
+ "blocksize": 0,
248
+ "clevel": 5,
249
+ "cname": "lz4",
250
+ "id": "blosc",
251
+ "shuffle": 1
252
+ },
253
+ "dtype": "<U21",
254
+ "fill_value": null,
255
+ "filters": null,
256
+ "order": "C",
257
+ "shape": [
258
+ 2
259
+ ],
260
+ "zarr_format": 2
261
+ },
262
+ "tracer_long_name/.zattrs": {
263
+ "_ARRAY_DIMENSIONS": [
264
+ "ntracers"
265
+ ],
266
+ "long_name": "Tracer long name"
267
+ },
242
268
  "tracer_name/.zarray": {
243
269
  "chunks": [
244
270
  2
@@ -264,6 +290,32 @@
264
290
  "ntracers"
265
291
  ],
266
292
  "long_name": "Tracer name"
293
+ },
294
+ "tracer_unit/.zarray": {
295
+ "chunks": [
296
+ 2
297
+ ],
298
+ "compressor": {
299
+ "blocksize": 0,
300
+ "clevel": 5,
301
+ "cname": "lz4",
302
+ "id": "blosc",
303
+ "shuffle": 1
304
+ },
305
+ "dtype": "<U15",
306
+ "fill_value": null,
307
+ "filters": null,
308
+ "order": "C",
309
+ "shape": [
310
+ 2
311
+ ],
312
+ "zarr_format": 2
313
+ },
314
+ "tracer_unit/.zattrs": {
315
+ "_ARRAY_DIMENSIONS": [
316
+ "ntracers"
317
+ ],
318
+ "long_name": "Tracer unit"
267
319
  }
268
320
  },
269
321
  "zarr_consolidated_format": 1
@@ -4,6 +4,6 @@
4
4
  "ntracers",
5
5
  "nriver"
6
6
  ],
7
- "coordinates": "abs_time river_name tracer_name",
7
+ "coordinates": "abs_time river_name tracer_long_name tracer_name tracer_unit",
8
8
  "long_name": "River tracer data"
9
9
  }
@@ -0,0 +1,20 @@
1
+ {
2
+ "chunks": [
3
+ 2
4
+ ],
5
+ "compressor": {
6
+ "blocksize": 0,
7
+ "clevel": 5,
8
+ "cname": "lz4",
9
+ "id": "blosc",
10
+ "shuffle": 1
11
+ },
12
+ "dtype": "<U21",
13
+ "fill_value": null,
14
+ "filters": null,
15
+ "order": "C",
16
+ "shape": [
17
+ 2
18
+ ],
19
+ "zarr_format": 2
20
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "_ARRAY_DIMENSIONS": [
3
+ "ntracers"
4
+ ],
5
+ "long_name": "Tracer long name"
6
+ }
@@ -0,0 +1,20 @@
1
+ {
2
+ "chunks": [
3
+ 2
4
+ ],
5
+ "compressor": {
6
+ "blocksize": 0,
7
+ "clevel": 5,
8
+ "cname": "lz4",
9
+ "id": "blosc",
10
+ "shuffle": 1
11
+ },
12
+ "dtype": "<U15",
13
+ "fill_value": null,
14
+ "filters": null,
15
+ "order": "C",
16
+ "shape": [
17
+ 2
18
+ ],
19
+ "zarr_format": 2
20
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "_ARRAY_DIMENSIONS": [
3
+ "ntracers"
4
+ ],
5
+ "long_name": "Tracer unit"
6
+ }
@@ -234,7 +234,7 @@
234
234
  "ntracers",
235
235
  "nriver"
236
236
  ],
237
- "coordinates": "abs_time month river_name tracer_name",
237
+ "coordinates": "abs_time month river_name tracer_long_name tracer_name tracer_unit",
238
238
  "long_name": "River tracer data"
239
239
  },
240
240
  "river_volume/.zarray": {
@@ -268,6 +268,32 @@
268
268
  "long_name": "River volume flux",
269
269
  "units": "m^3/s"
270
270
  },
271
+ "tracer_long_name/.zarray": {
272
+ "chunks": [
273
+ 34
274
+ ],
275
+ "compressor": {
276
+ "blocksize": 0,
277
+ "clevel": 5,
278
+ "cname": "lz4",
279
+ "id": "blosc",
280
+ "shuffle": 1
281
+ },
282
+ "dtype": "<U43",
283
+ "fill_value": null,
284
+ "filters": null,
285
+ "order": "C",
286
+ "shape": [
287
+ 34
288
+ ],
289
+ "zarr_format": 2
290
+ },
291
+ "tracer_long_name/.zattrs": {
292
+ "_ARRAY_DIMENSIONS": [
293
+ "ntracers"
294
+ ],
295
+ "long_name": "Tracer long name"
296
+ },
271
297
  "tracer_name/.zarray": {
272
298
  "chunks": [
273
299
  34
@@ -293,6 +319,32 @@
293
319
  "ntracers"
294
320
  ],
295
321
  "long_name": "Tracer name"
322
+ },
323
+ "tracer_unit/.zarray": {
324
+ "chunks": [
325
+ 34
326
+ ],
327
+ "compressor": {
328
+ "blocksize": 0,
329
+ "clevel": 5,
330
+ "cname": "lz4",
331
+ "id": "blosc",
332
+ "shuffle": 1
333
+ },
334
+ "dtype": "<U15",
335
+ "fill_value": null,
336
+ "filters": null,
337
+ "order": "C",
338
+ "shape": [
339
+ 34
340
+ ],
341
+ "zarr_format": 2
342
+ },
343
+ "tracer_unit/.zattrs": {
344
+ "_ARRAY_DIMENSIONS": [
345
+ "ntracers"
346
+ ],
347
+ "long_name": "Tracer unit"
296
348
  }
297
349
  },
298
350
  "zarr_consolidated_format": 1
@@ -4,6 +4,6 @@
4
4
  "ntracers",
5
5
  "nriver"
6
6
  ],
7
- "coordinates": "abs_time month river_name tracer_name",
7
+ "coordinates": "abs_time month river_name tracer_long_name tracer_name tracer_unit",
8
8
  "long_name": "River tracer data"
9
9
  }
@@ -0,0 +1,20 @@
1
+ {
2
+ "chunks": [
3
+ 34
4
+ ],
5
+ "compressor": {
6
+ "blocksize": 0,
7
+ "clevel": 5,
8
+ "cname": "lz4",
9
+ "id": "blosc",
10
+ "shuffle": 1
11
+ },
12
+ "dtype": "<U43",
13
+ "fill_value": null,
14
+ "filters": null,
15
+ "order": "C",
16
+ "shape": [
17
+ 34
18
+ ],
19
+ "zarr_format": 2
20
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "_ARRAY_DIMENSIONS": [
3
+ "ntracers"
4
+ ],
5
+ "long_name": "Tracer long name"
6
+ }
@@ -0,0 +1,20 @@
1
+ {
2
+ "chunks": [
3
+ 34
4
+ ],
5
+ "compressor": {
6
+ "blocksize": 0,
7
+ "clevel": 5,
8
+ "cname": "lz4",
9
+ "id": "blosc",
10
+ "shuffle": 1
11
+ },
12
+ "dtype": "<U15",
13
+ "fill_value": null,
14
+ "filters": null,
15
+ "order": "C",
16
+ "shape": [
17
+ 34
18
+ ],
19
+ "zarr_format": 2
20
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "_ARRAY_DIMENSIONS": [
3
+ "ntracers"
4
+ ],
5
+ "long_name": "Tracer unit"
6
+ }
@@ -1,7 +1,6 @@
1
1
  {
2
- "allan_factor": 2.0,
3
2
  "model_reference_date": "2000-01-01 00:00:00",
4
- "roms_tools_version": "0.1.dev157+dirty",
3
+ "roms_tools_version": "0.1.dev177",
5
4
  "source": "TPXO",
6
5
  "title": "ROMS tidal forcing created by ROMS-Tools"
7
6
  }
@@ -1,15 +1,39 @@
1
1
  {
2
2
  "metadata": {
3
3
  ".zattrs": {
4
- "allan_factor": 2.0,
5
4
  "model_reference_date": "2000-01-01 00:00:00",
6
- "roms_tools_version": "0.1.dev157+dirty",
5
+ "roms_tools_version": "0.1.dev177",
7
6
  "source": "TPXO",
8
7
  "title": "ROMS tidal forcing created by ROMS-Tools"
9
8
  },
10
9
  ".zgroup": {
11
10
  "zarr_format": 2
12
11
  },
12
+ "ntides/.zarray": {
13
+ "chunks": [
14
+ 1
15
+ ],
16
+ "compressor": {
17
+ "blocksize": 0,
18
+ "clevel": 5,
19
+ "cname": "lz4",
20
+ "id": "blosc",
21
+ "shuffle": 1
22
+ },
23
+ "dtype": "<U3",
24
+ "fill_value": null,
25
+ "filters": null,
26
+ "order": "C",
27
+ "shape": [
28
+ 1
29
+ ],
30
+ "zarr_format": 2
31
+ },
32
+ "ntides/.zattrs": {
33
+ "_ARRAY_DIMENSIONS": [
34
+ "ntides"
35
+ ]
36
+ },
13
37
  "omega/.zarray": {
14
38
  "chunks": [
15
39
  1
@@ -33,9 +57,7 @@
33
57
  "omega/.zattrs": {
34
58
  "_ARRAY_DIMENSIONS": [
35
59
  "ntides"
36
- ],
37
- "long_name": "Tidal frequencies",
38
- "units": "1/s"
60
+ ]
39
61
  },
40
62
  "pot_Im/.zarray": {
41
63
  "chunks": [
@@ -0,0 +1,20 @@
1
+ {
2
+ "chunks": [
3
+ 1
4
+ ],
5
+ "compressor": {
6
+ "blocksize": 0,
7
+ "clevel": 5,
8
+ "cname": "lz4",
9
+ "id": "blosc",
10
+ "shuffle": 1
11
+ },
12
+ "dtype": "<U3",
13
+ "fill_value": null,
14
+ "filters": null,
15
+ "order": "C",
16
+ "shape": [
17
+ 1
18
+ ],
19
+ "zarr_format": 2
20
+ }
@@ -0,0 +1,5 @@
1
+ {
2
+ "_ARRAY_DIMENSIONS": [
3
+ "ntides"
4
+ ]
5
+ }
@@ -1,7 +1,5 @@
1
1
  {
2
2
  "_ARRAY_DIMENSIONS": [
3
3
  "ntides"
4
- ],
5
- "long_name": "Tidal frequencies",
6
- "units": "1/s"
4
+ ]
7
5
  }
@@ -8,9 +8,11 @@ from roms_tools.setup.datasets import (
8
8
  GLORYSDataset,
9
9
  ERA5Correction,
10
10
  CESMBGCDataset,
11
+ TPXODataset,
11
12
  )
12
13
  from roms_tools.download import download_test_data
13
14
  from pathlib import Path
15
+ from collections import OrderedDict
14
16
 
15
17
 
16
18
  @pytest.fixture
@@ -529,7 +531,7 @@ def test_climatology_error(use_dask):
529
531
  [
530
532
  ("era5_data", 0.25),
531
533
  ("glorys_data", 1 / 12),
532
- ("tpxo_data", 1 / 6),
534
+ # ("tpxo_data", 1 / 6),
533
535
  ("cesm_bgc_data", 1.0),
534
536
  ("cesm_surface_bgc_data", 1.0),
535
537
  ("unified_bgc_data", 2.0),
@@ -540,3 +542,103 @@ def test_horizontal_resolution(data_fixture, expected_resolution, request):
540
542
 
541
543
  data = request.getfixturevalue(data_fixture)
542
544
  assert np.isclose(data.resolution, expected_resolution)
545
+
546
+
547
+ class TestTPXODataset:
548
+ @pytest.fixture
549
+ def regional_tpxo_dataset(self, use_dask):
550
+ """TPXO dataset with regional coverage and 25 constituents: M2, S2, N2, K2, K1, O1, P1, Q1, MM, Mf, MSF, M4, Mn4, Ms4, ..."""
551
+ fname_grid = Path(download_test_data("regional_grid_tpxo10v2.nc"))
552
+ fname_h = Path(download_test_data("regional_h_tpxo10v2.nc"))
553
+
554
+ return TPXODataset(
555
+ filename=fname_h,
556
+ grid_filename=fname_grid,
557
+ location="h",
558
+ var_names={"ssh_Re": "hRe", "ssh_Im": "hIm"},
559
+ use_dask=use_dask,
560
+ )
561
+
562
+ @pytest.fixture
563
+ def global_tpxo_dataset(self, use_dask):
564
+ """TPXO dataset with global coverage and 1 constituent: M2"""
565
+ fname_grid = Path(download_test_data("global_grid_tpxo10.v2.nc"))
566
+ fname_h = Path(download_test_data("global_h_tpxo10.v2.nc"))
567
+
568
+ return TPXODataset(
569
+ filename=fname_h,
570
+ grid_filename=fname_grid,
571
+ location="h",
572
+ var_names={"ssh_Re": "hRe", "ssh_Im": "hIm"},
573
+ use_dask=use_dask,
574
+ )
575
+
576
+ @pytest.fixture
577
+ def omega(self):
578
+ return {
579
+ "m2": 1.405189e-04,
580
+ "s2": 1.454441e-04,
581
+ "n2": 1.378797e-04,
582
+ "k2": 1.458423e-04,
583
+ "k1": 7.292117e-05,
584
+ "o1": 6.759774e-05,
585
+ "p1": 7.252295e-05,
586
+ "q1": 6.495854e-05,
587
+ "mm": 0.026392e-04,
588
+ "mf": 0.053234e-04,
589
+ "m4": 2.810377e-04,
590
+ "mn4": 2.783984e-04,
591
+ "ms4": 2.859630e-04,
592
+ "2n2": 1.352405e-04,
593
+ "s1": 7.2722e-05,
594
+ }
595
+
596
+ @pytest.mark.parametrize(
597
+ "tpxo_dataset_fixture",
598
+ [
599
+ "regional_tpxo_dataset",
600
+ "global_tpxo_dataset",
601
+ ],
602
+ )
603
+ def test_initialization_and_clean_up(self, tpxo_dataset_fixture, request):
604
+
605
+ tpxo_dataset = request.getfixturevalue(tpxo_dataset_fixture)
606
+ assert tpxo_dataset.location == "h"
607
+
608
+ assert "hRe" in tpxo_dataset.ds.data_vars
609
+ assert "hIm" in tpxo_dataset.ds.data_vars
610
+ assert "mask" in tpxo_dataset.ds.data_vars
611
+ assert "longitude" in tpxo_dataset.ds.dims
612
+ assert "latitude" in tpxo_dataset.ds.dims
613
+ assert "longitude" in tpxo_dataset.ds.variables
614
+ assert "latitude" in tpxo_dataset.ds.variables
615
+
616
+ def test_select_fewer_constituents(self, regional_tpxo_dataset, omega):
617
+
618
+ regional_tpxo_dataset.select_constituents(2, omega)
619
+ assert (
620
+ regional_tpxo_dataset.ds["ntides"].values.astype("U3") == ["m2", "s2"]
621
+ ).all()
622
+
623
+ def test_select_constituents_with_reordering(self, regional_tpxo_dataset, omega):
624
+
625
+ regional_tpxo_dataset.select_constituents(11, omega)
626
+
627
+ assert len(regional_tpxo_dataset.ds["ntides"]) == 11
628
+ # check that m4 has been moved from 12th to 11th position to follow TPXO9 order
629
+ assert (
630
+ regional_tpxo_dataset.ds["ntides"].isel(ntides=10).item().decode("utf-8")
631
+ == "m4"
632
+ )
633
+
634
+ def test_select_constituents_omega_mismatch(self, regional_tpxo_dataset, omega):
635
+
636
+ omega = OrderedDict(
637
+ list(omega.items())[:3] + [("fake", 6.495854e-05)] + list(omega.items())[3:]
638
+ )
639
+ with pytest.raises(ValueError, match="The dataset contains tidal constituents"):
640
+ regional_tpxo_dataset.select_constituents(11, omega)
641
+
642
+ def test_select_constituents_too_few(self, global_tpxo_dataset, omega):
643
+ with pytest.raises(ValueError, match="The dataset contains tidal constituents"):
644
+ global_tpxo_dataset.select_constituents(11, omega)