def test_convert_segy_generates_single_npy(self, tmpdir): # Setup prefix = "volume1" input_file = self.testfile output_dir = tmpdir.strpath metadata_only = False iline = 189 xline = 193 cube_size = -1 stride = 128 normalize = True clip = True inputpath = "" # Test convert_segy.main(input_file, output_dir, prefix, iline, xline, metadata_only, stride, cube_size, normalize, clip) # Validate npy_files = test_util.get_npy_files(tmpdir.strpath) assert len(npy_files) == 1 min_val, max_val = _get_min_max(tmpdir.strpath) assert min_val >= MIN_RANGE assert max_val <= MAX_RANGE
def test_convert_segy_normalizes_data(self, tmpdir): """ Run process_all_files and checks that it returns with 0 exit code :param function filedir: fixture for setup and cleanup """ # Setup prefix = "volume1" input_file = self.testfile output_dir = tmpdir.strpath metadata_only = False iline = 189 xline = 193 cube_size = 128 stride = 128 normalize = True inputpath = "" clip = True # Test convert_segy.main(input_file, output_dir, prefix, iline, xline, metadata_only, stride, cube_size, normalize, clip) # Validate npy_files = test_util.get_npy_files(tmpdir.strpath) assert len(npy_files) == 2 min_val, max_val = _get_min_max(tmpdir.strpath) assert min_val >= MIN_RANGE assert max_val <= MAX_RANGE
def test_convert_segy_copies_exact_data_with_no_normalization( self, tmpdir): """ Run process_all_files and checks that it returns with 0 exit code :param function filedir: fixture for setup and cleanup """ # Setup prefix = "volume1" input_file = self.testfile output_dir = tmpdir.strpath metadata_only = False iline = 189 xline = 193 cube_size = 128 stride = 128 normalize = False inputpath = "" clip = False # Test convert_segy.main(input_file, output_dir, prefix, iline, xline, metadata_only, stride, cube_size, normalize, clip) # Validate expected_max = 1039.8 expected_min = -1039.8 npy_files = test_util.get_npy_files(tmpdir.strpath) assert len(npy_files) == 2 min_val, max_val = _get_min_max(tmpdir.strpath) assert expected_min == pytest.approx(min_val, rel=1e-3) assert expected_max == pytest.approx(max_val, rel=1e-3)
def test_process_npy_file_should_have_same_content_as_segy(self, tmpdir): """ Check the actual content of a npy file generated from the segy :param function tmpdir: pytest fixture for local test directory cleanup """ segyextract.process_segy_data_into_single_array( FILENAME, tmpdir.strpath, PREFIX) npy_files = test_util.get_npy_files(tmpdir.strpath) assert len(npy_files) == 1 data = np.load(os.path.join(tmpdir.strpath, npy_files[0])) _compare_output_to_segy(FILENAME, data, 40, 200, 10)
def _output_npy_files_are_correct_for_cube_size(expected_count, cube_size, outputdir): """ Check # of npy files in directory :param int expected_count: expected # of npy files :param str outputdir: directory to check for npy files :param int cube_size: size of cube array :returns: npy_files in outputdir :rtype: list """ npy_files = test_util.get_npy_files(outputdir) assert len(npy_files) == expected_count data = np.load(os.path.join(outputdir, npy_files[0])) assert len(data.shape) == 3 assert data.shape.count(cube_size) == 3 return npy_files
def _get_min_max(outputdir): """ Check # of npy files in directory :param str outputdir: directory to check for npy files :returns: min_val, max_val of values in npy files :rtype: int, int """ min_val = 0 max_val = 0 npy_files = test_util.get_npy_files(outputdir) for file in npy_files: data = np.load(os.path.join(outputdir, file)) this_min = np.amin(data) this_max = np.amax(data) if this_min < min_val: min_val = this_min if this_max > max_val: max_val = this_max return min_val, max_val
def test_process_segy_data_should_create_cube_size_equal_to_segy( self, tmpdir, filename, inline, xline, depth): """ Create single npy file for segy and validate size :param dict tmpdir: pytest fixture for local test directory cleanup :param str filename: SEG-Y filename :param int inline: byte location for inline :param int xline: byte location for crossline :param int depth: number of samples """ segyextract.process_segy_data_into_single_array( filename, tmpdir.strpath, PREFIX) npy_files = test_util.get_npy_files(tmpdir.strpath) assert len(npy_files) == 1 data = np.load(os.path.join(tmpdir.strpath, npy_files[0])) assert len(data.shape) == 3 assert data.shape[0] == inline assert data.shape[1] == xline assert data.shape[2] == depth