6.3.2. Data class structure

6.3.2.1. Spectral & response data

class pyspex.data.Data[source]

Main data class used to set and get observed data.

Variables:
  • ninst (int) – Number of instruments loaded.

  • inst (list of objects) – Python list of instrument objects.

delete(ins)[source]

Delete instrument with number ins.

Parameters:

ins (int) – Instrument number to delete.

load(resfile, spofile)[source]

Add a new set of spectrum and response file to the dataset. Provide the full filename including extension!

Parameters:
  • resfile (str) – SPEX response file name (including .res extension).

  • spofile (str) – SPEX spectrum file name (including .spo extension).

Return type:

int

save(ins, spofile, overwrite=False)[source]

Save a spectrum to a .spo file.

Parameters:
  • ins (int) – Instrument number to save.

  • spofile (str) – Output filename for SPEX output file (including .spo extension).

  • overwrite (bool) – (Optional) Overwrite an existing .spo file with the same name.

update()[source]

Update the number of instruments.

class pyspex.data.Instrument[source]

Properties of an instrument.

Variables:
  • nsector (int) – Number of sectors in instrument.

  • nregion – Number of data regions in response.

  • nreg (int) – Number of regions in data.

  • ncomp (int) – Number of response components.

  • index (int) – Index number of this instrument.

  • sponame (str) – Filename of .spo file.

  • resname (str) – Filename of .res file

  • reg (list of objects) – List of regions for this instrument.

update(iins)[source]

Update the instrument information.

Parameters:

iins (int) – Instrument number to update.

class pyspex.data.Region[source]

Properties of one region.

Variables:
  • index (int) – Region number.

  • emin (float) – Min data energy range (keV).

  • emax (float) – Max data energy range (keV).

  • srccount (float) – Net source counts.

  • srccerr (float) – Net source count error.

  • bkgcount (float) – Subtracted background counts.

  • bkgcerr (float) – Error subtracted background counts.

  • srcrate (float) – Net source count rate (counts/s).

  • srcrerr (float) – Net source count rate error (counts/s).

  • bkgrate (float) – Background count rate subtracted.

  • bkgrerr (float) – Error background count rate subtracted.

  • mbkgrate (float) – Model background count rate.

  • tintmin (float) – Minimum integration time per channel.

  • tintmax (float) – Maximum integration time per channel.

  • tintaver (float) – Average integration time per channel.

update(iins, ireg)[source]

Update the region properties.

Parameters:
  • iins (int) – Instrument number.

  • ireg (int) – Region number to update.

6.3.2.2. Spectral binning and data selection

class pyspex.data.Bins[source]

Class containing the binning methods.

bin(inst, reg, elow, ehigh, factor, unit=None)[source]

Bin the spectrum using a fixed factor.

Parameters:
  • inst (int) – Instrument number.

  • reg (int) – Region number.

  • elow (float) – Start point of energy/channel interval.

  • ehigh (float) – End point of energy/channel interval.

  • factor (int) – Binning factor

  • unit (str) – Unit of the energy/channel range, for example: ‘kev’, ‘ev’, ‘ryd’, ‘j’, ‘hz’, ‘ang’, ‘nm’

ignore(inst, reg, elow, ehigh, unit=None)[source]

Ignore the bins given by the energy/channel range.

Parameters:
  • inst (int) – Instrument number.

  • reg (int) – Region number.

  • elow (float) – Start point of energy/channel interval.

  • ehigh (float) – End point of energy/channel interval.

  • unit (str) – Unit of the energy/channel range, for example: ‘kev’, ‘ev’, ‘ryd’, ‘j’, ‘hz’, ‘ang’, ‘nm’

obin(inst, reg, elow, ehigh, unit=None)[source]

Bin the spectrum optimally given the instrument resolution and statistics.

Parameters:
  • inst (int) – Instrument number.

  • reg (int) – Region number.

  • elow (float) – Start point of energy/channel interval.

  • ehigh (float) – End point of energy/channel interval.

  • unit (str) – Unit of the energy/channel range, for example: ‘kev’, ‘ev’, ‘ryd’, ‘j’, ‘hz’, ‘ang’, ‘nm’

rbin(inst, reg, elow, ehigh, unit=None)[source]

Bin the spectrum and the response optimally given the instrument resolution and statistics.

