Extractor

class ompy.Extractor(ensemble=None, trapezoid=None, path='saved_run/extractor')[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 False

  • method (str) – The scipy.minimization method to use. Defaults to Powell.

  • options (dict) – The scipy.minimization options to use.

  • nld (list[Vector]) – The nuclear level densities extracted.

  • 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, the fit will be extended beyond Ex=Eg by the (FWHM) of the resolution. Remember to set the resolution according to your experiment. Defaults to False.

  • x0 (np.ndarray or str) – Initial values. See decompose.

  • randomize_initial_values (bool) – Randomize initial values for decomposition. Defaults to True.

  • seed (int) – Random seed for reproducibility of results.

  • 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.

check_unconstrained_results()

Checks results for unconstrained elements (np.nan)

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

ensemble_gsf()

rtype:

Vector

ensemble_nld()

rtype:

Vector

extract_from([ensemble, trapezoid, regenerate])

Decompose each first generation matrix in an Ensemble

gsf_mean()

rtype:

ndarray

gsf_std()

rtype:

ndarray

guess_initial_values(E_nld, matrix[, method])

Guess initial values x0 for minimization rountine

nld_mean()

rtype:

ndarray

nld_std()

rtype:

ndarray

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

x0_BSFG(E_nld[, E0, a])

Initial guess that resembles Backshifted Fermi-gas solution

x0_CT(E_nld)

Initial guess that resembles CT solution

x0_parabola(E_nld[, E0, y0, a])

Initial guess as parabola a(E_nld - E0)² + y0

Methods Documentation

__call__(ensemble=None, trapezoid=None)[source]

Call self as a function.

check_unconstrained_results()[source]

Checks results for unconstrained elements (np.nan)

Returns:

True if results contain unconstrained elements, else False

Return type:

bool

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 size

  • std (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.

  • x0 (Optional[ndarray]) – The initial guess for nld and gsf. If np.ndarray, ordered as (T0, nld0). Otherwise, if str, used as the method, see guess_initial_values (where also defaults are given).

  • product (bool) – Whether to return the first generation matrix resulting from the product of nld and gsf.

Return type:

Tuple[Vector, Vector]

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.

Parameters:

matrix (Matrix) – Matrix for which the sesoluton shall be calculated

Return type:

ndarray

Returns:

resolution at Ex = Eg.

ensemble_gsf()[source]
Return type:

Vector

ensemble_nld()[source]
Return type:

Vector

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.

gsf_mean()[source]
Return type:

ndarray

gsf_std()[source]
Return type:

ndarray

guess_initial_values(E_nld, matrix, method=None)[source]

Guess initial values x0 for minimization rountine

Note

Different initial guesses will affect the normalization constants needed later. In order to minimize the effort when changing the initial guess (method), one can try to provide initial guesses where the nld is approx(!) 1 in all bins.

Parameters:
  • E_nld (ndarray) – Energy array of nld

  • matrix (Matrix) – Matrix to be sent to minimization

  • method (optional) – Method for initial guesses. Defaults to a backshifted Fermi-gas like initial value. This default is choosen, because we often find a CT-like result – so we want something dissimilar as a start.

Returns:

Initial guesses as a stacked array of (T0, nld0)

Return type:

x0

nld_mean()[source]
Return type:

ndarray

nld_std()[source]
Return type:

ndarray

plot(ax=None, scale='log', plot_mean=False, color='k', **kwargs)[source]

Basic visualization of nld and gsf

Parameters:
  • ax (Optional[Any]) – An axis to plot onto

  • scale (str) – Scale to use

  • plot_mean (bool) – Whether to plot individual samples or mean & std. dev

Return type:

None

static resolution_Eg(matrix)[source]

Resolution along Eg axis for each Ex. Defaults in this class are for OSCAR.

Parameters:

matrix (Matrix) – Matrix for which the sesoluton shall be calculated

Return type:

ndarray

Returns:

resolution

step(num)[source]

Wrapper around _extract in order to be consistent with other classes

Parameters:

num (int) – Number of the fg matrix to extract

Return type:

Tuple[Vector, Vector]

static x0_BSFG(E_nld, E0=-0.2, a=15)[source]

Initial guess that resembles Backshifted Fermi-gas solution

Note that this is like a fermi-gas after transformation with Aexp(αE). Default parameters are chosen somewhat arbitrary, but resembling fitted values reported in EB2005.

Parameters:
  • E_nld (ndarray) – Energy array of nld in [MeV]

  • E0 (optional) – Back-shift in [MeV]. Defaults to -0.2.

  • a (optional) – Level density parameter in [MeV⁻¹]. Defaults to 15.

Returns:

Initial guess

Return type:

nld0

static x0_CT(E_nld)[source]

Initial guess that resembles CT solution

This is the proposal of Schiller2000 – however, note that a constant nld of 1 after the transformation with Aexp(αE) is just like the CT formula.

Parameters:

E_nld (ndarray) – Energy array of nld

Returns:

Initial guess

Return type:

nld0

static x0_parabola(E_nld, E0=4, y0=0.01, a=1)[source]

Initial guess as parabola a(E_nld - E0)² + y0

This is quite crazy; For E0 > 0: the NLD is not expected to reduce for higher Ex

Parameters:
  • E_nld (ndarray) – Energy array of nld [in MeV]

  • E0 (float) – shift constant in x direction [in MeV]

  • y0 (float) – shift constant in y direction.

  • a (float) – multiplier

Returns:

Initial guess

Return type:

nld0