Skip to content

Commit c614a87

Browse files
authored
Merge pull request #285 from markspec/284_sparsity_check_override
2 parents 95bd831 + c116a3b commit c614a87

File tree

2 files changed

+25
-8
lines changed

2 files changed

+25
-8
lines changed

src/mdio/converters/exceptions.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,16 @@ def __init__(self, grid_traces, segy_traces):
1515
)
1616

1717
super().__init__(self.message)
18+
19+
20+
class GridTraceSparsityError(Exception):
21+
"""Raised when mdio grid will be sparsely populated from SEG-Y traces."""
22+
23+
def __init__(self, shape, num_traces):
24+
"""Initialize error."""
25+
self.message = (
26+
f"Grid shape: {shape} but SEG-Y tracecount: {num_traces}. "
27+
"This grid is very sparse and most likely user error with indexing."
28+
)
29+
30+
super().__init__(self.message)

src/mdio/converters/segy.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from __future__ import annotations
55

66
import logging
7+
import os
78
from datetime import datetime
89
from datetime import timezone
910
from importlib import metadata
@@ -16,6 +17,7 @@
1617

1718
from mdio.api.io_utils import process_url
1819
from mdio.converters.exceptions import GridTraceCountError
20+
from mdio.converters.exceptions import GridTraceSparsityError
1921
from mdio.core import Grid
2022
from mdio.core.utils_write import write_attribute
2123
from mdio.segy import blocked_io
@@ -61,14 +63,16 @@ def grid_density_qc(grid: Grid, num_traces: int) -> None:
6163
Basic qc of the grid to check density and provide warning/exception
6264
when indexing is problematic to provide user with insights to the use.
6365
If trace density on the specified grid is less than 50% a warning is
64-
logged. If denisty is less than 1% an exception is raised.
66+
logged. If density is less than 10% an exception is raised. To ignore
67+
trace sparsity check set environment variable:
68+
MDIO_IGNORE_CHECKS = True
6569
6670
Args:
6771
grid: The grid instance to check.
6872
num_traces: Expected number of traces.
6973
7074
Raises:
71-
GridTraceCountError: When the grid is too sparse.
75+
GridTraceSparsityError: When the grid is too sparse.
7276
"""
7377
grid_traces = np.prod(grid.shape[:-1], dtype=np.uint64) # Exclude sample
7478
dims = {k: v for k, v in zip(grid.dim_names, grid.shape)} # noqa: B905
@@ -78,16 +82,16 @@ def grid_density_qc(grid: Grid, num_traces: int) -> None:
7882

7983
# Extreme case where the grid is very sparse (usually user error)
8084
if grid_traces > 10 * num_traces:
85+
logger.warning("WARNING: Sparse mdio grid detected!")
8186
for dim_name in grid.dim_names:
8287
dim_min = grid.get_min(dim_name)
8388
dim_max = grid.get_max(dim_name)
8489
logger.warning(f"{dim_name} min: {dim_min} max: {dim_max}")
85-
86-
msg = (
87-
f"Grid shape: {grid.shape} but SEG-Y tracecount: {num_traces}. "
88-
"This grid is very sparse and most likely user error with indexing."
89-
)
90-
raise GridTraceCountError(msg)
90+
if os.getenv("MDIO_IGNORE_CHECKS", False):
91+
# Do not raise an exception if MDIO_IGNORE_CHECK is False
92+
pass
93+
else:
94+
raise GridTraceSparsityError(grid.shape, num_traces)
9195

9296
# Warning if we have above 50% sparsity.
9397
if grid_traces > 2 * num_traces:

0 commit comments

Comments
 (0)