roms-tools 2.5.0__py3-none-any.whl → 2.6.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.
@@ -0,0 +1,137 @@
1
+ import numpy as np
2
+
3
+
4
+ def _validate_plot_inputs(field, s, eta, xi, depth, lat, lon, include_boundary):
5
+ """Validate input parameters for the plot method.
6
+
7
+ Parameters
8
+ ----------
9
+ field : xr.DataArray
10
+ Input data to be plotted.
11
+ s : int, float, or None
12
+ Depth level index or value for the s-coordinate. Use None for surface plotting.
13
+ eta : int or None
14
+ Eta index for ROMS grid selection. Must be within bounds.
15
+ xi : int or None
16
+ Xi index for ROMS grid selection. Must be within bounds.
17
+ depth : int, float, or None
18
+ Depth value for slicing. Not yet implemented.
19
+ lat : float or None
20
+ Latitude value for slicing. Must be specified with `lon` if provided.
21
+ lon : float or None
22
+ Longitude value for slicing. Must be specified with `lat` if provided.
23
+ include_boundary : bool
24
+ Whether to include boundary points when selecting grid indices.
25
+
26
+ Raises
27
+ ------
28
+ ValueError
29
+ If conflicting dimensions are specified.
30
+ If eta or xi indices are out of bounds.
31
+ If eta or xi lie on the boundary when `include_boundary=False`.
32
+ """
33
+
34
+ # Check conflicting dimension choices
35
+ if s is not None and depth is not None:
36
+ raise ValueError(
37
+ "Conflicting input: You cannot specify both 's' and 'depth' at the same time."
38
+ )
39
+ if any([eta is not None, xi is not None]) and any(
40
+ [lat is not None, lon is not None]
41
+ ):
42
+ raise ValueError(
43
+ "Conflicting input: You cannot specify 'lat' or 'lon' simultaneously with 'eta' or 'xi'."
44
+ )
45
+
46
+ # 3D fields: Check for valid dimension specification
47
+ if len(field.dims) == 3:
48
+ if not any(
49
+ [
50
+ s is not None,
51
+ eta is not None,
52
+ xi is not None,
53
+ depth is not None,
54
+ lat is not None,
55
+ lon is not None,
56
+ ]
57
+ ):
58
+ raise ValueError(
59
+ "Invalid input: For 3D fields, you must specify at least one of the dimensions 's', 'eta', 'xi', 'depth', 'lat', or 'lon'."
60
+ )
61
+ if sum([dim is not None for dim in [s, eta, xi, depth, lat, lon]]) > 2:
62
+ raise ValueError(
63
+ "Ambiguous input: For 3D fields, specify at most two of 's', 'eta', 'xi', 'depth', 'lat', or 'lon'. Specifying more than two is not allowed."
64
+ )
65
+
66
+ # 2D fields: Check for conflicts in dimension choices
67
+ if len(field.dims) == 2:
68
+ if s is not None:
69
+ raise ValueError("Vertical dimension 's' should be None for 2D fields.")
70
+ if depth is not None:
71
+ raise ValueError("Vertical dimension 'depth' should be None for 2D fields.")
72
+ if all([eta is not None, xi is not None]):
73
+ raise ValueError(
74
+ "Conflicting input: For 2D fields, specify only one dimension, either 'eta' or 'xi', not both."
75
+ )
76
+ if all([lat is not None, lon is not None]):
77
+ raise ValueError(
78
+ "Conflicting input: For 2D fields, specify only one dimension, either 'lat' or 'lon', not both."
79
+ )
80
+
81
+ # Check that indices are within bounds
82
+ if eta is not None:
83
+ dim = "eta_rho" if "eta_rho" in field.dims else "eta_v"
84
+ if not eta < len(field[dim]):
85
+ raise ValueError(
86
+ f"Invalid eta index: {eta} is out of bounds. Must be between 0 and {len(field[dim]) - 1}."
87
+ )
88
+ if not include_boundary:
89
+ if eta == 0 or eta == len(field[dim]) - 1:
90
+ raise ValueError(
91
+ f"Invalid eta index: {eta} lies on the boundary, which is excluded when `include_boundary = False`. "
92
+ "Either set `include_boundary = True`, or adjust eta to avoid boundary values."
93
+ )
94
+
95
+ if xi is not None:
96
+ dim = "xi_rho" if "xi_rho" in field.dims else "xi_u"
97
+ if not xi < len(field[dim]):
98
+ raise ValueError(
99
+ f"Invalid eta index: {xi} is out of bounds. Must be between 0 and {len(field[dim]) - 1}."
100
+ )
101
+ if not include_boundary:
102
+ if xi == 0 or xi == len(field[dim]) - 1:
103
+ raise ValueError(
104
+ f"Invalid xi index: {xi} lies on the boundary, which is excluded when `include_boundary = False`. "
105
+ "Either set `include_boundary = True`, or adjust eta to avoid boundary values."
106
+ )
107
+
108
+
109
+ def _generate_coordinate_range(min, max, resolution):
110
+ """Generate an array of target latitude or longitude coordinates within a specified
111
+ range.
112
+
113
+ This method generates an array of target coordinates between the provided `min` and `max`
114
+ values, with a specified resolution (spacing) between each coordinate. Both `min` and `max`
115
+ are included in the generated range.
116
+
117
+ Parameters
118
+ ----------
119
+ min : float
120
+ The minimum value (in degrees) of the coordinate range (inclusive).
121
+
122
+ max : float
123
+ The maximum value (in degrees) of the coordinate range (inclusive).
124
+
125
+ resolution : float
126
+ The spacing (in degrees) between each coordinate in the array.
127
+
128
+ Returns
129
+ -------
130
+ numpy.ndarray
131
+ An array of target coordinates generated from the specified range and resolution.
132
+ """
133
+
134
+ # Generate the array including both min and max values
135
+ target = np.arange(min, max + resolution, resolution)
136
+
137
+ return target