NormalizerNLD

class ompy.NormalizerNLD(*, nld=None, discrete=None, path='saved_run/normalizers', regenerate=False, norm_pars=None)[source]

Bases: AbstractNormalizer

Normalizes NLD to empirical data

Normalizes nld/gsf according to:

nld' = nld * A * np.exp(alpha * Ex), and

This is the transformation eq (3), Schiller2000

Takes empirical data in form of an array of discrete levels, neutron separation energy Sn, a model to estimate what the NLD is at Sn, and several parameters for the model as well as bounds on normalization parameters.

As a consequence of a complex problem, this class has a complex interface. Much of the book-keeping associated with normalization has been automated, but there is still a lot of settings and parameters for the user to take care of. Some default values has been seen, but the user must be _EXTREMELY_ careful when evaluating the output.

Variables:
  • discrete (Vector) – The discrete NLD at lower energies. [MeV]

  • nld (Vector) – The NLD to normalize. Gets converted to [MeV] from [keV].

  • norm_pars (NormalizationParameters) – Normalization parameters like experimental D₀, and spin(-cut) model

  • bounds (Dict[str, Tuple[float, float]) – The bounds on each of the parameters. Its keys are ‘A’, ‘alpha’, ‘T’, and ‘D0’. The values are on the form (min, max).

  • model (Callable[..., ndarray]) – The model to use at high energies to estimate the NLD. Defaults to constant temperature model.

  • de_kwargs (dict) – Additional keywords to differential evolution. Defaults to {“seed”: 65424}. Note that bounds has been taken out as a separate attribute, but is a keyword of de.

  • multinest_path (Path) – Where to save the multinest output. defaults to ‘multinest’.

  • multinest_kwargs (dict) – Additional keywords to multinest. Defaults to {“seed”: 65498, “resume”: False}

  • res (ResultsNormalized) – Results of the normalization

  • smooth_levels_fwhm (float) – FWHM with which the discrete levels shall be smoothed when loading from file. Defaults to 0.1 MeV.

  • path (Path) – The path save the results.

Normalizes nld ang gSF.

Note

The prefered syntax is Normalizer(nld=…) If neither is given, the nld (and other parameters) can be explicity be set later by:

`normalizer.normalize(..., nld=...)`

or:

`normalizer.nld = ...`

In the later case you might have to send in a copy if it’s a mutable to ensure it is not changed.

Parameters:

Todo

  • parameter to limit the number of multinest samples to store. Note that the samples should be shuffled to retain some “random” samples from the pdf (not the importance weighted)

Attributes Summary

LOG

discrete

smooth_levels_fwhm

Methods Summary

D0_from_nldSn(nld_model, Sn, Jtarget, ...)

Calculate D0 from nld(Sn), assuming equiparity.

__call__(*args, **kwargs)

Wrapper around normalize

const_temperature(E, T, Eshift)

Constant Temperature NLD

initial_guess([limit_low, limit_high])

Find an inital guess for the constant, α, T and D₀

lnlike(x, nld_low, nld_high, discrete, ...)

Compute log likelihood of the normalization fitting

load([path])

Loads (pickeled) instance.

nldSn_from_D0(D0, Sn, Jtarget, spincutModel, ...)

Calculate nld(Sn) from D0

normalize(*[, limit_low, limit_high, nld, ...])

Normalize NLD to a low and high energy region

optimize(num, args, guess)

Find parameters given model constraints and an initial guess

plot(*[, ax, add_label, results, ...])

Plot the NLD, discrete levels and result of normalization

save([path, overwrite])

Save (pickels) the instance

save_results_txt([path, nld, gsf, samples, ...])

Save results as txt

self_if_none(*args, **kwargs)

wrapper for lib.self_if_none

Attributes Documentation

LOG = <Logger ompy.normalizer_nld (WARNING)>
discrete
smooth_levels_fwhm

Methods Documentation

static D0_from_nldSn(nld_model, Sn, Jtarget, spincutModel, spincutPars, **kwargs)[source]

Calculate D0 from nld(Sn), assuming equiparity.

This is the inverse of nldSn_from_D0

Parameters:
  • nld_model (Callable[..., Any]) – Model for nld above data of the from y = nld_model(E) in 1/MeV.

  • Sn (float or [float, float]) – Separation energy [MeV]. If a tuple, it is assumed that it is of the form [value, uncertainty].

  • Jtarget (float) – Target spin

  • spincutModel (str) – Model to for the spincut

  • Dict[str (spincutPars) – Additional parameters necessary for the spin cut model

  • Any] – Additional parameters necessary for the spin cut model

  • **kwargs – Description

Returns:

D0 in eV

Return type:

D0

__call__(*args, **kwargs)[source]

Wrapper around normalize

Return type:

None

static const_temperature(E, T, Eshift)[source]

Constant Temperature NLD

Return type:

ndarray

initial_guess(limit_low=None, limit_high=None)[source]

Find an inital guess for the constant, α, T and D₀

Uses differential evolution to perform the guessing.

Parameters:
  • limit_low (Optional[Tuple[float, float]]) – The limits (start, stop) where to normalize to discrete levels.

  • limit_high (Optional[Tuple[float, float]]) – The limits (start, stop) where to normalize to a theoretical model and neutron separation energy at high energies.

Return type:

Tuple[Tuple[float, float, float, float], Dict[str, float]]

Returns:

The arguments used for chi^2 minimization and the minimizer.

static lnlike(x, nld_low, nld_high, discrete, model, Sn, nldSn)[source]

Compute log likelihood of the normalization fitting

This is the result up a, which is irrelevant for the maximization

Parameters:
  • x (Tuple[float, float, float, float]) – The arguments ordered as A, alpha, T and Eshift

  • nld_low (Vector) – The lower region where discrete levels will be fitted.

  • nld_high (Vector) – The upper region to fit to model.

  • discrete (Vector) – The discrete levels to be used in fitting the lower region.

  • model (Callable[..., ndarray]) – The model to use when fitting the upper region. Must support the keyword arguments model(E=..., T=..., Eshift=...) -> ndarray

Returns:

log likelihood

Return type:

lnlike

load(path=None)

Loads (pickeled) instance.

Such that it can be loaded if regenerate = False. Note that if any modifications of the __getstate__ method are present, these will effect what attributes are pickeled.

Parameters:

path (Union[str, Path, None]) – The path to the directoryto load file. If the value is None, ‘self.path’ will be used.

Raises:

FileNotFoundError – If file is not found

static nldSn_from_D0(D0, Sn, Jtarget, spincutModel, spincutPars, **kwargs)[source]

Calculate nld(Sn) from D0

1/D0 = nld(Sn) * ( g(Jtarget+1/2, pi_target)
  • g(Jtarget1/2, pi_target) )

Here we assume equal parity, g(J,pi) = g(J)/2 and nld(Sn) = 1/D0 * 2/(g(Jtarget+1/2) + g(Jtarget-1/2)) For the case Jtarget = 0, the g(Jtarget-1/2) = 0

Parameters:
  • D0 (float or [float, float]) – Average resonance spacing from s waves [eV]. If a tuple, it is assumed that it is of the form [value, uncertainty].

  • Sn (float or [float, float]) – Separation energy [MeV]. If a tuple, it is assumed that it is of the form [value, uncertainty].

  • Jtarget (float) – Target spin

  • spincutModel (str) – Model to for the spincut

  • Dict[str (spincutPars) – Additional parameters necessary for the spin cut model

  • Any] – Additional parameters necessary for the spin cut model

  • **kwargs – Description

Returns:

Ex=Sn and nld at Sn [MeV, 1/MeV]

Return type:

nld

normalize(*, limit_low=None, limit_high=None, nld=None, discrete=None, bounds=None, norm_pars=None, num=0)[source]

Normalize NLD to a low and high energy region

Parameters:
  • limit_low (Optional[Tuple[float, float]]) – The limits (start, stop) where to normalize to discrete levels.

  • limit_high (Optional[Tuple[float, float]]) – The limits (start, stop) where to normalize to a theoretical model and neutron separation energy at high energies.

  • nld (Optional[Vector]) – The nuclear level density vector to normalize.

  • discrete (Optional[Vector]) – The discrete level density at low energies to normalize to.

  • bounds (Optional[Dict[str, Tuple[float, float]]]) – The bounds of the parameters

  • norm_pars (NormalizationParameters) – Normalization parameters like

  • D₀ (experimental) –

  • spin (and) –

  • num (optional) – Loop number, defauts to 0

  • regenerate – Whether to use already generated files (False) or generate them all anew (True).

Return type:

None

optimize(num, args, guess)[source]

Find parameters given model constraints and an initial guess

Employs Multinest

Parameters:
  • num (int) – Loop number

  • args_nld (Iterable) – Additional arguments for the nld lnlike

  • guess (Dict[str, float]) – The initial guess of the parameters

Returns:

  • popt (Dict[str, Tuple[float, float]]): Median and 1sigma of the

    parameters

  • samples (Dict[str, List[float]]): Multinest samples.

    Note: They are still importance weighted, not random draws from the posterior.

Return type:

Tuple

Raises:

ValueError – Invalid parameters for automatic prior

Note

You might want to adjust the priors for your specific case! Here we just propose a general solution that might often work out of the box.

plot(*, ax=None, add_label=True, results=None, add_figlegend=True, plot_fitregion=True, reset_color_cycle=True, **kwargs)[source]

Plot the NLD, discrete levels and result of normalization

Parameters:
  • ax (optional) – The matplotlib axis to plot onto. Creates axis is not provided

  • add_label (bool, optional) – Defaults to True.

  • add_figlegend (bool, optional) – Defaults to True.

  • results (ResultsNormalized, optional) – If provided, nld and model are taken from here instead.

  • plot_fitregion (Optional[bool], optional) – Defaults to True.

  • reset_color_cycle (Optional[bool], optional) – Defaults to True

  • **kwargs – Description

Return type:

Tuple[Any, Any]

Returns:

fig, ax

save(path=None, overwrite=True)

Save (pickels) the instance

Such that it can be loaded, and enabling the regenerate later.

Parameters:
  • path (Union[str, Path, None]) – The path to the save directory. If the value is None, ‘self.path’ will be used.

  • overwrite (bool) – Overwrite file if existent

save_results_txt(path=None, nld=None, gsf=None, samples=None, suffix=None)

Save results as txt

Uses a folder to save nld, gsf, and the samples (converted to an array)

Parameters:
  • path (Union[str, Path, None]) – The path to the save directory. If the value is None, ‘self.path’ will be used.

  • nld (Optional[Vector]) – (unnormalized) NLD to save

  • gsf (Optional[Vector]) – (unnormalized) gSF to save

  • samples (Optional[dict]) – samples to use for normalization

  • suffix (Optional[str]) – suffix to append to filename, eg. iteration number

self_if_none(*args, **kwargs)[source]

wrapper for lib.self_if_none