spectrum - Spectrum manipulations

Spectrum I/O, multi-roll merge, adaptive continuum fit, emission-line detection and fit.

Warning

All input wavelengths in Å.

Table(name, colX, colY[, ext, keepHdr]) Simple FITS table handler.
Spectrum(name[, varname, keepFits]) FITS 1D-spectrum handler.
SimSpectrum(name[, varname, keepFits]) Multi-roll NISP simulated spectrum (Simulations_140425).
inspec.spectrum.formatwarning(message, category, filename, lineno, file=None, line=None)[source]
inspec.spectrum.get_extension(name, default=0)[source]

Return (name, EXT) from ‘name[ext]’, using default ext if unspecified.

class inspec.spectrum.Table(name, colX, colY, ext=1, keepHdr=False)[source]

Simple FITS table handler.

colY can be a single column name (self.ny=1) or a tuple of column names (self.ny=len(colY)). If self.ny>1, self.y is a (self.ny, self.npts) 2D-array. ext specifies the extension number or name, which can also be specified in name[ext].

static isSorted(x, increasing=None, strictly=False)[source]

Check if x in [strictly] sorted (increasing=None), increasing (True) or decreasing (False).

sort()[source]
interpolate(x, cols=None, monotonic=False)[source]

Interpolate table over input array x. For self.ny>1, cols specifies the column indices to be interpolated (all by default).

class inspec.spectrum.Spectrum(name, varname=None, keepFits=True)[source]

FITS 1D-spectrum handler.

Class to read and manage a spectrum typically from a FITS file (NAXIS=1), including the associated [co]variance from an extension or an external file.

Warning

this is not directly compatible w/ NISP simulated spectrum from Simulations_140425. See SimSpectrum.

Spectrum initialization.

hasVar
hasCov
close()[source]

Close FITS file (if any) and forget about it.

readKey(keyword, default=None)[source]

Read a single keyword, defaulting to default if any.

setKey(keywords=(), **kwargs)[source]

Set keywords from keywords=((key, val[, comment]),) or kwargs key=val or key=(val, comment).

resetHeader()[source]

Delete all non-standard keywords.

writeto(outName, force=False, hdrOnly=False, keywords=(), **kwargs)[source]

Save Spectrum to new FITS-file.

classmethod read_spectrum(arg, keepFits=True)[source]

Return an initiated Spectrum from arg=name[, var_name], including proper deciphering of arg.

static get_varname(specname, exists=False)[source]

Return variance spectrum name associated to spectrum ‘specname’. Assumes variance spectrum is located in same directory as spectrum. If exists, test if variance file exists or return None.

classmethod from_vecs(x, y, name='', v=None)[source]

Initialize spectrum from arbitrary vectors.

Parameters:
  • x – wavelength array [Å]
  • y – signal array [erg/s/cm²/Å]
  • name – name of spectrum
  • v – variance array
Raises:

AssertionError – incompatible vectors or non-uniformly sampled wavelengths

classmethod from_simtables(name, path='', minnpts=3)[source]

Read spectrum stored in simulation table “name.fits” and associated noise table “name_noise.fits”. Return None if spectrum is too short.

Note

valid for Simulations_140425.

extend(x)[source]

Extend all spectra to match wavelength sampling x.

plot(ax=None, errorband=False, sgfilter=None, **kwargs)[source]

Plot spectrum.

Parameters:
  • ax – plot axis
  • errorband – add errorbands
  • sgfilter – Savitzky-Golay filter parameters (hsize, order)
  • kwargs – propagated to plot command
Returns:

plot axis

fracs(xmin, xmax)
class inspec.spectrum.SimSpectrum(name, varname=None, keepFits=True)[source]

Multi-roll NISP simulated spectrum (Simulations_140425).

Warning

Wavelengths in Å, fluxes in 1e-17 erg/s/cm²/Å.

Spectrum initialization.

classmethod from_idx(idx, path='')[source]

Read spectra corresponding to index idx, return {'roll': spectrum}.

static select_refspec(sdict)[source]

Select reference spectrum from sdict = { 'roll': spectrum }.

Select reference with most current start % step = 4.8 A

classmethod merge_specs(sdict, rtol=0.02)[source]

Merge spectra from sdict = { 'roll': spectrum } to produce a Spectrum.

writeto(name, path='', clobber=True, keywords={})[source]

Minimal FITS writer. No propagation of header.

inspec.spectrum.fit_adaptive(spec, pmax=0.05, dmax=3, nmax=3, verbose=False)[source]

Trivial wrapper to S.fit_adaptive_spectrum().

inspec.spectrum.plot_specs(sdict, sgfilter=None, model=None, metadata=None, emilines={}, fig=None, add_pull=True)[source]

Plot spectra from sdict = { 'roll': spectrum }.