Skip to content

Commit

Permalink
Allow import/export completely custom SEG-Y via spec override environ…
Browse files Browse the repository at this point in the history
…ment variable (#440)

* Add environment variable for SEG-Y text header encoding (#439)

* Update segy dependency to version 0.2.2

Upgraded segy from version 0.2.0 to 0.2.2 in pyproject.toml.

* allow full spec override via json env var.
  • Loading branch information
tasansal authored Sep 26, 2024
1 parent 5abb0f7 commit a663aca
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 12 deletions.
20 changes: 10 additions & 10 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ dask = ">=2024.6.1"
tqdm = "^4.66.4"
psutil = "^6.0.0"
fsspec = ">=2024.9.0"
segy = "^0.2.0"
segy = "^0.2.2"
rich = "^13.7.1"
urllib3 = "^1.26.18" # Workaround for poetry-plugin-export/issues/183

Expand Down
8 changes: 7 additions & 1 deletion src/mdio/segy/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

from __future__ import annotations

import os
from importlib import metadata

from segy.alias.segyio import SEGYIO_BIN_FIELD_MAP
Expand Down Expand Up @@ -57,14 +58,19 @@ def get_trace_fields(version: str) -> list[HeaderField]:

def mdio_segy_spec(version: str | None = None) -> SegySpec:
"""Get a SEG-Y encoding spec for MDIO based on version."""
spec_override = os.getenv("MDIO__SEGY__SPEC")

if spec_override is not None:
return SegySpec.model_validate_json(spec_override)

version = MDIO_VERSION if version is None else version

binary_fields = get_binary_fields()
trace_fields = get_trace_fields(version)

return SegySpec(
segy_standard=None,
text_header=TextHeaderSpec(), # default EBCDIC
text_header=TextHeaderSpec(),
binary_header=HeaderSpec(fields=binary_fields, item_size=400, offset=3200),
trace=TraceSpec(
header=HeaderSpec(fields=trace_fields, item_size=240),
Expand Down

0 comments on commit a663aca

Please sign in to comment.