Skip to content

Commit a2ee5b8

Browse files
committed
Linting
1 parent fb60ef5 commit a2ee5b8

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

@@ -340,6 +341,7 @@ def _add_grid_override_to_metadata(dataset: Dataset, grid_overrides: dict[str, A
340341

341342
def _add_raw_headers_to_template(mdio_template: AbstractDatasetTemplate) -> AbstractDatasetTemplate:
342343
"""Add raw headers capability to the MDIO template by monkey-patching its _add_variables method.
344+
343345
This function modifies the template's _add_variables method to also add a raw headers variable
344346
with the following characteristics:
345347
- Same rank as the Headers variable (all dimensions except vertical)
@@ -351,9 +353,11 @@ def _add_raw_headers_to_template(mdio_template: AbstractDatasetTemplate) -> Abst
351353
- Chunked the same as the Headers variable
352354
Args:
353355
mdio_template: The MDIO template to mutate
356+
Returns:
357+
The mutated MDIO template
354358
"""
355359
# Check if raw headers enhancement has already been applied to avoid duplicate additions
356-
if hasattr(mdio_template, '_mdio_raw_headers_enhanced'):
360+
if hasattr(mdio_template, "_mdio_raw_headers_enhanced"):
357361
return mdio_template
358362

359363
# Store the original _add_variables method
@@ -368,7 +372,6 @@ def enhanced_add_variables() -> None:
368372

369373
# Create chunk grid metadata
370374
chunk_metadata = RegularChunkGrid(configuration=RegularChunkShape(chunk_shape=chunk_shape))
371-
from mdio.builder.schemas.v1.variable import VariableMetadata
372375

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

src/mdio/segy/_workers.py

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

0 commit comments

Comments
 (0)