44
44
"GMT_IS_SURFACE" ,
45
45
]
46
46
47
- MODES = ["GMT_CONTAINER_ONLY" , "GMT_OUTPUT " ]
47
+ MODES = ["GMT_CONTAINER_ONLY" , "GMT_IS_OUTPUT " ]
48
48
49
49
REGISTRATIONS = ["GMT_GRID_PIXEL_REG" , "GMT_GRID_NODE_REG" ]
50
50
@@ -113,7 +113,7 @@ class Session:
113
113
... )
114
114
... # Read the contents of the temp file before it's deleted.
115
115
... print(fout.read().strip())
116
- -179.5 179.5 -89.5 89.5 -8182 5651.5 1 1 360 180 0 0
116
+ -180 180 -90 90 -8182 5651.5 1 1 360 180 1 1
117
117
"""
118
118
119
119
# The minimum version of GMT required
@@ -511,13 +511,13 @@ def create_data(self, family, geometry, mode, **kwargs):
511
511
----------
512
512
family : str
513
513
A valid GMT data family name (e.g., ``'GMT_IS_DATASET'``). See the
514
- ``data_families `` attribute for valid names.
514
+ ``FAMILIES `` attribute for valid names.
515
515
geometry : str
516
516
A valid GMT data geometry name (e.g., ``'GMT_IS_POINT'``). See the
517
- ``data_geometries `` attribute for valid names.
517
+ ``GEOMETRIES `` attribute for valid names.
518
518
mode : str
519
- A valid GMT data mode (e.g., ``'GMT_OUTPUT '``). See the
520
- ``data_modes `` attribute for valid names.
519
+ A valid GMT data mode (e.g., ``'GMT_IS_OUTPUT '``). See the
520
+ ``MODES `` attribute for valid names.
521
521
dim : list of 4 integers
522
522
The dimensions of the dataset. See the documentation for the GMT C
523
523
API function ``GMT_Create_Data`` (``src/gmt_api.c``) for the full
@@ -530,7 +530,7 @@ def create_data(self, family, geometry, mode, **kwargs):
530
530
inc : list of 2 floats
531
531
The increments between points of the dataset. See the C function
532
532
documentation.
533
- registration : int
533
+ registration : str
534
534
The node registration (what the coordinates mean). Can be
535
535
``'GMT_GRID_PIXEL_REG'`` or ``'GMT_GRID_NODE_REG'``. Defaults to
536
536
``'GMT_GRID_NODE_REG'``.
@@ -563,7 +563,9 @@ def create_data(self, family, geometry, mode, **kwargs):
563
563
564
564
family_int = self ._parse_constant (family , valid = FAMILIES , valid_modifiers = VIAS )
565
565
mode_int = self ._parse_constant (
566
- mode , valid = MODES , valid_modifiers = ["GMT_GRID_IS_GEO" ]
566
+ mode ,
567
+ valid = MODES ,
568
+ valid_modifiers = ["GMT_GRID_IS_CARTESIAN" , "GMT_GRID_IS_GEO" ],
567
569
)
568
570
geometry_int = self ._parse_constant (geometry , valid = GEOMETRIES )
569
571
registration_int = self ._parse_constant (
@@ -856,12 +858,12 @@ def write_data(self, family, geometry, mode, wesn, output, data):
856
858
----------
857
859
family : str
858
860
A valid GMT data family name (e.g., ``'GMT_IS_DATASET'``). See the
859
- ``data_families `` attribute for valid names. Don't use the
861
+ ``FAMILIES `` attribute for valid names. Don't use the
860
862
``GMT_VIA_VECTOR`` or ``GMT_VIA_MATRIX`` constructs for this. Use
861
863
``GMT_IS_VECTOR`` and ``GMT_IS_MATRIX`` instead.
862
864
geometry : str
863
865
A valid GMT data geometry name (e.g., ``'GMT_IS_POINT'``). See the
864
- ``data_geometries `` attribute for valid names.
866
+ ``GEOMETRIES `` attribute for valid names.
865
867
mode : str
866
868
How the data is to be written to the file. This option varies
867
869
depending on the given family. See the GMT API documentation for
@@ -1243,21 +1245,30 @@ def virtualfile_from_grid(self, grid):
1243
1245
... args = '{} -L0 -Cn ->{}'.format(fin, fout.name)
1244
1246
... ses.call_module('grdinfo', args)
1245
1247
... print(fout.read().strip())
1246
- -179.5 179.5 -89.5 89.5 -8182 5651.5 1 1 360 180 0 0
1248
+ -180 180 -90 90 -8182 5651.5 1 1 360 180 1 1
1247
1249
>>> # The output is: w e s n z0 z1 dx dy n_columns n_rows reg gtype
1248
1250
1249
1251
"""
1252
+ _gtype = {0 : "GMT_GRID_IS_CARTESIAN" , 1 : "GMT_GRID_IS_GEO" }[grid .gmt .gtype ]
1253
+ _reg = {0 : "GMT_GRID_NODE_REG" , 1 : "GMT_GRID_PIXEL_REG" }[grid .gmt .registration ]
1254
+
1250
1255
# Conversion to a C-contiguous array needs to be done here and not in
1251
1256
# put_matrix because we need to maintain a reference to the copy while
1252
1257
# it is being used by the C API. Otherwise, the array would be garbage
1253
1258
# collected and the memory freed. Creating it in this context manager
1254
1259
# guarantees that the copy will be around until the virtual file is
1255
1260
# closed. The conversion is implicit in dataarray_to_matrix.
1256
1261
matrix , region , inc = dataarray_to_matrix (grid )
1262
+
1257
1263
family = "GMT_IS_GRID|GMT_VIA_MATRIX"
1258
1264
geometry = "GMT_IS_SURFACE"
1259
1265
gmt_grid = self .create_data (
1260
- family , geometry , mode = "GMT_CONTAINER_ONLY" , ranges = region , inc = inc
1266
+ family ,
1267
+ geometry ,
1268
+ mode = f"GMT_CONTAINER_ONLY|{ _gtype } " ,
1269
+ ranges = region ,
1270
+ inc = inc ,
1271
+ registration = _reg ,
1261
1272
)
1262
1273
self .put_matrix (gmt_grid , matrix )
1263
1274
args = (family , geometry , "GMT_IN|GMT_IS_REFERENCE" , gmt_grid )
0 commit comments