Skip to content

Commit

Permalink
fix: crashing when all constraints of a type outside of box
Browse files Browse the repository at this point in the history
  • Loading branch information
Lachlan Grose committed Jan 20, 2022
1 parent 9abcc04 commit 7907f58
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
4 changes: 4 additions & 0 deletions LoopStructural/interpolators/discrete_interpolator.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,13 +361,17 @@ def build_matrix(self, square=True, damp=0.0):
# which is not ideal.
max_weight = 0
for c in self.constraints.values():
if len(c["w"]) == 0:
continue
if c["w"].max() > max_weight:
max_weight = c["w"].max()
a = []
b = []
rows = []
cols = []
for c in self.constraints.values():
if len(c["w"]) == 0:
continue
aa = (c["A"] * c["w"][:, None] / max_weight).flatten()
b.extend((c["B"] * c["w"] / max_weight).tolist())
mask = aa == 0
Expand Down
11 changes: 10 additions & 1 deletion tests/unit_tests/interpolator/test_outside_box.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,16 @@ def test_outside_box_normal():
model.data = data
model.create_and_add_foliation('strati',interpolatortype=interpolator)
model.update()

def test_outside_box_normal():
for interpolator in ['PLI','FDI']:
print(f'Running test for {interpolator} with normal constraints')
model = GeologicalModel(np.zeros(3),np.ones(3))
data = pd.DataFrame([[0.5,0.5,0.5,0,1.,0.,np.nan,'strati'],
[1.5,0.5,0.5,0,1.,0.,np.nan,'strati'],
[0.5,1.5,1.5,0,1.,0.,1.,'strati']],columns=['X','Y','Z','nx','ny','nz','val','feature_name'])
model.data = data
model.create_and_add_foliation('strati',interpolatortype=interpolator)
model.update()
def test_outside_box_value():
for interpolator in ['PLI','FDI']:
print(f'Running test for {interpolator} with normal constraints')
Expand Down

0 comments on commit 7907f58

Please sign in to comment.