@@ -1360,7 +1360,9 @@ def virtualfile_from_grid(self, grid):
1360
1360
with self .open_virtual_file (* args ) as vfile :
1361
1361
yield vfile
1362
1362
1363
- def virtualfile_from_data (self , check_kind = None , data = None , x = None , y = None , z = None ):
1363
+ def virtualfile_from_data (
1364
+ self , check_kind = None , data = None , x = None , y = None , z = None , extra_arrays = None
1365
+ ):
1364
1366
"""
1365
1367
Store any data inside a virtual file.
1366
1368
@@ -1378,6 +1380,9 @@ def virtualfile_from_data(self, check_kind=None, data=None, x=None, y=None, z=No
1378
1380
raster grid, a vector matrix/arrays, or other supported data input.
1379
1381
x/y/z : 1d arrays or None
1380
1382
x, y and z columns as numpy arrays.
1383
+ extra_arrays : list of 1d arrays
1384
+ Optional. A list of numpy arrays in addition to x, y and z. All
1385
+ of these arrays must be of the same size as the x/y/z arrays.
1381
1386
1382
1387
Returns
1383
1388
-------
@@ -1430,14 +1435,26 @@ def virtualfile_from_data(self, check_kind=None, data=None, x=None, y=None, z=No
1430
1435
if kind in ("file" , "grid" ):
1431
1436
_data = (data ,)
1432
1437
elif kind == "vectors" :
1433
- _data = (x , y , z )
1438
+ _data = [np .atleast_1d (x ), np .atleast_1d (y )]
1439
+ if z is not None :
1440
+ _data .append (np .atleast_1d (z ))
1441
+ if extra_arrays :
1442
+ _data .extend (extra_arrays )
1434
1443
elif kind == "matrix" : # turn 2D arrays into list of vectors
1435
1444
try :
1436
1445
# pandas.DataFrame and xarray.Dataset types
1437
1446
_data = [array for _ , array in data .items ()]
1438
1447
except AttributeError :
1439
- # Python lists, tuples, and numpy ndarray types
1440
- _data = np .atleast_2d (np .asanyarray (data ).T )
1448
+ try :
1449
+ # Just use virtualfile_from_matrix for 2D numpy.ndarray
1450
+ # which are signed integer (i), unsigned integer (u) or
1451
+ # floating point (f) types
1452
+ assert data .ndim == 2 and data .dtype .kind in "iuf"
1453
+ _virtualfile_from = self .virtualfile_from_matrix
1454
+ _data = (data ,)
1455
+ except (AssertionError , AttributeError ):
1456
+ # Python lists, tuples, and numpy ndarray types
1457
+ _data = np .atleast_2d (np .asanyarray (data ).T )
1441
1458
1442
1459
# Finally create the virtualfile from the data, to be passed into GMT
1443
1460
file_context = _virtualfile_from (* _data )
0 commit comments