|
PyXspec
1.0.1
|
Public Member Functions | |
| def | __init__ |
| def | __call__ |
| def | __isub__ |
| def | __iadd__ |
| def | clear |
| def | diagrsp |
| def | dummyrsp |
| def | fakeit |
| def | ignore |
| def | notice |
| def | removeDummyrsp |
| def | show |
Public Attributes | |
| nGroups | |
| The number of data groups [int]. | |
| nSpectra | |
| The number of loaded spectra [int]. | |
Spectral data container. This is a singleton - only 1 instance allowed Public instance attributes, GET only unless stated otherwise. nGroups -- The number of data groups [int]. nSpectra -- The number of loaded spectra [int].
| def __init__ | ( | self | ) |
| def __call__ | ( | self, | |
| expr | |||
| ) |
DataManager get or set spectra.
Get:
expr -- An integer referring to the spectrum index number. Returns
the spectrum, or raises an Exception if the integer is out
of range.
Set:
expr -- A string following the same syntax rules as Xspec's
traditional "data" command handler.
| def __iadd__ | ( | self, | |
| spectra | |||
| ) |
Add 1 spectrum to the data container. spectra - the data filename string.
| def __isub__ | ( | self, | |
| spectra | |||
| ) |
Remove 1 or all spectra from the data container. spectra - either a single spectrum index number (int), a single Spectrum object, or the string "*" to remove all.
| def clear | ( | self | ) |
Remove all spectra from the data container.
| def diagrsp | ( | self | ) |
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.
| def dummyrsp | ( | self, | |
lowE = None, |
|||
highE = None, |
|||
nBins = None, |
|||
scaleType = None, |
|||
chanOffset = None, |
|||
chanWidth = None |
|||
| ) |
Create a dummy response and apply it to all spectra.
Input arguments, 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.
| def fakeit | ( | self, | |
nSpectra = 1, |
|||
settings = None, |
|||
applyStats = True, |
|||
filePrefix = "" |
|||
| ) |
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).
All arguments 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,
which 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.
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.
| def ignore | ( | self, | |
| ignoreRange | |||
| ) |
Apply an ingore channels range to multiple loaded spectra.
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).
| def notice | ( | self, | |
| noticeRange | |||
| ) |
Apply a notice channels range to multiple loaded spectra.
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.
| def removeDummyrsp | ( | self | ) |
Remove all dummy responses, restore original responses (if any).
| def show | ( | self | ) |
Display information for all loaded spectra.
The number of data groups [int].
The number of loaded spectra [int].
1.7.5.1