Commit 518f0899 authored by Gregory Harris's avatar Gregory Harris
Browse files

Support multiple files in file_load

parent 9b2568de
from pathlib import Path
from knack.log import get_logger
from lasloader.file_loader import LasParser, LocalFileLoader
from lasloader.file_loader import LasParser, LocalFileLoader, FileUtilities
from lasloader.record_mapper import LasToRecordMapper
from lasloader.configuration import Configuration
from lasloader.json_writer import JsonToFile
......@@ -12,38 +12,42 @@ logger = get_logger(__name__)
def printlas(input_path):
"""
Print a LAS file header
:param str input_path: Path and filename of a LAS file
:param str input_path: Path and filename of a LAS file or folder or LAS files
"""
las_parser = LasParser(LocalFileLoader())
las_data = las_parser.load_las_file(input_path)
print(las_data.header)
for file_path in FileUtilities.get_filenames(Path(input_path), '.las'):
logger.warning(f"LAS file: {file_path}")
las_data = las_parser.load_las_file(input_path)
print(las_data.header)
print("")
def convert(input_path: str, config_path: str, wellbore_id: str):
"""
Convert a LAS file to Wellbore and Well Log and write to json files.
:param str input_path: Path and filename of a LAS file
:param str input_path: Path and filename of a LAS file or folder containing LAS files
:param str config_path: Path to the LAS metadata file
:param str wellbore_id: The wellbore id
"""
las_parser = LasParser(LocalFileLoader())
las_data = las_parser.load_las_file(input_path)
config = Configuration(LocalFileLoader(), config_path)
mapper = LasToRecordMapper(las_data, config)
logger.info("Mapping LAS file to wellbore and well log records.")
wellbore_record = mapper.map_to_wellbore_record()
welllog_record = mapper.map_to_well_log_record(wellbore_id)
for file_path in FileUtilities.get_filenames(Path(input_path), '.las'):
logger.warning(f"LAS file: {file_path}")
las_data = las_parser.load_las_file(file_path)
mapper = LasToRecordMapper(las_data, config)
wellbore_record = mapper.map_to_wellbore_record()
welllog_record = mapper.map_to_well_log_record(wellbore_id)
path = Path(input_path)
writer = JsonToFile()
path = Path(file_path)
writer = JsonToFile()
logger.info("Writing wellbore and well log records to JSON files.")
writer.write(vars(wellbore_record), path.with_suffix('.wellbore.json'))
logger.warning(f"Wellbore record file created: {path.with_suffix('.wellbore.json')}")
writer.write(vars(welllog_record), path.with_suffix('.welllog.json'))
logger.warning(f"Well log record file created: {path.with_suffix('.welllog.json')}")
logger.info("Writing wellbore and well log records to JSON files.")
writer.write(vars(wellbore_record), path.with_suffix('.wellbore.json'))
logger.warning(f"Wellbore record file created: {path.with_suffix('.wellbore.json')}")
writer.write(vars(welllog_record), path.with_suffix('.welllog.json'))
logger.warning(f"Well log record file created: {path.with_suffix('.welllog.json')}")
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment