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-1226: OMF files failing to export and import from command line #44

Merged
merged 36 commits into from
Nov 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
54f2639
version to 3.0.0-rc.1
sebhmg Mar 23, 2023
193608d
allow using geoh5py pre-release
sebhmg Mar 24, 2023
1eeb7bf
set version to rc.2
sebhmg Mar 24, 2023
21beac1
try again syntax to allow geoh5py prerelease
sebhmg Mar 24, 2023
686c600
remove unnecessary '*' in geoh5py version constraint
sebhmg Mar 27, 2023
ab14a05
disable LFS
sebhmg Mar 28, 2023
00725df
set version to rc.3
sebhmg Mar 28, 2023
f72a8a3
GEOPY-892: add usage of argparse and tests
sebhmg Mar 27, 2023
86e1e3a
Merge pull request #29 from sebhmg/GEOPY-892
sebhmg Mar 28, 2023
dc47e48
Loop over legends instead of assuming order
domfournier Apr 18, 2023
af5e162
Add unitest
domfournier Apr 18, 2023
4569e0b
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Apr 18, 2023
c161987
Pylint
domfournier Apr 18, 2023
282e508
Merge branch 'GEOPY-925' of https://github.com/MiraGeoscience/omf int…
domfournier Apr 18, 2023
bb1ae51
set version to rc.4
sebhmg Apr 18, 2023
079cd0a
Merge pull request #30 from MiraGeoscience/GEOPY-925
sebhmg Apr 18, 2023
11be08f
GEOPY-836 set version to 3.0.0
andrewg-mira May 12, 2023
3709416
GEOPY-836 set version to 3.0.0 in README
sebhmg May 15, 2023
111ef24
pre-commit autoupdate
sebhmg May 15, 2023
6c62a33
fix pylint warning
sebhmg May 15, 2023
0b3ac0f
Merge pull request #31 from MiraGeoscience/release/3.0.0
andrewg-mira May 15, 2023
b02323d
Fix link in readme
domfournier Aug 17, 2023
6d44114
Bump version
domfournier Aug 17, 2023
a2fa8ee
More version bump
domfournier Aug 17, 2023
e5a356d
Merge branch 'release/3.0.1' into GEOPY-899
domfournier Aug 17, 2023
429a745
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 17, 2023
6160a0d
Update pyproject.toml
domfournier Aug 25, 2023
b6342f9
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 25, 2023
75ca22c
Update __init__.py
domfournier Aug 25, 2023
3e29fe5
Merge pull request #35 from MiraGeoscience/GEOPY-899
andrewg-mira Aug 25, 2023
b57e158
Merge pull request #36 from MiraGeoscience/release/3.0.1
andrewg-mira Aug 25, 2023
2d9c620
Merge remote-tracking branch 'upstream/main' into release/3.1.0
sebhmg Nov 23, 2023
a414e6e
add back the compression option, plus tests
sebhmg Nov 23, 2023
4b8265d
pylint: ignore duplicate code in tests
sebhmg Nov 23, 2023
d0245cd
Deal with unordered legends
domfournier Nov 23, 2023
d35385e
Merge pull request #1 from MiraGeoscience/GEOPY-1226
sebhmg Nov 23, 2023
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
12 changes: 8 additions & 4 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
*.pt filter=lfs diff=lfs merge=lfs -text
*.geoh5 filter=lfs diff=lfs merge=lfs -text
/assets/** filter=lfs diff=lfs merge=lfs -text
*.h5 filter=lfs diff=lfs merge=lfs -text
# can only push Git LFS objects to public forks if the repository network already has Git LFS objects
# or you have write access to the root of the repository network.
# (from https://docs.github.com/en/repositories/working-with-files/managing-large-files/collaboration-with-git-large-file-storage)
#
#*.pt filter=lfs diff=lfs merge=lfs -text
#*.geoh5 filter=lfs diff=lfs merge=lfs -text
#/assets/** filter=lfs diff=lfs merge=lfs -text
#*.h5 filter=lfs diff=lfs merge=lfs -text
12 changes: 6 additions & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ ci:

repos:
- repo: https://github.com/psf/black
rev: 23.1.0
rev: 23.3.0
hooks:
- id: black
- repo: https://github.com/PyCQA/isort
Expand All @@ -28,12 +28,12 @@ repos:
- id: flake8
files: ^omf/fileio/geoh5*
- repo: https://github.com/asottile/pyupgrade
rev: v3.3.1
rev: v3.4.0
hooks:
- id: pyupgrade
args: [--py38-plus]
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.0.0
rev: v1.3.0
hooks:
- id: mypy
additional_dependencies: [types-six]
Expand All @@ -52,10 +52,10 @@ repos:
exclude: (devtools|docs)/
files: ^(omf/fileio/geoh5|tests/)
- repo: https://github.com/codespell-project/codespell
rev: v2.2.2
rev: v2.2.4
hooks:
- id: codespell
exclude: (\.ipynb$)
exclude: (\.ipynb$|^poetry.lock$)
entry: codespell -I .codespellignore
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
Expand All @@ -74,7 +74,7 @@ repos:
- id: mixed-line-ending
- id: name-tests-test
- repo: https://github.com/rstcheck/rstcheck
rev: v6.1.1
rev: v6.1.2
hooks:
- id: rstcheck
additional_dependencies: [sphinx]
Expand Down
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ omf
Version: 3.1.0-alpha.1

API library for Open Mining Format, a new standard for mining data backed by
the `Global Mining Standards & Guidelines Group <http://www.globalminingstandards.org/>`_.
the `Global Mining Standards & Guidelines Group <https://gmggroup.org/>`_.

.. warning::
**Pre-Release Notice**
Expand Down
4 changes: 2 additions & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@
# built documents.
#
# The short X.Y version.
version = u'0.9.3'
version = u'3.0.0'
# The full version, including alpha/beta/rc tags.
release = u'0.9.3'
release = u'3.0.0'

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand Down
26 changes: 16 additions & 10 deletions omf/fileio/geoh5.py
Original file line number Diff line number Diff line change
Expand Up @@ -647,19 +647,25 @@
if not element.legends:
return kwargs

ind = 0
alpha = 0
value_map = {ind: "Unknown"}
color_map = [np.r_[ind, [0, 0, 0], alpha]]
alpha = 1.0
value_map = {0: "Unknown"}
color_map = [np.r_[0, [0, 0, 0], alpha]]

for name, rgb in zip(element.legends[0].values, element.legends[1].values):
ind += 1
for legend in element.legends:
if isinstance(legend.values, StringArray):
for count, name in enumerate(legend.values):
if str(name).lower() == "unknown":
name = f"[{str(name).upper()}]"

Check warning on line 658 in omf/fileio/geoh5.py

View check run for this annotation

Codecov / codecov/patch

omf/fileio/geoh5.py#L658

Added line #L658 was not covered by tests

if str(name).lower() == "unknown":
name = f"[{str(name).upper()}]"
value_map[count + 1] = str(name)

value_map[ind] = str(name)
color_map.append(np.r_[ind, rgb, alpha])
else:
color_map.append(
[
np.r_[count + 1, val, alpha]
for count, val in enumerate(legend.values)
]
)

kwargs["value_map"] = value_map
kwargs["type"] = "referenced"
Expand Down
15 changes: 12 additions & 3 deletions omf/scripts/geoh5_to_omf.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import argparse
import logging
import sys
from pathlib import Path
Expand All @@ -9,11 +10,19 @@


def run():
geoh5_filepath = Path(sys.argv[1])
if len(sys.argv) < 3:
parser = argparse.ArgumentParser(
prog="geoh5_to_omf",
description="Converts a geoh5 file to a new OMF file.",
)
parser.add_argument("geoh5_file", type=Path)
parser.add_argument("-o", "--out", type=Path, required=False, default=None)
args = parser.parse_args()

geoh5_filepath = args.geoh5_file
if args.out is None:
output_filepath = geoh5_filepath.with_suffix(".omf")
else:
output_filepath = Path(sys.argv[2])
output_filepath = args.out
if not output_filepath.suffix:
output_filepath = output_filepath.with_suffix(".omf")
if output_filepath.exists():
Expand Down
49 changes: 32 additions & 17 deletions omf/scripts/omf_to_geoh5.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import argparse
import logging
import sys
from pathlib import Path
Expand All @@ -9,32 +10,46 @@


def run():
omf_filepath = Path(sys.argv[1])
output_filepath = omf_filepath.with_suffix(".geoh5")
compression = 5

if len(sys.argv) < 3:
parser = argparse.ArgumentParser(
prog="omf_to_geoh5",
description="Converts an OMF file to a new geoh5 file.",
)
parser.add_argument("omf_file", type=Path, help="Path to the OMF file to convert.")
parser.add_argument(
"-o",
"--out",
type=Path,
required=False,
default=None,
help=(
"Path to the output geoh5 file. If not specified, create the output file "
"at the same location as the input file, but with the geoh5 extension."
),
)
parser.add_argument(
"--gzip",
type=int,
choices=range(0, 10),
default=5,
help="Gzip compression level (0-9) for h5 data.",
)
args = parser.parse_args()

omf_filepath = args.omf_file
if args.out is None:
output_filepath = omf_filepath.with_suffix(".geoh5")
else:
if sys.argv[2].isdigit():
compression = sys.argv[2]
if len(sys.argv) > 3:
output_filepath = Path(sys.argv[3])
elif isinstance(sys.argv[2], str):
output_filepath = Path(sys.argv[2])
if not output_filepath.suffix:
output_filepath = output_filepath.with_suffix(".geoh5")
if len(sys.argv) > 3:
compression = sys.argv[3]

output_filepath = args.out
if not output_filepath.suffix:
output_filepath = output_filepath.with_suffix(".geoh5")
if output_filepath.exists():
_logger.error(
"Cowardly refuses to overwrite existing file '%s'.", output_filepath
)
sys.exit(1)

reader = OMFReader(str(omf_filepath.absolute()))
GeoH5Writer(reader.get_project(), output_filepath, compression=compression)
GeoH5Writer(reader.get_project(), output_filepath, compression=args.gzip)
_logger.info("geoh5 file created: %s", output_filepath)


Expand Down
60 changes: 35 additions & 25 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -374,8 +374,8 @@ min-public-methods=1
[EXCEPTIONS]

# Exceptions that will emit a warning when caught.
overgeneral-exceptions=BaseException,
Exception
overgeneral-exceptions=builtins.BaseException,
builtins.Exception


[FORMAT]
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ omf_to_geoh5 = 'omf.scripts.omf_to_geoh5:run'

[tool.poetry.dependencies]
python = "^3.8,<3.11"
geoh5py = "~0.8.0rc2"
geoh5py = {version = "~0.8.0rc2", allow-prereleases = true}
# geoh5py = {url = "https://github.com/MiraGeoscience/geoh5py/archive/refs/heads/release/0.8.0.zip#sha256="}
numpy = "~1.23.5"
properties = "~0.6.0"
Expand Down
Loading