Beispiel #1
0
                          inttype=inttype,
                          debug=False)
        data[j, :] = zeroshift(data[j, :],
                               xarr,
                               nws,
                               blank=blank,
                               inttype=inttype)
    return data


def zeroshift(data, xarr, nws, blank=0, inttype='interp'):
    """Calculate zeropoint shift and apply to the data
    """
    if nws is not None:
        w_arr = nws.value(xarr)
        data = st.interpolate(xarr,
                              w_arr,
                              data,
                              inttype,
                              left=blank,
                              right=blank)
    return data


if not iraf.deftask('specselfid'):
    parfile = iraf.osfn("saltspec$specselfid.par")
    t = iraf.IrafTaskFactory(taskname="specselfid",
                             value=parfile,
                             function=specselfid,
                             pkgname='saltspec')
Beispiel #2
0
           if afile[k].strip().upper()!=bfile[k].strip().upper(): return False
        if isinstance(afile[k], int):
           if afile[k]==bfile[k]: return False
        if isinstance(afile[k], float):
           if abs(afile[k]-bfile[k])>0.01: return False
    return True

def linkfiles(fname, pdir, detmode, rawpath, prodpath, outpath, prefix='mbxgp', fprefix='bxgp', clobber=False):

   #copy the raw data
   infile=rawpath+fname
   link=outpath+pdir+'/raw/'+fname
   saltio.symlink(infile,link,clobber)

   #copy the product data
   if not fastmode(detmode):
       pfname=prefix+fname
   else:
       pfname=fprefix+fname
   infile = prodpath+pfname
   link = outpath+pdir+'/product/'+pfname
   if fname[0] in ['S', 'P', 'H', 'R']: 
      saltio.symlink(infile,link,clobber)


# -----------------------------------------------------------
# main code
if not iraf.deftask('saltobsid'):
  parfile = iraf.osfn("pipetools$saltobsid.par")
  t = iraf.IrafTaskFactory(taskname="saltobsid",value=parfile,function=saltobsid, pkgname='pipetools')
Beispiel #3
0
                    '
           
            
            #Open file to write new time to header, if desired.
            if writetoheader:
                try:
                    filetowrite=fits.open(file,mode='update')
                except Exception, e:
                    print e
                
                for num in range(len(dateTimeString)):
                    hdr=filetowrite[num].header
                    if hdr.has_key(keyword)==1:
                        if clobber:
                            hdr.update(keyword,newTime[num],comment)
                            print 'Keyword ' +keyword +' has been updated in header extension '+str(num)+' to the following value: '+ str(newTime[num])
                        else:
                            print 'Keyword '+keyword+' has not been updated.'
                    else:   
                        hdr.update(keyword,newTime[num],comment,after='TIME-OBS')
                        print 'Keyword ' + keyword +' has been added to header extension '+str(num)+' as the following value: '+ str(newTime[num])
                
                    filetowrite.flush()
                filetowrite.close()

# -----------------------------------------------------------
# end main code 
if not iraf.deftask('saltheadtime'):
   parfile = iraf.osfn("saltred$saltheadtime.par") 
   t =iraf.IrafTaskFactory(taskname="saltheadtime",value=parfile,function=saltheadtime,pkgname='saltred')
Beispiel #4
0
    msg += '#grating=%s\n' % grating.strip()
    msg += '#graang=%s\n' % grang
    msg += '#gratilt=%s\n' % grasteps
    msg += '#arang=%s\n' % arang
    msg += '#artilt=%s\n' % arsteps
    msg += '#filter=%s\n' % rfilter.strip()
    if objid:
        msg += '#slitid=%s\n' % objid
    msg += '#Function=%s\n' % function
    msg += '#Order=%s\n' % order
    msg += '#Starting Data\n'
    dout.write(msg)

    for i in range(len(ws_arr)):
        if ws_arr[i, 0]:
            msg = '%5.2f ' % ws_arr[i, 0]
            msg += ' '.join(['%e' % k for k in ws_arr[i, 1:]])
            dout.write(msg + '\n')
    dout.write('\n')
    dout.close()

    return


# main code

if not iraf.deftask('specidentify'):
    parfile = iraf.osfn("saltspec$specidentify.par")
    t = iraf.IrafTaskFactory(
        taskname="specidentify", value=parfile, function=specidentify, pkgname='saltspec')
Beispiel #5
0
    #set binning
    binstr = saltstring.makebinstr(flatkeys[2])

    #set gain
    gnstr = saltstring.makegainstr(flatkeys[3])

    #set readout
    rostr = saltstring.makereadoutstr(flatkeys[4])

    fltstr = flatkeys[5].strip()

    if flatkeys[6].count('SKY'):
        skystr = 'Sky'
    else:
        skystr = ''

    flatname = '%s%s%sFlat%s%s%s%s%s.fits' % (instr, obsdate, skystr, mdstr,
                                              binstr, gnstr, rostr, fltstr)
    return flatname


# -----------------------------------------------------------
# main code

if not iraf.deftask('saltclean'):
    parfile = iraf.osfn("saltred$saltclean.par")
    t = iraf.IrafTaskFactory(taskname="saltclean",
                             value=parfile,
                             function=saltclean,
                             pkgname='saltred')
Beispiel #6
0
        for i in range(ys):
            x = numpy.arange(xs)
            rdata = data[i, :]
            rmask = mask[i, :]
            rmask = nd.minimum_filter(rmask, size=3)
            if rmask.any() == True:
                rdata = numpy.interp(x, x[rmask], rdata[rmask])
                data[i, rmask == 0] = rdata[rmask == 0]

    return data


def tran_func(a, xshift, yshift, xmag, ymag, xrot, yrot):
    xtran = ymag * a[0] * cos(yrot * pi / 180.0) \
        - xmag * a[1] * sin(xrot * pi / 180) \
        - yshift
    ytran = ymag * a[0] * sin(yrot * pi / 180.0) \
        + xmag * a[1] * cos(xrot * pi / 180) \
        - xshift
    return xtran, ytran


# -----------------------------------------------------------
# main code
if not iraf.deftask('saltmosaic'):
    parfile = iraf.osfn("saltred$saltmosaic.par")
    t = iraf.IrafTaskFactory(taskname="saltmosaic",
                             value=parfile,
                             function=saltmosaic,
                             pkgname='saltred')
Beispiel #7
0
    """Return the keyword value.  Throw a warning if it doesn't work """

    try:
        value = saltkey.get(keyword, struct)
        if isinstance(default, str): value = value.strip()
    except SaltIOError:
        value = default
        infile = struct._file.name
        message = 'WARNING: cannot find keyword %s in %s' % (keyword, infile)
        if warn and log: log.message(message, with_header=False)
    if (str(value).strip() == ''): value = default
    if (type(value) != type(default)):
        infile = struct._file.name
        message = 'WARNING: Type mismatch for %s for  %s in %s[0]' % (
            str(value), keyword, infile)
        message += '/n ' + str(type(value)) + ' ' + str(type(default))
        if warn and log: log.message(message, with_header=False)
        value = default

    return value


