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.
- erangearray_like
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 Background data of the observation.
- ignore_badbool, optional
Whether to ignore bad channels whose quality flags are 2 or 5. The default is True.
- keep_channel_infobool, optional
Whether to keep channel information when grouping the data. The default is False.
- name
Attributes
Area scaling factor.
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_erange(erange: list | tuple)[source]#
Set energy range of interest.
- Parameters:
- erangearray_like
Energy range of interest in keV, e.g.,
erange=[(0.5, 2), (5, 200)].
- 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.
- Parameters:
- grouping
ndarray The grouping flags. If None, restore the grouping flags stored in the spectrum file.
- grouping
- group(method: str, scale: float | None = None, preserve_data_group: bool = False)[source]#
Group the spectrum.
- Parameters:
- method
str Method to group spectrum and background adaptively, these options are available so that each channel group has:
'const': scale number channels'min': total (source + background) counts >= scale'sig': source significance >= scale sigma'bmin': background counts >= scale, used to avoid bias when usingwstatto simultaneously fit the source and background'bsig': background significance >= scale sigma, used to avoid bias when usingpgstatto simultaneously fit the source and background'opt': optimal binning, see Kaastra & Bleeker (2016) [1]'optmin': optimal binning with total counts >= scale'optsig': optimal binning with source significance >= scale sigma'optbmin': optimal binning with background counts >= scale'optbsig': optimal binning with background significance >= scale sigma
- scale
float,intorNone Grouping scale.
- preserve_data_groupbool, optional
Whether to preserve the grouping flags stored in spec_data. If true, will first group the data based on the grouping flags stored in spec_data, then apply the grouping method specified in group. If false, will directly apply the grouping method specified in group to the data, ignoring the grouping flags stored in spec_data. The default is False.
- method
- 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:
plt.FigureThe 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, 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:
- countsarray_like
Spectrum counts in each measuring channel.
- errorsarray_like
Uncertainty of spectrum counts.
- poissonbool
Whether spectrum data follows counting statistics.
- exposure
float Spectrum exposure.
- qualityarray_like, optional
Data quality of each spectrum channel. The default is
0for all channels. The possible values are:0: good1: defined bad by software2: defined dubious by software5: defined bad by user-1: reason for bad flag unknown
- groupingarray_like, optional
The grouping flag. When grouping the spectrum, channel with a grouping flag of 1 with all successive channels with grouping flags of -1 will be combined. The default is
1for all channels.- area_scale
floator array_like, optional Area scaling factor. The default is 1.0.
- back_scale
floator array_like, optional Background scaling factor. The default is 1.0.
- sys_errors
floator array_like, optional Systematic errors. If scalar, it will be applied to all channels. The default is 0.0.
- zero_errors_warningbool, optional
Whether to warn about zero errors when poisson is False. The default is True.
- non_int_warningbool, optional
Whether to warn about non-integer counts when poisson is True. The default is True.
- sys_errors_warningbool, optional
Whether to warn about non-zero systematic errors when poisson is True. The default is True.
Attributes
Area scaling factor.
Background scaling factor.
Spectrum counts in each measuring channel.
Uncertainty of spectrum counts.
Spectrum exposure.
Grouping flags of the spectrum.
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_egridarray_like
Photon energy array of response matrix, must be increasing.
- channel_eminarray_like
Left edge of the measurement channel energy array, must be increasing.
- channel_emaxarray_like
Right edge of the measurement channel energy array, must be increasing.
- response_matrixarray_like or
sparsematrix Response matrix, the shape is (len(photon_egrid), len(channel)). This can be a sparse matrix.
- channelarray_like
Measurement channel information.
- channel_type
str, optional Measurement channel type, e.g. ‘PI’. The default is ‘Ch’.
- sparsebool, optional
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, optional Flag indicating which channel to be used in grouping.
- keep_channel_infobool, optional
Whether to keep channel information when grouping the response. The default is False.
- grouping
- 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, optional Flag indicating which channel to be used in grouping.
- keep_channel_infobool, optional
Whether to keep channel information when grouping the response. The default is False.
- grouping
- 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, optional Energy range to show. Other energy ranges will be hatched.
- good_quality
ndarray, optional Flags indicating which measurement channel to be used in plotting. It must be the same length as the number of channels.
- ylogbool, optional
Whether to use log scale on y-axis. The default is True.
- noticed_range
- Returns:
- fig
plt.Figure The figure object.
- fig
- 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, optional Energy range to show. Other energy ranges will be hatched.
- good_quality
ndarray, optional Flags indicating which measurement channel to be used in plotting. It must be the same length as the number of channels.
- norm
str, optional Colorbar normalization method. The default is
'log'.
- noticed_range
- Returns:
- fig
plt.Figure The figure object.
- fig
- 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.