Skip to content

Commit 60f0f76

Browse files
committed
Pre-commit autofixes
1 parent 5a70b66 commit 60f0f76

File tree

7 files changed

+30
-26
lines changed

7 files changed

+30
-26
lines changed

src/mdio/builder/dataset_builder.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,9 @@ def add_dimension(self, name: str, size: int) -> "MDIODatasetBuilder":
101101
self._state = _BuilderState.HAS_DIMENSIONS
102102
return self
103103

104-
def push_dimension(self, dimension: NamedDimension, position: int, new_dim_chunk_size: int=1, new_dim_size: int=1) -> "MDIODatasetBuilder":
104+
def push_dimension(
105+
self, dimension: NamedDimension, position: int, new_dim_chunk_size: int = 1, new_dim_size: int = 1
106+
) -> "MDIODatasetBuilder":
105107
"""Pushes a dimension to all Coordiantes and Variables.
106108
The position argument is the domain index of the dimension to push.
107109
If a Variable is within the position domain, it will be inserted at the position and all remaining dimensions will be shifted to the right.
@@ -130,23 +132,25 @@ def push_dimension(self, dimension: NamedDimension, position: int, new_dim_chunk
130132

131133
def propogate_dimension(variable: Variable, position: int, new_dim_chunk_size: int) -> Variable:
132134
"""Propogates the dimension to the variable or coordinate."""
133-
from mdio.builder.schemas.chunk_grid import RegularChunkGrid, RegularChunkShape
135+
from mdio.builder.schemas.chunk_grid import RegularChunkGrid
136+
from mdio.builder.schemas.chunk_grid import RegularChunkShape
137+
134138
if len(variable.dimensions) + 1 <= position:
135139
# Don't do anything if the new dimension is not within the Variable's domain
136140
return variable
137141
new_dimensions = variable.dimensions[:position] + [dimension] + variable.dimensions[position:]
138-
142+
139143
# Get current chunk shape from metadata
140144
current_chunk_shape = (1,) * len(variable.dimensions) # Default fallback
141145
if variable.metadata is not None and variable.metadata.chunk_grid is not None:
142146
current_chunk_shape = variable.metadata.chunk_grid.configuration.chunk_shape
143-
147+
144148
# Insert new chunk size at the correct position
145149
new_chunk_shape = current_chunk_shape[:position] + (new_dim_chunk_size,) + current_chunk_shape[position:]
146-
150+
147151
# Create new chunk grid configuration
148152
new_chunk_grid = RegularChunkGrid(configuration=RegularChunkShape(chunk_shape=new_chunk_shape))
149-
153+
150154
# Update metadata with new chunk grid
151155
new_metadata = variable.metadata.model_copy() if variable.metadata else VariableMetadata()
152156
new_metadata.chunk_grid = new_chunk_grid

src/mdio/builder/templates/abstract_dataset_template.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
"""Template method pattern implementation for MDIO v1 dataset template."""
22

33
import copy
4+
import logging
45
from abc import ABC
56
from abc import abstractmethod
6-
import logging
7+
from collections.abc import Callable
78
from typing import Any
8-
from typing import Callable
99

1010
from mdio.builder.dataset_builder import MDIODatasetBuilder
1111
from mdio.builder.schemas import compressors
@@ -21,6 +21,7 @@
2121

2222
logger = logging.getLogger(__name__)
2323

24+
2425
class AbstractDatasetTemplate(ABC):
2526
"""Abstract base class that defines the template method for Dataset building factory.
2627
@@ -80,7 +81,6 @@ def build_dataset(
8081
if header_dtype:
8182
self._add_trace_headers(header_dtype)
8283

83-
8484
# This seems to be breaking the dataset, but adds the trace dimension.
8585
for transform in self._queued_transforms:
8686
logger.debug(f"Applying transform: {transform.__name__}")
@@ -163,7 +163,6 @@ def _add_dimensions(self) -> None:
163163
for i in range(len(self._dim_sizes) - len(self._dim_names)):
164164
self._builder.add_dimension(f"dim_{i}", self._dim_sizes[len(self._dim_names) + i])
165165

166-
167166
def _add_coordinates(self) -> None:
168167
"""Add custom coordinates.
169168

src/mdio/converters/segy.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,7 @@ def segy_to_mdio( # noqa PLR0913
516516
if "trace" in grid.dim_names:
517517
# Find the trace dimension index and remove it from sizes
518518
trace_idx = grid.dim_names.index("trace")
519-
dataset_sizes = grid.shape[:trace_idx] + grid.shape[trace_idx + 1:]
519+
dataset_sizes = grid.shape[:trace_idx] + grid.shape[trace_idx + 1 :]
520520

521521
mdio_ds: Dataset = mdio_template.build_dataset(
522522
name=mdio_template.name,

src/mdio/segy/geometry.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,9 @@ def create_trace_index(
247247
return index_headers
248248

249249

250-
def analyze_non_indexed_headers(index_headers: HeaderArray, dtype: DTypeLike = np.int16, index_names: Sequence[str] = None) -> NDArray:
250+
def analyze_non_indexed_headers(
251+
index_headers: HeaderArray, dtype: DTypeLike = np.int16, index_names: Sequence[str] = None
252+
) -> NDArray:
251253
"""Check input headers for SEG-Y input to help determine geometry.
252254
253255
This function reads in trace_qc_count headers and finds the unique cable values. Then, it
@@ -436,7 +438,7 @@ def transform(
436438
self,
437439
index_headers: HeaderArray,
438440
grid_overrides: dict[str, bool | int],
439-
index_names = None,
441+
index_names=None,
440442
) -> NDArray:
441443
"""Perform the grid transform."""
442444
self.validate(index_headers, grid_overrides)
@@ -474,7 +476,7 @@ def transform(
474476
self,
475477
index_headers: HeaderArray,
476478
grid_overrides: dict[str, bool | int],
477-
index_names = None,
479+
index_names=None,
478480
) -> NDArray:
479481
"""Perform the grid transform."""
480482
self.validate(index_headers, grid_overrides)
@@ -538,7 +540,6 @@ def run(
538540
chunksize: Sequence[int] | None = None,
539541
) -> tuple[HeaderArray, tuple[str], tuple[int]]:
540542
"""Run grid overrides and return result."""
541-
542543
for override in grid_overrides:
543544
if override in self.parameters:
544545
continue

src/mdio/segy/parsers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@
1111

1212
import numpy as np
1313
from psutil import cpu_count
14+
from segy.arrays import HeaderArray
1415
from tqdm.auto import tqdm
1516

1617
from mdio.segy._workers import header_scan_worker
1718

18-
from segy.arrays import HeaderArray
1919
if TYPE_CHECKING:
2020
from segy import SegyFile
2121

src/mdio/segy/utilities.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010
import numpy as np
1111
from dask.array.core import normalize_chunks
1212

13+
from mdio.builder.schemas.dimension import NamedDimension
1314
from mdio.core import Dimension
1415
from mdio.segy.geometry import GridOverrider
1516
from mdio.segy.parsers import parse_headers
16-
from mdio.builder.schemas.dimension import NamedDimension
1717

1818
if TYPE_CHECKING:
1919
from numpy.typing import DTypeLike
@@ -28,41 +28,42 @@
2828

2929
def _create_delayed_trace_dimension_transform(headers_subset: HeaderArray, position: int) -> callable:
3030
"""Create a delayed transform function that adds a trace dimension and its coordinate.
31-
31+
3232
This function creates a closure that captures the headers_subset and position,
3333
but defers the actual computation until the transform is executed by the dataset builder.
3434
The transform adds both the trace dimension and a corresponding coordinate.
35-
35+
3636
Args:
3737
headers_subset: The header array containing trace information
3838
position: The position where the trace dimension should be inserted
39-
39+
4040
Returns:
4141
A callable that can be used as a transform function
4242
"""
43+
4344
def delayed_transform(builder):
4445
from mdio.builder.schemas.dtype import ScalarType
45-
46+
4647
# Calculate the trace dimension size at execution time
4748
if "trace" in headers_subset.dtype.names:
4849
trace_size = int(np.max(headers_subset["trace"]))
4950
else:
5051
# Fallback: if trace field doesn't exist, we need to determine size differently
5152
raise ValueError("Trace field not found in headers_subset when executing delayed transform")
52-
53+
5354
# Add the trace dimension
5455
trace_dimension = NamedDimension(name="trace", size=trace_size)
5556
builder.push_dimension(trace_dimension, position=position, new_dim_chunk_size=1, new_dim_size=trace_size)
56-
57+
5758
# Add the corresponding coordinate for the trace dimension
5859
builder.add_coordinate(
5960
"trace",
6061
dimensions=("trace",),
6162
data_type=ScalarType.INT32,
6263
)
63-
64+
6465
return builder
65-
66+
6667
return delayed_transform
6768

6869

tests/integration/test_import_streamer_grid_overrides.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
import dask
99
import numpy as np
10-
import numpy.testing as npt
1110
import pytest
1211
import xarray.testing as xrt
1312
from tests.integration.conftest import get_segy_mock_4d_spec

0 commit comments

Comments
 (0)