19
19
array_to_datetime ,
20
20
as_c_contiguous ,
21
21
dataarray_to_matrix ,
22
- kwargs_to_ctypes_array ,
22
+ sequence_to_ctypes_array ,
23
+ strings_to_ctypes_array ,
23
24
vectors_to_arrays ,
24
25
)
25
26
from pygmt .clib .loading import load_libgmt
@@ -656,7 +657,17 @@ def call_module(self, module: str, args: list[str]):
656
657
f"Module '{ module } ' failed with status code { status } :\n { self ._error_message } "
657
658
)
658
659
659
- def create_data (self , family , geometry , mode , ** kwargs ):
660
+ def create_data (
661
+ self ,
662
+ family ,
663
+ geometry ,
664
+ mode ,
665
+ dim = None ,
666
+ ranges = None ,
667
+ inc = None ,
668
+ registration = "GMT_GRID_NODE_REG" ,
669
+ pad = None ,
670
+ ):
660
671
"""
661
672
Create an empty GMT data container.
662
673
@@ -720,15 +731,13 @@ def create_data(self, family, geometry, mode, **kwargs):
720
731
valid_modifiers = ["GMT_GRID_IS_CARTESIAN" , "GMT_GRID_IS_GEO" ],
721
732
)
722
733
geometry_int = self ._parse_constant (geometry , valid = GEOMETRIES )
723
- registration_int = self ._parse_constant (
724
- kwargs .get ("registration" , "GMT_GRID_NODE_REG" ), valid = REGISTRATIONS
725
- )
734
+ registration_int = self ._parse_constant (registration , valid = REGISTRATIONS )
726
735
727
736
# Convert dim, ranges, and inc to ctypes arrays if given (will be None
728
737
# if not given to represent NULL pointers)
729
- dim = kwargs_to_ctypes_array ( " dim" , kwargs , ctp .c_uint64 * 4 )
730
- ranges = kwargs_to_ctypes_array ( " ranges" , kwargs , ctp .c_double * 4 )
731
- inc = kwargs_to_ctypes_array ( " inc" , kwargs , ctp .c_double * 2 )
738
+ dim = sequence_to_ctypes_array ( dim , ctp .c_uint64 , 4 )
739
+ ranges = sequence_to_ctypes_array ( ranges , ctp .c_double , 4 )
740
+ inc = sequence_to_ctypes_array ( inc , ctp .c_double , 2 )
732
741
733
742
# Use a NULL pointer (None) for existing data to indicate that the
734
743
# container should be created empty. Fill it in later using put_vector
@@ -742,7 +751,7 @@ def create_data(self, family, geometry, mode, **kwargs):
742
751
ranges ,
743
752
inc ,
744
753
registration_int ,
745
- self ._parse_pad (family , kwargs ),
754
+ self ._parse_pad (family , pad ),
746
755
None ,
747
756
)
748
757
@@ -751,15 +760,14 @@ def create_data(self, family, geometry, mode, **kwargs):
751
760
752
761
return data_ptr
753
762
754
- def _parse_pad (self , family , kwargs ):
763
+ def _parse_pad (self , family , pad ):
755
764
"""
756
765
Parse and return an appropriate value for pad if none is given.
757
766
758
767
Pad is a bit tricky because, for matrix types, pad control the matrix ordering
759
768
(row or column major). Using the default pad will set it to column major and
760
769
mess things up with the numpy arrays.
761
770
"""
762
- pad = kwargs .get ("pad" , None )
763
771
if pad is None :
764
772
pad = 0 if "MATRIX" in family else self ["GMT_PAD_DEFAULT" ]
765
773
return pad
@@ -918,13 +926,9 @@ def put_vector(self, dataset, column, vector):
918
926
919
927
gmt_type = self ._check_dtype_and_dim (vector , ndim = 1 )
920
928
if gmt_type in (self ["GMT_TEXT" ], self ["GMT_DATETIME" ]):
921
- vector_pointer = (ctp .c_char_p * len (vector ))()
922
929
if gmt_type == self ["GMT_DATETIME" ]:
923
- vector_pointer [:] = np .char .encode (
924
- np .datetime_as_string (array_to_datetime (vector ))
925
- )
926
- else :
927
- vector_pointer [:] = np .char .encode (vector )
930
+ vector = np .datetime_as_string (array_to_datetime (vector ))
931
+ vector_pointer = strings_to_ctypes_array (vector )
928
932
else :
929
933
vector_pointer = vector .ctypes .data_as (ctp .c_void_p )
930
934
status = c_put_vector (
@@ -981,13 +985,12 @@ def put_strings(self, dataset, family, strings):
981
985
restype = ctp .c_int ,
982
986
)
983
987
984
- strings_pointer = (ctp .c_char_p * len (strings ))()
985
- strings_pointer [:] = np .char .encode (strings )
986
-
987
988
family_int = self ._parse_constant (
988
989
family , valid = FAMILIES , valid_modifiers = METHODS
989
990
)
990
991
992
+ strings_pointer = strings_to_ctypes_array (strings )
993
+
991
994
status = c_put_strings (
992
995
self .session_pointer , family_int , dataset , strings_pointer
993
996
)
@@ -1108,7 +1111,7 @@ def write_data(self, family, geometry, mode, wesn, output, data):
1108
1111
self ["GMT_IS_FILE" ],
1109
1112
geometry_int ,
1110
1113
self [mode ],
1111
- ( ctp .c_double * 6 )( * wesn ),
1114
+ sequence_to_ctypes_array ( wesn , ctp .c_double , 6 ),
1112
1115
output .encode (),
1113
1116
data ,
1114
1117
)
0 commit comments