roms-tools 1.4.2__py3-none-any.whl → 1.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/_version.py +1 -1
- roms_tools/setup/boundary_forcing.py +276 -99
- roms_tools/setup/datasets.py +19 -15
- roms_tools/setup/fill.py +38 -2
- roms_tools/setup/initial_conditions.py +170 -44
- roms_tools/setup/regrid.py +198 -0
- roms_tools/setup/surface_forcing.py +136 -51
- roms_tools/setup/tides.py +103 -31
- roms_tools/setup/utils.py +235 -40
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/.zattrs +1 -1
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/.zmetadata +1 -1
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/ALK_ALT_CO2_east/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/ALK_ALT_CO2_north/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/ALK_ALT_CO2_south/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/ALK_ALT_CO2_west/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/ALK_east/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/ALK_north/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/ALK_south/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/ALK_west/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/DIC_ALT_CO2_east/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/DIC_ALT_CO2_north/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/DIC_ALT_CO2_south/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/DIC_ALT_CO2_west/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/DIC_east/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/DIC_north/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/DIC_south/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/DIC_west/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/DOC_east/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/DOC_north/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/DOC_south/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/DOC_west/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/DOCr_east/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/DOCr_north/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/DOCr_south/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/DOCr_west/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/DON_east/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/DON_north/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/DON_south/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/DON_west/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/DONr_east/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/DONr_north/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/DONr_south/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/DONr_west/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/DOP_east/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/DOP_north/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/DOP_south/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/DOP_west/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/DOPr_east/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/DOPr_north/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/DOPr_south/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/DOPr_west/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/Fe_east/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/Fe_north/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/Fe_south/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/Fe_west/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/Lig_east/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/Lig_north/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/Lig_south/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/Lig_west/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/NH4_east/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/NH4_north/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/NH4_south/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/NH4_west/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/NO3_east/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/NO3_north/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/NO3_south/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/NO3_west/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/O2_east/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/O2_north/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/O2_south/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/O2_west/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/PO4_east/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/PO4_north/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/PO4_south/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/PO4_west/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/SiO3_east/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/SiO3_north/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/SiO3_south/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/SiO3_west/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/diatC_east/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/diatC_north/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/diatC_south/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/diatC_west/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/diatChl_east/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/diatChl_north/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/diatChl_south/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/diatChl_west/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/diatFe_east/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/diatFe_north/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/diatFe_south/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/diatFe_west/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/diatP_east/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/diatP_north/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/diatP_south/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/diatP_west/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/diatSi_east/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/diatSi_north/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/diatSi_south/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/diatSi_west/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/diazC_east/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/diazC_north/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/diazC_south/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/diazC_west/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/diazChl_east/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/diazChl_north/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/diazChl_south/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/diazChl_west/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/diazFe_east/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/diazFe_north/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/diazFe_south/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/diazFe_west/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/diazP_east/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/diazP_north/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/diazP_south/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/diazP_west/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/spC_east/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/spC_north/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/spC_south/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/spC_west/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/spCaCO3_east/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/spCaCO3_north/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/spCaCO3_south/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/spCaCO3_west/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/spChl_east/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/spChl_north/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/spChl_south/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/spChl_west/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/spFe_east/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/spFe_north/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/spFe_south/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/spFe_west/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/spP_east/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/spP_north/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/spP_south/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/spP_west/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/zooC_east/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/zooC_north/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/zooC_south/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_boundary_forcing_from_climatology.zarr/zooC_west/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_surface_forcing.zarr/.zattrs +1 -1
- roms_tools/tests/test_setup/test_data/bgc_surface_forcing.zarr/.zmetadata +1 -1
- roms_tools/tests/test_setup/test_data/bgc_surface_forcing.zarr/pco2_air_alt/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/bgc_surface_forcing_from_climatology.zarr/.zattrs +1 -1
- roms_tools/tests/test_setup/test_data/bgc_surface_forcing_from_climatology.zarr/.zmetadata +1 -1
- roms_tools/tests/test_setup/test_data/bgc_surface_forcing_from_climatology.zarr/pco2_air_alt/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/boundary_forcing.zarr/.zattrs +1 -1
- roms_tools/tests/test_setup/test_data/boundary_forcing.zarr/.zmetadata +1 -1
- roms_tools/tests/test_setup/test_data/boundary_forcing.zarr/salt_east/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/boundary_forcing.zarr/salt_north/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/boundary_forcing.zarr/salt_south/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/boundary_forcing.zarr/salt_west/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/boundary_forcing.zarr/temp_east/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/boundary_forcing.zarr/temp_north/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/boundary_forcing.zarr/temp_south/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/boundary_forcing.zarr/temp_west/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/boundary_forcing.zarr/u_east/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/boundary_forcing.zarr/u_north/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/boundary_forcing.zarr/u_south/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/boundary_forcing.zarr/u_west/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/boundary_forcing.zarr/ubar_east/0.0 +0 -0
- roms_tools/tests/test_setup/test_data/boundary_forcing.zarr/ubar_north/0.0 +0 -0
- roms_tools/tests/test_setup/test_data/boundary_forcing.zarr/ubar_south/0.0 +0 -0
- roms_tools/tests/test_setup/test_data/boundary_forcing.zarr/ubar_west/0.0 +0 -0
- roms_tools/tests/test_setup/test_data/boundary_forcing.zarr/v_east/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/boundary_forcing.zarr/v_north/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/boundary_forcing.zarr/v_south/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/boundary_forcing.zarr/v_west/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/boundary_forcing.zarr/vbar_east/0.0 +0 -0
- roms_tools/tests/test_setup/test_data/boundary_forcing.zarr/vbar_north/0.0 +0 -0
- roms_tools/tests/test_setup/test_data/boundary_forcing.zarr/vbar_south/0.0 +0 -0
- roms_tools/tests/test_setup/test_data/boundary_forcing.zarr/vbar_west/0.0 +0 -0
- roms_tools/tests/test_setup/test_data/boundary_forcing.zarr/zeta_east/0.0 +0 -0
- roms_tools/tests/test_setup/test_data/boundary_forcing.zarr/zeta_south/0.0 +0 -0
- roms_tools/tests/test_setup/test_data/initial_conditions_with_bgc_from_climatology.zarr/.zattrs +1 -1
- roms_tools/tests/test_setup/test_data/initial_conditions_with_bgc_from_climatology.zarr/.zmetadata +1 -1
- roms_tools/tests/test_setup/test_data/initial_conditions_with_bgc_from_climatology.zarr/ALK/0.0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/initial_conditions_with_bgc_from_climatology.zarr/ALK_ALT_CO2/0.0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/initial_conditions_with_bgc_from_climatology.zarr/DIC/0.0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/initial_conditions_with_bgc_from_climatology.zarr/DIC_ALT_CO2/0.0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/initial_conditions_with_bgc_from_climatology.zarr/DOC/0.0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/initial_conditions_with_bgc_from_climatology.zarr/DOCr/0.0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/initial_conditions_with_bgc_from_climatology.zarr/DON/0.0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/initial_conditions_with_bgc_from_climatology.zarr/DONr/0.0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/initial_conditions_with_bgc_from_climatology.zarr/DOP/0.0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/initial_conditions_with_bgc_from_climatology.zarr/DOPr/0.0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/initial_conditions_with_bgc_from_climatology.zarr/Fe/0.0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/initial_conditions_with_bgc_from_climatology.zarr/Lig/0.0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/initial_conditions_with_bgc_from_climatology.zarr/NH4/0.0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/initial_conditions_with_bgc_from_climatology.zarr/NO3/0.0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/initial_conditions_with_bgc_from_climatology.zarr/O2/0.0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/initial_conditions_with_bgc_from_climatology.zarr/PO4/0.0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/initial_conditions_with_bgc_from_climatology.zarr/SiO3/0.0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/initial_conditions_with_bgc_from_climatology.zarr/diatC/0.0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/initial_conditions_with_bgc_from_climatology.zarr/diatChl/0.0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/initial_conditions_with_bgc_from_climatology.zarr/diatFe/0.0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/initial_conditions_with_bgc_from_climatology.zarr/diatP/0.0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/initial_conditions_with_bgc_from_climatology.zarr/diatSi/0.0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/initial_conditions_with_bgc_from_climatology.zarr/diazC/0.0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/initial_conditions_with_bgc_from_climatology.zarr/diazChl/0.0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/initial_conditions_with_bgc_from_climatology.zarr/diazFe/0.0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/initial_conditions_with_bgc_from_climatology.zarr/diazP/0.0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/initial_conditions_with_bgc_from_climatology.zarr/salt/0.0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/initial_conditions_with_bgc_from_climatology.zarr/spC/0.0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/initial_conditions_with_bgc_from_climatology.zarr/spCaCO3/0.0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/initial_conditions_with_bgc_from_climatology.zarr/spChl/0.0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/initial_conditions_with_bgc_from_climatology.zarr/spFe/0.0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/initial_conditions_with_bgc_from_climatology.zarr/spP/0.0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/initial_conditions_with_bgc_from_climatology.zarr/temp/0.0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/initial_conditions_with_bgc_from_climatology.zarr/u/0.0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/initial_conditions_with_bgc_from_climatology.zarr/ubar/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/initial_conditions_with_bgc_from_climatology.zarr/v/0.0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/initial_conditions_with_bgc_from_climatology.zarr/vbar/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/initial_conditions_with_bgc_from_climatology.zarr/zeta/0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/initial_conditions_with_bgc_from_climatology.zarr/zooC/0.0.0.0 +0 -0
- roms_tools/tests/test_setup/test_fill.py +43 -14
- roms_tools/tests/test_setup/test_regrid.py +59 -0
- roms_tools/tests/test_setup/test_surface_forcing.py +18 -0
- {roms_tools-1.4.2.dist-info → roms_tools-1.5.0.dist-info}/METADATA +2 -2
- {roms_tools-1.4.2.dist-info → roms_tools-1.5.0.dist-info}/RECORD +222 -221
- roms_tools/setup/mixins.py +0 -227
- {roms_tools-1.4.2.dist-info → roms_tools-1.5.0.dist-info}/LICENSE +0 -0
- {roms_tools-1.4.2.dist-info → roms_tools-1.5.0.dist-info}/WHEEL +0 -0
- {roms_tools-1.4.2.dist-info → roms_tools-1.5.0.dist-info}/top_level.txt +0 -0
|
@@ -12,15 +12,21 @@ from roms_tools.setup.utils import (
|
|
|
12
12
|
substitute_nans_by_fillvalue,
|
|
13
13
|
get_variable_metadata,
|
|
14
14
|
save_datasets,
|
|
15
|
+
get_target_coords,
|
|
16
|
+
rotate_velocities,
|
|
17
|
+
compute_barotropic_velocity,
|
|
18
|
+
_extrapolate_deepest_to_bottom,
|
|
19
|
+
transpose_dimensions,
|
|
15
20
|
)
|
|
16
|
-
from roms_tools.setup.
|
|
21
|
+
from roms_tools.setup.fill import _lateral_fill
|
|
22
|
+
from roms_tools.setup.regrid import _lateral_regrid, _vertical_regrid
|
|
17
23
|
from roms_tools.setup.plot import _plot, _section_plot, _profile_plot, _line_plot
|
|
18
24
|
import matplotlib.pyplot as plt
|
|
19
25
|
from pathlib import Path
|
|
20
26
|
|
|
21
27
|
|
|
22
28
|
@dataclass(frozen=True, kw_only=True)
|
|
23
|
-
class InitialConditions
|
|
29
|
+
class InitialConditions:
|
|
24
30
|
"""Represents initial conditions for ROMS, including physical and biogeochemical
|
|
25
31
|
data.
|
|
26
32
|
|
|
@@ -85,42 +91,15 @@ class InitialConditions(ROMSToolsMixins):
|
|
|
85
91
|
def __post_init__(self):
|
|
86
92
|
|
|
87
93
|
self._input_checks()
|
|
88
|
-
lon, lat, angle, straddle = super()._get_target_lon_lat()
|
|
89
94
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
latitude_range=[lat.min().values, lat.max().values],
|
|
93
|
-
longitude_range=[lon.min().values, lon.max().values],
|
|
94
|
-
margin=2,
|
|
95
|
-
straddle=straddle,
|
|
96
|
-
)
|
|
97
|
-
|
|
98
|
-
vars_2d = ["zeta"]
|
|
99
|
-
vars_3d = ["temp", "salt", "u", "v"]
|
|
100
|
-
data_vars = super()._regrid_data(data, vars_2d, vars_3d, lon, lat)
|
|
101
|
-
data_vars = super()._process_velocities(data_vars, angle, "u", "v")
|
|
95
|
+
data_vars = {}
|
|
96
|
+
data_vars = self._process_data(data_vars, type="physics")
|
|
102
97
|
|
|
103
98
|
if self.bgc_source is not None:
|
|
104
|
-
|
|
105
|
-
bgc_data.choose_subdomain(
|
|
106
|
-
latitude_range=[lat.min().values, lat.max().values],
|
|
107
|
-
longitude_range=[lon.min().values, lon.max().values],
|
|
108
|
-
margin=2,
|
|
109
|
-
straddle=straddle,
|
|
110
|
-
)
|
|
111
|
-
|
|
112
|
-
vars_2d = []
|
|
113
|
-
vars_3d = bgc_data.var_names.keys()
|
|
114
|
-
bgc_data_vars = super()._regrid_data(bgc_data, vars_2d, vars_3d, lon, lat)
|
|
99
|
+
data_vars = self._process_data(data_vars, type="bgc")
|
|
115
100
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
bgc_data_vars[var] = bgc_data_vars[var].assign_coords(
|
|
119
|
-
{"time": data_vars["temp"]["time"]}
|
|
120
|
-
)
|
|
121
|
-
|
|
122
|
-
# Combine data variables from physical and biogeochemical sources
|
|
123
|
-
data_vars.update(bgc_data_vars)
|
|
101
|
+
for var in data_vars.keys():
|
|
102
|
+
data_vars[var] = transpose_dimensions(data_vars[var])
|
|
124
103
|
|
|
125
104
|
d_meta = get_variable_metadata()
|
|
126
105
|
ds = self._write_into_dataset(data_vars, d_meta)
|
|
@@ -137,6 +116,80 @@ class InitialConditions(ROMSToolsMixins):
|
|
|
137
116
|
|
|
138
117
|
object.__setattr__(self, "ds", ds)
|
|
139
118
|
|
|
119
|
+
def _process_data(self, data_vars, type="physics"):
|
|
120
|
+
|
|
121
|
+
target_coords = get_target_coords(self.grid)
|
|
122
|
+
|
|
123
|
+
if type == "physics":
|
|
124
|
+
data = self._get_data()
|
|
125
|
+
else:
|
|
126
|
+
data = self._get_bgc_data()
|
|
127
|
+
|
|
128
|
+
data.choose_subdomain(
|
|
129
|
+
latitude_range=[
|
|
130
|
+
target_coords["lat"].min().values,
|
|
131
|
+
target_coords["lat"].max().values,
|
|
132
|
+
],
|
|
133
|
+
longitude_range=[
|
|
134
|
+
target_coords["lon"].min().values,
|
|
135
|
+
target_coords["lon"].max().values,
|
|
136
|
+
],
|
|
137
|
+
margin=2,
|
|
138
|
+
straddle=target_coords["straddle"],
|
|
139
|
+
)
|
|
140
|
+
|
|
141
|
+
variable_info = self._set_variable_info(data, type=type)
|
|
142
|
+
|
|
143
|
+
data_vars = _extrapolate_deepest_to_bottom(data_vars, data)
|
|
144
|
+
|
|
145
|
+
data_vars = _lateral_fill(data_vars, data)
|
|
146
|
+
|
|
147
|
+
# lateral regridding
|
|
148
|
+
var_names = variable_info.keys()
|
|
149
|
+
data_vars = _lateral_regrid(
|
|
150
|
+
data, target_coords["lon"], target_coords["lat"], data_vars, var_names
|
|
151
|
+
)
|
|
152
|
+
|
|
153
|
+
# rotation of velocities and interpolation to u/v points
|
|
154
|
+
if "u" in variable_info and "v" in variable_info:
|
|
155
|
+
(data_vars["u"], data_vars["v"],) = rotate_velocities(
|
|
156
|
+
data_vars["u"],
|
|
157
|
+
data_vars["v"],
|
|
158
|
+
target_coords["angle"],
|
|
159
|
+
interpolate=True,
|
|
160
|
+
)
|
|
161
|
+
|
|
162
|
+
# vertical regridding
|
|
163
|
+
for location in ["rho", "u", "v"]:
|
|
164
|
+
var_names = [
|
|
165
|
+
name
|
|
166
|
+
for name, info in variable_info.items()
|
|
167
|
+
if info["location"] == location and info["is_3d"]
|
|
168
|
+
]
|
|
169
|
+
if len(var_names) > 0:
|
|
170
|
+
data_vars = _vertical_regrid(
|
|
171
|
+
data,
|
|
172
|
+
self.grid.ds[f"layer_depth_{location}"],
|
|
173
|
+
data_vars,
|
|
174
|
+
var_names,
|
|
175
|
+
)
|
|
176
|
+
|
|
177
|
+
# compute barotropic velocities
|
|
178
|
+
if "u" in variable_info and "v" in variable_info:
|
|
179
|
+
for var in ["u", "v"]:
|
|
180
|
+
data_vars[f"{var}bar"] = compute_barotropic_velocity(
|
|
181
|
+
data_vars[var], self.grid.ds[f"interface_depth_{var}"]
|
|
182
|
+
)
|
|
183
|
+
|
|
184
|
+
if type == "bgc":
|
|
185
|
+
# Ensure time coordinate matches that of physical variables
|
|
186
|
+
for var in variable_info.keys():
|
|
187
|
+
data_vars[var] = data_vars[var].assign_coords(
|
|
188
|
+
{"time": data_vars["temp"]["time"]}
|
|
189
|
+
)
|
|
190
|
+
|
|
191
|
+
return data_vars
|
|
192
|
+
|
|
140
193
|
def _input_checks(self):
|
|
141
194
|
|
|
142
195
|
if "name" not in self.source.keys():
|
|
@@ -201,6 +254,71 @@ class InitialConditions(ROMSToolsMixins):
|
|
|
201
254
|
|
|
202
255
|
return data
|
|
203
256
|
|
|
257
|
+
def _set_variable_info(self, data, type="physics"):
|
|
258
|
+
"""Sets up a dictionary with metadata for variables based on the type.
|
|
259
|
+
|
|
260
|
+
The dictionary contains the following information:
|
|
261
|
+
- `location`: Where the variable resides in the grid (e.g., rho, u, or v points).
|
|
262
|
+
- `is_vector`: Whether the variable is part of a vector (True for velocity components like 'u' and 'v').
|
|
263
|
+
- `vector_pair`: For vector variables, this indicates the associated variable that forms the vector (e.g., 'u' and 'v').
|
|
264
|
+
- `is_3d`: Indicates whether the variable is 3D (True for variables like 'temp' and 'salt') or 2D (False for 'zeta').
|
|
265
|
+
|
|
266
|
+
Returns
|
|
267
|
+
-------
|
|
268
|
+
dict
|
|
269
|
+
A dictionary where the keys are variable names and the values are dictionaries of metadata
|
|
270
|
+
about each variable, including 'location', 'is_vector', 'vector_pair', and 'is_3d'.
|
|
271
|
+
"""
|
|
272
|
+
default_info = {
|
|
273
|
+
"location": "rho",
|
|
274
|
+
"is_vector": False,
|
|
275
|
+
"vector_pair": None,
|
|
276
|
+
"is_3d": True,
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
# Define a dictionary for variable names and their associated information
|
|
280
|
+
if type == "physics":
|
|
281
|
+
variable_info = {
|
|
282
|
+
"zeta": {
|
|
283
|
+
"location": "rho",
|
|
284
|
+
"is_vector": False,
|
|
285
|
+
"vector_pair": None,
|
|
286
|
+
"is_3d": False,
|
|
287
|
+
},
|
|
288
|
+
"temp": default_info,
|
|
289
|
+
"salt": default_info,
|
|
290
|
+
"u": {
|
|
291
|
+
"location": "u",
|
|
292
|
+
"is_vector": True,
|
|
293
|
+
"vector_pair": "v",
|
|
294
|
+
"is_3d": True,
|
|
295
|
+
},
|
|
296
|
+
"v": {
|
|
297
|
+
"location": "v",
|
|
298
|
+
"is_vector": True,
|
|
299
|
+
"vector_pair": "u",
|
|
300
|
+
"is_3d": True,
|
|
301
|
+
},
|
|
302
|
+
"ubar": {
|
|
303
|
+
"location": "u",
|
|
304
|
+
"is_vector": True,
|
|
305
|
+
"vector_pair": "vbar",
|
|
306
|
+
"is_3d": False,
|
|
307
|
+
},
|
|
308
|
+
"vbar": {
|
|
309
|
+
"location": "v",
|
|
310
|
+
"is_vector": True,
|
|
311
|
+
"vector_pair": "ubar",
|
|
312
|
+
"is_3d": False,
|
|
313
|
+
},
|
|
314
|
+
}
|
|
315
|
+
elif type == "bgc":
|
|
316
|
+
variable_info = {}
|
|
317
|
+
for var in data.var_names.keys():
|
|
318
|
+
variable_info[var] = default_info
|
|
319
|
+
|
|
320
|
+
return variable_info
|
|
321
|
+
|
|
204
322
|
def _write_into_dataset(self, data_vars, d_meta):
|
|
205
323
|
|
|
206
324
|
# save in new dataset
|
|
@@ -222,12 +340,16 @@ class InitialConditions(ROMSToolsMixins):
|
|
|
222
340
|
"s_rho",
|
|
223
341
|
"lat_rho",
|
|
224
342
|
"lon_rho",
|
|
225
|
-
"layer_depth_rho",
|
|
226
|
-
"interface_depth_rho",
|
|
227
343
|
"lat_u",
|
|
228
344
|
"lon_u",
|
|
229
345
|
"lat_v",
|
|
230
346
|
"lon_v",
|
|
347
|
+
"layer_depth_rho",
|
|
348
|
+
"interface_depth_rho",
|
|
349
|
+
"layer_depth_u",
|
|
350
|
+
"interface_depth_u",
|
|
351
|
+
"layer_depth_v",
|
|
352
|
+
"interface_depth_v",
|
|
231
353
|
]
|
|
232
354
|
existing_vars = [var for var in variables_to_drop if var in ds]
|
|
233
355
|
ds = ds.drop_vars(existing_vars)
|
|
@@ -381,7 +503,7 @@ class InitialConditions(ROMSToolsMixins):
|
|
|
381
503
|
if all(dim in field.dims for dim in ["eta_rho", "xi_rho"]):
|
|
382
504
|
interface_depth = self.grid.ds.interface_depth_rho
|
|
383
505
|
layer_depth = self.grid.ds.layer_depth_rho
|
|
384
|
-
|
|
506
|
+
mask = self.grid.ds.mask_rho
|
|
385
507
|
field = field.assign_coords(
|
|
386
508
|
{"lon": self.grid.ds.lon_rho, "lat": self.grid.ds.lat_rho}
|
|
387
509
|
)
|
|
@@ -389,7 +511,7 @@ class InitialConditions(ROMSToolsMixins):
|
|
|
389
511
|
elif all(dim in field.dims for dim in ["eta_rho", "xi_u"]):
|
|
390
512
|
interface_depth = self.grid.ds.interface_depth_u
|
|
391
513
|
layer_depth = self.grid.ds.layer_depth_u
|
|
392
|
-
|
|
514
|
+
mask = self.grid.ds.mask_u
|
|
393
515
|
field = field.assign_coords(
|
|
394
516
|
{"lon": self.grid.ds.lon_u, "lat": self.grid.ds.lat_u}
|
|
395
517
|
)
|
|
@@ -397,7 +519,7 @@ class InitialConditions(ROMSToolsMixins):
|
|
|
397
519
|
elif all(dim in field.dims for dim in ["eta_v", "xi_rho"]):
|
|
398
520
|
interface_depth = self.grid.ds.interface_depth_v
|
|
399
521
|
layer_depth = self.grid.ds.layer_depth_v
|
|
400
|
-
|
|
522
|
+
mask = self.grid.ds.mask_v
|
|
401
523
|
field = field.assign_coords(
|
|
402
524
|
{"lon": self.grid.ds.lon_v, "lat": self.grid.ds.lat_v}
|
|
403
525
|
)
|
|
@@ -419,14 +541,16 @@ class InitialConditions(ROMSToolsMixins):
|
|
|
419
541
|
title = title + f", eta_rho = {field.eta_rho[eta].item()}"
|
|
420
542
|
field = field.isel(eta_rho=eta)
|
|
421
543
|
layer_depth = layer_depth.isel(eta_rho=eta)
|
|
422
|
-
field = field.assign_coords({"layer_depth": layer_depth})
|
|
423
544
|
interface_depth = interface_depth.isel(eta_rho=eta)
|
|
545
|
+
if "s_rho" in field.dims:
|
|
546
|
+
field = field.assign_coords({"layer_depth": layer_depth})
|
|
424
547
|
elif "eta_v" in field.dims:
|
|
425
548
|
title = title + f", eta_v = {field.eta_v[eta].item()}"
|
|
426
549
|
field = field.isel(eta_v=eta)
|
|
427
550
|
layer_depth = layer_depth.isel(eta_v=eta)
|
|
428
|
-
field = field.assign_coords({"layer_depth": layer_depth})
|
|
429
551
|
interface_depth = interface_depth.isel(eta_v=eta)
|
|
552
|
+
if "s_rho" in field.dims:
|
|
553
|
+
field = field.assign_coords({"layer_depth": layer_depth})
|
|
430
554
|
else:
|
|
431
555
|
raise ValueError(
|
|
432
556
|
f"None of the expected dimensions (eta_rho, eta_v) found in ds[{varname}]."
|
|
@@ -436,14 +560,16 @@ class InitialConditions(ROMSToolsMixins):
|
|
|
436
560
|
title = title + f", xi_rho = {field.xi_rho[xi].item()}"
|
|
437
561
|
field = field.isel(xi_rho=xi)
|
|
438
562
|
layer_depth = layer_depth.isel(xi_rho=xi)
|
|
439
|
-
field = field.assign_coords({"layer_depth": layer_depth})
|
|
440
563
|
interface_depth = interface_depth.isel(xi_rho=xi)
|
|
564
|
+
if "s_rho" in field.dims:
|
|
565
|
+
field = field.assign_coords({"layer_depth": layer_depth})
|
|
441
566
|
elif "xi_u" in field.dims:
|
|
442
567
|
title = title + f", xi_u = {field.xi_u[xi].item()}"
|
|
443
568
|
field = field.isel(xi_u=xi)
|
|
444
569
|
layer_depth = layer_depth.isel(xi_u=xi)
|
|
445
|
-
field = field.assign_coords({"layer_depth": layer_depth})
|
|
446
570
|
interface_depth = interface_depth.isel(xi_u=xi)
|
|
571
|
+
if "s_rho" in field.dims:
|
|
572
|
+
field = field.assign_coords({"layer_depth": layer_depth})
|
|
447
573
|
else:
|
|
448
574
|
raise ValueError(
|
|
449
575
|
f"None of the expected dimensions (xi_rho, xi_u) found in ds[{varname}]."
|
|
@@ -467,7 +593,7 @@ class InitialConditions(ROMSToolsMixins):
|
|
|
467
593
|
if eta is None and xi is None:
|
|
468
594
|
_plot(
|
|
469
595
|
self.grid.ds,
|
|
470
|
-
field=field,
|
|
596
|
+
field=field.where(mask),
|
|
471
597
|
straddle=self.grid.straddle,
|
|
472
598
|
depth_contours=depth_contours,
|
|
473
599
|
title=title,
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
import xarray as xr
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class LateralRegrid:
|
|
5
|
+
"""Applies lateral fill and regridding to data.
|
|
6
|
+
|
|
7
|
+
This class fills missing values in ocean data and interpolates it onto a new grid
|
|
8
|
+
defined by the provided longitude and latitude.
|
|
9
|
+
|
|
10
|
+
Parameters
|
|
11
|
+
----------
|
|
12
|
+
data : DataContainer
|
|
13
|
+
Container with variables to be interpolated, including a `mask` and dimension names.
|
|
14
|
+
lon : xarray.DataArray
|
|
15
|
+
Target longitude coordinates.
|
|
16
|
+
lat : xarray.DataArray
|
|
17
|
+
Target latitude coordinates.
|
|
18
|
+
"""
|
|
19
|
+
|
|
20
|
+
def __init__(self, data, lon, lat):
|
|
21
|
+
"""Initializes the lateral fill and target grid coordinates.
|
|
22
|
+
|
|
23
|
+
Parameters
|
|
24
|
+
----------
|
|
25
|
+
data : DataContainer
|
|
26
|
+
Data with dimensions and mask for filling.
|
|
27
|
+
lon : xarray.DataArray
|
|
28
|
+
Longitude for new grid.
|
|
29
|
+
lat : xarray.DataArray
|
|
30
|
+
Latitude for new grid.
|
|
31
|
+
"""
|
|
32
|
+
|
|
33
|
+
self.coords = {
|
|
34
|
+
data.dim_names["latitude"]: lat,
|
|
35
|
+
data.dim_names["longitude"]: lon,
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
def apply(self, var):
|
|
39
|
+
"""Fills missing values and regrids the variable.
|
|
40
|
+
|
|
41
|
+
Parameters
|
|
42
|
+
----------
|
|
43
|
+
var : xarray.DataArray
|
|
44
|
+
Input data to fill and regrid.
|
|
45
|
+
|
|
46
|
+
Returns
|
|
47
|
+
-------
|
|
48
|
+
xarray.DataArray
|
|
49
|
+
Regridded data with filled values.
|
|
50
|
+
"""
|
|
51
|
+
regridded = var.interp(self.coords, method="linear").drop_vars(
|
|
52
|
+
list(self.coords.keys())
|
|
53
|
+
)
|
|
54
|
+
return regridded
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
class VerticalRegrid:
|
|
58
|
+
"""Performs vertical interpolation of data onto new depth coordinates.
|
|
59
|
+
|
|
60
|
+
Parameters
|
|
61
|
+
----------
|
|
62
|
+
data : DataContainer
|
|
63
|
+
Container holding the data to be regridded, with relevant dimension names.
|
|
64
|
+
target_depth : xarray.DataArray
|
|
65
|
+
Target depth coordinates for interpolation.
|
|
66
|
+
"""
|
|
67
|
+
|
|
68
|
+
def __init__(self, data, target_depth):
|
|
69
|
+
"""Initializes vertical regridding with specified depth coordinates.
|
|
70
|
+
|
|
71
|
+
Parameters
|
|
72
|
+
----------
|
|
73
|
+
data : DataContainer
|
|
74
|
+
Container holding the data to be regridded, with relevant dimension names.
|
|
75
|
+
target_depth : xarray.DataArray
|
|
76
|
+
Target depth coordinates for interpolation.
|
|
77
|
+
"""
|
|
78
|
+
|
|
79
|
+
self.depth_dim = data.dim_names["depth"]
|
|
80
|
+
dims = {"dim": self.depth_dim}
|
|
81
|
+
|
|
82
|
+
dlev = data.ds[data.dim_names["depth"]] - target_depth
|
|
83
|
+
is_below = dlev == dlev.where(dlev >= 0).min(**dims)
|
|
84
|
+
is_above = dlev == dlev.where(dlev <= 0).max(**dims)
|
|
85
|
+
p_below = dlev.where(is_below).sum(**dims)
|
|
86
|
+
p_above = -dlev.where(is_above).sum(**dims)
|
|
87
|
+
denominator = p_below + p_above
|
|
88
|
+
denominator = denominator.where(denominator > 1e-6, 1e-6)
|
|
89
|
+
factor = p_below / denominator
|
|
90
|
+
|
|
91
|
+
upper_mask = is_above.sum(**dims) > 0
|
|
92
|
+
lower_mask = is_below.sum(**dims) > 0
|
|
93
|
+
|
|
94
|
+
self.coeff = xr.Dataset(
|
|
95
|
+
{
|
|
96
|
+
"is_below": is_below,
|
|
97
|
+
"is_above": is_above,
|
|
98
|
+
"upper_mask": upper_mask,
|
|
99
|
+
"lower_mask": lower_mask,
|
|
100
|
+
"factor": factor,
|
|
101
|
+
}
|
|
102
|
+
)
|
|
103
|
+
|
|
104
|
+
def apply(self, var, fill_nans=True):
|
|
105
|
+
"""Interpolates the variable onto the new depth grid using precomputed
|
|
106
|
+
coefficients for linear interpolation between layers.
|
|
107
|
+
|
|
108
|
+
Parameters
|
|
109
|
+
----------
|
|
110
|
+
var : xarray.DataArray
|
|
111
|
+
The input data to be regridded along the depth dimension. This should be
|
|
112
|
+
an array with the same depth coordinates as the original grid.
|
|
113
|
+
fill_nans : bool, optional
|
|
114
|
+
Whether to fill NaN values in the regridded data. If True (default),
|
|
115
|
+
forward-fill and backward-fill are applied along the 's_rho' dimension to
|
|
116
|
+
ensure there are no NaNs after interpolation.
|
|
117
|
+
|
|
118
|
+
Returns
|
|
119
|
+
-------
|
|
120
|
+
xarray.DataArray
|
|
121
|
+
The regridded data array, interpolated onto the new depth grid. NaN values
|
|
122
|
+
are replaced if `fill_nans=True`, with extrapolation allowed at the surface
|
|
123
|
+
and bottom layers to minimize gaps.
|
|
124
|
+
"""
|
|
125
|
+
|
|
126
|
+
dims = {"dim": self.depth_dim}
|
|
127
|
+
|
|
128
|
+
var_below = var.where(self.coeff["is_below"]).sum(**dims)
|
|
129
|
+
var_above = var.where(self.coeff["is_above"]).sum(**dims)
|
|
130
|
+
|
|
131
|
+
result = var_below + (var_above - var_below) * self.coeff["factor"]
|
|
132
|
+
if fill_nans:
|
|
133
|
+
result = result.where(self.coeff["upper_mask"], var.isel({dims["dim"]: 0}))
|
|
134
|
+
result = result.where(self.coeff["lower_mask"], var.isel({dims["dim"]: -1}))
|
|
135
|
+
else:
|
|
136
|
+
result = result.where(self.coeff["upper_mask"]).where(
|
|
137
|
+
self.coeff["lower_mask"]
|
|
138
|
+
)
|
|
139
|
+
|
|
140
|
+
return result
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
def _lateral_regrid(data, lon, lat, data_vars, var_names):
|
|
144
|
+
"""Laterally regrid specified variables onto new latitude and longitude coordinates.
|
|
145
|
+
|
|
146
|
+
Parameters
|
|
147
|
+
----------
|
|
148
|
+
data : Dataset
|
|
149
|
+
Input data containing the information about source dimensions.
|
|
150
|
+
lon : xarray.DataArray
|
|
151
|
+
Target longitude coordinates.
|
|
152
|
+
lat : xarray.DataArray
|
|
153
|
+
Target latitude coordinates.
|
|
154
|
+
data_vars : dict of str : xarray.DataArray
|
|
155
|
+
Dictionary of variables to regrid.
|
|
156
|
+
var_names : list of str
|
|
157
|
+
Names of variables to regrid.
|
|
158
|
+
|
|
159
|
+
Returns
|
|
160
|
+
-------
|
|
161
|
+
dict of str : xarray.DataArray
|
|
162
|
+
Updated data_vars with regridded variables.
|
|
163
|
+
"""
|
|
164
|
+
lateral_regrid = LateralRegrid(data, lon, lat)
|
|
165
|
+
|
|
166
|
+
for var_name in var_names:
|
|
167
|
+
if var_name in data_vars:
|
|
168
|
+
data_vars[var_name] = lateral_regrid.apply(data_vars[var_name])
|
|
169
|
+
|
|
170
|
+
return data_vars
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
def _vertical_regrid(data, target_depth, data_vars, var_names):
|
|
174
|
+
"""Vertically regrid specified variables onto new depth coordinates.
|
|
175
|
+
|
|
176
|
+
Parameters
|
|
177
|
+
----------
|
|
178
|
+
data : Dataset
|
|
179
|
+
Input dataset containing the variables and source depth information.
|
|
180
|
+
target_depth : xarray.DataArray
|
|
181
|
+
Target depth coordinates for regridding.
|
|
182
|
+
data_vars : dict of str : xarray.DataArray
|
|
183
|
+
Dictionary of variables to be regridded.
|
|
184
|
+
var_names : list of str
|
|
185
|
+
Names of variables to regrid.
|
|
186
|
+
|
|
187
|
+
Returns
|
|
188
|
+
-------
|
|
189
|
+
dict of str : xarray.DataArray
|
|
190
|
+
Updated data_vars with variables regridded onto the target depth coordinates.
|
|
191
|
+
"""
|
|
192
|
+
vertical_regrid = VerticalRegrid(data, target_depth)
|
|
193
|
+
|
|
194
|
+
for var_name in var_names:
|
|
195
|
+
if var_name in data_vars:
|
|
196
|
+
data_vars[var_name] = vertical_regrid.apply(data_vars[var_name])
|
|
197
|
+
|
|
198
|
+
return data_vars
|