stix2xspec.xspec_utils module
- stix2xspec.xspec_utils.annotate_plot(model, chisq=None, last_component=False, exclude_parameters=['norm'], error=False, MK=False)
annotations for plot - parameters and confidence intervals if they can be calculated Input: xspec Model object Output: HTML-formatted string
- stix2xspec.xspec_utils.fit_thermal_nonthermal(xspec, thmodel='apec', ntmodel='bknpower', lowErange=[2.0, 10.0], highErange=[8.0, 30.0], breakEstart=15, breakEfrozen=False, minCounts=10, statMethod='chi', query='no', renorm=True, nIterations=1000, renotice=True)
Fit thermal and non-thermal components to spectrum via the following steps:
fit thermal over low energy
- fit non-thermal over high-energy with initial break energy frozen (if non-thermal model is bknpow or thick2)
2a) unfreeze break energy and fit non-thermal again
fit thermal and non-thermal together over entire energy range
- Parameters
xspec –
thmodel (str, optional) – Defaults to ‘apec’. Thermal model to use.
ntmodel (str, optional) – Defaults to ‘bknpower’. Non-thermal model to use. Can also be set to None, in which case only a thermal model will be fit to the data.
lowErange (list or tuple, optional) – Defaults to [2.0,10.0].
highErange (list or tuple, optional) – Defaults to [8.0,30.0]
breakEstart (float, optional) – Defaults to 15. Energy at which to
breakEfrozen (bool, optional) – Defaults to False. Freeze the break energy parameter or not.
minCounts (int, optional) – Defaults to 10. Not yet implemented.
statMethod (str, optional) – Defaults to ‘chi’. Statistics to be used.
query (str, optional) – Defaults to ‘no’. Whether to query the user for further iterations once max iterations are reached.
renorm (bool, optional) – Defaults to True. Whether to re-normalize the data or not.
nIterations (int, optional) – Defaults to 1000. Number of iterations before querying for more or stopping.
renotice (bool, optional) – Defaults to True. Whether to notice all the channels after the fit is complete (for plotting purposes mainly) or not.
- Returns
model, chisq
- Return type
tuple
- stix2xspec.xspec_utils.fits_time_to_datetime(fitsfile, idx=None)
Return a datetime axis or single datetime given an OGIP-format FITS file.
- Parameters
fitsfile (str) – Name of FITS file.
idx (int, optional) – Index at which to return datetime. Defaults to None.
- Returns
Array of datetimes, or single datetime if idx is not None.
- Return type
np.array
- stix2xspec.xspec_utils.get_xspec_model_params(model_component, norm=False)
Returns tuple of current values of xspec model component parameters. Input: xspec Component object
- stix2xspec.xspec_utils.get_xspec_model_sigmas(model_component)
Returns tuple of current values of xspec model component parameter sigmas. Input: xspec Component object
- stix2xspec.xspec_utils.plot_data(xspec, fitrange=False, dataGroup=1, erange=False, yrange=False, counts=False, title=None)
Plot spectrum data in PlotLy, as either count rate (default) or counts. Input: xspec global object
- stix2xspec.xspec_utils.plot_fit(xspec, model, fitrange=False, dataGroup=1, erange=False, yrange=[-3, 4], res_range=[-5, 5], title=False, annotation=False, plotdata_dict=False, width=500, height=700)
Plot data, fit, residuals in PlotLy. Plot from dictionary of plot parameters if xspec = None, model = plotadata
- Input:
- xspec: xspec global object or dict
Inputs to plot
- model: xspec Model object or None
Model data or None, if a previously-generated plotdata_dict is used as the input variable _xspec_
Returns: plotdata_dict: dict
The PlotLy plot data in a dictionary, to make tweaking the plot via update_layout, update_traces, update_axes, etc. later possible, since the Model object will overwrite itself eventually and be unable to plot via repeated calls to this function.
- stix2xspec.xspec_utils.set_xspec_model_params(model, model_component, component_params, frozen=False)
Sets current values of xspec model parameters. Input: xspec Model Component object, tuple of xspec model parameters
- stix2xspec.xspec_utils.show_error(model)
Show parameters and errors, if errors have been calculated. Input: xspec Model object
- stix2xspec.xspec_utils.show_model(model, df=False)
Equivalant of pyxspec show() but in Markdown for Jupyter Notebooks, or easy copy-pasting. Return dataframe to display nicely in terminal or JupyterLab Input: xspec Model object
- stix2xspec.xspec_utils.show_statistic(fit)
input xspec.Fit
- stix2xspec.xspec_utils.spectrum_from_time_interval(original_fitsfile, start_time, end_time, out_fitsname=None)
Write average count rate over selected time interval to new FITS file for fitting with XSPEC.
- Parameters
original_fitsfile (str) – Name of FITS file from which to get the spectrum.
start_time (str, datetime, int, float) – Start time in format readable by astropy.Time.
end_time (str, datetime, int, float) – End time in format readable by astropy.Time.
out_fitsname (str) – Name of output FITS file. Defaults to None.