Skip to content

Commit 908f244

Browse files
committed
update docstring
1 parent 7d5b52c commit 908f244

2 files changed

Lines changed: 55 additions & 17 deletions

File tree

uxarray/cross_sections/dataarray_accessor.py

Lines changed: 50 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616

1717

1818
class UxDataArrayCrossSectionAccessor:
19-
"""TODO"""
20-
2119
def __init__(self, uxda) -> None:
2220
self.uxda = uxda
2321

@@ -29,16 +27,58 @@ def __call__(
2927
lat: float | None = None,
3028
lon: float | None = None,
3129
steps: int = 100,
32-
interp_type="nearest",
3330
) -> xr.DataArray:
3431
"""
35-
TODO:
36-
"""
32+
Extracts a cross-section sampled along an arbitrary great-circle arc (GCA) or line of constant latitude/longitude.
3733
38-
if interp_type != "nearest":
39-
raise ValueError(
40-
f"Only 'nearest' interpolation is supported, not '{interp_type}'"
41-
)
34+
Exactly one mode must be specified:
35+
36+
- **Great‐circle**: supply both `start` and `end` (lon, lat) tuples,
37+
samples a geodesic arc.
38+
- **Constant latitude**: supply `lat` alone (float),
39+
returns points along that latitude.
40+
- **Constant longitude**: supply `lon` alone (float),
41+
returns points along that longitude.
42+
43+
Parameters
44+
----------
45+
start : tuple[float, float], optional
46+
(lon, lat) of the geodesic start point.
47+
end : tuple[float, float], optional
48+
(lon, lat) of the geodesic end point.
49+
lat : float, optional
50+
Latitude for a constant‐latitude slice.
51+
lon : float, optional
52+
Longitude for a constant‐longitude slice.
53+
steps : int, default 100
54+
Number of sample points (including endpoints).
55+
56+
Returns
57+
-------
58+
xr.DataArray
59+
A DataArray with a new `"steps"` dimension, plus `"lat"` and `"lon"`
60+
coordinate variables giving the sampling positions.
61+
62+
63+
Examples
64+
--------
65+
66+
Cross-section between two points (lon ,lat)
67+
68+
>>> uxda.cross_section(start=(-45, -45), end=(45, 45))
69+
70+
Constant latitude cross-section
71+
72+
>>> uxda.cross_section(lat=45)
73+
74+
Constant longitude cross-section
75+
76+
>>> uxda.cross_section(lon=0)
77+
78+
Constant longitude cross-section with custom number of steps
79+
80+
>>> uxda.cross_section(lon=0, steps=200)
81+
"""
4282

4383
great_circle = start is not None or end is not None
4484
const_lon = lon is not None
@@ -68,15 +108,13 @@ def __call__(
68108
)
69109
face_idx = np.array([row[0] if row else -1 for row in faces], dtype=INT_DTYPE)
70110

71-
# Prepare new dimension names & axes
72111
orig_dims = list(self.uxda.dims)
73112
face_axis = orig_dims.index("n_face")
74113
new_dim = "steps"
75114
new_dims = [new_dim if d == "n_face" else d for d in orig_dims]
76115
dim_axis = new_dims.index(new_dim)
77116

78-
# TODO:
79-
arr = np.moveaxis(self.uxda.compute().data, face_axis, -1)
117+
arr = np.moveaxis(self.uxda.compute().values, face_axis, -1)
80118
M, Nf = arr.reshape(-1, arr.shape[-1]).shape
81119
flat_orig = arr.reshape(M, Nf)
82120

uxarray/cross_sections/sample.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44

55

66
@njit(parallel=True)
7-
def _fill_numba(flat_orig, face_idx, n_face, n_samples):
7+
def _fill_numba(flat_orig, face_idx, n_face, n_steps):
88
M = flat_orig.shape[0]
9-
out = np.full((M, n_samples), np.nan, flat_orig.dtype)
10-
for i in prange(n_samples):
9+
out = np.full((M, n_steps), np.nan, flat_orig.dtype)
10+
for i in prange(n_steps):
1111
f = face_idx[i]
1212
if 0 <= f < n_face:
1313
out[:, i] = flat_orig[:, f]
@@ -77,7 +77,7 @@ def sample_constant_latitude(lat: float, steps: int) -> tuple[np.ndarray, np.nda
7777
rad_lon = np.deg2rad(lons)
7878
rad_lat = np.deg2rad(lats)
7979

80-
# spherical Cartesian
80+
# spherical to Cartesian
8181
x = np.cos(rad_lat) * np.cos(rad_lon)
8282
y = np.cos(rad_lat) * np.sin(rad_lon)
8383
z = np.sin(rad_lat)
@@ -104,7 +104,7 @@ def sample_constant_longitude(lon: float, steps: int) -> tuple[np.ndarray, np.nd
104104
rad_lon = np.deg2rad(lons)
105105
rad_lat = np.deg2rad(lats)
106106

107-
# spherical Cartesian
107+
# spherical to Cartesian
108108
x = np.cos(rad_lat) * np.cos(rad_lon)
109109
y = np.cos(rad_lat) * np.sin(rad_lon)
110110
z = np.sin(rad_lat)

0 commit comments

Comments
 (0)