roms-tools 2.2.1__py3-none-any.whl → 2.4.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- ci/environment.yml +1 -0
- roms_tools/__init__.py +2 -0
- roms_tools/analysis/roms_output.py +590 -0
- roms_tools/{setup/download.py → download.py} +3 -0
- roms_tools/{setup/plot.py → plot.py} +34 -28
- roms_tools/setup/boundary_forcing.py +199 -203
- roms_tools/setup/datasets.py +60 -136
- roms_tools/setup/grid.py +40 -67
- roms_tools/setup/initial_conditions.py +249 -247
- roms_tools/setup/nesting.py +6 -27
- roms_tools/setup/river_forcing.py +41 -76
- roms_tools/setup/surface_forcing.py +125 -75
- roms_tools/setup/tides.py +31 -51
- roms_tools/setup/topography.py +1 -1
- roms_tools/setup/utils.py +44 -224
- roms_tools/tests/test_analysis/test_roms_output.py +269 -0
- roms_tools/tests/{test_setup/test_regrid.py → test_regrid.py} +1 -1
- roms_tools/tests/test_setup/test_boundary_forcing.py +221 -58
- roms_tools/tests/test_setup/test_data/boundary_forcing.zarr/.zattrs +5 -3
- roms_tools/tests/test_setup/test_data/boundary_forcing.zarr/.zmetadata +156 -121
- roms_tools/tests/test_setup/test_data/boundary_forcing.zarr/abs_time/.zarray +2 -2
- roms_tools/tests/test_setup/test_data/boundary_forcing.zarr/abs_time/.zattrs +2 -1
- roms_tools/tests/test_setup/test_data/boundary_forcing.zarr/abs_time/0 +0 -0
- roms_tools/tests/test_setup/test_data/boundary_forcing.zarr/bry_time/.zarray +2 -2
- roms_tools/tests/test_setup/test_data/boundary_forcing.zarr/bry_time/.zattrs +1 -1
- roms_tools/tests/test_setup/test_data/boundary_forcing.zarr/bry_time/0 +0 -0
- roms_tools/tests/test_setup/test_data/boundary_forcing.zarr/salt_east/.zarray +4 -4
- 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/.zarray +4 -4
- 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/.zarray +4 -4
- 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/.zarray +4 -4
- 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/.zarray +4 -4
- 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/.zarray +4 -4
- 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/.zarray +4 -4
- 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/.zarray +4 -4
- 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/.zarray +4 -4
- 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/.zarray +4 -4
- 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/.zarray +4 -4
- 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/.zarray +4 -4
- 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/.zarray +4 -4
- 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/.zarray +4 -4
- 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/.zarray +4 -4
- 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/.zarray +4 -4
- 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/.zarray +4 -4
- 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/.zarray +4 -4
- 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/.zarray +4 -4
- 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/.zarray +4 -4
- 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/.zarray +4 -4
- 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/.zarray +4 -4
- 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/.zarray +4 -4
- 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/.zarray +4 -4
- 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/.zarray +4 -4
- roms_tools/tests/test_setup/test_data/boundary_forcing.zarr/zeta_east/.zattrs +8 -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_north/.zarray +4 -4
- roms_tools/tests/test_setup/test_data/boundary_forcing.zarr/zeta_north/.zattrs +8 -0
- roms_tools/tests/test_setup/test_data/boundary_forcing.zarr/zeta_north/0.0 +0 -0
- roms_tools/tests/test_setup/test_data/boundary_forcing.zarr/zeta_south/.zarray +4 -4
- roms_tools/tests/test_setup/test_data/boundary_forcing.zarr/zeta_south/.zattrs +8 -0
- roms_tools/tests/test_setup/test_data/boundary_forcing.zarr/zeta_south/0.0 +0 -0
- roms_tools/tests/test_setup/test_data/boundary_forcing.zarr/zeta_west/.zarray +4 -4
- roms_tools/tests/test_setup/test_data/boundary_forcing.zarr/zeta_west/.zattrs +8 -0
- roms_tools/tests/test_setup/test_data/boundary_forcing.zarr/zeta_west/0.0 +0 -0
- roms_tools/tests/test_setup/test_data/grid_that_straddles_dateline.zarr/.zattrs +4 -4
- roms_tools/tests/test_setup/test_data/grid_that_straddles_dateline.zarr/.zmetadata +4 -4
- roms_tools/tests/test_setup/test_data/grid_that_straddles_dateline.zarr/angle/0.0 +0 -0
- roms_tools/tests/test_setup/test_data/grid_that_straddles_dateline.zarr/angle_coarse/0.0 +0 -0
- roms_tools/tests/test_setup/test_data/grid_that_straddles_dateline.zarr/f/0.0 +0 -0
- roms_tools/tests/test_setup/test_data/grid_that_straddles_dateline.zarr/h/0.0 +0 -0
- roms_tools/tests/test_setup/test_data/grid_that_straddles_dateline.zarr/lat_coarse/0.0 +0 -0
- roms_tools/tests/test_setup/test_data/grid_that_straddles_dateline.zarr/lat_rho/0.0 +0 -0
- roms_tools/tests/test_setup/test_data/grid_that_straddles_dateline.zarr/lat_u/0.0 +0 -0
- roms_tools/tests/test_setup/test_data/grid_that_straddles_dateline.zarr/lat_v/0.0 +0 -0
- roms_tools/tests/test_setup/test_data/grid_that_straddles_dateline.zarr/lon_coarse/0.0 +0 -0
- roms_tools/tests/test_setup/test_data/grid_that_straddles_dateline.zarr/lon_rho/0.0 +0 -0
- roms_tools/tests/test_setup/test_data/grid_that_straddles_dateline.zarr/lon_u/0.0 +0 -0
- roms_tools/tests/test_setup/test_data/grid_that_straddles_dateline.zarr/lon_v/0.0 +0 -0
- roms_tools/tests/test_setup/test_data/grid_that_straddles_dateline.zarr/mask_coarse/0.0 +0 -0
- roms_tools/tests/test_setup/test_data/grid_that_straddles_dateline.zarr/mask_rho/0.0 +0 -0
- roms_tools/tests/test_setup/test_data/grid_that_straddles_dateline.zarr/mask_u/0.0 +0 -0
- roms_tools/tests/test_setup/test_data/grid_that_straddles_dateline.zarr/mask_v/0.0 +0 -0
- roms_tools/tests/test_setup/test_data/grid_that_straddles_dateline.zarr/pm/0.0 +0 -0
- roms_tools/tests/test_setup/test_data/grid_that_straddles_dateline.zarr/pn/0.0 +0 -0
- roms_tools/tests/test_setup/test_data/initial_conditions_with_bgc_from_climatology.zarr/.zattrs +2 -1
- roms_tools/tests/test_setup/test_data/initial_conditions_with_bgc_from_climatology.zarr/.zmetadata +6 -4
- roms_tools/tests/test_setup/test_data/initial_conditions_with_bgc_from_climatology.zarr/Cs_r/.zattrs +1 -1
- roms_tools/tests/test_setup/test_data/initial_conditions_with_bgc_from_climatology.zarr/Cs_w/.zattrs +1 -1
- 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/PO4/0.0.0.0 +0 -0
- roms_tools/tests/test_setup/test_data/initial_conditions_with_bgc_from_climatology.zarr/abs_time/.zattrs +1 -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/ocean_time/.zattrs +1 -1
- 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/spFe/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/river_forcing_no_climatology.zarr/.zmetadata +30 -0
- roms_tools/tests/test_setup/test_data/river_forcing_no_climatology.zarr/river_location/.zarray +22 -0
- roms_tools/tests/test_setup/test_data/river_forcing_no_climatology.zarr/river_location/.zattrs +8 -0
- roms_tools/tests/test_setup/test_data/river_forcing_no_climatology.zarr/river_location/0.0 +0 -0
- roms_tools/tests/test_setup/test_data/river_forcing_with_bgc.zarr/.zmetadata +30 -0
- roms_tools/tests/test_setup/test_data/river_forcing_with_bgc.zarr/river_location/.zarray +22 -0
- roms_tools/tests/test_setup/test_data/river_forcing_with_bgc.zarr/river_location/.zattrs +8 -0
- roms_tools/tests/test_setup/test_data/river_forcing_with_bgc.zarr/river_location/0.0 +0 -0
- roms_tools/tests/test_setup/test_datasets.py +1 -1
- roms_tools/tests/test_setup/test_grid.py +1 -14
- roms_tools/tests/test_setup/test_initial_conditions.py +205 -67
- roms_tools/tests/test_setup/test_nesting.py +0 -16
- roms_tools/tests/test_setup/test_river_forcing.py +9 -37
- roms_tools/tests/test_setup/test_surface_forcing.py +103 -74
- roms_tools/tests/test_setup/test_tides.py +5 -17
- roms_tools/tests/test_setup/test_topography.py +1 -1
- roms_tools/tests/test_setup/test_utils.py +57 -1
- roms_tools/tests/{test_utils.py → test_tiling/test_partition.py} +1 -1
- roms_tools/tiling/partition.py +338 -0
- roms_tools/utils.py +310 -276
- roms_tools/vertical_coordinate.py +227 -0
- {roms_tools-2.2.1.dist-info → roms_tools-2.4.0.dist-info}/METADATA +1 -1
- {roms_tools-2.2.1.dist-info → roms_tools-2.4.0.dist-info}/RECORD +151 -142
- roms_tools/setup/vertical_coordinate.py +0 -109
- /roms_tools/{setup/regrid.py → regrid.py} +0 -0
- {roms_tools-2.2.1.dist-info → roms_tools-2.4.0.dist-info}/LICENSE +0 -0
- {roms_tools-2.2.1.dist-info → roms_tools-2.4.0.dist-info}/WHEEL +0 -0
- {roms_tools-2.2.1.dist-info → roms_tools-2.4.0.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
import numpy as np
|
|
2
|
+
import xarray as xr
|
|
3
|
+
from roms_tools.utils import (
|
|
4
|
+
transpose_dimensions,
|
|
5
|
+
interpolate_from_rho_to_u,
|
|
6
|
+
interpolate_from_rho_to_v,
|
|
7
|
+
)
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def compute_cs(sigma, theta_s, theta_b):
|
|
11
|
+
"""Compute the S-coordinate stretching curves according to Shchepetkin and
|
|
12
|
+
McWilliams (2009).
|
|
13
|
+
|
|
14
|
+
Parameters
|
|
15
|
+
----------
|
|
16
|
+
sigma : np.ndarray or float
|
|
17
|
+
The sigma-coordinate values.
|
|
18
|
+
theta_s : float
|
|
19
|
+
The surface control parameter.
|
|
20
|
+
theta_b : float
|
|
21
|
+
The bottom control parameter.
|
|
22
|
+
|
|
23
|
+
Returns
|
|
24
|
+
-------
|
|
25
|
+
C : np.ndarray or float
|
|
26
|
+
The stretching curve values.
|
|
27
|
+
|
|
28
|
+
Raises
|
|
29
|
+
------
|
|
30
|
+
ValueError
|
|
31
|
+
If theta_s or theta_b are not within the valid range.
|
|
32
|
+
"""
|
|
33
|
+
if not (0 < theta_s <= 10):
|
|
34
|
+
raise ValueError("theta_s must be between 0 and 10.")
|
|
35
|
+
if not (0 < theta_b <= 4):
|
|
36
|
+
raise ValueError("theta_b must be between 0 and 4.")
|
|
37
|
+
|
|
38
|
+
C = (1 - np.cosh(theta_s * sigma)) / (np.cosh(theta_s) - 1)
|
|
39
|
+
C = (np.exp(theta_b * C) - 1) / (1 - np.exp(-theta_b))
|
|
40
|
+
|
|
41
|
+
return C
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def sigma_stretch(theta_s, theta_b, N, type):
|
|
45
|
+
"""Compute sigma and stretching curves based on the type and parameters.
|
|
46
|
+
|
|
47
|
+
Parameters
|
|
48
|
+
----------
|
|
49
|
+
theta_s : float
|
|
50
|
+
The surface control parameter.
|
|
51
|
+
theta_b : float
|
|
52
|
+
The bottom control parameter.
|
|
53
|
+
N : int
|
|
54
|
+
The number of vertical levels.
|
|
55
|
+
type : str
|
|
56
|
+
The type of sigma ('w' for vertical velocity points, 'r' for rho-points).
|
|
57
|
+
|
|
58
|
+
Returns
|
|
59
|
+
-------
|
|
60
|
+
cs : xr.DataArray
|
|
61
|
+
The stretching curve values.
|
|
62
|
+
sigma : xr.DataArray
|
|
63
|
+
The sigma-coordinate values.
|
|
64
|
+
|
|
65
|
+
Raises
|
|
66
|
+
------
|
|
67
|
+
ValueError
|
|
68
|
+
If the type is not 'w' or 'r'.
|
|
69
|
+
"""
|
|
70
|
+
if type == "w":
|
|
71
|
+
k = xr.DataArray(np.arange(N + 1), dims="s_w")
|
|
72
|
+
sigma = (k - N) / N
|
|
73
|
+
elif type == "r":
|
|
74
|
+
k = xr.DataArray(np.arange(1, N + 1), dims="s_rho")
|
|
75
|
+
sigma = (k - N - 0.5) / N
|
|
76
|
+
else:
|
|
77
|
+
raise ValueError(
|
|
78
|
+
"Type must be either 'w' for vertical velocity points or 'r' for rho-points."
|
|
79
|
+
)
|
|
80
|
+
|
|
81
|
+
cs = compute_cs(sigma, theta_s, theta_b)
|
|
82
|
+
|
|
83
|
+
return cs, sigma
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
def compute_depth(zeta, h, hc, cs, sigma):
|
|
87
|
+
"""Compute the depth at different sigma levels.
|
|
88
|
+
|
|
89
|
+
Parameters
|
|
90
|
+
----------
|
|
91
|
+
zeta : xr.DataArray or scalar
|
|
92
|
+
The sea surface height.
|
|
93
|
+
h : xr.DataArray
|
|
94
|
+
The depth of the sea bottom.
|
|
95
|
+
hc : float
|
|
96
|
+
The critical depth.
|
|
97
|
+
cs : xr.DataArray
|
|
98
|
+
The stretching curve values.
|
|
99
|
+
sigma : xr.DataArray
|
|
100
|
+
The sigma-coordinate values.
|
|
101
|
+
|
|
102
|
+
Returns
|
|
103
|
+
-------
|
|
104
|
+
z : xr.DataArray
|
|
105
|
+
The depth at different sigma levels.
|
|
106
|
+
"""
|
|
107
|
+
|
|
108
|
+
z = (hc * sigma + h * cs) / (hc + h)
|
|
109
|
+
z = zeta + (zeta + h) * z
|
|
110
|
+
|
|
111
|
+
z = -transpose_dimensions(z)
|
|
112
|
+
|
|
113
|
+
return z
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
def compute_depth_coordinates(
|
|
117
|
+
grid_ds: "xr.Dataset",
|
|
118
|
+
zeta: xr.DataArray | float = 0,
|
|
119
|
+
depth_type: str = "layer",
|
|
120
|
+
location: str = "rho",
|
|
121
|
+
eta: int = None,
|
|
122
|
+
xi: int = None,
|
|
123
|
+
) -> "xr.DataArray":
|
|
124
|
+
"""Compute vertical depth coordinates for a given ROMS grid location.
|
|
125
|
+
|
|
126
|
+
This function calculates depth coordinates (layer or interface) at a specified grid
|
|
127
|
+
location (`rho`, `u`, or `v`). It optimizes computations by slicing the bathymetry (`h`)
|
|
128
|
+
and free-surface elevation (`zeta`) before performing vertical coordinate calculations,
|
|
129
|
+
reducing memory usage and improving efficiency.
|
|
130
|
+
|
|
131
|
+
Parameters
|
|
132
|
+
----------
|
|
133
|
+
grid_ds : xr.Dataset
|
|
134
|
+
ROMS grid dataset containing bathymetry (`h`), stretching curves (`Cs`),
|
|
135
|
+
and sigma-layer parameters (`sigma`). The dataset's attributes should include
|
|
136
|
+
the critical depth parameter (`hc`).
|
|
137
|
+
|
|
138
|
+
zeta : xr.DataArray or float, optional
|
|
139
|
+
Free-surface elevation. If set to `0` (default), the static sea level is assumed.
|
|
140
|
+
|
|
141
|
+
depth_type : str, optional
|
|
142
|
+
Type of depth coordinates to compute:
|
|
143
|
+
- `"layer"` (default): Depth at the center of vertical layers.
|
|
144
|
+
- `"interface"`: Depth at layer interfaces.
|
|
145
|
+
|
|
146
|
+
location : str, optional
|
|
147
|
+
Grid location for depth computation:
|
|
148
|
+
- `"rho"` (default): Depth at cell centers (rho points).
|
|
149
|
+
- `"u"`: Depth at eastward velocity points (u points).
|
|
150
|
+
- `"v"`: Depth at northward velocity points (v points).
|
|
151
|
+
|
|
152
|
+
eta : int, optional
|
|
153
|
+
Meridional (north-south) index to extract a zonal slice. If not provided,
|
|
154
|
+
all meridional indices are included.
|
|
155
|
+
|
|
156
|
+
xi : int, optional
|
|
157
|
+
Zonal (east-west) index to extract a meridional slice. If not provided,
|
|
158
|
+
all zonal indices are included.
|
|
159
|
+
|
|
160
|
+
Returns
|
|
161
|
+
-------
|
|
162
|
+
xr.DataArray
|
|
163
|
+
Computed depth coordinates. The shape of the output depends on the given indices:
|
|
164
|
+
- Full 3D (or 4D if `zeta` includes time) depth field if no indices are specified.
|
|
165
|
+
- 2D (or 3D if `zeta` includes time) slice if either `eta` or `xi` are specified.
|
|
166
|
+
- 1D (or 2D if `zeta` includes time) slice if both `eta` and `xi` are specified.
|
|
167
|
+
|
|
168
|
+
Notes
|
|
169
|
+
-----
|
|
170
|
+
- The function first interpolates `h` and `zeta` to the specified grid location (`rho`, `u`, or `v`).
|
|
171
|
+
- Spatial slicing (`eta`, `xi`) is performed before depth computation to optimize efficiency.
|
|
172
|
+
- Depth calculations rely on the ROMS vertical stretching curves (`Cs`) and sigma-layers.
|
|
173
|
+
"""
|
|
174
|
+
|
|
175
|
+
# Select the appropriate depth computation parameters
|
|
176
|
+
if depth_type == "layer":
|
|
177
|
+
Cs = grid_ds["Cs_r"]
|
|
178
|
+
sigma = grid_ds["sigma_r"]
|
|
179
|
+
elif depth_type == "interface":
|
|
180
|
+
Cs = grid_ds["Cs_w"]
|
|
181
|
+
sigma = grid_ds["sigma_w"]
|
|
182
|
+
else:
|
|
183
|
+
raise ValueError(
|
|
184
|
+
f"Invalid depth_type: {depth_type}. Choose 'layer' or 'interface'."
|
|
185
|
+
)
|
|
186
|
+
|
|
187
|
+
h = grid_ds["h"]
|
|
188
|
+
|
|
189
|
+
# Interpolate h and zeta to the specified location
|
|
190
|
+
if location == "u":
|
|
191
|
+
h = interpolate_from_rho_to_u(h)
|
|
192
|
+
if isinstance(zeta, xr.DataArray):
|
|
193
|
+
zeta = interpolate_from_rho_to_u(zeta)
|
|
194
|
+
elif location == "v":
|
|
195
|
+
h = interpolate_from_rho_to_v(h)
|
|
196
|
+
if isinstance(zeta, xr.DataArray):
|
|
197
|
+
zeta = interpolate_from_rho_to_v(zeta)
|
|
198
|
+
|
|
199
|
+
# Slice spatially based on indices
|
|
200
|
+
if eta is not None:
|
|
201
|
+
if location == "v":
|
|
202
|
+
h = h.isel(eta_v=eta)
|
|
203
|
+
if isinstance(zeta, xr.DataArray):
|
|
204
|
+
zeta = zeta.isel(eta_v=eta)
|
|
205
|
+
else: # Applies to "rho" or "u"
|
|
206
|
+
h = h.isel(eta_rho=eta)
|
|
207
|
+
if isinstance(zeta, xr.DataArray):
|
|
208
|
+
zeta = zeta.isel(eta_rho=eta)
|
|
209
|
+
|
|
210
|
+
if xi is not None:
|
|
211
|
+
if location == "u":
|
|
212
|
+
h = h.isel(xi_u=xi)
|
|
213
|
+
if isinstance(zeta, xr.DataArray):
|
|
214
|
+
zeta = zeta.isel(xi_u=xi)
|
|
215
|
+
else: # Applies to "rho" or "v"
|
|
216
|
+
h = h.isel(xi_rho=xi)
|
|
217
|
+
if isinstance(zeta, xr.DataArray):
|
|
218
|
+
zeta = zeta.isel(xi_rho=xi)
|
|
219
|
+
|
|
220
|
+
depth = compute_depth(zeta, h, grid_ds.attrs["hc"], Cs, sigma)
|
|
221
|
+
|
|
222
|
+
# Add metadata
|
|
223
|
+
depth.attrs.update(
|
|
224
|
+
{"long_name": f"{depth_type} depth at {location}-points", "units": "m"}
|
|
225
|
+
)
|
|
226
|
+
|
|
227
|
+
return depth
|