In [21]:
# imports
from scipy.io import readsav
from scipy import interpolate
sys.path.append(os.path.abspath('/Users/xavier/local/Python/PYPIT/src/'))
from linetools import utils as ltu
from linetools.spectra import xspectrum1d
import armsgs
import ardebug
debug = ardebug.init()
last_updated = "2 May 2016"
version = '0.1'
msgs = armsgs.get_logger((None, debug, last_updated, version, 1))
import arwave as arwv
import arutils
try:
from xastropy.xutils import xdebug as debugger
except:
import pdb as debugger
In [2]:
spec1d_fil = '/Users/xavier/PYPIT/Tiffany/lris_red/Science/spec1d_OFF_J1044p6306_LRISr_2016Feb16T112439.fits'
hdu = fits.open(spec1d_fil)
hdu.info()
In [3]:
h2_obj = Table(hdu[5].data)
In [4]:
#debugger.xplot(h2_obj['box_sky'])
In [16]:
slf = arutils.dummy_self(pypitdir=os.getenv('PYPIT'))
slf._pixcen = np.zeros(10)
slf._lordloc = 0
slf._rordloc = 0
slf._argflag['arc'] = {}
slf._argflag['arc']['calibrate'] = {}
slf._argflag['arc']['calibrate']['detection'] = 5.
slf._argflag['arc']['calibrate']['nfitpix'] = 7.
#
slf._argflag['reduce'] = {}
slf._argflag['reduce']['flexure'] ={}
slf._argflag['reduce']['flexure']['spectrum'] = None
slf._argflag['reduce']['flexure']['maxshift'] = 20.
#
slf._argflag['run']['spectrograph'] = 'LRISr'
#
msgs._debug['flexure'] = True
In [11]:
# Load archive
reload(arwv)
arx_file, arx_spec = arwv.flexure_archive(slf, 1)
In [19]:
obj_sky = xspectrum1d.XSpectrum1D.from_tuple((h2_obj['box_wave'], h2_obj['box_sky']))
In [18]:
reload(arwv)
flex_dict = arwv.flex_shift(slf, 1, obj_sky, arx_spec)
In [22]:
x = np.linspace(0., 1., obj_sky.npix)
f = interpolate.interp1d(x, obj_sky.wavelength.value, bounds_error=False, fill_value="extrapolate")
twave = f(x+flex_dict['shift']/(obj_sky.npix-1))
new_sky = xspectrum1d.XSpectrum1D.from_tuple((twave, obj_sky.flux))
In [23]:
pfile = '/Users/xavier/local/Python/PYPIT/data/sky_spec/paranal_sky.fits'
phdu = fits.open(pfile)
In [24]:
pwave = phdu[0].data
pflux = phdu[1].data
In [25]:
debugger.xplot(new_sky.wavelength, h2_obj['box_sky'], xtwo=pwave, ytwo=pflux*8)