# -----------------------------------------------------------
# main code
if not iraf.deftask('saltobslog'):
    parfile = iraf.osfn("saltred$saltobslog.par")
    t = iraf.IrafTaskFactory(taskname="saltobslog",
                             value=parfile,
                             function=saltobslog,
                             pkgname='saltred')
Beispiel #8
0
    #if len(obsdate)<4: obsdate=''

    #set the mode string
    #mdstr=saltstring.makedetmodestr(biaskeys[2])
    detstr='B'
    instr='H'
    ampstr='A2'
    if biaskeys[1]=='08443-03-01': 
       detstr='R'
       instr='R'
       ampstr='A4'

    #set binning
    binstr=saltstring.makebinstr(biaskeys[3])

    #set the AMP string


    biasname='%s%sBias%s%s%s.fits' % (instr, obsdate, detstr, binstr, ampstr)
    return biasname

   



if not iraf.deftask('hrsclean'):
    parfile = iraf.osfn("salthrs$hrsclean.par")
    t = iraf.IrafTaskFactory(taskname="hrsclean",value=parfile,function=hrsclean, pkgname='salthrs')

Beispiel #9
0
           winsect=saltio.getSection(saltkey.get('AMPSEC', struct[i+6*j]), iraf_format=True)
           y1=(winsect[0]-1)/ybin
           #y2=(winsect[1])/ybin+1
           y2=y1+len(struct[i+6*j].data)

           x1=(winsect[2]-1)/xbin
           x2=len(struct[i+6*j].data[0])
           #x2=(winsect[3])/xbin
         
           extdata[y1:y2,x1:x2]=struct[i+6*j].data
        
           xmax=max(xmax, x2)
           
 
        #add the correct header information *TODO*   
 
        #append to the hdu list
        exthdu=yfits.ImageHDU(extdata[:,0:xmax])
        outstruct.append(exthdu)


    #return the new extension
    return outstruct

# -----------------------------------------------------------
# main code

if not iraf.deftask('saltembed'):
    parfile = iraf.osfn("saltred$saltembed.par")
    t =  iraf.IrafTaskFactory(taskname="saltembed",value=parfile,function=saltembed, pkgname='saltred')
Beispiel #10
0
    #flat field the data
    for i in range(nextend):
       if struct[i].name=='SCI' or len(struct)==1:

            #create the median image
            if mask: 
               bpmext = saltkey.get('BPMEXT', struct[i])
               mask_arr = (struct[bpmext].data == 0) * (struct[i].data > minlevel)
            else:
               mask_arr = (struct[i].data < minlevel)

            #create the data
            coef=fit_surface(struct[i].data, mask=mask_arr, xorder=order, yorder=order, xyorder=0)
            y, x = np.indices(struct[i].data.shape)
            sf=surface(coef, xorder=order, yorder=order, xyorder=0)
            print coef
            struct[i].data=sf(x,y)

            #Account for variance frames 
            if mask:
               struct[bpmext].data = struct[bpmext].data*0


    return struct

# -----------------------------------------------------------
# main code
if not iraf.deftask('saltsurface'):
   parfile = iraf.osfn("saltred$saltsurface.par")
   t = iraf.IrafTaskFactory(taskname="saltsurface",value=parfile,function=saltsurface, pkgname='saltred')
Beispiel #11
0
        message = infits+' is not a SALT File \n'
    try:
        i=infits.index("R")
    except:
        message = infits+' is not a SALT File \n'

    if i>=0:
        inname=infits[i:]
    else:
        inname=''
        message = 'SALTSDBLOADFITS -- ERROR : ' + message
        raise SaltError(message)

    return inname


def findimagenumber (filename):
    """find the number for each image file"""
    #split the file so that name is a string equal to OBSDATE+number
    name=filename.split('/')[-1].split('.')[0]
    return int(name[9:])


# -----------------------------------------------------------
# main code


if not iraf.deftask('saltsdbloadfits'):
  parfile = iraf.osfn("pipetools$saltsdbloadfits.par")
  t = iraf.IrafTaskFactory(taskname="saltsdbloadfits",value=parfile,function=saltsdbloadfits, pkgname='pipetools')
Beispiel #12
0
                status = saltkey.rem('BIASSEC',struct[hdu],infile,logfile)
                datasec = '[1:'+str(dx2_2-dx1_2)+',1:'+str(dy2_2-dy1_2)+']'
                status = saltkey.put('DATASEC',datasec,struct[hdu+1],infile,logfile)
                status = saltkey.rem('BIASSEC',struct[hdu+1],infile,logfile)

# log coefficient table

            if (status == 0):
                infilename = infile.split('/')
                infilename = infilename[len(infilename)-1]
                message = '%25s[%3d] %5.2f %4d %8.6f' % \
                    (infilename, hdu, gain1, overlevel_1, float(xcoeff[amplifier+1]))
                saltprint.log(logfile,message,verbose)
                message = '%25s[%3d] %5.2f %4d %8.6f' % \
                    (infilename, hdu+1, gain2, overlevel_2,float(xcoeff[amplifier]))
                saltprint.log(logfile,message,verbose)

# update image in HDU structure

            if (status == 0):
                struct,status = saltio.writeimage(struct,hdu,imagedata1,logfile)
                struct,status = saltio.writeimage(struct,hdu+1,imagedata2,logfile)

    return struct, status

# -----------------------------------------------------------
# main code
if not iraf.deftask('saltslot'):
   parfile = iraf.osfn("saltred$saltslot.par")
   t = iraf.IrafTaskFactory(taskname="saltslot",value=parfile,function=saltslot, pkgname='saltred')
