Exemple #1
0
def make_calring(hdu, method=None, thresh=5, niter=3, conv=0.05, minsize=10, axc=None, ayc=None):
    """Open each image and measure the position of the ring including its center and radius
     
      Return the information about the calibration ring
   """

    # setup the data
    data = hdu[0].data
    # extract the time and convert to decimal hours
    utctime = saltkey.get("UTC-OBS", hdu[0])
    utctime = salttime.time_obs2hr((utctime.split()[-1]))

    # determine the correct etalon and information to extract
    etstate = saltkey.get("ET-STATE", hdu[0])

    if etstate.count("S2"):
        etz = saltkey.get("ET1Z", hdu[0])
    elif etstate.count("S3"):
        etz = saltkey.get("ET2Z", hdu[0])
    else:
        msg = "This etalon state is not currently supported"
        raise SaltError(msg)

    # extract the ring
    ring_list = findrings(data, thresh=thresh, niter=niter, minsize=minsize, axc=axc, ayc=ayc)

    # assumes only one ring in the data set
    ring = ring_list[0]

    # determine the center and radius of the ring
    if method is not None:
        ring = findcenter(data, ring, method, niter=niter, conv=conv)

    if axc:
        ring.xc = axc
    if ayc:
        ring.yc = ayc

    return ring.xc, ring.yc, ring.prad, ring.prad_err, etz, utctime
Exemple #2
0
def salthtml(propcode,scamobslog,rssobslog, hrsobslog, htmlpath,nightlog,readme,clobber,logfile,verbose):

# set up
   
    filenames = []
    proposers = []
    propids = []
    instrumes = []
    objects = []
    ras = []
    decs = []
    detmodes = []
    ccdtypes = []
    ccdsums = []
    gainsets = []
    rospeeds = []
    filters = []
    gratings = []
    gr_angles = []
    ar_angles = []
    time_obss = []
    date_obss = []
    exptimes = []
    hours = []
    filename = {}
    proposer = {}
    propid = {}
    instrume = {}
    object = {}
    ra = {}
    dec = {}
    detmode = {}
    ccdsum = {}
    ccdtype = {}
    gainset = {}
    rospeed = {}
    filter = {}
    grating = {}
    gr_angle = {}
    ar_angle = {}
    time_obs = {}
    exptime = {}
    status=0

# test the logfile

    logfile = saltio.logname(logfile)

# log the call

    saltprint.line(logfile,verbose)
    history = 'SALTHTML -- '
    history += 'scamobslog='+scamobslog+' '
    history += 'rssobslog='+rssobslog+' '
    history += 'htmlpath='+htmlpath+' '
    history += 'nightlog='+nightlog+' '
    history += 'readme='+readme+' '
    yn = 'n'
    if (clobber): yn = 'y'
    history += 'clobber='+yn+' '
    history += 'logfile='+logfile+' '
    yn = 'n'
    if (verbose): yn = 'y'
    history += 'verbose='+yn
    saltprint.log(logfile,history,verbose)

# start time

    saltprint.time('\nSALTHTML -- started at',logfile,verbose)
    saltprint.log(logfile,' ',verbose)

# are the arguments defined

    if (status == 0): pids,status = saltio.argunpack('propcode',propcode ,logfile)
    if (status == 0): status = saltio.argdefined('scamobslog',scamobslog,logfile)
    if (status == 0): status = saltio.argdefined('rssobslog',rssobslog,logfile)
    if (status == 0): status = saltio.argdefined('htmlpath',htmlpath,logfile)



# check htmlpath exists, ends with a "/" and convert to absolute path

    if (status == 0): htmlpath, status = saltio.abspath(htmlpath,logfile)

# check observation log files exist

    if (status == 0 and scamobslog.upper() != 'NONE'): status = saltio.fileexists(scamobslog,logfile)
    if (status == 0 and rssobslog.upper() != 'NONE'): status = saltio.fileexists(rssobslog,logfile)

