Skip to content

Commit

Permalink
Merge pull request #685 from rhayes777/feature/interpolator
Browse files Browse the repository at this point in the history
fix handling deeper attributes in interpolation
  • Loading branch information
rhayes777 authored Feb 13, 2023
2 parents f70c360 + b713264 commit 967534d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion autofit/mapper/model_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def replacing_for_path(self, path: Tuple[str, ...], value) -> "ModelObject":
new = copy.deepcopy(self)
obj = new
for key in path[:-1]:
obj = getattr(new, key)
obj = getattr(obj, key)

setattr(obj, path[-1], value)
return new
Expand Down
21 changes: 21 additions & 0 deletions test_autofit/test_interpolator.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,24 @@ def test_alternate_attribute(time_series, sigma):
assert result.gaussian.sigma == sigma
assert result.t == -sigma
assert result.gaussian.normalization == -sigma


def test_deeper_attributes():
collection = af.Collection(
model=af.Model(af.Gaussian, centre=0.0, normalization=1.0, sigma=-1.0,)
)

instance_1 = af.Collection(
t=1.0, collection=collection,
).instance_from_prior_medians()
instance_2 = af.Collection(
t=2.0, collection=collection,
).instance_from_prior_medians()

time_series = af.LinearInterpolator([instance_1, instance_2])

result = time_series[time_series.t == 1.5]

assert result.collection.model.centre == 0.0
assert result.collection.model.normalization == 1.0
assert result.collection.model.sigma == -1.0

0 comments on commit 967534d

Please sign in to comment.