threeML.utils.spectrum package

Submodules

threeML.utils.spectrum.binned_spectrum module

class threeML.utils.spectrum.binned_spectrum.BinnedSpectrum(counts, exposure, ebounds: Union[ndarray, ChannelSet], count_errors: Optional[ndarray] = None, sys_errors: Optional[ndarray] = None, quality: Optional[Quality] = None, scale_factor: float = 1.0, is_poisson: bool = False, mission: Optional[str] = None, instrument: Optional[str] = None, tstart: Optional[float] = None, tstop: Optional[float] = None)[source]

Bases: Histogram

INTERVAL_TYPE

alias of Channel

add_inverse_variance_weighted(other)[source]
clone(new_counts=None, new_count_errors=None, new_exposure=None, new_scale_factor=None)[source]

make a new spectrum with new counts and errors and all other parameters the same

Parameters:
  • new_counts – new counts for the spectrum

  • new_count_errors – new errors from the spectrum

Returns:

property count_errors: Optional[ndarray]

count error per channel

Type:

return

property counts: ndarray

counts per channel

Type:

return

property exposure: float

Exposure in seconds

Returns:

exposure

classmethod from_pandas(pandas_dataframe, exposure, scale_factor=1.0, is_poisson=False, mission=None, instrument=None)[source]

Build a spectrum from data contained within a pandas data frame.

The required columns are:

‘emin’: low energy bin edge ‘emax’: high energy bin edge ‘counts’: the counts in each bin

Optional column names are:

‘count_errors’: errors on the counts for non-Poisson data ‘sys_errors’: systematic error per channel ‘quality’ list of 3ML quality flags ‘good’, ‘warn’, ‘bad’

Parameters:
  • pandas_dataframe – data frame containing information to be read into spectrum

  • exposure – the exposure of the spectrum

  • scale_factor – the scale factor of the spectrum

  • is_poisson – if the data are Poisson distributed

  • mission – (optional) the mission name

  • instrument – (optional) the instrument name

Returns:

classmethod from_time_series(time_series, use_poly=False, from_model=False, **kwargs)[source]
Parameters:
  • time_series

  • use_poly

Returns:

property instrument: str
property is_poisson: bool
property mission: str
property n_channel: int
property n_channels: int
property quality: Quality
property rate_errors: Optional[ndarray]

If the spectrum has no Poisson error (POISSER is False in the header), this will return the STAT_ERR column :return: errors on the rates

property rates: ndarray

rates per channel

Type:

return

property scale_factor: float
property sys_errors: ndarray

Systematic errors per channel. This is nonzero only if the SYS_ERR column is present in the input file.

Returns:

the systematic errors stored in the input spectrum

to_pandas(use_rate=True)[source]

make a pandas table from the spectrum.

Parameters:

use_rate – if the table should use rates or counts

Returns:

property total_count: float

total counts

Type:

return

property total_count_error: Optional[float]

total count error

Type:

return

property total_rate: float

total rate

Type:

return

property total_rate_error: float

total rate error

Type:

return

property tstart: float
property tstop: float
class threeML.utils.spectrum.binned_spectrum.BinnedSpectrumWithDispersion(counts, exposure, response: InstrumentResponse, count_errors: Optional[ndarray] = None, sys_errors: Optional[ndarray] = None, quality=None, scale_factor: float = 1.0, is_poisson: bool = False, mission: Optional[str] = None, instrument: Optional[str] = None, tstart: Optional[float] = None, tstop: Optional[float] = None)[source]

Bases: BinnedSpectrum

clone(new_counts=None, new_count_errors=None, new_sys_errors=None, new_exposure=None, new_scale_factor=None)[source]

make a new spectrum with new counts and errors and all other parameters the same

Parameters:
  • new_sys_errors

  • new_exposure

  • new_scale_factor

  • new_counts – new counts for the spectrum

  • new_count_errors – new errors from the spectrum

Returns:

