roms-tools 0.0.6__py3-none-any.whl → 0.20__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 +29 -0
- roms_tools/__init__.py +6 -0
- roms_tools/_version.py +1 -1
- roms_tools/setup/atmospheric_forcing.py +935 -0
- roms_tools/setup/boundary_forcing.py +711 -0
- roms_tools/setup/datasets.py +457 -0
- roms_tools/setup/fill.py +376 -0
- roms_tools/setup/grid.py +610 -325
- roms_tools/setup/initial_conditions.py +528 -0
- roms_tools/setup/plot.py +203 -0
- roms_tools/setup/tides.py +809 -0
- roms_tools/setup/topography.py +257 -0
- roms_tools/setup/utils.py +162 -0
- roms_tools/setup/vertical_coordinate.py +494 -0
- roms_tools/tests/test_atmospheric_forcing.py +1645 -0
- roms_tools/tests/test_boundary_forcing.py +332 -0
- roms_tools/tests/test_datasets.py +306 -0
- roms_tools/tests/test_grid.py +226 -0
- roms_tools/tests/test_initial_conditions.py +300 -0
- roms_tools/tests/test_tides.py +366 -0
- roms_tools/tests/test_topography.py +78 -0
- roms_tools/tests/test_vertical_coordinate.py +337 -0
- roms_tools-0.20.dist-info/METADATA +90 -0
- roms_tools-0.20.dist-info/RECORD +28 -0
- {roms_tools-0.0.6.dist-info → roms_tools-0.20.dist-info}/WHEEL +1 -1
- {roms_tools-0.0.6.dist-info → roms_tools-0.20.dist-info}/top_level.txt +1 -0
- roms_tools/tests/test_setup.py +0 -54
- roms_tools-0.0.6.dist-info/METADATA +0 -134
- roms_tools-0.0.6.dist-info/RECORD +0 -10
- {roms_tools-0.0.6.dist-info → roms_tools-0.20.dist-info}/LICENSE +0 -0
roms_tools/setup/plot.py
ADDED
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
import cartopy.crs as ccrs
|
|
2
|
+
import matplotlib.pyplot as plt
|
|
3
|
+
import xarray as xr
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def _plot(
|
|
7
|
+
grid_ds,
|
|
8
|
+
field=None,
|
|
9
|
+
depth_contours=False,
|
|
10
|
+
straddle=False,
|
|
11
|
+
coarse_grid=False,
|
|
12
|
+
c="red",
|
|
13
|
+
title="",
|
|
14
|
+
kwargs={},
|
|
15
|
+
):
|
|
16
|
+
|
|
17
|
+
if field is None:
|
|
18
|
+
lon_deg = grid_ds["lon_rho"]
|
|
19
|
+
lat_deg = grid_ds["lat_rho"]
|
|
20
|
+
|
|
21
|
+
else:
|
|
22
|
+
|
|
23
|
+
field = field.squeeze()
|
|
24
|
+
|
|
25
|
+
if coarse_grid:
|
|
26
|
+
|
|
27
|
+
field = field.rename({"eta_rho": "eta_coarse", "xi_rho": "xi_coarse"})
|
|
28
|
+
field = field.where(grid_ds.mask_coarse)
|
|
29
|
+
lon_deg = field.lon
|
|
30
|
+
lat_deg = field.lat
|
|
31
|
+
|
|
32
|
+
else:
|
|
33
|
+
if all(dim in field.dims for dim in ["eta_rho", "xi_rho"]):
|
|
34
|
+
field = field.where(grid_ds.mask_rho)
|
|
35
|
+
lon_deg = grid_ds["lon_rho"]
|
|
36
|
+
lat_deg = grid_ds["lat_rho"]
|
|
37
|
+
elif all(dim in field.dims for dim in ["eta_rho", "xi_u"]):
|
|
38
|
+
field = field.where(grid_ds.mask_u)
|
|
39
|
+
lon_deg = grid_ds["lon_u"]
|
|
40
|
+
lat_deg = grid_ds["lat_u"]
|
|
41
|
+
elif all(dim in field.dims for dim in ["eta_v", "xi_rho"]):
|
|
42
|
+
field = field.where(grid_ds.mask_v)
|
|
43
|
+
lon_deg = grid_ds["lon_v"]
|
|
44
|
+
lat_deg = grid_ds["lat_v"]
|
|
45
|
+
else:
|
|
46
|
+
ValueError("provided field does not have two horizontal dimension")
|
|
47
|
+
|
|
48
|
+
# check if North or South pole are in domain
|
|
49
|
+
if lat_deg.max().values > 89 or lat_deg.min().values < -89:
|
|
50
|
+
raise NotImplementedError(
|
|
51
|
+
"Plotting is not implemented for the case that the domain contains the North or South pole."
|
|
52
|
+
)
|
|
53
|
+
|
|
54
|
+
if straddle:
|
|
55
|
+
lon_deg = xr.where(lon_deg > 180, lon_deg - 360, lon_deg)
|
|
56
|
+
|
|
57
|
+
# Define projections
|
|
58
|
+
proj = ccrs.PlateCarree()
|
|
59
|
+
|
|
60
|
+
trans = ccrs.NearsidePerspective(
|
|
61
|
+
central_longitude=lon_deg.mean().values, central_latitude=lat_deg.mean().values
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
lon_deg = lon_deg.values
|
|
65
|
+
lat_deg = lat_deg.values
|
|
66
|
+
|
|
67
|
+
# find corners
|
|
68
|
+
corners = [
|
|
69
|
+
(lon_deg[0, 0], lat_deg[0, 0]),
|
|
70
|
+
(lon_deg[0, -1], lat_deg[0, -1]),
|
|
71
|
+
(lon_deg[-1, -1], lat_deg[-1, -1]),
|
|
72
|
+
(lon_deg[-1, 0], lat_deg[-1, 0]),
|
|
73
|
+
]
|
|
74
|
+
|
|
75
|
+
# transform coordinates to projected space
|
|
76
|
+
transformed_corners = [trans.transform_point(lo, la, proj) for lo, la in corners]
|
|
77
|
+
transformed_lons, transformed_lats = zip(*transformed_corners)
|
|
78
|
+
|
|
79
|
+
fig, ax = plt.subplots(1, 1, figsize=(13, 7), subplot_kw={"projection": trans})
|
|
80
|
+
|
|
81
|
+
ax.plot(
|
|
82
|
+
list(transformed_lons) + [transformed_lons[0]],
|
|
83
|
+
list(transformed_lats) + [transformed_lats[0]],
|
|
84
|
+
"o-",
|
|
85
|
+
c=c,
|
|
86
|
+
)
|
|
87
|
+
|
|
88
|
+
ax.coastlines(
|
|
89
|
+
resolution="50m", linewidth=0.5, color="black"
|
|
90
|
+
) # add map of coastlines
|
|
91
|
+
ax.gridlines()
|
|
92
|
+
ax.set_title(title)
|
|
93
|
+
|
|
94
|
+
if field is not None:
|
|
95
|
+
p = ax.pcolormesh(lon_deg, lat_deg, field, transform=proj, **kwargs)
|
|
96
|
+
plt.colorbar(p, label=f"{field.long_name} [{field.units}]")
|
|
97
|
+
|
|
98
|
+
if depth_contours:
|
|
99
|
+
if all(dim in field.dims for dim in ["eta_rho", "xi_rho"]):
|
|
100
|
+
if "layer_depth_rho" in field.coords:
|
|
101
|
+
depth = field.layer_depth_rho
|
|
102
|
+
else:
|
|
103
|
+
depth = field.interface_depth_rho
|
|
104
|
+
elif all(dim in field.dims for dim in ["eta_rho", "xi_u"]):
|
|
105
|
+
if "layer_depth_u" in field.coords:
|
|
106
|
+
depth = field.layer_depth_u
|
|
107
|
+
else:
|
|
108
|
+
depth = field.interface_depth_u
|
|
109
|
+
elif all(dim in field.dims for dim in ["eta_v", "xi_rho"]):
|
|
110
|
+
if "layer_depth_v" in field.coords:
|
|
111
|
+
depth = field.layer_depth_v
|
|
112
|
+
else:
|
|
113
|
+
depth = field.interface_depth_v
|
|
114
|
+
|
|
115
|
+
cs = ax.contour(lon_deg, lat_deg, depth, transform=proj, colors="k")
|
|
116
|
+
ax.clabel(cs, inline=True, fontsize=10)
|
|
117
|
+
|
|
118
|
+
return fig
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
def _section_plot(field, interface_depth=None, title="", kwargs={}):
|
|
122
|
+
|
|
123
|
+
fig, ax = plt.subplots(1, 1, figsize=(9, 5))
|
|
124
|
+
|
|
125
|
+
dims_to_check = ["eta_rho", "eta_u", "eta_v", "xi_rho", "xi_u", "xi_v"]
|
|
126
|
+
try:
|
|
127
|
+
xdim = next(
|
|
128
|
+
dim
|
|
129
|
+
for dim in field.dims
|
|
130
|
+
if any(dim.startswith(prefix) for prefix in dims_to_check)
|
|
131
|
+
)
|
|
132
|
+
except StopIteration:
|
|
133
|
+
raise ValueError(
|
|
134
|
+
"None of the dimensions found in field.dims starts with (eta_rho, eta_u, eta_v, xi_rho, xi_u, xi_v)"
|
|
135
|
+
)
|
|
136
|
+
|
|
137
|
+
depths_to_check = [
|
|
138
|
+
"layer_depth_rho",
|
|
139
|
+
"layer_depth_u",
|
|
140
|
+
"layer_depth_v",
|
|
141
|
+
"interface_depth_rho",
|
|
142
|
+
"interface_depth_u",
|
|
143
|
+
"interface_depth_v",
|
|
144
|
+
]
|
|
145
|
+
try:
|
|
146
|
+
depth_label = next(
|
|
147
|
+
depth_label
|
|
148
|
+
for depth_label in field.coords
|
|
149
|
+
if any(depth_label.startswith(prefix) for prefix in depths_to_check)
|
|
150
|
+
)
|
|
151
|
+
except StopIteration:
|
|
152
|
+
raise ValueError(
|
|
153
|
+
"None of the coordinates found in field.coords starts with (layer_depth_rho, layer_depth_u, layer_depth_v, interface_depth_rho, interface_depth_u, interface_depth_v)"
|
|
154
|
+
)
|
|
155
|
+
|
|
156
|
+
more_kwargs = {"x": xdim, "y": depth_label, "yincrease": False}
|
|
157
|
+
field.plot(**kwargs, **more_kwargs, ax=ax)
|
|
158
|
+
|
|
159
|
+
if interface_depth is not None:
|
|
160
|
+
layer_key = "s_rho" if "s_rho" in interface_depth else "s_w"
|
|
161
|
+
|
|
162
|
+
for i in range(len(interface_depth[layer_key])):
|
|
163
|
+
ax.plot(
|
|
164
|
+
interface_depth[xdim], interface_depth.isel({layer_key: i}), color="k"
|
|
165
|
+
)
|
|
166
|
+
|
|
167
|
+
ax.set_title(title)
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
def _profile_plot(field, title=""):
|
|
171
|
+
|
|
172
|
+
depths_to_check = [
|
|
173
|
+
"layer_depth_rho",
|
|
174
|
+
"layer_depth_u",
|
|
175
|
+
"layer_depth_v",
|
|
176
|
+
"interface_depth_rho",
|
|
177
|
+
"interface_depth_u",
|
|
178
|
+
"interface_depth_v",
|
|
179
|
+
]
|
|
180
|
+
try:
|
|
181
|
+
depth_label = next(
|
|
182
|
+
depth_label
|
|
183
|
+
for depth_label in depths_to_check
|
|
184
|
+
if depth_label in field.coords
|
|
185
|
+
)
|
|
186
|
+
except StopIteration:
|
|
187
|
+
raise ValueError(
|
|
188
|
+
"None of the expected coordinates (layer_depth_rho, layer_depth_u, layer_depth_v, interface_depth_rho, interface_depth_u, interface_depth_v) found in field.coords"
|
|
189
|
+
)
|
|
190
|
+
|
|
191
|
+
fig, ax = plt.subplots(1, 1, figsize=(4, 7))
|
|
192
|
+
kwargs = {"y": depth_label, "yincrease": False}
|
|
193
|
+
field.plot(**kwargs)
|
|
194
|
+
ax.set_title(title)
|
|
195
|
+
ax.grid()
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
def _line_plot(field, title=""):
|
|
199
|
+
|
|
200
|
+
fig, ax = plt.subplots(1, 1, figsize=(7, 4))
|
|
201
|
+
field.plot()
|
|
202
|
+
ax.set_title(title)
|
|
203
|
+
ax.grid()
|