xspec

xspec.fakeit module

Functions for running XSPEC fakeit spectral simulations and count-rate to luminosity conversions.

xga.xspec.fakeit.cluster_cr_conv(sources, outer_radius, inner_radius=<Quantity 0. arcsec>, sim_temp=None, sim_met=0.3, conv_en=<Quantity [[0.5, 2. ]] keV>, abund_table='angr', group_spec=True, min_counts=5, min_sn=None, over_sample=None, one_rmf=True, num_cores=1, stacked_spectra=False, telescope=None)[source]

This function uses the xspec fakeit tool to calculate conversion factors between count rate and luminosity for ARFs and RMFs associated with spectra in the given sources. Once complete the conversion factors are stored within the relevant XGA spectrum object. If the requested spectra do not already exist then they will automatically be generated for you. Please be aware that this function does not support calculating conversion factors from AnnularSpectra.

Parameters:
  • sources (GalaxyCluster) – The GalaxyCluster objects to calculate conversion factors for.

  • outer_radius (str/Quantity) – The name or value of the outer radius of the region that the desired spectrum covers (for instance ‘r200’ would be acceptable for a GalaxyCluster, or Quantity(1000, ‘kpc’)). If ‘region’ is chosen (to use the regions in region files), then any inner radius will be ignored. If you are generating factors for multiple sources then you can also pass a Quantity with one entry per source.

  • inner_radius (str/Quantity) – The name or value of the outer radius of the region that the desired spectrum covers (for instance ‘r200’ would be acceptable for a GalaxyCluster, or Quantity(1000, ‘kpc’)). If ‘region’ is chosen (to use the regions in region files), then any inner radius will be ignored. By default this is zero arcseconds, resulting in a circular spectrum. If you are generating factors for multiple sources then you can also pass a Quantity with one entry per source.

  • sim_temp (Quantity) – The temperature(s) to use for the apec model.

  • sim_met (float/List) – The metallicity(s) (in solar met) to use for the apec model.

  • conv_en (Quantity) – The energy limit pairs to calculate conversion factors for.

  • abund_table (str) – The name of the XSPEC abundance table to use.

  • group_spec (bool) – A boolean flag that sets whether generated spectra are grouped or not.

  • min_counts (int) – If generating a grouped spectrum, this is the minimum number of counts per channel. To disable minimum counts set this parameter to None.

  • min_sn (int/float) – If generating a grouped spectrum, this is the minimum signal to noise in each channel. To disable minimum signal to noise set this parameter to None.

  • over_sample (float) – The minimum energy resolution for each group, set to None to disable. e.g. if over_sample=3 then the minimum width of a group is 1/3 of the resolution FWHM at that energy.

  • one_rmf (bool) – This flag tells the method whether it should only generate one RMF for a particular ObsID-instrument combination - this is much faster in some circumstances, however the RMF does depend slightly on position on the detector.

  • num_cores (int) – The number of cores to use (if running locally), default is set to 90% of available.

  • stacked_spectra (bool) – Whether stacked spectra (of all instruments for an ObsID) should be generated. If a stacking procedure for a particular telescope is not supported, this function will instead use individual spectra for an ObsID. The default is False.

  • telescope (str/List[str]) – Telescope(s) to perform the XSPEC operations for. Default is None, in which case the XSPEC simulation will be performed individually for all telescopes associated with a source.

Returns:

The source object(s) passed in.

Return type:

GalaxyCluster/ClusterSample/List[GalaxyCluster]

xspec.run module

Core execution machinery and decorators for running XSPEC scripts in parallel and parsing output files.

xga.xspec.run.execute_cmd(x_script, out_file, src, run_type, timeout)[source]

This function runs the supplied XSPEC script, then parses the output for errors and checks that the expected output file has been created.

Parameters:
  • x_script (str) – The path to an XSPEC script to be run.

  • out_file (str) – The expected path for the output file of that XSPEC script.

  • src (str) – A string representation of the source object that this fit is associated with.

  • run_type (str) – A flag that tells this function what type of run this is; e.g. fit or conv_factors.

  • timeout (float) – The length of time (in seconds) which the XSPEC script is allowed to run for before being killed.

Returns:

The path to the results file (or None if unsuccessful), string repr of the source associated with this fit, a boolean flag indicating if the fit is considered usable, list of any errors found, list of any warnings found, and a boolean flag indicating whether the XSPEC run timed out.

Return type:

Tuple[Union[str, None], str, bool, list, list, bool]

xga.xspec.run.xspec_call(xspec_func)[source]

This is used as a decorator for functions that produce XSPEC scripts. Depending on the system that XGA is running on (and whether the user requests parallel execution), the method of executing the XSPEC commands will change. This supports multi-threading.

Parameters:

xspec_func (function) – The XSPEC fit/simulation function to be decorated.

Returns:

The decorated function.

Return type:

function