11import pathlib
22import warnings
33
4+ import numpy as np
45import pytest
56
67import xtgeo
1112
1213SFILE1 = pathlib .Path ("cubes/etc/ib_synth_iainb.segy" )
1314SFILE2 = pathlib .Path ("cubes/reek/syntseis_20030101_seismic_depth_stack.segy" )
15+ SFILE3 = pathlib .Path ("cubes/etc/cube_w_deadtraces.segy" )
1416
1517TOP2A = pathlib .Path ("surfaces/reek/2/01_topreek_rota.gri" )
1618TOP2B = pathlib .Path ("surfaces/reek/2/04_basereek_rota.gri" )
@@ -35,6 +37,13 @@ def fixture_loadsfile2(testdata_path):
3537 return xtgeo .cube_from_file (testdata_path / SFILE2 )
3638
3739
40+ @pytest .fixture (name = "loadsfile3" )
41+ def fixture_loadsfile3 (testdata_path ):
42+ """Fixture for loading a SFILE3"""
43+ logger .info ("Load seismic file 3" )
44+ return xtgeo .cube_from_file (testdata_path / SFILE3 )
45+
46+
3847def test_single_slice_yflip_snapxy_both (loadsfile1 ):
3948 """Test cube values with exact location of maps, compared to cube samples"""
4049 cube1 = loadsfile1
@@ -517,3 +526,41 @@ def test_warn_errs_new_module_reek(loadsfile1, loadsfile2, testdata_path):
517526
518527 with pytest .raises (ValueError , match = "no valid data in the interval" ):
519528 _ = cube2 .compute_attributes_in_window (surf1 , surf1 , ndiv = 4 ) # same surface
529+
530+
531+ def test_compute_attrs_handling_of_dead_traces (loadsfile3 ):
532+ """Test handling of dead traces in the cube."""
533+ cube = loadsfile3
534+
535+ # Create a surface that is above the dead traces
536+ surf = xtgeo .surface_from_cube (cube , 1000.0 )
537+
538+ # Compute attributes in window
539+ attrs = cube .compute_attributes_in_window (surf , surf + 10 )
540+
541+ # Check if the result is as expected
542+ assert "mean" in attrs
543+ assert attrs ["mean" ].values .mean () == pytest .approx (239.18202 , abs = 1e-4 )
544+
545+ # count number of dead traces in cube
546+ dead_traces = (cube .traceidcodes == 2 ).sum ()
547+
548+ # count number of masked values in map
549+ masked_values = np .ma .count_masked (attrs ["mean" ].values )
550+
551+ assert dead_traces == masked_values , (
552+ "Number of dead traces does not match masked values"
553+ )
554+
555+
556+ def test_attribute_around_constant_cube_slices (loadsfile2 ):
557+ """Get attribute around a constant cube slices."""
558+
559+ mycube = loadsfile2
560+
561+ level1 = 1710
562+ level2 = 1730
563+
564+ myattrs = mycube .compute_attributes_in_window (level1 , level2 )
565+
566+ assert myattrs ["mean" ].values .mean () == pytest .approx (- 0.00293736 , abs = 1e-5 )
0 commit comments