ZerosMatrix¶
- class ompy.ZerosMatrix(shape=None, Ex=None, Eg=None, std=False, state=None)[source]¶
Bases:
Matrix
Return new Matrix of given shape, filled with zeros.
- Parameters:
shape (
Optional
[Tuple
[int
,int
]]) – Shape of the new Matrix as [len(Ex), len(Eg)]. If Ex and Eg are provided, the shape is inferred.Eg (
Optional
[ndarray
]) – The gamma ray energies using midbinning. Defaults to an array with the length inferred from shape, if not provided.Ex (
Optional
[ndarray
]) – The excitation energies using midbinning. Defaults to an array with the length inferred from shape, if not provided.std (
bool
) – Whether to create an array for the std, too
There is the option to initialize it in an empty state. In that case, all class variables will be None. It can be filled later using the load() method.
For initializing one can give values, [Ex, Eg] arrays, a filename for loading a saved matrix or a shape for initialzing it with zero entries.
- Parameters:
values – Set the matrix’ values.
Eg (
Optional
[ndarray
]) – The gamma ray energies using midbinning.Ex (
Optional
[ndarray
]) – The excitation energies using midbinning.std (
bool
) – The standard deviations at each bin of valuespath – Load a Matrix from a given path
state (
Union
[str
,MatrixState
,None
]) – An enum to keep track of what has been done to the matrix. Can also be a str. like in [“raw”, “unfolded”, …]shape (
Optional
[Tuple
[int
,int
]]) – Depreciated. Use ZerosMatrix instead.
Attributes Summary
Returns all indices of Eg
Returns all indices of Ex
Methods Summary
ascii_plot
([shape])Plots a rebinned ascii version of the matrix
Calculates the calibration coefficients of the energy axes
copy
()Return a deepcopy of the class
cut
(axis[, Emin, Emax, inplace, ...])Cuts the matrix to the sub-interval limits along given axis.
cut_diagonal
([E1, E2, inplace])Cut away counts to the right of a diagonal line defined by indices
cut_like
(other[, inplace])Cut a matrix like another matrix (according to energy arrays)
Iterates over the last non-zero elements .. note::.
fill
(Eg, Ex[, count])Add counts to the bin containing Eg and Ex.
fill_and_remove_negative
([window_size])Combination of
ompy.Matrix.fill_negative()
andompy.Matrix.remove_negative()
fill_negative
(window_size)Wrapper for
ompy.fill_negative_gauss()
has_equal_binning
(other, **kwargs)Check whether other has equal binning as self within precision.
index_Eg
(E)Returns the closest index corresponding to the Eg value
index_Ex
(E)Returns the closest index corresponding to the Ex value
indices_Eg
(E)Returns the closest indices corresponding to the Eg value
indices_Ex
(E)Returns the closest indices corresponding to the Ex value
iter
()line_mask
(E1, E2)Create a mask for above (True) and below (False) a line
load
(path[, filetype])Load matrix from specified format
plot
(*[, ax, title, scale, vmin, vmax, ...])Plots the matrix with the energy along the axis
plot_projection
(axis[, Emin, Emax, ax, ...])Plots the projection of the matrix along axis
projection
(axis[, Emin, Emax, normalize])Returns the projection along the specified axis
rebin
(axis[, mids, factor, inplace])Rebins one axis of the matrix
Entries with negative values are set to 0
save
(path[, filetype, which])Save matrix to file
Transform Eg and Ex from mid bin (=default) to lower bin.
Transform Eg and Ex from lower bin to mid bin (=default).
trapezoid
(Ex_min, Ex_max, Eg_min[, Eg_max, ...])Create a trapezoidal cut or mask delimited by the diagonal of the
verify_equdistant
(axis)Runs checks to verify if energy arrays are equidistant
verify_integrity
([check_equidistant])Runs checks to verify internal structure
Attributes Documentation
- counts¶
- range_Eg¶
Returns all indices of Eg
- range_Ex¶
Returns all indices of Ex
- shape¶
- state¶
Methods Documentation
- ascii_plot(shape=(5, 5))¶
Plots a rebinned ascii version of the matrix
- Parameters:
shape (tuple, optional) – Shape of the rebinned matrix
- calibration()¶
Calculates the calibration coefficients of the energy axes
- copy()¶
Return a deepcopy of the class
- Return type:
- cut(axis, Emin=None, Emax=None, inplace=True, Emin_inclusive=True, Emax_inclusive=True)¶
Cuts the matrix to the sub-interval limits along given axis.
- Parameters:
axis (
Union
[int
,str
]) – Which axis to apply the cut to. Can be 0, “Eg” or 1, “Ex”.Emin (
Optional
[float
]) – Lowest energy to be included. Defaults to lowest energy. Inclusive.Emax (
Optional
[float
]) – Higest energy to be included. Defaults to highest energy. Inclusive.inplace (
bool
) – If True make the cut in place. Otherwise return a new matrix. Defaults to TrueEmin_inclusive (
bool
) – whether the bin containing the lower bin should be included (True) or excluded (False). Defaults to True.Emax_inclusive (
bool
) – whether the bin containing the higest bin should be included (True) or excluded (False). Defaults to True.
- Return type:
- Returns:
None if inplace == False cut_matrix (Matrix): The cut version of the matrix
- cut_diagonal(E1=None, E2=None, inplace=True)¶
Cut away counts to the right of a diagonal line defined by indices
- Parameters:
- Return type:
- Returns:
The matrix with counts above diagonal removed (if inplace is False).
- cut_like(other, inplace=True)¶
Cut a matrix like another matrix (according to energy arrays)
- diagonal_elements()¶
Iterates over the last non-zero elements .. note:
Assumes that the matrix is diagonal, i.e. that there are no entries with `Eg > Ex + dE`.
- fill(Eg, Ex, count=1)¶
Add counts to the bin containing Eg and Ex. :type Eg:
float
:param Eg: Eg energy value (x-axis value) :type Eg: float :type Ex:float
:param Ex: Ex energy value (y-axis value) :type Ex: float :type count:Optional
[float
] :param count: Number to add to the bin. Defaults to 1. :type count: float, otional- Return type:
- fill_and_remove_negative(window_size=20)¶
Combination of
ompy.Matrix.fill_negative()
andompy.Matrix.remove_negative()
- fill_negative(window_size)¶
Wrapper for
ompy.fill_negative_gauss()
- has_equal_binning(other, **kwargs)¶
Check whether other has equal binning as self within precision. :type other: :param other: Matrix to compare to. :type other: Matrix :type **kwargs: :param **kwargs: Additional kwargs to np.allclose.
- Returns:
Returns True if both arrays are equal .
- Return type:
- Raises:
TypeError – If other is not a Matrix
ValueError – If any of the bins in any of the arrays are not equal.
- line_mask(E1, E2)¶
Create a mask for above (True) and below (False) a line
- Parameters:
- Return type:
- Returns:
The boolean array with counts below the line set to False
Todo
Write as a property with memonized output for unchanged matrix
Note
This method and Jørgen’s original method give 2 pixels difference Probably because of how the interpolated line is drawn
- load(path, filetype=None)¶
Load matrix from specified format
- Parameters:
- Raises:
ValueError – If filetype is unknown
- Return type:
- plot(*, ax=None, title=None, scale=None, vmin=None, vmax=None, midbin_ticks=False, add_cbar=True, **kwargs)¶
Plots the matrix with the energy along the axis
- Parameters:
title (
Optional
[str
]) – Defaults to the current matrix statescale (
Optional
[str
]) – Scale along the z-axis. Can be either “log” or “linear”. Defaults to logarithmic if number of counts > 1000vmin (
Optional
[float
]) – Minimum value for coloring in scalingscaling (vmax Maximum value for coloring in) –
add_cbar (
bool
) – Whether to add a colorbar. Defaults to True.**kwargs – Additional kwargs to plot command.
- Return type:
- Returns:
The ax used for plotting
- Raises:
ValueError – If scale is unsupported
- plot_projection(axis, Emin=None, Emax=None, *, ax=None, normalize=False, scale='linear', **kwargs)¶
Plots the projection of the matrix along axis
- Parameters:
axis (
Union
[int
,str
]) – The axis to project onto. Can be either of (0, ‘Eg’, ‘x’), (1, ‘Ex’, ‘y’)Emin (
Optional
[float
]) – The minimum energy to be summed over.Emax (
Optional
[float
]) – The maximum energy to be summed over.normalize (
bool
) – If True, normalize the counts to 1. Defaults to False.scale (optional, str) – y-scale, i.e log or linear. Defaults to “linear”.
**kwargs – Additional kwargs to plot command.
- Raises:
ValueError – If axis is not in [0, 1]
- Return type:
- Returns:
The ax used for plotting
- projection(axis, Emin=None, Emax=None, normalize=False)¶
Returns the projection along the specified axis
- Parameters:
- Raises:
ValueError – If axis is not in [0, 1]
- Return type:
- Returns:
The projection and the energies summed onto
- rebin(axis, mids=None, factor=None, inplace=True)¶
Rebins one axis of the matrix
- Parameters:
mids (
Optional
[Sequence
[float
]]) – The new mids along the axis. Can not be given alongside ‘factor’.factor (
Optional
[float
]) – The factor by which the step size shall be changed. Can not be given alongside ‘mids’.inplace (
bool
) – Whether to change the axis and values inplace or return the rebinned matrix.
- Return type:
- Returns:
The rebinned Matrix if inplace is ‘False’.
- Raises:
ValueError if the axis is not a valid axis. –
- remove_negative()¶
Entries with negative values are set to 0
- save(path, filetype=None, which='values', **kwargs)¶
Save matrix to file
- Parameters:
- Raises:
ValueError – If filetype is unknown
RuntimeError – If std attribute not set.
NotImplementedError – If which is unknown
- to_lower_bin()¶
Transform Eg and Ex from mid bin (=default) to lower bin.
- to_mid_bin()¶
Transform Eg and Ex from lower bin to mid bin (=default).
- trapezoid(Ex_min, Ex_max, Eg_min, Eg_max=None, inplace=True)¶
- Create a trapezoidal cut or mask delimited by the diagonal of the
matrix
- Parameters:
Ex_min (
float
) – The bottom edge of the trapezoidEx_max (
float
) – The top edge of the trapezoidEg_min (
float
) – The left edge of the trapezoidEg_max (
Optional
[float
]) – The right edge of the trapezoid used for defining the diagonal. If not set, the diagonal will be found by using the last nonzeros of each row.
- Return type:
- Returns:
Cut matrix if ‘inplace’ is True
Todo
-possibility to have inclusive or exclusive cut
- verify_equdistant(axis)¶
Runs checks to verify if energy arrays are equidistant
- axis: The axis to project onto.
Can be either of (0, ‘Eg’, ‘x’), (1, ‘Ex’, ‘y’)
- Raises:
ValueError – If any check fails
- verify_integrity(check_equidistant=False)¶
Runs checks to verify internal structure
- Parameters:
check_equidistant (bool, optional) – Check whether energy array are equidistant spaced. Defaults to False.
- Raises:
ValueError – If any check fails