1
1
"""
2
2
grdtrack - Sample grids at specified (x,y) locations.
3
3
"""
4
+ import warnings
5
+
4
6
import pandas as pd
7
+ import xarray as xr
5
8
from pygmt .clib import Session
6
9
from pygmt .exceptions import GMTInvalidInput
7
10
from pygmt .helpers import (
11
14
kwargs_to_strings ,
12
15
use_alias ,
13
16
)
17
+ from pygmt .src .which import which
14
18
15
19
__doctest_skip__ = ["grdtrack" ]
16
20
43
47
w = "wrap" ,
44
48
)
45
49
@kwargs_to_strings (R = "sequence" , S = "sequence" , i = "sequence_comma" , o = "sequence_comma" )
46
- def grdtrack (points = None , grid = None , newcolname = None , outfile = None , ** kwargs ):
50
+ def grdtrack (grid , points = None , newcolname = None , outfile = None , ** kwargs ):
47
51
r"""
48
52
Sample grids at specified (x,y) locations.
49
53
@@ -67,14 +71,14 @@ def grdtrack(points=None, grid=None, newcolname=None, outfile=None, **kwargs):
67
71
68
72
Parameters
69
73
----------
70
- points : str or {table-like}
71
- Pass in either a file name to an ASCII data table, a 2D
72
- {table-classes}.
73
-
74
74
grid : xarray.DataArray or str
75
75
Gridded array from which to sample values from, or a filename (netcdf
76
76
format).
77
77
78
+ points : str or {table-like}
79
+ Pass in either a file name to an ASCII data table, a 2D
80
+ {table-classes}.
81
+
78
82
newcolname : str
79
83
Required if ``points`` is a :class:`pandas.DataFrame`. The name for the
80
84
new column in the track :class:`pandas.DataFrame` table where the
@@ -292,6 +296,29 @@ def grdtrack(points=None, grid=None, newcolname=None, outfile=None, **kwargs):
292
296
if points is not None and kwargs .get ("E" ) is not None :
293
297
raise GMTInvalidInput ("Can't set both 'points' and 'profile'." )
294
298
299
+ # Backward compatibility with old parameter order "points, grid".
300
+ # deprecated_version="0.7.0", remove_version="v0.9.0"
301
+ is_a_grid = True
302
+ if not isinstance (grid , (xr .DataArray , xr .Dataset , str )):
303
+ is_a_grid = False
304
+ elif isinstance (grid , str ):
305
+ try :
306
+ xr .open_dataarray (which (grid , download = "a" ))
307
+ is_a_grid = True
308
+ except ValueError :
309
+ is_a_grid = False
310
+ if not is_a_grid :
311
+ msg = (
312
+ "Positional parameters 'points, grid' of pygmt.grdtrack() is changed "
313
+ "to 'grid, points=None' since v0.7.0. It's likely that you're NOT "
314
+ "passing an valid grid as the first positional argument or "
315
+ "passing an invalid grid to the 'grid' parameter. "
316
+ "Please check the order of arguments with the latest documentation. "
317
+ "The warning will be removed in v0.9.0."
318
+ )
319
+ grid , points = points , grid
320
+ warnings .warn (msg , category = FutureWarning , stacklevel = 1 )
321
+
295
322
with GMTTempFile (suffix = ".csv" ) as tmpfile :
296
323
with Session () as lib :
297
324
# Store the xarray.DataArray grid in virtualfile
0 commit comments