25
25
GMTInvalidInput ,
26
26
GMTVersionError ,
27
27
)
28
- from pygmt .helpers import data_kind , dummy_context
28
+ from pygmt .helpers import data_kind , dummy_context , fmt_docstring
29
29
30
30
FAMILIES = [
31
31
"GMT_IS_DATASET" ,
@@ -1360,6 +1360,7 @@ def virtualfile_from_grid(self, grid):
1360
1360
with self .open_virtual_file (* args ) as vfile :
1361
1361
yield vfile
1362
1362
1363
+ @fmt_docstring
1363
1364
def virtualfile_from_data (
1364
1365
self , check_kind = None , data = None , x = None , y = None , z = None , extra_arrays = None
1365
1366
):
@@ -1375,7 +1376,7 @@ def virtualfile_from_data(
1375
1376
check_kind : str
1376
1377
Used to validate the type of data that can be passed in. Choose
1377
1378
from 'raster', 'vector' or None. Default is None (no validation).
1378
- data : str, xarray.DataArray, 2d array, or None
1379
+ data : str or xarray.DataArray or {table-like} or None
1379
1380
Any raster or vector data format. This could be a file name, a
1380
1381
raster grid, a vector matrix/arrays, or other supported data input.
1381
1382
x/y/z : 1d arrays or None
@@ -1395,20 +1396,20 @@ def virtualfile_from_data(
1395
1396
>>> from pygmt.helpers import GMTTempFile
1396
1397
>>> import xarray as xr
1397
1398
>>> data = xr.Dataset(
1398
- ... coords={" index": [0, 1, 2]} ,
1399
- ... data_vars={
1400
- ... "x": ("index", [9, 8, 7]),
1401
- ... "y": ("index", [6, 5, 4]),
1402
- ... "z": ("index", [3, 2, 1]),
1403
- ... } ,
1399
+ ... coords=dict( index= [0, 1, 2]) ,
1400
+ ... data_vars=dict(
1401
+ ... x= ("index", [9, 8, 7]),
1402
+ ... y= ("index", [6, 5, 4]),
1403
+ ... z= ("index", [3, 2, 1]),
1404
+ ... ) ,
1404
1405
... )
1405
1406
>>> with Session() as ses:
1406
1407
... with ses.virtualfile_from_data(
1407
1408
... check_kind="vector", data=data
1408
1409
... ) as fin:
1409
1410
... # Send the output to a file so that we can read it
1410
1411
... with GMTTempFile() as fout:
1411
- ... ses.call_module("info", f"{ fin} ->{ fout.name}" )
1412
+ ... ses.call_module("info", fin + " ->" + fout.name)
1412
1413
... print(fout.read().strip())
1413
1414
...
1414
1415
<vector memory>: N = 3 <7/9> <4/6> <1/3>
0 commit comments