Extractor¶
-
class
ompy.
Extractor
(ensemble=None, trapezoid=None, path=None)[source]¶ Bases:
object
Extracts nld and γSF from an Ensemble or a Matrix
Basically a wrapper around a minimization routine with bookeeping. By giving an Ensemble instance and an Action cutting a Matrix into the desired shape, nuclear level density (nld) and gamma strength function (gsf/γSF) are extracted. The results are exposed in the attributes self.nld and self.gsf, as well as saved to disk. The saved results are used if filenames match, or can be loaded manually with load().
The method decompose(matrix, [std]) extracts the nld and gsf from a single Matrix.
- Variables
ensemble (Ensemble) – The Ensemble instance to extract nld and gsf from.
regenerate (bool) – Whether to force extraction from matrices even if previous results are found on disk. Defaults to True
method (str) – The scipy.minimization method to use. Defaults to Powell.
options (dict) – The scipy.minimization options to use.
gsf (list[Vector]) – The gamma strength functions extracted.
trapezoid (Action[Matrix]) – The Action cutting the matrices of the Ensemble into the desired shape where from the nld and gsf will be extracted from.
path (path) – The path to save and/or load nld and gsf to/from.
extend_diagonal_by_resolution (bool, optional) – If True (default), the fit will be extended beyond Ex=Eg by the (FWHM) of the resolution. Remember to set the resolution according to your experiment
resolution_Ex (float or np.ndarray, optional) – Resolution (FWHM) along Ex axis (particle detector resolution). Defaults to 150 keV
Todo
If path is given, it tries to load. If path is later set, it is not created. This is a very common pattern. Consider superclassing the disk book-keeping.
ensemble (Ensemble, optional): see above trapezoid (Action[Matrix], optional): see above path (Path or str, optional): see above
Methods Summary
__call__
([ensemble, trapezoid])Call self as a function.
constraining_counts
(matrix, resolution)Number of counts constraining each nld bin and gsf bin
decompose
(matrix[, std, x0, product])Decomposes a matrix into nld and γSF
diagonal_resolution
(matrix)Detector resolution at the Ex=Eg diagonal
- rtype
- rtype
extract_from
([ensemble, trapezoid, regenerate])Decompose each first generation matrix in an Ensemble
gsf_mean
()- rtype
gsf_std
()- rtype
load
([path])Load already extracted nld and gsf from file
nld_mean
()- rtype
nld_std
()- rtype
plot
([ax, scale, plot_mean, color])Basic visualization of nld and gsf
resolution_Eg
(matrix)Resolution along Eg axis for each Ex.
step
(num)Wrapper around _extract in order to be consistent with other classes
Methods Documentation
-
static
constraining_counts
(matrix, resolution)[source]¶ Number of counts constraining each nld bin and gsf bin
- Parameters
matrix (Matrix) – Input matrix
resolution (np.ndarray) – Resolution at Ex=Ex
- Returns
- Number of counts constraining each
nld and gsf bin
- Return type
Tuple[nld_counts, T_counts]
-
decompose
(matrix, std=None, x0=None, product=False)[source]¶ Decomposes a matrix into nld and γSF
- Algorithm:
Creates the energy range for nld based on the diagonal energy resolution. Tries to minimize the product:
firstgen = nld·gsf
using (weighted) chi square as error function.
If first nld / last gsf elements cannot be constrained, as there are no entries for them in the matrix, they will be set to np.nan
- Parameters
matrix (
Matrix
) – The matrix to decompose. Should already be cut into appropiate sizestd (
Optional
[Matrix
]) – The standard deviation for the matrix. Must be the same size as the matrix. If no std is provided, square error will be used instead of chi square.product (
bool
) – Whether to return the first generation matrix resulting from the product of nld and gsf.
- Return type
- Returns
The nuclear level density and the gamma strength function as Vectors. Optionally returns nld*γSF if product is True
-
diagonal_resolution
(matrix)[source]¶ Detector resolution at the Ex=Eg diagonal
Uses gaussian error propagations which assumes independence of resolutions along Ex and Eg axis.
-
extract_from
(ensemble=None, trapezoid=None, regenerate=None)[source]¶ Decompose each first generation matrix in an Ensemble
If regenerate is True it saves the extracted nld and gsf to file, or loads them if already generated. Exposes the vectors in the attributes self.nld and self.gsf.
- Parameters
ensemble (Ensemble, optional) – The ensemble to extract nld and gsf from. Can be provided in when initializing instead.
trapezoid (Action, optional) – An Action describing the cut to apply to the matrices to obtain the desired region for extracting nld and gsf.
regenerate (bool, optional) – Whether to regenerate all nld and gsf even if they are found on disk.
- Raises
ValueError – If no Ensemble instance is provided here or earlier.
-
plot
(ax=None, scale='log', plot_mean=False, color='k', **kwargs)[source]¶ Basic visualization of nld and gsf
-
static
resolution_Eg
(matrix)[source]¶ Resolution along Eg axis for each Ex. Defaults in this class are for OSCAR.
-
static
constraining_counts
(matrix, resolution)[source] Number of counts constraining each nld bin and gsf bin
- Parameters
matrix (Matrix) – Input matrix
resolution (np.ndarray) – Resolution at Ex=Ex
- Returns
- Number of counts constraining each
nld and gsf bin
- Return type
Tuple[nld_counts, T_counts]
-
decompose
(matrix, std=None, x0=None, product=False)[source] Decomposes a matrix into nld and γSF
- Algorithm:
Creates the energy range for nld based on the diagonal energy resolution. Tries to minimize the product:
firstgen = nld·gsf
using (weighted) chi square as error function.
If first nld / last gsf elements cannot be constrained, as there are no entries for them in the matrix, they will be set to np.nan
- Parameters
matrix (
Matrix
) – The matrix to decompose. Should already be cut into appropiate sizestd (
Optional
[Matrix
]) – The standard deviation for the matrix. Must be the same size as the matrix. If no std is provided, square error will be used instead of chi square.product (
bool
) – Whether to return the first generation matrix resulting from the product of nld and gsf.
- Return type
- Returns
The nuclear level density and the gamma strength function as Vectors. Optionally returns nld*γSF if product is True
-
diagonal_resolution
(matrix)[source] Detector resolution at the Ex=Eg diagonal
Uses gaussian error propagations which assumes independence of resolutions along Ex and Eg axis.
-
extract_from
(ensemble=None, trapezoid=None, regenerate=None)[source] Decompose each first generation matrix in an Ensemble
If regenerate is True it saves the extracted nld and gsf to file, or loads them if already generated. Exposes the vectors in the attributes self.nld and self.gsf.
- Parameters
ensemble (Ensemble, optional) – The ensemble to extract nld and gsf from. Can be provided in when initializing instead.
trapezoid (Action, optional) – An Action describing the cut to apply to the matrices to obtain the desired region for extracting nld and gsf.
regenerate (bool, optional) – Whether to regenerate all nld and gsf even if they are found on disk.
- Raises
ValueError – If no Ensemble instance is provided here or earlier.
-
load
(path=None)[source] Load already extracted nld and gsf from file
-
plot
(ax=None, scale='log', plot_mean=False, color='k', **kwargs)[source] Basic visualization of nld and gsf
-
static
resolution_Eg
(matrix)[source] Resolution along Eg axis for each Ex. Defaults in this class are for OSCAR.