# read observation logs

    for obslog in [scamobslog, rssobslog, hrsobslog]:
        if (status == 0 and obslog.upper() != 'NONE'): struct,status = saltio.openfits(obslog,logfile)
        if (status == 0 and obslog.upper() != 'NONE'): obstab,status = saltio.readtab(struct[1],obslog,logfile)
        if (status == 0 and obslog.upper() != 'NONE'): status = saltio.closefits(struct,logfile)
        if (status == 0 and obslog.upper() != 'NONE'):
            filenames.extend(obstab.field('filename'))
            objects.extend(obstab.field('object'))
            ras.extend(obstab.field('ra'))
            decs.extend(obstab.field('dec'))
            instrumes.extend(obstab.field('instrume'))
            proposers.extend(obstab.field('proposer'))
            propids.extend(obstab.field('propid'))
            ccdtypes.extend(obstab.field('ccdtype'))
            ccdsums.extend(obstab.field('ccdsum'))
            gainsets.extend(obstab.field('gainset'))
            rospeeds.extend(obstab.field('rospeed'))
            detmodes.extend(obstab.field('detmode'))
            filters.extend(obstab.field('filter'))
            time_obss.extend(obstab.field('time-obs'))
            date_obss.extend(obstab.field('date-obs'))
            exptimes.extend(obstab.field('exptime'))
            if (obslog == rssobslog):
                gratings.extend(obstab.field('grating'))
                gr_angles.extend(obstab.field('gr-angle'))
                ar_angles.extend(obstab.field('ar-angle'))
            else:
                for i in range(len(filenames)):
                    gratings.append(' ')
                    gr_angles.append(0.)
                    ar_angles.append(0.)


# Create the list of proposals

    if (status == 0): pids,status=saltio.cleanpropcode(pids, propids, logfile)


# date of observations
    
    date, caldate = salttime.date_obs2yyyymmdd(date_obss[0])

# sort into chronological order

    for i in range(len(filenames)):
        hours.append(salttime.time_obs2hr(time_obss[i]))
        if (hours[i] < 12.): hours[i] += 24
        filename[str(hours[i])] = filenames[i]
        object[str(hours[i])] = objects[i]
        ra[str(hours[i])] = ras[i]
        dec[str(hours[i])] = decs[i]
        instrume[str(hours[i])] = instrumes[i]
        proposer[str(hours[i])] = proposers[i]
        propid[str(hours[i])] = propids[i]
        ccdsum[str(hours[i])] = ccdsums[i].replace(' ','x')
        ccdtype[str(hours[i])] = ccdtypes[i]
        gainset[str(hours[i])] = gainsets[i]
        rospeed[str(hours[i])] = rospeeds[i]
        detmode[str(hours[i])] = detmodes[i]
        filter[str(hours[i])] = filters[i]
        time_obs[str(hours[i])] = time_obss[i]
        grating[str(hours[i])] = gratings[i]
        gr_angle[str(hours[i])] = gr_angles[i]
        ar_angle[str(hours[i])] = ar_angles[i]
        exptime[str(hours[i])] = exptimes[i]
        if (instrume[str(hours[i])] == 'SALTICAM'): instrume[str(hours[i])] = 'SCM'
        if ('Video Mode' in detmode[str(hours[i])]): detmode[str(hours[i])] = 'VI'
        if ('Slot Mode' in detmode[str(hours[i])]): detmode[str(hours[i])] = 'SL'
        if ('Frame Transfer' in detmode[str(hours[i])]): detmode[str(hours[i])] = 'FT'
        if ('Normal' in detmode[str(hours[i])]): detmode[str(hours[i])] = 'IM'
        if ('Bright' in gainset[str(hours[i])]): gainset[str(hours[i])] = 'BR'
        if ('Faint' in gainset[str(hours[i])]): gainset[str(hours[i])] = 'FA'
        if ('Fast' in rospeed[str(hours[i])]): rospeed[str(hours[i])] = 'FA'
        if ('Slow' in rospeed[str(hours[i])]): rospeed[str(hours[i])] = 'SL'
        if ('OBJECT' not in ccdtype[str(hours[i])].upper() and
            'UNKNOWN' in proposer[str(hours[i])].upper()):
            proposer[str(hours[i])] = ''
    hours.sort()

