pyird.spec package

Submodules

pyird.spec.continuum module

pyird.spec.continuum.blaze_to_df(wdata, blaze, readout_noise)

divide target flux by the blaze function

Parameters:
  • wdata – the wavelength calibrated 1D target spectrum

  • blaze – blaze function

Returns:

normalized spectrum of each order

pyird.spec.continuum.comb_norm(wfile, flatfile, combfile=None, method='mad', blaze=True)

read .dat file and make 1D normalized spectrum

Parameters:
  • wfile – path to the wavelength calibrated 1D target spectrum

  • flatfile – path to the wavelength calibrated 1D FLAT or blaze file

  • combfile – path to the laser frequency laser spectrum in Y/J band corresponding to wfile.

  • blaze – True when self.apext_flatfield() is used. if False, blaze function will be created from 1D FLAT

Returns:

pandas.DataFrame of 1D normalized spectrum

pyird.spec.continuum.continuum_oneord(wdata, flat, order)

fit continuum for one order

Parameters:
  • wdata – the wavelength calibrated target spectrum

  • flat – the wavelength calibrated FLAT

  • order – order number to fit

Returns:

spectrum and continuum of the order

pyird.spec.continuum.continuum_rsd(rsd, npix=2048, ignore_orders=None)

fit continuum for rsd

Parameters:
  • rsd – raw spectrum detector matrix

  • npix – number of pixels

  • ignore_order – list of orders not to be evaluated the goodness of the fitting

Returns:

pandas DataFrame of continuum

pyird.spec.continuum.fit_continuum(x, y, order=6, nsigma=[0.3, 3.0], maxniter=50, fitfunc='legendre')

Fit the continuum using sigma clipping

Parameters:
  • x – the wavelengths

  • y – the log-fluxes

  • order – the polynomial order to use

  • nsigma – the sigma clipping threshold: tuple (low, high)

  • maxniter – the maximum number of iterations to do

  • fitfunc – fitting function (default is legendre)

Returns:

The value of the continuum at the wavelengths in x

pyird.spec.continuum.make_blaze(wdata, flat, readout_noise, std_order=None)

extract blaze function for target based on FLAT

Parameters:
  • wdata – the wavelength calibrated target spectrum

  • flat – the wavelength calibrated FLAT

  • readout_noise – the readout noise of target spectrum

  • std_order – Once an order number is set, the blaze functions are standardized based on that order

Returns:

the blaze function created by scaling FLAT by a constant

pyird.spec.continuum.normalize(df_continuum, readout_noise)

normalize flux after combining all orders

Parameters:
  • df_continuum – pandas.DataFrame that contain the blaze function

  • readout_noise – the readout noise of target spectrum

Returns:

pandas.DataFrame of 1D normalized spectrum

pyird.spec.ecidentify module

Identifying lines in raw spectra.

pyird.spec.rsdmat module

Raw Spectral Detector matrix (RSD matrix)

pyird.spec.rsdmat.multiorder_to_rsd(rawspec, pixcoord, npix=2048, fill_value=nan)

conversion multiorder rawspec+pixcoord to RSD matrix.

Parameters:
  • rawspec – multiorder rawspec

  • pixcoord – multiorder pixel coordinate

  • npix – number of detector pixels in y direction

  • fill_value – filled value in empty elements

Returns:

RSD matrix (npix x norder)

pyird.spec.wavcal module

pyird.spec.wavcal.errfunc(p, XY, data, W, Ni, Nx)

calculate error function.

Parameters:
  • p – fitting coefficients

  • XY – meshgrid of (pixels, orders)

  • data – fitted data

  • W – matrix of weights

  • Ni – order of the fitting function arong each echelle order

  • Nx – order of the fitting function with respect to the aperture number

Returns:

residuals of data and fitting model

pyird.spec.wavcal.fit_wav_solution(XY, data, W, Ni, Nx)

optimize the fitting by using least-square method.

Parameters:
  • XY – meshgrid of (pixels, orders)

  • data – fitted data

  • W – matrix of weights

  • Ni – order of the fitting function arong each echelle order

  • Nx – order of the fitting function with respect to the aperture number

Returns:

best fit parameters (coefficients of 2d legendre series)

pyird.spec.wavcal.fitfunc(XY, Ni, Nx, params, poly='chebyshev')

calculate 2d polynomial series.

Parameters:
  • XY – meshgrid of (pixels, orders)

  • Ni – order of the fitting function arong each echelle order

  • Nx – order of the fitting function with respect to the aperture number

  • params – fitting coefficients

  • poly – ‘chebyshev’ or ‘legendre’ for fitting polynomial series

Returns:

wavelength of each pixels (flattened from npix x norder matrix)

pyird.spec.wavcal.pdat_to_wavmat(pdat, j, l, npix=2048)

conversion channel-wavelength data to wavelength matrix.

Parameters:
  • pdat – channel-wavelength data

  • npix – number of detector pixels in y direction

Returns:

channel-wavelength matrix (nipx x norder)

pyird.spec.wavcal.sigmaclip(data, wavsol, N=3)

clipping outliers.

Parameters:
  • data – the reference ThAr data

  • wavsol – best-fit model

  • N – the number of stds to use for both the lower and upper clipping limit

Returns:

residuals, drop_ind

pyird.spec.wavcal.wavcal_thar(dat, W, Ni=5, Nx=4, maxiter=10, stdlim=0.005)

wavelegth calibration for ThAr spectrum.

Parameters:
  • dat – ThAr spectrum (norder x npix matrix)

  • W – matrix of weights

  • Ni – order of the fitting function arong each echelle order

  • Nx – order of the fitting function with respect to the aperture number

  • maxiter – maximum number of iterations

  • stdlim – When the std of fitting residuals reaches this value, the iteration is terminated.

Returns:

final results of the wavlength solution data of ThAr signals used for fitting

Examples

>>> wavsol, data = wavcal_thar(thar)

Module contents