Skip to content

Commit c116a3b

Browse files
committed
Resolve #276: Allow users to ignore sparse trace check.
1 parent 40d961b commit c116a3b

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
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: 8 additions & 6 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
@@ -80,16 +82,16 @@ def grid_density_qc(grid: Grid, num_traces: int) -> None:
8082

8183
# Extreme case where the grid is very sparse (usually user error)
8284
if grid_traces > 10 * num_traces:
85+
logger.warning("WARNING: Sparse mdio grid detected!")
8386
for dim_name in grid.dim_names:
8487
dim_min = grid.get_min(dim_name)
8588
dim_max = grid.get_max(dim_name)
8689
logger.warning(f"{dim_name} min: {dim_min} max: {dim_max}")
87-
88-
msg = (
89-
f"Grid shape: {grid.shape} but SEG-Y tracecount: {num_traces}. "
90-
"This grid is very sparse and most likely user error with indexing."
91-
)
92-
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)
9395

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

0 commit comments

Comments
 (0)