Skip to content

Commit

Permalink
finish badpixel kludge
Browse files Browse the repository at this point in the history
  • Loading branch information
profxj committed Mar 15, 2018
1 parent 880804a commit 3be32c5
Showing 1 changed file with 7 additions and 14 deletions.
21 changes: 7 additions & 14 deletions linetools/analysis/abskin.py
Expand Up @@ -4,6 +4,7 @@

import numpy as np
import pdb
import warnings

from astropy import units as u
from astropy.convolution import convolve, Box1DKernel
Expand Down Expand Up @@ -33,15 +34,16 @@ def generate_stau(velo, flux, sig, kbin=22.*u.km/u.s, debug=False):
# Calculate dv
dv = np.abs(np.median(velo-np.roll(velo,1)))

# Test for bad pixels
# Test for and replace bad pixels
badzero = np.where((flux == 0) | (sig <= 0))[0]
if len(badzero) > 0:
if np.max(badzero)-np.min(badzero) >= 5:
raise ValueError('orig_kin: too many or too large sections of bad data')

warnings.warn("Input array to generate_stau has one or more bad pixels. Replacing with the local mean")
flux[badzero] = np.mean(np.array([flux[np.min(badzero)-1],
flux[np.max(badzero)+1]]))
pdb.set_trace() # Should add sig too
sig[badzero] = np.mean(np.array([sig[np.min(badzero)-1],
sig[np.max(badzero)+1]]))

# Generate the tau array
tau = np.zeros(npix)
Expand All @@ -56,19 +58,10 @@ def generate_stau(velo, flux, sig, kbin=22.*u.km/u.s, debug=False):

# Smooth
nbin = (np.round(kbin/dv)).value
try:
kernel = Box1DKernel(nbin, mode='center')
except:
pdb.set_trace()
kernel = Box1DKernel(nbin, mode='center')
stau = convolve(tau, kernel, boundary='fill', fill_value=0.)
if debug is True:
try:
from xastropy.xutils import xdebug as xdb
except ImportError:
pdb.set_trace()
else:
xdb.xplot(velo, tau, stau)
xdb.set_trace()
pdb.set_trace()

# Return
return stau
Expand Down

0 comments on commit 3be32c5

Please sign in to comment.