Full output
load_data = DataGroup(sizes={}, keys=[
data: {'R_0': <scipp.Variable> (Qz_0: 189) float64 <no unit> [0.927488, 0.95...ame': 'sQz', 'unit': '1/angstrom', 'physical_quantity': 'standard deviation of wavevector transfer resolution'}]}}},
])
@pytest.fixture(scope="module")
def fit_model(load_data):
data = load_data
# Rescale data
reflectivity = data["data"]["R_0"].values
scale_factor = 1 / np.max(reflectivity)
data["data"]["R_0"].values *= scale_factor
# 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)
sio2_layer.roughness.free = True
sio2_layer.material.sld.free = True
sio2_layer.thickness.free = True
subphase.material.sld.free = True
dlipids_layer.thickness.free = True
dlipids_layer.roughness.free = True
dlipids_layer.material.sld.free = True
multi_layer_model.scale.free = True
multi_layer_model.background.free = True
# Run the model and plot the results
multi_layer_model.interface = CalculatorFactory()
fitter1 = MultiFitter(multi_layer_model)
fitter1.switch_minimizer(AvailableMinimizers.Bumps_simplex)
> analysed = fitter1.fit(data)
^^^^^^^^^^^^^^^^^
tests/scipp-analysis/estia/ort_file_test.py:109:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
.tox/scipp-analysis-estia/lib/python3.12/site-packages/easyreflectometry/fitting.py:537: in fit
_emit_array_prep_warnings(stats, y_vals, f'reflectivity {i}')
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
stats = {'valid': 178, 'mighell_substituted': 11, 'masked': 0, 'transformed_all_points': False}
y_vals = array([9.27487850e-01, 9.52332638e-01, 9.23844445e-01, 9.27607868e-01,
9.45260107e-01, 9.48504316e-01, 9.374221...000e+00, 0.00000000e+00,
1.73206521e-03, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
0.00000000e+00])
label = 'reflectivity 0', action = 'fitting', extra = ''
def _emit_array_prep_warnings(stats: dict, y_vals: np.ndarray, label: str, *, action: str = 'fitting', extra: str = '') -> None:
"""Warn about zero-variance handling applied by :func:`_prepare_fit_arrays`.
Parameters
----------
stats : dict
The ``stats`` dict returned by :func:`_prepare_fit_arrays`.
y_vals : np.ndarray
The original (pre-transform) y values, used for the "all points" count.
label : str
Identifies what was fitted/sampled, e.g. ``'reflectivity 1'`` or
``'channel pp'``.
action : str, optional
Verb describing the operation, e.g. ``'fitting'`` or ``'sampling'``. By default, 'fitting'.
extra : str, optional
Extra sentence(s) appended to the Mighell-related warnings (e.g. a
likelihood-validity caveat for MCMC). By default, ''.
"""
if stats['masked'] > 0:
warnings.warn(
f'Masked {stats["masked"]} data point(s) in {label} due to zero variance during {action}.',
UserWarning,
)
if stats.get('transformed_all_points'):
warnings.warn(
f'Applied Mighell transform to all {len(y_vals)} point(s) in {label} during {action}.{extra}',
UserWarning,
)
elif stats['mighell_substituted'] > 0:
> warnings.warn(
f'Applied Mighell substitution to {stats["mighell_substituted"]} '
f'zero-variance point(s) in {label} during {action}.{extra}',
UserWarning,
)
E UserWarning: Applied Mighell substitution to 11 zero-variance point(s) in reflectivity 0 during fitting.
.tox/scipp-analysis-estia/lib/python3.12/site-packages/easyreflectometry/fitting.py:251: UserWarning