2.2. utils.specutils_cos package

2.2.1. check_segments

utils.specutils_cos.check_segments.check_segments(segments_list, input_file)

Checks that the array of “segments” in the COS spectrum header are expected values. It returns a scalar string representing the band (either “FUV” or “NUV”). If the array is not what’s expected, an Exception is raised.

Parameters:
  • segments_list (list) – List of segment labels.

  • input_file (str) – Name of input FITS file.

Returns:

str – A string representation of the band, either “FUV” or “NUV”.

Raises:

utils.specutils.SpecUtilsError

Note

This function does not attempt to access the input file, it only requires the name of the file for error reporting purposes.

2.2.2. cosspectrum

class utils.specutils_cos.cosspectrum.COSSegment(nelem=None, wavelengths=None, fluxes=None, fluxerrs=None, dqs=None)

Bases: object

Defines a spectrum from a COS segment. The data (wavelength, flux, flux errors) are stored as numpy ndarrays. A scalar int property provides the number of elements in this segment.

class utils.specutils_cos.cosspectrum.COSSpectrum(optical_element, band=None, cos_segments=None, orig_file=None)

Bases: object

Defines a COS spectrum, including wavelegnth, flux, flux errors, and DQ_WGT values. A COS spectrum consists of N segments (N = {2,3}) stored as a dict object. Each of these dicts contain a COSSegment object that contains the wavelengths, fluxes, flux errors, etc.

Raises:

ValueError

2.2.3. extract_subspec

utils.specutils_cos.extract_subspec.extract_subspec(cos_spectrum, segment, min_wl=None, max_wl=None)

Extracts a sub-spectrum of a COS segment’s spectrum. If both min. and max. wavelengths are specified, then it keeps the part of the spectrum within those bounds. If only a min. or max. is specified, then those are treated as lower or upper bounds, and the part of the spectrum redder/bluer than the bound is retained.

Parameters:
  • cos_spectrum (COSSpectrum) – COS spectrum as returned by READSPEC.

  • segment (str) – The segment to do the extraction on.

  • min_wl (float) – The minimum wavlength value to keep. If None, then there will be no lower bound.

  • max_wl (float) – The maximum wavelength value to keep. If None, then there will be no upper bound.

2.2.4. get_segment_names

utils.specutils_cos.get_segment_names.get_segment_names(cos_spectrum)

Returns a list of segment names sorted such that the bluest segment come first.

Parameters:

cos_spectrum (COSSpectrum) – COS spectrum as returned by READSPEC.

Returns:

list – A list of segment names.

2.2.5. plotspec

utils.specutils_cos.plotspec(cos_spectrum, output_type, output_file, flux_scale_factor, fluxerr_scale_factor, plot_metrics, dpi_val=96.0, output_size=1024, debug=False, full_ylabels=False, stitched_spectrum=None, title_addendum='', optimize=True)

Accepts a COSSpectrum object from the READSPEC function and produces preview plots.

Parameters:
  • cos_spectrum (COSSpectrum) – COS spectrum as returned by READSPEC.

  • output_type (str) – What kind of output to make?

  • output_file (str) – Name of output file (including full path).

  • flux_scale_factor (float) – Max. allowed ratio between the flux and a median flux value, used in edge trimming. Default = 10.

  • fluxerr_scale_factor (float) – Max. allowed ratio between the flux uncertainty and a median flux uncertainty value, used in edge trimming. Default = 5.

  • plot_metrics (list) – Collection of plot metrics (flux statistics, axis ranges, etc.) to use when making the plots. These are computed using utils.specutils.calc_plot_metrics().

  • dpi_val (float) – The DPI value of your device’s monitor. Affects the size of the output plots. Default = 96. (applicable to most modern monitors).

  • output_size – Size of plot in pixels (plots are square in dimensions). Defaults to 1024.

  • output_size – int

  • debug (bool) – Should the output plots include debugging information (color-coded data points based on rejection criteria, shaded exclude regions)? Default = False.

  • full_ylabels (bool) – Should the y-labels contain the full values (including the power of 10 in scientific notation)? Default = False.

  • stitched_spectrum (dict) – The stitched version of the COS spectrum, where each segment has been stitched using utils.specutils.stitch_components(). This is required is making a small (thumb-sized) plot, but not used if making a large-sized plot.

  • title_addendum (str) – A plot title addendum that contains possible warnings (e.g., if all DQ or DQ_WGT flags are defined as bad). This is only used in the case of large-sized COS plots, otherwise this information is included in the stitched spectrum (COS large-sized plots do not use a stitched version of the spectrum).

  • optimize (bool) – If set to True, will use a slightly optimized version of determining the plot covering fraction.

Raises:

OSError

2.2.6. readspec

utils.specutils_cos.readspec(input_file)

Reads in a COS spectrum FITS file (x1d, x1dsum, or x1dsum{1,2,3,4}) and returns the wavelengths, fluxes, flux uncertainties, and DQ_WGT values for the two (FUV segments) or three (NUV stripes).

Parameters:

input_file (str) – Name of input FITS file.

Returns:

COSSpectrum – The spectroscopic data (wavelength, flux, flux error, etc):

Raises:

KeyError