roms-tools 3.3.0__py3-none-any.whl → 3.5.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 +1 -1
- roms_tools/analysis/cdr_ensemble.py +10 -13
- roms_tools/analysis/roms_output.py +5 -304
- roms_tools/{download.py → datasets/download.py} +1 -0
- roms_tools/{setup → datasets}/lat_lon_datasets.py +88 -64
- roms_tools/{setup → datasets}/river_datasets.py +9 -4
- roms_tools/datasets/roms_dataset.py +854 -0
- roms_tools/datasets/utils.py +487 -0
- roms_tools/{setup/fill.py → fill.py} +110 -13
- roms_tools/plot.py +4 -4
- roms_tools/regrid.py +76 -0
- roms_tools/setup/boundary_forcing.py +53 -45
- roms_tools/setup/cdr_release.py +2 -4
- roms_tools/setup/grid.py +46 -15
- roms_tools/setup/initial_conditions.py +330 -71
- roms_tools/setup/mask.py +2 -5
- roms_tools/setup/nesting.py +13 -6
- roms_tools/setup/river_forcing.py +4 -4
- roms_tools/setup/surface_forcing.py +15 -11
- roms_tools/setup/tides.py +7 -6
- roms_tools/setup/topography.py +10 -2
- roms_tools/setup/utils.py +292 -666
- roms_tools/tests/test_analysis/test_cdr_ensemble.py +4 -6
- roms_tools/tests/test_analysis/test_roms_output.py +1 -220
- roms_tools/tests/{test_setup → test_datasets}/test_lat_lon_datasets.py +4 -4
- roms_tools/tests/{test_setup → test_datasets}/test_river_datasets.py +1 -1
- roms_tools/tests/test_datasets/test_roms_dataset.py +743 -0
- roms_tools/tests/test_datasets/test_utils.py +527 -0
- roms_tools/tests/{test_setup/test_fill.py → test_fill.py} +72 -9
- roms_tools/tests/test_regrid.py +120 -1
- roms_tools/tests/test_setup/test_boundary_forcing.py +57 -138
- roms_tools/tests/test_setup/test_cdr_release.py +4 -5
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/zarr.json +293 -2021
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_unified_climatology.zarr/zarr.json +294 -2022
- roms_tools/tests/test_setup/test_data/initial_conditions_from_roms.zarr/ALK/c/0/0/0/0 +0 -0
- roms_tools/tests/test_setup/test_data/{bgc_boundary_forcing_from_climatology.zarr/ALK_west → initial_conditions_from_roms.zarr/ALK}/zarr.json +11 -8
- roms_tools/tests/test_setup/test_data/initial_conditions_from_roms.zarr/ALK_ALT_CO2/c/0/0/0/0 +0 -0
- roms_tools/tests/test_setup/test_data/{bgc_boundary_forcing_from_climatology.zarr/ALK_ALT_CO2_west → initial_conditions_from_roms.zarr/ALK_ALT_CO2}/zarr.json +11 -8
- roms_tools/tests/test_setup/test_data/initial_conditions_from_roms.zarr/Cs_r/c/0 +0 -0
- roms_tools/tests/test_setup/test_data/{bgc_boundary_forcing_from_unified_climatology.zarr/diatFe_west → initial_conditions_from_roms.zarr/Cs_r}/zarr.json +5 -12
- roms_tools/tests/test_setup/test_data/initial_conditions_from_roms.zarr/Cs_w/c/0 +0 -0
- roms_tools/tests/test_setup/test_data/{bgc_boundary_forcing_from_climatology.zarr/diatFe_west → initial_conditions_from_roms.zarr/Cs_w}/zarr.json +3 -10
- roms_tools/tests/test_setup/test_data/initial_conditions_from_roms.zarr/DIC/c/0/0/0/0 +0 -0
- roms_tools/tests/test_setup/test_data/{bgc_boundary_forcing_from_climatology.zarr/DOCr_west → initial_conditions_from_roms.zarr/DIC}/zarr.json +11 -8
- roms_tools/tests/test_setup/test_data/initial_conditions_from_roms.zarr/DIC_ALT_CO2/c/0/0/0/0 +0 -0
- roms_tools/tests/test_setup/test_data/initial_conditions_from_roms.zarr/DIC_ALT_CO2/zarr.json +57 -0
- roms_tools/tests/test_setup/test_data/initial_conditions_from_roms.zarr/DOC/c/0/0/0/0 +0 -0
- roms_tools/tests/test_setup/test_data/initial_conditions_from_roms.zarr/DOC/zarr.json +57 -0
- roms_tools/tests/test_setup/test_data/initial_conditions_from_roms.zarr/DOCr/c/0/0/0/0 +0 -0
- roms_tools/tests/test_setup/test_data/{bgc_boundary_forcing_from_climatology.zarr/DIC_ALT_CO2_west → initial_conditions_from_roms.zarr/DOCr}/zarr.json +11 -8
- roms_tools/tests/test_setup/test_data/initial_conditions_from_roms.zarr/DON/c/0/0/0/0 +0 -0
- roms_tools/tests/test_setup/test_data/initial_conditions_from_roms.zarr/DON/zarr.json +57 -0
- roms_tools/tests/test_setup/test_data/initial_conditions_from_roms.zarr/DONr/c/0/0/0/0 +0 -0
- roms_tools/tests/test_setup/test_data/initial_conditions_from_roms.zarr/DONr/zarr.json +57 -0
- roms_tools/tests/test_setup/test_data/initial_conditions_from_roms.zarr/DOP/c/0/0/0/0 +0 -0
- roms_tools/tests/test_setup/test_data/initial_conditions_from_roms.zarr/DOP/zarr.json +57 -0
- roms_tools/tests/test_setup/test_data/initial_conditions_from_roms.zarr/DOPr/c/0/0/0/0 +0 -0
- roms_tools/tests/test_setup/test_data/initial_conditions_from_roms.zarr/DOPr/zarr.json +57 -0
- roms_tools/tests/test_setup/test_data/initial_conditions_from_roms.zarr/Fe/c/0/0/0/0 +0 -0
- roms_tools/tests/test_setup/test_data/initial_conditions_from_roms.zarr/Fe/zarr.json +57 -0
- roms_tools/tests/test_setup/test_data/initial_conditions_from_roms.zarr/Lig/c/0/0/0/0 +0 -0
- roms_tools/tests/test_setup/test_data/{bgc_boundary_forcing_from_climatology.zarr/DOP_west → initial_conditions_from_roms.zarr/Lig}/zarr.json +11 -8
- roms_tools/tests/test_setup/test_data/initial_conditions_from_roms.zarr/NH4/c/0/0/0/0 +0 -0
- roms_tools/tests/test_setup/test_data/{bgc_boundary_forcing_from_climatology.zarr/DON_west → initial_conditions_from_roms.zarr/NH4}/zarr.json +11 -8
- roms_tools/tests/test_setup/test_data/initial_conditions_from_roms.zarr/NO3/c/0/0/0/0 +0 -0
- roms_tools/tests/test_setup/test_data/initial_conditions_from_roms.zarr/NO3/zarr.json +57 -0
- roms_tools/tests/test_setup/test_data/initial_conditions_from_roms.zarr/O2/c/0/0/0/0 +0 -0
- roms_tools/tests/test_setup/test_data/{bgc_boundary_forcing_from_climatology.zarr/Lig_west → initial_conditions_from_roms.zarr/O2}/zarr.json +11 -8
- roms_tools/tests/test_setup/test_data/initial_conditions_from_roms.zarr/PO4/c/0/0/0/0 +0 -0
- roms_tools/tests/test_setup/test_data/initial_conditions_from_roms.zarr/PO4/zarr.json +57 -0
- roms_tools/tests/test_setup/test_data/initial_conditions_from_roms.zarr/SiO3/c/0/0/0/0 +0 -0
- roms_tools/tests/test_setup/test_data/initial_conditions_from_roms.zarr/SiO3/zarr.json +57 -0
- roms_tools/tests/test_setup/test_data/initial_conditions_from_roms.zarr/abs_time/zarr.json +47 -0
- roms_tools/tests/test_setup/test_data/initial_conditions_from_roms.zarr/diatC/c/0/0/0/0 +0 -0
- roms_tools/tests/test_setup/test_data/{bgc_boundary_forcing_from_climatology.zarr/diatC_west → initial_conditions_from_roms.zarr/diatC}/zarr.json +11 -8
- roms_tools/tests/test_setup/test_data/initial_conditions_from_roms.zarr/diatChl/c/0/0/0/0 +0 -0
- roms_tools/tests/test_setup/test_data/{bgc_boundary_forcing_from_climatology.zarr/diatChl_west → initial_conditions_from_roms.zarr/diatChl}/zarr.json +11 -8
- roms_tools/tests/test_setup/test_data/initial_conditions_from_roms.zarr/diatFe/c/0/0/0/0 +0 -0
- roms_tools/tests/test_setup/test_data/{bgc_boundary_forcing_from_climatology.zarr/O2_west → initial_conditions_from_roms.zarr/diatFe}/zarr.json +11 -8
- roms_tools/tests/test_setup/test_data/initial_conditions_from_roms.zarr/diatP/c/0/0/0/0 +0 -0
- roms_tools/tests/test_setup/test_data/{bgc_boundary_forcing_from_climatology.zarr/DIC_west → initial_conditions_from_roms.zarr/diatP}/zarr.json +11 -8
- roms_tools/tests/test_setup/test_data/initial_conditions_from_roms.zarr/diatSi/c/0/0/0/0 +0 -0
- roms_tools/tests/test_setup/test_data/{bgc_boundary_forcing_from_climatology.zarr/DOC_west → initial_conditions_from_roms.zarr/diatSi}/zarr.json +11 -8
- roms_tools/tests/test_setup/test_data/initial_conditions_from_roms.zarr/diazC/c/0/0/0/0 +0 -0
- roms_tools/tests/test_setup/test_data/initial_conditions_from_roms.zarr/diazC/zarr.json +57 -0
- roms_tools/tests/test_setup/test_data/initial_conditions_from_roms.zarr/diazChl/c/0/0/0/0 +0 -0
- roms_tools/tests/test_setup/test_data/{bgc_boundary_forcing_from_climatology.zarr/diazChl_west → initial_conditions_from_roms.zarr/diazChl}/zarr.json +11 -8
- roms_tools/tests/test_setup/test_data/initial_conditions_from_roms.zarr/diazFe/c/0/0/0/0 +0 -0
- roms_tools/tests/test_setup/test_data/{bgc_boundary_forcing_from_climatology.zarr/Fe_west → initial_conditions_from_roms.zarr/diazFe}/zarr.json +11 -8
- roms_tools/tests/test_setup/test_data/initial_conditions_from_roms.zarr/diazP/c/0/0/0/0 +0 -0
- roms_tools/tests/test_setup/test_data/initial_conditions_from_roms.zarr/diazP/zarr.json +57 -0
- roms_tools/tests/test_setup/test_data/initial_conditions_from_roms.zarr/ocean_time/c/0 +0 -0
- roms_tools/tests/test_setup/test_data/initial_conditions_from_roms.zarr/ocean_time/zarr.json +47 -0
- roms_tools/tests/test_setup/test_data/initial_conditions_from_roms.zarr/salt/c/0/0/0/0 +0 -0
- roms_tools/tests/test_setup/test_data/{bgc_boundary_forcing_from_unified_climatology.zarr/ALK_west → initial_conditions_from_roms.zarr/salt}/zarr.json +12 -9
- roms_tools/tests/test_setup/test_data/initial_conditions_from_roms.zarr/spC/c/0/0/0/0 +0 -0
- roms_tools/tests/test_setup/test_data/initial_conditions_from_roms.zarr/spC/zarr.json +57 -0
- roms_tools/tests/test_setup/test_data/initial_conditions_from_roms.zarr/spCaCO3/c/0/0/0/0 +0 -0
- roms_tools/tests/test_setup/test_data/initial_conditions_from_roms.zarr/spCaCO3/zarr.json +57 -0
- roms_tools/tests/test_setup/test_data/initial_conditions_from_roms.zarr/spChl/c/0/0/0/0 +0 -0
- roms_tools/tests/test_setup/test_data/{bgc_boundary_forcing_from_climatology.zarr/spChl_west → initial_conditions_from_roms.zarr/spChl}/zarr.json +11 -8
- roms_tools/tests/test_setup/test_data/initial_conditions_from_roms.zarr/spFe/c/0/0/0/0 +0 -0
- roms_tools/tests/test_setup/test_data/initial_conditions_from_roms.zarr/spFe/zarr.json +57 -0
- roms_tools/tests/test_setup/test_data/initial_conditions_from_roms.zarr/spP/c/0/0/0/0 +0 -0
- roms_tools/tests/test_setup/test_data/initial_conditions_from_roms.zarr/spP/zarr.json +57 -0
- roms_tools/tests/test_setup/test_data/initial_conditions_from_roms.zarr/temp/c/0/0/0/0 +0 -0
- roms_tools/tests/test_setup/test_data/initial_conditions_from_roms.zarr/temp/zarr.json +57 -0
- roms_tools/tests/test_setup/test_data/initial_conditions_from_roms.zarr/u/c/0/0/0/0 +0 -0
- roms_tools/tests/test_setup/test_data/{bgc_boundary_forcing_from_climatology.zarr/NH4_west → initial_conditions_from_roms.zarr/u}/zarr.json +12 -9
- roms_tools/tests/test_setup/test_data/initial_conditions_from_roms.zarr/ubar/c/0/0/0 +0 -0
- roms_tools/tests/test_setup/test_data/initial_conditions_from_roms.zarr/ubar/zarr.json +54 -0
- roms_tools/tests/test_setup/test_data/initial_conditions_from_roms.zarr/v/c/0/0/0/0 +0 -0
- roms_tools/tests/test_setup/test_data/initial_conditions_from_roms.zarr/v/zarr.json +57 -0
- roms_tools/tests/test_setup/test_data/initial_conditions_from_roms.zarr/vbar/c/0/0/0 +0 -0
- roms_tools/tests/test_setup/test_data/initial_conditions_from_roms.zarr/vbar/zarr.json +54 -0
- roms_tools/tests/test_setup/test_data/initial_conditions_from_roms.zarr/w/zarr.json +57 -0
- roms_tools/tests/test_setup/test_data/initial_conditions_from_roms.zarr/zarr.json +2481 -0
- roms_tools/tests/test_setup/test_data/initial_conditions_from_roms.zarr/zeta/c/0/0/0 +0 -0
- roms_tools/tests/test_setup/test_data/initial_conditions_from_roms.zarr/zeta/zarr.json +54 -0
- roms_tools/tests/test_setup/test_data/initial_conditions_from_roms.zarr/zooC/c/0/0/0/0 +0 -0
- roms_tools/tests/test_setup/test_data/initial_conditions_from_roms.zarr/zooC/zarr.json +57 -0
- roms_tools/tests/test_setup/test_grid.py +66 -1
- roms_tools/tests/test_setup/test_initial_conditions.py +130 -104
- roms_tools/tests/test_setup/test_nesting.py +2 -1
- roms_tools/tests/test_setup/test_surface_forcing.py +1 -1
- roms_tools/tests/test_setup/test_tides.py +1 -1
- roms_tools/tests/test_setup/test_utils.py +100 -15
- roms_tools/tests/test_setup/test_validation.py +15 -0
- roms_tools/tests/test_tiling/test_partition.py +63 -15
- roms_tools/tests/test_utils.py +365 -0
- roms_tools/tiling/partition.py +81 -211
- roms_tools/utils.py +360 -62
- {roms_tools-3.3.0.dist-info → roms_tools-3.5.0.dist-info}/METADATA +2 -3
- {roms_tools-3.3.0.dist-info → roms_tools-3.5.0.dist-info}/RECORD +137 -174
- {roms_tools-3.3.0.dist-info → roms_tools-3.5.0.dist-info}/WHEEL +1 -1
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/ALK_ALT_CO2_west/c/0/0/0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/ALK_west/c/0/0/0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/DIC_ALT_CO2_west/c/0/0/0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/DIC_west/c/0/0/0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/DOC_west/c/0/0/0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/DOCr_west/c/0/0/0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/DON_west/c/0/0/0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/DONr_west/c/0/0/0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/DONr_west/zarr.json +0 -54
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/DOP_west/c/0/0/0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/DOPr_west/c/0/0/0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/DOPr_west/zarr.json +0 -54
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/Fe_west/c/0/0/0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/Lig_west/c/0/0/0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/NH4_west/c/0/0/0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/NO3_west/c/0/0/0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/NO3_west/zarr.json +0 -54
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/O2_west/c/0/0/0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/PO4_west/c/0/0/0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/PO4_west/zarr.json +0 -54
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/SiO3_west/c/0/0/0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/SiO3_west/zarr.json +0 -54
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/diatC_west/c/0/0/0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/diatChl_west/c/0/0/0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/diatFe_west/c/0/0/0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/diatP_west/c/0/0/0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/diatP_west/zarr.json +0 -54
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/diatSi_west/c/0/0/0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/diatSi_west/zarr.json +0 -54
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/diazC_west/c/0/0/0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/diazC_west/zarr.json +0 -54
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/diazChl_west/c/0/0/0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/diazFe_west/c/0/0/0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/diazFe_west/zarr.json +0 -54
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/diazP_west/c/0/0/0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/diazP_west/zarr.json +0 -54
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/spC_west/c/0/0/0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/spC_west/zarr.json +0 -54
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/spCaCO3_west/c/0/0/0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/spCaCO3_west/zarr.json +0 -54
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/spChl_west/c/0/0/0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/spFe_west/c/0/0/0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/spFe_west/zarr.json +0 -54
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/spP_west/c/0/0/0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/spP_west/zarr.json +0 -54
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/zooC_west/c/0/0/0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/zooC_west/zarr.json +0 -54
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_unified_climatology.zarr/ALK_ALT_CO2_west/c/0/0/0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_unified_climatology.zarr/ALK_ALT_CO2_west/zarr.json +0 -54
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_unified_climatology.zarr/ALK_west/c/0/0/0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_unified_climatology.zarr/DIC_ALT_CO2_west/c/0/0/0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_unified_climatology.zarr/DIC_ALT_CO2_west/zarr.json +0 -54
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_unified_climatology.zarr/DIC_west/c/0/0/0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_unified_climatology.zarr/DIC_west/zarr.json +0 -54
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_unified_climatology.zarr/DOC_west/c/0/0/0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_unified_climatology.zarr/DOC_west/zarr.json +0 -54
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_unified_climatology.zarr/DOCr_west/c/0/0/0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_unified_climatology.zarr/DOCr_west/zarr.json +0 -54
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_unified_climatology.zarr/DON_west/c/0/0/0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_unified_climatology.zarr/DON_west/zarr.json +0 -54
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_unified_climatology.zarr/DONr_west/c/0/0/0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_unified_climatology.zarr/DONr_west/zarr.json +0 -54
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_unified_climatology.zarr/DOP_west/c/0/0/0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_unified_climatology.zarr/DOP_west/zarr.json +0 -54
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_unified_climatology.zarr/DOPr_west/c/0/0/0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_unified_climatology.zarr/DOPr_west/zarr.json +0 -54
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_unified_climatology.zarr/Fe_west/c/0/0/0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_unified_climatology.zarr/Fe_west/zarr.json +0 -54
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_unified_climatology.zarr/Lig_west/c/0/0/0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_unified_climatology.zarr/Lig_west/zarr.json +0 -54
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_unified_climatology.zarr/NH4_west/c/0/0/0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_unified_climatology.zarr/NH4_west/zarr.json +0 -54
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_unified_climatology.zarr/NO3_west/c/0/0/0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_unified_climatology.zarr/NO3_west/zarr.json +0 -54
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_unified_climatology.zarr/O2_west/c/0/0/0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_unified_climatology.zarr/O2_west/zarr.json +0 -54
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_unified_climatology.zarr/PO4_west/c/0/0/0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_unified_climatology.zarr/PO4_west/zarr.json +0 -54
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_unified_climatology.zarr/SiO3_west/c/0/0/0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_unified_climatology.zarr/SiO3_west/zarr.json +0 -54
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_unified_climatology.zarr/diatC_west/c/0/0/0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_unified_climatology.zarr/diatC_west/zarr.json +0 -54
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_unified_climatology.zarr/diatChl_west/c/0/0/0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_unified_climatology.zarr/diatChl_west/zarr.json +0 -54
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_unified_climatology.zarr/diatFe_west/c/0/0/0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_unified_climatology.zarr/diatP_west/c/0/0/0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_unified_climatology.zarr/diatP_west/zarr.json +0 -54
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_unified_climatology.zarr/diatSi_west/c/0/0/0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_unified_climatology.zarr/diatSi_west/zarr.json +0 -54
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_unified_climatology.zarr/diazC_west/c/0/0/0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_unified_climatology.zarr/diazC_west/zarr.json +0 -54
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_unified_climatology.zarr/diazChl_west/c/0/0/0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_unified_climatology.zarr/diazChl_west/zarr.json +0 -54
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_unified_climatology.zarr/diazFe_west/c/0/0/0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_unified_climatology.zarr/diazFe_west/zarr.json +0 -54
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_unified_climatology.zarr/diazP_west/c/0/0/0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_unified_climatology.zarr/diazP_west/zarr.json +0 -54
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_unified_climatology.zarr/spC_west/c/0/0/0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_unified_climatology.zarr/spC_west/zarr.json +0 -54
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_unified_climatology.zarr/spCaCO3_west/c/0/0/0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_unified_climatology.zarr/spCaCO3_west/zarr.json +0 -54
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_unified_climatology.zarr/spChl_west/c/0/0/0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_unified_climatology.zarr/spChl_west/zarr.json +0 -54
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_unified_climatology.zarr/spFe_west/c/0/0/0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_unified_climatology.zarr/spFe_west/zarr.json +0 -54
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_unified_climatology.zarr/spP_west/c/0/0/0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_unified_climatology.zarr/spP_west/zarr.json +0 -54
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_unified_climatology.zarr/zooC_west/c/0/0/0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_unified_climatology.zarr/zooC_west/zarr.json +0 -54
- {roms_tools-3.3.0.dist-info → roms_tools-3.5.0.dist-info}/licenses/LICENSE +0 -0
- {roms_tools-3.3.0.dist-info → roms_tools-3.5.0.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,743 @@
|
|
|
1
|
+
import logging
|
|
2
|
+
import os
|
|
3
|
+
from datetime import datetime
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
|
|
6
|
+
import numpy as np
|
|
7
|
+
import pytest
|
|
8
|
+
import xarray as xr
|
|
9
|
+
|
|
10
|
+
from roms_tools import Grid
|
|
11
|
+
from roms_tools.datasets.download import download_test_data
|
|
12
|
+
from roms_tools.datasets.roms_dataset import ROMSDataset, choose_subdomain
|
|
13
|
+
from roms_tools.setup.utils import get_target_coords
|
|
14
|
+
|
|
15
|
+
try:
|
|
16
|
+
import xesmf # type: ignore
|
|
17
|
+
except ImportError:
|
|
18
|
+
xesmf = None
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
@pytest.fixture
|
|
22
|
+
def roms_dataset_from_restart_file(use_dask):
|
|
23
|
+
fname_grid = Path(download_test_data("epac25km_grd.nc"))
|
|
24
|
+
grid = Grid.from_file(fname_grid)
|
|
25
|
+
|
|
26
|
+
# Single file
|
|
27
|
+
return ROMSDataset(
|
|
28
|
+
grid=grid,
|
|
29
|
+
path=Path(download_test_data("eastpac25km_rst.19980106000000.nc")),
|
|
30
|
+
use_dask=use_dask,
|
|
31
|
+
)
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
@pytest.fixture
|
|
35
|
+
def roms_dataset_from_restart_file_adjusted_for_zeta(use_dask):
|
|
36
|
+
fname_grid = Path(download_test_data("epac25km_grd.nc"))
|
|
37
|
+
grid = Grid.from_file(fname_grid)
|
|
38
|
+
|
|
39
|
+
# Single file
|
|
40
|
+
return ROMSDataset(
|
|
41
|
+
grid=grid,
|
|
42
|
+
path=Path(download_test_data("eastpac25km_rst.19980106000000.nc")),
|
|
43
|
+
adjust_depth_for_sea_surface_height=True,
|
|
44
|
+
use_dask=use_dask,
|
|
45
|
+
)
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
@pytest.fixture
|
|
49
|
+
def roms_dataset_from_restart_file_with_straddling_grid(use_dask):
|
|
50
|
+
# Make fake grid that straddles the dateline and that has consistent sizes with test data below
|
|
51
|
+
grid = Grid(
|
|
52
|
+
nx=8, ny=13, center_lon=0, center_lat=60, rot=32, size_x=244, size_y=365
|
|
53
|
+
)
|
|
54
|
+
|
|
55
|
+
return ROMSDataset(
|
|
56
|
+
grid=grid,
|
|
57
|
+
path=Path(download_test_data("eastpac25km_rst.19980106000000.nc")),
|
|
58
|
+
use_dask=use_dask,
|
|
59
|
+
)
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
@pytest.mark.parametrize(
|
|
63
|
+
"roms_dataset_fixture",
|
|
64
|
+
[
|
|
65
|
+
"roms_dataset_from_restart_file",
|
|
66
|
+
"roms_dataset_from_restart_file_adjusted_for_zeta",
|
|
67
|
+
"roms_dataset_from_restart_file_with_straddling_grid",
|
|
68
|
+
],
|
|
69
|
+
)
|
|
70
|
+
def test_load_model_output_file(roms_dataset_fixture, request):
|
|
71
|
+
roms_dataset = request.getfixturevalue(roms_dataset_fixture)
|
|
72
|
+
|
|
73
|
+
assert isinstance(roms_dataset.ds, xr.Dataset)
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
@pytest.fixture
|
|
77
|
+
def roms_dataset_from_two_restart_files(use_dask):
|
|
78
|
+
fname_grid = Path(download_test_data("epac25km_grd.nc"))
|
|
79
|
+
grid = Grid.from_file(fname_grid)
|
|
80
|
+
|
|
81
|
+
# List of files
|
|
82
|
+
file1 = Path(download_test_data("eastpac25km_rst.19980106000000.nc"))
|
|
83
|
+
file2 = Path(download_test_data("eastpac25km_rst.19980126000000.nc"))
|
|
84
|
+
return ROMSDataset(grid=grid, path=[file1, file2], use_dask=use_dask)
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
def test_load_model_output_file_list(roms_dataset_from_two_restart_files):
|
|
88
|
+
assert isinstance(roms_dataset_from_two_restart_files.ds, xr.Dataset)
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
def test_load_model_output_with_wildcard(use_dask):
|
|
92
|
+
fname_grid = Path(download_test_data("epac25km_grd.nc"))
|
|
93
|
+
grid = Grid.from_file(fname_grid)
|
|
94
|
+
|
|
95
|
+
# Download at least two files, so these will be found within the pooch directory
|
|
96
|
+
Path(download_test_data("eastpac25km_rst.19980106000000.nc"))
|
|
97
|
+
Path(download_test_data("eastpac25km_rst.19980126000000.nc"))
|
|
98
|
+
directory = Path(
|
|
99
|
+
os.path.dirname(download_test_data("eastpac25km_rst.19980106000000.nc"))
|
|
100
|
+
)
|
|
101
|
+
|
|
102
|
+
output = ROMSDataset(grid=grid, path=directory / "*rst*.nc", use_dask=use_dask)
|
|
103
|
+
assert isinstance(output.ds, xr.Dataset)
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
def test_invalid_path(use_dask):
|
|
107
|
+
fname_grid = Path(download_test_data("epac25km_grd.nc"))
|
|
108
|
+
grid = Grid.from_file(fname_grid)
|
|
109
|
+
|
|
110
|
+
# Non-existent file
|
|
111
|
+
with pytest.raises(FileNotFoundError):
|
|
112
|
+
ROMSDataset(
|
|
113
|
+
grid=grid,
|
|
114
|
+
path=Path("/path/to/nonexistent/file.nc"),
|
|
115
|
+
use_dask=use_dask,
|
|
116
|
+
)
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
def test_check_consistency_data_grid(use_dask):
|
|
120
|
+
grid_params = {
|
|
121
|
+
"nx": 5,
|
|
122
|
+
"ny": 5,
|
|
123
|
+
"center_lon": -128,
|
|
124
|
+
"center_lat": 9,
|
|
125
|
+
"size_x": 100,
|
|
126
|
+
"size_y": 100,
|
|
127
|
+
}
|
|
128
|
+
grid = Grid(**grid_params)
|
|
129
|
+
|
|
130
|
+
with pytest.raises(ValueError, match="Inconsistent dataset dimensions"):
|
|
131
|
+
ROMSDataset(
|
|
132
|
+
grid=grid,
|
|
133
|
+
path=Path(download_test_data("eastpac25km_rst.19980106000000.nc")),
|
|
134
|
+
use_dask=use_dask,
|
|
135
|
+
)
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
def test_set_correct_model_reference_date(use_dask):
|
|
139
|
+
fname_grid = Path(download_test_data("epac25km_grd.nc"))
|
|
140
|
+
grid = Grid.from_file(fname_grid)
|
|
141
|
+
|
|
142
|
+
output = ROMSDataset(
|
|
143
|
+
grid=grid,
|
|
144
|
+
path=Path(download_test_data("eastpac25km_rst.19980106000000.nc")),
|
|
145
|
+
use_dask=use_dask,
|
|
146
|
+
)
|
|
147
|
+
assert output.model_reference_date == datetime(1995, 1, 1)
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
def test_model_reference_date_mismatch(use_dask):
|
|
151
|
+
fname_grid = Path(download_test_data("epac25km_grd.nc"))
|
|
152
|
+
grid = Grid.from_file(fname_grid)
|
|
153
|
+
|
|
154
|
+
# Create a ROMSDataset with a specified model_reference_date
|
|
155
|
+
model_ref_date = datetime(2020, 1, 1)
|
|
156
|
+
with pytest.raises(
|
|
157
|
+
ValueError, match="Mismatch between `self.model_reference_date`"
|
|
158
|
+
):
|
|
159
|
+
ROMSDataset(
|
|
160
|
+
grid=grid,
|
|
161
|
+
path=Path(download_test_data("eastpac25km_rst.19980106000000.nc")),
|
|
162
|
+
model_reference_date=model_ref_date,
|
|
163
|
+
use_dask=use_dask,
|
|
164
|
+
)
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
def test_model_reference_date_no_metadata(use_dask, tmp_path, caplog):
|
|
168
|
+
# Helper function to handle the test logic for cases where metadata is missing or invalid
|
|
169
|
+
def test_no_metadata(faulty_ocean_time_attr, expected_exception, log_message=None):
|
|
170
|
+
ds = xr.open_dataset(fname)
|
|
171
|
+
ds["ocean_time"].attrs = faulty_ocean_time_attr
|
|
172
|
+
|
|
173
|
+
# Write modified dataset to a new file
|
|
174
|
+
fname_mod = tmp_path / "eastpac25km_rst.19980106000000_without_metadata.nc"
|
|
175
|
+
ds.to_netcdf(fname_mod)
|
|
176
|
+
|
|
177
|
+
# Test case 1: Expecting a ValueError when metadata is missing or invalid
|
|
178
|
+
with pytest.raises(
|
|
179
|
+
expected_exception,
|
|
180
|
+
match="Model reference date could not be inferred from the metadata",
|
|
181
|
+
):
|
|
182
|
+
ROMSDataset(grid=grid, path=fname_mod, use_dask=use_dask)
|
|
183
|
+
|
|
184
|
+
# Test case 2: When a model reference date is explicitly set, verify the warning
|
|
185
|
+
with caplog.at_level(logging.WARNING):
|
|
186
|
+
ROMSDataset(
|
|
187
|
+
grid=grid,
|
|
188
|
+
path=fname_mod,
|
|
189
|
+
model_reference_date=datetime(1995, 1, 1),
|
|
190
|
+
use_dask=use_dask,
|
|
191
|
+
)
|
|
192
|
+
|
|
193
|
+
if log_message:
|
|
194
|
+
# Verify the warning message in the log
|
|
195
|
+
assert log_message in caplog.text
|
|
196
|
+
|
|
197
|
+
fname_mod.unlink()
|
|
198
|
+
|
|
199
|
+
# Load grid and test data
|
|
200
|
+
fname_grid = Path(download_test_data("epac25km_grd.nc"))
|
|
201
|
+
grid = Grid.from_file(fname_grid)
|
|
202
|
+
fname = download_test_data("eastpac25km_rst.19980106000000.nc")
|
|
203
|
+
|
|
204
|
+
# Test 1: Ocean time attribute 'long_name' is missing
|
|
205
|
+
test_no_metadata({}, ValueError)
|
|
206
|
+
|
|
207
|
+
# Test 2: Ocean time attribute 'long_name' contains invalid information
|
|
208
|
+
test_no_metadata(
|
|
209
|
+
{"long_name": "some random text"},
|
|
210
|
+
ValueError,
|
|
211
|
+
"Could not infer the model reference date from the metadata.",
|
|
212
|
+
)
|
|
213
|
+
|
|
214
|
+
|
|
215
|
+
def test_compute_depth_coordinates(use_dask):
|
|
216
|
+
fname_grid = Path(download_test_data("epac25km_grd.nc"))
|
|
217
|
+
grid = Grid.from_file(fname_grid)
|
|
218
|
+
fname_restart1 = Path(download_test_data("eastpac25km_rst.19980106000000.nc"))
|
|
219
|
+
|
|
220
|
+
for adjust_depth_for_sea_surface_height in [True, False]:
|
|
221
|
+
output = ROMSDataset(
|
|
222
|
+
grid=grid,
|
|
223
|
+
path=fname_restart1,
|
|
224
|
+
use_dask=use_dask,
|
|
225
|
+
adjust_depth_for_sea_surface_height=adjust_depth_for_sea_surface_height,
|
|
226
|
+
)
|
|
227
|
+
|
|
228
|
+
# Before calling get_vertical_coordinates, check if the dataset doesn't already have depth coordinates
|
|
229
|
+
assert "layer_depth_rho" not in output.ds_depth_coords.data_vars
|
|
230
|
+
|
|
231
|
+
# Call the method to get vertical coordinates
|
|
232
|
+
output._get_depth_coordinates(depth_type="layer")
|
|
233
|
+
|
|
234
|
+
# Check if the depth coordinates were added
|
|
235
|
+
assert "layer_depth_rho" in output.ds_depth_coords.data_vars
|
|
236
|
+
|
|
237
|
+
|
|
238
|
+
def test_missing_zeta_gets_raised(use_dask):
|
|
239
|
+
"""Test that a ValueError is raised when `zeta` is missing from the dataset and
|
|
240
|
+
`adjust_depth_for_sea_surface_height` is enabled.
|
|
241
|
+
"""
|
|
242
|
+
# Load the grid
|
|
243
|
+
fname_grid = Path(download_test_data("epac25km_grd.nc"))
|
|
244
|
+
grid = Grid.from_file(fname_grid)
|
|
245
|
+
|
|
246
|
+
# Load the ROMS output
|
|
247
|
+
fname_restart1 = Path(download_test_data("eastpac25km_rst.19980106000000.nc"))
|
|
248
|
+
roms_output = ROMSDataset(
|
|
249
|
+
grid=grid,
|
|
250
|
+
path=fname_restart1,
|
|
251
|
+
use_dask=use_dask,
|
|
252
|
+
adjust_depth_for_sea_surface_height=True,
|
|
253
|
+
)
|
|
254
|
+
|
|
255
|
+
# Remove `zeta` from the dataset
|
|
256
|
+
object.__setattr__(
|
|
257
|
+
roms_output, "ds", roms_output.ds.drop_vars("zeta", errors="ignore")
|
|
258
|
+
)
|
|
259
|
+
|
|
260
|
+
# Expect ValueError when calling `_get_depth_coordinates`
|
|
261
|
+
with pytest.raises(
|
|
262
|
+
ValueError,
|
|
263
|
+
match="`zeta` is required in provided ROMS output when `adjust_depth_for_sea_surface_height` is enabled.",
|
|
264
|
+
):
|
|
265
|
+
roms_output._get_depth_coordinates()
|
|
266
|
+
|
|
267
|
+
|
|
268
|
+
def test_check_vertical_coordinate_mismatch(use_dask):
|
|
269
|
+
fname_grid = Path(download_test_data("epac25km_grd.nc"))
|
|
270
|
+
grid = Grid.from_file(fname_grid)
|
|
271
|
+
|
|
272
|
+
fname_restart1 = Path(download_test_data("eastpac25km_rst.19980106000000.nc"))
|
|
273
|
+
output = ROMSDataset(grid=grid, path=fname_restart1, use_dask=use_dask)
|
|
274
|
+
|
|
275
|
+
# create a mock dataset with inconsistent vertical coordinate parameters
|
|
276
|
+
ds_mock = output.ds.copy()
|
|
277
|
+
|
|
278
|
+
# Modify one of the vertical coordinate attributes to cause a mismatch
|
|
279
|
+
ds_mock.attrs["theta_s"] = 999
|
|
280
|
+
|
|
281
|
+
# Check if ValueError is raised due to mismatch
|
|
282
|
+
with pytest.raises(ValueError, match="theta_s from grid"):
|
|
283
|
+
output._check_vertical_coordinate(ds_mock)
|
|
284
|
+
|
|
285
|
+
# create a mock dataset with inconsistent vertical coordinate parameters
|
|
286
|
+
ds_mock = output.ds.copy()
|
|
287
|
+
|
|
288
|
+
# Modify one of the vertical coordinate attributes to cause a mismatch
|
|
289
|
+
ds_mock.attrs["Cs_w"] = ds_mock.attrs["Cs_w"] + 0.01
|
|
290
|
+
|
|
291
|
+
# Check if ValueError is raised due to mismatch
|
|
292
|
+
with pytest.raises(ValueError, match="Cs_w from grid"):
|
|
293
|
+
output._check_vertical_coordinate(ds_mock)
|
|
294
|
+
|
|
295
|
+
|
|
296
|
+
def test_that_coordinates_and_masks_are_added(use_dask):
|
|
297
|
+
fname_grid = Path(download_test_data("epac25km_grd.nc"))
|
|
298
|
+
grid = Grid.from_file(fname_grid)
|
|
299
|
+
|
|
300
|
+
fname_restart1 = Path(download_test_data("eastpac25km_rst.19980106000000.nc"))
|
|
301
|
+
output = ROMSDataset(grid=grid, path=fname_restart1, use_dask=use_dask)
|
|
302
|
+
|
|
303
|
+
assert "time" in output.ds.coords
|
|
304
|
+
assert "lat_rho" in output.ds.coords
|
|
305
|
+
assert "lon_rho" in output.ds.coords
|
|
306
|
+
assert "mask_rho" in output.ds
|
|
307
|
+
assert "mask_u" in output.ds
|
|
308
|
+
assert "mask_v" in output.ds
|
|
309
|
+
|
|
310
|
+
|
|
311
|
+
# Test applying lateral fill
|
|
312
|
+
|
|
313
|
+
|
|
314
|
+
def make_roms_dataset(ds, grid):
|
|
315
|
+
roms = ROMSDataset.__new__(ROMSDataset)
|
|
316
|
+
roms.ds = ds
|
|
317
|
+
roms.grid = grid
|
|
318
|
+
return roms
|
|
319
|
+
|
|
320
|
+
|
|
321
|
+
def test_apply_lateral_fill_rho_success():
|
|
322
|
+
grid = Grid(
|
|
323
|
+
nx=10, ny=10, size_x=2500, size_y=3000, center_lon=-30, center_lat=57, rot=-20
|
|
324
|
+
)
|
|
325
|
+
|
|
326
|
+
ds = xr.Dataset()
|
|
327
|
+
ds["field"] = 5 * grid.ds.mask_rho.copy()
|
|
328
|
+
ds["mask_rho"] = grid.ds.mask_rho.copy()
|
|
329
|
+
|
|
330
|
+
roms = make_roms_dataset(ds, grid)
|
|
331
|
+
|
|
332
|
+
# land exists initially
|
|
333
|
+
assert (roms.ds["field"] == 0).any()
|
|
334
|
+
|
|
335
|
+
roms.apply_lateral_fill()
|
|
336
|
+
|
|
337
|
+
assert (roms.ds["field"] == 5).all()
|
|
338
|
+
|
|
339
|
+
|
|
340
|
+
def test_apply_lateral_fill_rho_missing_mask_raises():
|
|
341
|
+
grid = Grid(
|
|
342
|
+
nx=10, ny=10, size_x=2500, size_y=3000, center_lon=-30, center_lat=57, rot=-20
|
|
343
|
+
)
|
|
344
|
+
|
|
345
|
+
ds = xr.Dataset()
|
|
346
|
+
ds["field"] = grid.ds.mask_rho.copy()
|
|
347
|
+
|
|
348
|
+
roms = make_roms_dataset(ds, grid)
|
|
349
|
+
|
|
350
|
+
with pytest.raises(ValueError, match="mask_rho"):
|
|
351
|
+
roms.apply_lateral_fill()
|
|
352
|
+
|
|
353
|
+
|
|
354
|
+
def test_apply_lateral_fill_u_success():
|
|
355
|
+
grid = Grid(
|
|
356
|
+
nx=10, ny=10, size_x=2500, size_y=3000, center_lon=-30, center_lat=57, rot=-20
|
|
357
|
+
)
|
|
358
|
+
|
|
359
|
+
ds = xr.Dataset()
|
|
360
|
+
ds["u_field"] = 7 * grid.ds.mask_u.copy()
|
|
361
|
+
ds["mask_u"] = grid.ds.mask_u.copy()
|
|
362
|
+
|
|
363
|
+
roms = make_roms_dataset(ds, grid)
|
|
364
|
+
|
|
365
|
+
assert (roms.ds["u_field"] == 0).any()
|
|
366
|
+
|
|
367
|
+
roms.apply_lateral_fill()
|
|
368
|
+
|
|
369
|
+
assert (roms.ds["u_field"] == 7).all()
|
|
370
|
+
|
|
371
|
+
|
|
372
|
+
def test_apply_lateral_fill_u_missing_mask_raises():
|
|
373
|
+
grid = Grid(
|
|
374
|
+
nx=10, ny=10, size_x=2500, size_y=3000, center_lon=-30, center_lat=57, rot=-20
|
|
375
|
+
)
|
|
376
|
+
|
|
377
|
+
ds = xr.Dataset()
|
|
378
|
+
ds["u_field"] = grid.ds.mask_u.copy()
|
|
379
|
+
ds["mask_rho"] = grid.ds.mask_rho.copy()
|
|
380
|
+
|
|
381
|
+
roms = make_roms_dataset(ds, grid)
|
|
382
|
+
|
|
383
|
+
with pytest.raises(ValueError, match="mask_u"):
|
|
384
|
+
roms.apply_lateral_fill()
|
|
385
|
+
|
|
386
|
+
|
|
387
|
+
def test_apply_lateral_fill_v_success():
|
|
388
|
+
grid = Grid(
|
|
389
|
+
nx=10, ny=10, size_x=2500, size_y=3000, center_lon=-30, center_lat=57, rot=-20
|
|
390
|
+
)
|
|
391
|
+
|
|
392
|
+
ds = xr.Dataset()
|
|
393
|
+
ds["v_field"] = 9 * grid.ds.mask_v.copy()
|
|
394
|
+
ds["mask_v"] = grid.ds.mask_v.copy()
|
|
395
|
+
|
|
396
|
+
roms = make_roms_dataset(ds, grid)
|
|
397
|
+
|
|
398
|
+
assert (roms.ds["v_field"] == 0).any()
|
|
399
|
+
|
|
400
|
+
roms.apply_lateral_fill()
|
|
401
|
+
|
|
402
|
+
assert (roms.ds["v_field"] == 9).all()
|
|
403
|
+
|
|
404
|
+
|
|
405
|
+
def test_apply_lateral_fill_v_missing_mask_raises():
|
|
406
|
+
grid = Grid(
|
|
407
|
+
nx=10, ny=10, size_x=2500, size_y=3000, center_lon=-30, center_lat=57, rot=-20
|
|
408
|
+
)
|
|
409
|
+
|
|
410
|
+
ds = xr.Dataset()
|
|
411
|
+
ds["v_field"] = grid.ds.mask_v.copy()
|
|
412
|
+
ds["mask_rho"] = grid.ds.mask_rho.copy()
|
|
413
|
+
|
|
414
|
+
roms = make_roms_dataset(ds, grid)
|
|
415
|
+
|
|
416
|
+
with pytest.raises(ValueError, match="mask_v"):
|
|
417
|
+
roms.apply_lateral_fill()
|
|
418
|
+
|
|
419
|
+
|
|
420
|
+
def test_apply_lateral_fill_mixed_grids():
|
|
421
|
+
grid = Grid(
|
|
422
|
+
nx=10, ny=10, size_x=2500, size_y=3000, center_lon=-30, center_lat=57, rot=-20
|
|
423
|
+
)
|
|
424
|
+
|
|
425
|
+
ds = xr.Dataset()
|
|
426
|
+
ds["rho"] = 1 * grid.ds.mask_rho.copy()
|
|
427
|
+
ds["u"] = 2 * grid.ds.mask_u.copy()
|
|
428
|
+
ds["v"] = 3 * grid.ds.mask_v.copy()
|
|
429
|
+
|
|
430
|
+
ds["mask_rho"] = grid.ds.mask_rho.copy()
|
|
431
|
+
ds["mask_u"] = grid.ds.mask_u.copy()
|
|
432
|
+
ds["mask_v"] = grid.ds.mask_v.copy()
|
|
433
|
+
|
|
434
|
+
roms = make_roms_dataset(ds, grid)
|
|
435
|
+
|
|
436
|
+
roms.apply_lateral_fill()
|
|
437
|
+
|
|
438
|
+
assert (roms.ds["rho"] == 1).all()
|
|
439
|
+
assert (roms.ds["u"] == 2).all()
|
|
440
|
+
assert (roms.ds["v"] == 3).all()
|
|
441
|
+
|
|
442
|
+
|
|
443
|
+
# Test choose_subdomain
|
|
444
|
+
grid_cases = [
|
|
445
|
+
# --- SMALL INSIDE WESTERN HEMISPHERE -----------------------------------
|
|
446
|
+
(
|
|
447
|
+
# big grid west, does NOT cross Greenwich
|
|
448
|
+
{
|
|
449
|
+
"nx": 40,
|
|
450
|
+
"ny": 40,
|
|
451
|
+
"size_x": 4000,
|
|
452
|
+
"size_y": 4000,
|
|
453
|
+
"center_lon": -30,
|
|
454
|
+
"center_lat": 50,
|
|
455
|
+
"rot": 0,
|
|
456
|
+
},
|
|
457
|
+
# small grid fully west
|
|
458
|
+
{
|
|
459
|
+
"nx": 10,
|
|
460
|
+
"ny": 10,
|
|
461
|
+
"size_x": 500,
|
|
462
|
+
"size_y": 500,
|
|
463
|
+
"center_lon": -20,
|
|
464
|
+
"center_lat": 50,
|
|
465
|
+
"rot": 0,
|
|
466
|
+
},
|
|
467
|
+
),
|
|
468
|
+
# --- SMALL INSIDE EASTERN HEMISPHERE ----------------------------------
|
|
469
|
+
(
|
|
470
|
+
{
|
|
471
|
+
"nx": 40,
|
|
472
|
+
"ny": 40,
|
|
473
|
+
"size_x": 4000,
|
|
474
|
+
"size_y": 4000,
|
|
475
|
+
"center_lon": 10,
|
|
476
|
+
"center_lat": 45,
|
|
477
|
+
"rot": 0,
|
|
478
|
+
},
|
|
479
|
+
{
|
|
480
|
+
"nx": 10,
|
|
481
|
+
"ny": 10,
|
|
482
|
+
"size_x": 500,
|
|
483
|
+
"size_y": 500,
|
|
484
|
+
"center_lon": 20,
|
|
485
|
+
"center_lat": 45,
|
|
486
|
+
"rot": 0,
|
|
487
|
+
},
|
|
488
|
+
),
|
|
489
|
+
# --- SMALL GRID STRADDLING GREENWICH ----------------------------------
|
|
490
|
+
(
|
|
491
|
+
# big grid centered slightly west
|
|
492
|
+
{
|
|
493
|
+
"nx": 40,
|
|
494
|
+
"ny": 40,
|
|
495
|
+
"size_x": 5000,
|
|
496
|
+
"size_y": 4000,
|
|
497
|
+
"center_lon": -5,
|
|
498
|
+
"center_lat": 45,
|
|
499
|
+
"rot": 0,
|
|
500
|
+
},
|
|
501
|
+
# small grid crosses 0°
|
|
502
|
+
{
|
|
503
|
+
"nx": 10,
|
|
504
|
+
"ny": 10,
|
|
505
|
+
"size_x": 600,
|
|
506
|
+
"size_y": 600,
|
|
507
|
+
"center_lon": 0,
|
|
508
|
+
"center_lat": 45,
|
|
509
|
+
"rot": 0,
|
|
510
|
+
},
|
|
511
|
+
),
|
|
512
|
+
# --- LARGE GRID CROSSES GREENWICH, SMALL IS WEST -----------------------
|
|
513
|
+
(
|
|
514
|
+
{
|
|
515
|
+
"nx": 50,
|
|
516
|
+
"ny": 50,
|
|
517
|
+
"size_x": 8000,
|
|
518
|
+
"size_y": 5000,
|
|
519
|
+
"center_lon": -2,
|
|
520
|
+
"center_lat": 40,
|
|
521
|
+
"rot": 0,
|
|
522
|
+
},
|
|
523
|
+
{
|
|
524
|
+
"nx": 10,
|
|
525
|
+
"ny": 10,
|
|
526
|
+
"size_x": 400,
|
|
527
|
+
"size_y": 400,
|
|
528
|
+
"center_lon": -10,
|
|
529
|
+
"center_lat": 40,
|
|
530
|
+
"rot": 0,
|
|
531
|
+
},
|
|
532
|
+
),
|
|
533
|
+
# --- LARGE GRID CROSSES GREENWICH, SMALL IS EAST -----------------------
|
|
534
|
+
(
|
|
535
|
+
{
|
|
536
|
+
"nx": 50,
|
|
537
|
+
"ny": 50,
|
|
538
|
+
"size_x": 8000,
|
|
539
|
+
"size_y": 5000,
|
|
540
|
+
"center_lon": -2,
|
|
541
|
+
"center_lat": 40,
|
|
542
|
+
"rot": 0,
|
|
543
|
+
},
|
|
544
|
+
{
|
|
545
|
+
"nx": 10,
|
|
546
|
+
"ny": 10,
|
|
547
|
+
"size_x": 400,
|
|
548
|
+
"size_y": 400,
|
|
549
|
+
"center_lon": 8,
|
|
550
|
+
"center_lat": 40,
|
|
551
|
+
"rot": 0,
|
|
552
|
+
},
|
|
553
|
+
),
|
|
554
|
+
# --- BOTH GRIDS CROSS GREENWICH ---------------------------------------
|
|
555
|
+
(
|
|
556
|
+
{
|
|
557
|
+
"nx": 60,
|
|
558
|
+
"ny": 60,
|
|
559
|
+
"size_x": 9000,
|
|
560
|
+
"size_y": 6000,
|
|
561
|
+
"center_lon": 1,
|
|
562
|
+
"center_lat": 48,
|
|
563
|
+
"rot": 0,
|
|
564
|
+
},
|
|
565
|
+
{
|
|
566
|
+
"nx": 12,
|
|
567
|
+
"ny": 12,
|
|
568
|
+
"size_x": 900,
|
|
569
|
+
"size_y": 900,
|
|
570
|
+
"center_lon": -1,
|
|
571
|
+
"center_lat": 48,
|
|
572
|
+
"rot": 0,
|
|
573
|
+
},
|
|
574
|
+
),
|
|
575
|
+
]
|
|
576
|
+
|
|
577
|
+
|
|
578
|
+
# ----------------------------------------------------------------------
|
|
579
|
+
# THE TEST
|
|
580
|
+
# ----------------------------------------------------------------------
|
|
581
|
+
|
|
582
|
+
|
|
583
|
+
@pytest.mark.parametrize(
|
|
584
|
+
"big_params, small_params",
|
|
585
|
+
grid_cases,
|
|
586
|
+
)
|
|
587
|
+
def test_choose_subdomain_with(big_params, small_params):
|
|
588
|
+
"""Tests choose_subdomain() for rho, u, and v points over various grid configurations."""
|
|
589
|
+
# --- build big grid ---
|
|
590
|
+
big = Grid(**big_params)
|
|
591
|
+
ds = xr.Dataset()
|
|
592
|
+
ds = ds.assign_coords(
|
|
593
|
+
{
|
|
594
|
+
"lat_rho": big.ds.lat_rho,
|
|
595
|
+
"lon_rho": big.ds.lon_rho,
|
|
596
|
+
"lat_u": big.ds.lat_u,
|
|
597
|
+
"lon_u": big.ds.lon_u,
|
|
598
|
+
"lat_v": big.ds.lat_v,
|
|
599
|
+
"lon_v": big.ds.lon_v,
|
|
600
|
+
}
|
|
601
|
+
)
|
|
602
|
+
|
|
603
|
+
# simple fields for testing
|
|
604
|
+
ds["field_rho"] = (
|
|
605
|
+
("eta_rho", "xi_rho"),
|
|
606
|
+
(big.ds["eta_rho"] * big.ds["xi_rho"]).values,
|
|
607
|
+
)
|
|
608
|
+
ds["field_u"] = (("eta_rho", "xi_u"), np.random.rand(*big.ds["lat_u"].shape))
|
|
609
|
+
ds["field_v"] = (("eta_v", "xi_rho"), np.random.rand(*big.ds["lat_v"].shape))
|
|
610
|
+
|
|
611
|
+
# --- build small grid ---
|
|
612
|
+
small = Grid(**small_params)
|
|
613
|
+
target_coords = get_target_coords(small)
|
|
614
|
+
|
|
615
|
+
# --- apply function ---
|
|
616
|
+
sub = choose_subdomain(ds, big.ds, target_coords, buffer_points=10)
|
|
617
|
+
# --- rho tests ---
|
|
618
|
+
assert sub.lat_rho.shape[0] <= ds.lat_rho.shape[0]
|
|
619
|
+
assert sub.lat_rho.shape[1] <= ds.lat_rho.shape[1]
|
|
620
|
+
assert float(sub.lat_rho.min()) >= float(ds.lat_rho.min()) - 1e-6
|
|
621
|
+
assert float(sub.lat_rho.max()) <= float(ds.lat_rho.max()) + 1e-6
|
|
622
|
+
assert not sub.field_rho.isnull().any()
|
|
623
|
+
|
|
624
|
+
# --- u tests ---
|
|
625
|
+
if "lat_u" in sub.coords and "lon_u" in sub.coords:
|
|
626
|
+
assert sub.lat_u.shape[0] <= ds.lat_u.shape[0]
|
|
627
|
+
assert sub.lat_u.shape[1] <= ds.lat_u.shape[1]
|
|
628
|
+
assert float(sub.lat_u.min()) >= float(ds.lat_u.min()) - 1e-6
|
|
629
|
+
assert float(sub.lat_u.max()) <= float(ds.lat_u.max()) + 1e-6
|
|
630
|
+
assert not sub.field_u.isnull().any()
|
|
631
|
+
|
|
632
|
+
# --- v tests ---
|
|
633
|
+
if "lat_v" in sub.coords and "lon_v" in sub.coords:
|
|
634
|
+
assert sub.lat_v.shape[0] <= ds.lat_v.shape[0]
|
|
635
|
+
assert sub.lat_v.shape[1] <= ds.lat_v.shape[1]
|
|
636
|
+
assert float(sub.lat_v.min()) >= float(ds.lat_v.min()) - 1e-6
|
|
637
|
+
assert float(sub.lat_v.max()) <= float(ds.lat_v.max()) + 1e-6
|
|
638
|
+
assert not sub.field_v.isnull().any()
|
|
639
|
+
|
|
640
|
+
|
|
641
|
+
def test_choose_subdomain_dataset_and_grid(use_dask):
|
|
642
|
+
fname_grid = Path(download_test_data("epac25km_grd.nc"))
|
|
643
|
+
grid = Grid.from_file(fname_grid)
|
|
644
|
+
|
|
645
|
+
roms_dataset = ROMSDataset(
|
|
646
|
+
grid=grid,
|
|
647
|
+
path=Path(download_test_data("eastpac25km_rst.19980106000000.nc")),
|
|
648
|
+
use_dask=use_dask,
|
|
649
|
+
)
|
|
650
|
+
|
|
651
|
+
# Save original sizes
|
|
652
|
+
orig_grid_sizes = dict(roms_dataset.grid.ds.sizes)
|
|
653
|
+
orig_ds_sizes = dict(roms_dataset.ds.sizes)
|
|
654
|
+
|
|
655
|
+
# Create a small child grid and target coordinates
|
|
656
|
+
child_grid = Grid(
|
|
657
|
+
nx=5,
|
|
658
|
+
ny=5,
|
|
659
|
+
size_x=100,
|
|
660
|
+
size_y=100,
|
|
661
|
+
center_lon=-128.0,
|
|
662
|
+
center_lat=9.0,
|
|
663
|
+
rot=32.0,
|
|
664
|
+
)
|
|
665
|
+
target_coords = get_target_coords(child_grid)
|
|
666
|
+
|
|
667
|
+
# Apply subdomain selection
|
|
668
|
+
roms_dataset.choose_subdomain(target_coords, buffer_points=1)
|
|
669
|
+
|
|
670
|
+
new_grid_sizes = dict(roms_dataset.grid.ds.sizes)
|
|
671
|
+
new_ds_sizes = dict(roms_dataset.ds.sizes)
|
|
672
|
+
|
|
673
|
+
# Grid and dataset should both be reduced
|
|
674
|
+
assert new_grid_sizes != orig_grid_sizes, (
|
|
675
|
+
"Grid sizes did not change after choose_subdomain"
|
|
676
|
+
)
|
|
677
|
+
assert new_ds_sizes != orig_ds_sizes, (
|
|
678
|
+
"Dataset sizes did not change after choose_subdomain"
|
|
679
|
+
)
|
|
680
|
+
|
|
681
|
+
# Grid and dataset should remain consistent with each other
|
|
682
|
+
joint_dims = ["eta_rho", "xi_rho", "xi_u", "eta_v", "s_rho"]
|
|
683
|
+
|
|
684
|
+
for dim in joint_dims:
|
|
685
|
+
assert new_grid_sizes.get(dim) == new_ds_sizes.get(dim), (
|
|
686
|
+
f"Mismatch in dimension '{dim}': "
|
|
687
|
+
f"grid={new_grid_sizes.get(dim)}, ds={new_ds_sizes.get(dim)}"
|
|
688
|
+
)
|
|
689
|
+
|
|
690
|
+
|
|
691
|
+
def test_choose_subdomain_does_not_mutate_shared_grid(use_dask):
|
|
692
|
+
fname_grid = Path(download_test_data("epac25km_grd.nc"))
|
|
693
|
+
grid = Grid.from_file(fname_grid)
|
|
694
|
+
|
|
695
|
+
rd1 = ROMSDataset(
|
|
696
|
+
grid=grid,
|
|
697
|
+
path=Path(download_test_data("eastpac25km_rst.19980106000000.nc")),
|
|
698
|
+
use_dask=use_dask,
|
|
699
|
+
)
|
|
700
|
+
rd2 = ROMSDataset(
|
|
701
|
+
grid=grid,
|
|
702
|
+
path=Path(download_test_data("eastpac25km_rst.19980106000000.nc")),
|
|
703
|
+
use_dask=use_dask,
|
|
704
|
+
)
|
|
705
|
+
|
|
706
|
+
child_grid = Grid(
|
|
707
|
+
nx=5,
|
|
708
|
+
ny=5,
|
|
709
|
+
size_x=100,
|
|
710
|
+
size_y=100,
|
|
711
|
+
center_lon=-128.0,
|
|
712
|
+
center_lat=9.0,
|
|
713
|
+
rot=32.0,
|
|
714
|
+
)
|
|
715
|
+
target_coords = get_target_coords(child_grid)
|
|
716
|
+
rd1.choose_subdomain(target_coords, buffer_points=1)
|
|
717
|
+
|
|
718
|
+
assert rd2.grid.ds.sizes == grid.ds.sizes
|
|
719
|
+
|
|
720
|
+
|
|
721
|
+
def test_choose_subdomain_then_compute_depth_coordinates(use_dask):
|
|
722
|
+
fname_grid = Path(download_test_data("epac25km_grd.nc"))
|
|
723
|
+
grid = Grid.from_file(fname_grid)
|
|
724
|
+
|
|
725
|
+
rd = ROMSDataset(
|
|
726
|
+
grid=grid,
|
|
727
|
+
path=Path(download_test_data("eastpac25km_rst.19980106000000.nc")),
|
|
728
|
+
use_dask=use_dask,
|
|
729
|
+
)
|
|
730
|
+
|
|
731
|
+
child_grid = Grid(
|
|
732
|
+
nx=5,
|
|
733
|
+
ny=5,
|
|
734
|
+
size_x=100,
|
|
735
|
+
size_y=100,
|
|
736
|
+
center_lon=-128.0,
|
|
737
|
+
center_lat=9.0,
|
|
738
|
+
rot=32.0,
|
|
739
|
+
)
|
|
740
|
+
target_coords = get_target_coords(child_grid)
|
|
741
|
+
rd.choose_subdomain(target_coords, buffer_points=1)
|
|
742
|
+
|
|
743
|
+
rd._get_depth_coordinates(locations=["rho", "u", "v"])
|