Beispiel #13
0
    """
    # Determine the number of extensions
    nextend = len(struct)

    #flat field the data
    for i in range(nextend):
        if struct[i].name == 'SCI' or len(struct) == 1:

            #create the median image
            mdata = median_filter(struct[i].data, size=(mbox, mbox))

            #create the data
            struct[i].data = struct[i].data / mdata

            #Account for variance frames
            if saltkey.found('VAREXT', struct[i]):
                varext = saltkey.get('VAREXT', struct[i])
                struct[varext].data = struct[varext].data / mdata

    return struct


# -----------------------------------------------------------
# main code
if not iraf.deftask('saltillum'):
    parfile = iraf.osfn("saltred$saltillum.par")
    t = iraf.IrafTaskFactory(taskname="saltillum",
                             value=parfile,
                             function=saltillum,
                             pkgname='saltred')
Beispiel #14
0
    #setup the obsdate--assumes fixed naming scheme
    obsdate = saltstring.makeobsdatestr(infiles, x1=x1, x2=x2)

    #if len(obsdate)<4: obsdate=''

    #set the mode string
    #mdstr=saltstring.makedetmodestr(biaskeys[2])
    detstr = 'B'
    instr = 'H'
    ampstr = 'A2'
    if biaskeys[1] == '08443-03-01':
        detstr = 'R'
        instr = 'R'
        ampstr = 'A4'

    #set binning
    binstr = saltstring.makebinstr(biaskeys[3])

    #set the AMP string

    biasname = '%s%sBias%s%s%s.fits' % (instr, obsdate, detstr, binstr, ampstr)
    return biasname


if not iraf.deftask('hrsclean'):
    parfile = iraf.osfn("salthrs$hrsclean.par")
    t = iraf.IrafTaskFactory(taskname="hrsclean",
                             value=parfile,
                             function=hrsclean,
                             pkgname='salthrs')
Beispiel #15
0
           winsect=saltio.getSection(saltkey.get('AMPSEC', struct[i+6*j]), iraf_format=True)
           y1=(winsect[0]-1)/ybin
           #y2=(winsect[1])/ybin+1
           y2=y1+len(struct[i+6*j].data)

           x1=(winsect[2]-1)/xbin
           x2=len(struct[i+6*j].data[0])
           #x2=(winsect[3])/xbin
         
           extdata[y1:y2,x1:x2]=struct[i+6*j].data
        
           xmax=max(xmax, x2)
           
 
        #add the correct header information *TODO*   
 
        #append to the hdu list
        exthdu=pyfits.ImageHDU(extdata[:,0:xmax])
        outstruct.append(exthdu)


    #return the new extension
    return outstruct

# -----------------------------------------------------------
# main code

if not iraf.deftask('saltembed'):
    parfile = iraf.osfn("saltred$saltembed.par")
    t =  iraf.IrafTaskFactory(taskname="saltembed",value=parfile,function=saltembed, pkgname='saltred')
Beispiel #16
0
   dbspeed, dbrate, dbgain, dbnoise, dbbias, dbamp=dblist

   #checkf or the gain
   if gainset not in dbrate:
       raise SaltError('GAINSET=%s does not match any vaue in gaindb file' % gainset)
   if rospeed not in dbspeed:
       raise SaltError('ROSPEED=%s does not match any vaue in gaindb file' % rospeed)
     
   #loop through the values and find the corresponding gain/rdnoise
   for i in range(len(dbspeed)):
       if dbspeed[i].strip().upper()==rospeed.strip().upper():
           if dbrate[i].strip().upper()==gainset.strip().upper():
               if int(dbamp[i])==int(amp):
                  gain=float(dbgain[i])
                  rdnoise=float(dbnoise[i])
                  found=True
                  return gain, rdnoise

   if not found:
       msg='Could not find a corresponding setting in the gaindb file for gainset=%s, rospeed=%s, amp=%i' \
            % (gainset, rospeed, amp)
       raise SaltError(msg)
                  
   return rdnoise, gain

# -----------------------------------------------------------
# main code
if not iraf.deftask('saltgain'):
   parfile = iraf.osfn("saltred$saltgain.par")
   t = iraf.IrafTaskFactory(taskname="saltgain",value=parfile,function=saltgain, pkgname='saltred')
Beispiel #17
0
    """Convert a SALT MEF file into a single extension fits file"""

    #open the image
    hdu = fits.open(img)

    #if len one, copy and return
    if len(hdu) == 1:
        hdu.writeto(oimg)
        return

    #create the new output image
    odu = fits.PrimaryHDU(data=hdu[ext].data, header=hdu[0].header)

    #combine the headers from the primary and first exention
    for c in hdu[ext].header.cards:
        odu.header.set(c.keyword, c.value, c.comment)

    #write the data out
    saltio.writefits(odu, oimg, clobber=clobber)


# -----------------------------------------------------------
# main code

if not iraf.deftask('salt2iraf'):
    parfile = iraf.osfn("saltred$salt2iraf.par")
    t = iraf.IrafTaskFactory(taskname="salt2iraf",
                             value=parfile,
                             function=salt2iraf,
                             pkgname='saltred')
Beispiel #18
0
    msg += '#filter=%s\n' % rfilter.strip()
    if objid:
        msg += '#slitid=%s\n' % objid
    msg += '#Function=%s\n' % function
    msg += '#Order=%s\n' % order
    if ws.func.func.domain is not None:
        msg += '#domain={},{}\n'.format(ws.func.func.domain[0],
                                        ws.func.func.domain[1])
    msg += '#Starting Data\n'
    dout.write(msg)

    for i in range(len(ws_arr)):
        if ws_arr[i, 0]:
            msg = '%5.2f ' % ws_arr[i, 0]
            msg += ' '.join(['%e' % k for k in ws_arr[i, 1:]])
            dout.write(msg + '\n')
    dout.write('\n')
    dout.close()

    return


# main code

if not iraf.deftask('specidentify'):
    parfile = iraf.osfn("saltspec$specidentify.par")
    t = iraf.IrafTaskFactory(taskname="specidentify",
                             value=parfile,
                             function=specidentify,
                             pkgname='saltspec')
Beispiel #19
0
    # re-interpt the std_spectra over the same wavelength
    std_spectra.interp(obs_spectra.wavelength)

    # re-interp the ext_spetra over the sam ewavelength
    ext_spectra.interp(obs_spectra.wavelength)

    # create the calibration spectra
    cal_spectra = Spectrum.Spectrum(obs_spectra.wavelength, obs_spectra.flux.copy(), stype="continuum")

    # set up the bandpass
    bandpass = np.diff(obs_spectra.wavelength).mean()

    # correct for extinction
    cal_spectra.flux = obs_spectra.flux / 10 ** (-0.4 * airmass * ext_spectra.flux)

    # correct for the exposure time and calculation the calitivity curve
    cal_spectra.flux = cal_spectra.flux / exptime / bandpass / std_spectra.flux

    # correct the error calc
    if error:
        cal_spectra.var = obs_spectra.var * cal_spectra.flux / obs_spectra.flux

    return cal_spectra


# main code
if not iraf.deftask("speccal"):
    parfile = iraf.osfn("saltspec$speccal.par")
    t = iraf.IrafTaskFactory(taskname="speccal", value=parfile, function=speccal, pkgname="saltspec")
Beispiel #20
0
            # for each line in the data, determine the wavelength solution
            # for a given line in the image
            wavemap = np.zeros_like(hdu[i].data)
            for j in range(len(hdu[i].data)):
                # find the wavelength solution for the data
                w_arr = sr.findsol(xarr, soldict, j, caltype, nearest, timeobs,
                                   exptime, instrume, grating, grang, arang,
                                   filtername, slit, xbin, ybin, slitid,
                                   function, order)
                if w_arr is not None: wavemap[j, :] = w_arr
            if array_only: return wavemap

            # write out the oimg
            hduwav = fits.ImageHDU(data=wavemap,
                                   header=hdu[i].header,
                                   name='WAV')
            hdu.append(hduwav)
            saltkey.new('WAVEXT',
                        len(hdu) - 1, 'Extension for Wavelength Map', hdu[i])

    return hdu


if not iraf.deftask('specwavemap'):
    parfile = iraf.osfn("saltspec$specwavemap.par")
    t = iraf.IrafTaskFactory(taskname="specwavemap",
                             value=parfile,
                             function=specwavemap,
                             pkgname='saltspec')
Beispiel #21
0
def findwskeyword(keyword, sol):
    """Find and return a value for a keyword in the list of the wavelength solution"""
    i = sol.index(keyword)
    j = sol[i:].index('\n')
    return sol[i:i + j].split('=')[1].strip()


def enterdatetime(dstr):
    """Break up the datetime string to create a datetime object
       return datetime
    """
    dlist = dstr.split()
    year, month, day = dlist[0].split('-')
    hour, minute, second = dlist[1].split(':')

    return datetime.datetime(
        int(year), int(month), int(day), int(hour), int(minute), int(float(second)))


def subtracttime(d1, d2):
    """Return the difference in two dates in seconds"""
    dt = max(d1, d2) - min(d1, d2)
    return 86400 * dt.days + dt.seconds


# main code
if not iraf.deftask('specrectify'):
    parfile = iraf.osfn("saltspec$specrectify.par")
    t = iraf.IrafTaskFactory(taskname="specrectify", value=parfile, 
                             function=specrectify, pkgname='saltspec')
Beispiel #22
0
                    hdr = filetowrite[num].header
                    if hdr.has_key(keyword) == 1:
                        if clobber:
                            hdr.update(keyword, newTime[num], comment)
                            print 'Keyword ' + keyword + ' has been updated in header extension ' + str(
                                num) + ' to the following value: ' + str(
                                    newTime[num])
                        else:
                            print 'Keyword ' + keyword + ' has not been updated.'
                    else:
                        hdr.update(keyword,
                                   newTime[num],
                                   comment,
                                   after='TIME-OBS')
                        print 'Keyword ' + keyword + ' has been added to header extension ' + str(
                            num) + ' as the following value: ' + str(
                                newTime[num])

                    filetowrite.flush()
                filetowrite.close()


# -----------------------------------------------------------
# end main code
if not iraf.deftask('saltheadtime'):
    parfile = iraf.osfn("saltred$saltheadtime.par")
    t = iraf.IrafTaskFactory(taskname="saltheadtime",
                             value=parfile,
                             function=saltheadtime,
                             pkgname='saltred')
Beispiel #23
0
            x = numpy.arange(xs)
            rdata = data[i, :]
            rmask = mask[i, :]
            rmask = nd.minimum_filter(rmask, size=3)
            if rmask.any() == True:
                rdata = numpy.interp(x, x[rmask], rdata[rmask])
                data[i, rmask == 0] = rdata[rmask == 0]

    return data


def tran_func(a, xshift, yshift, xmag, ymag, xrot, yrot):
    xtran = ymag * a[0] * cos(yrot * pi / 180.0) \
        - xmag * a[1] * sin(xrot * pi / 180) \
        - yshift
    ytran = ymag * a[0] * sin(yrot * pi / 180.0) \
        + xmag * a[1] * cos(xrot * pi / 180) \
        - xshift
    return xtran, ytran


# -----------------------------------------------------------
# main code
if not iraf.deftask('saltmosaic'):
    parfile = iraf.osfn("saltred$saltmosaic.par")
    t = iraf.IrafTaskFactory(
        taskname="saltmosaic",
        value=parfile,
        function=saltmosaic,
        pkgname='saltred')
Beispiel #24
0
            if (status == 0):
                infilename = infile.split('/')
                infilename = infilename[len(infilename) - 1]
                message = '%25s[%3d] %5.2f %4d %8.6f' % \
                    (infilename, hdu, gain1, overlevel_1, float(xcoeff[amplifier+1]))
                saltprint.log(logfile, message, verbose)
                message = '%25s[%3d] %5.2f %4d %8.6f' % \
                    (infilename, hdu+1, gain2, overlevel_2,float(xcoeff[amplifier]))
                saltprint.log(logfile, message, verbose)

# update image in HDU structure

            if (status == 0):
                struct, status = saltio.writeimage(struct, hdu, imagedata1,
                                                   logfile)
                struct, status = saltio.writeimage(struct, hdu + 1, imagedata2,
                                                   logfile)

    return struct, status


# -----------------------------------------------------------
# main code
if not iraf.deftask('saltslot'):
    parfile = iraf.osfn("saltred$saltslot.par")
    t = iraf.IrafTaskFactory(taskname="saltslot",
                             value=parfile,
                             function=saltslot,
                             pkgname='saltred')
Beispiel #25
0
    bpm:  bad pixel mask array

   """
   if bpm is None:
       bpm=arr*0.0+1.0
       wei=None
   else:
       # correct the weights for the bad pixel mask
       if ivar is None: ivar=arr*0.0+1.0
       wei=ivar*(1-bpm)
       #TODO: need to add a check to make sure that there are is a place
       #to make sure that one of the weights is at least zero
       check_wei=wei.sum(axis=0)
       wei[0][check_wei==0]=wei.min()
  
   if method=='average':
       c_arr, s_arr=np.average(arr, axis=0, weights=wei, returned=True)
       return c_arr, s_arr
   elif method=='median':
       return np.median(arr, axis=0), bpm.sum(axis=0)
   else: 
       msg='%s is not a method for combining arrays' % method
       raise SaltError(msg)

