Last active
January 9, 2019 17:22
-
-
Save j-faria/17f100855622df200e5f86af897621ff to your computer and use it in GitHub Desktop.
Trying to emulate IRAF's noao.onedspec.continuum
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import matplotlib.pyplot as plt | |
import numpy as np | |
from scipy.interpolate import LSQUnivariateSpline | |
def continuum(wave, flux, type='ratio', order=1, low_reject=2, high_reject=0, | |
niter=10): | |
m1 = np.ones_like(wave, dtype=np.bool) # use all points at first | |
m1 &= flux!=0 # but remove those where flux = 0 | |
knots = np.linspace(wave[m1][1], wave[m1][-2], order) | |
ff = LSQUnivariateSpline(wave[m1], flux[m1], t=knots) | |
for _ in range(niter): | |
r = flux - ff(wave) # residuals | |
sig = r.std() # sigma | |
m2 = r < - low_reject * sig | |
ff = LSQUnivariateSpline(wave[m1 & ~m2], flux[m1 & ~m2], t=knots) | |
if type == 'ratio': | |
return wave[m1], flux[m1] / ff(wave[m1]), ff | |
elif type == 'fit': | |
return wave[m1], ff(wave[m1]), ff | |
elif type == 'diff': | |
return wave[m1], flux[m1] - ff(wave[m1]), ff | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment