Ejemplo n.º 1
0
Archivo: extract.py Proyecto: gmace/plp
def test3(band, lname='ohlines'):
    '''
    Draw the extracted strip images with wavelength  
    '''    
    onum, odesc, owv1, owv2 = ip.read_orderinfo(band)
    cwv, cflx = ip.read_lines(lname+'.dat')
    
    wticks = np.arange(1.5, 2.5, 0.005)
    
    for desc in odesc:
        strdesc = 'IGRINS_%s_%s_%s' % (band, lname, desc)
        
        strip, shdr = ip.readfits(ONESTEP_PATH+'IGRINS_%s_%s.fits' % (desc,lname))
        wave = np.loadtxt(ONESTEP_PATH+'IGRINS_%s_%s.wave' % (desc,lname))
        
        draw_strips(strip, wave, desc=strdesc, linedata=[cwv, cflx])
Ejemplo n.º 2
0
def test3(band, lname='ohlines'):
    '''
    Draw the extracted strip images with wavelength  
    '''
    onum, odesc, owv1, owv2 = ip.read_orderinfo(band)
    cwv, cflx = ip.read_lines(lname + '.dat')

    wticks = np.arange(1.5, 2.5, 0.005)

    for desc in odesc:
        strdesc = 'IGRINS_%s_%s_%s' % (band, lname, desc)

        strip, shdr = ip.readfits(ONESTEP_PATH + 'IGRINS_%s_%s.fits' %
                                  (desc, lname))
        wave = np.loadtxt(ONESTEP_PATH + 'IGRINS_%s_%s.wave' % (desc, lname))

        draw_strips(strip, wave, desc=strdesc, linedata=[cwv, cflx])
