geocond 0.1.1__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.
- geocond-0.1.1/LICENSE +202 -0
- geocond-0.1.1/PKG-INFO +43 -0
- geocond-0.1.1/README.md +11 -0
- geocond-0.1.1/pyproject.toml +41 -0
- geocond-0.1.1/setup.cfg +4 -0
- geocond-0.1.1/src/geocond/__init__.py +3 -0
- geocond-0.1.1/src/geocond/compositing.py +154 -0
- geocond-0.1.1/src/geocond/geometry.py +130 -0
- geocond-0.1.1/src/geocond/py.typed +0 -0
- geocond-0.1.1/src/geocond/support.py +107 -0
- geocond-0.1.1/src/geocond/validation.py +61 -0
- geocond-0.1.1/src/geocond.egg-info/PKG-INFO +43 -0
- geocond-0.1.1/src/geocond.egg-info/SOURCES.txt +15 -0
- geocond-0.1.1/src/geocond.egg-info/dependency_links.txt +1 -0
- geocond-0.1.1/src/geocond.egg-info/requires.txt +20 -0
- geocond-0.1.1/src/geocond.egg-info/top_level.txt +1 -0
- geocond-0.1.1/tests/test_geometry_support.py +120 -0
geocond-0.1.1/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
geocond-0.1.1/PKG-INFO
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: geocond
|
|
3
|
+
Version: 0.1.1
|
|
4
|
+
Summary: Support-aware spatial conditioning, covariance estimation and sequential simulation
|
|
5
|
+
License-Expression: Apache-2.0
|
|
6
|
+
Project-URL: Repository, https://github.com/fsantibanezleal/GeoCond
|
|
7
|
+
Project-URL: Documentation, https://github.com/fsantibanezleal/GeoCond/tree/main/docs
|
|
8
|
+
Project-URL: Issues, https://github.com/fsantibanezleal/GeoCond/issues
|
|
9
|
+
Classifier: Development Status :: 3 - Alpha
|
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
|
11
|
+
Classifier: Topic :: Scientific/Engineering :: Mathematics
|
|
12
|
+
Requires-Python: >=3.12
|
|
13
|
+
Description-Content-Type: text/markdown
|
|
14
|
+
License-File: LICENSE
|
|
15
|
+
Requires-Dist: numpy<3,>=2.5
|
|
16
|
+
Requires-Dist: scipy<2,>=1.18
|
|
17
|
+
Provides-Extra: cuda
|
|
18
|
+
Requires-Dist: torch<3,>=2.14; extra == "cuda"
|
|
19
|
+
Provides-Extra: test
|
|
20
|
+
Requires-Dist: pytest>=9; extra == "test"
|
|
21
|
+
Requires-Dist: pytest-cov>=7; extra == "test"
|
|
22
|
+
Provides-Extra: reference
|
|
23
|
+
Requires-Dist: pykrige==1.7.3; extra == "reference"
|
|
24
|
+
Requires-Dist: gstools==1.7.0; extra == "reference"
|
|
25
|
+
Requires-Dist: welleng==0.29.1; extra == "reference"
|
|
26
|
+
Requires-Dist: scikit-learn<2,>=1.8; extra == "reference"
|
|
27
|
+
Provides-Extra: dev
|
|
28
|
+
Requires-Dist: build>=1.4; extra == "dev"
|
|
29
|
+
Requires-Dist: ruff>=0.14; extra == "dev"
|
|
30
|
+
Requires-Dist: twine>=6; extra == "dev"
|
|
31
|
+
Dynamic: license-file
|
|
32
|
+
|
|
33
|
+
# GeoCond
|
|
34
|
+
|
|
35
|
+
GeoCond is a Python library for support-aware spatial conditioning. Its scientific core separates observation geometry and sampling support from source-specific ingestion, web services and visualization.
|
|
36
|
+
|
|
37
|
+
The first release is under active implementation. The API and acceptance contract are recorded in [docs/api-contract.md](docs/api-contract.md); this repository does not yet claim a published or validated package release.
|
|
38
|
+
|
|
39
|
+
The complete planned core covers minimum-curvature trajectories, explicit support quadrature, conservative interval compositing, directional variograms, nearest/IDW baselines, simple/ordinary/universal kriging, full positive-semidefinite LMC cokriging, multiple-indicator CDFs, sequential Gaussian simulation and genuine training-image Direct Sampling. CPU calculations use NumPy/SciPy. CUDA kernels use an optional, lazily imported PyTorch dependency and retain the CPU algorithm's conditioning order.
|
|
40
|
+
|
|
41
|
+
Source adapters, geological assumptions, grouped training splits, neural training, native SNESIM orchestration and application deployment belong to consuming products. No field datasets, credentials, personal information or infrastructure bindings are part of the library.
|
|
42
|
+
|
|
43
|
+
Licensed under Apache-2.0. Numerical methods do not by themselves establish resource classes, reserves or operational certification.
|
geocond-0.1.1/README.md
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# GeoCond
|
|
2
|
+
|
|
3
|
+
GeoCond is a Python library for support-aware spatial conditioning. Its scientific core separates observation geometry and sampling support from source-specific ingestion, web services and visualization.
|
|
4
|
+
|
|
5
|
+
The first release is under active implementation. The API and acceptance contract are recorded in [docs/api-contract.md](docs/api-contract.md); this repository does not yet claim a published or validated package release.
|
|
6
|
+
|
|
7
|
+
The complete planned core covers minimum-curvature trajectories, explicit support quadrature, conservative interval compositing, directional variograms, nearest/IDW baselines, simple/ordinary/universal kriging, full positive-semidefinite LMC cokriging, multiple-indicator CDFs, sequential Gaussian simulation and genuine training-image Direct Sampling. CPU calculations use NumPy/SciPy. CUDA kernels use an optional, lazily imported PyTorch dependency and retain the CPU algorithm's conditioning order.
|
|
8
|
+
|
|
9
|
+
Source adapters, geological assumptions, grouped training splits, neural training, native SNESIM orchestration and application deployment belong to consuming products. No field datasets, credentials, personal information or infrastructure bindings are part of the library.
|
|
10
|
+
|
|
11
|
+
Licensed under Apache-2.0. Numerical methods do not by themselves establish resource classes, reserves or operational certification.
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=82"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "geocond"
|
|
7
|
+
version = "0.1.1"
|
|
8
|
+
description = "Support-aware spatial conditioning, covariance estimation and sequential simulation"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.12"
|
|
11
|
+
license = "Apache-2.0"
|
|
12
|
+
license-files = ["LICENSE"]
|
|
13
|
+
dependencies = ["numpy>=2.5,<3", "scipy>=1.18,<2"]
|
|
14
|
+
classifiers = ["Development Status :: 3 - Alpha", "Programming Language :: Python :: 3", "Topic :: Scientific/Engineering :: Mathematics"]
|
|
15
|
+
|
|
16
|
+
[project.optional-dependencies]
|
|
17
|
+
cuda = ["torch>=2.14,<3"]
|
|
18
|
+
test = ["pytest>=9", "pytest-cov>=7"]
|
|
19
|
+
reference = ["pykrige==1.7.3", "gstools==1.7.0", "welleng==0.29.1", "scikit-learn>=1.8,<2"]
|
|
20
|
+
dev = ["build>=1.4", "ruff>=0.14", "twine>=6"]
|
|
21
|
+
|
|
22
|
+
[project.urls]
|
|
23
|
+
Repository = "https://github.com/fsantibanezleal/GeoCond"
|
|
24
|
+
Documentation = "https://github.com/fsantibanezleal/GeoCond/tree/main/docs"
|
|
25
|
+
Issues = "https://github.com/fsantibanezleal/GeoCond/issues"
|
|
26
|
+
|
|
27
|
+
[tool.setuptools.packages.find]
|
|
28
|
+
where = ["src"]
|
|
29
|
+
|
|
30
|
+
[tool.setuptools.package-data]
|
|
31
|
+
geocond = ["py.typed"]
|
|
32
|
+
|
|
33
|
+
[tool.pytest.ini_options]
|
|
34
|
+
testpaths = ["tests"]
|
|
35
|
+
addopts = "-ra"
|
|
36
|
+
markers = ["cuda: requires a real CUDA device", "reference: independent optional reference package"]
|
|
37
|
+
|
|
38
|
+
[tool.ruff]
|
|
39
|
+
line-length = 100
|
|
40
|
+
target-version = "py312"
|
|
41
|
+
|
geocond-0.1.1/setup.cfg
ADDED
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
"""Conservative continuous-interval overlap, coverage and category proportions."""
|
|
2
|
+
|
|
3
|
+
from dataclasses import dataclass
|
|
4
|
+
|
|
5
|
+
import numpy as np
|
|
6
|
+
|
|
7
|
+
from .validation import ValidationError, array, positive
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
@dataclass(frozen=True)
|
|
11
|
+
class Composite:
|
|
12
|
+
start: float
|
|
13
|
+
end: float
|
|
14
|
+
mean: float
|
|
15
|
+
numerator: float
|
|
16
|
+
valid_length: float
|
|
17
|
+
missing_length: float
|
|
18
|
+
coverage: float
|
|
19
|
+
domain: str | None
|
|
20
|
+
parents: tuple[tuple[str, float], ...]
|
|
21
|
+
status: str
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def fixed_boundaries(start: float, end: float, length: float, *, residual: str = "keep"):
|
|
25
|
+
positive(length, "composite length")
|
|
26
|
+
if not np.isfinite([start, end]).all() or start < 0 or end <= start:
|
|
27
|
+
raise ValidationError("Composite range must be a positive measured-depth interval")
|
|
28
|
+
if residual not in {"keep", "drop"}:
|
|
29
|
+
raise ValidationError("Residual policy must be keep or drop")
|
|
30
|
+
count = int(np.floor((end - start) / length + 1e-12))
|
|
31
|
+
boundaries = start + np.arange(count + 1) * length
|
|
32
|
+
if residual == "keep" and end - boundaries[-1] > 1e-12 * max(1, end):
|
|
33
|
+
boundaries = np.r_[boundaries, end]
|
|
34
|
+
elif np.isclose(boundaries[-1], end, atol=1e-12, rtol=1e-12):
|
|
35
|
+
boundaries[-1] = end
|
|
36
|
+
return boundaries
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def _intervals(from_depth, to_depth, boundaries, source_ids, support_kind):
|
|
40
|
+
if support_kind != "continuous-interval":
|
|
41
|
+
raise ValidationError("Length compositing requires known continuous interval support")
|
|
42
|
+
a, b = array(from_depth, "from_depth", ndim=1), array(to_depth, "to_depth", ndim=1)
|
|
43
|
+
edges = array(boundaries, "boundaries", ndim=1)
|
|
44
|
+
if len(a) != len(b) or np.any(a < 0) or np.any(b <= a):
|
|
45
|
+
raise ValidationError("Every interval must have nonnegative start and positive length")
|
|
46
|
+
if len(edges) < 2 or edges[0] < 0 or np.any(np.diff(edges) <= 0):
|
|
47
|
+
raise ValidationError("Composite boundaries must be strictly increasing")
|
|
48
|
+
order = np.argsort(a, kind="stable")
|
|
49
|
+
if np.any(a[order][1:] < b[order][:-1]):
|
|
50
|
+
raise ValidationError(
|
|
51
|
+
"Overlapping intervals require a resolved observation policy before compositing"
|
|
52
|
+
)
|
|
53
|
+
ids = tuple(str(i) for i in range(len(a))) if source_ids is None else tuple(source_ids)
|
|
54
|
+
if len(ids) != len(a) or any(not isinstance(i, str) for i in ids) or len(set(ids)) != len(ids):
|
|
55
|
+
raise ValidationError("source_ids must be unique strings matching the input rows")
|
|
56
|
+
return a, b, edges, ids
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def composite_intervals(
|
|
60
|
+
from_depth,
|
|
61
|
+
to_depth,
|
|
62
|
+
values,
|
|
63
|
+
boundaries,
|
|
64
|
+
*,
|
|
65
|
+
support_kind="continuous-interval",
|
|
66
|
+
domains=None,
|
|
67
|
+
source_ids=None,
|
|
68
|
+
min_coverage=0,
|
|
69
|
+
):
|
|
70
|
+
a, b, edges, ids = _intervals(from_depth, to_depth, boundaries, source_ids, support_kind)
|
|
71
|
+
values = array(values, "values", ndim=1, finite=False)
|
|
72
|
+
if len(values) != len(a) or np.isinf(values).any():
|
|
73
|
+
raise ValidationError("Interval values must match rows and be finite or NaN for missing")
|
|
74
|
+
if not np.isfinite(min_coverage) or not 0 <= min_coverage <= 1:
|
|
75
|
+
raise ValidationError("min_coverage must be between zero and one")
|
|
76
|
+
if domains is None:
|
|
77
|
+
labels = [None] * len(a)
|
|
78
|
+
else:
|
|
79
|
+
labels = list(domains)
|
|
80
|
+
if len(labels) != len(a) or any(x is not None and not isinstance(x, str) for x in labels):
|
|
81
|
+
raise ValidationError("domains must contain one string or null per interval")
|
|
82
|
+
cuts = []
|
|
83
|
+
order = np.argsort(a, kind="stable")
|
|
84
|
+
for i, j in zip(order[:-1], order[1:], strict=True):
|
|
85
|
+
if labels[i] != labels[j]:
|
|
86
|
+
cuts.extend((b[i], a[j]))
|
|
87
|
+
edges = np.unique(np.r_[edges, [x for x in cuts if edges[0] < x < edges[-1]]])
|
|
88
|
+
result = []
|
|
89
|
+
for lo, hi in zip(edges[:-1], edges[1:], strict=True):
|
|
90
|
+
overlap = np.maximum(0, np.minimum(b, hi) - np.maximum(a, lo))
|
|
91
|
+
selected = np.flatnonzero(overlap > 0)
|
|
92
|
+
valid = selected[np.isfinite(values[selected])]
|
|
93
|
+
length = float(overlap[valid].sum())
|
|
94
|
+
numerator = float(overlap[valid] @ values[valid])
|
|
95
|
+
coverage = length / (hi - lo)
|
|
96
|
+
domain_set = {labels[i] for i in selected}
|
|
97
|
+
if len(domain_set) > 1:
|
|
98
|
+
raise ValidationError("Composite crosses unresolved domains")
|
|
99
|
+
status = (
|
|
100
|
+
"estimated"
|
|
101
|
+
if length > 0 and coverage + 1e-14 >= min_coverage
|
|
102
|
+
else "insufficient-coverage"
|
|
103
|
+
)
|
|
104
|
+
result.append(
|
|
105
|
+
Composite(
|
|
106
|
+
float(lo),
|
|
107
|
+
float(hi),
|
|
108
|
+
numerator / length if status == "estimated" else np.nan,
|
|
109
|
+
numerator,
|
|
110
|
+
length,
|
|
111
|
+
float(hi - lo - length),
|
|
112
|
+
float(coverage),
|
|
113
|
+
next(iter(domain_set), None),
|
|
114
|
+
tuple((ids[i], float(overlap[i])) for i in selected),
|
|
115
|
+
status,
|
|
116
|
+
)
|
|
117
|
+
)
|
|
118
|
+
return tuple(result)
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
def composite_categories(
|
|
122
|
+
from_depth,
|
|
123
|
+
to_depth,
|
|
124
|
+
categories,
|
|
125
|
+
boundaries,
|
|
126
|
+
*,
|
|
127
|
+
support_kind="continuous-interval",
|
|
128
|
+
source_ids=None,
|
|
129
|
+
):
|
|
130
|
+
a, b, edges, ids = _intervals(from_depth, to_depth, boundaries, source_ids, support_kind)
|
|
131
|
+
labels = list(categories)
|
|
132
|
+
if len(labels) != len(a) or any(
|
|
133
|
+
x is not None and not isinstance(x, (str, int)) for x in labels
|
|
134
|
+
):
|
|
135
|
+
raise ValidationError("Categories must be explicit string/integer codes or null")
|
|
136
|
+
result = []
|
|
137
|
+
for lo, hi in zip(edges[:-1], edges[1:], strict=True):
|
|
138
|
+
overlap = np.maximum(0, np.minimum(b, hi) - np.maximum(a, lo))
|
|
139
|
+
lengths = {}
|
|
140
|
+
for i in np.flatnonzero(overlap > 0):
|
|
141
|
+
if labels[i] is not None:
|
|
142
|
+
lengths[labels[i]] = lengths.get(labels[i], 0.0) + float(overlap[i])
|
|
143
|
+
total = sum(lengths.values())
|
|
144
|
+
result.append(
|
|
145
|
+
{
|
|
146
|
+
"start": float(lo),
|
|
147
|
+
"end": float(hi),
|
|
148
|
+
"coverage": total / (hi - lo),
|
|
149
|
+
"proportions": {k: v / total for k, v in lengths.items()},
|
|
150
|
+
"missing_length": float(hi - lo - total),
|
|
151
|
+
"parents": tuple((ids[i], float(overlap[i])) for i in np.flatnonzero(overlap > 0)),
|
|
152
|
+
}
|
|
153
|
+
)
|
|
154
|
+
return tuple(result)
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
"""Minimum-curvature trajectories in east/north/elevation-up coordinates."""
|
|
2
|
+
|
|
3
|
+
from dataclasses import dataclass, field
|
|
4
|
+
|
|
5
|
+
import numpy as np
|
|
6
|
+
from numpy.typing import ArrayLike, NDArray
|
|
7
|
+
|
|
8
|
+
from .validation import ValidationError, array
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
@dataclass(frozen=True)
|
|
12
|
+
class TrajectorySamples:
|
|
13
|
+
measured_depth: NDArray[np.float64]
|
|
14
|
+
points: NDArray[np.float64]
|
|
15
|
+
tangents: NDArray[np.float64]
|
|
16
|
+
extended: NDArray[np.bool_]
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def tangent(azimuth: ArrayLike, dip: ArrayLike, *, angle_unit: str = "degree"):
|
|
20
|
+
a, d = array(azimuth, "azimuth"), array(dip, "dip")
|
|
21
|
+
if a.shape != d.shape:
|
|
22
|
+
raise ValidationError("azimuth and dip shapes differ")
|
|
23
|
+
if angle_unit not in {"degree", "radian"}:
|
|
24
|
+
raise ValidationError("angle_unit must be degree or radian")
|
|
25
|
+
if angle_unit == "degree":
|
|
26
|
+
a, d = np.deg2rad(a), np.deg2rad(d)
|
|
27
|
+
if np.any(np.abs(d) > np.pi / 2 + 1e-14):
|
|
28
|
+
raise ValidationError("dip must be between -90 and 90 degrees")
|
|
29
|
+
return np.stack((np.cos(d) * np.sin(a), np.cos(d) * np.cos(a), np.sin(d)), axis=-1)
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def _arc(t0, t1, length, fraction):
|
|
33
|
+
dot = float(np.clip(t0 @ t1, -1, 1))
|
|
34
|
+
beta = float(np.arctan2(np.linalg.norm(np.cross(t0, t1)), dot))
|
|
35
|
+
if np.pi - beta < 1e-7:
|
|
36
|
+
raise ValidationError("Antiparallel survey tangents do not determine an arc plane")
|
|
37
|
+
if beta < 1e-8:
|
|
38
|
+
direction = (1 - fraction) * t0 + fraction * t1
|
|
39
|
+
direction /= np.linalg.norm(direction)
|
|
40
|
+
displacement = length * fraction * ((1 - fraction / 2) * t0 + fraction / 2 * t1)
|
|
41
|
+
return displacement, direction, beta
|
|
42
|
+
normal = (t1 - dot * t0) / np.sin(beta)
|
|
43
|
+
angle = fraction * beta
|
|
44
|
+
displacement = length / beta * (np.sin(angle) * t0 + 2 * np.sin(angle / 2) ** 2 * normal)
|
|
45
|
+
return displacement, np.cos(angle) * t0 + np.sin(angle) * normal, beta
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
@dataclass(frozen=True)
|
|
49
|
+
class Survey:
|
|
50
|
+
collar: ArrayLike
|
|
51
|
+
measured_depth: ArrayLike
|
|
52
|
+
azimuth: ArrayLike
|
|
53
|
+
dip: ArrayLike
|
|
54
|
+
angle_unit: str = "degree"
|
|
55
|
+
start_extension: str = "error"
|
|
56
|
+
end_extension: str = "error"
|
|
57
|
+
station_points: NDArray[np.float64] = field(init=False, repr=False)
|
|
58
|
+
station_tangents: NDArray[np.float64] = field(init=False, repr=False)
|
|
59
|
+
dogleg_radians: NDArray[np.float64] = field(init=False, repr=False)
|
|
60
|
+
|
|
61
|
+
def __post_init__(self):
|
|
62
|
+
collar = array(self.collar, "collar", ndim=1)
|
|
63
|
+
md = array(self.measured_depth, "measured_depth", ndim=1)
|
|
64
|
+
az = array(self.azimuth, "azimuth", ndim=1)
|
|
65
|
+
dip = array(self.dip, "dip", ndim=1)
|
|
66
|
+
if collar.shape != (3,) or not len(md) or az.shape != md.shape or dip.shape != md.shape:
|
|
67
|
+
raise ValidationError("Survey needs a 3D collar and matching nonempty station arrays")
|
|
68
|
+
if md[0] < 0 or np.any(np.diff(md) <= 0):
|
|
69
|
+
raise ValidationError(
|
|
70
|
+
"Measured station depths must be nonnegative and strictly increasing"
|
|
71
|
+
)
|
|
72
|
+
for policy in (self.start_extension, self.end_extension):
|
|
73
|
+
if policy not in {"error", "tangent"}:
|
|
74
|
+
raise ValidationError("Extension policy must be error or tangent")
|
|
75
|
+
if md[0] > 0 and self.start_extension != "tangent":
|
|
76
|
+
raise ValidationError(
|
|
77
|
+
"First station is below the collar; explicit tangent extension required"
|
|
78
|
+
)
|
|
79
|
+
ts = tangent(az, dip, angle_unit=self.angle_unit)
|
|
80
|
+
xyz = np.empty((len(md), 3))
|
|
81
|
+
xyz[0] = collar + md[0] * ts[0]
|
|
82
|
+
doglegs = np.empty(max(0, len(md) - 1))
|
|
83
|
+
for i in range(len(md) - 1):
|
|
84
|
+
delta, _, doglegs[i] = _arc(ts[i], ts[i + 1], md[i + 1] - md[i], 1)
|
|
85
|
+
xyz[i + 1] = xyz[i] + delta
|
|
86
|
+
for name, value in [
|
|
87
|
+
("collar", collar),
|
|
88
|
+
("measured_depth", md),
|
|
89
|
+
("azimuth", az),
|
|
90
|
+
("dip", dip),
|
|
91
|
+
("station_points", xyz),
|
|
92
|
+
("station_tangents", ts),
|
|
93
|
+
("dogleg_radians", doglegs),
|
|
94
|
+
]:
|
|
95
|
+
value.setflags(write=False)
|
|
96
|
+
object.__setattr__(self, name, value)
|
|
97
|
+
|
|
98
|
+
def at(self, depths: ArrayLike) -> TrajectorySamples:
|
|
99
|
+
md = array(np.atleast_1d(depths), "depths", ndim=1)
|
|
100
|
+
if np.any(md < 0):
|
|
101
|
+
raise ValidationError("Evaluation depths must be nonnegative")
|
|
102
|
+
lo, hi = self.measured_depth[[0, -1]]
|
|
103
|
+
if np.any(md < lo) and self.start_extension != "tangent":
|
|
104
|
+
raise ValidationError("Evaluation precedes first survey station")
|
|
105
|
+
if np.any(md > hi) and self.end_extension != "tangent":
|
|
106
|
+
raise ValidationError(
|
|
107
|
+
"Evaluation exceeds last station; explicit tangent extension required"
|
|
108
|
+
)
|
|
109
|
+
xyz, direction = np.empty((len(md), 3)), np.empty((len(md), 3))
|
|
110
|
+
extended = (md < lo) | (md > hi)
|
|
111
|
+
for row, depth in enumerate(md):
|
|
112
|
+
if depth <= lo:
|
|
113
|
+
xyz[row] = self.collar + depth * self.station_tangents[0]
|
|
114
|
+
direction[row] = self.station_tangents[0]
|
|
115
|
+
elif depth >= hi:
|
|
116
|
+
xyz[row] = self.station_points[-1] + (depth - hi) * self.station_tangents[-1]
|
|
117
|
+
direction[row] = self.station_tangents[-1]
|
|
118
|
+
else:
|
|
119
|
+
i = np.searchsorted(self.measured_depth, depth, side="right") - 1
|
|
120
|
+
length = self.measured_depth[i + 1] - self.measured_depth[i]
|
|
121
|
+
delta, direction[row], _ = _arc(
|
|
122
|
+
self.station_tangents[i],
|
|
123
|
+
self.station_tangents[i + 1],
|
|
124
|
+
length,
|
|
125
|
+
(depth - self.measured_depth[i]) / length,
|
|
126
|
+
)
|
|
127
|
+
xyz[row] = self.station_points[i] + delta
|
|
128
|
+
for item in (xyz, direction, extended):
|
|
129
|
+
item.setflags(write=False)
|
|
130
|
+
return TrajectorySamples(md, xyz, direction, extended)
|
|
File without changes
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
"""Explicit known sampling measures and Gauss-Legendre support quadrature."""
|
|
2
|
+
|
|
3
|
+
from dataclasses import dataclass
|
|
4
|
+
from itertools import product
|
|
5
|
+
|
|
6
|
+
import numpy as np
|
|
7
|
+
from numpy.polynomial.legendre import leggauss
|
|
8
|
+
from numpy.typing import ArrayLike
|
|
9
|
+
|
|
10
|
+
from .geometry import Survey
|
|
11
|
+
from .validation import ValidationError, array, integer, rotation_matrix
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
@dataclass(frozen=True)
|
|
15
|
+
class Support:
|
|
16
|
+
points: ArrayLike
|
|
17
|
+
weights: ArrayLike
|
|
18
|
+
kind: str
|
|
19
|
+
id: str = ""
|
|
20
|
+
measure: str | None = None
|
|
21
|
+
|
|
22
|
+
def __post_init__(self):
|
|
23
|
+
points, weights = (
|
|
24
|
+
array(self.points, "support points", ndim=2),
|
|
25
|
+
array(self.weights, "support weights", ndim=1),
|
|
26
|
+
)
|
|
27
|
+
if points.shape != (len(weights), 3) or not len(weights):
|
|
28
|
+
raise ValidationError("Support requires nonempty (n,3) points and n weights")
|
|
29
|
+
if self.kind not in {"point", "line", "trajectory", "block", "weighted"}:
|
|
30
|
+
raise ValidationError(
|
|
31
|
+
"Support must declare a known point, line, trajectory, block or weighted measure"
|
|
32
|
+
)
|
|
33
|
+
if np.any(weights < 0) or not np.isclose(weights.sum(), 1, atol=1e-12, rtol=0):
|
|
34
|
+
raise ValidationError("Known support weights must be nonnegative and sum to one")
|
|
35
|
+
if self.kind == "point" and len(weights) != 1:
|
|
36
|
+
raise ValidationError("Point support contains exactly one coordinate")
|
|
37
|
+
measure = self.measure
|
|
38
|
+
if measure is None:
|
|
39
|
+
if self.kind == "weighted":
|
|
40
|
+
raise ValidationError(
|
|
41
|
+
"Weighted support must explicitly declare discrete or continuous measure"
|
|
42
|
+
)
|
|
43
|
+
measure = "discrete" if self.kind == "point" else "continuous"
|
|
44
|
+
if measure not in {"continuous", "discrete"}:
|
|
45
|
+
raise ValidationError("Support measure must be continuous or discrete")
|
|
46
|
+
if self.kind == "point" and measure != "discrete":
|
|
47
|
+
raise ValidationError("A point support is a discrete sampling measure")
|
|
48
|
+
object.__setattr__(self, "points", points)
|
|
49
|
+
object.__setattr__(self, "weights", weights)
|
|
50
|
+
object.__setattr__(self, "measure", measure)
|
|
51
|
+
|
|
52
|
+
@property
|
|
53
|
+
def center(self):
|
|
54
|
+
return self.weights @ self.points
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def point_support(point: ArrayLike, *, id: str = "") -> Support:
|
|
58
|
+
point = array(point, "point", ndim=1)
|
|
59
|
+
return Support(point[None, :], [1.0], "point", id)
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def line_support(start: ArrayLike, end: ArrayLike, *, order: int = 8, id: str = "") -> Support:
|
|
63
|
+
a, b = array(start, "start", ndim=1), array(end, "end", ndim=1)
|
|
64
|
+
if a.shape != (3,) or b.shape != (3,) or np.linalg.norm(b - a) == 0:
|
|
65
|
+
raise ValidationError("Line support needs distinct 3D endpoints")
|
|
66
|
+
nodes, weights = leggauss(integer(order, "quadrature order"))
|
|
67
|
+
return Support(a + (nodes[:, None] + 1) / 2 * (b - a), weights / 2, "line", id)
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def trajectory_support(
|
|
71
|
+
survey: Survey, start: float, end: float, *, order: int = 8, id: str = ""
|
|
72
|
+
) -> Support:
|
|
73
|
+
if not np.isfinite([start, end]).all() or start < 0 or end <= start:
|
|
74
|
+
raise ValidationError("Trajectory support requires a positive measured-depth interval")
|
|
75
|
+
nodes, weights = leggauss(integer(order, "quadrature order"))
|
|
76
|
+
boundaries = np.r_[
|
|
77
|
+
start,
|
|
78
|
+
survey.measured_depth[(survey.measured_depth > start) & (survey.measured_depth < end)],
|
|
79
|
+
end,
|
|
80
|
+
]
|
|
81
|
+
points, measure = [], []
|
|
82
|
+
for a, b in zip(boundaries[:-1], boundaries[1:], strict=True):
|
|
83
|
+
points.append(survey.at(a + (nodes + 1) / 2 * (b - a)).points)
|
|
84
|
+
measure.append(weights / 2 * (b - a) / (end - start))
|
|
85
|
+
return Support(np.concatenate(points), np.concatenate(measure), "trajectory", id)
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
def block_support(
|
|
89
|
+
center: ArrayLike,
|
|
90
|
+
size: ArrayLike,
|
|
91
|
+
*,
|
|
92
|
+
order: int | tuple = 4,
|
|
93
|
+
rotation: ArrayLike | None = None,
|
|
94
|
+
id: str = "",
|
|
95
|
+
) -> Support:
|
|
96
|
+
center, size = array(center, "block center", ndim=1), array(size, "block size", ndim=1)
|
|
97
|
+
if center.shape != (3,) or size.shape != (3,) or np.any(size <= 0):
|
|
98
|
+
raise ValidationError("Block center and positive size must each have three components")
|
|
99
|
+
orders = (order,) * 3 if np.isscalar(order) else tuple(order)
|
|
100
|
+
if len(orders) != 3:
|
|
101
|
+
raise ValidationError("Block quadrature needs three orders")
|
|
102
|
+
rules = [leggauss(integer(o, "quadrature order")) for o in orders]
|
|
103
|
+
points, weights = [], []
|
|
104
|
+
for indices in product(*(range(o) for o in orders)):
|
|
105
|
+
points.append([rules[d][0][i] * size[d] / 2 for d, i in enumerate(indices)])
|
|
106
|
+
weights.append(np.prod([rules[d][1][i] / 2 for d, i in enumerate(indices)]))
|
|
107
|
+
return Support(center + np.asarray(points) @ rotation_matrix(rotation).T, weights, "block", id)
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"""Strict numerical validation and explicit failure types."""
|
|
2
|
+
|
|
3
|
+
from collections.abc import Callable
|
|
4
|
+
|
|
5
|
+
import numpy as np
|
|
6
|
+
from numpy.typing import ArrayLike, NDArray
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class ValidationError(ValueError):
|
|
10
|
+
"""Shared input violates a scientific or numerical contract."""
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class NumericalError(RuntimeError):
|
|
14
|
+
"""A scientifically specified system cannot be solved within its policy."""
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class CancelledError(RuntimeError):
|
|
18
|
+
"""Computation was cancelled; no complete result is available."""
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def array(
|
|
22
|
+
value: ArrayLike, name: str, *, ndim: int | None = None, finite: bool = True
|
|
23
|
+
) -> NDArray[np.float64]:
|
|
24
|
+
raw = np.asarray(value)
|
|
25
|
+
if raw.dtype.kind not in "iuf":
|
|
26
|
+
raise ValidationError(f"{name} must contain numeric values, not strings or booleans")
|
|
27
|
+
result = np.array(raw, dtype=np.float64, copy=True)
|
|
28
|
+
if ndim is not None and result.ndim != ndim:
|
|
29
|
+
raise ValidationError(f"{name} must have {ndim} dimensions")
|
|
30
|
+
if finite and not np.isfinite(result).all():
|
|
31
|
+
raise ValidationError(f"{name} must contain only finite values")
|
|
32
|
+
result.setflags(write=False)
|
|
33
|
+
return result
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def positive(value: float, name: str, *, zero: bool = False) -> float:
|
|
37
|
+
if isinstance(value, (bool, np.bool_)) or not np.isfinite(value):
|
|
38
|
+
raise ValidationError(f"{name} must be a finite number")
|
|
39
|
+
if value < 0 if zero else value <= 0:
|
|
40
|
+
raise ValidationError(f"{name} must be {'nonnegative' if zero else 'positive'}")
|
|
41
|
+
return float(value)
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def integer(value: int, name: str, *, minimum: int = 1) -> int:
|
|
45
|
+
if isinstance(value, (bool, np.bool_)) or int(value) != value or value < minimum:
|
|
46
|
+
raise ValidationError(f"{name} must be an integer >= {minimum}")
|
|
47
|
+
return int(value)
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def cancel_if_requested(cancel: Callable[[], bool] | None) -> None:
|
|
51
|
+
if cancel is not None and cancel():
|
|
52
|
+
raise CancelledError("Computation cancelled before a complete result was produced")
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def rotation_matrix(value: ArrayLike | None) -> NDArray[np.float64]:
|
|
56
|
+
result = array(np.eye(3) if value is None else value, "rotation", ndim=2)
|
|
57
|
+
if result.shape != (3, 3) or not np.allclose(result.T @ result, np.eye(3), atol=1e-10):
|
|
58
|
+
raise ValidationError("rotation must be an orthonormal 3 by 3 matrix")
|
|
59
|
+
if not np.isclose(np.linalg.det(result), 1, atol=1e-10):
|
|
60
|
+
raise ValidationError("rotation must be proper and right handed")
|
|
61
|
+
return result
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: geocond
|
|
3
|
+
Version: 0.1.1
|
|
4
|
+
Summary: Support-aware spatial conditioning, covariance estimation and sequential simulation
|
|
5
|
+
License-Expression: Apache-2.0
|
|
6
|
+
Project-URL: Repository, https://github.com/fsantibanezleal/GeoCond
|
|
7
|
+
Project-URL: Documentation, https://github.com/fsantibanezleal/GeoCond/tree/main/docs
|
|
8
|
+
Project-URL: Issues, https://github.com/fsantibanezleal/GeoCond/issues
|
|
9
|
+
Classifier: Development Status :: 3 - Alpha
|
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
|
11
|
+
Classifier: Topic :: Scientific/Engineering :: Mathematics
|
|
12
|
+
Requires-Python: >=3.12
|
|
13
|
+
Description-Content-Type: text/markdown
|
|
14
|
+
License-File: LICENSE
|
|
15
|
+
Requires-Dist: numpy<3,>=2.5
|
|
16
|
+
Requires-Dist: scipy<2,>=1.18
|
|
17
|
+
Provides-Extra: cuda
|
|
18
|
+
Requires-Dist: torch<3,>=2.14; extra == "cuda"
|
|
19
|
+
Provides-Extra: test
|
|
20
|
+
Requires-Dist: pytest>=9; extra == "test"
|
|
21
|
+
Requires-Dist: pytest-cov>=7; extra == "test"
|
|
22
|
+
Provides-Extra: reference
|
|
23
|
+
Requires-Dist: pykrige==1.7.3; extra == "reference"
|
|
24
|
+
Requires-Dist: gstools==1.7.0; extra == "reference"
|
|
25
|
+
Requires-Dist: welleng==0.29.1; extra == "reference"
|
|
26
|
+
Requires-Dist: scikit-learn<2,>=1.8; extra == "reference"
|
|
27
|
+
Provides-Extra: dev
|
|
28
|
+
Requires-Dist: build>=1.4; extra == "dev"
|
|
29
|
+
Requires-Dist: ruff>=0.14; extra == "dev"
|
|
30
|
+
Requires-Dist: twine>=6; extra == "dev"
|
|
31
|
+
Dynamic: license-file
|
|
32
|
+
|
|
33
|
+
# GeoCond
|
|
34
|
+
|
|
35
|
+
GeoCond is a Python library for support-aware spatial conditioning. Its scientific core separates observation geometry and sampling support from source-specific ingestion, web services and visualization.
|
|
36
|
+
|
|
37
|
+
The first release is under active implementation. The API and acceptance contract are recorded in [docs/api-contract.md](docs/api-contract.md); this repository does not yet claim a published or validated package release.
|
|
38
|
+
|
|
39
|
+
The complete planned core covers minimum-curvature trajectories, explicit support quadrature, conservative interval compositing, directional variograms, nearest/IDW baselines, simple/ordinary/universal kriging, full positive-semidefinite LMC cokriging, multiple-indicator CDFs, sequential Gaussian simulation and genuine training-image Direct Sampling. CPU calculations use NumPy/SciPy. CUDA kernels use an optional, lazily imported PyTorch dependency and retain the CPU algorithm's conditioning order.
|
|
40
|
+
|
|
41
|
+
Source adapters, geological assumptions, grouped training splits, neural training, native SNESIM orchestration and application deployment belong to consuming products. No field datasets, credentials, personal information or infrastructure bindings are part of the library.
|
|
42
|
+
|
|
43
|
+
Licensed under Apache-2.0. Numerical methods do not by themselves establish resource classes, reserves or operational certification.
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
src/geocond/__init__.py
|
|
5
|
+
src/geocond/compositing.py
|
|
6
|
+
src/geocond/geometry.py
|
|
7
|
+
src/geocond/py.typed
|
|
8
|
+
src/geocond/support.py
|
|
9
|
+
src/geocond/validation.py
|
|
10
|
+
src/geocond.egg-info/PKG-INFO
|
|
11
|
+
src/geocond.egg-info/SOURCES.txt
|
|
12
|
+
src/geocond.egg-info/dependency_links.txt
|
|
13
|
+
src/geocond.egg-info/requires.txt
|
|
14
|
+
src/geocond.egg-info/top_level.txt
|
|
15
|
+
tests/test_geometry_support.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
numpy<3,>=2.5
|
|
2
|
+
scipy<2,>=1.18
|
|
3
|
+
|
|
4
|
+
[cuda]
|
|
5
|
+
torch<3,>=2.14
|
|
6
|
+
|
|
7
|
+
[dev]
|
|
8
|
+
build>=1.4
|
|
9
|
+
ruff>=0.14
|
|
10
|
+
twine>=6
|
|
11
|
+
|
|
12
|
+
[reference]
|
|
13
|
+
pykrige==1.7.3
|
|
14
|
+
gstools==1.7.0
|
|
15
|
+
welleng==0.29.1
|
|
16
|
+
scikit-learn<2,>=1.8
|
|
17
|
+
|
|
18
|
+
[test]
|
|
19
|
+
pytest>=9
|
|
20
|
+
pytest-cov>=7
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
geocond
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import numpy as np
|
|
2
|
+
import pytest
|
|
3
|
+
from numpy.testing import assert_allclose
|
|
4
|
+
|
|
5
|
+
from geocond.geometry import Survey, tangent
|
|
6
|
+
from geocond.support import Support, block_support, line_support, point_support, trajectory_support
|
|
7
|
+
from geocond.compositing import composite_categories, composite_intervals, fixed_boundaries
|
|
8
|
+
from geocond.validation import ValidationError
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def test_straight_directions_and_arbitrary_tangent():
|
|
12
|
+
for az, dip in [(0, -90), (90, 0), (359, -37)]:
|
|
13
|
+
survey = Survey([12, 34, 500], [0, 100], [az, az], [dip, dip])
|
|
14
|
+
depths = np.array([0, 17, 100])
|
|
15
|
+
assert_allclose(
|
|
16
|
+
survey.at(depths).points, survey.collar + depths[:, None] * tangent(az, dip), atol=1e-12
|
|
17
|
+
)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def test_quarter_arc_and_inserted_station_are_same_curve():
|
|
21
|
+
length = 100.0
|
|
22
|
+
original = Survey([0, 0, 0], [0, length], [0, 0], [0, -90])
|
|
23
|
+
refined = Survey([0, 0, 0], [0, 50, length], [0, 0, 0], [0, -45, -90])
|
|
24
|
+
depths = np.linspace(0, length, 101)
|
|
25
|
+
theta = depths / length * np.pi / 2
|
|
26
|
+
exact = np.column_stack(
|
|
27
|
+
[
|
|
28
|
+
np.zeros_like(theta),
|
|
29
|
+
2 * length / np.pi * np.sin(theta),
|
|
30
|
+
-2 * length / np.pi * (1 - np.cos(theta)),
|
|
31
|
+
]
|
|
32
|
+
)
|
|
33
|
+
assert_allclose(original.at(depths).points, exact, atol=1e-12)
|
|
34
|
+
assert_allclose(refined.at(depths).points, exact, atol=1e-12)
|
|
35
|
+
assert not np.allclose(original.at([50]).points[0], original.station_points[-1] / 2)
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def test_azimuth_wrap_near_zero_and_antiparallel():
|
|
39
|
+
survey = Survey([0, 0, 0], [0, 100], [359, 1], [0, 0])
|
|
40
|
+
assert abs(survey.station_points[-1, 0]) < 1e-12
|
|
41
|
+
assert survey.station_points[-1, 1] > 99.9
|
|
42
|
+
tiny = Survey([0, 0, 0], [0, 100], [1, 1 + 1e-9], [-20, -20])
|
|
43
|
+
assert np.isfinite(tiny.at([50]).points).all()
|
|
44
|
+
with pytest.raises(ValidationError, match="Antiparallel"):
|
|
45
|
+
Survey([0, 0, 0], [0, 100], [0, 180], [0, 0])
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def test_extensions_are_explicit_and_inputs_are_owned():
|
|
49
|
+
with pytest.raises(ValidationError, match="First station"):
|
|
50
|
+
Survey([0, 0, 0], [10, 50], [0, 0], [-90, -90])
|
|
51
|
+
md = np.array([10.0, 50.0])
|
|
52
|
+
survey = Survey([0, 0, 0], md, [0, 0], [-90, -90], start_extension="tangent")
|
|
53
|
+
md[1] = 1000
|
|
54
|
+
assert survey.measured_depth[-1] == 50
|
|
55
|
+
assert survey.at([0, 10, 25]).extended.tolist() == [True, False, False]
|
|
56
|
+
with pytest.raises(ValidationError, match="exceeds"):
|
|
57
|
+
survey.at([51])
|
|
58
|
+
with pytest.raises(ValueError):
|
|
59
|
+
survey.collar[0] = 3
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
@pytest.mark.parametrize(
|
|
63
|
+
"md,az,dip",
|
|
64
|
+
[([0, 0], [0, 0], [0, 0]), ([0, 1], [0, 0], [0, -91]), ([0, 1], [0, np.inf], [0, 0])],
|
|
65
|
+
)
|
|
66
|
+
def test_bad_survey_rejected(md, az, dip):
|
|
67
|
+
with pytest.raises(ValidationError):
|
|
68
|
+
Survey([0, 0, 0], md, az, dip)
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def test_support_quadrature_integrates_polynomials_and_arc():
|
|
72
|
+
line = line_support([0, 0, 0], [2, 0, 0], order=3)
|
|
73
|
+
assert_allclose(line.weights @ line.points[:, 0] ** 4, 16 / 5)
|
|
74
|
+
block = block_support([1, 2, 3], [2, 4, 6], order=(3, 4, 5))
|
|
75
|
+
assert_allclose(block.center, [1, 2, 3])
|
|
76
|
+
assert_allclose(block.weights @ (block.points[:, 1] - 2) ** 2, 4 / 3)
|
|
77
|
+
survey = Survey([0, 0, 0], [0, 50, 100], [0, 0, 0], [0, -45, -90])
|
|
78
|
+
support = trajectory_support(survey, 0, 100, order=8)
|
|
79
|
+
assert_allclose(support.center, [0, 400 / np.pi**2, 400 / np.pi**2 - 200 / np.pi], atol=1e-12)
|
|
80
|
+
assert support.measure == "continuous"
|
|
81
|
+
assert point_support([0, 0, 0]).measure == "discrete"
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
def test_unknown_support_and_bad_weights_not_accepted():
|
|
85
|
+
for kwargs in [{"kind": "sampling-envelope"}, {"kind": "weighted"}]:
|
|
86
|
+
with pytest.raises(ValidationError):
|
|
87
|
+
Support([[0, 0, 0]], [1], **kwargs)
|
|
88
|
+
with pytest.raises(ValidationError):
|
|
89
|
+
Support([[0, 0, 0], [1, 1, 1]], [0.5, -0.5], "weighted", measure="discrete")
|
|
90
|
+
with pytest.raises(ValidationError):
|
|
91
|
+
block_support([0, 0, 0], [1, 1, 1], rotation=np.diag([-1, 1, 1]))
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
def test_composite_conservation_coverage_missing_and_domains():
|
|
95
|
+
result = composite_intervals([0, 1], [1, 3], [2, 5], [0, 2, 3], source_ids=["s0", "s1"])
|
|
96
|
+
assert_allclose([c.mean for c in result], [3.5, 5])
|
|
97
|
+
assert sum(c.numerator for c in result) == 12
|
|
98
|
+
assert sum(c.valid_length for c in result) == 3
|
|
99
|
+
assert result[0].parents == (("s0", 1), ("s1", 1))
|
|
100
|
+
missing = composite_intervals([0, 2, 3], [1, 3, 4], [0, np.nan, 8], [0, 4])[0]
|
|
101
|
+
assert (missing.mean, missing.coverage, missing.missing_length) == (4, 0.5, 2)
|
|
102
|
+
split = composite_intervals([0, 1], [1, 3], [2, 5], [0, 3], domains=["ore", "waste"])
|
|
103
|
+
assert [c.domain for c in split] == ["ore", "waste"]
|
|
104
|
+
assert_allclose([c.mean for c in split], [2, 5])
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
def test_composite_rejects_overlap_and_envelopes_residual_explicit():
|
|
108
|
+
with pytest.raises(ValidationError, match="Overlapping"):
|
|
109
|
+
composite_intervals([0, 0.5], [1, 2], [2, 3], [0, 2])
|
|
110
|
+
with pytest.raises(ValidationError, match="known continuous"):
|
|
111
|
+
composite_intervals([0], [1], [3], [0, 1], support_kind="sampling-envelope")
|
|
112
|
+
assert_allclose(fixed_boundaries(0, 5, 2), [0, 2, 4, 5])
|
|
113
|
+
assert_allclose(fixed_boundaries(0, 5, 2, residual="drop"), [0, 2, 4])
|
|
114
|
+
assert np.isnan(composite_intervals([0], [1], [2], [0, 2], min_coverage=0.8)[0].mean)
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
def test_category_proportions_do_not_average_codes_or_fill_unknown():
|
|
118
|
+
result = composite_categories([0, 1, 2], [1, 2, 4], ["A", None, "B"], [0, 4])[0]
|
|
119
|
+
assert result["proportions"] == {"A": 1 / 3, "B": 2 / 3}
|
|
120
|
+
assert result["coverage"] == 0.75
|