def test_depth_mode_1_repcode_invalid(tmpdir, merge_lis_prs, dfsr_filename): fpath = os.path.join(str(tmpdir), 'depth-reprc-invalid.lis') content = headers + [ 'data/lis/records/curves/' + dfsr_filename, ] + trailers merge_lis_prs(fpath, content) with lis.load(fpath) as (f, ): dfs = f.data_format_specs()[0] with pytest.raises(ValueError) as exc: _ = lis.curves(f, dfs) assert "Invalid representation code" in str(exc.value)
def test_fdata_dimensional_bad(tmpdir, merge_lis_prs): fpath = os.path.join(str(tmpdir), 'dimensional-bad.lis') content = headers + [ 'data/lis/records/curves/dfsr-dimensional-bad.lis.part', ] + trailers merge_lis_prs(fpath, content) with lis.load(fpath) as (f, ): dfs = f.data_format_specs()[0] with pytest.raises(ValueError) as exc: _ = lis.curves(f, dfs) assert 'cannot have multiple entries per sample' in str(exc.value)
def test_curves_encoding(tmpdir, merge_lis_prs): fpath = os.path.join(str(tmpdir), 'encoded-curves.dlis') content = [ 'data/lis/records/RHLR-1.lis.part', 'data/lis/records/THLR-1.lis.part', 'data/lis/records/FHLR-1.lis.part', 'data/lis/records/curves/dfsr-encoded.lis.part', 'data/lis/records/curves/fdata-encoded.lis.part', 'data/lis/records/FTLR-1.lis.part', 'data/lis/records/TTLR-1.lis.part', 'data/lis/records/RTLR-1.lis.part', ] merge_lis_prs(fpath, content) prev_encodings = dlisio.common.get_encodings() dlisio.common.set_encodings([]) try: f, = lis.load(fpath) dfs = f.data_format_specs()[0] with pytest.warns(UnicodeWarning): cur = lis.curves(f, dfs) assert cur[b'\xeb\xe1\xee\x31'] == [ b'\xda\xce\xc1\xde\xc5\xce\xc9\xc5' ] dlisio.common.set_encodings(['koi8_r']) dfs = f.data_format_specs()[0] curves = lis.curves(f, dfs) assert curves["КАН1"] == ["значение"] finally: dlisio.common.set_encodings(prev_encodings) f.close()
def test_fdata_samples_0(tmpdir, merge_lis_prs): fpath = os.path.join(str(tmpdir), 'dfsr-samples-0.lis') content = headers + [ 'data/lis/records/curves/dfsr-samples-0.lis.part', ] + trailers merge_lis_prs(fpath, content) with lis.load(fpath) as (f, ): dfs = f.data_format_specs()[0] with pytest.raises(ValueError) as exc: _ = lis.curves(f, dfs) assert "Invalid number of samples (0) for curve BAD" in str(exc.value)
def test_fdata_bad_data(tmpdir, merge_lis_prs): fpath = os.path.join(str(tmpdir), 'fdata-bad-data.lis') content = headers + [ 'data/lis/records/curves/dfsr-simple.lis.part', 'data/lis/records/curves/fdata-bad-fdata.lis.part', ] + trailers merge_lis_prs(fpath, content) with lis.load(fpath) as (f, ): dfs = f.data_format_specs()[0] with pytest.raises(RuntimeError) as exc: _ = lis.curves(f, dfs) assert "corrupted record: fmtstr would read past end" in str(exc.value)
def test_depth_mode_1_dir_down_nospace(tmpdir, merge_lis_prs): fpath = os.path.join(str(tmpdir), 'depth-dir-down.lis') content = headers + [ 'data/lis/records/curves/dfsr-depth-spacing-no.lis.part', ] + trailers merge_lis_prs(fpath, content) with lis.load(fpath) as (f, ): dfs = f.data_format_specs()[0] with pytest.raises(ValueError) as exc: _ = lis.curves(f, dfs) assert "No spacing recorded" in str(exc.value)
def test_fdata_dimensional_bad(tmpdir, merge_lis_prs): fpath = os.path.join(str(tmpdir), 'dimensional-bad.lis') content = headers + [ 'data/lis/records/curves/dfsr-dimensional-bad.lis.part', ] + trailers merge_lis_prs(fpath, content) with lis.load(fpath) as (f, ): dfs = f.data_format_specs()[0] with pytest.raises(RuntimeError) as exc: _ = lis.curves(f, dfs) assert "Cannot compute an integral number of entries from size (5) / " \ "repcode(79) for channel CH01" in str(exc.value)
def test_depth_mode_1_direction_bad(tmpdir, merge_lis_prs, dfsr_filename): fpath = os.path.join(str(tmpdir), 'depth-dir-bad.lis') content = headers + [ 'data/lis/records/curves/' + dfsr_filename, ] + trailers merge_lis_prs(fpath, content) with lis.load(fpath) as (f, ): dfs = f.data_format_specs()[0] with pytest.raises(RuntimeError) as exc: _ = lis.curves(f, dfs) assert "Direction flag incompatible with depth mode = 1" in str( exc.value)
def test_depth_mode_1_conversion(tmpdir, merge_lis_prs): fpath = os.path.join(str(tmpdir), 'depth-int-float-conversion') content = headers + [ 'data/lis/records/curves/dfsr-depth-conversion.lis.part', 'data/lis/records/curves/fdata-depth-down-PR1.lis.part', ] + trailers merge_lis_prs(fpath, content) with lis.load(fpath) as (f, ): dfs = f.data_format_specs()[0] with pytest.raises(RuntimeError) as exc: _ = lis.curves(f, dfs) assert "Unable to create integral index" in str(exc.value)
def test_fdata_repcodes_invalid(tmpdir, merge_lis_prs): fpath = os.path.join(str(tmpdir), 'fdata-repcodes-invalid.lis') content = headers + [ 'data/lis/records/curves/dfsr-repcodes-invalid.lis.part', ] + trailers merge_lis_prs(fpath, content) with lis.load(fpath) as (f, ): dfs = f.data_format_specs()[0] with pytest.raises(ValueError) as exc: _ = lis.curves(f, dfs) assert "Invalid representation code (170)" in str(exc.value)
def test_fdata_fast_channel_strings(tmpdir, merge_lis_prs): fpath = os.path.join(str(tmpdir), 'fast-channel-strings.lis') content = headers + [ 'data/lis/records/curves/dfsr-fast-str.lis.part', 'data/lis/records/curves/fdata-fast-str.lis.part', ] + trailers merge_lis_prs(fpath, content) with lis.load(fpath) as (f, ): dfs = f.data_format_specs()[0] curves = lis.curves(f, dfs, sample_rate=1) np.testing.assert_array_equal(curves['CH01'], np.array([1])) expected = np.array(["STR not sampled "]) np.testing.assert_array_equal(curves['CH03'], expected) curves = lis.curves(f, dfs, sample_rate=2) np.testing.assert_array_equal(curves['CH01'], np.array([0, 1])) expected = np.array(["STR sample 1 ", "STR sample 2 "]) np.testing.assert_array_equal(curves['CH02'], expected)
def test_fdata_fast_channel_first_fast(tmpdir, merge_lis_prs): fpath = os.path.join(str(tmpdir), 'fast-channel-is-first.lis') content = headers + [ 'data/lis/records/curves/dfsr-fast-first.lis.part', 'data/lis/records/curves/fdata-fast-int.lis.part', ] + trailers merge_lis_prs(fpath, content) with lis.load(fpath) as (f, ): dfs = f.data_format_specs()[0] with pytest.raises(ValueError) as exc: _ = lis.curves(f, dfs) assert "Index channel cannot be a fast channel" in str(exc.value)
def test_fdata_fast_channel_index_conversion(tmpdir, merge_lis_prs): fpath = os.path.join(str(tmpdir), 'fast-channels-index-conversion.lis') content = headers + [ 'data/lis/records/curves/dfsr-fast-conversion.lis.part', 'data/lis/records/curves/fdata-fast-conversion.lis.part', ] + trailers merge_lis_prs(fpath, content) with lis.load(fpath) as (f, ): dfs = f.data_format_specs()[0] with pytest.raises(RuntimeError) as exc: _ = lis.curves(f, dfs, sample_rate=2) assert "Unable to create integral index" in str(exc.value)
def test_fdata_fast_channel_depth(tmpdir, merge_lis_prs): fpath = os.path.join(str(tmpdir), 'fast-channel-depth.lis') content = headers + [ 'data/lis/records/curves/dfsr-fast-depth.lis.part', 'data/lis/records/curves/fdata-fast-depth.lis.part', ] + trailers merge_lis_prs(fpath, content) with lis.load(fpath) as (f, ): dfs = f.data_format_specs()[0] with pytest.raises(RuntimeError) as exc: _ = lis.curves(f, dfs) assert "Call other method to get fast channel data" in str(exc.value)
def test_fdata_fast_channel_bad(tmpdir, merge_lis_prs): fpath = os.path.join(str(tmpdir), 'fast-channel-bad.lis') content = headers + [ 'data/lis/records/curves/dfsr-fast-bad.lis.part', ] + trailers merge_lis_prs(fpath, content) with lis.load(fpath) as (f, ): dfs = f.data_format_specs()[0] # call correct method to get the error with pytest.raises(RuntimeError) as exc: _ = lis.curves(f, dfs) assert "Cannot compute an integral size for samples" in str(exc.value)
def test_fdata_size_0_one_channel(tmpdir, merge_lis_prs, dfsr_filename): fpath = os.path.join(str(tmpdir), 'dfsr-size-0.lis') content = headers + [ 'data/lis/records/curves/' + dfsr_filename, 'data/lis/records/curves/fdata-size.lis.part', ] + trailers merge_lis_prs(fpath, content) with lis.load(fpath) as (f, ): dfs = f.data_format_specs()[0] with pytest.raises(ValueError) as exc: _ = lis.curves(f, dfs) assert "size == 0" in str(exc.value)
def test_fdata_size_less_than_repcode_size(tmpdir, merge_lis_prs): fpath = os.path.join(str(tmpdir), 'dfsr-size-lt-repcode-size.lis') content = headers + [ 'data/lis/records/curves/dfsr-size-lt-repcode.lis.part', 'data/lis/records/curves/fdata-size.lis.part', ] + trailers merge_lis_prs(fpath, content) with lis.load(fpath) as (f, ): dfs = f.data_format_specs()[0] with pytest.raises(ValueError) as exc: _ = lis.curves(f, dfs) assert "Invalid number of entries per sample" in str(exc.value)
def test_depth_mode_1_direction_down(tmpdir, merge_lis_prs, dfsr_filename): fpath = os.path.join(str(tmpdir), 'depth-dir-down.lis') content = headers + [ 'data/lis/records/curves/' + dfsr_filename, 'data/lis/records/curves/fdata-depth-down-PR1.lis.part', 'data/lis/records/curves/fdata-depth-down-PR2.lis.part', 'data/lis/records/curves/fdata-depth-down-PR3.lis.part', ] + trailers merge_lis_prs(fpath, content) with lis.load(fpath) as (f, ): dfs = f.data_format_specs()[0] curves = lis.curves(f, dfs) assert curves['DEPT'] == [1, 2, 3, 4, 5] assert curves['CH01'] == [16, 17, 18, 19, 20]
def test_depth_mode_1_spacing_inconsistent(tmpdir, merge_lis_prs, dfsr_filename): fpath = os.path.join(str(tmpdir), 'depth-spacing-inconsistent.lis') content = headers + [ 'data/lis/records/curves/' + dfsr_filename, 'data/lis/records/curves/fdata-depth-down-PR1.lis.part', 'data/lis/records/curves/fdata-depth-down-PR3.lis.part', ] + trailers merge_lis_prs(fpath, content) with lis.load(fpath) as (f, ): dfs = f.data_format_specs()[0] with pytest.raises(RuntimeError) as exc: _ = lis.curves(f, dfs) assert "Depth spacing is inconsistent." in str(exc.value)
def test_depth_mode_1_direction_up(tmpdir, merge_lis_prs): fpath = os.path.join(str(tmpdir), 'depth-dir-up.lis') content = headers + [ 'data/lis/records/curves/dfsr-depth-dir-up.lis.part', 'data/lis/records/curves/fdata-depth-up-PR1.lis.part', 'data/lis/records/curves/fdata-depth-up-PR2.lis.part', 'data/lis/records/curves/fdata-depth-up-PR3.lis.part', ] + trailers merge_lis_prs(fpath, content) with lis.load(fpath) as (f, ): dfs = f.data_format_specs()[0] curves = lis.curves(f, dfs) assert curves['DEPT'] == [53, 52, 51, 50, 49] assert curves['CH01'] == [37, 36, 35, 34, 33]
def test_depth_mode_1_direction_inconsistent(tmpdir, merge_lis_prs): fpath = os.path.join(str(tmpdir), 'depth-dir-inconsistent') content = headers + [ 'data/lis/records/curves/dfsr-depth-dir-down.lis.part', 'data/lis/records/curves/fdata-depth-up-PR1.lis.part', 'data/lis/records/curves/fdata-depth-up-PR2.lis.part', 'data/lis/records/curves/fdata-depth-up-PR3.lis.part', ] + trailers merge_lis_prs(fpath, content) with lis.load(fpath) as (f, ): dfs = f.data_format_specs()[0] with pytest.raises(RuntimeError) as exc: _ = lis.curves(f, dfs) assert "Declared direction doesn't match actual data" in str(exc.value)
def test_read_curves(): path = 'data/lis/MUD_LOG_1.LIS' #TODO proper curves testing with lis.load(path) as (_, lf, _): dfs = lf.dfsr()[1] curves = lis.curves(lf, dfs) assert len(curves) == 3946 ch = curves['DEPT'][0:5] expected = np.array([145.0, 146.0, 147.0, 148.0, 149.0]) np.testing.assert_array_equal(expected, ch) ch = curves['BDIA'][0:5] expected = np.array([36.0, 36.0, 36.0, 36.0, 36.0]) np.testing.assert_array_equal(expected, ch)
def test_fdata_no_channels(tmpdir, merge_lis_prs): fpath = os.path.join(str(tmpdir), 'dfsr-no-channels.lis') content = headers + [ 'data/lis/records/curves/dfsr-entries-default.lis.part', 'data/lis/records/curves/fdata-size.lis.part', ] + trailers merge_lis_prs(fpath, content) with lis.load(fpath) as (f, ): dfs = f.data_format_specs()[0] with pytest.raises(ValueError) as exc: _ = lis.curves(f, dfs) msg = "DataFormatSpec() has no channels" assert msg in str(exc.value)
def test_fdata_size_0(tmpdir, merge_lis_prs, dfsr_filename): fpath = os.path.join(str(tmpdir), 'dfsr-size-0.lis') content = headers + [ 'data/lis/records/curves/' + dfsr_filename, 'data/lis/records/curves/fdata-size.lis.part', ] + trailers merge_lis_prs(fpath, content) with lis.load(fpath) as (f, ): dfs = f.data_format_specs()[0] with pytest.raises(ValueError) as exc: _ = lis.curves(f, dfs) msg = "Invalid size (0) for curve BAD , should be != 0" assert msg in str(exc.value)
def test_curve_metadata_mode_1(tmpdir, merge_lis_prs): fpath = os.path.join(str(tmpdir), 'fastmeta1.lis') content = headers + [ 'data/lis/records/curves/dfsr-fast-depth.lis.part', ] + trailers merge_lis_prs(fpath, content) with lis.load(fpath) as (f, *_): dfs = f.data_format_specs()[0] for rate in dfs.sample_rates(): curves = lis.curves(f, dfs, sample_rate=rate, strict=False) channels = lis.curves_metadata(dfs, sample_rate=rate, strict=False) assert list(curves.dtype.names) == list(channels.keys()) assert channels['DEPT'] == None
def test_fdata_repcodes_string(tmpdir, merge_lis_prs): fpath = os.path.join(str(tmpdir), 'fdata-repcodes-string.lis') content = headers + [ 'data/lis/records/curves/dfsr-repcodes-string.lis.part', 'data/lis/records/curves/fdata-repcodes-string.lis.part', ] + trailers merge_lis_prs(fpath, content) with lis.load(fpath) as (f, ): dfs = f.data_format_specs()[0] fmt = core.dfs_formatstring(dfs) assert fmt == 'a32' curves = lis.curves(f, dfs) assert curves['STR '] == "Now this is a string of size 32 "
def test_fdata_dimensional_ints(tmpdir, merge_lis_prs): fpath = os.path.join(str(tmpdir), 'dimensional-ints.lis') content = headers + [ 'data/lis/records/curves/dfsr-dimensional-int.lis.part', 'data/lis/records/curves/fdata-dimensional-int.lis.part', ] + trailers merge_lis_prs(fpath, content) with lis.load(fpath) as (f, ): dfs = f.data_format_specs()[0] curves = lis.curves(f, dfs) expected = np.array([[1, 2], [4, 5]]) np.testing.assert_array_equal(expected, curves['CH01']) expected = np.array([3, 6]) np.testing.assert_array_equal(expected, curves['CH02'])
def test_dfsr_subtype1(tmpdir, merge_lis_prs): fpath = os.path.join(str(tmpdir), 'dfsr-subtype1.lis') content = headers + [ 'data/lis/records/curves/dfsr-subtype1.lis.part', ] + trailers merge_lis_prs(fpath, content) with lis.load(fpath) as (f, ): dfs = f.data_format_specs()[0] ch1 = dfs.specs[0] assert ch1.mnemonic == "CH01" assert ch1.service_id == "testCH" assert ch1.service_order_nr == " 1234 " assert ch1.units == "INCH" assert ch1.api_codes == 45310011 assert ch1.filenr == 1 assert ch1.reserved_size == 4 assert ch1.samples == 1 assert ch1.reprc == 73 flags = ch1.process_indicators assert flags.original_logging_direction == 3 assert flags.true_vertical_depth_correction == True assert flags.data_channel_not_on_depth == True assert flags.data_channel_is_filtered == True assert flags.data_channel_is_calibrated == True assert flags.computed == True assert flags.derived == True assert flags.tool_defined_correction_nb_2 == True assert flags.tool_defined_correction_nb_1 == True assert flags.mudcake_correction == True assert flags.lithology_correction == True assert flags.inclinometry_correction == True assert flags.pressure_correction == True assert flags.hole_size_correction == True assert flags.temperature_correction == True assert flags.auxiliary_data_flag == True assert flags.schlumberger_proprietary == True curves = lis.curves(f, dfs) assert len(curves) == 0
def test_curve_metadata_mode_0_duplicated(tmpdir, merge_lis_prs): fpath = os.path.join(str(tmpdir), 'same-mnemonics.lis') content = headers + [ 'data/lis/records/curves/dfsr-mnemonics-same.lis.part', ] + trailers merge_lis_prs(fpath, content) with lis.load(fpath) as (f, *_): dfs = f.data_format_specs()[0] with pytest.raises(ValueError) as exc: _ = lis.curves_metadata(dfs, sample_rate=1, strict=True) assert 'duplicated mnemonics' in str(exc.value) curves = lis.curves(f, dfs, sample_rate=1, strict=False) channels = lis.curves_metadata(dfs, sample_rate=1, strict=False) assert list(curves.dtype.names) == list(channels.keys()) assert channels['NAME(0)'] == dfs.specs[0]
def test_fdata_repcodes_mask(tmpdir, merge_lis_prs): fpath = os.path.join(str(tmpdir), 'fdata-repcodes-mask.lis') content = headers + [ 'data/lis/records/curves/dfsr-repcodes-mask.lis.part', 'data/lis/records/curves/fdata-repcodes-mask.lis.part', ] + trailers merge_lis_prs(fpath, content) with lis.load(fpath) as (f, ): dfs = f.data_format_specs()[0] with pytest.raises(NotImplementedError): fmt = core.dfs_formatstring(dfs) assert fmt == 'm' with pytest.raises(NotImplementedError): curves = lis.curves(f, dfs) assert curves['MASK'] == bytearray([0xFF, 0xFF, 0xFF, 0xFF])