Ejemplo n.º 3
0
Archivo: extract.py Proyecto: gmace/plp
def extract_strips(filename, band, apnum=[], pdeg=PDEGREE, \
                   PA=0, offset=[1023.5,1023.5], pscale=0.018, \
                   slit_len=[-1,1], slit_step=0.025, wave_step=0.00001, \
                   fitting_path=FITTING_PATH, \
                   target_path=ONESTEP_PATH):
    '''
    Extract the strips directly based on ZEMAX analysis fitting data 
     (using mapping parameters like position angle, pixel scale, ... 
     - input :  for each band 
        1. FITTING DATA (fitting_path) 
        2. MAPPING DATA (PA,offset,pscale) 
        
    '''
    fpath, fname = ip.split_path(filename)
    if ip.exist_path(target_path) == False: target_path = fpath
    # extract the file name only without extension
    name = '.'.join(fname.split('.')[:-1])
    
    img, hdr = ip.readfits(filename)
    # read order information from file 
    onum, odesc, owv1, owv2 = ip.read_orderinfo(band)
    
    if len(apnum) == 0:
        apnum = range(len(onum))
    
    # read image size 
    ny, nx = img.shape 
    
    #==============================================================================
    # Extract strips based on ZEMAX fitting data 
    #==============================================================================     
    descs = []     
    strips = [] 
    wavelengths = [] 
    
    for k in apnum:
        desc, wv1, wv2 = (odesc[k], owv1[k], owv2[k])
        print "order # = %s, wrr = [%f, %f]" % (desc, wv1, wv2)
        # read the echellogram fitting data 
        mx = np.loadtxt(FITTING_PATH+'mx_%s_%02d_%02d.dat' % (desc, pdeg[0], pdeg[1]))
        my = np.loadtxt(FITTING_PATH+'my_%s_%02d_%02d.dat' % (desc, pdeg[0], pdeg[1]))
        
        # make X dimension array (for wavelength) 
        twave = np.arange(wv1, wv2, wave_step, dtype=np.float64)
        n_wave = len(twave)
        # make Y dimension array (for slit)
        tslit = np.arange(slit_len[0],slit_len[1]+slit_step, slit_step, dtype=np.float64)
        n_slit = len(tslit)
        # make 2D array for wavelength, slit-positions 
        swave = np.zeros([n_slit,n_wave], dtype=np.float64)
        sslit = np.zeros([n_slit,n_wave], dtype=np.float64)
        for i in range(n_wave):
            sslit[:,i] = tslit
        for i in range(n_slit):
            swave[i,:] = twave
        # find X, Y positions for each wavelength and slit-position
        sx = ip.polyval2d(swave, sslit, mx, deg=pdeg)
        sy = ip.polyval2d(swave, sslit, my, deg=pdeg)
        # transform into pixel units 
        px, py = ip.xy2pix(sx, sy, PA=PA, offset=offset, pscale=pscale)
        # check image range 0 < x < 2048
        xmin, xmax = (0,n_wave) 
        for i in range(n_slit):
            vv = np.where((px[i,:] >= 0) & (px[i,:] < nx))[0]
            if np.min(vv) > xmin: xmin = np.min(vv)
            if np.max(vv) < xmax: xmax = np.max(vv)
        
        # extract the aperture by using interpolation from image
        tstrip = ip.imextract(img, px[:,xmin:xmax], py[:,xmin:xmax])
        twave = twave[xmin:xmax]
        print ' + Wavelength valid range = [%f, %f]' % (twave[0], twave[-1])
        
        descs.append(desc)
        wavelengths.append(twave)
        strips.append(tstrip)

    #==============================================================================
    # Save the strips in FITS format
    #==============================================================================    
    for d, w, s in zip(descs, wavelengths, strips):
        shdr = header.copy()
        
        shdr.update('GEN-TIME', time.strftime('%Y-%m-%d %H:%M:%S'))
        shdr.update('LNAME', lname)
        shdr.update('ECH-ORD', d)
        # WCS header ========================================
        shdr.update('WAT0_001', 'system=world')
        shdr.update('WAT1_001', 'wtype=linear label=Wavelength units=microns units_display=microns')
        shdr.update('WAT2_001', 'wtype=linear')
        shdr.update('WCSDIM', 2)
        shdr.update('DISPAXIS', 1)
        shdr.update('DC-FLAG', 0)
        
        # wavelength axis header ============================= 
        shdr.update('CTYPE1', 'LINEAR  ')
        shdr.update('LTV1',   1)
        shdr.update('LTM1_1', 1.0)
        shdr.update('CRPIX1', 1.0)
          #header.update('CDELT1', w[1]-w[0])
        shdr.update('CRVAL1', w[0])
        shdr.update('CD1_1',  w[1]-w[0])
        
        # slit-position axis header ==========================
        shdr.update('CTYPE2', 'LINEAR  ')
        shdr.update('LTV2',   1)
        shdr.update('LTM2_2', 1.0)
        shdr.update('CRPIX2', 1.0)
          #header.update('CDELT1', w[1]-w[0])
        shdr.update('CRVAL2', -1.0)
        shdr.update('CD2_2',  slit_step)
        
        # save FITS with header 
        ip.savefits(EXTRACT_PATH+'IGRINS_%s_%s.fits' % (lname,d), s, header=shdr)
        np.savetxt(EXTRACT_PATH+'IGRINS_%s_%s.wave' % (lname,d), w)
