-
Notifications
You must be signed in to change notification settings - Fork 2
Open
Labels
[priority] highShould be prioritized soonShould be prioritized soon[scope] bugBug report or fix (major.minor.PATCH)Bug report or fix (major.minor.PATCH)
Description
easyreflectometry: 1.3.3
Lmfit: 1.3.3
When using LMFit_differential_evolution
as the minimizer, model evaluation can return NaN's which breaks the fitting:

Full workflow to replicate error below:
%matplotlib inline
import numpy as np
from easyreflectometry.calculators import CalculatorFactory
from easyreflectometry.data import load
from easyreflectometry.fitting import MultiFitter
from easyreflectometry.model import Model, PercentageFwhm
from easyreflectometry.plot import plot
from easyreflectometry.sample import (
Layer,
Material,
Multilayer,
LayerAreaPerMolecule,
SurfactantLayer,
Sample,
)
from easyscience.fitting import AvailableMinimizers
from pooch import retrieve
file_path = "amor_reduced_iofq.ort"
data = load(file_path)
plot(data)
# Set total refelctivity to 1 and plot reduced data
reflectivity = data["data"]["R_0"].values
scale_factor = 1 / np.max(reflectivity)
data["data"]["R_0"].values *= scale_factor
# print(f"Scale factor applied: {scale_factor}")
# print(f"Maximum reflectivity after scaling: {np.max(data['data']['R_0'].values)}")
plot(data)
# Create a model for the sample
si = Material(sld=2.07, isld=0.0, name="Si")
sio2 = Material(sld=3.47, isld=0.0, name="SiO2")
d2o = Material(sld=6.33, isld=0.0, name="D2O")
dlipids = Material(sld=5.0, isld=0.0, name="DLipids")
superphase = Layer(material=si, thickness=0, roughness=0, name="Si superphase")
sio2_layer = Layer(material=sio2, thickness=20, roughness=4, name="SiO2 layer")
dlipids_layer = Layer(material=dlipids, thickness=40, roughness=4, name="DLipids layer")
subphase = Layer(material=d2o, thickness=0, roughness=5, name="D2O subphase")
multi_sample = Sample(
Multilayer(superphase),
Multilayer(sio2_layer,),
Multilayer(dlipids_layer),
Multilayer(subphase),
name="Multilayer Structure",
)
multi_layer_model = Model(
sample=multi_sample,
scale=1,
background=0.000001,
resolution_function=PercentageFwhm(0),
name="Multilayer Model",
)
# Set the fitting parameters
sio2_layer.roughness.bounds = (3, 12)
sio2_layer.material.sld.bounds = (3.47, 5)
sio2_layer.thickness.bounds = (10, 30)
subphase.material.sld.bounds = (6, 6.35)
dlipids_layer.thickness.bounds = (30, 60)
dlipids_layer.roughness.bounds = (3, 10)
dlipids_layer.material.sld.bounds = (4, 6)
multi_layer_model.scale.bounds = (0.8, 1.2)
multi_layer_model.background.bounds = (1e-6, 1e-3)
# Run the model and plot the results
multi_layer_model.interface = CalculatorFactory()
fitter1 = MultiFitter(multi_layer_model)
fitter1.switch_minimizer(AvailableMinimizers.LMFit_differential_evolution)
analysed = fitter1.fit(data)
plot(analysed)
Metadata
Metadata
Assignees
Labels
[priority] highShould be prioritized soonShould be prioritized soon[scope] bugBug report or fix (major.minor.PATCH)Bug report or fix (major.minor.PATCH)