def test_no_mark_dead_warning(self, segy_path): """Check that a warning is emitted when `collect_stats` is run before `mark_dead_races`""" survey = Survey(segy_path, header_index="TRACE_SEQUENCE_FILE", header_cols="offset") with pytest.warns(RuntimeWarning): survey.collect_stats()
def survey(segy_path): """Create gather""" survey = Survey(segy_path, header_index=['INLINE_3D', 'CROSSLINE_3D'], header_cols=['offset', 'FieldRecord']) survey.remove_dead_traces(bar=False) survey.collect_stats(bar=False) survey.headers[HDR_FIRST_BREAK] = np.random.randint(0, 1000, len(survey.headers)) return survey
def test_get_quantile(self, stat_segy, quantile, is_scalar): """Run `get_quantile` and check the returned value and its type.""" path, _ = stat_segy survey = Survey(path, header_index="TRACE_SEQUENCE_FILE", header_cols="offset") survey.mark_dead_traces() survey.collect_stats() quantile_val = survey.get_quantile(quantile) assert np.isscalar(quantile) is is_scalar assert np.allclose( np.array(quantile_val).ravel(), survey.quantile_interpolator(quantile))
def test_collect_stats(self, stat_segy, init_limits, remove_dead, n_quantile_traces, quantile_precision, stats_limits, use_segyio_trace_loader): """Compare stats obtained by running `collect_stats` with the actual ones.""" path, trace_data = stat_segy survey = Survey(path, header_index="TRACE_SEQUENCE_FILE", header_cols="offset", limits=init_limits, use_segyio_trace_loader=use_segyio_trace_loader, bar=False) survey.mark_dead_traces(bar=False) if remove_dead: survey.remove_dead_traces(inplace=True) survey_copy = survey.copy() survey.collect_stats(n_quantile_traces=n_quantile_traces, quantile_precision=quantile_precision, limits=stats_limits, bar=True) # stats_limits take priority over init_limits stats_limits = init_limits if stats_limits is None else stats_limits trace_data = trace_data[:, stats_limits] if remove_dead: is_dead = np.isclose(trace_data.min(axis=1), trace_data.max(axis=1)) trace_data = trace_data[~is_dead].ravel() # Perform basic tests of estimated quantiles since fair comparison of interpolators is complicated quantiles = survey.quantile_interpolator(np.linspace(0, 1, 11)) assert np.isclose(quantiles[0], trace_data.min()) assert np.isclose(quantiles[-1], trace_data.max()) assert (np.diff(quantiles) >= 0).all() survey.quantile_interpolator = None # Fill the copy of the survey with actual stats and compare it with the source survey survey_copy.has_stats = True survey_copy.min = trace_data.min() survey_copy.max = trace_data.max() survey_copy.mean = trace_data.mean() survey_copy.std = trace_data.std() assert_surveys_equal(survey, survey_copy)