resins.models.mixins
Mixins providing generic implementations for
InstrumentModel methods.
The classes defined here are mixins to be used by specific models via multiple inheritance, allowing
common code to be shared between models. Please note, however, that when doing this, the mixin
must be the first base class (i.e. class Foo(Mixin, InstrumentModel)) so that its
implementation of a method overrides the abstract declaration in InstrumentModel.
- class resins.models.mixins.GaussianKernel1DMixin
Bases:
objectA mixin providing the implementation for the Gaussian kernel
get_kernelmethod.Implements
resins.models.model_base.InstrumentModel.get_kernelmethod of models whose broadening can be represented by a 1D Gaussian distribution. Any model that satisfies this condition should inherit theget_kernelmethod from this mixin instead of writing its own implementation.Technically, any model that implements the
resins.models.model_base.InstrumentModel.get_characteristicsmethod and which returns thesigmaparameter in its dictionary can use this mixin to inherit the Gaussianget_kernelmethod. However, it is recommended that only models that actually model a Gaussian kernel should use this mixin.Methods
get_kernel(points, mesh)Computes the Gaussian kernel centered on zero on the provided
meshat each (energy transfer or momentum scalar) point inpoints.get_peak(points, mesh)Computes the Gaussian broadening peak on the provided
meshat each (energy transfer or momentum scalar) point inpoints.- get_kernel(points: Float[np.ndarray, 'sample dimension=1'], mesh: Float[np.ndarray, 'mesh']) Float[np.ndarray, 'sample mesh']
Computes the Gaussian kernel centered on zero on the provided
meshat each (energy transfer or momentum scalar) point inpoints.- Parameters:
- points
The energy transfer or momentum scalar for which to compute the kernel. This must be a Nx1 2D array where N is the number of w/Q values.
- mesh
The mesh on which to evaluate the kernel. A 1D array which must encompass 0.
- Returns:
kernelsThe Gaussian kernel at w/Q point as given by this model, computed on the
meshand centered on zero. This is a 2D N x M array where N is the number of w/Q values and M is the length of themesharray.
- get_peak(points: Float[np.ndarray, 'sample dimension=1'], mesh: Float[np.ndarray, 'mesh']) Float[np.ndarray, 'sample mesh']
Computes the Gaussian broadening peak on the provided
meshat each (energy transfer or momentum scalar) point inpoints.- Parameters:
- points
The energy transfer or momentum scalar for which to compute the peak. This must be a Nx1 2D array where N is the number of w/Q values.
- mesh
The mesh on which to evaluate the kernel. This is a 1D array which must span the
pointswQ space of interest.
- Returns:
peaksThe Gaussian peak at each w/Q point in
pointsas given by this model, computed on themeshand centered on the corresponding w/Q. This is a 2D N x M array where N is the number of w/Q values and M is the length of themesharray.
- class resins.models.mixins.SimpleBroaden1DMixin
Bases:
objectA mixin providing the most simple implementation for the
broadenmethod.Implements
resins.models.model_base.InstrumentModel.convolvemethod in the most simple and basic way - the dot product between the matrix of kernels (obtained from theget_kernelmethod) and the intensities.This implementation should be mostly used as a reference method given that it is correct but inefficient. It should be able to work with any model, so it may be used when other implementations are unavailable.
Methods
broaden(points, data, mesh)Broadens the
dataon the fullmeshusing the straightforward scheme.- broaden(points: Float[np.ndarray, 'sample dimension=1'], data: Float[np.ndarray, 'data'], mesh: Float[np.ndarray, 'mesh']) Float[np.ndarray, 'spectrum']
Broadens the
dataon the fullmeshusing the straightforward scheme.- Parameters:
- points
The independent variable (energy transfer or momentum scalar) whose
datato broaden. This must be asamplex 1 2D array wheresampleis the number of w/Q values for which there isdata. Therefore, thesampledimension must match the length of thedataarray.- data
The intensities at the w/Q
points.- mesh
The mesh to use for the broadening. This is a 1D array which must span the entire
pointsspace of interest.
- Returns:
spectrumThe broadened spectrum. This is a 1D array of the same length as
mesh.