|
| 1 | +"""Unit tests for Seismic3DOffsetTilesTemplate.""" |
| 2 | + |
| 3 | +import pytest |
| 4 | +from tests.unit.v1.helpers import validate_variable |
| 5 | + |
| 6 | +from mdio.builder.schemas.chunk_grid import RegularChunkGrid |
| 7 | +from mdio.builder.schemas.compressors import Blosc |
| 8 | +from mdio.builder.schemas.compressors import BloscCname |
| 9 | +from mdio.builder.schemas.dtype import ScalarType |
| 10 | +from mdio.builder.schemas.dtype import StructuredType |
| 11 | +from mdio.builder.schemas.v1.dataset import Dataset |
| 12 | +from mdio.builder.schemas.v1.units import LengthUnitEnum |
| 13 | +from mdio.builder.schemas.v1.units import LengthUnitModel |
| 14 | +from mdio.builder.schemas.v1.units import TimeUnitEnum |
| 15 | +from mdio.builder.schemas.v1.units import TimeUnitModel |
| 16 | +from mdio.builder.templates.seismic_3d_offset_tiles import Seismic3DOffsetTilesTemplate |
| 17 | +from mdio.builder.templates.types import SeismicDataDomain |
| 18 | + |
| 19 | +UNITS_METER = LengthUnitModel(length=LengthUnitEnum.METER) |
| 20 | +UNITS_SECOND = TimeUnitModel(time=TimeUnitEnum.SECOND) |
| 21 | + |
| 22 | + |
| 23 | +def _validate_coordinates_headers_trace_mask(dataset: Dataset, headers: StructuredType, domain: str) -> None: |
| 24 | + """Validate the coordinate, headers, trace_mask variables in the dataset.""" |
| 25 | + # Verify variables |
| 26 | + # 5 dim coords + 2 non-dim coords + 1 data + 1 trace mask + 1 headers = 10 variables |
| 27 | + assert len(dataset.variables) == 10 |
| 28 | + |
| 29 | + # Verify trace headers |
| 30 | + validate_variable( |
| 31 | + dataset, |
| 32 | + name="headers", |
| 33 | + dims=[("inline", 256), ("crossline", 256), ("inline_offset_tile", 12), ("crossline_offset_tile", 12)], |
| 34 | + coords=["cdp_x", "cdp_y"], |
| 35 | + dtype=headers, |
| 36 | + ) |
| 37 | + |
| 38 | + validate_variable( |
| 39 | + dataset, |
| 40 | + name="trace_mask", |
| 41 | + dims=[("inline", 256), ("crossline", 256), ("inline_offset_tile", 12), ("crossline_offset_tile", 12)], |
| 42 | + coords=["cdp_x", "cdp_y"], |
| 43 | + dtype=ScalarType.BOOL, |
| 44 | + ) |
| 45 | + |
| 46 | + # Verify dimension coordinate variables |
| 47 | + validate_variable( |
| 48 | + dataset, |
| 49 | + name="inline", |
| 50 | + dims=[("inline", 256)], |
| 51 | + coords=["inline"], |
| 52 | + dtype=ScalarType.INT32, |
| 53 | + ) |
| 54 | + |
| 55 | + validate_variable( |
| 56 | + dataset, |
| 57 | + name="crossline", |
| 58 | + dims=[("crossline", 256)], |
| 59 | + coords=["crossline"], |
| 60 | + dtype=ScalarType.INT32, |
| 61 | + ) |
| 62 | + |
| 63 | + validate_variable( |
| 64 | + dataset, |
| 65 | + name="inline_offset_tile", |
| 66 | + dims=[("inline_offset_tile", 12)], |
| 67 | + coords=["inline_offset_tile"], |
| 68 | + dtype=ScalarType.INT16, |
| 69 | + ) |
| 70 | + |
| 71 | + validate_variable( |
| 72 | + dataset, |
| 73 | + name="crossline_offset_tile", |
| 74 | + dims=[("crossline_offset_tile", 12)], |
| 75 | + coords=["crossline_offset_tile"], |
| 76 | + dtype=ScalarType.INT16, |
| 77 | + ) |
| 78 | + |
| 79 | + domain_var = validate_variable( |
| 80 | + dataset, |
| 81 | + name=domain, |
| 82 | + dims=[(domain, 2048)], |
| 83 | + coords=[domain], |
| 84 | + dtype=ScalarType.INT32, |
| 85 | + ) |
| 86 | + assert domain_var.metadata.units_v1 in (UNITS_METER, UNITS_SECOND) |
| 87 | + |
| 88 | + # Verify non-dimension coordinate variables |
| 89 | + cdp_x = validate_variable( |
| 90 | + dataset, |
| 91 | + name="cdp_x", |
| 92 | + dims=[("inline", 256), ("crossline", 256)], |
| 93 | + coords=["cdp_x"], |
| 94 | + dtype=ScalarType.FLOAT64, |
| 95 | + ) |
| 96 | + assert cdp_x.metadata.units_v1 == UNITS_METER |
| 97 | + |
| 98 | + cdp_y = validate_variable( |
| 99 | + dataset, |
| 100 | + name="cdp_y", |
| 101 | + dims=[("inline", 256), ("crossline", 256)], |
| 102 | + coords=["cdp_y"], |
| 103 | + dtype=ScalarType.FLOAT64, |
| 104 | + ) |
| 105 | + assert cdp_y.metadata.units_v1 == UNITS_METER |
| 106 | + |
| 107 | + |
| 108 | +@pytest.mark.parametrize("data_domain", ["depth", "time"]) |
| 109 | +class TestSeismic3DOffsetTilesTemplate: |
| 110 | + """Unit tests for Seismic3DOffsetTilesTemplate.""" |
| 111 | + |
| 112 | + def test_configuration(self, data_domain: SeismicDataDomain) -> None: |
| 113 | + """Unit tests for Seismic3DOffsetTilesTemplate configuration.""" |
| 114 | + t = Seismic3DOffsetTilesTemplate(data_domain=data_domain) |
| 115 | + |
| 116 | + # Template attributes |
| 117 | + assert t._dim_names == ("inline", "crossline", "inline_offset_tile", "crossline_offset_tile", data_domain) |
| 118 | + assert t._physical_coord_names == ("cdp_x", "cdp_y") |
| 119 | + assert t._logical_coord_names == () |
| 120 | + assert t.full_chunk_shape == (4, 4, 6, 6, 4096) |
| 121 | + |
| 122 | + # Variables instantiated when build_dataset() is called |
| 123 | + assert t._builder is None |
| 124 | + assert t._dim_sizes == () |
| 125 | + |
| 126 | + # Verify dataset attributes |
| 127 | + attrs = t._load_dataset_attributes() |
| 128 | + assert attrs == {"surveyType": "3D", "gatherType": "offset_tiles"} |
| 129 | + assert t.default_variable_name == "amplitude" |
| 130 | + |
| 131 | + def test_build_dataset(self, data_domain: SeismicDataDomain, structured_headers: StructuredType) -> None: |
| 132 | + """Unit tests for Seismic3DOffsetTilesTemplate build.""" |
| 133 | + t = Seismic3DOffsetTilesTemplate(data_domain=data_domain) |
| 134 | + t.add_units({"cdp_x": UNITS_METER, "cdp_y": UNITS_METER}) |
| 135 | + t.add_units({"time": UNITS_SECOND, "depth": UNITS_METER}) |
| 136 | + |
| 137 | + dataset = t.build_dataset( |
| 138 | + "Wide Azimuth Offset Tiles", |
| 139 | + sizes=(256, 256, 12, 12, 2048), |
| 140 | + header_dtype=structured_headers, |
| 141 | + ) |
| 142 | + |
| 143 | + assert dataset.metadata.name == "Wide Azimuth Offset Tiles" |
| 144 | + assert dataset.metadata.attributes["surveyType"] == "3D" |
| 145 | + assert dataset.metadata.attributes["gatherType"] == "offset_tiles" |
| 146 | + |
| 147 | + _validate_coordinates_headers_trace_mask(dataset, structured_headers, data_domain) |
| 148 | + |
| 149 | + # Verify seismic variable |
| 150 | + seismic = validate_variable( |
| 151 | + dataset, |
| 152 | + name="amplitude", |
| 153 | + dims=[ |
| 154 | + ("inline", 256), |
| 155 | + ("crossline", 256), |
| 156 | + ("inline_offset_tile", 12), |
| 157 | + ("crossline_offset_tile", 12), |
| 158 | + (data_domain, 2048), |
| 159 | + ], |
| 160 | + coords=["cdp_x", "cdp_y"], |
| 161 | + dtype=ScalarType.FLOAT32, |
| 162 | + ) |
| 163 | + assert isinstance(seismic.compressor, Blosc) |
| 164 | + assert seismic.compressor.cname == BloscCname.zstd |
| 165 | + assert isinstance(seismic.metadata.chunk_grid, RegularChunkGrid) |
| 166 | + assert seismic.metadata.chunk_grid.configuration.chunk_shape == (4, 4, 6, 6, 4096) |
| 167 | + assert seismic.metadata.stats_v1 is None |
| 168 | + |
| 169 | + |
| 170 | +@pytest.mark.parametrize("data_domain", ["Time", "DePTh"]) |
| 171 | +def test_domain_case_handling(data_domain: str) -> None: |
| 172 | + """Test that domain parameter handles different cases correctly.""" |
| 173 | + template = Seismic3DOffsetTilesTemplate(data_domain=data_domain) |
| 174 | + assert template._data_domain == data_domain.lower() |
| 175 | + |
| 176 | + data_domain_suffix = data_domain.lower().capitalize() |
| 177 | + assert template.name == f"OffsetTiles3D{data_domain_suffix}" |
0 commit comments