Skip to content

Commit 7b40d17

Browse files
authored
Merge pull request #115 from knutfrode/dev
Switched to numpydoc docstrings for Sphinx. E.g. Args: -> Parameters,…
2 parents 1d84c7c + 762cad3 commit 7b40d17

File tree

2 files changed

+114
-43
lines changed

2 files changed

+114
-43
lines changed

docs/source/conf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
'sphinx.ext.viewcode',
5151
'sphinx.ext.mathjax',
5252
'sphinx_gallery.gen_gallery',
53-
# 'numpydoc',
53+
'numpydoc',
5454
'matplotlib.sphinxext.plot_directive',
5555
]
5656

@@ -90,7 +90,7 @@
9090

9191
# numpydoc_show_class_members = False
9292
# Report warnings for all validation checks except the ones listed after "all"
93-
# numpydoc_validation_checks = {"all", "ES01", "EX01", "SA01", "SA04"}
93+
numpydoc_validation_checks = {"all", "ES01", "EX01", "SA01", "SA04"}
9494
# don't report on objects that match any of these regex
9595
numpydoc_validation_exclude = {
9696
r"\.__repr__$",

trajan/traj.py

Lines changed: 112 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -99,24 +99,23 @@ def animate(self):
9999
@property
100100
def tx(self):
101101
"""
102-
Trajectory x coordinates (usually longitude).
102+
Trajectory x coordinates (usually longitude) - test.
103103
104-
.. seealso::
105-
106-
* :py:attr:`~xarray.Dataset.traj.tlon`
107-
* :py:attr:`~xarray.Dataset.traj.ty`
104+
See Also
105+
--------
106+
tlon, ty
108107
"""
108+
109109
return detect_tx_dim(self.ds)
110110

111111
@property
112112
def ty(self):
113113
"""
114114
Trajectory y coordinates (usually latitude).
115115
116-
.. seealso::
117-
118-
* :py:attr:`~xarray.Dataset.traj.tlat`
119-
* :py:attr:`~xarray.Dataset.traj.tx`
116+
See Also
117+
--------
118+
tlat, tx
120119
"""
121120
if 'lat' in self.ds:
122121
return self.ds.lat
@@ -146,7 +145,7 @@ def tlon(self):
146145
return X
147146

148147
@property
149-
def tlat(self):
148+
def tlat(self) -> xr.DataArray:
150149
"""
151150
Retrieve the trajectories in geographic coordinates (latitudes).
152151
"""
@@ -165,12 +164,17 @@ def transform(self, to_crs, x, y):
165164
"""
166165
Transform coordinates in this datasets coordinate system to `to_crs` coordinate system.
167166
168-
Args:
169-
to_crs: `pyproj.CRS`.
170-
x, y: Coordinates in `self` CRS.
167+
Parameters
168+
----------
169+
to_crs : pyproj.CRS
171170
172-
Returns:
173-
xn, yn: Coordinates in `to_crs`.
171+
x, y : arrays
172+
Coordinates in `self` CRS
173+
174+
Returns
175+
-------
176+
xn, yn : arrays
177+
Coordinates in `to_crs`
174178
"""
175179
t = pyproj.Transformer.from_crs(self.crs, to_crs, always_xy=True)
176180
return t.transform(x, y)
@@ -179,20 +183,25 @@ def itransform(self, from_crs, x, y):
179183
"""
180184
Transform coordinates in `from_crs` coordinate system to this datasets coordinate system.
181185
182-
Args:
183-
from_crs: `pyproj.CRS`.
184-
x, y: Coordinates in `from_crs` CRS.
186+
Parameters
187+
----------
188+
from_crs : `pyproj.CRS`
189+
190+
x, y : arrays
191+
Coordinates in `from_crs` CRS
185192
186-
Returns:
187-
xn, yn: Coordinates in this datasets CRS.
193+
Returns
194+
-------
195+
xn, yn : arrays
196+
Coordinates in this datasets CRS
188197
"""
189198
t = pyproj.Transformer.from_crs(from_crs, self.crs, always_xy=True)
190199
return t.transform(x, y)
191200

192201
@property
193202
def crs(self) -> pyproj.CRS:
194203
"""
195-
Retrieve the Proj.4 CRS from the CF-defined grid-mapping in the dataset.
204+
Retrieve the pyproj.CRS object from the CF-defined grid-mapping in the dataset.
196205
"""
197206
if len(self.ds.cf.grid_mapping_names) == 0:
198207
logger.debug(
@@ -212,10 +221,18 @@ def crs(self) -> pyproj.CRS:
212221
logger.debug(f'Constructing CRS from grid_mapping: {gm}')
213222
return pyproj.CRS.from_cf(gm.attrs)
214223

215-
def set_crs(self, crs):
224+
def set_crs(self, crs) -> xr.Dataset:
216225
"""
217226
Returns a new dataset with the CF-supported grid-mapping / projection set to `crs`.
218227
228+
Parameters
229+
----------
230+
crs: pyproj.CRS
231+
232+
Returns
233+
-------
234+
updated dataset
235+
219236
.. warning::
220237
221238
This does not transform the coordinates, make sure that `crs` is matching the data in the dataset.
@@ -331,16 +348,40 @@ def index_of_last(self):
331348
axis=1)[1][1]
332349

333350
@abstractmethod
334-
def speed(self):
335-
"""Returns the speed [m/s] along trajectories"""
351+
def speed(self) -> xr.DataArray:
352+
"""Returns the speed [m/s] along trajectories
353+
354+
Calculates the speed by dividing the distance between two points
355+
along trajectory by the corresponding time step.
356+
357+
Returns
358+
-------
359+
xarray.DataArray
360+
Same dimensions as original dataset, since last value is repeated along time dimension
361+
362+
See Also
363+
--------
364+
distance_to_next, time_to_next
365+
366+
"""
336367
distance = self.distance_to_next()
337368
timedelta_seconds = self.time_to_next() / np.timedelta64(1, 's')
338369

339370
return distance / timedelta_seconds
340371

341372
@abstractmethod
342373
def time_to_next(self) -> pd.Timedelta:
343-
"""Returns the timedelta between time steps"""
374+
"""Returns the timedelta between time steps
375+
376+
Returns
377+
-------
378+
xarray.DataArray
379+
Scalar timedelta for 1D objects, and DataArray of same size as input for 2D objects
380+
381+
See Also
382+
--------
383+
distance_to_next, speed
384+
"""
344385
pass
345386

346387
@abstractmethod
@@ -350,9 +391,24 @@ def velocity_spectrum(self) -> xr.DataArray:
350391
# def rotary_spectrum(self):
351392
# pass
352393

353-
def distance_to(self, other):
394+
def distance_to(self, other) -> xr.Dataset:
354395
"""
355396
Distance between trajectories or a single point.
397+
398+
Parameters
399+
----------
400+
other : xarray.DataSet
401+
Other dataset to which distance is calculated
402+
403+
Returns
404+
-------
405+
xarray.Dataset
406+
Same dimensions as original dataset
407+
408+
See Also
409+
--------
410+
distance_to_next
411+
356412
"""
357413

358414
other = other.broadcast_like(self.ds)
@@ -382,7 +438,17 @@ def distance_to(self, other):
382438
def distance_to_next(self):
383439
"""Returns distance in m from one position to the next
384440
385-
Last time is repeated for last position (which has no next position)
441+
Last time is repeated for last position (which has no next position)
442+
443+
Returns
444+
-------
445+
xarray.DataArray
446+
Same dimensions as original dataset, since last value is repeated along time dimension
447+
448+
See Also
449+
--------
450+
time_to_next, speed
451+
386452
"""
387453

388454
lon = self.ds.lon
@@ -501,16 +567,19 @@ def get_area_convex_hull(self):
501567
def gridtime(self, times, timedim = None) -> xr.Dataset:
502568
"""Interpolate dataset to a regular time interval or a different grid.
503569
504-
Args:
505-
`times`: array or str
506-
Target time interval, can be either:
507-
- an array of times, or
508-
- a string "freq" specifying a Pandas daterange (e.g. 'h', '6h, 'D'...) suitable for `pd.date_range`.
570+
Parameters
571+
----------
572+
times : array or str
573+
Target time interval, can be either:
574+
- an array of times, or
575+
- a string specifying a Pandas daterange (e.g. 'h', '6h, 'D'...) suitable for `pd.date_range`.
509576
510-
`timedime`: str
511-
Name of new time dimension. The default is to use the same name as previously.
577+
timedim : str
578+
Name of new time dimension. The default is to use the same name as previously.
512579
513-
Returns:
580+
Returns
581+
-------
582+
Dataset
514583
A new dataset interpolated to the target times. The dataset will be 1D (i.e. gridded) and the time dimension will be named `time`.
515584
"""
516585

@@ -525,17 +594,19 @@ def skill(self, other, method='liu-weissberg', **kwargs) -> xr.DataArray:
525594
"""
526595
Compare the skill score between this trajectory and `other`.
527596
528-
Args:
597+
Parameters
598+
----------
529599
530-
other: Another trajectory dataset.
600+
other: Another trajectory dataset.
531601
532-
method: skill-score method, currently only liu-weissberg. See :mod:`trajan.skill`.
602+
method: skill-score method, currently only liu-weissberg. See :mod:`trajan.skill`.
533603
534-
**kwargs: passed on to the skill-score method.
604+
**kwargs: passed on to the skill-score method.
535605
536-
Returns:
606+
Returns
607+
-------
537608
538-
skill: The skill-score in the same dimensions as this dataset.
609+
skill: The skill-score in the same dimensions as this dataset.
539610
540611
.. note::
541612

0 commit comments

Comments
 (0)