Skip to content

Commit f58593b

Browse files
committed
Linting
1 parent 5d38dbb commit f58593b

File tree

3 files changed

+16
-21
lines changed

3 files changed

+16
-21
lines changed

src/mdio/converters/segy.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ def get_compressor(lossless: bool, compression_tolerance: float = -1) -> Blosc |
131131
return compressor
132132

133133

134-
def segy_to_mdio( # noqa: PLR0913, PLR0915
134+
def segy_to_mdio( # noqa: PLR0913, PLR0915, PLR0912
135135
segy_path: str | Path,
136136
mdio_path_or_buffer: str | Path,
137137
index_bytes: Sequence[int],
@@ -398,7 +398,7 @@ def segy_to_mdio( # noqa: PLR0913, PLR0915
398398
valid_mask = np.ones(grid.num_traces, dtype=bool)
399399
for d_idx in range(len(grid.header_index_arrays)):
400400
coords = grid.header_index_arrays[d_idx]
401-
valid_mask &= (coords < grid.shape[d_idx])
401+
valid_mask &= coords < grid.shape[d_idx]
402402
valid_count = int(np.count_nonzero(valid_mask))
403403
if valid_count != num_traces:
404404
for dim_name in grid.dim_names:
@@ -409,6 +409,7 @@ def segy_to_mdio( # noqa: PLR0913, PLR0915
409409
raise GridTraceCountError(valid_count, num_traces)
410410

411411
import gc
412+
412413
del valid_mask
413414
gc.collect()
414415

@@ -484,7 +485,7 @@ def segy_to_mdio( # noqa: PLR0913, PLR0915
484485
local_idx = indexed_coords - sl.start # remains uint32
485486
# Free indexed_coords immediately
486487
del indexed_coords
487-
488+
488489
# Only convert dtype if necessary for indexing (numpy requires int for indexing)
489490
if local_idx.dtype != np.intp:
490491
local_idx = local_idx.astype(np.intp)
@@ -496,16 +497,16 @@ def segy_to_mdio( # noqa: PLR0913, PLR0915
496497

497498
# Mark live cells in the temporary block
498499
block[tuple(local_coords)] = True
499-
500+
500501
# Free local_coords immediately after use
501502
del local_coords
502503

503504
# Write the entire block to Zarr at once
504505
live_mask_array.set_basic_selection(selection=chunk_indices, value=block)
505-
506+
506507
# Free block immediately after writing
507508
del block
508-
509+
509510
# Force garbage collection periodically to free memory aggressively
510511
gc.collect()
511512

src/mdio/core/grid.py

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,12 @@
77
from typing import TYPE_CHECKING
88

99
import numpy as np
10-
import zarr
1110

12-
from mdio.constants import UINT32_MAX
1311
from mdio.core import Dimension
1412
from mdio.core.serialization import Serializer
15-
from mdio.core.utils_write import get_constrained_chunksize
1613

1714
if TYPE_CHECKING:
15+
import zarr
1816
from segy.arrays import HeaderArray
1917
from zarr import Array as ZarrArray
2018

@@ -112,8 +110,8 @@ def build_map(self, index_headers: HeaderArray) -> None:
112110
"""Compute per-trace grid coordinates (lazy map).
113111
114112
Instead of allocating a full `self.map` and `self.live_mask`, this computes, for each trace,
115-
its integer index along each dimension (excluding the final sample dimension) and stores them in
116-
`self.header_index_arrays`. The full mapping can then be derived chunk-by-chunk when writing.
113+
its integer index along each dimension (excluding the sample dimension) and stores them in
114+
`self.header_index_arrays`. The full mapping can then be derived chunkwise when writing.
117115
118116
Args:
119117
index_headers: Header array containing dimension indices (length = number of traces).
@@ -126,8 +124,8 @@ def build_map(self, index_headers: HeaderArray) -> None:
126124
# Cast to uint32.
127125
idx_arrays: list[np.ndarray] = []
128126
for dim in self.dims[:-1]:
129-
hdr_vals = index_headers[dim.name] # shape: (num_traces,)
130-
coords = np.searchsorted(dim, hdr_vals) # integer indices
127+
hdr_vals = index_headers[dim.name] # shape: (num_traces,)
128+
coords = np.searchsorted(dim, hdr_vals) # integer indices
131129
coords = coords.astype(np.uint32)
132130
idx_arrays.append(coords)
133131

@@ -136,7 +134,6 @@ def build_map(self, index_headers: HeaderArray) -> None:
136134

137135
# We no longer allocate `self.map` or `self.live_mask` here.
138136
# The full grid shape is `self.shape`, but mapping is done lazily per chunk.
139-
return
140137

141138
def get_traces_for_chunk(self, chunk_slices: tuple[slice, ...]) -> np.ndarray:
142139
"""Return all trace IDs whose grid-coordinates fall inside the given chunk slices.
@@ -157,16 +154,15 @@ def get_traces_for_chunk(self, chunk_slices: tuple[slice, ...]) -> np.ndarray:
157154
arr = self.header_index_arrays[dim_idx] # shape: (num_traces,)
158155
start, stop = sl.start, sl.stop
159156
if start is not None:
160-
mask &= (arr >= start)
157+
mask &= arr >= start
161158
if stop is not None:
162-
mask &= (arr < stop)
159+
mask &= arr < stop
163160
if not mask.any():
164161
# No traces remain after this dimension's filtering
165162
return np.empty((0,), dtype=np.uint32)
166163

167164
# Gather the trace IDs that survived all dimension tests
168-
trace_ids = np.nonzero(mask)[0].astype(np.uint32)
169-
return trace_ids
165+
return np.nonzero(mask)[0].astype(np.uint32)
170166

171167

172168
class GridSerializer(Serializer):

src/mdio/segy/blocked_io.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@
2323
from mdio.segy.creation import serialize_to_segy_stack
2424
from mdio.segy.utilities import find_trailing_ones_index
2525

26-
import zarr
27-
2826
if TYPE_CHECKING:
2927
from numpy.typing import NDArray
3028
from segy import SegyFactory
@@ -98,7 +96,7 @@ def to_zarr(
9896
# Aggregate statistics
9997
chunk_stats = [stat for stat in chunk_stats if stat is not None]
10098
# Each stat: (count, sum, sum_sq, min, max). Transpose to unpack rows.
101-
glob_count, glob_sum, glob_sum_square, glob_min, glob_max = zip(*chunk_stats)
99+
glob_count, glob_sum, glob_sum_square, glob_min, glob_max = zip(*chunk_stats, strict=False)
102100

103101
glob_count = np.sum(np.array(glob_count, dtype=np.uint64))
104102
glob_sum = np.sum(np.array(glob_sum, dtype=np.float64))

0 commit comments

Comments
 (0)