# -----------------------------------------------------------
# main code 
if not iraf.deftask('saltcombine'):
   parfile = iraf.osfn("saltred$saltcombine.par") 
   t = iraf.IrafTaskFactory(taskname="saltcombine",value=parfile,function=saltcombine, pkgname='saltred')
Beispiel #26
0
    """flat applies a flatfield to salt CCD data

       return  struct
    """
    # Determine the number of extensions
    nextend=len(struct)

    #flat field the data
    for i in range(nextend):
       if struct[i].name=='SCI' or len(struct)==1:
            #Account for variance frames 
            if saltkey.found('VAREXT', struct[i]):
               varext=saltkey.get('VAREXT', struct[i])
               if saltkey.found('VAREXT', fstruct[i]):
                   fvarext=saltkey.get('VAREXT', fstruct[i])
                   fvar=fstruct[fvarext].data
               else:
                   fvar=0
               struct[varext].data=(struct[i].data/fstruct[i].data)*(struct[varext].data/struct[i].data**2+fvar/fstruct[i].data**2)

            #flatten the data
            struct[i].data = struct[i].data / fstruct[i].data

    return struct

# -----------------------------------------------------------
# main code
if not iraf.deftask('saltflat'):
   parfile = iraf.osfn("saltred$saltflat.par")
   t = iraf.IrafTaskFactory(taskname="saltflat",value=parfile,function=saltflat, pkgname='saltred')
