Skip to content

Commit

Permalink
GMT_DATASET: Refactor nested classes to improve code readability (#3653)
Browse files Browse the repository at this point in the history
  • Loading branch information
seisman authored Nov 27, 2024
1 parent 100bcba commit 988746b
Showing 1 changed file with 54 additions and 52 deletions.
106 changes: 54 additions & 52 deletions pygmt/datatypes/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,60 @@
import pandas as pd


class _GMT_DATASEGMENT(ctp.Structure): # noqa: N801
"""
GMT datasegment structure for holding a segment with multiple columns.
"""

_fields_: ClassVar = [
# Number of rows/records in this segment
("n_rows", ctp.c_uint64),
# Number of fields in each record
("n_columns", ctp.c_uint64),
# Minimum coordinate for each column
("min", ctp.POINTER(ctp.c_double)),
# Maximum coordinate for each column
("max", ctp.POINTER(ctp.c_double)),
# Data x, y, and possibly other columns
("data", ctp.POINTER(ctp.POINTER(ctp.c_double))),
# Label string (if applicable)
("label", ctp.c_char_p),
# Segment header (if applicable)
("header", ctp.c_char_p),
# text beyond the data
("text", ctp.POINTER(ctp.c_char_p)),
# Book-keeping variables "hidden" from the API
("hidden", ctp.c_void_p),
]


class _GMT_DATATABLE(ctp.Structure): # noqa: N801
"""
GMT datatable structure for holding a table with multiple segments.
"""

_fields_: ClassVar = [
# Number of file header records (0 if no header)
("n_headers", ctp.c_uint),
# Number of columns (fields) in each record
("n_columns", ctp.c_uint64),
# Number of segments in the array
("n_segments", ctp.c_uint64),
# Total number of data records across all segments
("n_records", ctp.c_uint64),
# Minimum coordinate for each column
("min", ctp.POINTER(ctp.c_double)),
# Maximum coordinate for each column
("max", ctp.POINTER(ctp.c_double)),
# Array with all file header records, if any
("header", ctp.POINTER(ctp.c_char_p)),
# Pointer to array of segments
("segment", ctp.POINTER(ctp.POINTER(_GMT_DATASEGMENT))),
# Book-keeping variables "hidden" from the API
("hidden", ctp.c_void_p),
]


class _GMT_DATASET(ctp.Structure): # noqa: N801
"""
GMT dataset structure for holding multiple tables (files).
Expand Down Expand Up @@ -67,58 +121,6 @@ class _GMT_DATASET(ctp.Structure): # noqa: N801
[b'TEXT8 TEXT90', b'TEXT123 TEXT456789']
"""

class _GMT_DATATABLE(ctp.Structure): # noqa: N801
"""
GMT datatable structure for holding a table with multiple segments.
"""

class _GMT_DATASEGMENT(ctp.Structure): # noqa: N801
"""
GMT datasegment structure for holding a segment with multiple columns.
"""

_fields_: ClassVar = [
# Number of rows/records in this segment
("n_rows", ctp.c_uint64),
# Number of fields in each record
("n_columns", ctp.c_uint64),
# Minimum coordinate for each column
("min", ctp.POINTER(ctp.c_double)),
# Maximum coordinate for each column
("max", ctp.POINTER(ctp.c_double)),
# Data x, y, and possibly other columns
("data", ctp.POINTER(ctp.POINTER(ctp.c_double))),
# Label string (if applicable)
("label", ctp.c_char_p),
# Segment header (if applicable)
("header", ctp.c_char_p),
# text beyond the data
("text", ctp.POINTER(ctp.c_char_p)),
# Book-keeping variables "hidden" from the API
("hidden", ctp.c_void_p),
]

_fields_: ClassVar = [
# Number of file header records (0 if no header)
("n_headers", ctp.c_uint),
# Number of columns (fields) in each record
("n_columns", ctp.c_uint64),
# Number of segments in the array
("n_segments", ctp.c_uint64),
# Total number of data records across all segments
("n_records", ctp.c_uint64),
# Minimum coordinate for each column
("min", ctp.POINTER(ctp.c_double)),
# Maximum coordinate for each column
("max", ctp.POINTER(ctp.c_double)),
# Array with all file header records, if any
("header", ctp.POINTER(ctp.c_char_p)),
# Pointer to array of segments
("segment", ctp.POINTER(ctp.POINTER(_GMT_DATASEGMENT))),
# Book-keeping variables "hidden" from the API
("hidden", ctp.c_void_p),
]

_fields_: ClassVar = [
# The total number of tables (files) contained
("n_tables", ctp.c_uint64),
Expand Down

0 comments on commit 988746b

Please sign in to comment.