Skip to content

Commit 988746b

Browse files
authored
GMT_DATASET: Refactor nested classes to improve code readability (#3653)
1 parent 100bcba commit 988746b

File tree

1 file changed

+54
-52
lines changed

1 file changed

+54
-52
lines changed

pygmt/datatypes/dataset.py

+54-52
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,60 @@
1111
import pandas as pd
1212

1313

14+
class _GMT_DATASEGMENT(ctp.Structure): # noqa: N801
15+
"""
16+
GMT datasegment structure for holding a segment with multiple columns.
17+
"""
18+
19+
_fields_: ClassVar = [
20+
# Number of rows/records in this segment
21+
("n_rows", ctp.c_uint64),
22+
# Number of fields in each record
23+
("n_columns", ctp.c_uint64),
24+
# Minimum coordinate for each column
25+
("min", ctp.POINTER(ctp.c_double)),
26+
# Maximum coordinate for each column
27+
("max", ctp.POINTER(ctp.c_double)),
28+
# Data x, y, and possibly other columns
29+
("data", ctp.POINTER(ctp.POINTER(ctp.c_double))),
30+
# Label string (if applicable)
31+
("label", ctp.c_char_p),
32+
# Segment header (if applicable)
33+
("header", ctp.c_char_p),
34+
# text beyond the data
35+
("text", ctp.POINTER(ctp.c_char_p)),
36+
# Book-keeping variables "hidden" from the API
37+
("hidden", ctp.c_void_p),
38+
]
39+
40+
41+
class _GMT_DATATABLE(ctp.Structure): # noqa: N801
42+
"""
43+
GMT datatable structure for holding a table with multiple segments.
44+
"""
45+
46+
_fields_: ClassVar = [
47+
# Number of file header records (0 if no header)
48+
("n_headers", ctp.c_uint),
49+
# Number of columns (fields) in each record
50+
("n_columns", ctp.c_uint64),
51+
# Number of segments in the array
52+
("n_segments", ctp.c_uint64),
53+
# Total number of data records across all segments
54+
("n_records", ctp.c_uint64),
55+
# Minimum coordinate for each column
56+
("min", ctp.POINTER(ctp.c_double)),
57+
# Maximum coordinate for each column
58+
("max", ctp.POINTER(ctp.c_double)),
59+
# Array with all file header records, if any
60+
("header", ctp.POINTER(ctp.c_char_p)),
61+
# Pointer to array of segments
62+
("segment", ctp.POINTER(ctp.POINTER(_GMT_DATASEGMENT))),
63+
# Book-keeping variables "hidden" from the API
64+
("hidden", ctp.c_void_p),
65+
]
66+
67+
1468
class _GMT_DATASET(ctp.Structure): # noqa: N801
1569
"""
1670
GMT dataset structure for holding multiple tables (files).
@@ -67,58 +121,6 @@ class _GMT_DATASET(ctp.Structure): # noqa: N801
67121
[b'TEXT8 TEXT90', b'TEXT123 TEXT456789']
68122
"""
69123

70-
class _GMT_DATATABLE(ctp.Structure): # noqa: N801
71-
"""
72-
GMT datatable structure for holding a table with multiple segments.
73-
"""
74-
75-
class _GMT_DATASEGMENT(ctp.Structure): # noqa: N801
76-
"""
77-
GMT datasegment structure for holding a segment with multiple columns.
78-
"""
79-
80-
_fields_: ClassVar = [
81-
# Number of rows/records in this segment
82-
("n_rows", ctp.c_uint64),
83-
# Number of fields in each record
84-
("n_columns", ctp.c_uint64),
85-
# Minimum coordinate for each column
86-
("min", ctp.POINTER(ctp.c_double)),
87-
# Maximum coordinate for each column
88-
("max", ctp.POINTER(ctp.c_double)),
89-
# Data x, y, and possibly other columns
90-
("data", ctp.POINTER(ctp.POINTER(ctp.c_double))),
91-
# Label string (if applicable)
92-
("label", ctp.c_char_p),
93-
# Segment header (if applicable)
94-
("header", ctp.c_char_p),
95-
# text beyond the data
96-
("text", ctp.POINTER(ctp.c_char_p)),
97-
# Book-keeping variables "hidden" from the API
98-
("hidden", ctp.c_void_p),
99-
]
100-
101-
_fields_: ClassVar = [
102-
# Number of file header records (0 if no header)
103-
("n_headers", ctp.c_uint),
104-
# Number of columns (fields) in each record
105-
("n_columns", ctp.c_uint64),
106-
# Number of segments in the array
107-
("n_segments", ctp.c_uint64),
108-
# Total number of data records across all segments
109-
("n_records", ctp.c_uint64),
110-
# Minimum coordinate for each column
111-
("min", ctp.POINTER(ctp.c_double)),
112-
# Maximum coordinate for each column
113-
("max", ctp.POINTER(ctp.c_double)),
114-
# Array with all file header records, if any
115-
("header", ctp.POINTER(ctp.c_char_p)),
116-
# Pointer to array of segments
117-
("segment", ctp.POINTER(ctp.POINTER(_GMT_DATASEGMENT))),
118-
# Book-keeping variables "hidden" from the API
119-
("hidden", ctp.c_void_p),
120-
]
121-
122124
_fields_: ClassVar = [
123125
# The total number of tables (files) contained
124126
("n_tables", ctp.c_uint64),

0 commit comments

Comments
 (0)