Skip to content

Commit da473c8

Browse files
committed
Update dependency versions and clean up dataset template methods
- Bump `multidimio` version to `1.2.0rc0` and restrict `zarr` version to `>=3.1.3,<=3.1.6` for compatibility. - Remove the `include_raw_headers` parameter from dataset building methods in `DatasetFactory` and `AbstractDatasetTemplate`, simplifying the API. - Refactor coordinate specification methods in various dataset templates to ensure consistent usage of `CoordinateSpec` and improve code clarity. - Introduce a new function `maybe_add_raw_headers` to conditionally append raw headers to datasets based on experimental settings, enhancing the ingestion pipeline's flexibility.
1 parent 9297d1f commit da473c8

17 files changed

Lines changed: 69 additions & 77 deletions

src/mdio/builder/templates/base.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@
2020
from mdio.core.utils_write import MAX_COORDINATES_BYTES
2121
from mdio.core.utils_write import MAX_SIZE_LIVE_MASK
2222
from mdio.core.utils_write import get_constrained_chunksize
23+
from mdio.ingestion.schema_resolver import CoordinateSpec
2324

2425
if TYPE_CHECKING:
2526
from mdio.builder.schemas.v1.dataset import Dataset
2627
from mdio.builder.templates.types import SeismicDataDomain
27-
from mdio.ingestion.schema_resolver import CoordinateSpec
2828

2929

3030
class AbstractDatasetTemplate(ABC):
@@ -73,8 +73,6 @@ def _repr_html_(self) -> str:
7373

