Skip to content

Commit 4ddae82

Browse files
authored
Refactor: simplify and condense dictionary and function calls (#548)
1 parent cfdea9a commit 4ddae82

File tree

7 files changed

+8
-45
lines changed

7 files changed

+8
-45
lines changed

src/mdio/commands/info.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,7 @@ def info(mdio_path: str, output_format: str, access_pattern: str) -> None:
4545
"""
4646
from mdio import MDIOReader
4747

48-
reader = MDIOReader(
49-
mdio_path,
50-
access_pattern=access_pattern,
51-
return_metadata=True,
52-
)
48+
reader = MDIOReader(mdio_path, access_pattern=access_pattern, return_metadata=True)
5349

5450
grid_dict = parse_grid(reader.grid)
5551
stats_dict = cast_stats(reader.stats)

src/mdio/converters/numpy.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -147,11 +147,7 @@ def numpy_to_mdio( # noqa: PLR0913
147147
)
148148

149149
dims = [Dimension(name=name, coords=index_coords[name]) for name in index_names]
150-
create_conf = MDIOCreateConfig(
151-
path=mdio_path_or_buffer,
152-
grid=Grid(dims),
153-
variables=[mdio_var],
154-
)
150+
create_conf = MDIOCreateConfig(path=mdio_path_or_buffer, grid=Grid(dims), variables=[mdio_var])
155151
create_empty(create_conf, overwrite, storage_options)
156152

157153
writer = MDIOWriter(mdio_path_or_buffer, suffix, storage_options)

src/mdio/core/factory.py

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -171,13 +171,7 @@ def create_empty(
171171
chunk_key_encoding={"name": "v2", "separator": "/"},
172172
)
173173

174-
stats = {
175-
"mean": 0,
176-
"std": 0,
177-
"rms": 0,
178-
"min": 0,
179-
"max": 0,
180-
}
174+
stats = {"mean": 0, "std": 0, "rms": 0, "min": 0, "max": 0}
181175

182176
for key, value in stats.items():
183177
write_attribute(name=key, zarr_group=root_group, attribute=value)
@@ -238,11 +232,7 @@ def create_empty_like(
238232

239233
config = MDIOCreateConfig(path=dest_path, grid=grid, variables=variables)
240234

241-
create_empty(
242-
config=config,
243-
overwrite=overwrite,
244-
storage_options=storage_options_output,
245-
)
235+
create_empty(config=config, overwrite=overwrite, storage_options=storage_options_output)
246236

247237
writer = MDIOWriter(dest_path, storage_options=storage_options_output)
248238
writer.text_header = src_meta_grp.attrs["text_header"]

src/mdio/exceptions.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ class WrongTypeError(MDIOError):
4444
def __init__(self, message: str, name: str = None, expected: str = None):
4545
if name is not None and expected is not None:
4646
extras = f"Got: {name} Expected: {expected}"
47-
4847
message = f"{message} - {extras}"
4948

5049
super().__init__(message)

src/mdio/segy/_workers.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,7 @@
1717
from mdio.core import Grid
1818

1919

20-
def header_scan_worker(
21-
segy_file: SegyFile,
22-
trace_range: tuple[int, int],
23-
) -> HeaderArray:
20+
def header_scan_worker(segy_file: SegyFile, trace_range: tuple[int, int]) -> HeaderArray:
2421
"""Header scan worker.
2522
2623
If SegyFile is not open, it can either accept a path string or a handle that was opened in
@@ -90,7 +87,6 @@ def trace_worker(
9087
seq_trace_indices = grid.map[chunk_indices[:-1]]
9188

9289
tmp_data = np.zeros(seq_trace_indices.shape + (grid.shape[-1],), dtype=data_array.dtype)
93-
9490
tmp_metadata = np.zeros(seq_trace_indices.shape, dtype=metadata_array.dtype)
9591

9692
del grid # To save some memory

src/mdio/segy/blocked_io.py

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,7 @@
3232
default_cpus = cpu_count(logical=True)
3333

3434

35-
def to_zarr(
36-
segy_file: SegyFile,
37-
grid: Grid,
38-
data_array: Array,
39-
header_array: Array,
40-
) -> dict:
35+
def to_zarr(segy_file: SegyFile, grid: Grid, data_array: Array, header_array: Array) -> dict:
4136
"""Blocked I/O from SEG-Y to chunked `zarr.core.Array`.
4237
4338
Args:
@@ -112,13 +107,7 @@ def to_zarr(
112107
glob_min = glob_min.min().astype("float64")
113108
glob_max = glob_max.max().astype("float64")
114109

115-
return {
116-
"mean": glob_mean,
117-
"std": glob_std,
118-
"rms": glob_rms,
119-
"min": glob_min,
120-
"max": glob_max,
121-
}
110+
return {"mean": glob_mean, "std": glob_std, "rms": glob_rms, "min": glob_min, "max": glob_max}
122111

123112

124113
def segy_record_concat(

src/mdio/segy/creation.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,7 @@
2626
logger = logging.getLogger(__name__)
2727

2828

29-
def make_segy_factory(
30-
mdio: MDIOReader,
31-
spec: SegySpec,
32-
) -> SegyFactory:
29+
def make_segy_factory(mdio: MDIOReader, spec: SegySpec) -> SegyFactory:
3330
"""Generate SEG-Y factory from MDIO metadata."""
3431
grid = mdio.grid
3532
sample_dim = grid.select_dim("sample")

0 commit comments

Comments
 (0)