@@ -99,24 +99,23 @@ def animate(self):
99
99
@property
100
100
def tx (self ):
101
101
"""
102
- Trajectory x coordinates (usually longitude).
102
+ Trajectory x coordinates (usually longitude) - test .
103
103
104
- .. seealso::
105
-
106
- * :py:attr:`~xarray.Dataset.traj.tlon`
107
- * :py:attr:`~xarray.Dataset.traj.ty`
104
+ See Also
105
+ --------
106
+ tlon, ty
108
107
"""
108
+
109
109
return detect_tx_dim (self .ds )
110
110
111
111
@property
112
112
def ty (self ):
113
113
"""
114
114
Trajectory y coordinates (usually latitude).
115
115
116
- .. seealso::
117
-
118
- * :py:attr:`~xarray.Dataset.traj.tlat`
119
- * :py:attr:`~xarray.Dataset.traj.tx`
116
+ See Also
117
+ --------
118
+ tlat, tx
120
119
"""
121
120
if 'lat' in self .ds :
122
121
return self .ds .lat
@@ -146,7 +145,7 @@ def tlon(self):
146
145
return X
147
146
148
147
@property
149
- def tlat (self ):
148
+ def tlat (self ) -> xr . DataArray :
150
149
"""
151
150
Retrieve the trajectories in geographic coordinates (latitudes).
152
151
"""
@@ -165,12 +164,17 @@ def transform(self, to_crs, x, y):
165
164
"""
166
165
Transform coordinates in this datasets coordinate system to `to_crs` coordinate system.
167
166
168
- Args:
169
- to_crs: `pyproj.CRS`.
170
- x, y: Coordinates in `self` CRS.
167
+ Parameters
168
+ ----------
169
+ to_crs : pyproj.CRS
171
170
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`
174
178
"""
175
179
t = pyproj .Transformer .from_crs (self .crs , to_crs , always_xy = True )
176
180
return t .transform (x , y )
@@ -179,20 +183,25 @@ def itransform(self, from_crs, x, y):
179
183
"""
180
184
Transform coordinates in `from_crs` coordinate system to this datasets coordinate system.
181
185
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
185
192
186
- Returns:
187
- xn, yn: Coordinates in this datasets CRS.
193
+ Returns
194
+ -------
195
+ xn, yn : arrays
196
+ Coordinates in this datasets CRS
188
197
"""
189
198
t = pyproj .Transformer .from_crs (from_crs , self .crs , always_xy = True )
190
199
return t .transform (x , y )
191
200
192
201
@property
193
202
def crs (self ) -> pyproj .CRS :
194
203
"""
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.
196
205
"""
197
206
if len (self .ds .cf .grid_mapping_names ) == 0 :
198
207
logger .debug (
@@ -212,10 +221,18 @@ def crs(self) -> pyproj.CRS:
212
221
logger .debug (f'Constructing CRS from grid_mapping: { gm } ' )
213
222
return pyproj .CRS .from_cf (gm .attrs )
214
223
215
- def set_crs (self , crs ):
224
+ def set_crs (self , crs ) -> xr . Dataset :
216
225
"""
217
226
Returns a new dataset with the CF-supported grid-mapping / projection set to `crs`.
218
227
228
+ Parameters
229
+ ----------
230
+ crs: pyproj.CRS
231
+
232
+ Returns
233
+ -------
234
+ updated dataset
235
+
219
236
.. warning::
220
237
221
238
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):
331
348
axis = 1 )[1 ][1 ]
332
349
333
350
@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
+ """
336
367
distance = self .distance_to_next ()
337
368
timedelta_seconds = self .time_to_next () / np .timedelta64 (1 , 's' )
338
369
339
370
return distance / timedelta_seconds
340
371
341
372
@abstractmethod
342
373
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
+ """
344
385
pass
345
386
346
387
@abstractmethod
@@ -350,9 +391,24 @@ def velocity_spectrum(self) -> xr.DataArray:
350
391
# def rotary_spectrum(self):
351
392
# pass
352
393
353
- def distance_to (self , other ):
394
+ def distance_to (self , other ) -> xr . Dataset :
354
395
"""
355
396
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
+
356
412
"""
357
413
358
414
other = other .broadcast_like (self .ds )
@@ -382,7 +438,17 @@ def distance_to(self, other):
382
438
def distance_to_next (self ):
383
439
"""Returns distance in m from one position to the next
384
440
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
+
386
452
"""
387
453
388
454
lon = self .ds .lon
@@ -501,16 +567,19 @@ def get_area_convex_hull(self):
501
567
def gridtime (self , times , timedim = None ) -> xr .Dataset :
502
568
"""Interpolate dataset to a regular time interval or a different grid.
503
569
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`.
509
576
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.
512
579
513
- Returns:
580
+ Returns
581
+ -------
582
+ Dataset
514
583
A new dataset interpolated to the target times. The dataset will be 1D (i.e. gridded) and the time dimension will be named `time`.
515
584
"""
516
585
@@ -525,17 +594,19 @@ def skill(self, other, method='liu-weissberg', **kwargs) -> xr.DataArray:
525
594
"""
526
595
Compare the skill score between this trajectory and `other`.
527
596
528
- Args:
597
+ Parameters
598
+ ----------
529
599
530
- other: Another trajectory dataset.
600
+ other: Another trajectory dataset.
531
601
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`.
533
603
534
- **kwargs: passed on to the skill-score method.
604
+ **kwargs: passed on to the skill-score method.
535
605
536
- Returns:
606
+ Returns
607
+ -------
537
608
538
- skill: The skill-score in the same dimensions as this dataset.
609
+ skill: The skill-score in the same dimensions as this dataset.
539
610
540
611
.. note::
541
612
0 commit comments