classmethod from_time_series(time_series, response=None, use_poly=False, extract=False)[source]
Parameters:
  • time_series

  • use_poly

Returns:

property response: InstrumentResponse
class threeML.utils.spectrum.binned_spectrum.Channel(start: float, stop: float, swap_if_inverted: bool = False)[source]

Bases: Interval

property channel_width
class threeML.utils.spectrum.binned_spectrum.ChannelSet(list_of_intervals=())[source]

Bases: IntervalSet

INTERVAL_TYPE

alias of Channel

property channels_widths
classmethod from_instrument_response(instrument_response)[source]

Build EBOUNDS interval from an instrument response

Parameters:

instrument_response

Returns:

class threeML.utils.spectrum.binned_spectrum.Quality(quality: ndarray)[source]

Bases: object

property bad: ndarray
classmethod create_all_good(n_channels)[source]

construct a quality object with all good channels :param n_channels: :return:

classmethod from_ogip(ogip_quality)[source]

Read in quality from an OGIP file

Parameters:
  • cls

  • ogip_quality

Returns:

get_slice(idx)[source]
property good: ndarray
property n_elements: int
to_ogip() ndarray[source]

makes a quality array following the OGIP standards: 0 = good 2 = warn 5 = bad

Returns:

property warn: ndarray

threeML.utils.spectrum.binned_spectrum_set module

class threeML.utils.spectrum.binned_spectrum_set.BinnedSpectrumSet(binned_spectrum_list, reference_time=0.0, time_intervals=None)[source]

Bases: object

property count_errors_per_bin
property counts_per_bin
property exposure_per_bin
property n_channels
property quality_per_bin
property rate_errors_per_bin
property rates_per_bin
property reference_time
sort()[source]

sort the bin spectra in place according to time :return:

property sys_errors_per_bin
property time_intervals
time_to_index(time)[source]

get the index of the input time

Parameters:

time – time to search for

Returns:

integer

threeML.utils.spectrum.pha_spectrum module

class threeML.utils.spectrum.pha_spectrum.PHASpectrum(pha_file_or_instance: Union[str, Path, PHAII, FITSFile], spectrum_number: Optional[int] = None, file_type: str = 'observed', rsp_file: Optional[Union[str, InstrumentResponse]] = None, arf_file: Optional[str] = None)[source]

Bases: BinnedSpectrumWithDispersion

property ancillary_file: Optional[str]

Returns the ancillary file definied in the header, or None if there is none defined

Returns:

a path to a file, or None

property background_file: Union[None, str]

Returns the background file definied in the header, or None if there is none defined p

return:

a path to a file, or None

clone(new_counts=None, new_count_errors=None, new_exposure=None, new_scale_factor=None) PHASpectrum[source]

make a new spectrum with new counts and errors and all other parameters the same

Parameters:
  • new_exposure – the new exposure for the clone

  • new_scale_factor – the new scale factor for the clone

  • new_counts – new counts for the spectrum

  • new_count_errors – new errors from the spectrum

Returns:

new pha spectrum

property filename: str
classmethod from_dispersion_spectrum()[source]
property grouping: ndarray
property response_file: Optional[str]

Returns the response file definied in the header, or None if there is none defined

Returns:

a path to a file, or None

property scale_factor: float

This is a scale factor (in the BACKSCAL keyword) which must be used to rescale background and source regions

Returns:

set_ogip_grouping(grouping) None[source]

If the counts are rebinned, this updates the grouping :param grouping:

to_binned_spectrum() BinnedSpectrumWithDispersion[source]

Convert directly to as Binned Spectrum :returns:

class threeML.utils.spectrum.pha_spectrum.PHASpectrumSet(pha_file_or_instance: Union[str, Path, PHAII], file_type: str = 'observed', rsp_file: Optional[str] = None, arf_file: Optional[str] = None)[source]

Bases: BinnedSpectrumSet

property ancillary_file

