Esempio n. 1
0
def gatherframes(plan,frame):
    """This gathers up all the frames that one might want to use
    in conjunction with a science frame.
    """

    types = plan.pipeline.framelist.split()
    for type in types:
        otherframes = []
        if type == "Object":
            otherframes = Frameutil.findlikeframes(frame)
        else:
            otherframes = Frameutil.findframestype(frame,type)
            
        appendframes(plan,otherframes)

    plan.update()
Esempio n. 2
0
idlenv = os.path.abspath("test_data/idlenv")
testfile = "r101216_0093.fits.gz"
stdfile = "std-r101216_0093.fits.gz"
testfiledir = "r101216_0093"
testcalfile = "r101216_0092.fits.gz"
testdir = os.path.abspath("test_data")

if not os.path.isfile(os.path.join(testdir,testfile)):
	print "file %s does not exist, check test data and setup" % (os.path.join(testdir,testfile))
	sys.exit(-1)
hdr = pyfits.getheader(os.path.join(testdir,testfile),0)
calhdr = pyfits.getheader(os.path.join(testdir,testcalfile),0)
stdhdu = pyfits.open(os.path.join(testdir,testfiledir,'Science',stdfile))

instrument = Frameutil.find_instrument_name(hdr)
obsdate,obstime = Frameutil.getobsdate(hdr)
cobsdate,cobstime = Frameutil.getobsdate(calhdr)
nmsg,stdframe = Frameutil.addframe(testfile,hdr,obsdate,obstime,testfile,os.path.join(testdir,testfiledir),instrument)
nmsg,calframe = Frameutil.addframe(testcalfile,calhdr,cobsdate,cobstime,testcalfile,testdir,instrument)
xidlpipe = Pipeline(display_name="XIDL for LRIS",
		    runstr='idl -e long_reduce',
		    instrument=stdframe.instrument,
		    framelist="Object Line IntFlat Flat DmFlat Trace"                    
	)
pipes = [xidlpipe]
	
flag = dict(redo=False)
correctplan = Planutil.buildplan(stdframe,"test.plan",os.getcwd(),xidlpipe,flag)
correctplan.frames.append(stdframe)
Esempio n. 3
0
def buildandrunplan(filename,watchdir,stddir,pipelines,calibs,stars,idlenv,flag):
    """This does what it name says. It requires a filename for a standard image,
    the directory that image lives in, the output directory, a list of pipelines, calibration
    frames, a starlist, a filename for a csh script containing the IDL env information
    and a dictionary of flags.

    This copies the file into the appropiate output directory. It checks the file to
    see if it is a standard star observation and the star is in the starlist. It checks to see
    if a pipeline that can proccess the file is in the pipline list. Then, it finds the appropriate
    calibration frames, builds the final data reduction plan and executes it.

    The routine returns the run data reduction plan and a message string. If the plan is False,
    then the routine failed, the message string should return an error. Otherwise, the string is empty.
    """

    # first, we parse the input file and make the frame instance
    # remember, this copies the file from the current location (watchdir)
    # to the final directory which is stddir/ + date_str/ + filename/ 
    msg,frame= Frameutil.ingestframe(os.path.basename(filename),watchdir,stddir,flag)
    if not frame:
        return(msg,False)

    # second, we check to see if the input file is in the allowed list
    msg = check_if_std_frame(frame,stars)
    if msg:
        # crap - at this point we have already moved the to stddir
        if os.path.isfile(os.path.join(stddir,os.path.basename(filename))):
            os.remove(os.path.join(stddir,os.path.basename(filename)))
        return(msg,False)


    # given an acceptable frame, we make the plan file
    pipeline = find_pipeline(frame,pipelines)
    pipeflags(frame,pipeline)
    #    planname = re.sub(r"\.fit(s?)",r".plan",os.path.basename(filename))
    planname = "plan.par"
    plan = Planutil.buildplan(frame,planname,stddir,pipeline,flag)
    plan.frames.append(frame)
    # now we use the calib file list in the calib directory
    # to find matching calibrations
    #
    # find_calibframes also will copy those frames into the plan
    # directory
    calframes,msg = find_calibframes(frame,plan,calibs,stddir)
    if not calframes or len(calframes) == 0:
        if os.path.isfile(os.path.join(stddir,plan.finalpath,os.path.basename(filename))):
            os.remove(os.path.join(stddir,plan.finalpath,os.path.basename(filename)))
        return(msg,False)
    msg = "" # msg can be filled with information for find_calibframes that is not relevant
             # I should make linkreduced smarter
    plan.frames += calframes
    # update with calibration data frames and write out the plan file
    plan = Planutil.updateplandata(plan,stddir)
    runstr = writeplan(plan,stddir,idlenv)
    # executable = shlex.split(runstr)
    # actually run the pipeline
    cwd = os.path.join(stddir,plan.finalpath)
    outputfile = open(os.path.join(cwd,'longreduce.log'),"wb")
    curproc = None
    try:
        curproc = subprocess.call(runstr,
            cwd=cwd,
            stdout=outputfile,
            stderr=outputfile,
            executable="/bin/tcsh",
            shell=True
            )
            # curproc.wait()
        
    except :
        msg = "Error running process %s" % (runstr)

    return(msg,plan)