API reference¶
Generated from this package's own docstrings (numpydoc style -- see
this repository's CLAUDE.md for the convention). This page covers
pygdb's public surface -- everything listed in pygdb.__all__ --
grouped the way the quick start introduces
them.
The GDB class¶
pygdb.GDB(path, include_unlisted_blobs=False)
¶
High-level, name-based view of a single .gdb file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
Path to the |
required |
include_unlisted_blobs
|
bool
|
A file that carries a blob directory (see Notes) lists exactly
one live blob per (line, channel). By default a blob the
directory does not list -- an all-zero slot -- is skipped, as
if it were absent, and one |
False
|
Raises:
| Type | Description |
|---|---|
ValueError
|
At construction time, if |
Examples:
>>> db = GDB("survey.gdb")
>>> db.line_names[:3]
['L1000', 'L1001', 'L1010']
>>> db.channels_on_line("L1000")[:3]
['Fiducial', 'Easting', 'Northing']
>>> db.read("L1000", "Easting")[:3]
[612345.6, 612346.1, 612346.7]
>>> db.compression.name
'DB_COMP_NONE'
>>> db.coordinate_systems
['NAD83 / UTM zone 11N', 'WGS 84']
Notes
Channel and line tables are read once, lazily, on first access, and
cached; the (line, channel) -> blob index used by read() and
channels_on_line() is likewise built once (a full blob-chain walk)
on first use. Unlike the module-level gdb_reader functions this
class is built on (which each reopen path fresh, for statelessness),
GDB opens path once at construction and reuses that handle for
every read()/iter_line() call -- reopening per call was measured
at ~1.7-1.9x slower against this project's real sample corpus (see
the Rust-plan's M4 notes). Close it (db.close(), or use GDB as a
context manager) when done with it, or just let it get
garbage-collected -- __del__ closes it too, as a safety net.
Which copy of a blob is read. The blob chain is append-only, so
a (line, channel) can have several blobs, an older stale one and
the current one, in either order (issue #2). The file's persisted
blob directory (docs/spec.md section 2.2) says which is current,
and it is the only thing consulted. A directory entry is used only
if its start page lands on a walked blob header whose blob_index
equals the slot and whose page count matches; if a non-zero entry
fails that check, the last copy in chain order is used and a
GDBParseWarning says so. Without a usable directory the last copy
in chain order is used, with a warning if a pair is duplicated: that
is a guess, and not always the current copy.
Source code in pygdb/gdb.py
channel_makers
property
¶
dict of {str : ChannelMaker}: How each channel was made, from the
MAKER records in this file's registry (docs/spec.md section 9) --
the tool ("newchan.gx", a math expression, "newxy.gx", ...),
its label, and the parameters it ran with, e.g. a derived
channel's formula. Only channels with a record are present; see
pygdb.registry.find_channel_makers.
channel_names
property
¶
list of str: [c.name for c in self.channels].
channel_settings
property
¶
dict of {str : dict of {str : str}}: Real per-channel settings
recorded in this file's own internal registry
(docs/provenance/notes.md section 6.8c), e.g. {"raw_mag":
{"UNITS": "nT"}, ...}. Only a channel with at least one
populated registry key is present; most real files have none for
most channels -- see pygdb.registry.find_channel_settings for
what is and isn't decoded (the registry's key/value entries, not
its nested MAKER records, which are channel_makers).
channels
property
¶
list of ChannelRecord: This file's channel table, read once and cached.
chans_max
property
¶
int or None: The file's channel-table capacity (header offset 24).
comp_level
property
¶
int or None: The file's declared compression level (header offset 120).
compression
property
¶
CompressionInfo: The file's declared compression mode.
coordinate_channels
property
¶
dict of {str : str or None}: Which real channel plays the
X/Y/Z coordinate role, per this file's own internal registry
(docs/provenance/notes.md section 6.8b) -- a directly-decodable
alternative to guessing from channel-naming conventions.
Always {"X": ..., "Y": ..., "Z": ...}; a role this file's
registry doesn't confirm a real channel for (absent entirely,
or a real but ambiguous/blank entry -- see
pygdb.registry.find_channel_roles) is None, not omitted.
Confirmed present and correctly resolvable on every one of
this project's 22 real sample files for X/Y (100%), 2 of 22
for Z -- to_geoh5 uses this as its coordinate-channel
default, falling back to "Easting"/"Northing" only when a
role isn't confirmed here.
coordinate_systems
property
¶
list of str: Best-effort coordinate-system/map-projection names found in this file's REG/IPJ administrative-blob content (docs/spec.md section 8-9). An empty list just means none were found -- not every real file has this content, and even when it does, this is a name-only extraction, not a full projection definition.
display_lists
property
¶
list of list of DisplayListEntry: The file's Display List objects
(docs/spec.md section 9) -- [LIKELY] the channels shown in the
database's spreadsheet view -- each entry resolved by handle to the
channel's current name. See pygdb.registry.find_display_lists.
line_names
property
¶
list of str: [l.name for l in self.lines].
lines
property
¶
list of LineRecord: This file's line table, read once and cached.
page_size
property
¶
int or None: The file's page size in bytes (header offset 100).
projection_parameters
property
¶
dict of {str : ProjectionParameters}: Real geodetic parameters for
each coordinate system named in coordinate_systems, decoded from
this file's own internal IPJ registry (docs/spec.md section 8,
docs/provenance/notes.md section 6.7b) -- datum, ellipsoid, and
(when this coordinate system is a projected one) central
meridian, scale factor, and false easting/northing. An empty
dict just means no IPJ content was found, same as
coordinate_systems; see pygdb.registry.find_projection_parameters
for exactly what is and isn't decoded.
channel(name)
¶
Look up a channel by name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str or tuple of (str, int)
|
A plain channel name, or |
required |
Returns:
| Type | Description |
|---|---|
ChannelRecord
|
The matching channel. |
Raises:
| Type | Description |
|---|---|
KeyError
|
If no channel has this name. |
ValueError
|
If more than one channel shares this name and no
|
Source code in pygdb/gdb.py
channels_on_line(line)
¶
Names of channels that actually have data on line.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
line
|
str or tuple or LineRecord
|
A line name, a |
required |
Returns:
| Type | Description |
|---|---|
list of str
|
Channel names with a real data blob recorded for |
Source code in pygdb/gdb.py
close()
¶
iter_line(line)
¶
Iterate every channel's data on one line.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
line
|
str or tuple or LineRecord
|
A line name, a |
required |
Yields:
| Name | Type | Description |
|---|---|---|
channel |
ChannelRecord
|
The channel itself, not just its name -- deliberately, so
that if two channels share a name and both have data on
this line, both still come through as distinct,
fully-identified entries. |
values |
ndarray
|
Same as |
Notes
Uses _channels_with_data_on_line directly rather than one
read() call per channel (saving the repeated name lookups).
A rayon-based parallel batch decoder was tried for this and
removed: benchmarked against this project's real sample
corpus, it was consistently ~3x slower than plain sequential
calls at every scale tried, since this format's chunks are
small enough that the Rust decoder (pygdb._native) already
finishes each one in a fraction of a millisecond -- not enough
work per chunk to amortize rayon's per-task dispatch cost. See
rust/src/lib.rs's module doc for the full note.
Source code in pygdb/gdb.py
line(name)
¶
Look up a line by name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str or tuple of (str, int)
|
A plain line name, or |
required |
Returns:
| Type | Description |
|---|---|
LineRecord
|
The matching line. |
Raises:
| Type | Description |
|---|---|
KeyError
|
If no line has this name. |
ValueError
|
If more than one line shares this name and no |
Source code in pygdb/gdb.py
read(line, channel)
¶
Random access by name: decode every value recorded for channel on line.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
line
|
str or tuple or LineRecord
|
A line name, a |
required |
channel
|
str or tuple or ChannelRecord
|
A channel name, a |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
1-D for an ordinary scalar channel, 2-D |
Raises:
| Type | Description |
|---|---|
KeyError
|
If |
ValueError
|
If |
Warns:
| Type | Description |
|---|---|
GDBParseWarning
|
Per |
Source code in pygdb/gdb.py
to_dataframe(line=None)
¶
Build a pandas.DataFrame -- one row per station.
Needs the optional pandas dependency (pip install
python-gdb[pandas]), imported lazily here so importing
pygdb itself never requires it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
line
|
str, int, or LineRecord
|
If given, scope the export to that one line only,
mirroring If omitted (the default), export every line with real
data, concatenated into one table -- |
None
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
|
Raises:
| Type | Description |
|---|---|
ImportError
|
If the optional |
Warns:
| Type | Description |
|---|---|
GDBParseWarning
|
In whole-file mode, if a real channel collides with the
reserved |
Notes
A VA/array channel (docs/spec.md section 5) is exported as one
column per element, f"{name}[{j}]" for j in
range(array_width) -- the same flattening to_geoh5 uses,
for the same reason: there's no natural "one cell holds an
array" representation in a plain 2D table.
If two channels share a name and both have data on a line, the
second (and any later) occurrence's column is disambiguated as
f"{name}[{occurrence}]", identical numbering to to_xarray/
to_geoh5 (see _disambiguate_names).
If channels on one line don't all decode to the same row count
(a truncated/corrupt file), the short channel's column is
padded with missing values out to the max row count across
that line's channels, rather than being dropped or forcing
other channels to truncate to match -- see _pad_to_length's
docstring for why padding, specifically, is the right default
here where it wasn't for to_xarray/to_geoh5. A channel
entirely absent on one line in whole-file mode (present on
some lines, not others -- a normal, sparse case, docs/spec.md
section 1) needs no special handling here: it's simply missing
from that line's own per-line frame, and pandas.concat's
ordinary union-of-columns behavior fills the gap with missing
values across the whole table -- no warning, since a channel
simply not being on a line is the format's normal baseline,
not a sign of trouble.
Source code in pygdb/gdb.py
1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 | |
to_geoh5(path, *, x_channel=None, y_channel=None, z_channel=None)
¶
Export every line's data to a new .geoh5 file at path.
One Points object per line (holding real per-line data,
i.e. it has at least one channel with data), grouped under one
ContainerGroup named after this .gdb file, inside a
geoh5py.Workspace. Needs the optional geoh5py dependency
(pip install python-gdb[geoh5]), imported lazily here so
importing pygdb itself never requires it.
Unlike to_xarray (one line, in memory, no geometry needed),
this is whole-file and writes directly to disk, since a
geoh5py.Workspace is inherently file-backed and .geoh5's own
natural unit is one file holding a whole survey's worth of named
objects, not one line at a time.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
Path to the |
required |
x_channel
|
str
|
Name the channels providing each line's |
None
|
y_channel
|
str
|
Name the channels providing each line's |
None
|
z_channel
|
str
|
Name the channels providing each line's |
None
|
Raises:
| Type | Description |
|---|---|
ImportError
|
If the optional |
Warns:
| Type | Description |
|---|---|
GDBParseWarning
|
A line missing its resolved X or Y channel is skipped
entirely (no |
Notes
Array/VA channels (docs/spec.md section 5): .geoh5 (per
geoh5py, checked directly against its real data/ module
source) has no Data type holding more than one value per
vertex -- the plain numeric types silently ravel() anything
with ndim > 1. So each array channel is exported as one
Data entry per column, named f"{name}[{j}]" for j in
range(array_width), tied back together with a PropertyGroup
named after the channel (ObjectBase.add_data(...,
property_group=name)) -- the same "one Data per gate/column,
grouped" pattern geoh5py's own built-in survey types
(AirborneTEMSurvey et al.) use internally for multi-gate EM
decay-curve data, not a workaround invented here.
Duplicate channel names: disambiguated exactly like
to_xarray (see _disambiguate_names) -- f"{name}[{occurrence}]"
for every occurrence after the first, same numbering as
channel(("name", occurrence)).
Row-count mismatches: .geoh5 Data with VERTEX
association must match the parent object's vertex count
exactly -- there's no analogue to to_xarray's per-channel
dimension escape hatch. A channel that decodes to a different
row count than this line's vertex count (from x_channel) is
skipped (that channel only, not the whole line).
Not attempted: coordinate-system/CRS export --
self.coordinate_systems only returns best-effort names (no
EPSG codes or full projection definitions), which isn't enough
to populate .geoh5's real CRS metadata correctly.
Source code in pygdb/gdb.py
1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 | |
to_xarray(line=None)
¶
Build an xarray.Dataset.
Needs the optional xarray dependency (pip install
python-gdb[xarray]), imported lazily here so importing
pygdb itself never requires it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
line
|
str, int, or LineRecord
|
If given, scope the export to that one line only -- one
data variable per channel that has data on that line,
sharing a common If omitted (the default), export every line with real
data, stacked along a new |
None
|
Returns:
| Type | Description |
|---|---|
Dataset
|
|
Raises:
| Type | Description |
|---|---|
ImportError
|
If the optional |
Notes
Either way, a channel name shared by more than one channel in
this file's table is disambiguated as f"{name}[{occurrence}]"
the same way, resolved file-wide (not per line) so a given
channel's variable name never depends on which line(s) are
being exported -- see _disambiguate_names.
Source code in pygdb/gdb.py
pygdb.CompressionInfo(code, name, codec)
dataclass
¶
This file's declared compression mode.
Header offset 120, docs/spec.md section 7.
Attributes:
| Name | Type | Description |
|---|---|---|
code |
int or None
|
Raw compression-level int32 (0, 1, or 2). |
name |
str
|
The matching |
codec |
str
|
The matching real codec name ( |
Notes
This describes what the file was configured with, not a guarantee
every blob actually used it -- some real files declare
DB_COMP_SPEED/DB_COMP_SIZE but contain zero compressed blobs
(docs/spec.md section 7.6), and individual "bare" blobs inside a
genuinely-compressed file can skip compression entirely
(docs/spec.md section 7.4) -- read_blob_values() already detects
and handles both cases automatically per-blob.
Records¶
pygdb.ChannelRecord(index, offset, name, dtype_code, format_code, raw, array_width=1, array_basetype_code=0, name_is_clean=True)
dataclass
¶
One record from a .gdb file's channel symbol table.
Attributes:
| Name | Type | Description |
|---|---|---|
index |
int
|
Slot index into the channel table. |
offset |
int
|
Byte offset of this record within the file. |
name |
str
|
Channel name. |
dtype_code |
int
|
Raw int16 value: positive = |
format_code |
int
|
Raw int16 display-format code (see |
raw |
bytes
|
The record's raw, undecoded bytes. |
array_width |
int, default 1
|
[CONFIRMED] relative offset +118, int16. 1 = plain scalar channel (the overwhelming majority of real channels seen). >1 = a true VA/array channel storing that many elements per fiducial "cell" -- e.g. 24 (time-decay gates) or 30 (depth layers) in the real AG106386 Georgetown conductivity file. Independently cross-checked against that same file's plain-text ASCII sibling (.dfn) format, which spells out "30F10.4" (Fortran-style: 30 repetitions of a float field) for the exact same channel name -- see docs/provenance/notes.md. |
array_basetype_code |
int, default 0
|
[LIKELY] relative offset +86, int16. |
name_is_clean |
bool, default True
|
False if the name field was NUL-unterminated or had non-printable bytes -- see docs/provenance/notes.md re: older (pre-2020, e.g. 1990s GEOTEM) files sometimes leaving unused capacity slots un-zeroed rather than clean, unlike the 2020 USGS samples. |
Notes
eq=False keeps the default identity-based __eq__/__hash__
instead of dataclass's usual field-by-field one, so instances stay
hashable (GDB.iter_line() yields these and documents dict(...)
keyed by the record itself as safe -- see its docstring -- which
needs __hash__ to actually work). Value equality between two
separately-constructed-but-identical records is never used
anywhere in this codebase; every real lookup returns the same
cached instance from GDB.channels, so identity is all that's
ever needed in practice.
array_basetype_name
property
¶
str: Human-readable array base-type name (a DB_ARRAY_BASETYPE_* name).
format_name
property
¶
str: Human-readable display-format name (a DB_CHAN_FORMAT_* name).
is_array
property
¶
bool: True for a real VA/array channel (array_width > 1). [CONFIRMED].
is_string
property
¶
bool: True if dtype_code encodes a string width (negative).
looks_sane
property
¶
Heuristic sanity check distinguishing a real channel record from leftover-garbage bytes.
Returns:
| Type | Description |
|---|---|
bool
|
True if this record looks like real channel data rather than leftover-garbage bytes that happen to decode a clean printable name (observed for real in DB_Mag_833.gdb -- see docs/provenance/notes.md). Real records seen so far always have dtype either a known GS_* code (0-13) or a small negative string width, a format code in the known DB_CHAN_FORMAT_* range (0-6), and an array width of at least 1 (elements per fiducial). |
Notes
The array-width test catches leftover records that pass the
other two: 16 records in three real GSQ files (DB_AGG_1213,
DB_Mag_1213, DB_Mag_1212) hold clean names -- fill-pattern
names, projection-catalog names, second copies of real channel
names -- with dtype 0 and array width 0 (or garbage), and own no
data blob at all. Every genuine channel in the corpus has width
1 or more (docs/provenance/notes.md section 6.2d).
string_width
property
¶
int or None: Fixed on-disk width in bytes, for a string channel.
type_name
property
¶
str: Human-readable type name (a GS_* name, or "string[N]").
pygdb.LineRecord(index, offset, name, category_code, raw, name_is_clean=True)
dataclass
¶
One 128-byte line-table record.
Attributes:
| Name | Type | Description |
|---|---|---|
index |
int
|
0-based physical slot number -- this IS |
offset |
int
|
Byte offset of this record within the file. |
name |
str
|
Line name. |
category_code |
int or None
|
Raw int32 category code (see |
raw |
bytes
|
The record's raw, undecoded bytes. |
name_is_clean |
bool, default True
|
See |
Notes
[LIKELY]/[UNKNOWN] -- much less firmly established than
ChannelRecord: only the name (relative +32) and category code
(relative +108) fields are decoded. The table is located exactly
(exact_line_table_start, [CONFIRMED] on the corpus) and only
falls back to the find_line_table heuristic scan when that
cannot be validated. See docs/spec.md section 3.2 and docs/provenance/notes.md
section 6.3.
eq=False keeps the default identity-based __eq__/__hash__
instead of dataclass's usual field-by-field one -- needed both to
stay hashable (see ChannelRecord's docstring for why) and
because GDB._calibrate_line_indices mutates .index in place on
these after construction; a value-based __eq__/__hash__ pair
would be actively wrong for an object whose fields change
post-construction.
category_name
property
¶
str: Human-readable category name (a DB_CATEGORY_LINE_* name).
pygdb.BlobHeader(offset, n_pages, n_pages_dup, blob_index, timestamp, reserved_200, scale, row_count, gs_type_code)
dataclass
¶
The per-channel-per-line data block header.
Attributes:
| Name | Type | Description |
|---|---|---|
offset |
int
|
Absolute file offset of this header's first byte. |
n_pages |
int
|
[CONFIRMED] -- this blob's total on-disk size, in pages
( |
n_pages_dup |
int
|
[LIKELY] -- always seen equal to |
blob_index |
int
|
[CONFIRMED] -- see |
timestamp |
int
|
[LIKELY], modern files only -- see Notes. |
reserved_200 |
int
|
[UNKNOWN]. |
scale |
float
|
[LIKELY], modern files only. |
row_count |
int
|
[CONFIRMED], modern files only (verified against real ground-truth-matching decoded values). |
gs_type_code |
int
|
[CONFIRMED], modern files only (matches owning channel's own symbol-table dtype exactly). |
Notes
[CONFIRMED] for fields up to and including blob_index
(verified byte-exact on 5 real DB_COMP_NONE files via a
whole-file, zero-error chain walk that lands exactly on each
file's true size -- see docs/provenance/notes.md section 6.6).
Fields from timestamp onward are only [LIKELY]/[UNKNOWN]
and are known NOT to decode sensibly at these byte offsets in at
least one real older (1991 GSQ) file -- kept here for the modern
(2020 USGS) case where they were verified, not assumed general.
data_offset
property
¶
int: Absolute file offset where this blob's value data begins.
line_channel(chans_max)
¶
Decompose blob_index into (line_slot_index, channel_slot_index).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
chans_max
|
int
|
The file's channel-table capacity (from |
required |
Returns:
| Type | Description |
|---|---|
tuple of (int, int)
|
:: |
Source code in pygdb/gdb_reader.py
pygdb.BlobDirectory(data_slots, entries)
dataclass
¶
The persisted blob directory: which blob is the live one for each slot.
Attributes:
| Name | Type | Description |
|---|---|---|
data_slots |
int
|
Number of directory slots that address (line, channel) data
blobs (header word 48, |
entries |
dict of {int : (int, int)}
|
Every non-zero data slot as |
Notes
[CONFIRMED] layout, [LIKELY] interpretation
(docs/spec.md section 2.2; docs/provenance/notes.md section 6.1c).
The directory is an array of 6-byte slots starting at file offset
280. A live entry is (0x80000000 | start page, n_pages) where
the start page is relative to the first blob ((offset - blob
region start) / page_size), optionally with the 0x40000000 bit,
which flips each time the blob is rewritten. (Every data entry in
the first 22 corpus files read 0x8; the first data entry with
0xC, in USGS OFR 2011-1270 Kalay_nk.gdb, is the live copy -- the
other copy is on the free list.) Across the real corpus it addressed
100% of the real (line, channel) blobs of 20 of 22 files, and for
every duplicated pair with an independent oracle (13 of 13) it
pointed at the correct copy. A slot that is all-zero belongs to a
blob the file does not list as live.
resolve(blob_index, blobs_by_offset, first_offset, page_size)
¶
Look up the live blob for blob_index.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
blob_index
|
int
|
The slot, |
required |
blobs_by_offset
|
dict of {int : BlobHeader}
|
Every blob of the chain walk, keyed by absolute |
required |
first_offset
|
int
|
Absolute offset of the first blob ( |
required |
page_size
|
int
|
The file's page size. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
status |
str
|
|
blob |
BlobHeader or None
|
The live blob for |
Source code in pygdb/gdb_reader.py
.gdb reader functions¶
pygdb.check_magic(data)
¶
Check whether data starts with the format's magic bytes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
bytes
|
The file's leading bytes (at least 4). |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if |
Notes
[CONFIRMED] against 9/9 real files across two independent sources (2020 USGS Mojave survey, 1990s-2020s GSQ Queensland surveys from three different TEM systems/vendors).
The full 16-byte HEADER_SIGNATURE is only [LIKELY] -- it
matched exactly in 8/9 real files, but one real file
(DB_Mag_Elaine_1003.gdb, from GSQ's Mount Gordon delivery) has
f0 f0 f0 f0 at bytes 4-7 instead of the usual 00 00 00 00.
That file is otherwise structurally normal
(chans_max/users_max/page_size all decode sanely), so this looks
like a real, if rare, variation in that sub-block rather than a
different format entirely -- flagged [UNKNOWN] in
docs/provenance/notes.md. Only the 4-byte magic is treated as a
hard requirement here; the rest of the signature is reported
separately (magic_signature_matches_common_case).
Source code in pygdb/gdb_reader.py
pygdb.header_fields(data)
¶
Extract the header int32 fields whose approximate meaning is known.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
bytes
|
The file's header bytes. |
required |
Returns:
| Type | Description |
|---|---|
dict
|
Maps each of |
Warns:
| Type | Description |
|---|---|
GDBParseWarning
|
If |
Notes
comp_level==1 (DB_COMP_SPEED) does NOT mean the payload is
zlib -- confirmed it is NOT (docs/provenance/notes.md section
6.5b), it's canonical LZRW1 (section 6.5c). comp_level==2
(DB_COMP_SIZE) IS confirmed real zlib.
Source code in pygdb/gdb_reader.py
pygdb.find_channel_table(data, search_window=(0, None))
¶
Locate the start of the channel symbol table.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
bytes
|
Buffer to search (typically the start of the file). |
required |
search_window
|
tuple of (int, int or None)
|
|
(0, None)
|
Returns:
| Type | Description |
|---|---|
int
|
Byte offset of the channel table's first record. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If no |
Notes
Strategy [CONFIRMED against 2 real 2020 USGS files, RE-CONFIRMED
-- with one revision -- against 5 more real 1990s-2020s GSQ files,
see docs/provenance/notes.md/docs/provenance/log.md "pressure
test" round]: search for the default super-user name (from
GXDB.create()'s documented default super="SUPER"). The channel
table is found to occupy exactly chans_max consecutive 128-byte
records immediately before the user table, i.e.
::
channel_table_start == offset_of(super_name) - 8 - chans_max*128
This isn't a generic file-format constant we can hardcode a single
offset for -- it depends on chans_max, which itself varies
between files -- so we compute it.
REVISION from the original derivation: the two 2020 USGS files both had the default super-user name stored as literal uppercase ASCII "SUPER". Five real 1990s-2020s GSQ files instead have it stored as lowercase "super" -- confirmed to be the same structural pattern (same 128-byte-per-record math, same position relative to the channel table) once the case is corrected, not a different layout. Search for both cases. (One of the GSQ files, DB_Mag_833.gdb, also demonstrated that the literal string can coincidentally appear elsewhere in a file, e.g. inside embedded metadata blobs, and that the word "super"/"SUPER" appearing is not on its own sufficient -- a naive first-match there pointed at a bogus offset. Confirmed correct instead via an independent generic 128-byte-periodicity scan that landed on the identical answer once cross-checked.)
Every occurrence of "SUPER"/"super" is tried and the first one whose implied table start decodes a clean (NUL-terminated, printable) channel name is used.
Source code in pygdb/gdb_reader.py
518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 | |
pygdb.read_channels(path)
¶
Decode the channel symbol table.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
Path to the |
required |
Returns:
| Type | Description |
|---|---|
list of ChannelRecord
|
Every channel successfully decoded, in table order. |
Warns:
| Type | Description |
|---|---|
GDBParseWarning
|
A file that isn't a real |
Source code in pygdb/gdb_reader.py
605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 | |
pygdb.exact_line_table_start(data, lines_max)
¶
Compute the line table's start from the header and the channel table.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
bytes
|
The file's bytes up to at least the end of the channel table
( |
required |
lines_max
|
int or None
|
The line-table capacity (header word 36); |
required |
Returns:
| Type | Description |
|---|---|
int or None
|
Byte offset of the line table's first record, or |
Notes
The line table is lines_max 128-byte slots followed by a 24-byte
gap and then the channel table, so its start is
find_channel_table(data) - 24 - lines_max * 128. [CONFIRMED]
on all 23 real files examined (docs/spec.md section 2.1;
docs/provenance/notes.md section 6.1b): the computed start is
always a slot boundary that matches the heuristic's start, or is an
earlier slot the heuristic missed. The at-least-one-line-record
check only guards a file whose layout does not follow this
arithmetic; it is not needed for any real file seen.
Source code in pygdb/gdb_reader.py
pygdb.find_line_table(data, search_window=(128, None))
¶
Locate the start of the line symbol table.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
bytes
|
Buffer to search. |
required |
search_window
|
tuple of (int, int or None)
|
|
(128, None)
|
Returns:
| Type | Description |
|---|---|
int
|
Byte offset of the line table's first record. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If no line-record-shaped data (clean name + a known category code) is found in the search window. |
Notes
Prefer exact_line_table_start (via read_lines): the line
table's start follows exactly from lines_max and the channel
table's position (docs/spec.md section 2.1), which this heuristic
predates. This scan is now only the fallback for a file where that
arithmetic cannot be validated.
Unlike find_channel_table, there's no known default-name anchor
(the line table has nothing analogous to the channel table's
"SUPER" user record immediately after it), so this is a
heuristic [LIKELY] scan, not a structurally-proven technique:
it looks for a run of 128-byte records
whose relative +32 field looks like a clean, NUL-terminated,
printable line name and whose relative +108 category field
matches one of the two confirmed real values (100=NORMAL/FLIGHT,
200=GROUP), then returns the earliest such record in the run with
the most hits at a consistent 128-byte phase.
Known limitation, found by real-file testing (fixed by using
exact_line_table_start instead, not here): if a table's true first slot(s) don't carry a category
code in {100, 200}, this returns a start that's one or more slots
too late -- every subsequent LineRecord.index is then off by
that same fixed amount, which breaks blob_index lookups by line
name. Observed for real on a GSQ file (rm001141): physical slot
0 is a genuine, named record ("L0") with category 65636
([GUESS]: 65536 + 100, plausibly "a NORMAL line that was
since cleared," not confirmed), which this function doesn't
recognize, so it starts the table one slot late. A generic
backward-scan fix was tried and rejected: "keep walking backward
while the name field still looks clean" massively over-extends on
at least one real file (walked 30+ slots into what turned out to
be unrelated, legitimately-empty space before the real table).
GDB (in gdb.py) instead cross-validates and corrects this
against the actual blob chain, which is a strictly stronger
signal than anything available from the symbol-table bytes alone
-- prefer it over calling this function directly when correct
line-indexed data access matters, not just names.
Source code in pygdb/gdb_reader.py
781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 | |
pygdb.read_lines(path)
¶
Decode the line symbol table.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
Path to the |
required |
Returns:
| Type | Description |
|---|---|
list of LineRecord
|
Every line successfully decoded, in table order. |
Warns:
| Type | Description |
|---|---|
GDBParseWarning
|
A bad magic, truncated header, or unlocatable line table all
return |
Notes
The table is located exactly whenever possible (see
exact_line_table_start): it holds lines_max (header word 36)
128-byte slots and ends 24 bytes before the channel table, so its
start is channel_table_start - 24 - lines_max * 128
([CONFIRMED] on every real file in the corpus, docs/spec.md
section 2.1). Every one of the lines_max slots is then examined,
and LineRecord.index is the true slot number, so
LineRecord.index is exact and blob_index lookups keyed on it
are right.
Only when that arithmetic cannot be validated (a header without
lines_max, or no line-shaped record at the computed position) does
this fall back to the older heuristic (see find_line_table):
[LIKELY], less firmly established, reading forward until 8
consecutive records fail to look like either a populated line
record or clean unused capacity. In that fallback
LineRecord.index can be off by a small, fixed amount when the
scan starts one or more slots late -- .name is still correct but
.index is wrong. GDB (in gdb.py) corrects this against the
actual blob chain only in that case.
A populated slot whose category is neither 100 nor 200 (for
example the 65636 slot 0 of one 1991 file) is not returned, as
before -- but, unlike the fallback, it no longer shifts the
indices of the lines after it.
Source code in pygdb/gdb_reader.py
pygdb.iter_blobs(path, max_blobs=None)
¶
Walk the self-describing blob chain.
Walks from the start of the blob region to end of file (or
max_blobs, or a framing anomaly it cannot step past). A page that
does not start a blob is skipped: the walk resumes at the next page
that does.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
Path to the |
required |
max_blobs
|
int
|
Stop after yielding this many blobs, if given. |
None
|
Yields:
| Type | Description |
|---|---|
BlobHeader
|
Each blob header, in on-disk order. |
Warns:
| Type | Description |
|---|---|
GDBParseWarning
|
Reaching the file's true end cleanly is silent (the expected,
common case). Pages skipped because they do not start a blob get
one summary warning (count and offsets). A magic mismatch with no
later blob page, a non-positive |
Notes
[CONFIRMED] end-to-end (zero framing errors, landing exactly
on the true file size) on 20 real files spanning all 3 agencies
this project has files from and all three DB_COMP_* compression
modes, 2MB to 1.93GB -- see docs/provenance/notes.md section
6.6b/6.6d/6.9. One later real file (OpenEI BRIDGE
GP_Master_Gravity_11082023.gdb, 2023) has pages between blobs
that are not blobs: one page of leftover data at the region start
and a run of 96 all-zero pages. Its blobs are still contiguous
around those gaps, and the resynchronizing walk lands exactly on
the file's end.
As a generator, this already "returns partial results" in the most
natural way possible: whatever's been yielded before a problem is
hit stays with the caller (a for blob in iter_blobs(path): ...
loop simply ends, keeping everything already processed) -- nothing
is lost by stopping early.
Source code in pygdb/gdb_reader.py
1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 | |
pygdb.find_blob(path, line_slot, channel_slot, chans_max=None)
¶
Locate the blob for a specific (line, channel) pair.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
Path to the |
required |
line_slot
|
int
|
0-based physical line-table slot index. |
required |
channel_slot
|
int
|
0-based physical channel-table slot index. |
required |
chans_max
|
int
|
The file's channel-table capacity. If not given, it's read from the file's own header. |
None
|
Returns:
| Type | Description |
|---|---|
BlobHeader or None
|
The matching blob header, or |
Notes
Walks the chain (see iter_blobs) and computes the target
blob_index via the formula [CONFIRMED] in
docs/provenance/notes.md section 6.6.
This does a linear walk from the start of the blob region every
call -- fine for occasional lookups or for building a full
line/channel -> offset index once (walk the whole chain yourself
with iter_blobs() and record every blob.offset keyed by
blob.line_channel(chans_max) if you need many lookups).
Source code in pygdb/gdb_reader.py
pygdb.read_blob_directory(path)
¶
Read the persisted blob directory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
Path to the |
required |
Returns:
| Type | Description |
|---|---|
BlobDirectory or None
|
The directory, or |
Notes
See BlobDirectory. Only the data slots (0 <= slot <
data_slots) are read; the registry blob-symbol slots and the
cache slots after them are not used by the reader.
Source code in pygdb/gdb_reader.py
pygdb.read_blob_symbols(path)
¶
Read the names of the file's live administrative objects.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
Path to the |
required |
Returns:
| Type | Description |
|---|---|
dict of {int : str} or None
|
|
Notes
[CONFIRMED] layout (docs/spec.md section 2.1,
docs/provenance/notes.md section 6.2d): blobs_max 128-byte records
starting right after the blob directory, at 280 + 6 * index_slots,
each beginning with its NUL-terminated name. A record is live when
its category (record +76) is DB_CATEGORY_BLOB_NORMAL (0), which
held on exactly the 1,267 corpus records that own an administrative
blob. A freed slot has bit 0x10000 set and may still hold its old
name, so the category, not the name, decides.
Names seen on real files: four fixed objects ("__dbreg",
"Display List", "Line Selection", "Database Extension
Objects"), "?|IPJ_<X>:<Y>" projection objects, and "__<n>" REG
objects where n is a global symbol handle (blobs_max + lines_max
+ channel_slot for a channel).
Source code in pygdb/gdb_reader.py
1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 | |
pygdb.read_blob_values(path, blob, channel, comp_level=0, page_size=None, file=None)
¶
Decode a found blob's real row data.
Uses the owning channel's already-known type (from the symbol table, docs/provenance/notes.md section 6.2).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
Path to the |
required |
blob
|
BlobHeader
|
The blob to decode, as returned by |
required |
channel
|
ChannelRecord
|
The owning channel. |
required |
comp_level
|
int
|
The file's declared compression level: 0 ( |
0
|
page_size
|
int
|
The file's page size, needed to locate a compressed blob's
full span for |
None
|
file
|
BinaryIO
|
An already-open binary file handle for |
None
|
Returns:
| Type | Description |
|---|---|
ndarray
|
See |
Warns:
| Type | Description |
|---|---|
GDBParseWarning
|
Per an explicit engineering request, this fails gracefully
rather than raising: a negative |
Notes
[CONFIRMED] against real ground truth for GS_DOUBLE data and
for fixed-width strings, for DB_COMP_NONE (docs/provenance/notes.md
section 6.6: a real fid blob decoded this way reproduces the
exact CSV ground-truth value, and a real line-channel blob
decodes to the correct real line name repeated once per row).
Also handles compressed blobs (comp_level 1=DB_COMP_SPEED or
2=DB_COMP_SIZE), including multi-page ones -- [CONFIRMED]
against real ground truth for both single- and multi-page
DB_COMP_SIZE (a real single-page blob_index=0 decodes to the known
constant 5027; a real 36-page array-channel blob decodes to
LEI_Depth's exact known real depth profile, 0.0, 3.0, 6.3, 9.9,
..., repeated once per station -- both matching
docs/provenance/notes.md section 6.⅚.2b's independently-
established ground truth exactly) and for both single- and
multi-page DB_COMP_SPEED (a real 2-page Northing_AMGz55 blob
decodes to sane real coordinates with real rDUMMY sentinels).
See docs/provenance/notes.md section 6.6d: a multi-page blob has no
per-page re-framing -- just read the full n_pages*page_size span
instead of one page. A DB_COMP_SPEED blob is, however, a chain of
chunks of at most 16368 decompressed bytes each, not one chunk
(docs/provenance/notes.md section 6.6e): only the first carries the
16-byte magic, later ones are a bare 12-byte sub-header plus
payload, and the blob header's +24 field is the total
decompressed size across the chain. Decoding only the first chunk
-- as this function once did -- silently truncated any channel
longer than 2046 float64 values on a line.
A real third on-disk variant, auto-detected here rather than
assumed away (docs/provenance/notes.md section 6.6b): even
inside a file that genuinely declares (and elsewhere uses)
DB_COMP_SPEED, some individual blobs turn out to carry no chunk
wrapper at all -- just the plain 48-byte DB_COMP_NONE-style header
with real, directly readable data straight after it (confirmed on
a real Easting_AMGz55 blob in DB_EM_293.gdb: decoding it as if
comp_level==0 reproduces sane, real coordinate values with real
rDUMMY=-1.0E32 sentinels in the expected places). When
comp_level != 0, this function checks for the 16-byte chunk
magic at the 56-byte-header position first and only falls back to
the genuinely-compressed path if it's actually there -- otherwise
it decodes the blob exactly like a DB_COMP_NONE one.
Source code in pygdb/gdb_reader.py
1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 | |
.grd reader¶
pygdb.read_grd(path)
¶
Read a .grd file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
Path to the |
required |
Returns:
| Name | Type | Description |
|---|---|---|
header |
GrdHeader
|
The parsed 512-byte header. |
values |
array
|
The grid's raw (unscaled) element values in on-disk order
(row-major per the file's own |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Warns:
| Type | Description |
|---|---|
GRDParseWarning
|
If a compressed block is truncated or fails to decompress
(see |
Source code in pygdb/grd_reader.py
pygdb.GrdHeader(n_bytes_per_element, sign_flag, shape_e, shape_v, ordering, spacing_e, spacing_v, x_origin, y_origin, rotation, base_value, data_factor, raw)
dataclass
¶
element_size
property
¶
Bytes per element, with the +1024 compressed marker stripped.
Registry¶
pygdb.find_coordinate_systems(path, max_real_line_slot=None)
¶
Scan path for coordinate-system (map projection) names.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
Path to the |
required |
max_real_line_slot
|
int
|
The highest physical line-table slot index that corresponds to
a real survey line -- blobs whose |
None
|
Returns:
| Type | Description |
|---|---|
list of str
|
A de-duplicated, order-of-discovery list of name strings (e.g.
|
Warns:
| Type | Description |
|---|---|
GDBParseWarning
|
If |
Source code in pygdb/registry.py
pygdb.find_channel_roles(path, max_real_line_slot=None, channel_names=None)
¶
Scan path for which real channel plays the X/Y/Z coordinate role.
Reads the file's own internal registry (docs/provenance/notes.md
section 6.8b) -- a directly-decodable alternative to guessing from
channel-naming conventions ("Easting"/"Northing" and similar
aren't consistent enough across real files to guess safely; see
gdb.GDB.to_xarray's docstring for why this reader avoids that
kind of guess elsewhere too).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
Path to the |
required |
max_real_line_slot
|
int
|
See |
None
|
channel_names
|
iterable of str
|
The file's own real channel names, used to validate each
candidate registry value (see Notes). If not given, this calls
|
None
|
Returns:
| Type | Description |
|---|---|
dict of {str : str or None}
|
|
Warns:
| Type | Description |
|---|---|
GDBParseWarning
|
If |
Notes
A real complication, found by testing (section 6.8b): this
format's append-only blob storage can leave multiple, differing
stale copies of the same registry key in one file when a role gets
re-registered (confirmed on 2 of 22 real files) -- and neither
"prefer the first occurrence" nor "prefer the last" resolves both
real cases correctly (one needs each). The robust rule used here
instead: collect every candidate value found for a role, and keep
whichever one(s) actually name a real, current channel (checked
against channel_names) -- a direct cross-check against data this
reader already parses, not a positional guess.
Source code in pygdb/registry.py
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 | |
pygdb.find_channel_settings(path, channels=None)
¶
Scan path for real per-channel settings recorded in its REG registry.
Reads the same "REG "-tagged administrative-blob content
find_coordinate_systems/find_channel_roles already scan, but
decodes its flat key/value framing directly (docs/provenance/notes.md
section 6.8c) instead of searching for one specific marker -- so this
surfaces whatever real settings a channel's REG entries happen to
carry: real per-channel display units (UNITS), real user-entered
processing labels (LABEL), real processing formulas (FORMULA),
among others (docs/spec.md section 9 has the cross-validated evidence
for what these keys mean in practice).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
Path to the |
required |
channels
|
iterable of ChannelRecord
|
The file's own real channel table, used to resolve the channel
slot an object's symbol name points at to a real channel name
(see Notes). If not given, this calls |
None
|
Returns:
| Type | Description |
|---|---|
dict of {str : dict of {str : str}}
|
|
Warns:
| Type | Description |
|---|---|
GDBParseWarning
|
If |
Notes
Only an object's KEY\0value\0 entries are decoded (see
_decode_reg_flat_keyvalues). Its nested objects -- in practice a
MAKER record naming the GX that made the channel (docs/spec.md
section 9) -- are not. Which keys are meaningful for a given channel
is not itself decoded from anything -- only the keys a real file
happens to have written are returned.
Which channel an object belongs to comes from its blob symbol
(docs/spec.md section 2.1, docs/provenance/notes.md section 6.2d):
the administrative blob at blob_index = data_slots + k is named by
blob-symbol slot k, and a per-channel REG object is named
"__<n>", where n is the channel's global symbol handle,
blobs_max + lines_max + channel_slot. [CONFIRMED]: where an
object's LABEL equals a real channel's name, this mapping names
that channel on 218 corpus objects. The blob index's own remainder
(blob_index % chans_max), which an earlier version of this
function used, named it on none. An object whose handle is not a
channel's -- a line handle (real, 744 corpus objects, meaning
[UNKNOWN]) or any other name -- is skipped.
This format's append-only storage can leave stale, differing copies
of the same object (the same phenomenon find_channel_roles handles
for DB_CHAN_X/Y/Z and issue #2's data blobs) -- every occurrence
found is collapsed per key, last one in blob-chain order wins, with
a warning only when two real occurrences actually disagree.
Source code in pygdb/registry.py
364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 | |
pygdb.find_projection_parameters(path, max_real_line_slot=None)
¶
Scan path for real geodetic parameters recorded in its IPJ registry.
Reads the same IPJ-tagged administrative-blob content
find_coordinate_systems already scans for a name, but decodes the
object's fixed-offset binary record directly (docs/provenance/
notes.md section 6.7b) instead of stopping at the name -- real datum,
ellipsoid, and projection parameters, cross-validated against
independent ground truth on real files (docs/spec.md section 8).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
Path to the |
required |
max_real_line_slot
|
int
|
See |
None
|
Returns:
| Type | Description |
|---|---|
dict of {str : ProjectionParameters}
|
Keyed by the same working coordinate-system name
|
Warns:
| Type | Description |
|---|---|
GDBParseWarning
|
If |
Notes
A candidate blob is only decoded if it has the confirmed IPJ
object shape: the type-code field reading b"IPJ\x00", at least
652 bytes (through the last parameter slot), and the " JPI"
marker's own tag also present at its fixed +96 position -- a
structural gate before trusting the fixed-offset fields, matching
the validation find_channel_settings applies to REG objects.
Anything else is silently skipped, not warned about.
Source code in pygdb/registry.py
855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 | |
pygdb.ProjectionParameters(name, datum_name, ellipsoid_name, datum_transform_name, semi_major_axis, eccentricity, central_meridian, scale_factor, false_easting, false_northing, method_code=None, latitude_of_origin=None, standard_parallel_1=None, standard_parallel_2=None, parameters=(), method=None, method_parameters=dict(), parameter_source=None, prime_meridian=None, datum_transform_parameters=None, units_name=None, units_factor=None, projection_name=None)
dataclass
¶
Real geodetic parameters decoded from one IPJ registry object.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
The working coordinate-system name (the same string
|
datum_name |
str
|
E.g. |
ellipsoid_name |
str
|
E.g. |
datum_transform_name |
str or None
|
E.g. |
semi_major_axis |
float
|
The ellipsoid's semi-major axis, in metres. |
eccentricity |
float
|
The ellipsoid's eccentricity. |
central_meridian, scale_factor, false_easting, false_northing |
float or None
|
The projection's own parameters. |
method_code |
int or None
|
The projection-method code at |
latitude_of_origin |
float or None
|
Transverse Mercator or Lambert latitude of origin; for Polar Stereographic, the latitude in the same slot, which the source survey's own metadata calls the standard parallel. |
standard_parallel_1, standard_parallel_2 |
float or None
|
Lambert Conic Conformal (2SP) standard parallels. |
parameters |
tuple of (float or None)
|
All eight raw parameter slots ( |
method |
str or None
|
The projection method's GXF name, e.g. |
method_parameters |
dict of {str : float or None}
|
The method's parameters keyed by their GXF Table 1 names
(lowercased, underscores), e.g. |
parameter_source |
{'text', 'binary'} or None
|
Where the names in |
prime_meridian |
float or None
|
Degrees from Greenwich. |
datum_transform_parameters |
tuple of float or None
|
The 7-parameter Bursa-Wolf datum transform to WGS 84, in GXF
units: dX, dY, dZ in metres, Rx, Ry, Rz in arc-seconds, scale in
ppm. All zero for a datum that is already WGS 84. |
units_name |
str or None
|
The coordinate units, e.g. |
units_factor |
float or None
|
The units' factor to metres. |
projection_name |
str or None
|
The projection's name without its datum, e.g. |
Notes
[CONFIRMED] structure and slot positions for the method codes
above (docs/spec.md section 8, docs/provenance/notes.md section
6.7b), each against the file's own _PJ_PROJECTION text, with the
slot names from Geosoft's GXF Revision 3 specification, Table 1. The
on-disk value of an unset parameter is the vendor's float64 rDUMMY
sentinel (-1.0e32, docs/spec.md section 4), mapped to None here
rather than returned as a raw dummy a caller could mistake for a real
coordinate -- this reader's own convention.
Methods without a known code. A registry's _PJ_PROJECTION text
("Method name",p1,p2,...) lists a method's parameters in GXF Table 1
order, leaving out the unused ones; the binary keeps those as unset
slots. So the text names the binary's set slots, in order, for any
method in Table 1. The text is used only when its values equal the
binary's set slots exactly (43 of 43 corpus objects with text) --
the values returned are always the binary's. Text whose method
isn't in Table 1, or has a different parameter count, gives method
but no names.
The existing named fields (central_meridian, scale_factor,
false_easting, false_northing, latitude_of_origin,
standard_parallel_1, standard_parallel_2) are filled only for
the method codes with a confirmed slot layout, as before.
pygdb.find_channel_makers(path, channels=None)
¶
Scan path for how each channel was made.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
Path to the |
required |
channels
|
iterable of ChannelRecord
|
The file's channel table, used to resolve each record's owning
channel handle to a name. If not given, this calls
|
None
|
Returns:
| Type | Description |
|---|---|
dict of {str : ChannelMaker}
|
|
Warns:
| Type | Description |
|---|---|
GDBParseWarning
|
If |
Notes
Attribution follows find_channel_settings: the record is owned by
the channel named by its object's blob-symbol handle (docs/spec.md
section 2.1). Every copy of the object in the chain is read, since a
rewritten object can leave its MAKER record only in an older copy
of itself; differing copies are warned about, never merged.
Source code in pygdb/registry.py
1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 | |
pygdb.ChannelMaker(tool, label, parameters)
dataclass
¶
How a channel was made: one MAKER record from the file's registry.
Attributes:
| Name | Type | Description |
|---|---|---|
tool |
str
|
The tool that created the channel, as the file records it -- a GX
name ( |
label |
str
|
The tool's human-readable name ( |
parameters |
dict of {str : str}
|
The tool's parameters, |
Notes
[CONFIRMED] layout on all 305 corpus records (docs/spec.md section 9, docs/provenance/notes.md section 6.8c). Values are returned as the text the file stores; their meaning is the tool's, not decoded here.
pygdb.find_display_lists(path, channels=None)
¶
Read the file's Display List objects.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
Path to the |
required |
channels
|
iterable of ChannelRecord
|
The file's channel table, used to resolve each entry's handle to
the channel's current name. If not given, this calls
|
None
|
Returns:
| Type | Description |
|---|---|
list of list of DisplayListEntry
|
One list per live |
Warns:
| Type | Description |
|---|---|
GDBParseWarning
|
If |
Notes
[CONFIRMED] layout on all 48 corpus instances (docs/spec.md
section 9): a VV of fixed-width strings (82 or 130 bytes), each
name\0handle\0. [LIKELY] meaning: the channels shown in the
database's spreadsheet view. The live copy of each object comes from
the blob directory (docs/spec.md section 2.2).
Source code in pygdb/registry.py
1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 | |
pygdb.DisplayListEntry(label, handle, channel)
dataclass
¶
One entry of a Display List object.
Attributes:
| Name | Type | Description |
|---|---|---|
label |
str
|
The channel name stored in the list. A cached label: a channel renamed after it was added keeps its old name here. |
handle |
int
|
The channel's global symbol handle, which identifies it. |
channel |
str or None
|
The channel's current name, resolved from |
Warnings and errors¶
pygdb.GDBParseWarning
¶
Bases: RuntimeWarning
Warned whenever this reader hits a blob, chunk, or record it can't parse.
Covers an unexpected byte sequence, a file that ends prematurely
(truncated download, or a blob chain that runs past EOF), an
administrative-blob variant it doesn't recognize, or anything else
that doesn't fit the confirmed structure. This reader is designed
to degrade gracefully rather than hard-crash on this whole class
of problem: functions return whatever they successfully decoded up
to the point of trouble (a shorter-than-expected list, an empty
list, or in the worst case an empty result) instead of raising,
and a GDBParseWarning describing what couldn't be decoded and
why is always issued alongside, so a caller can tell a clean,
complete result from a partial one and go investigate.
Notes
See docs/provenance/notes.md's "reader robustness" notes for the design rationale (an explicit engineering request, not new format research).
This does not apply to a handful of genuine precondition failures
that aren't "this file has an interesting anomaly" (e.g. calling
read_blob_values with a channel/blob pair that can't
possibly match) -- those still raise normally.
pygdb.GDBUnseenFeatureWarning
¶
Bases: UserWarning
Warned when a file has a format feature this reader has never seen.
Nothing is wrong with the file, and the data is read normally. The
notice gives the exact values seen and asks the user to run
unseen_feature_report and post its output on the project's issue
tracker, which helps finish the format specification. Each feature is
reported at most once per file per process.
Notes
Deliberately not a GDBParseWarning: that one means something could
not be decoded. To turn these notices off, either filter the warning::
import warnings
import pygdb
warnings.simplefilter("ignore", pygdb.GDBUnseenFeatureWarning)
or set the environment variable PYGDB_UNSEEN_FEATURE_NOTICES=0,
which also skips the checks that run when a file is opened.
pygdb.unseen_feature_report(path)
¶
Describe every format feature in path that this reader has never seen.
This is what a GDBUnseenFeatureWarning asks you to run and post. It
returns nothing about the data in your file -- only about how the
file is laid out. But don't take our word for it: check the source
code for yourself! It's this function and the _find_* checks above
it, in pygdb/unseen.py.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
Path to the |
required |
Returns:
| Type | Description |
|---|---|
str
|
A plain-text report, ready to paste into the issue form. It never contains the file's path or name. With nothing unusual found, it says so. |
Notes
Every check runs again, whatever notices were already shown, and no
notice is issued while it does. It runs even when
PYGDB_UNSEEN_FEATURE_NOTICES=0. What each feature adds beyond its
one-line evidence:
- header words: the 128-byte header (table sizes, counts, page numbers);
- channel
+108/+116: each flagged channel's 128-byte record (name, type, format, display and array widths); - user table: nothing, since user records hold user names and paths;
- line type or line block: each flagged line's 128-byte record (name, category, date, number, flight, type, version);
- projection method or slot 7: the projection record,
+104..+652(coordinate-system, datum, ellipsoid, transform, units and projection names; the method code; the parameters); - projection object member: each member's length;
MAKERfield: the tool's name, never its parameters;- extension-object list: its payload, up to 512 bytes.
GDBParseWarnings raised while the file is read are left alone.
Examples:
Source code in pygdb/unseen.py
400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 | |
pygdb.GRDParseWarning
¶
Bases: RuntimeWarning
Warned on a truncated file or a compressed block that fails to decompress.
See gdb_reader.GDBParseWarning for the same design rationale
applied here: return whatever grid data was successfully decoded
(padded with the header's own dummy value for the missing tail, so
the array shape still matches shape_e * shape_v) rather than
raising and discarding a whole grid over one bad/missing block.
pygdb.LZRW1DecodeError
¶
Bases: Exception
Raised when a Speed-mode chunk can't be decoded.
Raised by decode_speed_chunk/parse_chunk_header for
truncated/corrupt data, or a subtype/marker this module doesn't
recognize. A single, deliberately narrow exception type (rather
than a bare AssertionError/IndexError/struct.error
grab-bag) so callers -- notably gdb_reader.read_blob_values --
can catch exactly this and fail gracefully (return whatever was
already decoded elsewhere, emit a clear warning) instead of
crashing.
Notes
See docs/provenance/notes.md's "reader robustness" notes for the design rationale; this reader is not meant to hard-crash on a truncated download or an unrecognized real-world variant, per an explicit engineering request from the coordinator.