Beispiel #27
0
                vhdu1 = saltkey.get('VAREXT', struct[i])
                vhdu2 = saltkey.get('VAREXT', struct[i + 1])
                try:
                    struct[vhdu1].data += xc2 * struct[vhdu2].data
                    struct[vhdu2].data += xc1 * struct[vhdu1].data
                except Exception, e:
                    msg = 'Cannot update the variance frame in %s[%i] because %s' % (
                        infile, vhdu1, e)
                    raise SaltError(msg)

            #print the message
            if log:
                message = '%25s[%1d]  Amp%1d - Amp%1d * %8.6f' % \
                         (infile, i, ext1, ext2, xc2)
                log.message(message, with_header=False, with_stdout=verbose)
                message = '%25s[%1d]  Amp%1d - Amp%1d * %8.6f' % \
                         (infile, i+1, ext2, ext1, xc1)
                log.message(message, with_header=False, with_stdout=verbose)

    return struct


# -----------------------------------------------------------
# main code
if not iraf.deftask('saltxtalk'):
    parfile = iraf.osfn("saltred$saltxtalk.par")
    t = iraf.IrafTaskFactory(taskname="saltxtalk",
                             value=parfile,
                             function=saltxtalk,
                             pkgname='saltred')
Beispiel #28
0
    # left over by intersting way to call it: ORDER BY pr.Proposal_ID DESC" % pid
    record=saltmysql.select(sdb,state_select,state_from,state_logic)

    if len(record)<1:
       message = pid + ' is not in the Science database'
       raise SaltError(message)
    elif len(record)==1:
       surname=[record[0][2]]
       email=[record[0][3]]
       propinfo[pid]=(surname,email)
    else:
       prop_id=-1
       surname=[]
       email=[]
       for entry in record:
           if entry[0] > prop_id:
               prop_id=entry[0]
               prop_code=entry[1]
               surname.append(entry[2])
               email.append(entry[3])
       propinfo[pid]=(surname,email)

    return propinfo

# -----------------------------------------------------------
# main code

if not iraf.deftask('saltemail'):
  parfile = iraf.osfn("pipetools$saltemail.par")
  t = iraf.IrafTaskFactory(taskname="saltemail",value=parfile,function=saltemail, pkgname='pipetools')
Beispiel #29
0
# -----------------------------------------------------------
# check to see if a given fits file is one to be edited

def checkfitsfile(infile, frange, klist):

    #make sure the file exists
    if not os.path.isfile(infile): return False
 
    #expeand klist
    finstr, fstart, fstop, keyitems=klist

    #check that the file is of the right instrument and date
    if not infile.count(finstr): return False

    #check that the files are in the appropriate range
    try:
       nid=saltstring.filenumber(infile, -9, -5)
    except Exception, e:
       return False
    if fstart <= nid <= fstop: return True
    return False



# -----------------------------------------------------------
# main code
if not iraf.deftask('salteditkey'):
  parfile = iraf.osfn("pipetools$salteditkey.par")
  t = iraf.IrafTaskFactory(taskname="salteditkey",value=parfile,function=salteditkey, pkgname='pipetools')
Beispiel #30
0
           except SaltError, e:
               log.message('%s' % e)

def convertsalt(img, oimg, ext=1, clobber=True):
   """Convert a SALT MEF file into a single extension fits file"""

   #open the image
   hdu=fits.open(img)

   #if len one, copy and return
   if len(hdu)==1:  
      hdu.writeto(oimg)
      return

   #create the new output image
   odu = fits.PrimaryHDU(data=hdu[ext].data, header=hdu[0].header)

   #combine the headers from the primary and first exention
   for c in hdu[ext].header.cards: 
       odu.header.set(c.keyword, c.value, c.comment)

   #write the data out
   saltio.writefits(odu, oimg, clobber=clobber)

# -----------------------------------------------------------
# main code

if not iraf.deftask('salt2iraf'):
   parfile = iraf.osfn("saltred$salt2iraf.par")
   t = iraf.IrafTaskFactory(taskname="salt2iraf",value=parfile,function=salt2iraf, pkgname='saltred')
Beispiel #31
0
                 message += ' using header file  '+inhead
                 saltprint.log(logfile,message,verbose)
            except:
                message = 'SALTBIN2FIT ERROR: Unable to create '+fitsimg+' from '+binimg
                message += ' using header file  '+inhead
                saltprint.log(logfile,message,verbose)



# end time

    if (status == 0):
        saltprint.log(logfile,' ',verbose)
        saltprint.time('SALTBIN2FIT completed at',logfile,verbose)
    else:
        saltprint.time('SALTBIN2FIT aborted at  ',logfile,verbose)

def findimagenumber (filename):
    """find the number for each image file"""
    #split the file so that name is a string equal to OBSDATE+number
    name=filename.split('/')[-1].split('.')[0]
    return int(name[9:])


# -----------------------------------------------------------
# main code

if not iraf.deftask('saltbin2fit'):
  parfile = iraf.osfn("pipetools$saltbin2fit.par")
  t = iraf.IrafTaskFactory(taskname="saltbin2fit",value=parfile,function=saltbin2fit, pkgname='pipetools')
Beispiel #32
0
   else: 
       default=-999
   return default

def getkey(struct,keyword,default,warn=True, log=None):
   """Return the keyword value.  Throw a warning if it doesn't work """

   try:
        value = saltkey.get(keyword, struct)
        if isinstance(default, str):  value=value.strip()
   except SaltIOError:
        value = default
        infile=struct._file.name
        message = 'WARNING: cannot find keyword %s in %s' %(keyword, infile)
        if warn and log: log.message(message, with_header=False)
   if (str(value).strip() == ''): value = default
   #if (type(value) != type(default)):
   #     infile=struct._file.name
   #     message='WARNING: Type mismatch for %s for  %s in %s[0]' % (str(value), keyword, infile)
   #     if warn and log: log.message(message, with_header=False)
   #     value=default

   return value


# -----------------------------------------------------------
# main code
if not iraf.deftask('saltobslog'):
   parfile = iraf.osfn("saltred$saltobslog.par")
   t = iraf.IrafTaskFactory(taskname="saltobslog",value=parfile,function=saltobslog, pkgname='saltred')
