Skip to content

Commit bbbfe0c

Browse files
committed
fix: add isosurfacing and scalar field method to base feature
adds methods to get the isosurface or scalar field of a geological feature. These return lists and can provide a list of names to name the surfaces e.g. get names of units from stratigraphic column or name using the fault name.
1 parent 6c75d4b commit bbbfe0c

File tree

2 files changed

+56
-1
lines changed

2 files changed

+56
-1
lines changed

LoopStructural/interpolators/supports/_3d_structured_grid.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ def evaluate_value(self, evaluation_points, property_array):
301301

302302
return np.sum(v, axis=1)
303303

304-
def evaluate_gradient(self, evaluation_points, property_array):
304+
def evaluate_gradient(self, evaluation_points, property_array) -> np.ndarray:
305305
"""Evaluate the gradient at a location given node values
306306
307307
Parameters

LoopStructural/modelling/features/_base_geological_feature.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1+
from __future__ import annotations
2+
13
from abc import ABCMeta, abstractmethod
4+
from typing import Union, List, Optional
25
from LoopStructural.modelling.features import FeatureType
36
from LoopStructural.utils import getLogger
47
from LoopStructural.utils.typing import NumericInput
8+
from LoopStructural.api import LoopIsosurfacer, surface_list
59

610

711
import numpy as np
@@ -263,3 +267,54 @@ def __tojson__(self):
263267
"regions": regions,
264268
"faults": faults,
265269
}
270+
271+
def surfaces(
272+
self,
273+
value: Union[float, int, List[Union[float, int]]],
274+
bounding_box=None,
275+
name=Optional[Union[List[str], str]],
276+
) -> surface_list:
277+
"""Find the surfaces of the geological feature at a given value
278+
279+
Parameters
280+
----------
281+
value : Union[float, int, List[float, int]]
282+
value or list of values to find the surface of the feature
283+
284+
Returns
285+
-------
286+
list
287+
list of surfaces
288+
"""
289+
if isinstance(value, (float, int)):
290+
value = [value]
291+
if bounding_box is None:
292+
if self.model is None:
293+
raise ValueError("Must specify bounding box")
294+
bounding_box = self.model.bounding_box
295+
296+
isosurfacer = LoopIsosurfacer(bounding_box, self)
297+
return isosurfacer.fit(value, name)
298+
299+
def scalar_field(self, bounding_box=None):
300+
"""Create a scalar field for the feature
301+
302+
Parameters
303+
----------
304+
bounding_box : Optional[BoundingBox], optional
305+
bounding box to evaluate the scalar field in, by default None
306+
307+
Returns
308+
-------
309+
np.ndarray
310+
scalar field
311+
"""
312+
if bounding_box is None:
313+
if self.model is None:
314+
raise ValueError("Must specify bounding box")
315+
bounding_box = self.model.bounding_box
316+
grid = bounding_box.vtk
317+
points = grid.points
318+
value = self.evaluate_value(points)
319+
grid[self.name] = value
320+
return grid

0 commit comments

Comments
 (0)