Skip to content

Commit

Permalink
removed depreacted messages for type instead of mode, as well as gaus…
Browse files Browse the repository at this point in the history
…sian smoothed changed behaviour.

Added residual return on full mode in spec fit.
  • Loading branch information
wkerzendorf committed May 27, 2011
1 parent 657d95a commit f19bd2b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
9 changes: 2 additions & 7 deletions oned/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,12 +162,7 @@ def from_fits(cls, filename, **kwargs):
return cls(wave, flux, mode='waveflux')

def __init__(self, *args, **kwargs):
#deprecate type soon
if kwargs.has_key('type') and not kwargs.has_key('mode'):
print "Usage of keyword type is deprecated. Please use mode instead"
kwargs['mode'] = kwargs['type']



if kwargs.has_key('mode'):
if kwargs['mode'] == 'ndarray':

Expand Down Expand Up @@ -433,7 +428,7 @@ def gaussian_smooth(self, kernel, **kwargs):
of <kernel> pixels.
"""
print "Deprecated: method has changed. It now returns a new instance with the smoothing applied"


newFlux = ndimage.gaussian_filter1d(self.flux, kernel, **kwargs)

Expand Down
24 changes: 18 additions & 6 deletions oned/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -587,22 +587,27 @@ def normalise(spectrum, function='spline',
return (spectrum / continuum, continuum, continuum_regions, coeffs)

def continuum2(spectrum, low_rej=2., high_rej=3., function='legendre', maxiter=3, order=5, mode='normal'):
def fitLegendre(x, y):
def fitLegendre(x, y, mode='fit'):
p = np.polynomial.Legendre.fit(x, y, order)
return p(spectrum.wave)
if mode=='fit':
return p(spectrum.wave)
if mode=='func':
return p

def fitChebyshev(x, y):
def fitChebyshev(x, y, mode='fit'):
p = np.polynomial.Chebyshev.fit(x, y, order)
return p(spectrum.wave)

if mode=='fit':
return p(spectrum.wave)
if mode=='func':
return p
if function=='legendre':
fitfunc = fitLegendre

if function=='chebyshev':
fitfunc = fitChebyshev

contFlux = fitfunc(spectrum.wave, spectrum.flux)
mask = np.ones(spectrum.wave.shape).astype(bool)
mask = spectrum.dq
high_rej_mask = np.zeros(spectrum.wave.shape).astype(bool)
low_rej_mask = np.zeros(spectrum.wave.shape).astype(bool)
for i in range(maxiter):
Expand All @@ -614,9 +619,16 @@ def fitChebyshev(x, y):
contFlux = fitfunc(spectrum.wave[mask], spectrum.flux[mask])
if mode == 'normal':
return onedspec(spectrum.wave, contFlux, mode='waveflux')

elif mode == 'rms':
residual = (spectrum.flux[mask] - contFlux[mask])
return onedspec(spectrum.wave, contFlux, mode='waveflux'), np.std(residual)

elif mode == 'full':
residual = (spectrum.flux[mask] - contFlux[mask])
return (onedspec(spectrum.wave, contFlux, mode='waveflux'),
onedspec(spectrum.wave, residual, mode='waveflux'),
fitfunc(spectrum.wave[mask], spectrum.flux[mask], mode='func'))



Expand Down

0 comments on commit f19bd2b

Please sign in to comment.