Beispiel #33
0
    """Apply an illumination correction to a set of images

       return  struct
    """
    # Determine the number of extensions
    nextend = len(struct)

    # flat field the data
    for i in range(nextend):
        if struct[i].name == "SCI" or len(struct) == 1:

            # create the median image
            mdata = median_filter(struct[i].data, size=(mbox, mbox))

            # create the data
            struct[i].data = struct[i].data / mdata

            # Account for variance frames
            if saltkey.found("VAREXT", struct[i]):
                varext = saltkey.get("VAREXT", struct[i])
                struct[varext].data = struct[varext].data / mdata

    return struct


# -----------------------------------------------------------
# main code
if not iraf.deftask("saltillum"):
    parfile = iraf.osfn("saltred$saltillum.par")
    t = iraf.IrafTaskFactory(taskname="saltillum", value=parfile, function=saltillum, pkgname="saltred")
Beispiel #34
0
   
   #re-interpt the std_spectra over the same wavelength
   std_spectra.interp(obs_spectra.wavelength)

   #re-interp the ext_spetra over the sam ewavelength
   ext_spectra.interp(obs_spectra.wavelength)

   #create the calibration spectra
   cal_spectra=Spectrum.Spectrum(obs_spectra.wavelength, obs_spectra.flux.copy(), stype='continuum')

   #set up the bandpass
   bandpass=np.diff(obs_spectra.wavelength).mean()

   #correct for extinction
   cal_spectra.flux=obs_spectra.flux/10**(-0.4*airmass*ext_spectra.flux)

   #correct for the exposure time and calculation the calitivity curve
   cal_spectra.flux=cal_spectra.flux/exptime/bandpass/std_spectra.flux

   #correct the error calc
   if error:
      cal_spectra.sigma=obs_spectra.sigma*cal_spectra.flux/obs_spectra.flux

   return cal_spectra


# main code 
if not iraf.deftask('speccal'):
   parfile = iraf.osfn("saltspec$speccal.par") 
   t = iraf.IrafTaskFactory(taskname="speccal",value=parfile,function=speccal, pkgname='saltspec')
Beispiel #35
0
            if subbias and bstruct:
                struct[i].data -= bstruct[i].data

                #update the variance frame
                if saltkey.found('VAREXT', struct[i]):
                    vhdu = saltkey.get('VAREXT', struct[i])
                    try:
                        vdata = struct[vhdu].data
                        struct[vhdu].data = vdata + bstruct[vhdu].data
                    except Exception, e:
                        msg = 'Cannot update the variance frame in %s[%i] because %s' % (
                            infile, vhdu, e)
                        raise SaltError(msg)

    if plotover:
        plt.ioff()
        plt.show()

    return struct


# -----------------------------------------------------------
# main code

if not iraf.deftask('saltbias'):
    parfile = iraf.osfn("saltred$saltbias.par")
    t = iraf.IrafTaskFactory(taskname="saltbias",
                             value=parfile,
                             function=saltbias,
                             pkgname='saltred')
Beispiel #36
0
                j,
                :],
            xarr,
            nws,
            blank=blank,
            inttype=inttype)
    return data


def zeroshift(data, xarr, nws, blank=0, inttype='interp'):
    """Calculate zeropoint shift and apply to the data
    """
    if nws is not None:
        w_arr = nws.value(xarr)
        data = st.interpolate(
            xarr,
            w_arr,
            data,
            inttype,
            left=blank,
            right=blank)
    return data

if not iraf.deftask('specselfid'):
    parfile = iraf.osfn("saltspec$specselfid.par")
    t = iraf.IrafTaskFactory(
        taskname="specselfid",
        value=parfile,
        function=specselfid,
        pkgname='saltspec')
Beispiel #37
0
def crgrow(crarr, grad=3):
   """If a cosmic ray has been identified in the source, delete the pixels around
      it according to gradius.  
   """

   darr=np.where(crarr>0)
   xlen=len(crarr[0])
   ylen=len(crarr)

   #set it up as a box
   if grad < 3: grad=3
   mbox=int(grad/2)

   for i in range(len(darr[0])):
        y=darr[0][i]
        x=darr[1][i]
        x1, x2, y1, y2 = setbox(x, y, mbox, xlen, ylen)
        crarr[y1:y2,x1:x2]=crarr[y,x]

   return crarr

#-----------------------------------------------------------
# Function to calculate the sigma at each pixel


# -----------------------------------------------------------
# main code
if not iraf.deftask('saltcrclean'):
   parfile = iraf.osfn("saltred$saltcrclean.par")
   t = iraf.IrafTaskFactory(taskname="saltcrclean",value=parfile,function=saltcrclean, pkgname='saltred')
Beispiel #38
0
                y2 = y2
                x2 = x2
            else:
                y1 = 0
                x1 = x2
                x2 = x1 + x2
        elif detector == 'hrdet':
            y1 = 0
            if i % 2 == 1: x1 = 0
            if i % 2 == 0:
                x1 = x2
                x2 = x1 + x2
            if i > 2:
                y1 = y2
                y2 = y1 + y2

        data[y1:y2, x1:x2] = hdu[i].data

    ihdu = pyfits.ImageHDU(data)
    nhdu = pyfits.HDUList([hdu[0], ihdu])

    return nhdu


if not iraf.deftask('hrsstack'):
    parfile = iraf.osfn("salthrs$hrsstack.par")
    t = iraf.IrafTaskFactory(taskname="hrsstack",
                             value=parfile,
                             function=hrsstack,
                             pkgname='salthrs')
Beispiel #39
0
        #correct the variance frame
        if saltkey.found('VAREXT', struct[i]):
           vhdu1=saltkey.get('VAREXT', struct[i])
           vhdu2=saltkey.get('VAREXT', struct[i+1])
           try:
               struct[vhdu1].data+=xc2*struct[vhdu2].data
               struct[vhdu2].data+=xc1*struct[vhdu1].data
           except Exception, e:
               msg='Cannot update the variance frame in %s[%i] because %s' % (infile, vhdu1, e)
               raise SaltError(msg)


        #print the message
        if log:
           message = '%25s[%1d]  Amp%1d - Amp%1d * %8.6f' % \
                    (infile, i, ext1, ext2, xc2)
           log.message(message, with_header=False, with_stdout=verbose)
           message = '%25s[%1d]  Amp%1d - Amp%1d * %8.6f' % \
                    (infile, i+1, ext2, ext1, xc1)
           log.message(message, with_header=False, with_stdout=verbose)


    return struct

