def add_curves_from_las(self, fname, remap=None, funcs=None): """ Given a LAS file, add curves from it to the current well instance. Essentially just wraps ``add_curves_from_lasio()``. Args: fname (str): The path of the LAS file to read curves from. remap (dict): Optional. A dict of 'old': 'new' LAS field names. funcs (dict): Optional. A dict of 'las field': function() for implementing a transform before loading. Can be a lambda. Returns: None. Works in place. """ try: # To treat as a single file self.add_curves_from_lasio(lasio.read(fname), remap=remap, funcs=funcs ) except: # It's a list! for f in fname: self.add_curves_from_lasio(lasio.read(f), remap=remap, funcs=funcs ) return None
def file_test(rows=500000, cols=50): "File test" print("Creating file with {} rows and {} columns".format(rows, cols)) file = create_file(rows, cols) print("Size of the file: {:.2f} MiB".format(getsize(file) / (1024 * 1024))) print("Reading file") sum1 = summarize(get_objects()) las = read(file) sum2 = summarize(get_objects()) diff = get_diff(sum1, sum2) print_(diff) for curve in las.curves: print("Name: {}, Min: {:.2f}, Mean: {:.2f}, Max: {:.2f}" .format(curve.mnemonic, nanmin(curve.data), nanmean(curve.data), nanmax(curve.data))) del las las = read(file) del las las = read(file) del las las = read(file) del las print("Happy end")
def test_pickle_default_wb(): las = read(egfn('sample.las')) with open('binary_serialization', 'wb') as fw: pickle.dump(las, fw) with open('binary_serialization', 'rb') as fr: las = pickle.load(fr) os.remove('binary_serialization')
def test_write_wrapped(): fn = stegfn("1.2", "sample_wrapped.las") l = read(fn) s = StringIO() l.write(s, version=2.0, wrap=True, fmt="%.5f") s.seek(0) assert s.read() == """~Version ---------------------------------------------------
def test_write_sect_widths_12_curves(): l = read(egfn("sample_write_sect_widths_12.las")) s = StringIO() l.write(s, version=1.2) for start in ("D.M ", "A.US/M ", "B.K/M3 ", "C.V/V "): s.seek(0) assert "\n" + start in s.read()
def test_df_indexing(): l = read(egfn("6038187_v1.2.las")) metres = 9.05 spacing = l.well["STEP"].value calc_index = math.floor((metres / spacing) - (l.well["STRT"].value / spacing)) calc_index = int(calc_index) assert l["GAMN"][calc_index] == l.df()["GAMN"][metres]
def test_df_reverse(): l = read(egfn("sample_rev.las")) metres = 1667 spacing = l.well["STEP"].value calc_index = math.floor((metres // spacing) - (l.well["STRT"].value // spacing)) calc_index = int(calc_index) assert l["DT"][calc_index] == l.df()["DT"][metres]
def test_write_units(): l = read(egfn("sample.las")) l.curves[0].unit = 'FT' s = StringIO() l.write(s, version=2, wrap=False, fmt="%.5f") s.seek(0) assert s.read() == '''~Version ---------------------------------------------------
def single_convert(input_file, output_file): l = lasio.read(input_file) k = 0.3048 l_dt = l["DT"] # muS/ft l_dt_muSm = l_dt / 0.3048; l.add_curve("DTm", l_dt_muSm) with open(output_file, mode='w') as f: l.write(f)
def test_data_characters_types(): from pandas.api.types import is_object_dtype from pandas.api.types import is_float_dtype las = lasio.read(egfn('data_characters.las')) assert is_object_dtype(las.df().index.dtype) assert is_object_dtype(las.df()['DATE'].dtype) assert is_float_dtype(las.df()['DEPT'].dtype) assert is_float_dtype(las.df()['ARC_GR_UNC_RT'].dtype)
def test_df_curve_addition_on_export(): l = read(egfn("sample.las")) df = l.df() df["ILD_COND"] = 1000 / df.ILD l.set_data_from_df(df, truncate=False) s = StringIO() l.write(s, version=2, wrap=False, fmt="%.5f") s.seek(0) assert s.read() == """~Version ---------------------------------------------------
def test_keys_curve_mnemonics(): l = read(egfn("sample.las")) # DEPT.M : 1 DEPTH # DT .US/M : 2 SONIC TRANSIT TIME # RHOB.K/M3 : 3 BULK DENSITY # NPHI.V/V : 4 NEUTRON POROSITY # SFLU.OHMM : 5 RXO RESISTIVITY # SFLA.OHMM : 6 SHALLOW RESISTIVITY # ILM .OHMM : 7 MEDIUM RESISTIVITY # ILD .OHMM : 8 DEEP RESISTIVITY assert l.keys() == ['DEPT', 'DT', 'RHOB', 'NPHI', 'SFLU', 'SFLA', 'ILM', 'ILD']
def read_lases_from_dir(dir_name): files = os.listdir(dir_name) tmp = [] for f in files: try: l = lasio.read(os.path.join(dir_name + '/' + f)) if not (l['GR'] is None): tmp.append(nan_interp(np.array(l['GR']))) # interpolating all nan from GR except Exception: raise return tmp
def test_multi_curve_mnemonics_gr(): l = read(egfn('sample_issue105_c.las')) assert l.keys() == [c.mnemonic for c in l.curves] == ['DEPT', 'GR:1', 'GR:2', 'GR[0]', 'GR[1]', 'GR[2]', 'GR[3]', 'GR[4]', 'GR[5]'] # DEPT.M : 1 DEPTH # GR.gAPI: mean gamma ray value # GR.gAPI: corrected gamma ray value # GR[0].gAPI: gamma ray image at angle 0 dega # GR[1].gAPI: gamma ray image at angle 60 dega # GR[2].gAPI: gamma ray image at angle 120 dega # GR[3].gAPI: gamma ray image at angle 180 dega # GR[4].gAPI: gamma ray image at angle 240 dega # GR[5].gAPI: gamma ray image at angle 300 dega
def test_open_string(): l = read("""~VERSION INFORMATION VERS. 1.2: CWLS LOG ASCII STANDARD -VERSION 1.2 WRAP. NO: ONE LINE PER DEPTH STEP ~WELL INFORMATION BLOCK #MNEM.UNIT DATA TYPE INFORMATION #--------- ------------- ------------------------------ STRT.M 1670.000000: STOP.M 1660.000000: STEP.M -0.1250: NULL. -999.2500: COMP. COMPANY: # ANY OIL COMPANY LTD. WELL. WELL: ANY ET AL OIL WELL #12 FLD . FIELD: EDAM LOC . LOCATION: A9-16-49-20W3M PROV. PROVINCE: SASKATCHEWAN SRVC. SERVICE COMPANY: ANY LOGGING COMPANY LTD. DATE. LOG DATE: 25-DEC-1988 UWI . UNIQUE WELL ID: 100091604920W300 ~CURVE INFORMATION #MNEM.UNIT API CODE CURVE DESCRIPTION #--------- ------------- ------------------------------ DEPT.M : 1 DEPTH DT .US/M : 2 SONIC TRANSIT TIME RHOB.K/M3 : 3 BULK DENSITY NPHI.V/V : 4 NEUTRON POROSITY SFLU.OHMM : 5 RXO RESISTIVITY SFLA.OHMM : 6 SHALLOW RESISTIVITY ILM .OHMM : 7 MEDIUM RESISTIVITY ILD .OHMM : 8 DEEP RESISTIVITY ~PARAMETER INFORMATION #MNEM.UNIT VALUE DESCRIPTION #--------- ------------- ------------------------------ BHT .DEGC 35.5000: BOTTOM HOLE TEMPERATURE BS .MM 200.0000: BIT SIZE FD .K/M3 1000.0000: FLUID DENSITY MATR. 0.0000: NEUTRON MATRIX(0=LIME,1=SAND,2=DOLO) MDEN. 2710.0000: LOGGING MATRIX DENSITY RMF .OHMM 0.2160: MUD FILTRATE RESISTIVITY DFD .K/M3 1525.0000: DRILL FLUID DENSITY ~Other Note: The logging tools became stuck at 625 meters causing the data between 625 meters and 615 meters to be invalid. ~A DEPTH DT RHOB NPHI SFLU SFLA ILM ILD 1670.000 123.450 2550.000 0.450 123.450 123.450 110.200 105.600 1669.875 123.450 2550.000 0.450 123.450 123.450 110.200 105.600 1669.750 123.450 2550.000 0.450 123.450 123.450 110.200 105.600 """)
def from_las(cls, fname): """Wraps lasio """ params = {} l = lasio.read(fname) curves = [Curve(c, basis=l['DEPT']) for c in l.curves] params = {'las': l, 'header': Header.from_lasio_well(l.well), 'location': Location(l.well), 'curves': curves, } return cls(params)
def from_las(cls, fname, remap=None, funcs=None): """ Constructor. Essentially just wraps ``from_lasio()``, but is more convenient for most purposes. Args: fname (str): The path of the LAS file. remap (dict): Optional. A dict of 'old': 'new' LAS field names. funcs (dict): Optional. A dict of 'las field': function() for implementing a transform before loading. Can be a lambda. Returns: well. The well object. """ l = lasio.read(fname) # Pass to other constructor. return cls.from_lasio(l, remap=remap, funcs=funcs)
def add_curves_from_las(self, fname, remap=None, funcs=None): """ Given a LAS file, add curves from it to the current well instance. Essentially just wraps ``add_curves_from_lasio()``. Args: fname (str): The path of the LAS file to read curves from. remap (dict): Optional. A dict of 'old': 'new' LAS field names. funcs (dict): Optional. A dict of 'las field': function() for implementing a transform before loading. Can be a lambda. Returns: None. Works in place. """ l = lasio.read(fname) # Pass to other constructor. return self.add_curves_from_lasio(l, remap=remap, funcs=funcs)
def las_hdr_extract(las_ls): #Open file for storing results. f = open('./test', 'w') # Loop through header extraction. for i in range(len(las_ls)): d = lasio.read(las_ls[i]) uwi = d.well["UWI"].value wlnam = d.well["WELL-NAME"].value fldnam = d.well["FIELD-NAME"].value long = str(d.well["LONG"].value) lati = str(d.well["LATI"].value) output = uwi + ', ' + str(wlnam) + ', ' + str(fldnam) + ', ' + str(long) + ', ' + str(lati) + '\n' try: f.write(output) except: print(las_ls[i]) continue #return uwi, wlnam, fldnam, long, lati # Legacy code # close file leaving it ready for use f.close()
def test_missing_STRT_STOP(): las = lasio.read(egfn("sample_TVD.las")) assert len(las.well) == 12
def test_issue_201_non_delimiter_colon_end(): las = lasio.read(egfn("colon_pick_end.las")) assert las.params["TCS"].descr == "Time Circ. Stopped" assert las.params["TIML"].unit == "hh:mm" assert las.params["TIML"].value == "23:15 23-JAN-2001" assert las.params["TIML"].descr == "Time Logger At Bottom:"
def test_missing_wrap_write_wrap_none_fails(): l = lasio.read(egfn("missing_wrap.las")) with pytest.raises(KeyError): l.write(sys.stdout, wrap=None)
def test_read_v12_sample_curve_api(): l = lasio.read(stegfn("1.2", "sample_curve_api.las"))
def test_comma_decimal_mark_params(): las = lasio.read(egfn("comma_decimal_mark.las")) assert las.params["MDEN"].value == 2710.1
def test_missing_null_loads(): l = lasio.read(egfn("missing_null.las"))
def test_df_curve_names(): l = read(egfn("sample_rev.las"), use_pandas=True) assert l.keys() == list(l.df.columns.values)
def test_blank_line_in_header(): las = lasio.read(egfn("blank_line.las")) assert las.curves[0].mnemonic == "DEPT"
def test_curves_attribute(): l = read(egfn("sample.las")) assert isinstance(l.curves[1], las.CurveItem)
def test_barebones_missing_all_sections(): las = lasio.read(egfn("barebones2.las")) assert las.curves[-1].mnemonic == "UNKNOWN:8"
def test_issue92(): las = lasio.read(egfn("issue92.las"), ignore_header_errors=True)
def test_read_v12_sample_minimal(): l = lasio.read(stegfn("1.2", "sample_minimal.las"))
def test_UWI_API_leading_zero(): las = lasio.read(egfn("UWI_API_leading_zero.las")) assert las.well["UWI"].value == "05123370660000"
def test_read_cyrillic_depth_unit(): las = lasio.read(egfn("sample_cyrillic_depth_unit.las")) assert las.index_unit == "M"
def test_autodepthindex(): m = read(egfn("autodepthindex_M.las")) f = read(egfn("autodepthindex_F.las")) ft = read(egfn("autodepthindex_FT.las")) err = read(egfn("autodepthindex_M_FT.las"))
def test_barebones(): las = lasio.read(egfn("barebones.las")) assert las["DEPT"][1] == 201
def test_autodepthindex_m(): l = read(egfn("autodepthindex_M.las")) assert (l.depth_ft[-1] * 0.3048 == l.index[-1])
def test_missing_a_section(): las = lasio.read(egfn("missing_a_section.las")) assert las.data.size == 0
def test_duplicate_step(): las = lasio.read(egfn("duplicate_step.las"))
def test_missing_null_missing_headeritem(): l = lasio.read(egfn("missing_null.las")) assert not "NULL" in l.well
def test_comma_decimal_mark_data(): las = lasio.read(egfn("comma_decimal_mark.las")) assert las["SFLU"][1] == 123.42
def test_missing_wrap_write_wrap_specified_works(): l = lasio.read(egfn("missing_wrap.las")) l.write(sys.stdout, wrap=True)
def test_read_incorrect_shape(): with pytest.raises(ValueError): lasio.read(egfn("sample_lastcolblanked.las"))
def test_read_v12_sample(): l = lasio.read(stegfn("1.2", "sample.las"))
def test_read_v2_sample(): l = lasio.read(stegfn("2.0", "sample_2.0.las"))
def test_df_indexing(): l = read(egfn("6038187_v1.2.las"), use_pandas=True) metres = 9.05 spacing = l.well["STEP"].value calc_index = (metres / spacing) - (l.well["STRT"].value / spacing) assert l["GAMN"][calc_index] == l.df.GAMN[metres]
def test_blank_line_at_start(): las = lasio.read(egfn("blank_line_start.las"))
def test_emptyparam(capsys): las = lasio.read(egfn("emptyparam.las")) out, err = capsys.readouterr() msg = "Header section Parameter regexp=~P is empty." assert not msg in out
def test_not_a_las_file(): with pytest.raises(KeyError): las = lasio.read(egfn("not_a_las_file.las"))
def test_get_curves_method(): l = read(egfn("sample.las")) assert l.get_curve('DT') == l.curves[1]
def test_data_characters_1(): las = lasio.read(egfn("data_characters.las")) assert las["TIME"][0] == "00:00:00"
def test_df_reverse(): l = read(egfn("sample_rev.las"), use_pandas=True) metres = 1667 spacing = l.well["STEP"].value calc_index = (metres / spacing) - (l.well["STRT"].value / spacing) assert l["DT"][calc_index] == l.df.DT[metres]
def test_data_characters_2(): las = lasio.read(egfn("data_characters.las")) assert las["DATE"][0] == "01-Jan-20"
def test_utf8_default(): fn = egfn("sample_extended_chars_utf8.las") l = read(fn)
def test_read_v12_sample_wrapped(): l = lasio.read(stegfn("1.2", "sample_wrapped.las"))
def test_autodepthindex_inconsistent(): err = read(egfn("autodepthindex_M_FT.las")) with pytest.raises(las.LASUnknownUnitError): print(err.depth_m)
def test_strip_square_brackets(): las = lasio.read(egfn("sample_bracketed_units.las")) assert las.curves[0].unit == "M"
def test_autodepthindex_ft(): l = read(egfn("autodepthindex_FT.las")) assert (l.depth_m[-1] / 0.3048 == l.index[-1])
def test_index_unit_equals_f(): las = lasio.read(egfn("autodepthindex_M.las"), index_unit="f") assert (las.depth_ft == las.index).all()
def test_use_pandas_False(): l = read(egfn("6038187_v1.2.las"), use_pandas=False) l.df assert True
def test_index_unit_equals_m(): las = lasio.read(egfn("autodepthindex_M.las"), index_unit="m") assert (las.depth_ft[1:] != las.index[1:]).all()