Skip to content

Commit

Permalink
fix: creating basebuilder
Browse files Browse the repository at this point in the history
  • Loading branch information
Lachlan Grose committed Sep 28, 2022
1 parent 9cb79cb commit 3480e3d
Show file tree
Hide file tree
Showing 4 changed files with 137 additions and 80 deletions.
79 changes: 79 additions & 0 deletions LoopStructural/modelling/features/builders/_base_builder.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
class BaseBuilder:
def __init__(self, name="Feature"):
self._name = name
self._feature = None
self._feature = None
self._up_to_date = False
self._build_arguments = {}
self.faults = []

@property
def feature(self):
return self._feature

@property
def build_arguments(self):
return self._build_arguments

@build_arguments.setter
def build_arguments(self, build_arguments):
# self._build_arguments = {}
for k, i in build_arguments.items():
if i != self._build_arguments.get(k, None):
self._build_arguments[k] = i
## if build_arguments change then flag to reinterpolate
self._up_to_date = False

def update(self):
self.build(**self.build_arguments)

def build(self,**kwargs):
raise NotImplementedError('BaseBuilder should be inherited and build method overwritten')

@property
def name(self):
return self._name

def up_to_date(self, callback=None):
"""
check if the feature is uptodate
if its not update.
Parameters
----------
callback : function
a function that is called when the feature is updated
"""
for f in self.faults:
f.builder.up_to_date(callback=callback)
# has anything changed in the builder since we built the feature? if so update
if self._up_to_date == False:
self.update()
if callable(callback):
callback(1)
return
# check if the interpolator is up to date, if not solve
if self._interpolator.up_to_date == False:
self.update()
if callable(callback):
callback(1)
return
if callable(callback):
callback(1)

def add_fault(self, fault):
"""
Add a fault to the geological feature builder
Parameters
----------
fault : FaultSegment
A faultsegment to add to the geological feature
Returns
-------
"""
self._up_to_date = False
self.faults.append(fault)
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Feature builder
"""

import numpy as np
import pandas as pd

Expand All @@ -20,14 +21,15 @@
inequality_name,
)
from LoopStructural.modelling.features import GeologicalFeature
from LoopStructural.modelling.features.builders import BaseBuilder
from LoopStructural.utils.helper import (
get_data_bounding_box_map as get_data_bounding_box,
)
from LoopStructural.utils import get_data_axis_aligned_bounding_box
from LoopStructural.utils import RegionEverywhere


class GeologicalFeatureBuilder:
class GeologicalFeatureBuilder(BaseBuilder):
def __init__(
self,
interpolator: GeologicalInterpolator,
Expand All @@ -46,14 +48,14 @@ def __init__(
defining whether the location (xyz) should be included in the
kwargs - name of the feature, region to interpolate the feature
"""
BaseBuilder.__init__(self, name)
if issubclass(type(interpolator), GeologicalInterpolator) == False:
raise TypeError(
"interpolator is {} and must be a GeologicalInterpolator".format(
type(interpolator)
)
)
self._interpolator = interpolator
self._name = name
self._interpolator.set_property_name(self._name)
# everywhere region is just a lambda that returns true for all locations
if region is None:
Expand All @@ -69,12 +71,9 @@ def __init__(
+ weight_name()
)
self.data = pd.DataFrame(columns=header)
self.faults = []
self.data_added = False
self._interpolator.set_region(region=self.region)
self._feature = None
self._up_to_date = False
self._build_arguments = {}

self._feature = GeologicalFeature(
self._name,
self._interpolator,
Expand All @@ -85,78 +84,12 @@ def __init__(
self._orthogonal_features = {}
self._equality_constraints = {}

@property
def feature(self):
return self._feature

@property
def build_arguments(self):
return self._build_arguments

@build_arguments.setter
def build_arguments(self, build_arguments):
# self._build_arguments = {}
for k, i in build_arguments.items():
if i != self._build_arguments.get(k, None):
self._build_arguments[k] = i
## if build_arguments change then flag to reinterpolate
self._up_to_date = False

def update(self):
self.build(**self.build_arguments)

@property
def name(self):
return self._name


@property
def interpolator(self):
return self._interpolator

def up_to_date(self, callback=None):
"""
check if the feature is uptodate
if its not update.
Parameters
----------
callback : function
a function that is called when the feature is updated
"""
for f in self.faults:
f.builder.up_to_date(callback=callback)
# has anything changed in the builder since we built the feature? if so update
if self._up_to_date == False:
self.update()
if callable(callback):
callback(1)
return
# check if the interpolator is up to date, if not solve
if self._interpolator.up_to_date == False:
self.update()
if callable(callback):
callback(1)
return
if callable(callback):
callback(1)

def add_fault(self, fault):
"""
Add a fault to the geological feature builder
Parameters
----------
fault : FaultSegment
A faultsegment to add to the geological feature
Returns
-------
"""
self._up_to_date = False
self.faults.append(fault)

def add_data_from_data_frame(self, data_frame, overwrite=False):
"""
Extract data from a pandas dataframe with columns for
Expand Down
45 changes: 45 additions & 0 deletions tests/unit_tests/modelling/test_geological_feature_builder.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import pytest
from LoopStructural.modelling.features.builders import GeologicalFeatureBuilder

def test_geological_feature_builder_constructor():
interpolator =
builder = GeologicalFeatureBuilder()
pass

def test_get_interpolator():
pass

def test_add_data_to_interpolator():
pass

def test_install_gradient_constraints():
pass

def test_get_value_constraints():
pass

def test_get_gradient_constraints():
pass

def test_get_tangent_constraints():
pass

def test_norm_constraints():
pass

def get_orientation_constraints():
pass

def get_data_locations():
pass

def test_test_interpolation_geometry():
pass

def test_not_up_to_date():
"""test to make sure that the feature
isn't interpolated when everything is set up
"""
pass
def test_get_feature():
pass
14 changes: 7 additions & 7 deletions tests/unit_tests/modelling/test_intrusions.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from LoopStructural.datasets import load_tabular_intrusion
data, boundary_points = load_tabular_intrusion()

def test_intrusion_freame_builder():
def test_intrusion_frame_builder():
model = GeologicalModel(boundary_points[0, :], boundary_points[1, :])
model.data = data
model.nsteps = [10,10,10]
Expand Down Expand Up @@ -115,9 +115,9 @@ def test_intrusion_builder():
assert len(intrusion_feature.lateral_simulated_thresholds) > 0
assert len(intrusion_feature.growth_simulated_thresholds) > 0

if __name__ == "__main__":
test_intrusion_freame_builder()
test_intrusion_builder()
if __name__ == "__main__":
test_intrusion_freame_builder()
test_intrusion_builder()
# if __name__ == "__main__":
# test_intrusion_freame_builder()
# test_intrusion_builder()
# if __name__ == "__main__":
# test_intrusion_freame_builder()
# test_intrusion_builder()

0 comments on commit 3480e3d

Please sign in to comment.