Skip to content

Commit e15d6a4

Browse files
BrianMichelltasansal
authored andcommitted
Linting
1 parent eb6bed2 commit e15d6a4

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
@@ -154,39 +154,39 @@ def trace_worker( # noqa: PLR0913
154154
)
155155
if raw_header_key in worker_variables:
156156
tmp_raw_headers = np.zeros_like(dataset[raw_header_key])
157-
157+
158158
# Get the indices where we need to place results
159159
live_mask = not_null
160160
live_positions = np.where(live_mask.ravel())[0]
161-
161+
162162
if len(live_positions) > 0:
163163
# Calculate byte ranges for headers
164-
HEADER_SIZE = 240
164+
header_size = 240
165165
trace_offset = segy_file.spec.trace.offset
166166
trace_itemsize = segy_file.spec.trace.itemsize
167-
167+
168168
starts = []
169169
ends = []
170170
for global_trace_idx in live_trace_indexes:
171171
header_start = trace_offset + global_trace_idx * trace_itemsize
172-
header_end = header_start + HEADER_SIZE
172+
header_end = header_start + header_size
173173
starts.append(header_start)
174174
ends.append(header_end)
175-
175+
176176
# Capture raw bytes
177177
raw_header_bytes = merge_cat_file(segy_file.fs, segy_file.url, starts, ends)
178-
178+
179179
# Convert and place results
180180
raw_headers_array = np.frombuffer(bytes(raw_header_bytes), dtype="|V240")
181181
tmp_raw_headers.ravel()[live_positions] = raw_headers_array
182-
182+
183183
ds_to_write[raw_header_key] = Variable(
184184
ds_to_write[raw_header_key].dims,
185185
tmp_raw_headers,
186186
attrs=ds_to_write[raw_header_key].attrs,
187187
encoding=ds_to_write[raw_header_key].encoding,
188188
)
189-
189+
190190
data_variable = ds_to_write[data_variable_name]
191191
fill_value = _get_fill_value(ScalarType(data_variable.dtype.name))
192192
tmp_samples = np.full_like(data_variable, fill_value=fill_value)

0 commit comments

Comments
 (0)