Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GEOPY-1413: Move all optional parameters to general tabs #27

Merged
merged 2 commits into from
Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 25 additions & 27 deletions las_geoh5/export_directories/uijson.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,30 @@
# (see LICENSE file at the root of this source code package).
#

from copy import deepcopy

ui_json = {
"title": "Drillhole group to LAS file directories",
"geoh5": None,
"run_command": "las_geoh5.export_directories.driver",
"run_command_boolean": {
"value": False,
"label": "Run python module",
"main": True,
"tooltip": "Warning: launches process to run python model on save",
},
"monitoring_directory": None,
"conda_environment": "las-geoh5",
"conda_environment_boolean": False,
"workspace": None,
"drillhole_group": {
"main": True,
"label": "Drillhole group",
"value": None,
"groupType": ["{825424fb-c2c6-4fea-9f2b-6cd00023d393}"],
},
"name": {
"main": True,
"label": "Property group name",
"value": None,
"optional": True,
"enabled": False,
from geoh5py.ui_json.constants import default_ui_json

# pylint: disable=duplicate-code

ui_json = dict(
deepcopy(default_ui_json),
**{
"title": "Drillhole group to LAS file directories",
"run_command": "las_geoh5.export_directories.driver",
"conda_environment": "las-geoh5",
"drillhole_group": {
"main": True,
"label": "Drillhole group",
"value": None,
"groupType": ["{825424fb-c2c6-4fea-9f2b-6cd00023d393}"],
},
"name": {
"main": True,
"label": "Property group name",
"value": None,
"optional": True,
"enabled": False,
},
},
}
)
1 change: 1 addition & 0 deletions las_geoh5/import_directories/uijson.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@
**{
"title": "LAS file directories to Drillhole group",
"run_command": "las_geoh5.import_directories.driver",
"conda_environment": "las-geoh5",
}
)
57 changes: 42 additions & 15 deletions las_geoh5/import_files/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,40 @@
from las_geoh5.import_files.params import ImportOptions, NameOptions
from las_geoh5.import_las import las_to_drillhole

logger = logging.getLogger("Import Files")
logger.setLevel(logging.INFO)
stream_handler = logging.StreamHandler()
file_handler = logging.FileHandler("import_las_files.log")
formatter = logging.Formatter("%(asctime)s : %(name)s : %(levelname)s : %(message)s")
file_handler.setFormatter(formatter)
stream_handler.setFormatter(formatter)
file_handler.setLevel(logging.INFO)
stream_handler.setLevel(logging.INFO)
logger.addHandler(file_handler)
logger.addHandler(stream_handler)

def get_logger(
name: str, level: int = logging.INFO, path: str | Path | None = None
) -> logging.Logger:
"""
Create a looger with stream and optional file handlers.

:param name: Logger name.
:param level: logging level.
:param path: Creates a file handler at the specified path if not None.
:return: Logger object.
"""
if isinstance(path, str):
path = Path(path)

Check warning on line 40 in las_geoh5/import_files/driver.py

View check run for this annotation

Codecov / codecov/patch

las_geoh5/import_files/driver.py#L40

Added line #L40 was not covered by tests

logger = logging.getLogger(name)
logger.setLevel(level)
formatter = logging.Formatter(
"%(asctime)s : %(name)s : %(levelname)s : %(message)s"
)

stream_handler = logging.StreamHandler()
stream_handler.setFormatter(formatter)
stream_handler.setLevel(level)
logger.addHandler(stream_handler)

if path is not None:
filename = f"{'_'.join([k.lower() for k in name.split(' ')])}.log"
file_handler = logging.FileHandler(path / filename)
file_handler.setFormatter(formatter)
file_handler.setLevel(level)
logger.addHandler(file_handler)

return logger


def elapsed_time_logger(start, end, message):
Expand All @@ -53,10 +76,11 @@
return out


def run(filepath: str): # pylint: disable=too-many-locals
def run(filepath: Path): # pylint: disable=too-many-locals
start = time()
ifile = InputFile.read_ui_json(filepath)

logger = get_logger("Import Files", path=filepath.parent)
logger.info(
"Importing las file data to workspace %s.geoh5.",
ifile.data["geoh5"].h5file.stem,
Expand All @@ -65,6 +89,9 @@
workspace = Workspace()
begin_reading = time()

# lasfiles = []
# for file in ifile.data["files"].split(";"):
# lasfiles.append(lasio.read(file, mnemonic_case="preserve"))
domfournier marked this conversation as resolved.
Show resolved Hide resolved
with Pool() as pool:
futures = []
for file in tqdm(ifile.data["files"].split(";"), desc="Reading las files"):
Expand Down Expand Up @@ -105,9 +132,9 @@
)
end = time()
logger.info(elapsed_time_logger(start, end, "All done."))
logpath = Path(file_handler.baseFilename)
logpath = Path(logger.handlers[1].baseFilename) # type: ignore
dh_group.add_file(logpath)
file_handler.close()
logger.handlers[1].close()
logpath.unlink()

