@@ -1554,6 +1554,7 @@ def virtualfile_in( # noqa: PLR0912
1554
1554
extra_arrays = None ,
1555
1555
required_z = False ,
1556
1556
required_data = True ,
1557
+ _grid_mode = "GMT_IN" , # An internal parameter to workaround GMT API bugs.
1557
1558
):
1558
1559
"""
1559
1560
Store any data inside a virtual file.
@@ -1638,7 +1639,7 @@ def virtualfile_in( # noqa: PLR0912
1638
1639
}[kind ]
1639
1640
1640
1641
# Ensure the data is an iterable (Python list or tuple)
1641
- if kind in {"geojson" , "grid" , " image" , "file" , "arg" }:
1642
+ if kind in {"geojson" , "image" , "file" , "arg" }:
1642
1643
if kind == "image" and data .dtype != "uint8" :
1643
1644
msg = (
1644
1645
f"Input image has dtype: { data .dtype } which is unsupported, "
@@ -1649,6 +1650,8 @@ def virtualfile_in( # noqa: PLR0912
1649
1650
)
1650
1651
warnings .warn (message = msg , category = RuntimeWarning , stacklevel = 2 )
1651
1652
_data = (data ,) if not isinstance (data , pathlib .PurePath ) else (str (data ),)
1653
+ elif kind == "grid" :
1654
+ _data = (data , _grid_mode )
1652
1655
elif kind == "vectors" :
1653
1656
_data = [np .atleast_1d (x ), np .atleast_1d (y )]
1654
1657
if z is not None :
@@ -1873,7 +1876,7 @@ def read_virtualfile(
1873
1876
return ctp .cast (pointer , ctp .POINTER (dtype ))
1874
1877
1875
1878
@contextlib .contextmanager
1876
- def virtualfile_from_xrgrid (self , xrgrid ):
1879
+ def virtualfile_from_xrgrid (self , xrgrid , _grid_mode = "GMT_IN" ):
1877
1880
"""
1878
1881
Create a virtual file from an xarray.DataArray object.
1879
1882
"""
@@ -1906,7 +1909,7 @@ def virtualfile_from_xrgrid(self, xrgrid):
1906
1909
matrix = np .pad (matrix , self ["GMT_PAD_DEFAULT" ]).astype (np .float32 )
1907
1910
gmtgrid .contents .data = matrix .ctypes .data_as (ctp .POINTER (gmt_grdfloat ))
1908
1911
1909
- with self .open_virtualfile (family , geometry , "GMT_IN" , gmtgrid ) as vfile :
1912
+ with self .open_virtualfile (family , geometry , _grid_mode , gmtgrid ) as vfile :
1910
1913
yield vfile
1911
1914
1912
1915
def virtualfile_to_dataset (
0 commit comments