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-1708: Import fails on version number of las #53

Merged
merged 2 commits into from
Aug 6, 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
4 changes: 2 additions & 2 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@
html_static_path = ["_static"]

# The short X.Y version.
version = "0.3.0"
version = "0.2.1"
# The full version, including alpha/beta/rc tags.
release = "0.3.0-alpha.1"
release = "0.2.1-alpha.1"
99 changes: 97 additions & 2 deletions las_geoh5/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@
# flake8: noqa

from __future__ import annotations

import re
from pathlib import Path
from lasio import reader

__version__ = "0.3.0-alpha.1"
__version__ = "0.2.1-alpha.1"


def assets_path() -> Path:
Expand All @@ -25,3 +26,97 @@
raise RuntimeError(f"Assets folder not found: {assets_folder}")

return assets_folder


# TODO: Propose change on lasio to fix possible version issue


def configure_metadata_patterns(line, section_name): # pylint: disable=too-many-locals
"""Configure regular-expression patterns to parse section meta-data lines.

# OVERLOAD lasio.reader.configure_metadata_patterns

Arguments:
line (str): line from LAS header section
section_name (str): Name of the section the 'line' is from.

Returns:
An array of regular-expression strings (patterns).
"""

# Default return value
patterns = []

# Default regular expressions for name, value and desc fields
name_re = r"\.?(?P<name>[^.]*)\."
value_re = r"(?P<value>.*):"
desc_re = r"(?P<descr>.*)"

# Default regular expression for unit field. Note that we
# attempt to match "1000 psi" as a special case which allows
# a single whitespace character, in contradiction to the LAS specification
# See GitHub issue #363 for details.
if "VERS" in line:
unit_re = r"(?P<unit>\D*)"
else:
unit_re = r"(?P<unit>([0-9]+\s)?[^\s]*)"
domfournier marked this conversation as resolved.
Show resolved Hide resolved

# Alternate regular expressions for special cases
name_missing_period_re = r"(?P<name>[^:]*):"
value_missing_period_re = r"(?P<value>.*)"
value_without_colon_delimiter_re = r"(?P<value>[^:]*)"
value_with_time_colon_re = (
r"(?P<value>.*?)(?:(?<!( [0-2][0-3]| hh| HH)):(?!([0-5][0-9]|mm|MM)))"
)
name_with_dots_re = r"\.?(?P<name>[^.].*[.])\."
no_desc_re = ""
no_unit_re = ""

# Configure special cases
# 1. missing period (assume that only name and value are present)
# 2. missing colon delimiter and description field
# 3. double_dots '..' caused by mnemonic abbreviation (with period)
# next to the dot delimiter.
if ":" in line:
if not "." in line[: line.find(":")]:
# If there is no period, then we assume that the colon exists and
# everything on the left is the name, and everything on the right
# is the value - therefore no unit or description field.
name_re = name_missing_period_re
value_re = value_missing_period_re
desc_re = no_desc_re
unit_re = no_unit_re
value_with_time_colon_re = value_missing_period_re

Check warning on line 89 in las_geoh5/__init__.py

View check run for this annotation

Codecov / codecov/patch

las_geoh5/__init__.py#L85-L89

Added lines #L85 - L89 were not covered by tests

if not ":" in line:
# If there isn't a colon delimiter then there isn't
# a description field either.
value_re = value_without_colon_delimiter_re
desc_re = no_desc_re

Check warning on line 95 in las_geoh5/__init__.py

View check run for this annotation

Codecov / codecov/patch

las_geoh5/__init__.py#L94-L95

Added lines #L94 - L95 were not covered by tests

if ".." in line and section_name == "Curves":
name_re = name_with_dots_re

Check warning on line 98 in las_geoh5/__init__.py

View check run for this annotation

Codecov / codecov/patch

las_geoh5/__init__.py#L97-L98

Added lines #L97 - L98 were not covered by tests
else:
if re.search(r"[^ ]\.\.", line) and section_name == "Curves":
double_dot = line.find("..")
desc_colon = line.rfind(":")

Check warning on line 102 in las_geoh5/__init__.py

View check run for this annotation

Codecov / codecov/patch

las_geoh5/__init__.py#L101-L102

Added lines #L101 - L102 were not covered by tests

# Check that a double_dot is not in the
# description string.
if double_dot < desc_colon:
name_re = name_with_dots_re

Check warning on line 107 in las_geoh5/__init__.py

View check run for this annotation

Codecov / codecov/patch

las_geoh5/__init__.py#L106-L107

Added lines #L106 - L107 were not covered by tests

if section_name == "Parameter":
# Search for a value entry with a time-value first.
pattern = name_re + unit_re + value_with_time_colon_re + desc_re
patterns.append(pattern)

# Add the regular pattern for all section_names
# for the Parameter section this will run after time-value pattern
pattern = name_re + unit_re + value_re + desc_re
patterns.append(pattern)

return patterns


reader.configure_metadata_patterns = configure_metadata_patterns
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "las-geoh5"
version = "0.3.0-alpha.1"
version = "0.2.1-alpha.1"
description = "Las/Geoh5 conversion"
license = "MIT"
readme = "README.rst"
Expand Down
Loading