def striplog_from_text(filename, lexicon=None): """ creates a Striplog object from a las or flat text file Parameters ---------- Lexicon : dict A vocabulary for parsing lithologic or stratigraphic descriptions (default set to Lexicon.default() if lexicon is None) Returns ------- strip: striplog object """ if lexicon is None: lexicon = Lexicon.default() if re.compile(r".+\.las").match(filename): print(f"File {filename:s} OK! Creation of the striplog ...") with open(filename, 'r') as las3: strip = Striplog.from_las3(las3.read(), lexicon) elif re.compile(r".+\.(csv|txt)").match(filename): print(f"File {filename:s} OK! Creation of the striplog ...") f = re.DOTALL | re.IGNORECASE regex_data = r'start.+?\n(.+?)(?:\n\n+|\n*\#|\n*$)' # retrieve data of BH pattern = re.compile(regex_data, flags=f) with open(filename, 'r') as csv: text = pattern.search(csv.read()).group(1) text = re.sub(r'[\t]+', ';', re.sub(r'(\n+|\r\n|\r)', '\n', text.strip())) strip = Striplog.from_descriptions(text, dlm=';', lexicon=lexicon) else: print("Error! Please check the file extension !") raise return strip
def test_from_descriptions(): """Test the CSV route. """ lexicon = Lexicon.default() strip2 = Striplog.from_descriptions(text=csv_intervals, lexicon=lexicon) assert len(strip2.unique) == 7
def test_from_descriptions(): """Test the CSV route. """ lexicon = Lexicon.default() strip2 = Striplog.from_descriptions(text=csv_intervals, lexicon=lexicon) assert len(strip2.top) == 7