API Utilities#
Implementation of various functions that ease the work, but do not belong in one of the other modules.
- satlas2.utilities.generateSpectrum(models: ~satlas2.core.Model | list, x: ArrayLike, generator: callable | None = <bound method Generator.poisson of Generator(PCG64)>) ArrayLike [source]#
Generates a dataset based on the models and x-values provided.
- Parameters:
models (Union[Model, list]) – A single Model or list of models. In case of a list, all models are summed together.
x (ArrayLike) – The x values for which a y value has to be generated.
generator (callable, optional) – A callable with one parameter that returns a random value based on this. The default is a Poisson generator.
- Returns:
A same-sized array as x with values given by feeding the Model.f(x) value to the generator.
- Return type:
ArrayLike
- satlas2.utilities.poissonInterval(data: ArrayLike, sigma: float = 1, alpha: float | None = None, mean: bool = False) Tuple[float, float] [source]#
Calculates the confidence interval for the mean of a Poisson distribution.
- Parameters:
data (ArrayLike) – Samples of separate Poisson distributions.
sigma (float) – The significance level given in equivalent sigma. Defaults to 1-sigma.
alpha (Optional[float]) – Significance level of interval. If given, sigma is ignored.
mean (bool) – Set to True if the exact mean is given, by default False
- Returns:
low, high – Lower and higher limits for the interval.
- Return type:
Tuple[float, float]
- satlas2.utilities.weightedAverage(x: ArrayLike, sigma: ArrayLike, axis: int | None = None) Tuple[float, float] [source]#
Takes the weighted average of an array of values and the associated errors. Calculates the scatter and statistical error, and returns the greater of these two values.
- Parameters:
x (ArrayLike) – Array-like assortment of measured values, is transformed into a 1D-array.
sigma (ArrayLike) – Array-like assortment of errors on the measured values, is transformed into a 1D-array.
axis (Optional[int]) – Axis over which the weighted average should be calculated
- Returns:
Returns a tuple (weighted average, uncertainty), with the uncertainty being the greater of the uncertainty calculated from the statistical uncertainty and the scattering uncertainty.
- Return type:
Tuple[float, float]
Note
The formulas used are
\[ \begin{align}\begin{aligned}\left\langle x\right\rangle_{weighted} &= \frac{\sum_{i=1}^N \frac{x_i} {\sigma_i^2}} {\sum_{i=1}^N \frac{1} {\sigma_i^2}}\\\sigma_{stat}^2 &= \frac{1}{\sum_{i=1}^N \frac{1}{\sigma_i^2}}\\\sigma_{scatter}^2 &= \frac{\sum_{i=1}^N \left(\frac{x_i-\left\langle x\right\rangle_{weighted}} {\sigma_i}\right)^2} {\left(N-1\right)\sum_{i=1}^N \frac{1}{\sigma_i^2}}\end{aligned}\end{align} \]