roms-tools 1.4.1__py3-none-any.whl → 1.4.2__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 +77 -70
- roms_tools/setup/datasets.py +38 -59
- roms_tools/setup/download.py +3 -6
- roms_tools/setup/fill.py +8 -16
- roms_tools/setup/grid.py +74 -113
- roms_tools/setup/initial_conditions.py +43 -36
- roms_tools/setup/mixins.py +10 -14
- roms_tools/setup/surface_forcing.py +35 -33
- roms_tools/setup/tides.py +37 -41
- roms_tools/setup/topography.py +9 -17
- roms_tools/setup/utils.py +19 -40
- roms_tools/setup/vertical_coordinate.py +4 -6
- roms_tools/tests/test_setup/test_boundary_forcing.py +6 -13
- roms_tools/tests/test_setup/test_data/grid.zarr/.zattrs +2 -2
- roms_tools/tests/test_setup/test_data/grid.zarr/.zmetadata +2 -62
- roms_tools/tests/test_setup/test_data/grid_that_straddles_dateline.zarr/.zattrs +2 -2
- roms_tools/tests/test_setup/test_data/grid_that_straddles_dateline.zarr/.zmetadata +2 -62
- roms_tools/tests/test_setup/test_datasets.py +8 -18
- roms_tools/tests/test_setup/test_grid.py +9 -9
- roms_tools/tests/test_setup/test_initial_conditions.py +4 -7
- roms_tools/tests/test_setup/test_surface_forcing.py +56 -56
- roms_tools/tests/test_setup/test_tides.py +6 -10
- roms_tools/tests/test_setup/test_topography.py +2 -4
- roms_tools/tests/test_setup/test_vertical_coordinate.py +2 -6
- roms_tools/tests/test_utils.py +30 -30
- roms_tools/utils.py +6 -7
- {roms_tools-1.4.1.dist-info → roms_tools-1.4.2.dist-info}/METADATA +1 -1
- {roms_tools-1.4.1.dist-info → roms_tools-1.4.2.dist-info}/RECORD +32 -44
- roms_tools/tests/test_setup/test_data/grid.zarr/lat_psi/.zarray +0 -22
- roms_tools/tests/test_setup/test_data/grid.zarr/lat_psi/.zattrs +0 -8
- roms_tools/tests/test_setup/test_data/grid.zarr/lat_psi/0.0 +0 -0
- roms_tools/tests/test_setup/test_data/grid.zarr/lon_psi/.zarray +0 -22
- roms_tools/tests/test_setup/test_data/grid.zarr/lon_psi/.zattrs +0 -8
- roms_tools/tests/test_setup/test_data/grid.zarr/lon_psi/0.0 +0 -0
- roms_tools/tests/test_setup/test_data/grid_that_straddles_dateline.zarr/lat_psi/.zarray +0 -22
- roms_tools/tests/test_setup/test_data/grid_that_straddles_dateline.zarr/lat_psi/.zattrs +0 -8
- roms_tools/tests/test_setup/test_data/grid_that_straddles_dateline.zarr/lat_psi/0.0 +0 -0
- roms_tools/tests/test_setup/test_data/grid_that_straddles_dateline.zarr/lon_psi/.zarray +0 -22
- roms_tools/tests/test_setup/test_data/grid_that_straddles_dateline.zarr/lon_psi/.zattrs +0 -8
- roms_tools/tests/test_setup/test_data/grid_that_straddles_dateline.zarr/lon_psi/0.0 +0 -0
- {roms_tools-1.4.1.dist-info → roms_tools-1.4.2.dist-info}/LICENSE +0 -0
- {roms_tools-1.4.1.dist-info → roms_tools-1.4.2.dist-info}/WHEEL +0 -0
- {roms_tools-1.4.1.dist-info → roms_tools-1.4.2.dist-info}/top_level.txt +0 -0
roms_tools/setup/grid.py
CHANGED
|
@@ -21,29 +21,28 @@ RADIUS_OF_EARTH = 6371315.0 # in m
|
|
|
21
21
|
|
|
22
22
|
@dataclass(frozen=True, kw_only=True)
|
|
23
23
|
class Grid:
|
|
24
|
-
"""
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
The default is 0, which means that the x-direction of the grid is aligned with lines of constant latitude.
|
|
24
|
+
"""A single ROMS grid.
|
|
25
|
+
|
|
26
|
+
Used for creating, plotting, and then saving a new ROMS domain grid.
|
|
27
|
+
|
|
28
|
+
Parameters
|
|
29
|
+
----------
|
|
30
|
+
nx : int
|
|
31
|
+
Number of grid points in the x-direction.
|
|
32
|
+
ny : int
|
|
33
|
+
Number of grid points in the y-direction.
|
|
34
|
+
size_x : float
|
|
35
|
+
Domain size in the x-direction (in kilometers).
|
|
36
|
+
size_y : float
|
|
37
|
+
Domain size in the y-direction (in kilometers).
|
|
38
|
+
center_lon : float
|
|
39
|
+
Longitude of grid center.
|
|
40
|
+
center_lat : float
|
|
41
|
+
Latitude of grid center.
|
|
42
|
+
rot : float, optional
|
|
43
|
+
Rotation of grid x-direction from lines of constant latitude, measured in degrees.
|
|
44
|
+
Positive values represent a counterclockwise rotation.
|
|
45
|
+
The default is 0, which means that the x-direction of the grid is aligned with lines of constant latitude.
|
|
47
46
|
N : int, optional
|
|
48
47
|
The number of vertical levels. The default is 100.
|
|
49
48
|
theta_s : float, optional
|
|
@@ -58,44 +57,10 @@ class Grid:
|
|
|
58
57
|
hmin : float, optional
|
|
59
58
|
The minimum ocean depth (in meters). The default is 5.0.
|
|
60
59
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
ny : int
|
|
66
|
-
Number of grid points in the y-direction.
|
|
67
|
-
size_x : float
|
|
68
|
-
Domain size in the x-direction (in kilometers).
|
|
69
|
-
size_y : float
|
|
70
|
-
Domain size in the y-direction (in kilometers).
|
|
71
|
-
center_lon : float
|
|
72
|
-
Longitude of grid center.
|
|
73
|
-
center_lat : float
|
|
74
|
-
Latitude of grid center.
|
|
75
|
-
rot : float
|
|
76
|
-
Rotation of grid x-direction from lines of constant latitude.
|
|
77
|
-
N : int
|
|
78
|
-
The number of vertical levels.
|
|
79
|
-
theta_s : float
|
|
80
|
-
The surface control parameter.
|
|
81
|
-
theta_b : float
|
|
82
|
-
The bottom control parameter.
|
|
83
|
-
hc : float
|
|
84
|
-
The critical depth (in meters).
|
|
85
|
-
topography_source : str
|
|
86
|
-
Data source used for the topography.
|
|
87
|
-
hmin : float
|
|
88
|
-
Minimum ocean depth (in meters).
|
|
89
|
-
ds : xr.Dataset
|
|
90
|
-
The xarray Dataset containing the grid data.
|
|
91
|
-
straddle : bool
|
|
92
|
-
Indicates if the Greenwich meridian (0° longitude) intersects the domain.
|
|
93
|
-
`True` if it does, `False` otherwise.
|
|
94
|
-
|
|
95
|
-
Raises
|
|
96
|
-
------
|
|
97
|
-
ValueError
|
|
98
|
-
If you try to create a grid with domain size larger than 20000 km.
|
|
60
|
+
Raises
|
|
61
|
+
------
|
|
62
|
+
ValueError
|
|
63
|
+
If you try to create a grid with domain size larger than 20000 km.
|
|
99
64
|
"""
|
|
100
65
|
|
|
101
66
|
nx: int
|
|
@@ -147,8 +112,8 @@ class Grid:
|
|
|
147
112
|
)
|
|
148
113
|
|
|
149
114
|
def update_topography_and_mask(self, hmin, topography_source="ETOPO5") -> None:
|
|
150
|
-
"""
|
|
151
|
-
|
|
115
|
+
"""Update the grid dataset by adding or overwriting the topography and land/sea
|
|
116
|
+
mask.
|
|
152
117
|
|
|
153
118
|
This method processes the topography data and generates a land/sea mask.
|
|
154
119
|
It applies several steps, including interpolating topography, smoothing
|
|
@@ -176,8 +141,7 @@ class Grid:
|
|
|
176
141
|
object.__setattr__(self, "hmin", hmin)
|
|
177
142
|
|
|
178
143
|
def _straddle(self) -> None:
|
|
179
|
-
"""
|
|
180
|
-
Check if the Greenwich meridian goes through the domain.
|
|
144
|
+
"""Check if the Greenwich meridian goes through the domain.
|
|
181
145
|
|
|
182
146
|
This method sets the `straddle` attribute to `True` if the Greenwich meridian
|
|
183
147
|
(0° longitude) intersects the domain defined by `lon_rho`. Otherwise, it sets
|
|
@@ -196,9 +160,8 @@ class Grid:
|
|
|
196
160
|
object.__setattr__(self, "straddle", False)
|
|
197
161
|
|
|
198
162
|
def _coarsen(self):
|
|
199
|
-
"""
|
|
200
|
-
|
|
201
|
-
fine-resoluion grid variables. The coarsening is by a factor of two.
|
|
163
|
+
"""Update the grid by adding grid variables that are coarsened versions of the
|
|
164
|
+
original fine-resoluion grid variables. The coarsening is by a factor of two.
|
|
202
165
|
|
|
203
166
|
The specific variables being coarsened are:
|
|
204
167
|
- `lon_rho` -> `lon_coarse`: Longitude at rho points.
|
|
@@ -249,8 +212,7 @@ class Grid:
|
|
|
249
212
|
self.ds[coarse_var].attrs["units"] = self.ds[fine_var].attrs["units"]
|
|
250
213
|
|
|
251
214
|
def update_vertical_coordinate(self, N, theta_s, theta_b, hc) -> None:
|
|
252
|
-
"""
|
|
253
|
-
Create vertical coordinate variables for the ROMS grid.
|
|
215
|
+
"""Create vertical coordinate variables for the ROMS grid.
|
|
254
216
|
|
|
255
217
|
This method computes the S-coordinate stretching curves and depths
|
|
256
218
|
at various grid points (rho, u, v) using the specified parameters.
|
|
@@ -353,8 +315,7 @@ class Grid:
|
|
|
353
315
|
object.__setattr__(self, "N", N)
|
|
354
316
|
|
|
355
317
|
def plot(self, bathymetry: bool = False) -> None:
|
|
356
|
-
"""
|
|
357
|
-
Plot the grid.
|
|
318
|
+
"""Plot the grid.
|
|
358
319
|
|
|
359
320
|
Parameters
|
|
360
321
|
----------
|
|
@@ -365,7 +326,6 @@ class Grid:
|
|
|
365
326
|
-------
|
|
366
327
|
None
|
|
367
328
|
This method does not return any value. It generates and displays a plot.
|
|
368
|
-
|
|
369
329
|
"""
|
|
370
330
|
|
|
371
331
|
if bathymetry:
|
|
@@ -396,19 +356,20 @@ class Grid:
|
|
|
396
356
|
eta=None,
|
|
397
357
|
xi=None,
|
|
398
358
|
) -> None:
|
|
399
|
-
"""
|
|
400
|
-
Plot the vertical coordinate system for a given eta-, xi-, or s-slice.
|
|
359
|
+
"""Plot the vertical coordinate system for a given eta-, xi-, or s-slice.
|
|
401
360
|
|
|
402
361
|
Parameters
|
|
403
362
|
----------
|
|
404
363
|
varname : str, optional
|
|
405
364
|
The vertical coordinate field to plot. Options include:
|
|
365
|
+
|
|
406
366
|
- "layer_depth_rho": Layer depth at rho-points.
|
|
407
367
|
- "layer_depth_u": Layer depth at u-points.
|
|
408
368
|
- "layer_depth_v": Layer depth at v-points.
|
|
409
369
|
- "interface_depth_rho": Interface depth at rho-points.
|
|
410
370
|
- "interface_depth_u": Interface depth at u-points.
|
|
411
371
|
- "interface_depth_v": Interface depth at v-points.
|
|
372
|
+
|
|
412
373
|
s: int, optional
|
|
413
374
|
The s-index to plot. Default is None.
|
|
414
375
|
eta : int, optional
|
|
@@ -526,17 +487,19 @@ class Grid:
|
|
|
526
487
|
def save(
|
|
527
488
|
self, filepath: Union[str, Path], np_eta: int = None, np_xi: int = None
|
|
528
489
|
) -> None:
|
|
529
|
-
"""
|
|
530
|
-
Save the grid information to a netCDF4 file.
|
|
490
|
+
"""Save the grid information to a netCDF4 file.
|
|
531
491
|
|
|
532
492
|
This method supports saving the dataset in two modes:
|
|
533
493
|
|
|
534
|
-
|
|
535
|
-
|
|
494
|
+
1. **Single File Mode (default)**:
|
|
495
|
+
|
|
496
|
+
If both `np_eta` and `np_xi` are `None`, the entire dataset is saved as a single netCDF4 file
|
|
497
|
+
with the base filename specified by `filepath.nc`.
|
|
498
|
+
|
|
499
|
+
2. **Partitioned Mode**:
|
|
536
500
|
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
- The files are saved as `filepath.0.nc`, `filepath.1.nc`, ..., where the numbering corresponds to the partition index.
|
|
501
|
+
- If either `np_eta` or `np_xi` is specified, the dataset is divided into spatial tiles along the eta-axis and xi-axis.
|
|
502
|
+
- Each spatial tile is saved as a separate netCDF4 file.
|
|
540
503
|
|
|
541
504
|
Parameters
|
|
542
505
|
----------
|
|
@@ -571,8 +534,7 @@ class Grid:
|
|
|
571
534
|
|
|
572
535
|
@classmethod
|
|
573
536
|
def from_file(cls, filepath: Union[str, Path]) -> "Grid":
|
|
574
|
-
"""
|
|
575
|
-
Create a Grid instance from an existing file.
|
|
537
|
+
"""Create a Grid instance from an existing file.
|
|
576
538
|
|
|
577
539
|
Parameters
|
|
578
540
|
----------
|
|
@@ -686,8 +648,8 @@ class Grid:
|
|
|
686
648
|
return grid
|
|
687
649
|
|
|
688
650
|
def to_yaml(self, filepath: Union[str, Path]) -> None:
|
|
689
|
-
"""
|
|
690
|
-
|
|
651
|
+
"""Export the parameters of the class to a YAML file, including the version of
|
|
652
|
+
roms-tools.
|
|
691
653
|
|
|
692
654
|
Parameters
|
|
693
655
|
----------
|
|
@@ -721,8 +683,7 @@ class Grid:
|
|
|
721
683
|
|
|
722
684
|
@classmethod
|
|
723
685
|
def from_yaml(cls, filepath: Union[str, Path]) -> "Grid":
|
|
724
|
-
"""
|
|
725
|
-
Create an instance of the class from a YAML file.
|
|
686
|
+
"""Create an instance of the class from a YAML file.
|
|
726
687
|
|
|
727
688
|
Parameters
|
|
728
689
|
----------
|
|
@@ -915,7 +876,7 @@ def _make_initial_lon_lat_ds(size_x, size_y, nx, ny):
|
|
|
915
876
|
|
|
916
877
|
|
|
917
878
|
def _rotate(lon, lat, lonu, latu, lonv, latv, lonq, latq, rot):
|
|
918
|
-
"""Rotate grid counterclockwise relative to surface of Earth by rot degrees"""
|
|
879
|
+
"""Rotate grid counterclockwise relative to surface of Earth by rot degrees."""
|
|
919
880
|
|
|
920
881
|
(lon, lat) = _rot_sphere(lon, lat, rot)
|
|
921
882
|
(lonu, latu) = _rot_sphere(lonu, latu, rot)
|
|
@@ -1055,7 +1016,8 @@ def _tra_sphere(lon, lat, tra):
|
|
|
1055
1016
|
|
|
1056
1017
|
|
|
1057
1018
|
def _compute_coordinate_metrics(lon, lonu, latu, lonv, latv):
|
|
1058
|
-
"""Compute the curvilinear coordinate metrics pn and pm, defined as 1/grid
|
|
1019
|
+
"""Compute the curvilinear coordinate metrics pn and pm, defined as 1/grid
|
|
1020
|
+
spacing."""
|
|
1059
1021
|
|
|
1060
1022
|
# pm = 1/dx
|
|
1061
1023
|
pmu = gc_dist(lonu[:, :-1], latu[:, :-1], lonu[:, 1:], latu[:, 1:])
|
|
@@ -1096,7 +1058,7 @@ def gc_dist(lon1, lat1, lon2, lat2):
|
|
|
1096
1058
|
|
|
1097
1059
|
|
|
1098
1060
|
def _compute_angle(lon, lonu, latu, lonq):
|
|
1099
|
-
"""Compute angles of local grid positive x-axis relative to east"""
|
|
1061
|
+
"""Compute angles of local grid positive x-axis relative to east."""
|
|
1100
1062
|
|
|
1101
1063
|
dellat = latu[:, 1:] - latu[:, :-1]
|
|
1102
1064
|
dellon = lonu[:, 1:] - lonu[:, :-1]
|
|
@@ -1166,16 +1128,16 @@ def _create_grid_ds(
|
|
|
1166
1128
|
dims=["eta_v", "xi_rho"],
|
|
1167
1129
|
attrs={"long_name": "latitude of v-points", "units": "degrees North"},
|
|
1168
1130
|
)
|
|
1169
|
-
lon_q = xr.Variable(
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
)
|
|
1174
|
-
lat_q = xr.Variable(
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
)
|
|
1131
|
+
# lon_q = xr.Variable(
|
|
1132
|
+
# data=lonq * 180 / np.pi,
|
|
1133
|
+
# dims=["eta_psi", "xi_psi"],
|
|
1134
|
+
# attrs={"long_name": "longitude of psi-points", "units": "degrees East"},
|
|
1135
|
+
# )
|
|
1136
|
+
# lat_q = xr.Variable(
|
|
1137
|
+
# data=latq * 180 / np.pi,
|
|
1138
|
+
# dims=["eta_psi", "xi_psi"],
|
|
1139
|
+
# attrs={"long_name": "latitude of psi-points", "units": "degrees North"},
|
|
1140
|
+
# )
|
|
1179
1141
|
|
|
1180
1142
|
ds = ds.assign_coords(
|
|
1181
1143
|
{
|
|
@@ -1185,8 +1147,8 @@ def _create_grid_ds(
|
|
|
1185
1147
|
"lon_u": lon_u,
|
|
1186
1148
|
"lat_v": lat_v,
|
|
1187
1149
|
"lon_v": lon_v,
|
|
1188
|
-
"lat_psi": lat_q,
|
|
1189
|
-
"lon_psi": lon_q,
|
|
1150
|
+
# "lat_psi": lat_q,
|
|
1151
|
+
# "lon_psi": lon_q,
|
|
1190
1152
|
}
|
|
1191
1153
|
)
|
|
1192
1154
|
|
|
@@ -1250,8 +1212,7 @@ def _add_global_metadata(ds, size_x, size_y, center_lon, center_lat, rot):
|
|
|
1250
1212
|
|
|
1251
1213
|
|
|
1252
1214
|
def _f2c(f):
|
|
1253
|
-
"""
|
|
1254
|
-
Coarsen input xarray DataArray f in both x- and y-direction.
|
|
1215
|
+
"""Coarsen input xarray DataArray f in both x- and y-direction.
|
|
1255
1216
|
|
|
1256
1217
|
Parameters
|
|
1257
1218
|
----------
|
|
@@ -1274,8 +1235,7 @@ def _f2c(f):
|
|
|
1274
1235
|
|
|
1275
1236
|
|
|
1276
1237
|
def _f2c_xdir(f):
|
|
1277
|
-
"""
|
|
1278
|
-
Coarsen input xarray DataArray f in x-direction.
|
|
1238
|
+
"""Coarsen input xarray DataArray f in x-direction.
|
|
1279
1239
|
|
|
1280
1240
|
Parameters
|
|
1281
1241
|
----------
|
|
@@ -1305,12 +1265,13 @@ def _f2c_xdir(f):
|
|
|
1305
1265
|
|
|
1306
1266
|
|
|
1307
1267
|
def _add_lat_lon_at_velocity_points(ds, straddle):
|
|
1308
|
-
"""
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1268
|
+
"""Adds latitude and longitude coordinates at velocity points (u and v points) to
|
|
1269
|
+
the dataset. This function computes approximate latitude and longitude values at u
|
|
1270
|
+
and v velocity points based on the rho points (cell centers). If the grid straddles
|
|
1271
|
+
the Greenwich meridian, it adjusts the longitudes to avoid jumps from 360 to 0
|
|
1272
|
+
degrees. The computed coordinates are added to the dataset as new variables with
|
|
1273
|
+
appropriate metadata.
|
|
1274
|
+
|
|
1314
1275
|
Parameters
|
|
1315
1276
|
----------
|
|
1316
1277
|
ds : xarray.Dataset
|
|
@@ -21,8 +21,8 @@ from pathlib import Path
|
|
|
21
21
|
|
|
22
22
|
@dataclass(frozen=True, kw_only=True)
|
|
23
23
|
class InitialConditions(ROMSToolsMixins):
|
|
24
|
-
"""
|
|
25
|
-
|
|
24
|
+
"""Represents initial conditions for ROMS, including physical and biogeochemical
|
|
25
|
+
data.
|
|
26
26
|
|
|
27
27
|
Parameters
|
|
28
28
|
----------
|
|
@@ -32,27 +32,33 @@ class InitialConditions(ROMSToolsMixins):
|
|
|
32
32
|
The date and time at which the initial conditions are set.
|
|
33
33
|
If no exact match is found, the closest time entry to `ini_time` within the time range [ini_time, ini_time + 24 hours] is selected.
|
|
34
34
|
source : Dict[str, Union[str, Path, List[Union[str, Path]]], bool]
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
35
|
+
|
|
36
|
+
Dictionary specifying the source of the physical initial condition data. Keys include:
|
|
37
|
+
|
|
38
|
+
- "name" (str): Name of the data source (e.g., "GLORYS").
|
|
39
|
+
- "path" (Union[str, Path, List[Union[str, Path]]]): The path to the raw data file(s). This can be:
|
|
40
|
+
|
|
41
|
+
- A single string (with or without wildcards).
|
|
42
|
+
- A single Path object.
|
|
43
|
+
- A list of strings or Path objects containing multiple files.
|
|
44
|
+
- "climatology" (bool): Indicates if the data is climatology data. Defaults to False.
|
|
45
|
+
|
|
46
|
+
bgc_source : Dict[str, Union[str, Path, List[Union[str, Path]]], bool]
|
|
47
|
+
Dictionary specifying the source of the biogeochemical (BGC) initial condition data. Keys include:
|
|
48
|
+
|
|
49
|
+
- "name" (str): Name of the data source (e.g., "CESM_REGRIDDED").
|
|
50
|
+
- "path" (Union[str, Path, List[Union[str, Path]]]): The path to the raw data file(s). This can be:
|
|
51
|
+
|
|
52
|
+
- A single string (with or without wildcards).
|
|
53
|
+
- A single Path object.
|
|
54
|
+
- A list of strings or Path objects containing multiple files.
|
|
55
|
+
- "climatology" (bool): Indicates if the data is climatology data. Defaults to False.
|
|
56
|
+
|
|
46
57
|
model_reference_date : datetime, optional
|
|
47
58
|
The reference date for the model. Defaults to January 1, 2000.
|
|
48
59
|
use_dask: bool, optional
|
|
49
60
|
Indicates whether to use dask for processing. If True, data is processed with dask; if False, data is processed eagerly. Defaults to False.
|
|
50
61
|
|
|
51
|
-
Attributes
|
|
52
|
-
----------
|
|
53
|
-
ds : xr.Dataset
|
|
54
|
-
Xarray Dataset containing the initial condition data loaded from the specified files.
|
|
55
|
-
|
|
56
62
|
Examples
|
|
57
63
|
--------
|
|
58
64
|
>>> initial_conditions = InitialConditions(
|
|
@@ -79,7 +85,7 @@ class InitialConditions(ROMSToolsMixins):
|
|
|
79
85
|
def __post_init__(self):
|
|
80
86
|
|
|
81
87
|
self._input_checks()
|
|
82
|
-
lon, lat, angle, straddle = super().
|
|
88
|
+
lon, lat, angle, straddle = super()._get_target_lon_lat()
|
|
83
89
|
|
|
84
90
|
data = self._get_data()
|
|
85
91
|
data.choose_subdomain(
|
|
@@ -91,8 +97,8 @@ class InitialConditions(ROMSToolsMixins):
|
|
|
91
97
|
|
|
92
98
|
vars_2d = ["zeta"]
|
|
93
99
|
vars_3d = ["temp", "salt", "u", "v"]
|
|
94
|
-
data_vars = super().
|
|
95
|
-
data_vars = super().
|
|
100
|
+
data_vars = super()._regrid_data(data, vars_2d, vars_3d, lon, lat)
|
|
101
|
+
data_vars = super()._process_velocities(data_vars, angle, "u", "v")
|
|
96
102
|
|
|
97
103
|
if self.bgc_source is not None:
|
|
98
104
|
bgc_data = self._get_bgc_data()
|
|
@@ -105,7 +111,7 @@ class InitialConditions(ROMSToolsMixins):
|
|
|
105
111
|
|
|
106
112
|
vars_2d = []
|
|
107
113
|
vars_3d = bgc_data.var_names.keys()
|
|
108
|
-
bgc_data_vars = super().
|
|
114
|
+
bgc_data_vars = super()._regrid_data(bgc_data, vars_2d, vars_3d, lon, lat)
|
|
109
115
|
|
|
110
116
|
# Ensure time coordinate matches that of physical variables
|
|
111
117
|
for var in bgc_data_vars.keys():
|
|
@@ -277,13 +283,13 @@ class InitialConditions(ROMSToolsMixins):
|
|
|
277
283
|
depth_contours=False,
|
|
278
284
|
layer_contours=False,
|
|
279
285
|
) -> None:
|
|
280
|
-
"""
|
|
281
|
-
Plot the initial conditions field for a given eta-, xi-, or s_rho-slice.
|
|
286
|
+
"""Plot the initial conditions field for a given eta-, xi-, or s_rho- slice.
|
|
282
287
|
|
|
283
288
|
Parameters
|
|
284
289
|
----------
|
|
285
290
|
varname : str
|
|
286
291
|
The name of the initial conditions field to plot. Options include:
|
|
292
|
+
|
|
287
293
|
- "temp": Potential temperature.
|
|
288
294
|
- "salt": Salinity.
|
|
289
295
|
- "zeta": Free surface.
|
|
@@ -324,6 +330,7 @@ class InitialConditions(ROMSToolsMixins):
|
|
|
324
330
|
- "diazC": Diazotroph Carbon (mmol/m³).
|
|
325
331
|
- "diazP": Diazotroph Phosphorus (mmol/m³).
|
|
326
332
|
- "diazFe": Diazotroph Iron (mmol/m³).
|
|
333
|
+
|
|
327
334
|
s : int, optional
|
|
328
335
|
The index of the vertical layer (`s_rho`) to plot. If not specified, the plot
|
|
329
336
|
will represent a horizontal slice (eta- or xi- plane). Default is None.
|
|
@@ -354,7 +361,6 @@ class InitialConditions(ROMSToolsMixins):
|
|
|
354
361
|
If the specified `varname` is not one of the valid options.
|
|
355
362
|
If the field specified by `varname` is 3D and none of `s`, `eta`, or `xi` are specified.
|
|
356
363
|
If the field specified by `varname` is 2D and both `eta` and `xi` are specified.
|
|
357
|
-
|
|
358
364
|
"""
|
|
359
365
|
|
|
360
366
|
if len(self.ds[varname].squeeze().dims) == 3 and not any(
|
|
@@ -492,17 +498,19 @@ class InitialConditions(ROMSToolsMixins):
|
|
|
492
498
|
def save(
|
|
493
499
|
self, filepath: Union[str, Path], np_eta: int = None, np_xi: int = None
|
|
494
500
|
) -> None:
|
|
495
|
-
"""
|
|
496
|
-
Save the initial conditions information to a netCDF4 file.
|
|
501
|
+
"""Save the initial conditions information to a netCDF4 file.
|
|
497
502
|
|
|
498
503
|
This method supports saving the dataset in two modes:
|
|
499
504
|
|
|
500
|
-
|
|
501
|
-
- If both `np_eta` and `np_xi` are `None`, the entire dataset is saved as a single file at the specified `filepath.nc`.
|
|
505
|
+
1. **Single File Mode (default)**:
|
|
502
506
|
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
507
|
+
If both `np_eta` and `np_xi` are `None`, the entire dataset is saved as a single netCDF4 file
|
|
508
|
+
with the base filename specified by `filepath.nc`.
|
|
509
|
+
|
|
510
|
+
2. **Partitioned Mode**:
|
|
511
|
+
|
|
512
|
+
- If either `np_eta` or `np_xi` is specified, the dataset is divided into spatial tiles along the eta-axis and xi-axis.
|
|
513
|
+
- Each spatial tile is saved as a separate netCDF4 file.
|
|
506
514
|
|
|
507
515
|
Parameters
|
|
508
516
|
----------
|
|
@@ -536,8 +544,8 @@ class InitialConditions(ROMSToolsMixins):
|
|
|
536
544
|
return saved_filenames
|
|
537
545
|
|
|
538
546
|
def to_yaml(self, filepath: Union[str, Path]) -> None:
|
|
539
|
-
"""
|
|
540
|
-
|
|
547
|
+
"""Export the parameters of the class to a YAML file, including the version of
|
|
548
|
+
roms-tools.
|
|
541
549
|
|
|
542
550
|
Parameters
|
|
543
551
|
----------
|
|
@@ -588,8 +596,7 @@ class InitialConditions(ROMSToolsMixins):
|
|
|
588
596
|
def from_yaml(
|
|
589
597
|
cls, filepath: Union[str, Path], use_dask: bool = False
|
|
590
598
|
) -> "InitialConditions":
|
|
591
|
-
"""
|
|
592
|
-
Create an instance of the InitialConditions class from a YAML file.
|
|
599
|
+
"""Create an instance of the InitialConditions class from a YAML file.
|
|
593
600
|
|
|
594
601
|
Parameters
|
|
595
602
|
----------
|
roms_tools/setup/mixins.py
CHANGED
|
@@ -12,22 +12,20 @@ import numpy as np
|
|
|
12
12
|
|
|
13
13
|
@dataclass(frozen=True, kw_only=True)
|
|
14
14
|
class ROMSToolsMixins:
|
|
15
|
-
"""
|
|
16
|
-
Represents a mixin tool for ROMS-Tools with capabilities shared by the various
|
|
15
|
+
"""Represents a mixin tool for ROMS-Tools with capabilities shared by the various
|
|
17
16
|
ROMS-Tools dataclasses.
|
|
18
17
|
|
|
19
18
|
Parameters
|
|
20
19
|
----------
|
|
21
20
|
grid : Grid
|
|
22
21
|
Object representing the grid information used for the model.
|
|
23
|
-
|
|
24
22
|
"""
|
|
25
23
|
|
|
26
24
|
grid: Grid
|
|
27
25
|
|
|
28
|
-
def
|
|
29
|
-
"""
|
|
30
|
-
|
|
26
|
+
def _get_target_lon_lat(self, use_coarse_grid=False):
|
|
27
|
+
"""Retrieves the longitude and latitude arrays from the grid and adjusts them
|
|
28
|
+
based on the grid's orientation.
|
|
31
29
|
|
|
32
30
|
This method provides longitude and latitude coordinates, with options for using a coarse grid
|
|
33
31
|
if specified. It also handles longitudes to ensure they are between -180 and 180 degrees and adjusts
|
|
@@ -67,10 +65,9 @@ class ROMSToolsMixins:
|
|
|
67
65
|
|
|
68
66
|
return lon, lat, angle, straddle
|
|
69
67
|
|
|
70
|
-
def
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
Interpolates data onto the desired grid and processes it for 2D and 3D variables.
|
|
68
|
+
def _regrid_data(self, data, vars_2d, vars_3d, lon, lat):
|
|
69
|
+
"""Interpolates data onto the desired grid and processes it for 2D and 3D
|
|
70
|
+
variables.
|
|
74
71
|
|
|
75
72
|
This method interpolates the specified 2D and 3D variables onto a new grid defined by the provided
|
|
76
73
|
longitude and latitude coordinates. It handles both 2D and 3D data, performing extrapolation for 3D
|
|
@@ -164,10 +161,9 @@ class ROMSToolsMixins:
|
|
|
164
161
|
|
|
165
162
|
return data_vars
|
|
166
163
|
|
|
167
|
-
def
|
|
168
|
-
"""
|
|
169
|
-
|
|
170
|
-
them to the appropriate grid points.
|
|
164
|
+
def _process_velocities(self, data_vars, angle, uname, vname, interpolate=True):
|
|
165
|
+
"""Process and rotate velocity components to align with the grid orientation and
|
|
166
|
+
optionally interpolate them to the appropriate grid points.
|
|
171
167
|
|
|
172
168
|
This method performs the following steps:
|
|
173
169
|
|