Instrument Model¶
We here introduce the InstrumentModel, which contains all information related to the instrument: the BackgroundModel, ResolutionModel and also a fittable offset in the energy transfer due to slight instrument misalignment.
The InstrumentModel does not itself do any calculations; it is merely a container for all information about the instrument.
In [1]:
Copied!
import numpy as np
from easydynamics.sample_model import Gaussian
from easydynamics.sample_model import Polynomial
from easydynamics.sample_model.background_model import BackgroundModel
from easydynamics.sample_model.instrument_model import InstrumentModel
from easydynamics.sample_model.resolution_model import ResolutionModel
%matplotlib widget
import numpy as np
from easydynamics.sample_model import Gaussian
from easydynamics.sample_model import Polynomial
from easydynamics.sample_model.background_model import BackgroundModel
from easydynamics.sample_model.instrument_model import InstrumentModel
from easydynamics.sample_model.resolution_model import ResolutionModel
%matplotlib widget
In [2]:
Copied!
# Create a BackgroundModel and a ResolutionModel and add them to an
# InstrumentModel
Q = np.linspace(0.1, 2.0, 5)
background_model = BackgroundModel()
background_model.components = Polynomial(coefficients=[1, 0.1, 0.01])
resolution_model = ResolutionModel()
resolution_model.append_component(Gaussian(width=0.05))
instrument_model = InstrumentModel(
Q=Q,
resolution_model=resolution_model,
background_model=background_model,
)
# Create a BackgroundModel and a ResolutionModel and add them to an
# InstrumentModel
Q = np.linspace(0.1, 2.0, 5)
background_model = BackgroundModel()
background_model.components = Polynomial(coefficients=[1, 0.1, 0.01])
resolution_model = ResolutionModel()
resolution_model.append_component(Gaussian(width=0.05))
instrument_model = InstrumentModel(
Q=Q,
resolution_model=resolution_model,
background_model=background_model,
)
In [3]:
Copied!
instrument_model.get_all_variables(Q_index=1)
instrument_model.get_all_variables(Q_index=1)
Out[3]:
[<Parameter 'energy_offset': 0.0000 meV, bounds=[-inf:inf]>, <Parameter 'Polynomial_c0': 1.0000, bounds=[-inf:inf]>, <Parameter 'Polynomial_c1': 0.1000, bounds=[-inf:inf]>, <Parameter 'Polynomial_c2': 0.0100, bounds=[-inf:inf]>, <Parameter 'Gaussian area': 1.0000 meV, bounds=[0.0:inf]>, <Parameter 'Gaussian center': 0.0000 meV (fixed), bounds=[-inf:inf]>, <Parameter 'Gaussian width': 0.0500 meV, bounds=[1e-10:inf]>]
In [4]:
Copied!
instrument_model.fix_resolution_parameters()
instrument_model.get_all_variables(Q_index=1)
instrument_model.fix_resolution_parameters()
instrument_model.get_all_variables(Q_index=1)
Out[4]:
[<Parameter 'energy_offset': 0.0000 meV, bounds=[-inf:inf]>, <Parameter 'Polynomial_c0': 1.0000, bounds=[-inf:inf]>, <Parameter 'Polynomial_c1': 0.1000, bounds=[-inf:inf]>, <Parameter 'Polynomial_c2': 0.0100, bounds=[-inf:inf]>, <Parameter 'Gaussian area': 1.0000 meV (fixed), bounds=[0.0:inf]>, <Parameter 'Gaussian center': 0.0000 meV (fixed), bounds=[-inf:inf]>, <Parameter 'Gaussian width': 0.0500 meV (fixed), bounds=[1e-10:inf]>]