# create HTML directory in datapath and define html files

    docpath = htmlpath + 'doc/'
    if (status == 0 and not os.path.exists(docpath)): status = saltio.createdir(docpath,False,logfile)

    htmlfile = docpath + 'ObservationSequence' + date +'.html'
    notefile = docpath + 'CapeTownNotes' + date + '.html'
    nlogfile = docpath + 'AstronomersLog' + date + '.html'
    plogfile = docpath + 'PipelineLog' + date + '.html'
    elogfile = docpath + 'EnvironmentLog' + date + '.html'
    dlogfile = docpath + 'InstrumentDiagnostics' + date + '.html'

# Copy css and banner images to the doc directory
    if (status == 0):
        status=saltio.copy(iraf.osfn('pipetools$html/style.css'),docpath,False,logfile)
        status=saltio.copy(iraf.osfn('pipetools$html/style_home.css'),docpath,False,logfile)
        status=saltio.copy(iraf.osfn('pipetools$html/header_salt.jpg'),docpath,False,logfile)


# write observation log html file

    if (status == 0):
        status = writeobslog(htmlfile,filename,object,ra,dec,instrume,detmode,filter,ccdsum,
                             gainset,rospeed,grating,gr_angle,ar_angle,exptime,time_obs,proposer,
                             propid,hours,date,caldate,clobber,logfile,verbose,status)

# write readme html file

    if (status == 0):
        status = writecapetownnotes(notefile,readme,date,caldate,clobber,logfile,verbose,status)

# write nightlog html file

    if (status == 0):
        status = writenightlog(nlogfile,nightlog,date,caldate,clobber,logfile,verbose,status)

# write pipeline log html file

    if (status == 0):
        status = writepipelog(plogfile,date,caldate,clobber,logfile,verbose,status)

# write environment log html file

    if (status == 0):
        status = writeenvlog(elogfile,date,caldate,clobber,logfile,verbose,status)

# write instrument diagnostics html file

    if (status == 0):
        status = writediaglog(dlogfile,date,caldate,clobber,logfile,verbose,status)

# copy html files to PI directories

    if (status == 0):
        saltprint.log(logfile,' ',verbose)
        for pids in set(propids):
            for pid in pids.split(','):
                pid = pid.strip().upper()
                pidpath = htmlpath + pid
                if (os.path.exists(pidpath)):
                    if (os.path.exists(pidpath+'/doc')):
                        for file in glob.glob(pidpath+'/doc/*'):
                            status = saltio.delete(file,False,logfile)
                        status = saltio.deletedir(pidpath+'/doc',logfile)
                    status = saltio.copydir(docpath,pidpath+'/doc',verbose,logfile)
                    if (status == 0):
                        infile, status = saltio.openascii(pidpath+'/doc/CapeTownNotes'+date+'.html','r',logfile)
                    if (status == 0): saltio.delete(pidpath+'/doc/CapeTownNotes'+date+'.html',False,logfile)
                    if (status == 0):
                        outfile, status = saltio.openascii(pidpath+'/doc/CapeTownNotes'+date+'.html','w',logfile)
                        if (status == 0):
                            for line in infile:
                                #line = line.replace('SALT user','Dr ' + string.capwords(pi.lower()))
                                #line = line.replace('yourname',pi)
                                line = line.replace('yyyymmdd',date)
                                outfile.write(line)
                            status = saltio.closeascii(outfile,logfile)

# end time

    if (status == 0):
        saltprint.time('\nSALTHTML -- completed at',logfile,verbose)
    else:
        saltprint.time('\nSALTHTML -- aborted at',logfile,verbose)