elisa.data.base#
- class ObservationData(name: str, erange: list | tuple, spec_data: SpectrumData, resp_data: ResponseData, back_data: SpectrumData | None = None, ignore_bad: bool = True, keep_channel_info: bool = False)[source]#
Bases:
objectObservation data.
- Parameters:
name (
str) – Name of the observation data.erange (
list|tuple) – Energy range of interest in keV, e.g.,erange=[(0.5, 2), (5, 200)].spec_data (
SpectrumData) – Spectrum data of the observation.resp_data (
ResponseData) – Response matrix data of the observation.back_data (
SpectrumData|None) – Background data of the observation.ignore_bad (
bool) – Whether to ignore bad channels whose quality flags are 2 or 5. The default is True.keep_channel_info (
bool) – Whether to keep channel information when grouping the data. The default is False.
Attributes
Area scaling factor of grouped spectrum bins.
Background counts of grouped measuring channels.
The background data of the observation.
Uncertainty of background counts of grouped measuring channels.
Background exposure.
Whether background data follows Poisson counting statistics.
Ratio of spectrum to background effective exposure.
Grouped net counts per second per keV.
Uncertainty of grouped net counts per second per keV.
Grouped channel information.
Right edge of the grouped measurement channel energy grid.
Geometric mean of the grouped measurement channel energy grid.
Midpoint of the grouped measurement channel energy grid.
Left edge of the grouped measurement channel energy grid.
Width between left/right edge and geometric mean of channel grid.
Width of the grouped measurement channel energy grid.
Energy range of interest.
Flags indicating which measurement channel to be used.
Current grouping flags of the observation data.
Whether the observation has background.
Whether to keep channel information when grouping the data.
Name of the observation data.
Net counts of grouped measuring channels.
Uncertainty of net counts of grouped measuring channels.
The response matrix data of the observation.
Grouped response matrix.
Grouped response matrix in sparse representation.
Spectrum counts of grouped measuring channels.
The spectrum data of the observation.
Uncertainty of grouped spectrum counts.
Spectrum exposure.
Whether spectrum data follows Poisson counting statistics.
Methods
Return a fixed data object.
group(method[, scale, preserve_data_group])Group the spectrum.
plot_effective_area([hatch, ylog])Plot the effective area.
plot_matrix([hatch, norm])Plot the response matrix.
plot_spec([xlog, data_ylog, sig_ylog])Plot the spectrum.
set_erange(erange)Set energy range of interest.
set_grouping(grouping)Set grouping flags.
- set_grouping(grouping: ndarray | None)[source]#
Set grouping flags.
First group the spectrum and background according to the grouping flags, then ignore the channel groups falling outside the energy range of interest.
- group(method: str, scale: float | None = None, preserve_data_group: bool = False)[source]#
Group the spectrum.
- Parameters:
method – Method to group spectrum and background adaptively, these options are available so that each channel group has:
- Warns:
GroupWarningWarn if grouping scale is not met for any channel.
Notes
If there are ignored channels in a channel group, this may cause an inconsistency in a spectral plot. That is to say, the error bar of a channel group will cover these bad channels, whilst these bad channels are never used in fitting.
References
- plot_spec(xlog: bool = True, data_ylog: bool = True, sig_ylog: bool = False) Figure[source]#
Plot the spectrum.
Warning
The significance plot is accurate only if the spectrum data has enough count statistics.
- Parameters:
- Returns:
The figure object.
- property spec_data: SpectrumData#
The spectrum data of the observation.
- property resp_data: ResponseData#
The response matrix data of the observation.
- property back_data: SpectrumData | None#
The background data of the observation.
- property back_errors: ndarray | None#
Uncertainty of background counts of grouped measuring channels.
- property sparse_matrix: csc_array#
Grouped response matrix in sparse representation.
- class SpectrumData(counts: ndarray, errors: ndarray, poisson: bool, exposure: float, quality: ndarray | None = None, grouping: ndarray | None = None, area_scale: float | ndarray = 1.0, back_scale: float | ndarray = 1.0, net: bool | None = None, sys_errors: float | ndarray = 0.0, zero_errors_warning: bool = True, non_int_warning: bool = True, sys_errors_warning: bool = True)[source]#
Bases:
objectSpectrum data.
- Parameters:
counts (
ndarray) – Spectrum counts in each measuring channel.errors (
ndarray) – Uncertainty of spectrum counts.poisson (
bool) – Whether spectrum data follows counting statistics.exposure (
float) – Spectrum exposure.quality – Data quality of each spectrum channel. The default is
0for all channels. The possible values are:
Attributes
Per-channel area scaling factors.
Per-channel background scaling factors.
Spectrum counts in each measuring channel.
Uncertainty of spectrum counts.
Spectrum exposure.
Grouping flags of the spectrum.
Whether grouped source scales should follow NET averaging.
Whether spectrum data follows counting statistics.
Data quality of each spectrum channel.
Methods
group(grouping[, quality])Group the spectrum.
- class ResponseData(photon_egrid: ndarray, channel_emin: ndarray, channel_emax: ndarray, response_matrix: ndarray | sparray, channel: ndarray, channel_type: str = 'Ch', sparse: bool = False)[source]#
Bases:
objectResponse matrix data.
- Parameters:
photon_egrid (
ndarray) – Photon energy array of response matrix, must be increasing.channel_emin (
ndarray) – Left edge of the measurement channel energy array, must be increasing.channel_emax (
ndarray) – Right edge of the measurement channel energy array, must be increasing.response_matrix (
ndarray|sparray) – Response matrix, the shape is (len(photon_egrid), len(channel)). This can be a sparse matrix.channel (
ndarray) – Measurement channel information.channel_type (
str) – Measurement channel type, e.g. ‘PI’. The default is ‘Ch’.sparse (
bool) – Whether the response matrix is sparse. The default is False.
Attributes
Measurement channel information.
Right edge of measurement energy grid.
Left edge of measurement energy grid.
Estimated Full Width at Half Maximum (FWHM) in channel energy space.
Number of channels.
Measurement channel type.
Estimated Full Width at Half Maximum (FWHM) in photon energy space.
Response matrix.
Photon energy grid of response matrix.
Whether the response matrix is sparse.
Sparse response matrix.
Methods
group(grouping[, quality, keep_channel_info])Group the response matrix.
group_energy(grouping[, quality, ...])Get grouped channels' energy grid information.
plot_effective_area([noticed_range, ...])Plot the response matrix.
plot_matrix([noticed_range, good_quality, norm])Plot the response matrix.
- group(grouping: ndarray, quality: ndarray | None = None, keep_channel_info: bool = False) tuple[ndarray, ndarray, coo_array, ndarray][source]#
Group the response matrix.
- Parameters:
grouping (
ndarray) – Channel with a grouping flag of 1 with all successive channels with grouping flags of -1 are combined.quality (
ndarray|None) – Flag indicating which channel to be used in grouping.keep_channel_info (
bool) – Whether to keep channel information when grouping the response. The default is False.
- Returns:
- group_energy(grouping: ndarray, quality: ndarray | None = None, keep_channel_info: bool = False) tuple[ndarray, ndarray, ndarray][source]#
Get grouped channels’ energy grid information.
- Parameters:
grouping (
ndarray) – Channel with a grouping flag of 1 with all successive channels with grouping flags of -1 are combined.quality (
ndarray|None) – Flag indicating which channel to be used in grouping.keep_channel_info (
bool) – Whether to keep channel information when grouping the response. The default is False.
- Returns:
- plot_effective_area(noticed_range: ndarray | None = None, good_quality: ndarray | None = None, ylog: bool = True) Figure[source]#
Plot the response matrix.
- Parameters:
noticed_range (
ndarray|None) – Energy range to show. Other energy ranges will be hatched.good_quality (
ndarray|None) – Flags indicating which measurement channel to be used in plotting. It must be the same length as the number of channels.ylog (
bool) – Whether to use log scale on y-axis. The default is True.
- Returns:
The figure object.
- plot_matrix(noticed_range: ndarray | None = None, good_quality: ndarray | None = None, norm: str = 'log') Figure[source]#
Plot the response matrix.
- Parameters:
noticed_range (
ndarray|None) – Energy range to show. Other energy ranges will be hatched.good_quality (
ndarray|None) – Flags indicating which measurement channel to be used in plotting. It must be the same length as the number of channels.norm (
str) – Colorbar normalization method. The default is'log'.
- Returns:
The figure object.
- property sparse_matrix: coo_array#
Sparse response matrix.
- property fwhm: ndarray#
Estimated Full Width at Half Maximum (FWHM) in photon energy space.
Note
The calculation code is translated from
heasp. This does assume that the response has a well-defined main peak and operates by the simple method of stepping out from the peak in both directions till the response falls below half the maximum. A better solution would obviously be to fit a gaussian.
- property channel_fwhm: ndarray#
Estimated Full Width at Half Maximum (FWHM) in channel energy space.
Note
The calculation code is translated from
heasp. The calculation interpolates the estimated_fwhm using the nominal channel energy to give the FWHM for each channel. Assuming that FWHM does not change significantly over the channel, so just find the FWHM at the center energy of the channel.
- class FixedData(name: str, spec_counts: NDArray, spec_errors: NDArray, spec_poisson: bool, spec_exposure: float, area_scale: float | NDArray, has_back: bool, back_counts: NDArray | None, back_errors: NDArray | None, back_poisson: bool | None, back_exposure: np.float64 | None, back_ratio: np.float64 | NDArray | None, net_counts: NDArray, net_errors: NDArray, ce: NDArray, ce_errors: NDArray, photon_egrid: NDArray, channel: NDArray, channel_emin: NDArray, channel_emax: NDArray, channel_emid: NDArray, channel_width: NDArray, channel_emean: NDArray, channel_errors: NDArray, response_matrix: NDArray, sparse_matrix: coo_array, response_sparse: bool)[source]#
Bases:
NamedTupleData to fit.
Methods
count(value, /)Return number of occurrences of value.
index(value[, start, stop])Return first index of value.
- sparse_matrix: coo_array#
Sparse response matrix.