Parameters:
  • inst (int) – Instrument number.

  • reg (int) – Region number.

  • elow (float) – Start point of energy/channel interval.

  • ehigh (float) – End point of energy/channel interval.

  • unit (str) – Unit of the energy/channel range, for example: ‘kev’, ‘ev’, ‘ryd’, ‘j’, ‘hz’, ‘ang’, ‘nm’

reset(inst, reg)[source]

Reset the binning and use status to use all with the original binning.

Parameters:
  • inst (int) – Instrument number.

  • reg (int) – Region number.

syserr(inst, reg, elow, ehigh, src, bkg, unit=None)[source]

Add an additional error to the source and background spectrum.

Parameters:
  • inst (int) – Instrument number.

  • reg (int) – Region number.

  • elow (float) – Start point of energy/channel interval.

  • ehigh (float) – End point of energy/channel interval.

  • src (float) – Error value to be quadratically added to the current error bar of the source spectrum.

  • bkg (float) – Error value to be quadratically added to the current error bar of the background spectrum.

  • unit (str) – Unit of the energy/channel range, for example: ‘kev’, ‘ev’, ‘ryd’, ‘j’, ‘hz’, ‘ang’, ‘nm’

use(inst, reg, elow, ehigh, unit=None)[source]

Use the bins given by the energy/channel range.

Parameters:
  • inst (int) – Instrument number.

  • reg (int) – Region number.

  • elow (float) – Start point of energy/channel interval.

  • ehigh (float) – End point of energy/channel interval.

  • unit (str) – Unit of the energy/channel range, for example: ‘kev’, ‘ev’, ‘ryd’, ‘j’, ‘hz’, ‘ang’, ‘nm’

vbin(inst, reg, elow, ehigh, factor, snr, unit=None)[source]

Bin the spectrum using a variable bin size, given a minimum bin factor and a minimum signal to noise ratio.

Parameters:
  • inst (int) – Instrument number.

  • reg (int) – Region number.

  • elow (float) – Start point of energy/channel interval.

  • ehigh (float) – End point of energy/channel interval.

  • factor (int) – Minimal binning factor

  • snr (float) – Minimal signal to noise for a data point after binning.

  • unit (str) – Unit of the energy/channel range, for example: ‘kev’, ‘ev’, ‘ryd’, ‘j’, ‘hz’, ‘ang’, ‘nm’

6.3.2.3. Simulate spectra

class pyspex.data.Simulate[source]

Class to simulate spectra.

set_bnoise(status)[source]

Add Poisson noise to the background spectrum (status is True or False).

Parameters:

status (bool) – Add Poisson noise to the simulated background spectrum.

set_instrument(irange)[source]

Define the range of instruments to simulate.

Parameters:

irange (str) – Instrument range to simulate (default all)

set_noise(status)[source]

Add Poisson noise to the source spectrum (status is True or False).

Parameters:

status (bool) – Add Poisson noise to the simulated source spectrum.

set_random()[source]

Set the random seed to a random number (default).

set_random_seed(seed)[source]

Set the random seed to an integer value.

Parameters:

seed (int) – Set the random seed for the simulation.

set_region(rrange)[source]

Define the range of regions to simulate.

Parameters:

rrange (str) – Region range to simulate (default all)

set_syserr(src, bkg)[source]

Add a systematic error to the source spectrum (src) and to the background spectrum (bkg).

Parameters:
  • src (float) – Add a systematic error to the source spectrum.

  • bkg (float) – Add a systematic error to the background spectrum.

simulate(extime, inst=None, reg=None, ssys=None, bsys=None, noise=None, bnoise=None, seed=None)[source]

Simulate a spectrum for exposure time extime and optionally with a number of options.

Parameters:
  • extime (float) – Exposure time to simulate.

  • inst (str) – (Optional) Instrument range to simulate (default all)

  • reg (str) – (Optional) Region range to simulate (default all)

  • ssys (float) – (Optional) Add a systematic error to the source spectrum (Default 0).

  • bsys (float) – (Optional) Add a systematic error to the background spectrum (Default 0).

  • noise (bool) – (Optional) Add Poisson noise to the simulated source spectrum (Default True).

  • bnoise (bool) – (Optional) Add Poisson noise to the simulated background spectrum (Default False).

  • seed (int) – (Optional) Set the random seed for the simulation (Default: system clock).

simulate_exposure(extime)[source]

Simulate the spectrum for the provided exposure time.

Parameters:

extime (float) – Exposure time to simulate.