Skip to content

GMT_DATASET: Refactor nested classes to improve code readability #3653

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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