# -----------------------------------------------------------
# main code
if not iraf.deftask('saltxtalk'):
   parfile = iraf.osfn("saltred$saltxtalk.par")
   t = iraf.IrafTaskFactory(taskname="saltxtalk",value=parfile,function=saltxtalk, pkgname='saltred')
Beispiel #40
0
# open diagnostic log html file

    if (status == 0):
        saltprint.log(logfile,'SALTHTML -- creating InstrumentDiagnostics' + date + '.html',verbose)
        outfile, status = saltio.openascii(dlogfile,'w',logfile)

# write html header

    if (status == 0): status = htmlheader(outfile,date,caldate,'InstrumentDiagnostics',0,logfile)

# content pending

    outfile.write('Content pending\n')

# write html footer

    if (status == 0): status = htmlfooter(outfile,logfile)

# close htmlfile

    if (status == 0): status = saltio.closeascii(outfile,logfile)

    return status

# -----------------------------------------------------------
# main code

if not iraf.deftask('salthtml'):
  parfile = iraf.osfn("pipetools$salthtml.par")
  t = iraf.IrafTaskFactory(taskname="salthtml",value=parfile,function=salthtml, pkgname='pipetools')
Beispiel #41
0
   # Determine the number of extensions
   nextend=len(struct)

   #do the math
   for i in range(nextend):
      if struct[i].name!='PRIMARY' or len(struct)==1:
         #screw variance frames. Pay me more
         #actually do the math
         if is_image: 
            struct[i].data = eval('struct[i].data'+str(op)+'opstruct[i].data')
            
            if op == '/':
               #find where division by zero is going to happen
               zidx = numpy.where(opstruct[i].data == 0)
               struct[i].data[zidx] = divzero

         else: 
            struct[i].data = eval('struct[i].data'+str(op)+'opstruct')
            
            if op == '/' and opstruct == 0:
               struct[i].data = numpy.ones(struct[i].data.shape)*divzero

   return struct
            
# -----------------------------------------------------------
# main code

if not iraf.deftask('saltarith'):
   parfile = iraf.osfn("saltred$saltarith.par")
   t = iraf.IrafTaskFactory(taskname="saltarith",value=parfile,function=saltarith, pkgname='saltred')
Beispiel #42
0
   else:
       try:
           infile=inhdu._HDUList__file.name
           bpfile=bphdu._HDUList__file.name
       except:
           infile=inhdu.filename
           bpfile=bphdu.filename
    
       
       if not saltkey.compare(inhdu[0], bphdu[0], 'INSTRUME', infile, bpfile):
           message = '%s and %s are not the same %s' % (infile,bpfile, 'INSTRUME')
           raise SaltError(message)
       for k in ['CCDSUM', 'NAXIS1', 'NAXIS2']:
           if not saltkey.compare(inhdu[sci_ext], bphdu[sci_ext], k, infile, bpfile):
                  message = '%s and %s are not the same %s' % (infile,bpfile, k)
                  raise SaltError(message)
       data=bphdu[sci_ext].data.copy()

   header=inhdu[sci_ext].header.copy()
   header['EXTVER']=bp_ext
   header['SCIEXT']=(sci_ext,'Extension of science frame')
   return fits.ImageHDU(data=data, header=header, name='BPM')



# -----------------------------------------------------------
# main code
if not iraf.deftask('saltprepare'):
   parfile = iraf.osfn("saltred$saltprepare.par")
   t = iraf.IrafTaskFactory(taskname="saltprepare",value=parfile,function=saltprepare, pkgname='saltred')
Beispiel #43
0
                    timeobs,
                    exptime,
                    instrume,
                    grating,
                    grang,
                    arang,
                    filtername,
                    slit,
                    xbin,
                    ybin,
                    slitid,
                    function,
                    order,
                )
                if w_arr is not None:
                    wavemap[j, :] = w_arr
            if array_only:
                return wavemap

            # write out the oimg
            hduwav = fits.ImageHDU(data=wavemap, header=hdu[i].header, name="WAV")
            hdu.append(hduwav)
            saltkey.new("WAVEXT", len(hdu) - 1, "Extension for Wavelength Map", hdu[i])

    return hdu


if not iraf.deftask("specwavemap"):
    parfile = iraf.osfn("saltspec$specwavemap.par")
    t = iraf.IrafTaskFactory(taskname="specwavemap", value=parfile, function=specwavemap, pkgname="saltspec")
Beispiel #44
0
        if struct[i].name != 'PRIMARY' or len(struct) == 1:
            #screw variance frames. Pay me more
            #actually do the math
            if is_image:
                struct[i].data = eval('struct[i].data' + str(op) +
                                      'opstruct[i].data')

                if op == '/':
                    #find where division by zero is going to happen
                    zidx = numpy.where(opstruct[i].data == 0)
                    struct[i].data[zidx] = divzero

            else:
                struct[i].data = eval('struct[i].data' + str(op) + 'opstruct')

                if op == '/' and opstruct == 0:
                    struct[i].data = numpy.ones(struct[i].data.shape) * divzero

    return struct


# -----------------------------------------------------------
# main code

if not iraf.deftask('saltarith'):
    parfile = iraf.osfn("saltred$saltarith.par")
    t = iraf.IrafTaskFactory(taskname="saltarith",
                             value=parfile,
                             function=saltarith,
                             pkgname='saltred')
Beispiel #45
0
def findwskeyword(keyword, sol):
    """Find and return a value for a keyword in the list of the wavelength solution"""
    i = sol.index(keyword)
    j = sol[i:].index('\n')
    return sol[i:i + j].split('=')[1].strip()


def enterdatetime(dstr):
    """Break up the datetime string to create a datetime object
       return datetime
    """
    dlist = dstr.split()
    year, month, day = dlist[0].split('-')
    hour, minute, second = dlist[1].split(':')

    return datetime.datetime(
        int(year), int(month), int(day), int(hour), int(minute), int(float(second)))


def subtracttime(d1, d2):
    """Return the difference in two dates in seconds"""
    dt = max(d1, d2) - min(d1, d2)
    return 86400 * dt.days + dt.seconds


# main code
if not iraf.deftask('specrectify'):
    parfile = iraf.osfn("saltspec$specrectify.par")
    t = iraf.IrafTaskFactory(taskname="specrectify", value=parfile, 
                             function=specrectify, pkgname='saltspec')
Beispiel #46
0
                            == 0) * (struct[i].data > minlevel)
            else:
                mask_arr = (struct[i].data < minlevel)

            #create the data
            coef = fit_surface(struct[i].data,
                               mask=mask_arr,
                               xorder=order,
                               yorder=order,
                               xyorder=0)
            y, x = np.indices(struct[i].data.shape)
            sf = surface(coef, xorder=order, yorder=order, xyorder=0)
            print coef
            struct[i].data = sf(x, y)

            #Account for variance frames
            if mask:
                struct[bpmext].data = struct[bpmext].data * 0

    return struct


