clean_block

tayph.clean_block(wl, block, deg=0, w=200, nsigma=5.0, verbose=False, renorm=True, parallel=False)[source] [edit on github]

This quickly cleans a spectral block by performing trimming of zeroes at the edges, setting zeroes and negative values to NaN, normalising the flux along both axes, rejecting outlier values by using a running MAD, and optionally detrending using polynomials. This is intended for quick-look cross-correlation when reading in the data.

The output is the trimmed wavelength axis, the outlier-rejected sequence of spectra (block), and the residuals after outlier rejection. If detrend set to True, polynomials will be fit, and the residuals after polyfitting are also returned. So setting detrend=True increases the number of output variables from 3 to 4.

I’ve ran mad trying to make this faster but medians simply don’t collapse into nice matrix operations. So what remains is to parallelise running_MAD_2D. The parallel keyword in clean_block directly propagates into running_MAD_@D If clean_block is called once on a wide array (e.g. stitched spectra with ~1e5 points, paralellisation achieves a factor 2 speedup on my old 8-core laptop). However, if clean_block is called on a sequence of less wide arrays (e.g.) spectral orders, it’s better to do that loop in parallel rather than call clean_block with parallel itself.

Set the renorm keyword to maintain the average flux in the block. If set to False, this function will return spectra that have an average of 1.0