Ejemplo n.º 4
0
def extract_strips(filename, band, apnum=[], pdeg=PDEGREE, \
                   PA=0, offset=[1023.5,1023.5], pscale=0.018, \
                   slit_len=[-1,1], slit_step=0.025, wave_step=0.00001, \
                   fitting_path=FITTING_PATH, \
                   target_path=ONESTEP_PATH):
    '''
    Extract the strips directly based on ZEMAX analysis fitting data 
     (using mapping parameters like position angle, pixel scale, ... 
     - input :  for each band 
        1. FITTING DATA (fitting_path) 
        2. MAPPING DATA (PA,offset,pscale) 
        
    '''
    fpath, fname = ip.split_path(filename)
    if ip.exist_path(target_path) == False: target_path = fpath
    # extract the file name only without extension
    name = '.'.join(fname.split('.')[:-1])

    img, hdr = ip.readfits(filename)
    # read order information from file
    onum, odesc, owv1, owv2 = ip.read_orderinfo(band)

    if len(apnum) == 0:
        apnum = range(len(onum))

    # read image size
    ny, nx = img.shape

    #==============================================================================
    # Extract strips based on ZEMAX fitting data
    #==============================================================================
    descs = []
    strips = []
    wavelengths = []

    for k in apnum:
        desc, wv1, wv2 = (odesc[k], owv1[k], owv2[k])
        print "order # = %s, wrr = [%f, %f]" % (desc, wv1, wv2)
        # read the echellogram fitting data
        mx = np.loadtxt(FITTING_PATH + 'mx_%s_%02d_%02d.dat' %
                        (desc, pdeg[0], pdeg[1]))
        my = np.loadtxt(FITTING_PATH + 'my_%s_%02d_%02d.dat' %
                        (desc, pdeg[0], pdeg[1]))

        # make X dimension array (for wavelength)
        twave = np.arange(wv1, wv2, wave_step, dtype=np.float64)
        n_wave = len(twave)
        # make Y dimension array (for slit)
        tslit = np.arange(slit_len[0],
                          slit_len[1] + slit_step,
                          slit_step,
                          dtype=np.float64)
        n_slit = len(tslit)
        # make 2D array for wavelength, slit-positions
        swave = np.zeros([n_slit, n_wave], dtype=np.float64)
        sslit = np.zeros([n_slit, n_wave], dtype=np.float64)
        for i in range(n_wave):
            sslit[:, i] = tslit
        for i in range(n_slit):
            swave[i, :] = twave
        # find X, Y positions for each wavelength and slit-position
        sx = ip.polyval2d(swave, sslit, mx, deg=pdeg)
        sy = ip.polyval2d(swave, sslit, my, deg=pdeg)
        # transform into pixel units
        px, py = ip.xy2pix(sx, sy, PA=PA, offset=offset, pscale=pscale)
        # check image range 0 < x < 2048
        xmin, xmax = (0, n_wave)
        for i in range(n_slit):
            vv = np.where((px[i, :] >= 0) & (px[i, :] < nx))[0]
            if np.min(vv) > xmin: xmin = np.min(vv)
            if np.max(vv) < xmax: xmax = np.max(vv)

        # extract the aperture by using interpolation from image
        tstrip = ip.imextract(img, px[:, xmin:xmax], py[:, xmin:xmax])
        twave = twave[xmin:xmax]
        print ' + Wavelength valid range = [%f, %f]' % (twave[0], twave[-1])

        descs.append(desc)
        wavelengths.append(twave)
        strips.append(tstrip)

    #==============================================================================
    # Save the strips in FITS format
    #==============================================================================
    for d, w, s in zip(descs, wavelengths, strips):
        shdr = header.copy()

        shdr.update('GEN-TIME', time.strftime('%Y-%m-%d %H:%M:%S'))
        shdr.update('LNAME', lname)
        shdr.update('ECH-ORD', d)
        # WCS header ========================================
        shdr.update('WAT0_001', 'system=world')
        shdr.update(
            'WAT1_001',
            'wtype=linear label=Wavelength units=microns units_display=microns'
        )
        shdr.update('WAT2_001', 'wtype=linear')
        shdr.update('WCSDIM', 2)
        shdr.update('DISPAXIS', 1)
        shdr.update('DC-FLAG', 0)

        # wavelength axis header =============================
        shdr.update('CTYPE1', 'LINEAR  ')
        shdr.update('LTV1', 1)
        shdr.update('LTM1_1', 1.0)
        shdr.update('CRPIX1', 1.0)
        #header.update('CDELT1', w[1]-w[0])
        shdr.update('CRVAL1', w[0])
        shdr.update('CD1_1', w[1] - w[0])

        # slit-position axis header ==========================
        shdr.update('CTYPE2', 'LINEAR  ')
        shdr.update('LTV2', 1)
        shdr.update('LTM2_2', 1.0)
        shdr.update('CRPIX2', 1.0)
        #header.update('CDELT1', w[1]-w[0])
        shdr.update('CRVAL2', -1.0)
        shdr.update('CD2_2', slit_step)

        # save FITS with header
        ip.savefits(EXTRACT_PATH + 'IGRINS_%s_%s.fits' % (lname, d),
                    s,
                    header=shdr)
        np.savetxt(EXTRACT_PATH + 'IGRINS_%s_%s.wave' % (lname, d), w)