Vector¶
-
class
ompy.
Vector
(values=None, E=None, path=None, std=None, units='keV')[source]¶ Bases:
ompy.AbstractArray
Stores 1d array with energy axes (a vector)
- Variables
There are several ways to initialize
An initialization with only E, or energy, defaults to zero values.
An initialization using a path loads a vector from said path.
If no std is given, it will default to None
- Parameters
- Raises
ValueError if the given arrays are of differing lenghts. –
Todo
Crean up initialization.
Attributes Summary
Methods Summary
Calculate and return the calibration coefficients of the energy axes
copy
()Return a deepcopy of the class
cut
([Emin, Emax, inplace])Cut the vector at the energy limits
cut_nan
([inplace])Cut the vector where elements are np.nan
error
(other[, std])Computes the (weighted) χ²
has_equal_binning
(other, **kwargs)Check whether other has equal_binning as self within precision.
index
(E)Returns the closest index corresponding to the E value
load
(path[, filetype])Load to a file of specified format
plot
([ax, scale, kind])Plots the vector
save
(path[, filetype])Save to a file of specified format
to_MeV
()Convert E from keV to MeV if necessary
to_keV
()Convert E from MeV to keV if necessary
transform
([const, alpha, inplace])Apply a normalization transformation.
Verify the internal consistency of the vector
Attributes Documentation
Methods Documentation
-
calibration
()[source]¶ Calculate and return the calibration coefficients of the energy axes
Formatted as “a{axis}{power of E}”
-
copy
()¶ Return a deepcopy of the class
- Return type
-
has_equal_binning
(other, **kwargs)[source]¶ Check whether other has equal_binning as self within precision.
- Parameters
other (Vector) – Vector to compare to.
kwargs – Additional kwargs to np.allclose.
- Return type
- Returns
Returns True if both arrays are equal .
- Raises
TypeError – If other is not a Vector.
ValueError – If any of the bins in any of the arrays are not equal.
-
load
(path, filetype=None)[source]¶ Load to a file of specified format
- Parameters
- Raises
ValueError – Filetype is not supported
- Return type
None
-
plot
(ax=None, scale='linear', kind='line', **kwargs)[source]¶ Plots the vector
- Parameters
ax (matplotlib axis, optional) – The axis to plot onto. If not provided, a new figure is created
scale (str, optional) – The scale to use. Can be linear (default), log, symlog or logit.
kind (str, optional) –
‘line’ : line plot (default) evokes ax.plot
’plot’ : same as ‘line’
’step’ : step plot
’bar’ : vertical bar plot
kwargs (optional) – Additional kwargs to plot command.
- Return type
- Returns
The figure and axis used.
-
save
(path, filetype=None)[source]¶ Save to a file of specified format
- Parameters
- Raises
ValueError – Filetype is not supported
- Return type
None
-
transform
(const=1, alpha=0, inplace=True)[source]¶ Apply a normalization transformation:
vector -> const * vector * exp(alpha*energy)
If the vector has std, the std will be transformed as well.
- Parameters
- Return type
- Returns
Optional[Vector]
-
verify_integrity
()[source]¶ Verify the internal consistency of the vector
- Raises
AssertionError or ValueError if any test fails –
-
calibration
()[source] Calculate and return the calibration coefficients of the energy axes
Formatted as “a{axis}{power of E}”
-
cut
(Emin=None, Emax=None, inplace=True)[source] Cut the vector at the energy limits
-
cut_nan
(inplace=True)[source] Cut the vector where elements are np.nan
-
error
(other, std=None)[source] Computes the (weighted) χ²
-
has_equal_binning
(other, **kwargs)[source] Check whether other has equal_binning as self within precision.
- Parameters
other (Vector) – Vector to compare to.
kwargs – Additional kwargs to np.allclose.
- Return type
- Returns
Returns True if both arrays are equal .
- Raises
TypeError – If other is not a Vector.
ValueError – If any of the bins in any of the arrays are not equal.
-
load
(path, filetype=None)[source] Load to a file of specified format
- Parameters
- Raises
ValueError – Filetype is not supported
- Return type
None
-
plot
(ax=None, scale='linear', kind='line', **kwargs)[source] Plots the vector
- Parameters
ax (matplotlib axis, optional) – The axis to plot onto. If not provided, a new figure is created
scale (str, optional) – The scale to use. Can be linear (default), log, symlog or logit.
kind (str, optional) –
‘line’ : line plot (default) evokes ax.plot
’plot’ : same as ‘line’
’step’ : step plot
’bar’ : vertical bar plot
kwargs (optional) – Additional kwargs to plot command.
- Return type
- Returns
The figure and axis used.
-
save
(path, filetype=None)[source] Save to a file of specified format
- Parameters
- Raises
ValueError – Filetype is not supported
- Return type
None
-
transform
(const=1, alpha=0, inplace=True)[source] Apply a normalization transformation:
vector -> const * vector * exp(alpha*energy)
If the vector has std, the std will be transformed as well.
- Parameters
- Return type
- Returns
Optional[Vector]
-
verify_integrity
()[source] Verify the internal consistency of the vector
- Raises
AssertionError or ValueError if any test fails –