25
25
vectors_to_arrays ,
26
26
)
27
27
from pygmt .clib .loading import load_libgmt
28
- from pygmt .datatypes import _GMT_DATASET , _GMT_GRID
28
+ from pygmt .datatypes import _GMT_DATASET , _GMT_GRID , _GMT_IMAGE
29
29
from pygmt .exceptions import (
30
30
GMTCLibError ,
31
31
GMTCLibNoSessionError ,
@@ -1070,7 +1070,7 @@ def put_matrix(self, dataset, matrix, pad=0):
1070
1070
def read_data (
1071
1071
self ,
1072
1072
infile : str ,
1073
- kind : Literal ["dataset" , "grid" ],
1073
+ kind : Literal ["dataset" , "grid" , "image" ],
1074
1074
family : str | None = None ,
1075
1075
geometry : str | None = None ,
1076
1076
mode : str = "GMT_READ_NORMAL" ,
@@ -1088,8 +1088,8 @@ def read_data(
1088
1088
infile
1089
1089
The input file name.
1090
1090
kind
1091
- The data kind of the input file. Valid values are ``"dataset"`` and
1092
- ``"grid "``.
1091
+ The data kind of the input file. Valid values are ``"dataset"``, ``"grid"``
1092
+ and ``"image "``.
1093
1093
family
1094
1094
A valid GMT data family name (e.g., ``"GMT_IS_DATASET"``). See the
1095
1095
``FAMILIES`` attribute for valid names. If ``None``, will determine the data
@@ -1140,6 +1140,7 @@ def read_data(
1140
1140
_family , _geometry , dtype = {
1141
1141
"dataset" : ("GMT_IS_DATASET" , "GMT_IS_PLP" , _GMT_DATASET ),
1142
1142
"grid" : ("GMT_IS_GRID" , "GMT_IS_SURFACE" , _GMT_GRID ),
1143
+ "image" : ("GMT_IS_IMAGE" , "GMT_IS_SURFACE" , _GMT_IMAGE ),
1143
1144
}[kind ]
1144
1145
if family is None :
1145
1146
family = _family
@@ -1797,7 +1798,9 @@ def virtualfile_from_data(
1797
1798
1798
1799
@contextlib .contextmanager
1799
1800
def virtualfile_out (
1800
- self , kind : Literal ["dataset" , "grid" ] = "dataset" , fname : str | None = None
1801
+ self ,
1802
+ kind : Literal ["dataset" , "grid" , "image" ] = "dataset" ,
1803
+ fname : str | None = None ,
1801
1804
) -> Generator [str , None , None ]:
1802
1805
r"""
1803
1806
Create a virtual file or an actual file for storing output data.
@@ -1810,8 +1813,8 @@ def virtualfile_out(
1810
1813
Parameters
1811
1814
----------
1812
1815
kind
1813
- The data kind of the virtual file to create. Valid values are ``"dataset"``
1814
- and ``"grid "``. Ignored if ``fname`` is specified.
1816
+ The data kind of the virtual file to create. Valid values are ``"dataset"``,
1817
+ ``"grid"``, and ``"image "``. Ignored if ``fname`` is specified.
1815
1818
fname
1816
1819
The name of the actual file to write the output data. No virtual file will
1817
1820
be created.
@@ -1854,8 +1857,10 @@ def virtualfile_out(
1854
1857
family , geometry = {
1855
1858
"dataset" : ("GMT_IS_DATASET" , "GMT_IS_PLP" ),
1856
1859
"grid" : ("GMT_IS_GRID" , "GMT_IS_SURFACE" ),
1860
+ "image" : ("GMT_IS_IMAGE" , "GMT_IS_SURFACE" ),
1857
1861
}[kind ]
1858
- with self .open_virtualfile (family , geometry , "GMT_OUT" , None ) as vfile :
1862
+ direction = "GMT_OUT|GMT_IS_REFERENCE" if kind == "image" else "GMT_OUT"
1863
+ with self .open_virtualfile (family , geometry , direction , None ) as vfile :
1859
1864
yield vfile
1860
1865
1861
1866
def inquire_virtualfile (self , vfname : str ) -> int :
@@ -1901,7 +1906,8 @@ def read_virtualfile(
1901
1906
Name of the virtual file to read.
1902
1907
kind
1903
1908
Cast the data into a GMT data container. Valid values are ``"dataset"``,
1904
- ``"grid"`` and ``None``. If ``None``, will return a ctypes void pointer.
1909
+ ``"grid"``, ``"image"`` and ``None``. If ``None``, will return a ctypes void
1910
+ pointer.
1905
1911
1906
1912
Returns
1907
1913
-------
@@ -1951,9 +1957,9 @@ def read_virtualfile(
1951
1957
# _GMT_DATASET).
1952
1958
if kind is None : # Return the ctypes void pointer
1953
1959
return pointer
1954
- if kind in { "image" , " cube"} :
1960
+ if kind == " cube" :
1955
1961
raise NotImplementedError (f"kind={ kind } is not supported yet." )
1956
- dtype = {"dataset" : _GMT_DATASET , "grid" : _GMT_GRID }[kind ]
1962
+ dtype = {"dataset" : _GMT_DATASET , "grid" : _GMT_GRID , "image" : _GMT_IMAGE }[kind ]
1957
1963
return ctp .cast (pointer , ctp .POINTER (dtype ))
1958
1964
1959
1965
def virtualfile_to_dataset (
0 commit comments