7474
def declare_coordinate_specs(self) -> tuple[CoordinateSpec, ...]:
7575
"""Return the non-dimension coordinate specs (name, dims, dtype) for this template."""
76-
from mdio.ingestion.schema_resolver import CoordinateSpec
77-
7876
specs = [
7977
CoordinateSpec(
8078
name=coord_name,
@@ -98,16 +96,13 @@ def build_dataset(
9896
name: str,
9997
sizes: tuple[int, ...],
10098
header_dtype: StructuredType = None,
101-
include_raw_headers: bool = False,
10299
) -> Dataset:
103100
"""Template method that builds the dataset.
104101
105102
Args:
106103
name: The name of the dataset.
107104
sizes: The sizes of the dimensions.
108105
header_dtype: Optional structured headers for the dataset.
109-
include_raw_headers: Whether to include raw binary headers variable. Only supported
110-
in Zarr v3 format. Defaults to False.
111106
112107
Returns:
113108
Dataset: The constructed dataset
@@ -125,9 +120,6 @@ def build_dataset(
125120
if header_dtype is not None:
126121
self._add_trace_headers(header_dtype)
127122

128-
if include_raw_headers:
129-
self._add_raw_headers()
130-
131123
return self._builder.build()
132124

133125
def add_units(self, units: dict[str, AllUnitModel]) -> None:

src/mdio/builder/templates/seismic_2d_cdp.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from mdio.builder.templates.types import SeismicDataDomain
1414
from mdio.core.utils_write import MAX_COORDINATES_BYTES
1515
from mdio.core.utils_write import get_constrained_chunksize
16+
from mdio.ingestion.schema_resolver import CoordinateSpec
1617

1718

1819
class Seismic2DCdpGathersTemplate(AbstractDatasetTemplate):
@@ -39,9 +40,8 @@ def _name(self) -> str:
3940
def _load_dataset_attributes(self) -> dict[str, Any]:
4041
return {"surveyType": "2D", "gatherType": "cdp"}
4142

42-
def declare_coordinate_specs(self) -> tuple[Any, ...]:
43-
from mdio.ingestion.schema_resolver import CoordinateSpec
44-
43+
def declare_coordinate_specs(self) -> tuple[CoordinateSpec, ...]:
44+
"""Declare CDP-indexed X/Y coordinates for the 2D CDP gathers template."""
4545
return (
4646
CoordinateSpec(name="cdp_x", dimensions=("cdp",), dtype=ScalarType.FLOAT64),
4747
CoordinateSpec(name="cdp_y", dimensions=("cdp",), dtype=ScalarType.FLOAT64),

src/mdio/builder/templates/seismic_3d_cdp.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from mdio.builder.templates.types import SeismicDataDomain
1414
from mdio.core.utils_write import MAX_COORDINATES_BYTES
1515
from mdio.core.utils_write import get_constrained_chunksize
16+
from mdio.ingestion.schema_resolver import CoordinateSpec
1617

1718

1819
class Seismic3DCdpGathersTemplate(AbstractDatasetTemplate):
@@ -39,9 +40,8 @@ def _name(self) -> str:
3940
def _load_dataset_attributes(self) -> dict[str, Any]:
4041
return {"surveyType": "3D", "gatherType": "cdp"}
4142

42-
def declare_coordinate_specs(self) -> tuple[Any, ...]:
43-
from mdio.ingestion.schema_resolver import CoordinateSpec
44-
43+
def declare_coordinate_specs(self) -> tuple[CoordinateSpec, ...]:
44+
"""Declare inline/crossline-indexed X/Y coordinates for the 3D CDP gathers template."""
4545
return (
4646
CoordinateSpec(name="cdp_x", dimensions=("inline", "crossline"), dtype=ScalarType.FLOAT64),
4747
CoordinateSpec(name="cdp_y", dimensions=("inline", "crossline"), dtype=ScalarType.FLOAT64),

src/mdio/builder/templates/seismic_3d_coca.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from mdio.builder.templates.types import SeismicDataDomain
1212
from mdio.core.utils_write import MAX_COORDINATES_BYTES
1313
from mdio.core.utils_write import get_constrained_chunksize
14+
from mdio.ingestion.schema_resolver import CoordinateSpec
1415

1516

1617
class Seismic3DCocaGathersTemplate(AbstractDatasetTemplate):
@@ -30,9 +31,8 @@ def _name(self) -> str:
3031
def _load_dataset_attributes(self) -> dict[str, Any]:
3132
return {"surveyType": "3D", "gatherType": "common_offset_common_azimuth"}
3233

33-
def declare_coordinate_specs(self) -> tuple[Any, ...]:
34-
from mdio.ingestion.schema_resolver import CoordinateSpec
35-
34+
def declare_coordinate_specs(self) -> tuple[CoordinateSpec, ...]:
35+
"""Declare inline/crossline-indexed X/Y coordinates for the 3D CoCA gathers template."""
3636
return (
3737
CoordinateSpec(name="cdp_x", dimensions=("inline", "crossline"), dtype=ScalarType.FLOAT64),
3838
CoordinateSpec(name="cdp_y", dimensions=("inline", "crossline"), dtype=ScalarType.FLOAT64),

src/mdio/builder/templates/seismic_3d_obn.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from mdio.builder.templates.types import SeismicDataDomain
1313
from mdio.core.utils_write import MAX_COORDINATES_BYTES
1414
from mdio.core.utils_write import get_constrained_chunksize
15+
from mdio.ingestion.schema_resolver import CoordinateSpec
1516

1617

1718
class Seismic3DObnReceiverGathersTemplate(AbstractDatasetTemplate):
@@ -56,9 +57,8 @@ def _name(self) -> str:
5657
def _load_dataset_attributes(self) -> dict[str, Any]:
5758
return {"surveyType": "3D", "gatherType": "common_receiver"}
5859

59-
def declare_coordinate_specs(self) -> tuple[Any, ...]:
60-
from mdio.ingestion.schema_resolver import CoordinateSpec
61-
60+
def declare_coordinate_specs(self) -> tuple[CoordinateSpec, ...]:
61+
"""Declare receiver- and shot-indexed coordinates for the 3D OBN receiver gathers template."""
6262
receiver_dim = ("receiver",)
6363
shot_dims = ("shot_line", "gun", "shot_index")
6464
return (

src/mdio/builder/templates/seismic_3d_streamer_field.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from mdio.builder.templates.types import SeismicDataDomain
1313
from mdio.core.utils_write import MAX_COORDINATES_BYTES
1414
from mdio.core.utils_write import get_constrained_chunksize
15+
from mdio.ingestion.schema_resolver import CoordinateSpec
1516

1617

1718
class Seismic3DStreamerFieldRecordsTemplate(AbstractDatasetTemplate):
@@ -44,9 +45,8 @@ def _name(self) -> str:
4445
def _load_dataset_attributes(self) -> dict[str, Any]:
4546
return {"surveyDimensionality": "3D", "gatherType": "common_source"}
4647

47-
def declare_coordinate_specs(self) -> tuple[Any, ...]:
48-
from mdio.ingestion.schema_resolver import CoordinateSpec
49-
48+
def declare_coordinate_specs(self) -> tuple[CoordinateSpec, ...]:
49+
"""Declare shot- and receiver-indexed coordinates for the 3D streamer field records template."""
5050
shot_dims = ("sail_line", "gun", "shot_index")
5151
receiver_dims = ("sail_line", "gun", "shot_index", "cable", "channel")
5252
return (
@@ -91,9 +91,7 @@ def _add_coordinates(self) -> None:
9191
# Chunk grids for shot-indexed (3D) and receiver-indexed (5D) non-dim coordinates.
9292
shot_chunk_shape = get_constrained_chunksize(self._dim_sizes[:3], ScalarType.FLOAT64, MAX_COORDINATES_BYTES)
9393
chunk_grid_3d = RegularChunkGrid(configuration=RegularChunkShape(chunk_shape=shot_chunk_shape))
94-
receiver_chunk_shape = get_constrained_chunksize(
95-
self._dim_sizes[:5], ScalarType.FLOAT64, MAX_COORDINATES_BYTES
96-
)
94+
receiver_chunk_shape = get_constrained_chunksize(self._dim_sizes[:5], ScalarType.FLOAT64, MAX_COORDINATES_BYTES)
9795
chunk_grid_5d = RegularChunkGrid(configuration=RegularChunkShape(chunk_shape=receiver_chunk_shape))
9896

9997
compressor = Blosc(cname=BloscCname.zstd)

src/mdio/ingestion/_raw_headers_experimental.py

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,21 @@
44
that removing the feature is a single-file delete plus the (small) handful of call
55
sites that import from here. The behaviour:
66
7-
* ``should_include_raw_headers()`` decides whether the ``raw_headers`` variable
8-
should be added to the dataset for this run. Honours the env-driven
9-
:class:`mdio.core.config.MDIOSettings` and the active Zarr format.
7+
* ``maybe_add_raw_headers()`` decides whether the ``raw_headers`` variable should
8+
be added to the dataset for this run, and if so appends it via the template's
9+
internal builder. Honours the env-driven :class:`mdio.core.config.MDIOSettings`
10+
and the active Zarr format.
1011
* ``attach_raw_binary_header()`` adds the base64-encoded binary file header to a
1112
segy_file_header attribute dict, if (and only if) the feature is enabled.
1213
1314
Removal plan
1415
------------
1516
Delete this module and:
1617
17-
#. Drop the call to :func:`should_include_raw_headers` in
18-
:mod:`mdio.ingestion.pipeline` (and the resulting ``include_raw_headers``
19-
kwarg threaded through :class:`~mdio.ingestion.dataset_factory.DatasetFactory`
20-
/ :meth:`AbstractDatasetTemplate.build_dataset` / ``_add_raw_headers``).
18+
#. Drop the call to :func:`maybe_add_raw_headers` in
19+
:mod:`mdio.ingestion.pipeline`.
20+
#. Drop the ``_add_raw_headers`` method on
21+
:class:`~mdio.builder.templates.base.AbstractDatasetTemplate`.
2122
#. Drop the call to :func:`attach_raw_binary_header` in
2223
:mod:`mdio.ingestion.metadata`.
2324
#. Drop ``MDIOSettings.raw_headers``.
@@ -37,10 +38,13 @@
3738
if TYPE_CHECKING:
3839
from typing import Any
3940

41+
from mdio.builder.schemas.v1.dataset import Dataset
42+
from mdio.builder.templates.base import AbstractDatasetTemplate
43+
4044
logger = logging.getLogger(__name__)
4145

4246

43-
def should_include_raw_headers() -> bool:
47+
def _should_include_raw_headers() -> bool:
4448
"""True iff the experimental flag is set and the active Zarr format supports it."""
4549
if not MDIOSettings().raw_headers:
4650
return False
@@ -51,6 +55,19 @@ def should_include_raw_headers() -> bool:
5155
return True
5256

5357

58+
def maybe_add_raw_headers(template: AbstractDatasetTemplate, dataset: Dataset) -> Dataset:
59+
"""Append the raw_headers variable to ``dataset`` if the experimental flag enables it.
60+
61+
The template's internal builder (still alive after ``build_dataset``) is reused
62+
so dimension resolution stays consistent. Returns the original dataset untouched
63+
when the feature is disabled.
64+
"""
65+
if not _should_include_raw_headers():
66+
return dataset
67+
template._add_raw_headers() # noqa: SLF001 - experimental seam, see removal plan above
68+
return template._builder.build() # noqa: SLF001
69+
70+
5471
def attach_raw_binary_header(attrs: dict[str, Any], raw_binary_headers: bytes) -> None:
5572
"""Attach a base64-encoded raw binary header to ``attrs`` if the feature is enabled."""
5673
if not MDIOSettings().raw_headers:

src/mdio/ingestion/dataset_factory.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ def build(
2929
schema: ResolvedSchema,
3030
dimensions: list[Dimension],
3131
header_dtype: StructuredType | None = None,
32-
include_raw_headers: bool = False,
3332
) -> Dataset:
3433
"""Build MDIO dataset from schema and dimensions.
3534
@@ -38,7 +37,6 @@ def build(
3837
schema: Resolved schema specifying dataset structure
3938
dimensions: List of dimension objects with coordinates
4039
header_dtype: Optional structured type for trace headers
41-
include_raw_headers: Whether to include raw binary headers (Zarr v3 only)
4240
4341
Returns:
4442
Complete Dataset ready for xarray conversion
@@ -51,5 +49,4 @@ def build(
5149
name=schema.name,
5250
sizes=sizes,
5351
header_dtype=header_dtype,
54-
include_raw_headers=include_raw_headers,
5552
)

src/mdio/ingestion/header_analysis.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,7 @@ def analyze_streamer_headers(
8888
geom_type = StreamerShotGeometryType.A
8989
logger.info("Found overlapping channels, assuming streamer type A")
9090
overlap_info = (
91-
"Cable %s index %s with channel range %s overlaps cable %s index %s with "
92-
"channel range %s."
91+
"Cable %s index %s with channel range %s overlaps cable %s index %s with channel range %s."
9392
)
9493
logger.info(overlap_info, cable1, idx1, cable1_range, cable2, idx2, cable2_range)
9594
return unique_cables, cable_chan_min, cable_chan_max, geom_type

src/mdio/ingestion/index_strategies.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -226,9 +226,7 @@ def __init__(self, line_field: str = "sail_line", always_calculate: bool = False
226226

227227
def transform_headers(self, headers: HeaderArray) -> HeaderArray:
228228
"""Create ``shot_index`` for multi-gun acquisition."""
229-
unique_lines, unique_guns_per_line, geom_type = analyze_lines_for_guns(
230-
headers, line_field=self.line_field
231-
)
229+
unique_lines, unique_guns_per_line, geom_type = analyze_lines_for_guns(headers, line_field=self.line_field)
232230

233231
logger.info("Ingesting dataset as shot type: %s (line_field=%s)", geom_type.name, self.line_field)
234232

@@ -369,9 +367,7 @@ def create_strategy(
369367

370368
if grid_overrides.auto_shot_wrap:
371369
line_field, always_calculate = self._resolve_shot_wrap_params(template)
372-
strategies.append(
373-
ShotWrappingStrategy(line_field=line_field, always_calculate=always_calculate)
374-
)
370+
strategies.append(ShotWrappingStrategy(line_field=line_field, always_calculate=always_calculate))
375371

376372
# NonBinned and HasDuplicates are mutually exclusive.
377373
if grid_overrides.non_binned:

0 commit comments

Comments
 (0)