1616
1717
1818class 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
0 commit comments