Skip to content

Commit f82e501

Browse files
committed
Updated several docstrings to Xarray style
1 parent 1d4b7d1 commit f82e501

File tree

2 files changed

+53
-20
lines changed

2 files changed

+53
-20
lines changed

docs/source/conf.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
autoapi_dirs = [ '../../trajan' ]
2222
autoapi_keep_files = False # set to True when debugging autoapi generated files
2323
autoapi_python_class_content = 'both'
24-
autodoc_typehints = 'description'
24+
autodoc_typehints = 'none'
2525

2626
import warnings
2727
warnings.filterwarnings("ignore", category=UserWarning,
@@ -64,6 +64,7 @@
6464
'scipy': ('https://docs.scipy.org/doc/scipy', None),
6565
'cftime': ('https://unidata.github.io/cftime', None),
6666
'sphinx': ('https://www.sphinx-doc.org/en/master/', None),
67+
'pyproj': ('https://pyproj4.github.io/pyproj/stable/', None),
6768
'xarray': ('https://xarray.pydata.org/en/stable/', None),
6869
'pandas': ("https://pandas.pydata.org/pandas-docs/stable", None),
6970
}
@@ -95,7 +96,7 @@
9596
napoleon_google_docstring = False
9697
napoleon_numpy_docstring = True
9798
napoleon_use_param = False
98-
napoleon_use_ivar = True
99+
napoleon_use_ivar = False
99100
napoleon_use_rtype = False
100101
napoleon_preprocess_types = True
101102
napoleon_type_aliases = {

trajan/traj.py

Lines changed: 50 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ def animate(self):
8888
@property
8989
def tx(self):
9090
"""
91-
Trajectory x coordinates (usually longitude) - test.
91+
Trajectory x coordinates (usually longitude).
9292
9393
See Also
9494
--------
@@ -121,6 +121,10 @@ def ty(self):
121121
def tlon(self):
122122
"""
123123
Retrieve the trajectories in geographic coordinates (longitudes).
124+
125+
See Also
126+
--------
127+
tx, tlat
124128
"""
125129
if self.crs.is_geographic:
126130
return self.tx
@@ -137,6 +141,10 @@ def tlon(self):
137141
def tlat(self) -> xr.DataArray:
138142
"""
139143
Retrieve the trajectories in geographic coordinates (latitudes).
144+
145+
See Also
146+
--------
147+
ty, tlon
140148
"""
141149
if self.crs.is_geographic:
142150
return self.ty
@@ -155,14 +163,14 @@ def transform(self, to_crs, x, y):
155163
156164
Parameters
157165
----------
158-
to_crs : pyproj.CRS
166+
to_crs : pyproj.crs.CRS
159167
160-
x, y : arrays
168+
x, y : array-like
161169
Coordinates in `self` CRS
162170
163171
Returns
164172
-------
165-
xn, yn : arrays
173+
xn, yn : array-like
166174
Coordinates in `to_crs`
167175
"""
168176
t = pyproj.Transformer.from_crs(self.crs, to_crs, always_xy=True)
@@ -174,23 +182,27 @@ def itransform(self, from_crs, x, y):
174182
175183
Parameters
176184
----------
177-
from_crs : `pyproj.CRS`
185+
from_crs : pyproj.crs.CRS
178186
179-
x, y : arrays
180-
Coordinates in `from_crs` CRS
187+
x, y : array-like
188+
Coordinates in from_crs CRS
181189
182190
Returns
183191
-------
184-
xn, yn : arrays
192+
xn, yn : array-like
185193
Coordinates in this datasets CRS
186194
"""
187195
t = pyproj.Transformer.from_crs(from_crs, self.crs, always_xy=True)
188196
return t.transform(x, y)
189197

190198
@property
191-
def crs(self) -> pyproj.CRS:
199+
def crs(self) -> pyproj.crs.CRS:
192200
"""
193-
Retrieve the pyproj.CRS object from the CF-defined grid-mapping in the dataset.
201+
Retrieve the pyproj.crs.CRS object from the CF-defined grid-mapping in the dataset.
202+
203+
Returns
204+
-------
205+
pyproj.crs.CRS
194206
"""
195207
if len(self.ds.cf.grid_mapping_names) == 0:
196208
logger.debug(
@@ -208,23 +220,24 @@ def crs(self) -> pyproj.CRS:
208220
else:
209221
gm = self.ds.cf['grid_mapping']
210222
logger.debug(f'Constructing CRS from grid_mapping: {gm}')
211-
return pyproj.CRS.from_cf(gm.attrs)
223+
return pyproj.crs.CRS.from_cf(gm.attrs)
212224

213225
def set_crs(self, crs) -> xr.Dataset:
214226
"""
215227
Returns a new dataset with the CF-supported grid-mapping / projection set to `crs`.
216228
217229
Parameters
218230
----------
219-
crs: pyproj.CRS
231+
crs : pyproj.crs.CRS
220232
221233
Returns
222234
-------
223-
updated dataset
224-
225-
.. warning::
235+
Dataset
236+
Updated dataset
226237
227-
This does not transform the coordinates, make sure that `crs` is matching the data in the dataset.
238+
Warning
239+
-------
240+
This does not transform the coordinates, make sure that `crs` is matching the data in the dataset.
228241
"""
229242

230243
# TODO: Ideally this would be handled by cf-xarray or rio-xarray.
@@ -282,6 +295,19 @@ def assign_cf_attrs(self,
282295
**kwargs) -> xr.Dataset:
283296
"""
284297
Return a new dataset with CF-standard and common attributes set.
298+
299+
Parameters
300+
----------
301+
*kwargs
302+
Attribute names and values
303+
304+
Returns
305+
-------
306+
Dataset
307+
Updated dataset with provided attributes, in addition to several CF standard attributes,
308+
including Conventions, featureType, geospatial_lat_min etc.
309+
310+
285311
"""
286312
ds = self.ds.copy(deep=True)
287313

@@ -332,7 +358,13 @@ def assign_cf_attrs(self,
332358
return ds
333359

334360
def index_of_last(self):
335-
"""Find index of last valid position along each trajectory."""
361+
"""Find index of last valid position along each trajectory.
362+
363+
Returns
364+
-------
365+
array-like
366+
Array of the index of the last valid position along each trajectory.
367+
"""
336368
return np.ma.notmasked_edges(np.ma.masked_invalid(self.ds.lon.values),
337369
axis=1)[1][1]
338370

@@ -612,7 +644,7 @@ def skill(self, other, method='liu-weissberg', **kwargs) -> xr.Dataset:
612644
Returns
613645
-------
614646
615-
skill : :class:`xarray.Dataset`
647+
skill : Dataset
616648
The skill-score in the same dimensions as this dataset.
617649
618650
Notes

0 commit comments

Comments
 (0)