if ifile.data["monitoring_directory"]:
Expand All @@ -130,4 +157,4 @@


if __name__ == "__main__":
run(sys.argv[1])
run(Path(sys.argv[1]))

Check warning on line 160 in las_geoh5/import_files/driver.py

View check run for this annotation

Codecov / codecov/patch

las_geoh5/import_files/driver.py#L160

Added line #L160 was not covered by tests
3 changes: 0 additions & 3 deletions las_geoh5/import_files/params.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from pydantic import BaseModel, ConfigDict, model_validator

LAS_GEOH5_STANDARD = {
"depth_name": "DEPTH",
"collar_x_name": "X",
"collar_y_name": "Y",
"collar_z_name": "ELEV",
Expand All @@ -19,14 +18,12 @@ class NameOptions(BaseModel):
"""
Stores options for naming of dillhole parameters in las files.

:param depth_name: Name of the depth field.
:param collar_x_name: Name of the collar x field.
:param collar_y_name: Name of the collar y field.
:param collar_z_name: Name of the collar z field.
"""

well_name: str = "WELL"
depth_name: str = "DEPTH"
collar_x_name: str = "X"
collar_y_name: str = "Y"
collar_z_name: str = "ELEV"
Expand Down
65 changes: 39 additions & 26 deletions las_geoh5/import_files/uijson.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,21 @@

from copy import deepcopy

from las_geoh5.export_directories.uijson import ui_json
from geoh5py.ui_json.constants import default_ui_json

# pylint: disable=duplicate-code

ui_json = dict(
deepcopy(ui_json),
deepcopy(default_ui_json),
**{
"title": "LAS files to Drillhole group",
"run_command": "las_geoh5.import_files.driver",
"name": {
"conda_environment": "las-geoh5",
"drillhole_group": {
"main": True,
"label": "Name",
"value": "",
"label": "Drillhole group",
"value": None,
"groupType": ["{825424fb-c2c6-4fea-9f2b-6cd00023d393}"],
},
"files": {
"main": True,
Expand All @@ -28,44 +32,52 @@
"fileType": ["las"],
"fileMulti": True,
},
"depths_name": {
"label": "Depths",
"value": "DEPTH",
"group": "Import fields",
"optional": True,
"enabled": False,
"name": {
"main": True,
"label": "Property group name",
"group": "Property group",
"value": "",
},
"collocation_tolerance": {
"main": True,
"label": "Collocation tolerance",
"group": "Property group",
"value": 0.01,
"tooltip": (
"Tolerance for determining collocation of data locations "
"and ultimately deciding if incoming data should belong to "
"an existing property group.",
),
},
"collar_x_name": {
"label": "Collar x",
"main": True,
"label": "Easting",
"tooltip": "Name of header field containing the collar easting.",
"value": "X",
"group": "Import fields",
"group": "Collar",
"optional": True,
"enabled": False,
},
"collar_y_name": {
"label": "Collar y",
"main": True,
"label": "Northing",
"tooltip": "Name of header field containing the collar northing.",
"value": "Y",
"group": "Import fields",
"group": "Collar",
"optional": True,
"enabled": False,
},
"collar_z_name": {
"label": "Collar z",
"main": True,
"tooltip": "Name of header field containing the collar elevation.",
"label": "Elevation",
"value": "ELEV",
"group": "Import fields",
"group": "Collar",
"optional": True,
"enabled": False,
},
"collocation_tolerance": {
"label": "Collocation tolerance",
"value": 0.01,
"tooltip": (
"Tolerance for determining collocation of data locations "
"and ultimately deciding if incoming data should belong to "
"an existing property group.",
),
},
"skip_empty_header": {
"main": True,
"label": "Skip empty header",
"value": False,
"tooltip": (
Expand All @@ -75,6 +87,7 @@
),
},
"warnings": {
"main": True,
"label": "Warnings",
"value": True,
"tooltip": "Show warnings during import.",
Expand Down
8 changes: 4 additions & 4 deletions las_geoh5_assets/uijson/export_las_directories.ui.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
"run_command": "las_geoh5.export_directories.driver",
"run_command_boolean": {
"value": false,
"label": "Run python module",
"main": true,
"tooltip": "Warning: launches process to run python model on save"
"label": "Run python module ",
"tooltip": "Warning: launches process to run python model on save",
"main": true
},
"monitoring_directory": "",
"conda_environment": "las-geoh5",
Expand All @@ -27,4 +27,4 @@
"optional": true,
"enabled": false
}
}
}
8 changes: 4 additions & 4 deletions las_geoh5_assets/uijson/import_las_directories.ui.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
"run_command": "las_geoh5.import_directories.driver",
"run_command_boolean": {
"value": false,
"label": "Run python module",
"main": true,
"tooltip": "Warning: launches process to run python model on save"
"label": "Run python module ",
"tooltip": "Warning: launches process to run python model on save",
"main": true
},
"monitoring_directory": "",
"conda_environment": "las-geoh5",
Expand All @@ -27,4 +27,4 @@
"optional": true,
"enabled": false
}
}
}
Loading
Loading