evo-data-converters-ubc 0.1.4__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,140 @@
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+ *.pyc
6
+
7
+ # C extensions
8
+ *.so
9
+
10
+ # Distribution / packaging
11
+ .Python
12
+ build/
13
+ develop-eggs/
14
+ dist/
15
+ downloads/
16
+ eggs/
17
+ .eggs/
18
+ lib/
19
+ lib64/
20
+ parts/
21
+ sdist/
22
+ var/
23
+ wheels/
24
+ pip-wheel-metadata/
25
+ share/python-wheels/
26
+ *.egg-info/
27
+ .installed.cfg
28
+ *.egg
29
+ MANIFEST
30
+
31
+ # PyInstaller
32
+ # Usually these files are written by a python script from a template
33
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
34
+ *.manifest
35
+ *.spec
36
+
37
+ # Installer logs
38
+ pip-log.txt
39
+ pip-delete-this-directory.txt
40
+
41
+ # Unit test / coverage reports
42
+ htmlcov/
43
+ .tox/
44
+ .nox/
45
+ .coverage
46
+ .coverage.*
47
+ .cache
48
+ nosetests.xml
49
+ coverage.xml
50
+ *.cover
51
+ *.py,cover
52
+ .hypothesis/
53
+ .pytest_cache/
54
+
55
+ # Translations
56
+ *.mo
57
+ *.pot
58
+
59
+ # Django stuff:
60
+ *.log
61
+ local_settings.py
62
+ db.sqlite3
63
+ db.sqlite3-journal
64
+
65
+ # Flask stuff:
66
+ instance/
67
+ .webassets-cache
68
+
69
+ # Scrapy stuff:
70
+ .scrapy
71
+
72
+ # Sphinx documentation
73
+ docs/_build/
74
+
75
+ # PyBuilder
76
+ target/
77
+
78
+ # Jupyter Notebook
79
+ .ipynb_checkpoints
80
+
81
+ # IPython
82
+ profile_default/
83
+ ipython_config.py
84
+
85
+ # pipenv
86
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
87
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
88
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
89
+ # install all needed dependencies.
90
+ #Pipfile.lock
91
+
92
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow
93
+ __pypackages__/
94
+
95
+ # Celery stuff
96
+ celerybeat-schedule
97
+ celerybeat.pid
98
+
99
+ # SageMath parsed files
100
+ *.sage.py
101
+
102
+ # Environments
103
+ .env
104
+ .venv
105
+ example_virtual_env
106
+ env/
107
+ venv/
108
+ ENV/
109
+ env.bak/
110
+ venv.bak/
111
+
112
+ # Spyder project settings
113
+ .spyderproject
114
+ .spyproject
115
+
116
+ # Rope project settings
117
+ .ropeproject
118
+
119
+ # mkdocs documentation
120
+ /site
121
+
122
+ # mypy
123
+ .mypy_cache/
124
+ .dmypy.json
125
+ dmypy.json
126
+
127
+ # Pyre type checker
128
+ .pyre/
129
+
130
+ # Custom
131
+ .idea
132
+ query_results.parquet
133
+ .cache_ggshield
134
+
135
+ # Object data client caches
136
+ samples/data-converters/python/convert-omf/data/cache
137
+ data/cache
138
+
139
+ # Development tools
140
+ .vscode/
@@ -0,0 +1,190 @@
1
+ Copyright © 2025 Bentley Systems, Incorporated.
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
14
+
15
+ Apache License
16
+ Version 2.0, January 2004
17
+ http://www.apache.org/licenses/
18
+
19
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
20
+
21
+ 1. Definitions.
22
+
23
+ "License" shall mean the terms and conditions for use, reproduction,
24
+ and distribution as defined by Sections 1 through 9 of this document.
25
+
26
+ "Licensor" shall mean the copyright owner or entity authorized by
27
+ the copyright owner that is granting the License.
28
+
29
+ "Legal Entity" shall mean the union of the acting entity and all
30
+ other entities that control, are controlled by, or are under common
31
+ control with that entity. For the purposes of this definition,
32
+ "control" means (i) the power, direct or indirect, to cause the
33
+ direction or management of such entity, whether by contract or
34
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
35
+ outstanding shares, or (iii) beneficial ownership of such entity.
36
+
37
+ "You" (or "Your") shall mean an individual or Legal Entity
38
+ exercising permissions granted by this License.
39
+
40
+ "Source" form shall mean the preferred form for making modifications,
41
+ including but not limited to software source code, documentation
42
+ source, and configuration files.
43
+
44
+ "Object" form shall mean any form resulting from mechanical
45
+ transformation or translation of a Source form, including but
46
+ not limited to compiled object code, generated documentation,
47
+ and conversions to other media types.
48
+
49
+ "Work" shall mean the work of authorship, whether in Source or
50
+ Object form, made available under the License, as indicated by a
51
+ copyright notice that is included in or attached to the work
52
+ (an example is provided in the Appendix below).
53
+
54
+ "Derivative Works" shall mean any work, whether in Source or Object
55
+ form, that is based on (or derived from) the Work and for which the
56
+ editorial revisions, annotations, elaborations, or other modifications
57
+ represent, as a whole, an original work of authorship. For the purposes
58
+ of this License, Derivative Works shall not include works that remain
59
+ separable from, or merely link (or bind by name) to the interfaces of,
60
+ the Work and Derivative Works thereof.
61
+
62
+ "Contribution" shall mean any work of authorship, including
63
+ the original version of the Work and any modifications or additions
64
+ to that Work or Derivative Works thereof, that is intentionally
65
+ submitted to Licensor for inclusion in the Work by the copyright owner
66
+ or by an individual or Legal Entity authorized to submit on behalf of
67
+ the copyright owner. For the purposes of this definition, "submitted"
68
+ means any form of electronic, verbal, or written communication sent
69
+ to the Licensor or its representatives, including but not limited to
70
+ communication on electronic mailing lists, source code control systems,
71
+ and issue tracking systems that are managed by, or on behalf of, the
72
+ Licensor for the purpose of discussing and improving the Work, but
73
+ excluding communication that is conspicuously marked or otherwise
74
+ designated in writing by the copyright owner as "Not a Contribution."
75
+
76
+ "Contributor" shall mean Licensor and any individual or Legal Entity
77
+ on behalf of whom a Contribution has been received by Licensor and
78
+ subsequently incorporated within the Work.
79
+
80
+ 2. Grant of Copyright License. Subject to the terms and conditions of
81
+ this License, each Contributor hereby grants to You a perpetual,
82
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
83
+ copyright license to reproduce, prepare Derivative Works of,
84
+ publicly display, publicly perform, sublicense, and distribute the
85
+ Work and such Derivative Works in Source or Object form.
86
+
87
+ 3. Grant of Patent License. Subject to the terms and conditions of
88
+ this License, each Contributor hereby grants to You a perpetual,
89
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
90
+ (except as stated in this section) patent license to make, have made,
91
+ use, offer to sell, sell, import, and otherwise transfer the Work,
92
+ where such license applies only to those patent claims licensable
93
+ by such Contributor that are necessarily infringed by their
94
+ Contribution(s) alone or by combination of their Contribution(s)
95
+ with the Work to which such Contribution(s) was submitted. If You
96
+ institute patent litigation against any entity (including a
97
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
98
+ or a Contribution incorporated within the Work constitutes direct
99
+ or contributory patent infringement, then any patent licenses
100
+ granted to You under this License for that Work shall terminate
101
+ as of the date such litigation is filed.
102
+
103
+ 4. Redistribution. You may reproduce and distribute copies of the
104
+ Work or Derivative Works thereof in any medium, with or without
105
+ modifications, and in Source or Object form, provided that You
106
+ meet the following conditions:
107
+
108
+ (a) You must give any other recipients of the Work or
109
+ Derivative Works a copy of this License; and
110
+
111
+ (b) You must cause any modified files to carry prominent notices
112
+ stating that You changed the files; and
113
+
114
+ (c) You must retain, in the Source form of any Derivative Works
115
+ that You distribute, all copyright, patent, trademark, and
116
+ attribution notices from the Source form of the Work,
117
+ excluding those notices that do not pertain to any part of
118
+ the Derivative Works; and
119
+
120
+ (d) If the Work includes a "NOTICE" text file as part of its
121
+ distribution, then any Derivative Works that You distribute must
122
+ include a readable copy of the attribution notices contained
123
+ within such NOTICE file, excluding those notices that do not
124
+ pertain to any part of the Derivative Works, in at least one
125
+ of the following places: within a NOTICE text file distributed
126
+ as part of the Derivative Works; within the Source form or
127
+ documentation, if provided along with the Derivative Works; or,
128
+ within a display generated by the Derivative Works, if and
129
+ wherever such third-party notices normally appear. The contents
130
+ of the NOTICE file are for informational purposes only and
131
+ do not modify the License. You may add Your own attribution
132
+ notices within Derivative Works that You distribute, alongside
133
+ or as an addendum to the NOTICE text from the Work, provided
134
+ that such additional attribution notices cannot be construed
135
+ as modifying the License.
136
+
137
+ You may add Your own copyright statement to Your modifications and
138
+ may provide additional or different license terms and conditions
139
+ for use, reproduction, or distribution of Your modifications, or
140
+ for any such Derivative Works as a whole, provided Your use,
141
+ reproduction, and distribution of the Work otherwise complies with
142
+ the conditions stated in this License.
143
+
144
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
145
+ any Contribution intentionally submitted for inclusion in the Work
146
+ by You to the Licensor shall be under the terms and conditions of
147
+ this License, without any additional terms or conditions.
148
+ Notwithstanding the above, nothing herein shall supersede or modify
149
+ the terms of any separate license agreement you may have executed
150
+ with Licensor regarding such Contributions.
151
+
152
+ 6. Trademarks. This License does not grant permission to use the trade
153
+ names, trademarks, service marks, or product names of the Licensor,
154
+ except as required for reasonable and customary use in describing the
155
+ origin of the Work and reproducing the content of the NOTICE file.
156
+
157
+ 7. Disclaimer of Warranty. Unless required by applicable law or
158
+ agreed to in writing, Licensor provides the Work (and each
159
+ Contributor provides its Contributions) on an "AS IS" BASIS,
160
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
161
+ implied, including, without limitation, any warranties or conditions
162
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
163
+ PARTICULAR PURPOSE. You are solely responsible for determining the
164
+ appropriateness of using or redistributing the Work and assume any
165
+ risks associated with Your exercise of permissions under this License.
166
+
167
+ 8. Limitation of Liability. In no event and under no legal theory,
168
+ whether in tort (including negligence), contract, or otherwise,
169
+ unless required by applicable law (such as deliberate and grossly
170
+ negligent acts) or agreed to in writing, shall any Contributor be
171
+ liable to You for damages, including any direct, indirect, special,
172
+ incidental, or consequential damages of any character arising as a
173
+ result of this License or out of the use or inability to use the
174
+ Work (including but not limited to damages for loss of goodwill,
175
+ work stoppage, computer failure or malfunction, or any and all
176
+ other commercial damages or losses), even if such Contributor
177
+ has been advised of the possibility of such damages.
178
+
179
+ 9. Accepting Warranty or Additional Liability. While redistributing
180
+ the Work or Derivative Works thereof, You may choose to offer,
181
+ and charge a fee for, acceptance of support, warranty, indemnity,
182
+ or other liability obligations and/or rights consistent with this
183
+ License. However, in accepting such obligations, You may act only
184
+ on Your own behalf and on Your sole responsibility, not on behalf
185
+ of any other Contributor, and only if You agree to indemnify,
186
+ defend, and hold each Contributor harmless for any liability
187
+ incurred by, or claims asserted against, such Contributor by reason
188
+ of your accepting any such warranty or additional liability.
189
+
190
+ END OF TERMS AND CONDITIONS
@@ -0,0 +1,68 @@
1
+ Metadata-Version: 2.4
2
+ Name: evo-data-converters-ubc
3
+ Version: 0.1.4
4
+ Summary: Python data converters for UBC to Evo geoscience objects
5
+ Project-URL: Source, https://github.com/SeequentEvo/evo-python-sdk
6
+ Project-URL: Tracker, https://github.com/SeequentEvo/evo-python-sdk/issues
7
+ Project-URL: Homepage, https://www.seequent.com/
8
+ Project-URL: Documentation, https://developer.seequent.com/
9
+ Author-email: Seequent <support@seequent.com>
10
+ License-File: LICENSE.md
11
+ Requires-Python: >=3.10
12
+ Requires-Dist: evo-data-converters-common>=0.3.1
13
+ Description-Content-Type: text/markdown
14
+
15
+ <p align="center"><a href="https://seequent.com" target="_blank"><picture><source media="(prefers-color-scheme: dark)" srcset="https://developer.seequent.com/img/seequent-logo-dark.svg" alt="Seequent logo" width="400" /><img src="https://developer.seequent.com/img/seequent-logo.svg" alt="Seequent logo" width="400" /></picture></a></p>
16
+ <p align="center">
17
+ <a href="https://pypi.org/project/evo-data-converters-ubc/"><img alt="PyPI - Version" src="https://img.shields.io/pypi/v/evo-data-converters-ubc" /></a>
18
+ <a href="https://github.com/SeequentEvo/evo-data-converters/actions/workflows/on-merge.yaml"><img src="https://github.com/SeequentEvo/evo-data-converters/actions/workflows/on-merge.yaml/badge.svg" alt="" /></a>
19
+ </p>
20
+ <p align="center">
21
+ <a href="https://developer.seequent.com/" target="_blank">Seequent Developer Portal</a>
22
+ &bull; <a href="https://community.seequent.com/group/19-evo" target="_blank">Seequent Community</a>
23
+ &bull; <a href="https://seequent.com" target="_blank">Seequent website</a>
24
+ </p>
25
+
26
+ ## Evo
27
+
28
+ Evo is a unified platform for geoscience teams. It enables access, connection, computation, and management of subsurface data. This empowers better decision-making, simplified collaboration, and accelerated innovation. Evo is built on open APIs, allowing developers to build custom integrations and applications. Our open schemas, code examples, and SDK are available for the community to use and extend.
29
+
30
+ Evo is powered by Seequent, a Bentley organisation.
31
+
32
+ ## Pre-requisites
33
+
34
+ * Python 3.10, 3.11, or 3.12
35
+
36
+ ## Installation
37
+
38
+ ```shell
39
+ pip install evo-data-converters-ubc
40
+ ```
41
+
42
+ ## UBC
43
+
44
+ See https://help.seequent.com/Geo/5.0/en-GB/Content/block-models/ubc-grids.htm.
45
+
46
+ ## Usage
47
+
48
+ For examples of using this package, see the [Jupyter notebooks.](https://github.com/SeequentEvo/evo-data-converters/tree/main/packages/ubc/samples/convert-ubc)
49
+
50
+ ## Code of conduct
51
+
52
+ We rely on an open, friendly, inclusive environment. To help us ensure this remains possible, please familiarise yourself with our [code of conduct.](https://github.com/SeequentEvo/evo-data-converters/blob/main/CODE_OF_CONDUCT.md)
53
+
54
+ ## License
55
+ Evo data converters are open source and licensed under the [Apache 2.0 license.](https://github.com/SeequentEvo/evo-data-converters/tree/main/packages/ubc/./LICENSE.md)
56
+
57
+ Copyright © 2025 Bentley Systems, Incorporated.
58
+
59
+ Licensed under the Apache License, Version 2.0 (the "License").
60
+ You may obtain a copy of the License at
61
+
62
+ http://www.apache.org/licenses/LICENSE-2.0
63
+
64
+ Unless required by applicable law or agreed to in writing, software
65
+ distributed under the License is distributed on an "AS IS" BASIS,
66
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
67
+ See the License for the specific language governing permissions and
68
+ limitations under the License.
@@ -0,0 +1,51 @@
1
+ [project]
2
+ name = "evo-data-converters-ubc"
3
+ description = "Python data converters for UBC to Evo geoscience objects"
4
+ version = "0.1.4"
5
+ requires-python = ">=3.10"
6
+ license-files = ["LICENSE.md"]
7
+ dynamic = ["readme"]
8
+ authors = [
9
+ { name = "Seequent", email = "support@seequent.com" }
10
+ ]
11
+
12
+ dependencies = [
13
+ "evo-data-converters-common>=0.3.1",
14
+ ]
15
+
16
+ [project.urls]
17
+ Source = "https://github.com/SeequentEvo/evo-python-sdk"
18
+ Tracker = "https://github.com/SeequentEvo/evo-python-sdk/issues"
19
+ Homepage = "https://www.seequent.com/"
20
+ Documentation = "https://developer.seequent.com/"
21
+
22
+ [dependency-groups]
23
+ dev = [
24
+ "pytest",
25
+ ]
26
+
27
+ [tool.ruff]
28
+ src = ["src", "tests"]
29
+ line-length = 120
30
+
31
+ [build-system]
32
+ requires = ["hatchling", "hatch-fancy-pypi-readme"]
33
+ build-backend = "hatchling.build"
34
+
35
+ [tool.hatch.build.targets.sdist]
36
+ include = ["src"]
37
+
38
+ [tool.hatch.build.targets.wheel]
39
+ packages = ["src/evo"]
40
+
41
+ [tool.hatch.metadata.hooks.fancy-pypi-readme]
42
+ content-type = "text/markdown"
43
+
44
+ [[tool.hatch.metadata.hooks.fancy-pypi-readme.fragments]]
45
+ path = "README.md"
46
+
47
+ [[tool.hatch.metadata.hooks.fancy-pypi-readme.substitutions]]
48
+ # Literal TOML strings (single quotes) need no escaping of backslashes.
49
+ # Converts relative links to absolute links in PyPI
50
+ pattern = '\[(.+?)\]\(((?!https?://)\S+?)\)'
51
+ replacement = '[\1](https://github.com/SeequentEvo/evo-data-converters/tree/main/packages/ubc/\g<2>)'
@@ -0,0 +1,10 @@
1
+ # Copyright © 2025 Bentley Systems, Incorporated
2
+ # Licensed under the Apache License, Version 2.0 (the "License");
3
+ # you may not use this file except in compliance with the License.
4
+ # You may obtain a copy of the License at
5
+ # http://www.apache.org/licenses/LICENSE-2.0
6
+ # Unless required by applicable law or agreed to in writing, software
7
+ # distributed under the License is distributed on an "AS IS" BASIS,
8
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
9
+ # See the License for the specific language governing permissions and
10
+ # limitations under the License.
@@ -0,0 +1,15 @@
1
+ # Copyright © 2025 Bentley Systems, Incorporated
2
+ # Licensed under the Apache License, Version 2.0 (the "License");
3
+ # you may not use this file except in compliance with the License.
4
+ # You may obtain a copy of the License at
5
+ # http://www.apache.org/licenses/LICENSE-2.0
6
+ # Unless required by applicable law or agreed to in writing, software
7
+ # distributed under the License is distributed on an "AS IS" BASIS,
8
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
9
+ # See the License for the specific language governing permissions and
10
+ # limitations under the License.
11
+
12
+ from evo.data_converters.ubc.importer.ubc_reader import UBCFileIOError, UBCInvalidDataError, UBCOOMError
13
+ from evo.data_converters.ubc.importer.ubc_to_evo import convert_ubc
14
+
15
+ __all__ = ["UBCFileIOError", "UBCInvalidDataError", "UBCOOMError", "convert_ubc"]
@@ -0,0 +1,150 @@
1
+ # Copyright © 2025 Bentley Systems, Incorporated
2
+ # Licensed under the Apache License, Version 2.0 (the "License");
3
+ # you may not use this file except in compliance with the License.
4
+ # You may obtain a copy of the License at
5
+ # http://www.apache.org/licenses/LICENSE-2.0
6
+ # Unless required by applicable law or agreed to in writing, software
7
+ # distributed under the License is distributed on an "AS IS" BASIS,
8
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
9
+ # See the License for the specific language governing permissions and
10
+ # limitations under the License.
11
+
12
+ import contextlib
13
+ import math
14
+ import os
15
+ from collections.abc import Iterator
16
+ from io import TextIOWrapper
17
+ from typing import Any
18
+
19
+ import numpy
20
+
21
+
22
+ class UBCInvalidDataError(Exception):
23
+ pass
24
+
25
+
26
+ class UBCOOMError(Exception):
27
+ pass
28
+
29
+
30
+ class UBCFileIOError(Exception):
31
+ pass
32
+
33
+
34
+ class UBCFile:
35
+ FILE_TYPE = "" # this is to be overridden in subclass
36
+
37
+ def __init__(self, filename: str):
38
+ self.filename = filename
39
+ self.base_filename = os.path.basename(filename)
40
+ self.line_number_of_import_file: int | None = None
41
+
42
+ @contextlib.contextmanager
43
+ def opened_file(self) -> Iterator[TextIOWrapper]:
44
+ try:
45
+ with open(self.filename, "r") as open_file:
46
+ yield open_file
47
+ except StopIteration:
48
+ line_number_msg = (
49
+ f" after line: {self.line_number_of_import_file:d}" if self.line_number_of_import_file else ""
50
+ )
51
+ msg = f"The file '{self.base_filename}' is lacking the expected data{line_number_msg}"
52
+ raise UBCFileIOError(msg)
53
+ except OSError as io_error_exception:
54
+ raise UBCFileIOError(
55
+ f"An unexpected IO error ({io_error_exception}) occurred while reading the {self.base_filename}"
56
+ )
57
+
58
+ def execute(self, *args: Any, **kwargs: Any) -> Any:
59
+ try:
60
+ return self.run(*args, **kwargs)
61
+ except OSError as exc:
62
+ raise UBCFileIOError(f"Error reading file: {exc.args[0]}")
63
+ except MemoryError:
64
+ raise UBCOOMError(f"Ran out of memory while importing grid file '{self.base_filename}'")
65
+ except ValueError as value_error_exception:
66
+ if str(value_error_exception) == "array is too big.":
67
+ raise UBCOOMError(f"Ran out of memory while importing grid file '{self.base_filename}'")
68
+ else:
69
+ line_number = f":{self.line_number_of_import_file:d}" if self.line_number_of_import_file else ""
70
+ raise UBCInvalidDataError(
71
+ f"Error importing the UBC model from the file '{self.base_filename}'{line_number}"
72
+ )
73
+ except IndexError:
74
+ raise UBCInvalidDataError(
75
+ f"Error importing the UBC model from the file '{self.base_filename}'"
76
+ "The specified number of cells differs to the number of cell widths given in "
77
+ "one or more directions"
78
+ )
79
+ except Exception as exc:
80
+ raise UBCFileIOError(f"Error importing the UBC model from '{self.base_filename}'.\n{exc.args[0]}")
81
+
82
+ def run(self, *args: Any, **kwargs: Any) -> Any:
83
+ raise NotImplementedError
84
+
85
+
86
+ class UBCMeshFileImporter(UBCFile):
87
+ FILE_TYPE = "mesh"
88
+
89
+ @staticmethod
90
+ def row_iter(open_file: TextIOWrapper) -> Iterator[tuple[int, list[str]]]:
91
+ for line_number, line in enumerate(open_file, start=1):
92
+ yield line_number, line.split()
93
+
94
+ @staticmethod
95
+ def floats_iter(source: list[str]) -> Iterator[float]:
96
+ for txt in source:
97
+ pos = txt.find("*")
98
+ if pos != -1:
99
+ num = int(txt[:pos])
100
+ val = float(txt[pos + 1 :])
101
+ for _ in range(num):
102
+ yield val
103
+ else:
104
+ yield float(txt)
105
+
106
+ def run(self, *args: Any, **kwargs: Any) -> tuple[numpy.ndarray, list[numpy.ndarray], list[int]]:
107
+ self.line_number_of_import_file = 0
108
+ with self.opened_file() as data_file:
109
+ line_iterator = self.row_iter(data_file)
110
+ self.line_number_of_import_file, line = next(line_iterator)
111
+ size_of_dimensions = [int(size) for size in line[:3]] # x, y, z dimensions of grid
112
+ if 0 in size_of_dimensions:
113
+ # This is how we do error handling...
114
+ raise UBCInvalidDataError(f"Invalid size (0) detected in {self.filename}")
115
+ self.line_number_of_import_file, line = next(line_iterator)
116
+ origin = numpy.array([float(ordinate) for ordinate in line[:3]])
117
+ if len(origin) < 3:
118
+ raise UBCInvalidDataError(f"Invalid origin detected in {self.filename}")
119
+ spacings = []
120
+ for size in size_of_dimensions:
121
+ i = 0
122
+ d = numpy.zeros((size,), numpy.float64)
123
+ while i < size:
124
+ self.line_number_of_import_file, input_line = next(line_iterator)
125
+ for f in self.floats_iter(input_line):
126
+ d[i] = f
127
+ i += 1
128
+ spacings.append(d)
129
+ origin[2] -= sum(spacings[2])
130
+ spacings[2] = spacings[2][::-1]
131
+ return origin, spacings, size_of_dimensions
132
+
133
+
134
+ class UBCPropertyFileImporter(UBCFile):
135
+ FILE_TYPE = "property"
136
+
137
+ def run(self, n_blocks: int, size_in_blocks: list) -> numpy.ndarray:
138
+ with self.opened_file() as data_file:
139
+ values_array = numpy.fromfile(data_file, sep="\n", count=n_blocks)
140
+
141
+ if len(values_array) != n_blocks or any(math.isinf(value) or math.isnan(value) for value in values_array):
142
+ raise UBCInvalidDataError(
143
+ "Error importing the UBC properties from file: "
144
+ f"'{self.base_filename}'. "
145
+ f"The number of property values ({len(values_array)})"
146
+ f"differs from the number of grid cells ({n_blocks})."
147
+ )
148
+ new_shape = tuple(size_in_blocks[:2][::-1] + [size_in_blocks[2]])
149
+ values_array.shape = new_shape
150
+ return values_array[:, :, ::-1].swapaxes(0, 1).swapaxes(0, 2).ravel()
@@ -0,0 +1,79 @@
1
+ # Copyright © 2025 Bentley Systems, Incorporated
2
+ # Licensed under the Apache License, Version 2.0 (the "License");
3
+ # you may not use this file except in compliance with the License.
4
+ # You may obtain a copy of the License at
5
+ # http://www.apache.org/licenses/LICENSE-2.0
6
+ # Unless required by applicable law or agreed to in writing, software
7
+ # distributed under the License is distributed on an "AS IS" BASIS,
8
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
9
+ # See the License for the specific language governing permissions and
10
+ # limitations under the License.
11
+
12
+ from typing import TYPE_CHECKING, Optional
13
+
14
+ from evo_schemas.components import BaseSpatialDataProperties_V1_0_1
15
+
16
+ import evo.logging
17
+ from evo.data_converters.common import (
18
+ EvoWorkspaceMetadata,
19
+ create_evo_object_service_and_data_client,
20
+ publish_geoscience_objects_sync,
21
+ )
22
+ from evo.data_converters.ubc.importer import utils
23
+ from evo.objects.data import ObjectMetadata
24
+
25
+ logger = evo.logging.getLogger("data_converters")
26
+
27
+ if TYPE_CHECKING:
28
+ from evo.notebooks import ServiceManagerWidget
29
+
30
+
31
+ def convert_ubc(
32
+ files_path: list[str],
33
+ epsg_code: int,
34
+ evo_workspace_metadata: Optional[EvoWorkspaceMetadata] = None,
35
+ service_manager_widget: Optional["ServiceManagerWidget"] = None,
36
+ tags: Optional[dict[str, str]] = None,
37
+ upload_path: str = "",
38
+ publish_objects: bool = True,
39
+ overwrite_existing_objects: bool = False,
40
+ ) -> list[BaseSpatialDataProperties_V1_0_1 | ObjectMetadata]:
41
+ """Converts a UBC files into Geoscience Objects.
42
+
43
+ :param files_path: list of paths to the UBC .msh/.nev files.
44
+ :param epsg_code: The EPSG code to use when creating a Coordinate Reference System object.
45
+ :param evo_workspace_metadata: (Optional) Evo workspace metadata.
46
+ :param service_manager_widget: (Optional) Service Manager Widget for use in jupyter notebooks.
47
+ :param tags: (Optional) Dict of tags to add to the Geoscience Object(s).
48
+ :param upload_path: (Optional) Path objects will be published under.
49
+ :publish_objects: (Optional) Set False to return rather than publish objects.
50
+ :overwrite_existing_objects: (Optional) Set True to overwrite any existing object at the upload_path.
51
+
52
+ One of evo_workspace_metadata or service_manager_widget is required.
53
+
54
+ Converted objects will be published if either of the following is true:
55
+ - evo_workspace_metadata.hub_url is present, or
56
+ - service_manager_widget was passed to this function.
57
+
58
+ :return: List of Geoscience Objects, or list of ObjectMetadata if published.
59
+
60
+ :raise MissingConnectionDetailsError: If no connections details could be derived.
61
+ :raise ConflictingConnectionDetailsError: If both evo_workspace_metadata and service_manager_widget present.
62
+ :raise UBCFileIOError: If failed to read UBC file.
63
+ :raise UBCInvalidDataError: If an error was detected within the UBC file.
64
+ :raise UBCOOMError: If out of memory error occurred while handling the UBC file.
65
+ """
66
+
67
+ object_service_client, data_client = create_evo_object_service_and_data_client(
68
+ evo_workspace_metadata=evo_workspace_metadata, service_manager_widget=service_manager_widget
69
+ )
70
+
71
+ geoscience_objects = [utils.get_geoscience_object_from_ubc(data_client, files_path, epsg_code, tags)]
72
+ objects_metadata = None
73
+ if publish_objects:
74
+ logger.debug("Publishing Geoscience Objects")
75
+ objects_metadata = publish_geoscience_objects_sync(
76
+ geoscience_objects, object_service_client, data_client, upload_path, overwrite_existing_objects
77
+ )
78
+
79
+ return objects_metadata if objects_metadata else geoscience_objects
@@ -0,0 +1,100 @@
1
+ # Copyright © 2025 Bentley Systems, Incorporated
2
+ # Licensed under the Apache License, Version 2.0 (the "License");
3
+ # you may not use this file except in compliance with the License.
4
+ # You may obtain a copy of the License at
5
+ # http://www.apache.org/licenses/LICENSE-2.0
6
+ # Unless required by applicable law or agreed to in writing, software
7
+ # distributed under the License is distributed on an "AS IS" BASIS,
8
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
9
+ # See the License for the specific language governing permissions and
10
+ # limitations under the License.
11
+
12
+ import os
13
+ from typing import Optional
14
+
15
+ import numpy
16
+ import pyarrow as pa
17
+ from evo_schemas.components import (
18
+ ContinuousAttribute_V1_1_0,
19
+ NanContinuous_V1_0_1,
20
+ Rotation_V1_1_0,
21
+ )
22
+ from evo_schemas.elements import FloatArray1_V1_0_1
23
+ from evo_schemas.objects import Tensor3DGrid_V1_2_0, Tensor3DGrid_V1_2_0_GridCells3D
24
+
25
+ import evo.logging
26
+ from evo.data_converters.common import crs_from_epsg_code
27
+ from evo.data_converters.common.utils import get_object_tags, grid_bounding_box
28
+
29
+ from evo.data_converters.ubc.importer.ubc_reader import UBCMeshFileImporter, UBCPropertyFileImporter
30
+ from evo.objects.utils.data import ObjectDataClient
31
+
32
+ logger = evo.logging.getLogger("data_converters")
33
+
34
+
35
+ def _create_continuous_attributes(
36
+ data_client: ObjectDataClient, label_to_values: dict
37
+ ) -> list[ContinuousAttribute_V1_1_0]:
38
+ cell_attributes = []
39
+ for name, values in label_to_values.items():
40
+ table = pa.table({"values": values})
41
+ cell_attributes.append(
42
+ ContinuousAttribute_V1_1_0(
43
+ name=name,
44
+ key=name,
45
+ nan_description=NanContinuous_V1_0_1(values=[]),
46
+ values=FloatArray1_V1_0_1(**data_client.save_table(table)),
47
+ )
48
+ )
49
+ return cell_attributes
50
+
51
+
52
+ def _handle_ubc_files_list(files_path: list[str]) -> tuple[str, list[str]]:
53
+ ubc_mesh_file: str | None = None
54
+ ubc_numeric_values_files: list[str] = []
55
+ for f in files_path:
56
+ if f.endswith(".msh"):
57
+ if ubc_mesh_file:
58
+ raise ValueError("Multiple UBC mesh files provided.")
59
+ ubc_mesh_file = f
60
+ else: # assuming that all other files are numeric values files
61
+ ubc_numeric_values_files.append(f)
62
+
63
+ if not ubc_mesh_file:
64
+ raise ValueError("No UBC mesh file provided.")
65
+
66
+ return ubc_mesh_file, ubc_numeric_values_files
67
+
68
+
69
+ def get_geoscience_object_from_ubc(
70
+ data_client: ObjectDataClient, files_path: list[str], epsg_code: int, tags: Optional[dict[str, str]] = None
71
+ ) -> Tensor3DGrid_V1_2_0:
72
+ ubc_mesh_file, ubc_numeric_values_files = _handle_ubc_files_list(files_path)
73
+ name = os.path.splitext(os.path.basename(ubc_mesh_file))[0]
74
+ origin, spacings, size_of_dimensions = UBCMeshFileImporter(ubc_mesh_file).execute()
75
+
76
+ n_blocks = size_of_dimensions[0] * size_of_dimensions[1] * size_of_dimensions[2]
77
+ numerical_values = {}
78
+ for value_file in ubc_numeric_values_files:
79
+ values = UBCPropertyFileImporter(value_file).execute(n_blocks, size_of_dimensions)
80
+ numerical_values[os.path.splitext(os.path.basename(value_file))[0]] = values
81
+
82
+ bbox = grid_bounding_box(origin, numpy.identity(3), numpy.array([numpy.sum(d) for d in spacings]))
83
+ cell_attributes = _create_continuous_attributes(data_client, numerical_values)
84
+
85
+ grid_cells_3d = Tensor3DGrid_V1_2_0_GridCells3D(
86
+ cell_sizes_x=spacings[0].tolist(), cell_sizes_y=spacings[1].tolist(), cell_sizes_z=spacings[2].tolist()
87
+ )
88
+
89
+ return Tensor3DGrid_V1_2_0(
90
+ name=name,
91
+ origin=origin.tolist(),
92
+ size=size_of_dimensions,
93
+ grid_cells_3d=grid_cells_3d,
94
+ coordinate_reference_system=crs_from_epsg_code(epsg_code),
95
+ bounding_box=bbox,
96
+ rotation=Rotation_V1_1_0(dip_azimuth=0.0, dip=0.0, pitch=0.0),
97
+ cell_attributes=cell_attributes,
98
+ uuid=None,
99
+ tags=get_object_tags(path=os.path.basename(ubc_mesh_file), input_type="UBC", extra_tags=tags),
100
+ )