44from __future__ import annotations
55
66import logging
7+ import os
78from datetime import datetime
89from datetime import timezone
910from importlib import metadata
1617
1718from mdio .api .io_utils import process_url
1819from mdio .converters .exceptions import GridTraceCountError
20+ from mdio .converters .exceptions import GridTraceSparsityError
1921from mdio .core import Grid
2022from mdio .core .utils_write import write_attribute
2123from 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