DataManager

class xspec.DataManager

Spectral data container.

PyXspec automatically creates a single object of this class, named AllData.

Methods

  • __call__ (the '()' operator)

  • __iadd__ (the '+=' operator)

  • __isub__ (the '-=' operator)

  • clear

  • diagrsp

  • dummyrsp

  • fakeit

  • ignore

  • notice

  • removeDummyrsp

  • show

Attributes (get-only)

  • nGroups

  • nSpectra

__call__(expr)

DataManager get or set spectra.

Args:
expr:
Get:

An integer referring to the spectrum index number. Returns the spectrum, or raises an Exception if the integer is out of range.

Set:

A string following the same syntax rules as Xspec's traditional "data" command handler.

__iadd__(spectra)

Add 1 spectrum to the data container.

Args:

spectra: The data filename string.

__init__()
__isub__(spectra)

Remove 1 or all spectra from the data container.

Args:
spectra: Either a single spectrum index number [int], a single

Spectrum object, or the string '*' to remove all.

clear()

Remove all spectra from the data container.

diagrsp()

Diagonalize the current response matrix for ideal response.

All currently loaded responses will be replaced with diagonal response matrices. The energy range and channel binning information are retained from the original response, as is the effective area. The channel values are mapped directly into the corresponding energy ranges to simulate a detector with perfect spectral resolution.

To remove diagonal responses and restore the originals, call the AllData.removeDummyrsp() method.

dummyrsp(lowE=None, highE=None, nBins=None, scaleType=None, chanOffset=None, chanWidth=None)

Create a dummy response and apply it to all spectra.

Args: (all are optional)

lowE: Input response energy lower bound, in keV. [float]

highE: Input response energy higher bound, in keV. [float]

nBins: Number of bins into which the energy range is

divided [int].

scaleType: 'log' or 'lin' [string]

chanOffset: Starting value of dummy channel

energies. [float]

chanWidth: Energy width of the channel bins. [float]

If this is set to 0, the dummy response can only be used for evaluating model arrays, and not for fitting to spectra.

Examples:

# All values are optional, use keywords to enter values
# non-consecutively.  Unspecified values revert to the
# current defaults.
AllData.dummyrsp(.3, 30., 100, chanWidth=.5)
AllData.dummyrsp(highE = 50.)
AllData.dummyrsp(.1,10.,100,"lin",.0, 1.0)

Initial defaults: lowE = .1, highE = 50., nBins = 50, scaleType = 'log', chanOffset = .0, chanWidth = .0.

The defaults for lowE, highE, nBins, scaleType, and chanOffset will be modified for each explicit new entry. chanWidth always defaults to 0.

To remove dummy responses and restore actual responses (if any), call the removeDummyrsp() method.

To apply a dummy response to just a single spectrum, use the Spectrum.dummyrsp method.

fakeit(nSpectra=1, settings=None, applyStats=True, filePrefix='', noWrite=False)

Produce spectra with simulated data using XSPEC's fakeit command.

Note that if this method is run when spectra are currently loaded, it will follow the same rule as the standard XSPEC fakeit function: It will REMOVE ALL pre-existing spectra and replace each one with a simulated spectrum (even if nSpectra is less than the number originally loaded).

Args: (all are optional)

nSpectra: The number of fake spectra to produce. [int]

If there are nOrig pre-existing spectra loaded at the time this function is called and nSpectra < nOrig, nSpectra will be RESET to nOrig (see note above).

If nSpectra == nOrig, then each of the fake spectra will use the settings from the respective original spectra for their defaults (see the FakeitSettings class description).

If nSpectra > nOrig, then settings for the fake spectra numbered above nOrig will not be based on pre-existing spectra (if any).

settings: A collection of 0 to nSpectra FakeitSettings objects.

This may be entered as a list, a dictionary, a single FakeitSettings object, or None. If settings is a dictionary, the key,value pairs should be the spectrum index number (1 is lowest) and the FakeitSettings object.

This function will match up FakeitSettings objects 1-to-1 with the nSpectra fake spectra to be created.

If user provides FEWER than nSpectra FakeitSettings objects, fakeit will generate the necessary additional objects with their default settings.

If MORE than nSpectra FakeitSettings objects are provided, the extra objects will be ignored.

applyStats: If set to True, statistical fluctuations will be

included in the generation of fake spectra. [bool]

filePrefix: Optional string to attach as a prefix to default fakeit

output file names.

Note that this only applies when using the default file names. If a file name is explicitly entered in the FakeitSettings.fileName attribute, it will not make use of this.

noWrite: If set to True, no fakeit output files will be generated.

Default is False. [bool]

Examples:

# Assume no data is loaded, but a model is defined:

AllData.fakeit()
# Creates 1 fake spectrum using the default FakeitSettings object,
# which has all input strings empty.  So it will use XSPEC's internal
# dummy response and its output file name will be dummy_rsp_1.fak.

# Now assume AllData contains 2 spectra PRIOR to running EACH of the
# following commands, then:

AllData.fakeit()
# Creates 2 fake spectra with all settings (response, arf,
# background, exposure, corrscale, backExposure, filenames) based
# on the original spectra.  The original 2 spectra are removed from
# AllData.

AllData.fakeit(3)
# Creates the first 2 spectra as above.  The 3rd fake spectrum is
# based on the default FakeitSettings object and its output filename
# will be dummy_rsp_3.fak

fs = FakeitSettings(background="back1.pha", exposure=2000.0)
sl = 3*[fs]
AllData.fakeit(3, sl)
# Same as above, but all 3 fake spectra will have a background file
# based on back1.pha, and exposure time = 2000.0 sec.

AllData.fakeit(3, sl, False, "my_fake_")
# Same as above, but no statistical fluctuations will be applied to
# fake spectra, and all output files will have the "my_fake_"
# prefix attached.

fs1 = FakeitSettings("resp1.rmf","arf1.pha",exposure=1500.)
fs2 = FakeitSettings(fs1)
fs2.response = "resp2.rmf"
sd = {3:fs1, 5:fs2}
AllData.fakeit(5, sd)
# Creates 5 fake spectra.  The first 2 use the settings from the
# originally loaded data.  Spectra 3 and 5 use the settings from
# the fs1 and fs2 FakeitSettings objects, which differ only in their
# response names.  Spectrum 4 uses the default FakeitSettings object.
ignore(ignoreRange)

Apply an ingore channels range to multiple loaded spectra.

Args:
ignoreRange: String specifying the spectra ranges and/or

channel ranges to ignore, or "bad".

This follows the same syntax as used in the standard Xspec "ignore" command, except that the spectrum range always defaults to ALL spectra.

If the channel ranges are floats rather than ints, they will be treated as energies or wavelengths (depending on the Plot settings).

notice(noticeRange)

Apply a notice channels range to multiple loaded spectra.

Args:
noticeRange: String specifying the spectra ranges and/or

channel ranges to notice.

This follows the same syntax as used in the standard Xspec "notice" command, except that the spectrum range always defaults to ALL spectra.

If the numbers are floats rather than ints, they will be treated as energies or wavelengths (depending on the Plot settings). If the string is 'all', it will notice all channels in all spectra.

removeDummyrsp()

Remove all dummy responses, restore original responses (if any).

show()

Display information for all loaded spectra.

property nGroups

The number of data groups [int].

property nSpectra

The number of loaded spectra [int].