Skip to content

Commit fb910e7

Browse files
committed
Linting
1 parent cdf9c6f commit fb910e7

File tree

2 files changed

+19
-16
lines changed

2 files changed

+19
-16
lines changed

src/mdio/converters/segy.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,20 @@
1414

1515
from mdio.api.io import _normalize_path
1616
from mdio.api.io import to_mdio
17+
from mdio.builder.schemas.chunk_grid import RegularChunkGrid
18+
from mdio.builder.schemas.chunk_grid import RegularChunkShape
19+
from mdio.builder.schemas.compressors import Blosc
20+
from mdio.builder.schemas.compressors import BloscCname
21+
from mdio.builder.schemas.dtype import ScalarType
1722
from mdio.builder.schemas.v1.units import LengthUnitEnum
1823
from mdio.builder.schemas.v1.units import LengthUnitModel
24+
from mdio.builder.schemas.v1.variable import VariableMetadata
1925
from mdio.builder.xarray_builder import to_xarray_dataset
2026
from mdio.converters.exceptions import EnvironmentFormatError
2127
from mdio.converters.exceptions import GridTraceCountError
2228
from mdio.converters.exceptions import GridTraceSparsityError
2329
from mdio.converters.type_converter import to_structured_type
2430
from mdio.core.grid import Grid
25-
from mdio.builder.schemas.chunk_grid import RegularChunkGrid
26-
from mdio.builder.schemas.chunk_grid import RegularChunkShape
27-
from mdio.builder.schemas.compressors import Blosc
28-
from mdio.builder.schemas.compressors import BloscCname
29-
from mdio.builder.schemas.dtype import ScalarType
3031
from mdio.segy import blocked_io
3132
from mdio.segy.utilities import get_grid_plan
3233

@@ -337,6 +338,7 @@ def _add_segy_ingest_attributes(dataset: Dataset, segy_file: SegyFile, grid_over
337338

338339
def _add_raw_headers_to_template(mdio_template: AbstractDatasetTemplate) -> AbstractDatasetTemplate:
339340
"""Add raw headers capability to the MDIO template by monkey-patching its _add_variables method.
341+
340342
This function modifies the template's _add_variables method to also add a raw headers variable
341343
with the following characteristics:
342344
- Same rank as the Headers variable (all dimensions except vertical)
@@ -348,9 +350,11 @@ def _add_raw_headers_to_template(mdio_template: AbstractDatasetTemplate) -> Abst
348350
- Chunked the same as the Headers variable
349351
Args:
350352
mdio_template: The MDIO template to mutate
353+
Returns:
354+
The mutated MDIO template
351355
"""
352356
# Check if raw headers enhancement has already been applied to avoid duplicate additions
353-
if hasattr(mdio_template, '_mdio_raw_headers_enhanced'):
357+
if hasattr(mdio_template, "_mdio_raw_headers_enhanced"):
354358
return mdio_template
355359

356360
# Store the original _add_variables method
@@ -365,7 +369,6 @@ def enhanced_add_variables() -> None:
365369

366370
# Create chunk grid metadata
367371
chunk_metadata = RegularChunkGrid(configuration=RegularChunkShape(chunk_shape=chunk_shape))
368-
from mdio.builder.schemas.v1.variable import VariableMetadata
369372

370373
# Add the raw headers variable using the builder's add_variable method
371374
mdio_template._builder.add_variable(

src/mdio/segy/_workers.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -152,39 +152,39 @@ def trace_worker( # noqa: PLR0913
152152
)
153153
if raw_header_key in worker_variables:
154154
tmp_raw_headers = np.zeros_like(dataset[raw_header_key])
155-
155+
156156
# Get the indices where we need to place results
157157
live_mask = not_null
158158
live_positions = np.where(live_mask.ravel())[0]
159-
159+
160160
if len(live_positions) > 0:
161161
# Calculate byte ranges for headers
162-
HEADER_SIZE = 240
162+
header_size = 240
163163
trace_offset = segy_file.spec.trace.offset
164164
trace_itemsize = segy_file.spec.trace.itemsize
165-
165+
166166
starts = []
167167
ends = []
168168
for global_trace_idx in live_trace_indexes:
169169
header_start = trace_offset + global_trace_idx * trace_itemsize
170-
header_end = header_start + HEADER_SIZE
170+
header_end = header_start + header_size
171171
starts.append(header_start)
172172
ends.append(header_end)
173-
173+
174174
# Capture raw bytes
175175
raw_header_bytes = merge_cat_file(segy_file.fs, segy_file.url, starts, ends)
176-
176+
177177
# Convert and place results
178178
raw_headers_array = np.frombuffer(bytes(raw_header_bytes), dtype="|V240")
179179
tmp_raw_headers.ravel()[live_positions] = raw_headers_array
180-
180+
181181
ds_to_write[raw_header_key] = Variable(
182182
ds_to_write[raw_header_key].dims,
183183
tmp_raw_headers,
184184
attrs=ds_to_write[raw_header_key].attrs,
185185
encoding=ds_to_write[raw_header_key].encoding,
186186
)
187-
187+
188188
data_variable = ds_to_write[data_variable_name]
189189
fill_value = _get_fill_value(ScalarType(data_variable.dtype.name))
190190
tmp_samples = np.full_like(data_variable, fill_value=fill_value)

0 commit comments

Comments
 (0)