roms-tools 2.3.0__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 +1 -0
- roms_tools/analysis/roms_output.py +10 -6
- roms_tools/setup/boundary_forcing.py +178 -193
- roms_tools/setup/datasets.py +58 -1
- roms_tools/setup/grid.py +31 -97
- roms_tools/setup/initial_conditions.py +172 -126
- roms_tools/setup/nesting.py +2 -23
- roms_tools/setup/river_forcing.py +34 -67
- roms_tools/setup/surface_forcing.py +111 -61
- roms_tools/setup/tides.py +7 -30
- roms_tools/setup/utils.py +24 -70
- roms_tools/tests/test_setup/test_boundary_forcing.py +220 -57
- 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_grid.py +0 -13
- roms_tools/tests/test_setup/test_initial_conditions.py +204 -66
- roms_tools/tests/test_setup/test_nesting.py +0 -16
- roms_tools/tests/test_setup/test_river_forcing.py +8 -36
- roms_tools/tests/test_setup/test_surface_forcing.py +102 -73
- roms_tools/tests/test_setup/test_tides.py +4 -16
- roms_tools/tests/test_setup/test_utils.py +1 -0
- roms_tools/tests/{test_utils.py → test_tiling/test_partition.py} +1 -1
- roms_tools/tiling/partition.py +338 -0
- roms_tools/utils.py +66 -333
- roms_tools/vertical_coordinate.py +54 -133
- {roms_tools-2.3.0.dist-info → roms_tools-2.4.0.dist-info}/METADATA +1 -1
- {roms_tools-2.3.0.dist-info → roms_tools-2.4.0.dist-info}/RECORD +143 -136
- {roms_tools-2.3.0.dist-info → roms_tools-2.4.0.dist-info}/LICENSE +0 -0
- {roms_tools-2.3.0.dist-info → roms_tools-2.4.0.dist-info}/WHEEL +0 -0
- {roms_tools-2.3.0.dist-info → roms_tools-2.4.0.dist-info}/top_level.txt +0 -0
roms_tools/setup/datasets.py
CHANGED
|
@@ -355,6 +355,47 @@ class Dataset:
|
|
|
355
355
|
# Set the computed resolution as an attribute
|
|
356
356
|
object.__setattr__(self, "resolution", resolution)
|
|
357
357
|
|
|
358
|
+
def compute_minimal_grid_spacing(self, ds: xr.Dataset):
|
|
359
|
+
"""Compute the minimal grid spacing in a dataset based on latitude and longitude
|
|
360
|
+
spacing, considering Earth's radius.
|
|
361
|
+
|
|
362
|
+
Parameters
|
|
363
|
+
----------
|
|
364
|
+
ds : xr.Dataset
|
|
365
|
+
Dataset containing latitude and longitude dimensions.
|
|
366
|
+
|
|
367
|
+
Returns
|
|
368
|
+
-------
|
|
369
|
+
minimal_spacing : float
|
|
370
|
+
The smallest horizontal grid spacing derived from the latitude
|
|
371
|
+
and longitude differences, in meters.
|
|
372
|
+
"""
|
|
373
|
+
|
|
374
|
+
r_earth = 6371315.0
|
|
375
|
+
lat_dim = self.dim_names["latitude"]
|
|
376
|
+
lon_dim = self.dim_names["longitude"]
|
|
377
|
+
|
|
378
|
+
# Get latitude and longitude values from the dataset
|
|
379
|
+
latitudes = ds[lat_dim].values
|
|
380
|
+
longitudes = ds[lon_dim].values
|
|
381
|
+
|
|
382
|
+
# Compute differences along latitude and longitude
|
|
383
|
+
lat_diff = np.abs(np.diff(latitudes)).min() # Minimal latitude spacing
|
|
384
|
+
lon_diff = np.abs(np.diff(longitudes)).min() # Minimal longitude spacing
|
|
385
|
+
|
|
386
|
+
# Latitude spacing is constant at all longitudes
|
|
387
|
+
min_lat_spacing = (2 * np.pi * r_earth * lat_diff) / 360
|
|
388
|
+
|
|
389
|
+
# Longitude spacing varies with latitude
|
|
390
|
+
min_lon_spacing = (
|
|
391
|
+
2 * np.pi * r_earth * lon_diff * np.cos(np.radians(latitudes.min()))
|
|
392
|
+
) / 360
|
|
393
|
+
|
|
394
|
+
# The minimal spacing is the smaller of the two
|
|
395
|
+
minimal_spacing = min(min_lat_spacing, min_lon_spacing)
|
|
396
|
+
|
|
397
|
+
return minimal_spacing
|
|
398
|
+
|
|
358
399
|
def check_if_global(self, ds) -> bool:
|
|
359
400
|
"""Checks if the dataset covers the entire globe in the longitude dimension.
|
|
360
401
|
|
|
@@ -470,7 +511,12 @@ class Dataset:
|
|
|
470
511
|
pass
|
|
471
512
|
|
|
472
513
|
def choose_subdomain(
|
|
473
|
-
self,
|
|
514
|
+
self,
|
|
515
|
+
target_coords,
|
|
516
|
+
buffer_points=20,
|
|
517
|
+
return_copy=False,
|
|
518
|
+
return_coords_only=False,
|
|
519
|
+
verbose=False,
|
|
474
520
|
):
|
|
475
521
|
"""Selects a subdomain from the xarray Dataset based on specified target
|
|
476
522
|
coordinates, extending the selection by a defined buffer. Adjusts longitude
|
|
@@ -488,6 +534,9 @@ class Dataset:
|
|
|
488
534
|
return_subdomain : bool, optional
|
|
489
535
|
If True, returns the subset of the original dataset representing the chosen
|
|
490
536
|
subdomain. If False, assigns the subset to `self.ds`. Defaults to False.
|
|
537
|
+
return_coords_only : bool, optional
|
|
538
|
+
If True, returns a new xarray.Dataset containing only the latitude and longitude
|
|
539
|
+
of the subdomain. Defaults to False.
|
|
491
540
|
verbose : bool, optional
|
|
492
541
|
If True, print message if dataset is concatenated along longitude dimension.
|
|
493
542
|
Defaults to False.
|
|
@@ -592,6 +641,13 @@ class Dataset:
|
|
|
592
641
|
else:
|
|
593
642
|
subdomain[self.dim_names["longitude"]] = xr.where(lon < 0, lon + 360, lon)
|
|
594
643
|
|
|
644
|
+
if return_coords_only:
|
|
645
|
+
# Create and return a dataset with only latitudes and longitudes
|
|
646
|
+
coords_ds = subdomain[
|
|
647
|
+
[self.dim_names["latitude"], self.dim_names["longitude"]]
|
|
648
|
+
]
|
|
649
|
+
return coords_ds
|
|
650
|
+
|
|
595
651
|
if return_copy:
|
|
596
652
|
return Dataset.from_ds(self, subdomain)
|
|
597
653
|
else:
|
|
@@ -2058,6 +2114,7 @@ def _select_relevant_times(
|
|
|
2058
2114
|
)
|
|
2059
2115
|
if not end_time:
|
|
2060
2116
|
# Interpolate from climatology for initial conditions
|
|
2117
|
+
ds["time"] = ds["time"].dt.days
|
|
2061
2118
|
ds = interpolate_from_climatology(ds, time_dim, start_time)
|
|
2062
2119
|
else:
|
|
2063
2120
|
time_type = get_time_type(ds[time_dim])
|
roms_tools/setup/grid.py
CHANGED
|
@@ -8,13 +8,10 @@ import matplotlib.pyplot as plt
|
|
|
8
8
|
import yaml
|
|
9
9
|
import importlib.metadata
|
|
10
10
|
from typing import Dict, Union, List
|
|
11
|
+
from roms_tools.utils import save_datasets
|
|
11
12
|
from roms_tools.setup.topography import _add_topography
|
|
12
13
|
from roms_tools.setup.mask import _add_mask, _add_velocity_masks
|
|
13
|
-
from roms_tools.vertical_coordinate import
|
|
14
|
-
sigma_stretch,
|
|
15
|
-
compute_depth,
|
|
16
|
-
add_depth_coordinates_to_dataset,
|
|
17
|
-
)
|
|
14
|
+
from roms_tools.vertical_coordinate import compute_depth_coordinates, sigma_stretch
|
|
18
15
|
from roms_tools.plot import _plot, _section_plot
|
|
19
16
|
from roms_tools.setup.utils import (
|
|
20
17
|
interpolate_from_rho_to_u,
|
|
@@ -22,7 +19,7 @@ from roms_tools.setup.utils import (
|
|
|
22
19
|
get_target_coords,
|
|
23
20
|
gc_dist,
|
|
24
21
|
)
|
|
25
|
-
from roms_tools.setup.utils import extract_single_value
|
|
22
|
+
from roms_tools.setup.utils import extract_single_value
|
|
26
23
|
from pathlib import Path
|
|
27
24
|
|
|
28
25
|
|
|
@@ -396,14 +393,14 @@ class Grid:
|
|
|
396
393
|
object.__setattr__(self, "ds", ds)
|
|
397
394
|
|
|
398
395
|
def plot(
|
|
399
|
-
self, bathymetry: bool =
|
|
396
|
+
self, bathymetry: bool = True, title: str = None, with_dim_names: bool = False
|
|
400
397
|
) -> None:
|
|
401
398
|
"""Plot the grid.
|
|
402
399
|
|
|
403
400
|
Parameters
|
|
404
401
|
----------
|
|
405
402
|
bathymetry : bool, optional
|
|
406
|
-
Whether or not to plot the bathymetry. Default is
|
|
403
|
+
Whether or not to plot the bathymetry. Default is True.
|
|
407
404
|
title : str, optional
|
|
408
405
|
The title of the plot. If not provided, it will be set to a default.
|
|
409
406
|
with_dim_names : bool, optional
|
|
@@ -446,41 +443,6 @@ class Grid:
|
|
|
446
443
|
field=field, title=title, with_dim_names=with_dim_names, plot_data=False
|
|
447
444
|
)
|
|
448
445
|
|
|
449
|
-
def compute_depth_coordinates(
|
|
450
|
-
self, depth_type: str, locations: list[str] = ["rho", "u", "v"]
|
|
451
|
-
):
|
|
452
|
-
"""Compute and update vertical depth coordinates.
|
|
453
|
-
|
|
454
|
-
Calculates vertical depth coordinates (layer or interface) for specified locations (e.g., rho, u, v points)
|
|
455
|
-
and updates them in the dataset (`self.ds`).
|
|
456
|
-
|
|
457
|
-
Parameters
|
|
458
|
-
----------
|
|
459
|
-
depth_type : str
|
|
460
|
-
The type of depth coordinate to compute. Valid options:
|
|
461
|
-
- "layer": Compute layer depth coordinates.
|
|
462
|
-
- "interface": Compute interface depth coordinates.
|
|
463
|
-
locations : list[str], optional
|
|
464
|
-
Locations for which to compute depth coordinates. Default is ["rho", "u", "v"].
|
|
465
|
-
Valid options include:
|
|
466
|
-
- "rho": Depth coordinates at rho points.
|
|
467
|
-
- "u": Depth coordinates at u points.
|
|
468
|
-
- "v": Depth coordinates at v points.
|
|
469
|
-
|
|
470
|
-
Updates
|
|
471
|
-
-------
|
|
472
|
-
self.ds : xarray.Dataset
|
|
473
|
-
The dataset (`self.ds`) is updated with the following depth coordinate variables:
|
|
474
|
-
- f"{depth_type}_depth_rho": Depth coordinates at rho points.
|
|
475
|
-
- f"{depth_type}_depth_u": Depth coordinates at u points (if included in `locations`).
|
|
476
|
-
- f"{depth_type}_depth_v": Depth coordinates at v points (if included in `locations`).
|
|
477
|
-
|
|
478
|
-
Notes
|
|
479
|
-
-----
|
|
480
|
-
This method uses the `compute_and_update_depth_coordinates` function to perform calculations and updates.
|
|
481
|
-
"""
|
|
482
|
-
add_depth_coordinates_to_dataset(self.ds, self.ds, depth_type, locations)
|
|
483
|
-
|
|
484
446
|
def plot_vertical_coordinate(
|
|
485
447
|
self,
|
|
486
448
|
s=None,
|
|
@@ -511,56 +473,48 @@ class Grid:
|
|
|
511
473
|
If not exactly one of s, eta, xi is specified.
|
|
512
474
|
"""
|
|
513
475
|
|
|
514
|
-
title = "Layer depth at rho-points"
|
|
515
|
-
|
|
516
476
|
if sum(s is not None for s in [s, eta, xi]) != 1:
|
|
517
477
|
raise ValueError("Exactly one of s, eta, or xi must be specified.")
|
|
518
478
|
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
if self.straddle:
|
|
523
|
-
lon_deg = xr.where(lon_deg > 180, lon_deg - 360, lon_deg)
|
|
524
|
-
h = h.assign_coords({"lon": lon_deg, "lat": lat_deg})
|
|
479
|
+
depth = compute_depth_coordinates(
|
|
480
|
+
self.ds, zeta=0, depth_type="layer", location="rho", eta=eta, xi=xi
|
|
481
|
+
)
|
|
525
482
|
|
|
526
|
-
|
|
483
|
+
title = "Layer depth at rho-points"
|
|
527
484
|
if eta is not None:
|
|
528
|
-
title = title + f", eta_rho = {
|
|
529
|
-
h = h.isel(eta_rho=eta)
|
|
485
|
+
title = title + f", eta_rho = {self.ds.eta_rho[eta].item()}"
|
|
530
486
|
if xi is not None:
|
|
531
|
-
title = title + f", xi_rho = {
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
layer_depth = compute_depth(0, h, self.hc, self.ds.Cs_r, self.ds.sigma_r)
|
|
536
|
-
title = title + f", s_rho = {layer_depth.s_rho[s].item()}"
|
|
537
|
-
layer_depth = layer_depth.isel(s_rho=s)
|
|
487
|
+
title = title + f", xi_rho = {self.ds.xi_rho[xi].item()}"
|
|
488
|
+
if s is not None:
|
|
489
|
+
title = title + f", s_rho = {depth.s_rho[s].item()}"
|
|
490
|
+
depth = depth.isel(s_rho=s)
|
|
538
491
|
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
vmax = layer_depth.max().values
|
|
543
|
-
vmin = layer_depth.min().values
|
|
492
|
+
vmax = depth.max().values
|
|
493
|
+
vmin = depth.min().values
|
|
544
494
|
cmap = plt.colormaps.get_cmap("YlGnBu")
|
|
545
495
|
cmap.set_bad(color="gray")
|
|
546
496
|
kwargs = {"vmax": vmax, "vmin": vmin, "cmap": cmap}
|
|
547
497
|
|
|
498
|
+
lat_deg = self.ds.lat_rho
|
|
499
|
+
lon_deg = self.ds.lon_rho
|
|
500
|
+
if self.straddle:
|
|
501
|
+
lon_deg = xr.where(lon_deg > 180, lon_deg - 360, lon_deg)
|
|
502
|
+
depth = depth.assign_coords({"lon": lon_deg, "lat": lat_deg})
|
|
503
|
+
|
|
548
504
|
_plot(
|
|
549
|
-
field=
|
|
505
|
+
field=depth.where(self.ds.mask_rho),
|
|
550
506
|
depth_contours=False,
|
|
551
507
|
title=title,
|
|
552
508
|
kwargs=kwargs,
|
|
553
509
|
)
|
|
554
510
|
else:
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
interface_depth = compute_depth(
|
|
562
|
-
0, h, self.hc, self.ds.Cs_w, self.ds.sigma_w
|
|
511
|
+
field = xr.zeros_like(depth)
|
|
512
|
+
field = field.assign_coords({"layer_depth": depth})
|
|
513
|
+
|
|
514
|
+
interface_depth = compute_depth_coordinates(
|
|
515
|
+
self.ds, zeta=0, depth_type="interface", eta=eta, xi=xi
|
|
563
516
|
)
|
|
517
|
+
|
|
564
518
|
cmap = plt.colormaps.get_cmap("YlGnBu")
|
|
565
519
|
cmap.set_bad(color="gray")
|
|
566
520
|
kwargs = {"vmax": 0.0, "vmin": 0.0, "cmap": cmap, "add_colorbar": False}
|
|
@@ -572,31 +526,13 @@ class Grid:
|
|
|
572
526
|
kwargs=kwargs,
|
|
573
527
|
)
|
|
574
528
|
|
|
575
|
-
def save(
|
|
576
|
-
self, filepath: Union[str, Path], np_eta: int = None, np_xi: int = None
|
|
577
|
-
) -> None:
|
|
529
|
+
def save(self, filepath: Union[str, Path]) -> None:
|
|
578
530
|
"""Save the grid information to a netCDF4 file.
|
|
579
531
|
|
|
580
|
-
This method supports saving the dataset in two modes:
|
|
581
|
-
|
|
582
|
-
1. **Single File Mode (default)**:
|
|
583
|
-
|
|
584
|
-
If both `np_eta` and `np_xi` are `None`, the entire dataset is saved as a single netCDF4 file
|
|
585
|
-
with the base filename specified by `filepath.nc`.
|
|
586
|
-
|
|
587
|
-
2. **Partitioned Mode**:
|
|
588
|
-
|
|
589
|
-
- If either `np_eta` or `np_xi` is specified, the dataset is divided into spatial tiles along the eta-axis and xi-axis.
|
|
590
|
-
- Each spatial tile is saved as a separate netCDF4 file.
|
|
591
|
-
|
|
592
532
|
Parameters
|
|
593
533
|
----------
|
|
594
534
|
filepath : Union[str, Path]
|
|
595
535
|
The base path or filename where the dataset should be saved.
|
|
596
|
-
np_eta : int, optional
|
|
597
|
-
The number of partitions along the `eta` direction. If `None`, no spatial partitioning is performed.
|
|
598
|
-
np_xi : int, optional
|
|
599
|
-
The number of partitions along the `xi` direction. If `None`, no spatial partitioning is performed.
|
|
600
536
|
|
|
601
537
|
Returns
|
|
602
538
|
-------
|
|
@@ -614,9 +550,7 @@ class Grid:
|
|
|
614
550
|
dataset_list = [self.ds.load()]
|
|
615
551
|
output_filenames = [str(filepath)]
|
|
616
552
|
|
|
617
|
-
saved_filenames = save_datasets(
|
|
618
|
-
dataset_list, output_filenames, np_eta=np_eta, np_xi=np_xi
|
|
619
|
-
)
|
|
553
|
+
saved_filenames = save_datasets(dataset_list, output_filenames)
|
|
620
554
|
|
|
621
555
|
return saved_filenames
|
|
622
556
|
|