resolution_functions.models.ideal
- class resins.models.ideal.GenericBoxcar1DModel(model_data: ModelData, width: float = 1.0, **_)
Bases:
StaticSnappedPeaksMixin,SimpleBroaden1DMixin,InstrumentModelA generic Boxcar model.
Models the resolution as a Boxcar (square) function.
A useful relationship: the standard deviation of a width-1 boxcar is √(1/12). So to produce crudely “equivalent” broadening to a Gaussian of known σ, use a boxcar width = σ √12 .
- Parameters:
- model_data
The data associated with the model for a given version of a given instrument.
- width
The width of the Boxcar function in meV. This width is used for all values of [w, Q].
- Attributes:
- input
The names of the columns in the
pointsarray expected by all computation methods, i.e. the names of the independent variables ([Q, w]) that the model models.data_classAbstract base class for defining the data required by a model.
- width
The width of the Boxcar function in meV. This width is used for all values of [w, Q].
citationThe citation for this model.
Methods
__call__(points, data, *meshes)Broadens the
dataon themeshes.broaden(points, data, mesh)Broadens the
dataon the fullmeshusing the straightforward scheme.get_characteristics(points)Returns the broadening width at each value of energy transfer given by
points.get_kernel(points, mesh)Computes the Boxcar (square) kernel centered on zero on the provided
meshat each value ofpoints(energy transfer or momentum scalar).get_peak(points, mesh)Apply the kernel at the nearest
meshpoint for at each value ofpointsenergy transfer.Warning
This model is for testing purposes - it does not do any computation and instead uses the user-provided width for all values of [w, Q]. It should not be normally used to model instruments.
- get_characteristics(points: Float[np.ndarray, 'sample dimension=1']) dict[str, Float[np.ndarray, ' sample']]
Returns the broadening width at each value of energy transfer given by
points.This model is a static test model, so it returns the same width for each value of
points, which is in the form of the width of a Boxcar kernel.- Parameters:
- points
The energy transfer in meV at which to compute the width in sigma of the kernel. This must be a
samplex 1 2D array wheresampleis the number of energy transfers.
- Returns:
characteristicsThe characteristics of the broadening function, i.e. the Boxcar width in meV and derived standard deviation (sigma).
- get_kernel(points: Float[np.ndarray, 'sample dimension=1'], mesh: Float[np.ndarray, ' mesh']) Float[np.ndarray, 'sample mesh']
Computes the Boxcar (square) kernel centered on zero on the provided
meshat each value ofpoints(energy transfer or momentum scalar).Note that these kernels will always consist of an odd-integer number of full-height samples, approximately
widthwide, moving directly to zero at the surrounding samples. The area is normalised as though this is a trapezoid (i.e. as though lines connect the boxcar top to the surrounding samples), resulting in lower height than the ideal boxcar.- 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.
- Returns:
kernelThe Boxcar kernel at each value of
pointsas given by this model, computed on themeshand 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.
- class resins.models.ideal.GenericGaussian1DModel(model_data: ModelData, sigma: float = 1.0, **_)
Bases:
SimpleBroaden1DMixin,GaussianKernel1DMixin,InstrumentModelA generic Gaussian model.
Models the resolution as a Gaussian function.
- Parameters:
- model_data
The data associated with the model for a given version of a given instrument.
- sigma
The width (in sigma) of the Gaussian function. This width is used for all values of [w, Q].
- Attributes:
- input
The names of the columns in the
pointsarray expected by all computation methods, i.e. the names of the independent variables ([Q, w]) that the model models.data_classAbstract base class for defining the data required by a model.
- sigma
The width (in sigma) of the Gaussian function. This width is used for all values of [w, Q].
citationThe citation for this model.
Methods
__call__(points, data, *meshes)Broadens the
dataon themeshes.broaden(points, data, mesh)Broadens the
dataon the fullmeshusing the straightforward scheme.get_characteristics(points)Returns the broadening width at each value of energy transfer given by
points.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.Warning
This model is for testing purposes - it does not do any computation and instead uses the user-provided width for all values of [w, Q]. It should not be normally used to model instruments.
- get_characteristics(points: Float[np.ndarray, 'sample dimension=1']) dict[str, Float[np.ndarray, ' sample']]
Returns the broadening width at each value of energy transfer given by
points.This model is a static test model, so it returns the same width for each value of
points, which is in the form of the standard deviation (sigma) of a Gaussian model.- Parameters:
- points
The energy transfer in meV at which to compute the width in sigma of the kernel. This must be a
samplex 1 2D array wheresampleis the number of energy transfers.
- Returns:
characteristicsThe characteristics of the broadening function, i.e. the Gaussian width as sigma in meV.
- class resins.models.ideal.GenericLorentzian1DModel(model_data: ModelData, fwhm: float = 1.0, **_)
Bases:
SimpleBroaden1DMixin,InstrumentModelA generic Lorentzian model.
Models the resolution as a Lorentzian function.
- Parameters:
- model_data
The data associated with the model for a given version of a given instrument.
- fwhm
The width (in Full-Width Half-Maximum) of the Lorentzian function. This width is used for all values of [w, Q].
- Attributes:
- input
The names of the columns in the
pointsarray expected by all computation methods, i.e. the names of the independent variables ([Q, w]) that the model models.data_classAbstract base class for defining the data required by a model.
- fwhm
The width (in Full-Width Half-Maximum) of the Lorentzian function. This width is used for all values of [w, Q].
citationThe citation for this model.
Methods
__call__(points, data, *meshes)Broadens the
dataon themeshes.broaden(points, data, mesh)Broadens the
dataon the fullmeshusing the straightforward scheme.get_characteristics(points)Returns the broadening width at each value of energy transfer given by
points.get_kernel(points, mesh)Computes the Lorentzian kernel centered on zero on the provided
meshat each value ofpoints(energy transfer or momentum scalar).get_peak(points, mesh)Computes the Lorentzian kernel on the provided
meshat each value of thepointsenergy transfer.Warning
This model is for testing purposes - it does not do any computation and instead uses the user-provided width for all values of [w, Q]. It should not be normally used to model instruments.
- get_characteristics(points: Float[np.ndarray, 'sample dimension=1']) dict[str, Float[np.ndarray, ' sample']]
Returns the broadening width at each value of energy transfer given by
points.This model is a static test model, so it returns the same width for each value of
points, which is in the form of the Full-Width Half-Maximum of a Lorentzian model.- Parameters:
- points
The energy transfer in meV at which to compute the width in sigma of the kernel. This must be a
samplex 1 2D array wheresampleis the number of energy transfers.
- Returns:
characteristicsThe characteristics of the broadening function, i.e. the Lorentzian width as FWHM.
- get_kernel(points: Float[np.ndarray, 'sample dimension=1'], mesh: Float[np.ndarray, ' mesh']) Float[np.ndarray, 'sample mesh']
Computes the Lorentzian kernel centered on zero on the provided
meshat each value ofpoints(energy transfer or momentum scalar).- 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.
- Returns:
kernelThe Lorentzian kernel at each value of
pointsas given by this model, computed on themeshand 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 Lorentzian kernel on the provided
meshat each value of thepointsenergy transfer.- Parameters:
- points
The energy transfer in meV for which to compute the kernel. This must be a Nx1 2D array where N is the number of energy transfers.
- mesh
The mesh on which to evaluate the kernel. This is a 1D array which must span the
pointstransfer space of interest.
- Returns:
kernelThe Lorentzian kernel at each value of
pointsas given by this model, computed on themeshand centered on the corresponding energy transfer. 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.ideal.GenericTrapezoid1DModel(model_data: ModelData, long_base: float = 1.0, short_base: float = 0.5, **_)
Bases:
SimpleBroaden1DMixin,StaticSnappedPeaksMixin,InstrumentModelA generic Trapezoid model.
Models the resolution as an isosceles Trapezoid function.
Note that shape and area are only exactly correct when base lengths correspond to an even number of bin widths. The get_peak() and broaden() methods will snap input points to the nearest mesh value; this results in a consistent peak shape.
- Parameters:
- model_data
The data associated with the model for a given version of a given instrument.
- long_base
The length of the longer (bottom) base of the Trapezoid function. This width is used for all values of [w, Q].
- short_base
The length of the shorter (top) base of the Trapezoid function. This width is used for all values of [w, Q].
- Attributes:
- input
The names of the columns in the
pointsarray expected by all computation methods, i.e. the names of the independent variables ([Q, w]) that the model models.data_classAbstract base class for defining the data required by a model.
- long_base
The length of the longer (bottom) base of the Trapezoid function. This width is used for all values of [w, Q].
- short_base
The length of the shorter (top) base of the Trapezoid function. This width is used for all values of [w, Q].
citationThe citation for this model.
Methods
__call__(points, data, *meshes)Broadens the
dataon themeshes.broaden(points, data, mesh)Broadens the
dataon the fullmeshusing the straightforward scheme.get_characteristics(points)Returns the characteristics of a Trapezoid function for each value of energy transfer given by
points.get_kernel(points, mesh)Computes the Trapezoid kernel centered on zero on the provided
meshat each value ofpoints(energy transfer or momentum scalar).get_peak(points, mesh)Apply the kernel at the nearest
meshpoint for at each value ofpointsenergy transfer.Warning
This model is for testing purposes - it does not do any computation and instead uses the user-provided width for all values of [w, Q]. It should not be normally used to model instruments.
- get_characteristics(points: Float[np.ndarray, 'sample dimension=1']) dict[str, Float[np.ndarray, ' sample']]
Returns the characteristics of a Trapezoid function for each value of energy transfer given by
points.This model is a static test model, so it returns the same characteristics for each value of
points. A Trapezoid model has two characteristics:long_base- the length of the longer (bottom) base of a trapezoidshort_base- the length of the shorter (top) base of a trapezoid.
- Parameters:
- points
The energy transfer in meV at which to compute the width in sigma of the kernel. This must be a
samplex 1 2D array wheresampleis the number of energy transfers.
- Returns:
characteristicsThe characteristics of the broadening function.
- get_kernel(points: Float[np.ndarray, 'sample dimension=1'], mesh: Float[np.ndarray, ' mesh']) Float[np.ndarray, 'sample mesh']
Computes the Trapezoid kernel centered on zero on the provided
meshat each value ofpoints(energy transfer or momentum scalar).Note that shape and area are only exactly correct when base lengths correspond to an even number of bin widths.
- 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.
- Returns:
kernelThe Trapezoid kernel at each value of
pointsas given by this model, computed on themeshand 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.
- class resins.models.ideal.GenericTriangle1DModel(model_data: ModelData, fwhm: float = 1.0, **_)
Bases:
SimpleBroaden1DMixin,StaticSnappedPeaksMixin,InstrumentModelA generic Triangle model.
Models the resolution as an isosceles Triangle function.
Note that shape and area are only exactly correct when FHWM equals an integer number of bins.
- Parameters:
- model_data
The data associated with the model for a given version of a given instrument.
- fwhm
The width (in Full-Width Half-Maximum) of the Triangle function. This width is used for all values of [w, Q].
- Attributes:
- input
The names of the columns in the
pointsarray expected by all computation methods, i.e. the names of the independent variables ([Q, w]) that the model models.data_classAbstract base class for defining the data required by a model.
- fwhm
The width (in Full-Width Half-Maximum) of the Triangle function. This width is used for all values of [w, Q].
citationThe citation for this model.
Methods
__call__(points, data, *meshes)Broadens the
dataon themeshes.broaden(points, data, mesh)Broadens the
dataon the fullmeshusing the straightforward scheme.get_characteristics(points)Returns the broadening width at each value of energy transfer given by
points.get_kernel(points, mesh)Computes the Triangle kernel centered on zero on the provided
meshat each value ofpoints(energy transfer or momentum scalar).get_peak(points, mesh)Apply the kernel at the nearest
meshpoint for at each value ofpointsenergy transfer.Warning
This model is for testing purposes - it does not do any computation and instead uses the user-provided width for all values of [w, Q]. It should not be normally used to model instruments.
- get_characteristics(points: Float[np.ndarray, 'sample dimension=1']) dict[str, Float[np.ndarray, ' sample']]
Returns the broadening width at each value of energy transfer given by
points.This model is a static test model, so it returns the same width for each value of
points, which is in the form of the Full-Width Half-Maximum of a Triangle model.- Parameters:
- points
The energy transfer in meV at which to compute the width in sigma of the kernel. This must be a
samplex 1 2D array wheresampleis the number of energy transfers.
- Returns:
characteristicsThe characteristics of the broadening function, i.e. the Triangle width as FWHM.
- get_kernel(points: Float[np.ndarray, 'sample dimension=1'], mesh: Float[np.ndarray, ' mesh']) Float[np.ndarray, 'sample mesh']
Computes the Triangle kernel centered on zero on the provided
meshat each value ofpoints(energy transfer or momentum scalar).Note that shape and area are only exactly correct when FHWM equals an integer number of bins.
- 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.
- Returns:
kernelThe Triangle kernel at each value of
pointsas given by this model, computed on themeshand 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.
- class resins.models.ideal.StaticSnappedPeaksMixin
Bases:
objectMixin providing a get_peak() by copying kernel to nearest bins
This results in ‘snapping’ to the nearest bin rather than a more accurate evaluation at the true point position. However it also eliminates surprising changes to the kernel shape based on the sub-bin position, and gives similar results to convolution with pre-binned data.
get_kernel() must be provided by the inheriting class or another Mixin.
Methods
get_peak(points, mesh)Apply the kernel at the nearest
meshpoint for at each value ofpointsenergy transfer.- get_peak(points: Float[np.ndarray, 'sample dimension=1'], mesh: Float[np.ndarray, ' mesh']) Float[np.ndarray, 'sample mesh']
Apply the kernel at the nearest
meshpoint for at each value ofpointsenergy transfer.The kernel is obtained by calling get_kernel() for the first item of
points: this is intended for use with energy-independent (“static”) broadening functions.Note that peak positions are quantized to the nearest mesh point. As a result, the position of peaks in this approach does not vary smoothly with the input parameters.
- Parameters:
- points
The energy transfer in meV for which to compute the kernel. This must be a Nx1 2D array where N is the number of energy transfers.
- mesh
The mesh on which to evaluate the kernel. This is a 1D array which must span the
pointstransfer space of interest.
- Returns:
peaksBroadening kernel aligned to nearest
meshpoint for each input point. This is a 2D N x M array where N is the length ofpoints(i.e. number of ω values) and M is the length of themesharray.