# -----------------------------------------------------------
# main code
if not iraf.deftask('saltsurface'):
    parfile = iraf.osfn("saltred$saltsurface.par")
    t = iraf.IrafTaskFactory(taskname="saltsurface",
                             value=parfile,
                             function=saltsurface,
                             pkgname='saltred')
Beispiel #47
0
              x1=0
              y2=y2
              x2=x2
           else:
              y1=0
              x1=x2
              x2=x1+x2
        elif detector=='hrdet':
           y1=0
           if i%2==1: x1=0
           if i%2==0: 
              x1=x2
              x2=x1+x2
           if i>2:
              y1=y2
              y2=y1+y2 
              
              
        data[y1:y2,x1:x2]=hdu[i].data
    
    ihdu = pyfits.ImageHDU(data)
    nhdu = pyfits.HDUList([hdu[0], ihdu])

    return nhdu


if not iraf.deftask('hrsstack'):
    parfile = iraf.osfn("salthrs$hrsstack.par")
    t = iraf.IrafTaskFactory(taskname="hrsstack",value=parfile,function=hrsstack, pkgname='salthrs')

Beispiel #48
0
    if rospeed not in dbspeed:
        raise SaltError('ROSPEED=%s does not match any vaue in gaindb file' %
                        rospeed)

    #loop through the values and find the corresponding gain/rdnoise
    for i in range(len(dbspeed)):
        if dbspeed[i].strip().upper() == rospeed.strip().upper():
            if dbrate[i].strip().upper() == gainset.strip().upper():
                if int(dbamp[i]) == int(amp):
                    gain = float(dbgain[i])
                    rdnoise = float(dbnoise[i])
                    found = True
                    return gain, rdnoise

    if not found:
        msg='Could not find a corresponding setting in the gaindb file for gainset=%s, rospeed=%s, amp=%i' \
             % (gainset, rospeed, amp)
        raise SaltError(msg)

    return rdnoise, gain


# -----------------------------------------------------------
# main code
if not iraf.deftask('saltgain'):
    parfile = iraf.osfn("saltred$saltgain.par")
    t = iraf.IrafTaskFactory(taskname="saltgain",
                             value=parfile,
                             function=saltgain,
                             pkgname='saltred')
Beispiel #49
0
def createbadpixel(inhdu, bphdu, sci_ext, bp_ext):
   """Create the bad pixel hdu from a bad pixel hdu"""
   if bphdu is None:
       data=inhdu[sci_ext].data*0.0
   else:
       infile=inhdu._HDUList__file.name
       bpfile=bphdu._HDUList__file.name
       
       if not saltkey.compare(inhdu[0], bphdu[0], 'INSTRUME', infile, bpfile):
           message = '%s and %s are not the same %s' % (infile,bpfile, 'INSTRUME')
           raise SaltError(message)
       for k in ['CCDSUM', 'NAXIS1', 'NAXIS2']:
           if not saltkey.compare(inhdu[sci_ext], bphdu[sci_ext], k, infile, bpfile):
                  message = '%s and %s are not the same %s' % (infile,bpfile, k)
                  raise SaltError(message)
       data=bphdu[sci_ext].data.copy()

   header=inhdu[sci_ext].header.copy()
   header['EXTVER']=bp_ext
   header.update('SCIEXT',sci_ext,comment='Extension of science frame')
   return pyfits.ImageHDU(data=data, header=header, name='BPM')



# -----------------------------------------------------------
# main code
if not iraf.deftask('saltprepare'):
   parfile = iraf.osfn("saltred$saltprepare.par")
   t = iraf.IrafTaskFactory(taskname="saltprepare",value=parfile,function=saltprepare, pkgname='saltred')
Beispiel #50
0
    if bpm is None:
        bpm = arr * 0.0 + 1.0
        wei = None
    else:
        # correct the weights for the bad pixel mask
        if ivar is None: ivar = arr * 0.0 + 1.0
        wei = ivar * (1 - bpm)
        #TODO: need to add a check to make sure that there are is a place
        #to make sure that one of the weights is at least zero
        check_wei = wei.sum(axis=0)
        wei[0][check_wei == 0] = wei.min()

    if method == 'average':
        c_arr, s_arr = np.average(arr, axis=0, weights=wei, returned=True)
        return c_arr, s_arr
    elif method == 'median':
        return np.median(arr, axis=0), bpm.sum(axis=0)
    else:
        msg = '%s is not a method for combining arrays' % method
        raise SaltError(msg)


# -----------------------------------------------------------
# main code
if not iraf.deftask('saltcombine'):
    parfile = iraf.osfn("saltred$saltcombine.par")
    t = iraf.IrafTaskFactory(taskname="saltcombine",
                             value=parfile,
                             function=saltcombine,
                             pkgname='saltred')
Beispiel #51
0
               saltkey.put('DATASEC',datasec,struct[bhdu])

       #subtract the master bias if necessary
       if subbias and bstruct:
           struct[i].data -= bstruct[i].data

           #update the variance frame
           if saltkey.found('VAREXT', struct[i]):
               vhdu=saltkey.get('VAREXT', struct[i])
               try:
                   vdata=struct[vhdu].data
                   struct[vhdu].data=vdata+bstruct[vhdu].data
               except Exception, e:
                    msg='Cannot update the variance frame in %s[%i] because %s' % (infile, vhdu, e)
                    raise SaltError(msg)
 
       

   if plotover: 
       plt.ioff()
       plt.show()

   return struct

# -----------------------------------------------------------
# main code

if not iraf.deftask('saltbias'):
  parfile = iraf.osfn("saltred$saltbias.par")
  t = iraf.IrafTaskFactory(taskname="saltbias",value=parfile,function=saltbias, pkgname='saltred')
Beispiel #52
0
    cal_spectra = Spectrum.Spectrum(
        obs_spectra.wavelength,
        obs_spectra.flux.copy(),
        stype='continuum')

    # set up the bandpass
    bandpass = np.diff(obs_spectra.wavelength).mean()

    # correct for extinction
    cal_spectra.flux = obs_spectra.flux / \
        10 ** (-0.4 * airmass * ext_spectra.flux)

    # correct for the exposure time and calculation the calitivity curve
    cal_spectra.flux = cal_spectra.flux / exptime / bandpass / std_spectra.flux

    # correct the error calc
    if error:
        cal_spectra.var = obs_spectra.var * cal_spectra.flux / obs_spectra.flux

    return cal_spectra


# main code
if not iraf.deftask('speccal'):
    parfile = iraf.osfn("saltspec$speccal.par")
    t = iraf.IrafTaskFactory(
        taskname="speccal",
        value=parfile,
        function=speccal,
        pkgname='saltspec')