Skip to content

Commit 2d6e250

Browse files
committed
Fir createdOn in create_empty_like
1 parent d974125 commit 2d6e250

File tree

2 files changed

+17
-15
lines changed

2 files changed

+17
-15
lines changed

src/mdio/api/create.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ def create_empty_like( # noqa PLR0913
126126
# Keep the name (which is the same as the used template name) and the original API version
127127
# ds_output.attrs["name"]
128128
# ds_output.attrs["apiVersion"]
129-
ds_output.attrs["createdOn"] = datetime.now(UTC)
129+
ds_output.attrs["createdOn"] = str(datetime.now(UTC))
130130

131131
# Coordinates
132132
if not keep_coordinates:

tests/integration/test_z_create_empty.py

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
This set of tests has to run after the segy_roundtrip_teapot tests have run because
44
the teapot dataset is used as the input for the create_empty_like test.
55
6-
NOTE: The only reliable way to ensure the test order (including the case when the
6+
NOTE: The only reliable way to ensure the test order (including the case when the
77
test are run in parallel) is to use the alphabetical order of the test names.
88
"""
99

@@ -29,11 +29,15 @@
2929
from xarray import Dataset as xr_Dataset
3030

3131

32-
from tests.integration.testing_helpers import UNITS_NONE, UNITS_SECOND, UNITS_METER, UNITS_FOOT, UNITS_METER_PER_SECOND, UNITS_FEET_PER_SECOND
32+
from tests.integration.testing_helpers import UNITS_FEET_PER_SECOND
33+
from tests.integration.testing_helpers import UNITS_FOOT
34+
from tests.integration.testing_helpers import UNITS_METER
35+
from tests.integration.testing_helpers import UNITS_METER_PER_SECOND
36+
from tests.integration.testing_helpers import UNITS_NONE
37+
from tests.integration.testing_helpers import UNITS_SECOND
3338
from tests.integration.testing_helpers import get_teapot_segy_spec
34-
from tests.integration.testing_helpers import validate_xr_variable
3539
from tests.integration.testing_helpers import get_values
36-
40+
from tests.integration.testing_helpers import validate_xr_variable
3741

3842
from mdio import __version__
3943
from mdio.api.create import create_empty
@@ -46,6 +50,7 @@
4650
from mdio.converters.mdio import mdio_to_segy
4751
from mdio.core import Dimension
4852

53+
4954
class PostStack3DVelocityTemplate(Seismic3DPostStackTemplate):
5055
"""Custom template that uses 'velocity' as the default variable name instead of 'amplitude'."""
5156

@@ -81,6 +86,7 @@ def _name(self) -> str:
8186
domain_suffix = self._data_domain.capitalize()
8287
return f"PostStack3DVelocity{domain_suffix}"
8388

89+
8490
class TestCreateEmptyMdio:
8591
"""Tests for create_empty_mdio function."""
8692

@@ -146,7 +152,9 @@ def validate_teapod_dataset_metadata(cls, ds: xr_Dataset, is_velocity: bool) ->
146152
assert attributes["gatherType"] == "stacked"
147153

148154
@classmethod
149-
def validate_teapod_dataset_variables(cls, ds: xr_Dataset, header_dtype: np.dtype | None, is_velocity: bool) -> None:
155+
def validate_teapod_dataset_variables(
156+
cls, ds: xr_Dataset, header_dtype: np.dtype | None, is_velocity: bool
157+
) -> None:
150158
"""Validate an empty MDIO dataset structure and content."""
151159
# Check that the dataset has the expected shape
152160
assert ds.sizes == {"inline": 345, "crossline": 188, "time": 1501}
@@ -209,16 +217,13 @@ def mdio_no_headers(self, empty_mdio_dir: Path) -> Path:
209217
self._create_empty_mdio(create_headers=False, output_path=empty_mdio)
210218
return empty_mdio
211219

212-
213220
def test_dataset_metadata(self, mdio_with_headers: Path) -> None:
214221
"""Test dataset metadata for empty MDIO file."""
215222
ds = open_mdio(mdio_with_headers)
216223
self.validate_teapod_dataset_metadata(ds, is_velocity=True)
217224

218-
219225
def test_variables(self, mdio_with_headers: Path, mdio_no_headers: Path) -> None:
220226
"""Test grid validation for empty MDIO file."""
221-
222227
ds = open_mdio(mdio_with_headers)
223228
header_dtype = get_teapot_segy_spec().trace.header.dtype
224229
self.validate_teapod_dataset_variables(ds, header_dtype=header_dtype, is_velocity=True)
@@ -381,18 +386,15 @@ def test_populate_empty_dataset(self, mdio_with_headers: Path) -> None:
381386
output_path=mdio_with_headers.parent / "populated_empty.sgy",
382387
)
383388

384-
385-
def test_create_empty_like(self, teapot_mdio_tmp: Path) -> None:
389+
def test_create_empty_like(self, teapot_mdio_tmp: Path, empty_mdio_dir: Path) -> None:
386390
"""Create an empty MDIO file like the input MDIO file.
387-
391+
388392
This test has to run after the segy_roundtrip_teapot tests have run because
389393
its uses 'teapot_mdio_tmp' created by the segy_roundtrip_teapot tests as the input.
390394
"""
391-
392395
ds = create_empty_like(
393396
input_path=teapot_mdio_tmp,
394-
# TODO: write to a file
395-
output_path=None, # We don't want to write to disk for now
397+
output_path=empty_mdio_dir / "create_empty_like.mdio",
396398
keep_coordinates=True,
397399
overwrite=True,
398400
)

0 commit comments

Comments
 (0)