Returns the ancillary file definied in the header, or None if there is none defined

Returns:

a path to a file, or None

property background_file

Returns the background file definied in the header, or None if there is none defined p

return:

a path to a file, or None

clone(new_counts=None, new_count_errors=None)[source]

make a new spectrum with new counts and errors and all other parameters the same

Parameters:
  • new_counts – new counts for the spectrum

  • new_count_errors – new errors from the spectrum

Returns:

new pha spectrum

property filename
classmethod from_dispersion_spectrum(dispersion_spectrum: BinnedSpectrumWithDispersion, file_type: str = 'observed') PHASpectrum[source]
property grouping
property response_file

Returns the response file definied in the header, or None if there is none defined

Returns:

a path to a file, or None

property scale_factor

This is a scale factor (in the BACKSCAL keyword) which must be used to rescale background and source regions

Returns:

set_ogip_grouping(grouping)[source]

If the counts are rebinned, this updates the grouping :param grouping:

threeML.utils.spectrum.share_spectrum module

class threeML.utils.spectrum.share_spectrum.ShareSpectrum(datalist)[source]

Bases: object

property base_plugin_key
property data_ebin_connect
property data_ein_edges

threeML.utils.spectrum.spectrum_likelihood module

class threeML.utils.spectrum.spectrum_likelihood.BinnedStatistic(spectrum_plugin)[source]

Bases: object

get_current_value()[source]
get_randomized_background_counts()[source]
get_randomized_background_errors()[source]
get_randomized_source_counts(source_model_counts)[source]
get_randomized_source_errors()[source]
threeML.utils.spectrum.spectrum_likelihood.GaussianObservedGaussianBackgroundStatistic

alias of NotAvailableStatistic

class threeML.utils.spectrum.spectrum_likelihood.GaussianObservedStatistic(spectrum_plugin)[source]

Bases: BinnedStatistic

get_current_value(precalc_fluxes: Optional[array] = None)[source]
get_randomized_source_counts(source_model_counts)[source]
get_randomized_source_errors()[source]
class threeML.utils.spectrum.spectrum_likelihood.NotAvailableStatistic(spectrum_plugin)[source]

Bases: object

class threeML.utils.spectrum.spectrum_likelihood.PoissonObservedGaussianBackgroundStatistic(spectrum_plugin)[source]

Bases: BinnedStatistic

get_current_value(precalc_fluxes: Optional[array] = None)[source]
get_randomized_background_counts()[source]
get_randomized_background_errors()[source]
get_randomized_source_counts(source_model_counts)[source]
class threeML.utils.spectrum.spectrum_likelihood.PoissonObservedIdealBackgroundStatistic(spectrum_plugin)[source]

Bases: BinnedStatistic

get_current_value(precalc_fluxes: Optional[array] = None)[source]
get_randomized_background_counts()[source]
get_randomized_source_counts(source_model_counts)[source]
class threeML.utils.spectrum.spectrum_likelihood.PoissonObservedModeledBackgroundStatistic(spectrum_plugin)[source]

Bases: BinnedStatistic

get_current_value(precalc_fluxes: Optional[array] = None)[source]
get_randomized_background_errors()[source]
get_randomized_source_counts(source_model_counts)[source]
property synthetic_background_plugin
class threeML.utils.spectrum.spectrum_likelihood.PoissonObservedNoBackgroundStatistic(spectrum_plugin)[source]

Bases: BinnedStatistic

get_current_value(precalc_fluxes: Optional[array] = None)[source]
get_randomized_source_counts(source_model_counts)[source]
class threeML.utils.spectrum.spectrum_likelihood.PoissonObservedPoissonBackgroundStatistic(spectrum_plugin)[source]

Bases: BinnedStatistic

get_current_value(precalc_fluxes: Optional[array] = None)[source]
get_randomized_background_counts()[source]
get_randomized_source_counts(source_model_counts)[source]

Module contents