Skip to content

Commit 04cce83

Browse files
committed
Update SEG-Y import for cloud native support and add test
1 parent 343e33d commit 04cce83

File tree

4 files changed

+36
-9
lines changed

4 files changed

+36
-9
lines changed

src/mdio/commands/segy.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666

6767

6868
@cli.command(name="import")
69-
@argument("segy-path", type=Path(exists=True))
69+
@argument("segy-path", type=STRING)
7070
@argument("mdio-path", type=STRING)
7171
@option(
7272
"-loc",

src/mdio/segy/_workers.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from __future__ import annotations
44

5+
import os
56
from typing import TYPE_CHECKING
67
from typing import Any
78

@@ -37,7 +38,14 @@ def header_scan_worker(
3738
Returns:
3839
HeaderArray parsed from SEG-Y library.
3940
"""
40-
return segy_file.header[slice(*trace_range)]
41+
slice_ = slice(*trace_range)
42+
43+
cloud_native_mode = os.getenv("MDIO__IMPORT__CLOUD_NATIVE", default="False")
44+
45+
if cloud_native_mode.lower() in {"true", "1"}:
46+
return segy_file.trace[slice_].header
47+
48+
return segy_file.header[slice_]
4149

4250

4351
def trace_worker(

tests/conftest.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,17 @@ def fake_segy_tmp(tmp_path_factory):
1414

1515

1616
@pytest.fixture(scope="session")
17-
def segy_input(tmp_path_factory):
17+
def segy_input_uri():
18+
"""Path to dome dataset for cloud testing."""
19+
return "http://s3.amazonaws.com/teapot/filt_mig.sgy"
20+
21+
22+
@pytest.fixture(scope="session")
23+
def segy_input(segy_input_uri, tmp_path_factory):
1824
"""Download teapot dome dataset for testing."""
19-
url = "http://s3.amazonaws.com/teapot/filt_mig.sgy"
2025
tmp_dir = tmp_path_factory.mktemp("segy")
2126
tmp_file = path.join(tmp_dir, "teapot.segy")
22-
urlretrieve(url, tmp_file) # noqa: S310
27+
urlretrieve(segy_input_uri, tmp_file) # noqa: S310
2328

2429
return tmp_file
2530

tests/test_main.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Test cases for the __main__ module."""
22

3+
import os
34
from pathlib import Path
45

56
import pytest
@@ -8,18 +9,31 @@
89
from mdio import __main__
910

1011

11-
@pytest.fixture()
12+
@pytest.fixture
1213
def runner() -> CliRunner:
1314
"""Fixture for invoking command-line interfaces."""
1415
return CliRunner()
1516

1617

17-
@pytest.mark.dependency()
18+
@pytest.mark.dependency
1819
def test_main_succeeds(runner: CliRunner, segy_input: str, zarr_tmp: Path) -> None:
1920
"""It exits with a status code of zero."""
2021
cli_args = ["segy", "import", segy_input, str(zarr_tmp)]
21-
cli_args.extend(["-loc", "181,185"])
22-
cli_args.extend(["-names", "inline,crossline"])
22+
cli_args.extend(["--header-locations", "181,185"])
23+
cli_args.extend(["--header-names", "inline,crossline"])
24+
25+
result = runner.invoke(__main__.main, args=cli_args)
26+
assert result.exit_code == 0
27+
28+
29+
@pytest.mark.dependency(depends=["test_main_succeeds"])
30+
def test_main_cloud(runner: CliRunner, segy_input_uri: str, zarr_tmp: Path) -> None:
31+
"""It exits with a status code of zero."""
32+
os.environ["MDIO__IMPORT__CLOUD_NATIVE"] = "true"
33+
cli_args = ["segy", "import", str(segy_input_uri), str(zarr_tmp)]
34+
cli_args.extend(["--header-locations", "181,185"])
35+
cli_args.extend(["--header-names", "inline,crossline"])
36+
cli_args.extend(["--overwrite"])
2337

2438
result = runner.invoke(__main__.main, args=cli_args)
2539
assert result.exit_code == 0

0 commit comments

Comments
 (0)