Beispiel #1
0
def replaceSuffix(filename, suffix):
    """Replace the suffix in the file name.

    If filename includes an underscore ('_') character, the slice
    between that point (the rightmost underscore) and the extension will
    be replaced with the specified suffix.  If there is no underscore,
    the suffix will be inserted before the extension.
    If filename does not end with one of the recognized extensions,
    all of the string starting with the rightmost underscore will be
    replaced by the specified suffix, or the suffix will be appended
    if there is no underscore in filename.

    >>> print replaceSuffix ('abc_raw.fits', '_flt')
    abc_flt.fits
    >>> print replaceSuffix ('abc.fits
    ', '_flt')
    abc_flt.fits
    >>> print replaceSuffix ('abc_raw.flub', '_flt')
    abc_flt
    >>> print replaceSuffix ('abc.flub', '_flt')
    abc.flub_flt

    @param filename: a file name
    @type filename: string

    @param suffix: the suffix to replace the existing suffix
    @type suffix: string

    @return: the input file name with the suffix included
    @rtype: string
    """
    # retrieve global logger object
    global log
    if log==None:
        # instantiate the logger object and put into the global variable 
        log = gemLog.getGeminiLog()
    
    found = False
    # Extensions is a list of recognized filename extensions.
    for extn in extensions:
        if filename.endswith(extn):
            j = filename.rfind('_')
            if j >= 0:
                newname = filename[:j] + suffix + extn
            else:
                k = filename.rfind(extn)
                newname = filename[:k] + suffix + extn
            found = True
            break

    if not found:
        j = filename.rfind('_')
        if j >= 0:
            newname = filename[:j] + suffix
        else:
            newname = filename + suffix
    
    log.status('replaceSuffix changed the filename from '+filename+' to '+
               newname, category='IQ')
    return newname
 def showParameters(self, rc):
     """
     A simple primitive to log the currently set parameters in the 
     reduction context dictionary.
     """
     
     # Instantiate the log
     log = gemLog.getGeminiLog(logType=rc["logType"],
                               logLevel=rc["logLevel"])
     
     rcparams = rc.param_names()
     if (rc["show"]):
         toshows = rc["show"].split(":")
         for toshow in toshows:
             if toshow in rcparams:
                 log.stdinfo("%s = %s" % (toshow, repr(rc[toshow])))
             else:
                 log.stdinfo("%s is not set" % (toshow))
     else:
         for param in rcparams:
             log.stdinfo("%s = %s" % (param, repr(rc[param])))
     # print "all",repr(rc.parm_dict_by_tag("showParams", "all"))
     # print "iraf",repr(rc.parm_dict_by_tag("showParams", "iraf"))
     # print "test",repr(rc.parm_dict_by_tag("showParams", "test"))
     # print "sdf",repr(rc.parm_dict_by_tag("showParams", "sdf"))
     # print repr(dir(rc.ro.primDict[rc.ro.curPrimType][0]))
     
     yield rc
Beispiel #3
0
def printlog(text, logfile=None, verbose=True):
    """Append text to the log file.

    @param text: text string to log
    @type text: string

    @param logfile: name of log file, or None
    @type logfile: string

    @param verbose: if True, then also print to standard output
    @type verbose: boolean
    """
    # retrieve global logger object
    global log
    if log==None:
        # instantiate the logger object and put into the global variable 
        log = gemLog.getGeminiLog()
        

    if logfile == 'STDOUT':
        logfile = None
        verbose = True

    if (text[0:5] == 'ERROR') or (text[0:7] == 'WARNING'):
        verbose = True

    if logfile is not None:
        fd = open(logfile, mode='a')
        fd.write(text + '\n')
        fd.close()

    if verbose:
        log.fullinfo(text, category='IQ')
 def getList(self, rc):
     """
     This primitive will check the files in the stack lists are on disk,
     and then update the inputs list to include all members of the stack 
     for stacking.
     
     :param purpose: 
     :type purpose: string
     """
     
     # Instantiate the log
     log = gemLog.getGeminiLog(logType=rc["logType"],
                               logLevel=rc["logLevel"])
     
     # Get purpose of list
     sidset = set()
     purpose=rc["purpose"]
     if purpose is None:
         purpose = ""
     
     # Get ID for all inputs
     for inp in rc.inputs:
         sidset.add(purpose+IDFactory.generate_stackable_id(inp.ad))
     
     # Import inputs from all lists
     for sid in sidset:
         stacklist = rc.get_list(sid) #.filelist
         log.stdinfo("List for stack id %s(...):" % sid[0:35])
         for f in stacklist:
             rc.report_output(f, stream=rc["to_stream"])
             log.stdinfo("   %s" % os.path.basename(f))
     
     yield rc
Beispiel #5
0
    def __init__(self,ad, addBPM=True, sigma=0.0, threshold=2.5, fwhm=5.5,
               logfile='fluxcal.log'):
       
        """
           Run all the functions to calculate ZP
           with the default parameters. 
           If you want to change some of then, you could
           run the individual functions.
        
           -  DetectSources(ad)
           -  AddReferenceCatalogs(ad)
           -  CorrelateWithReferenceCatalogs (ad)
           -  CalculateZeroPoint(ad)
        """
        
        basename = os.path.basename(ad.filename)
        adout = deepcopy(ad)
        adout.filename = 'fc_'+basename
        self.adout = adout
        self.addBPM=addBPM
        self.sigma=sigma
        self.threshold=threshold
        self.fwhm=fwhm

        self.logfile = logfile
        self.log=gemLog.getGeminiLog(logName=logfile,logLevel=6)
        log = self.log

        log.info( "\n  ==================== FLUXCAL for "+ad.filename+" ====================")
    def stackFlats(self, rc):
        """
        This primitive will combine the input flats with rejection
        parameters set appropriately for GMOS imaging twilight flats.
        """
        
        # Instantiate the log
        log = gemLog.getGeminiLog(logType=rc["logType"],
                                  logLevel=rc["logLevel"])
        
        # Log the standard "starting primitive" debug message
        log.debug(gt.log_message("primitive", "stackFlats", "starting"))
        
        # Check for at least 2 input frames
        adinput = rc.get_inputs_as_astrodata()
        nframes = len(adinput)
        if nframes<2:
            log.stdinfo("At least two frames must be provided to " +
                        "stackFlats")
            # Report input to RC without change
            adoutput_list = adinput
            rc.report_output(adoutput_list)
        else:
            # Define rejection parameters based on number of input frames,
            # to be used with minmax rejection. Note: if reject_method
            # parameter is overridden, these parameters will just be
            # ignored
            reject_method = rc["reject_method"]
            nlow = 0
            nhigh = 0
            if nframes <= 2:
                reject_method = None
            elif nframes <= 5:
                nlow = 1
                nhigh = 1
            elif nframes <= 10:
                nlow = 2
                nhigh = 2
            else:
                nlow = 2
                nhigh = 3
            log.fullinfo("For %d input frames, using reject_method=%s, "\
                         "nlow=%d, nhigh=%d" % 
                         (nframes, reject_method, nlow, nhigh))

            # Run the scaleByIntensity primitive to scale flats to the
            # same level
            rc.run("scaleByIntensity")

            # Run the stackFrames primitive with the defined parameters
            prim_str = "stackFrames(suffix=%s,operation=%s,mask=%s," \
                       "reject_method=%s,nlow=%s,nhigh=%s)" % \
                       (rc["suffix"],rc["operation"],rc["mask"],
                        reject_method,nlow,nhigh)
            rc.run(prim_str)
        
        yield rc
 def log(self, rc):
     log = gemLog.getGeminiLog(logType=rc["logType"],
                               logLevel=rc["logLevel"])
     
     msg = rc["msg"]
     if msg == None:
         msg = "..."
     log.fullinfo(msg)
     
     yield rc
 def __init__(self):
     '''
     Goes into ConfigSpace and gets all the file URIs to create a XML index.
     '''
     # raise FatalDeprecation("CalibrationDefinitionLibrary NOT IN USE!")
     
     self.xmlIndex = {}
     #self.update_xml_index()
     # instantiate the logger object and put into the global variable 
     self.log = gemLog.getGeminiLog()
def _header_align(reference, adinput):
    """
    This function uses the POFFSET and QOFFSET header keywords
    to get reference points to use in correcting an input WCS to
    a reference WCS. Positive POFFSET is assumed to mean higher x
    value, and positive QOFFSET is assumed to mean higher y value.
    This function only allows for relative shifts between the images;
    rotations and scales will not be handled properly
    
    :param reference: reference image to register other images to. Must
                      have only one SCI extension.
    :type reference: AstroData object
    
    :param adinput: images to register to reference image. Must have
                  only one SCI extension.
    :type adinput: AstroData objects, either a single instance or a list
    """

    log = gemLog.getGeminiLog()

    if not isinstance(adinput, list):
        adinput = [adinput]

    # get starting offsets from reference image (first one given)
    pixscale = float(reference.pixel_scale())
    ref_xoff = reference.phu_get_key_value("POFFSET") / pixscale
    ref_yoff = reference.phu_get_key_value("QOFFSET") / pixscale

    # reference position is the center of the reference frame
    data_shape = reference["SCI"].data.shape
    ref_coord = [data_shape[1] / 2, data_shape[0] / 2]

    log.fullinfo("Pixel scale: %.4f" % pixscale)
    log.fullinfo("Reference offsets: %.4f %.4f" % (ref_xoff, ref_yoff))
    log.fullinfo("Reference coordinates: %.1f %.1f" % (ref_coord[0], ref_coord[1]))

    objIns = []
    for i in range(len(adinput)):
        ad = adinput[i]
        pixscale = float(ad.pixel_scale())
        xoff = ad.phu_get_key_value("POFFSET") / pixscale
        yoff = ad.phu_get_key_value("QOFFSET") / pixscale

        img_x = xoff - ref_xoff + ref_coord[0]
        img_y = yoff - ref_yoff + ref_coord[1]

        log.fullinfo("For image " + ad.filename + ":")
        log.fullinfo("   Image offsets: %.4f %.4f" % (xoff, yoff))
        log.fullinfo("   Coordinates to transform: %.4f %.4f" % (img_x, img_y))

        objIns.append(np.array([[ref_coord], [[img_x, img_y]]]))

    adoutput_list = _align_wcs(reference, adinput, objIns, rotate=False, scale=False)

    return adoutput_list
    def subtract(self,rc):
        # This is a bare-bones primitive interface to the ad sub
        # function from the arith module.  The value, dictionary,
        # or AD instance to be subtracted from the input is stored in
        # rc["operand"]

        # Instantiate the log
        log = gemLog.getGeminiLog(logType=rc["logType"],
                                  logLevel=rc["logLevel"])

        # Log the standard "starting primitive" debug message
        log.debug(gt.log_message("primitive", "subtract", "starting"))

        # Define the keyword to be used for the time stamp for this primitive
        timestamp_key = self.timestamp_keys["subtract"]

        # Initialize the list of output AstroData objects
        adoutput_list = []
        
        # Get data to be subtracted from the RC
        operand = rc["operand"]
        if operand is None:
            log.stdinfo("No operand to subtract; no changes will be "\
                            "made to input")
        elif type(operand)==AstroData:
            log.stdinfo("Subtracting %s from input" % 
                        (operand.filename))
        else:
            log.stdinfo("Subtracting %s from input" % 
                        (repr(operand)))
            
        # Loop over each input AstroData object in the input list
        for ad in rc.get_inputs_as_astrodata():

            if operand is not None:
                # Subtract operand from data
                ad.sub(operand)

                # Add the appropriate time stamps to the PHU
                gt.mark_history(adinput=ad, keyword=timestamp_key)

                # Change the filename
                ad.filename = gt.filename_updater(
                    adinput=ad, suffix=rc["suffix"], strip=True)

            # Append the output AstroData object to the list
            # of output AstroData objects
            adoutput_list.append(ad)

        # Report the list of output AstroData objects to the reduction
        # context
        rc.report_output(adoutput_list)
        
        yield rc
Beispiel #11
0
def checkParam(parameter, paramType, defaultValue, compareValue=0.0):
    """
    This is a very basic and general parameter checking function. Basically, 
    pass a parameter, expected type 
    and a default value. If it is the same type then:
    1) If it is a list, return it.
    2) If it is a string, check if it is  '', if it is then return default value.
    3) If it is a number, check that it is greater than 'compareValue', if it 
    is not then return defaultValue.
    
    Example usage:
    
    -checkParam( mode, type(''), 'constant' )
    -checkParam( fwhm, type(0.0), 5.5, compareValue=1.5 ) 
    
    @param parameter: Parameter for testing.
    @type parameter: Any
    
    @param paramType: What the expected type of the parameter should be.
    @type paramType: type( Any )
    
    @param defaultValue: What the default value will be if failures occur. 
                        Hopefully, the type matches paramType.
    @type defaultValue: type( Any )
    
    @param compareValue: Value to compare against in the case the parameter 
                        is a float or int. This will check whether
    the parameter is greater than the compareValue.
    @type compareValue: float or int
    
    @return: Parameter if it is the correct type and compare, default if it 
            fails comparison, or None if errors.
    @rtype: paramType or None
    """
    global log
    if log==None:
        log = gemLog.getGeminiLog()
        
    if type(parameter) == paramType:
        if (paramType == type(0)) or (paramType == type(0.0)):
            if parameter > compareValue:
                return parameter
        elif paramType == str:
            if parameter != '': 
                return parameter
        else:
            return parameter
    else:
        log.warning('Type of parameter, '+str(type(parameter))+
                    ' is not the correct type:'+str(paramType))
        #$$$ There needs to be an exception class to properly handle this raise
        raise 'Incorrect Parameter Type', type(parameter)
    return defaultValue
    def addToList(self, rc):
        """
        This primitive will update the lists of files to be stacked
        that have the same observationID with the current inputs.
        This file is cached between calls to reduce, thus allowing
        for one-file-at-a-time processing.
        
        :param purpose: 
        :type purpose: string
        
        """
        # Instantiate the log
        log = gemLog.getGeminiLog(logType=rc["logType"],
                                  logLevel=rc["logLevel"])
        
        from astrodata import memorytrack as mt
        
        mt.memtrack("addToList [inside]", "1")
        
        # Perform an update to the stack cache file (or create it) using the
        # current inputs in the reduction context
        purpose = rc["purpose"]
        if purpose is None:
            purpose = ""
        if purpose == "":
            suffix = "_list"
        else:
            suffix = "_%s" % purpose
            
        mt.memtrack("addToList [inside]", "2")
        
        # Update file names and write the files to disk to ensure the right
        # version is stored before adding it to the list.
        adoutput = []
        for ad in rc.get_inputs_as_astrodata():
            mt.memtrack("addToList [inside]", "3")
            ad.filename = gt.filename_updater(adinput=ad, suffix=suffix,
                                              strip=True)
            mt.memtrack("addToList [inside]", "3.1")
            log.stdinfo("Writing %s to disk" % ad.filename)
            mt.memtrack("addToList [inside]", "3.2")
            ad.write(clobber=True)
            mt.memtrack("addToList [inside]", "3.3")
            adoutput.append(ad)
            mt.memtrack("addtoList [inside]", "3.4")

        rc.report_output(adoutput)
        
        # Call the rq_stack_update method
        rc.rq_stack_update(purpose=purpose)
        mt.memtrack("addToList [inside]", "4")

        yield rc
 def sleep(self, rc):
     # Instantiate the log
     log = gemLog.getGeminiLog(logType=rc["logType"],
                               logLevel=rc["logLevel"])
     if rc["duration"]:
         dur = float(rc["duration"])
     else:
         dur = 5.
     log.status("Sleeping for %f seconds" % dur)
     time.sleep(dur)
     
     yield rc
    def addObjectMaskToDQ(self, rc):
        """
        This primitive combines the object mask in a OBJMASK extension
        into the DQ plane
        """
        
        # Instantiate the log
        log = gemLog.getGeminiLog(logType=rc["logType"],
                                  logLevel=rc["logLevel"])
        
        # Log the standard "starting primitive" debug message
        log.debug(gt.log_message("primitive", "addObjectMaskToDQ", "starting"))
        
        # Define the keyword to be used for the time stamp for this primitive
        timestamp_key = self.timestamp_keys["addObjectMaskToDQ"]

        # Initialize the list of output AstroData objects
        adoutput_list = []
        
        # Loop over each input AstroData object in the input list
        for ad in rc.get_inputs_as_astrodata():
            
            for sciext in ad["SCI"]:
                extver = sciext.extver()
                dqext = ad["DQ",extver]
                mask = ad["OBJMASK",extver]
                if mask is None:
                    log.warning("No object mask present for "\
                                    "%s[SCI,%d]; "\
                                    "cannot apply object mask" %
                                (ad.filename,extver))
                else:
                    if dqext is not None:
                        ad["DQ",extver].data = dqext.data | mask.data
                    else:
                        dqext = deepcopy(mask)
                        dqext.rename_ext("DQ",extver)
                        ad.append(dqext)

            # Change the filename
            ad.filename = gt.filename_updater(adinput=ad, suffix=rc["suffix"], 
                                              strip=True)
            
            # Append the output AstroData object to the list 
            # of output AstroData objects
            adoutput_list.append(ad)
        
        # Report the list of output AstroData objects to the reduction
        # context
        rc.report_output(adoutput_list)
        
        yield rc
    def alignToReferenceImage(self, rc):
        """
        This primitive applies the transformation encoded in the input images
        WCSs to align them with a reference image, in reference image pixel
        coordinates.  The reference image is taken to be the first image in
        the input list.

        By default, the transformation into the reference frame is done via
        interpolation.  The interpolator parameter specifies the interpolation 
        method.  The options are nearest-neighbor, bilinear, or nth-order 
        spline, with n = 2, 3, 4, or 5.  If interpolator is None, 
        no interpolation is done: the input image is shifted by an integer
        number of pixels, such that the center of the frame matches up as
        well as possible.  The variance plane, if present, is transformed in
        the same way as the science data.  

        The data quality plane, if present, must be handled a little
        differently.  DQ flags are set bit-wise, such that each pixel is the 
        sum of any of the following values: 0=good pixel,
        1=bad pixel (from bad pixel mask), 2=nonlinear, 4=saturated, etc.
        To transform the DQ plane without losing flag information, it is
        unpacked into separate masks, each of which is transformed in the same
        way as the science data.  A pixel is flagged if it had greater than
        1% influence from a bad pixel.  The transformed masks are then added
        back together to generate the transformed DQ plane.
        
        In order not to lose any data, the output image arrays (including the
        reference image's) are expanded with respect to the input image arrays.
        The science and variance data arrays are padded with zeros; the DQ
        plane is padded with ones.  

        The WCS keywords in the headers of the output images are updated
        to reflect the transformation.

        :param interpolator: type of interpolation desired
        :type interpolator: string, possible values are None, 'nearest', 
                            'linear', 'spline2', 'spline3', 'spline4', 
                            or 'spline5'

        :param suffix: string to add on the end of the input filenames to 
                       generate output filenames
        :type suffix: string
        
        """
        log = gemLog.getGeminiLog(logType=rc['logType'],logLevel=rc['logLevel'])
        log.debug(gt.log_message("primitive", "alignToReferenceImage", 
                                 "starting"))
        adoutput_list = rf.align_to_reference_image(
                                         adinput=rc.get_inputs(style='AD'),
                                         interpolator=rc['interpolator'])
        rc.report_output(adoutput_list)
        yield rc
 def contextReport(self, rc):
     # Instantiate the log
     log = gemLog.getGeminiLog(logType=rc["logType"],
                              logLevel=rc["logLevel"])
     
     log.fullinfo(rc.report(report_history=rc["report_history"],
                            internal_dict=rc["internal_dict"],
                            context_vars=rc["context_vars"],
                            report_inputs=rc["report_inputs"],
                            report_parameters=rc["report_parameters"],
                            showall=rc["showall"]))
     
     yield rc
 def time(self, rc):
     # Instantiate the log
     log = gemLog.getGeminiLog(logType=rc["logType"],
                               logLevel=rc["logLevel"])
     
     cur = datetime.now()
     elap = ""
     if rc["lastTime"] and not rc["start"]:
         td = cur - rc["lastTime"]
         elap = " (%s)" % str(td)
     log.stdinfo("Time: %s %s" % (str(datetime.now()), elap))
     rc.update({"lastTime":cur})
     
     yield rc
    def __init__(self, ad, logLevel=6, firstPass=50, delta=7, logfile=""):

        if not logfile:
            logfile = "selectreferences.log"

        basename = os.path.basename(ad.filename)
        outad = deepcopy(ad)
        outad.filename = "corr_" + basename
        self.outad = outad

        self.log = gemLog.getGeminiLog(logName=logfile, logLevel=logLevel)
        log = self.log
        log.defaultCategory(level="ALL", category="corrObjRef")

        log.info("\n  ******  CORRELATE OBJECT AND REFERENCE POSITIONS for: %s.   *********" % ad.filename)
        self.firstpass = firstPass
        self.delta = delta
    def __init__(self, ad, catalogName=None, logLevel=6, logfile=''):

        self.ad = ad

        basename = os.path.basename(ad.filename)

        self.outad = deepcopy(ad)
        self.outad.filename = 'ref_'+basename

        if not logfile:
            logfile = 'selectreferences.log'

        self.log = gemLog.getGeminiLog(logName=logfile, logLevel=logLevel)
        log = self.log
        log.defaultCategory(level='ALL', category='selectReferences')

    
        log.info( "\n ****** SELECT REFERENCES for: %s *******"%ad.filename)
    def __init__(self, ad, logLevel=6, logfile='', zplogfile='ZPcorr.log', extinction=None):

        if not logfile:
            logfile = 'calculateZeropoint.log'

        self.log = gemLog.getGeminiLog(logName=logfile, logLevel=logLevel)
        log = self.log
        log.defaultCategory(level='ALL',category='calczp')

        basename = os.path.basename(ad.filename)
        outad = deepcopy(ad)
        outad.filename = 'zpcalc_'+basename
        self.outad = outad

        self.zplogfile = zplogfile
        self.extinction = extinction


        log.info( "\n ******  CALCULATE ZERO POINT CORRECTION for: %s.  *********"%ad.filename)
 def showOutputs(self, rc):
     log = gemLog.getGeminiLog(logType=rc["logType"],
                               logLevel=rc["logLevel"])
     streams = rc.outputs.keys()
     streams.sort()
     streams.remove("main")
     streams.insert(0,"main")
     tstream = rc["streams"]
     
     for stream in streams:
         if tstream == None or stream in tstream:
             log.stdinfo("stream: "+stream)
             if len(rc.outputs[stream])>0:
                 for adr in rc.outputs[stream]:
                     log.stdinfo(str(adr))
             else:
                 log.stdinfo("    empty")
     
     yield rc
Beispiel #22
0
def appendSuffix(filename, suffix):
    """Append a suffix to the root of the file name.

    If filename does not end with one of the recognized extensions,
    the suffix will just be appended to filename.

    >>> print appendSuffix ('abc.fits', '_flt')
    abc_flt.fits
    >>> print appendSuffix ('abc', '_flt')
    abc_flt
    >>> print appendSuffix ('abc.xyz', '_flt')
    abc.xyz_flt

    @param filename: a file name
    @type filename: string

    @param suffix: the suffix (e.g. '_flt') to append
    @type suffix: string

    @return: the input file name with the suffix included
    @rtype: string
    
    """
    # retrieve global logger object
    global log
    if log==None:
        # instantiate the logger object and put into the global variable 
        log = gemLog.getGeminiLog()

    found = False
    # Extensions is a list of recognized filename extensions.
    for extn in extensions:
        if filename.endswith(extn):
            k = filename.rfind(extn)
            newname = filename[:k] + suffix + extn
            found = True
            break

    if not found:
        newname = filename + suffix
    log.status('appendSuffix changed the filename from '+filename+' to '+
               newname, category='IQ')
    return newname
Beispiel #23
0
def urlfetch(url, store = None, clobber = False):
    log = gemLog.getGeminiLog()
    purl = urlparse.urlparse(url)
    host = "fits" #"hbffits3.hi.gemini.edu" #@@CONFIG: FITSSTORE RETRIEVAL HOST
    npurl = urlparse.ParseResult(purl.scheme,
                                 purl.hostname,
                                 purl.path,
                                 purl.params,
                                 purl.query,
                                 purl.fragment)
    
    url = npurl.geturl()
    #log.debug("nu20: adutils.urlfetch asked to get ", url)
    #print("nu20: adutils.urlfetch asked to get ", url)
    
    try:
        res = urllib2.urlopen(url)
    except urllib2.HTTPError, error:
        print "ERROR"
        print error.read()
        raise 
 def showInputs(self, rc):
     """
     A simple primitive to show the filenames for the current inputs to 
     this primitive.
     """
     
     # Instantiate the log
     log = gemLog.getGeminiLog(logType=rc["logType"],
                               logLevel=rc["logLevel"])
     log.stdinfo("Inputs:")
     #print "pG977:", id(rc), repr(rc.inputs)
     #if "stream" in rc:
     #    stream = rc["stream"]
     #else:
     #    stream = "main"
     
     log.stdinfo("stream: %s" % (rc._current_stream))
     for inf in rc.inputs:
         log.stdinfo("  %s" % inf.filename)
     
     yield rc
    def forwardInput(self, rc):
        log = gemLog.getGeminiLog(logType=rc["logType"],
                                  logLevel=rc["logLevel"])
        
        if rc["to_stream"] != None:
            stream = rc["to_stream"]
        else:
            stream = "main"
        prefix = rc["prefix"];
        do_deepcopy = rc["deepcopy"]
        if do_deepcopy is None:
            do_deepcopy = True

        if "by_token" in rc:
            bt = rc["by_token"]
            for ar in rc.inputs:
                if bt in ar.filename:
                    rc.report_output(ar.ad, stream = stream)
            #print "pG110:",repr(rc.outputs)
        else:
            inputs = rc.get_inputs_as_astrodata()
            inputs_copy = []
            for ad in inputs:
                if do_deepcopy:
                    from copy import deepcopy
                    ad_copy = deepcopy(ad)
                else:
                    ad_copy = ad
                if prefix:
                    ad_copy.filename = os.path.join(
                                        prefix+os.path.basename(ad.filename))
                else:
                    ad_copy.filename = ad.filename
                inputs_copy.append(ad_copy)

            log.fullinfo("Reporting Output: "+ \
                             ", ".join([ ad.filename for ad in inputs_copy]))
            rc.report_output(inputs_copy, stream = stream, )
        
        yield rc
 def listDir(self, rc):
     # Instantiate the log
     log = gemLog.getGeminiLog(logType=rc["logType"],
                               logLevel=rc["logLevel"])
     
     if rc["dir"] == None:
         thedir = "."
     else:
         thedir = rc["dir"]
     log.status("Listing for: "+ thedir)
     files = os.listdir(thedir)
     sfiles = []
     for f in files:
         if f[-5:].lower() == ".fits":
             sfiles.append(f)
     sfiles.sort()
     if len(sfiles) == 0:
         log.status("No FITS files")
     else:
         log.status("\n\t".join(sfiles))
     
     yield rc
Beispiel #27
0
    def __init__(self, ad, sigma=0.0, threshold=2.5, fwhm=5.5, logLevel=6, logfile=''):

        if 'CAL' in ad.types:
            raise RuntimeError, " **** AD type 'CAL' not supported  by DetectSources****"

        basename = os.path.basename(ad.filename)

        self.sigma = sigma
        self.threshold = threshold
        self.fwhm = fwhm

        if not logfile:
            logfile = 'detectSources.log'

        self.log = gemLog.getGeminiLog()
        log = self.log
        log.defaultCategory(level='ALL',category='DetecSources')
 
        outad = deepcopy(ad)
        outad.filename = 'ds_'+basename
        self.outad = outad
        log.info( "\n ******  DETECTING  SOURCES  for: %s *************"%ad.filename)
 def addInputs(self, rc):
     # Instantiate the log
     log = gemLog.getGeminiLog(logType=rc["logType"],
                               logLevel=rc["logLevel"])
     
     import glob as gl
     if rc["files"] == None:
         glob = "./*.fits"
     else:
         glob = rc["files"]
     log.status("Listing for: "+ glob)
     files = gl.glob(glob)
     files.sort()
     if len(files) == 0:
         log.status("No files")
     else:
         log.status("\t"+"\n\t".join(files))
     yield rc
     add = True # rc["inputs"]
     if add:
         rc.add_input(files)
     
     yield rc
Beispiel #29
0
def verifyOutlist( inlist, outlist ):
    """
    Verifies that for every file in the inList, there is a corresponding 
    output file.
    
    @param inList: A list of input file paths.
    @type inList: list
    
    @param outlist: A list of output file paths.
    @type outlist: list    
    
    """
    global log
    if log==None:
        log = gemLog.getGeminiLog()
    
    try:    
        if outlist == []:
            # Will append unique filenames if none exist in outlist             
            for i in range(len(inlist)):
                line = 'output' + str(i+1)+ '.fits'
                outlist.append(line)             
            return outlist
        elif len(outlist) < len(inlist):
            # Will append unique filenames if not enough in outlist
            l = len(inlist) - len(outlist)           
            for i in range(l):
                line = 'output' + str(l+i)+ '.fits'
                outlist.append(line)
            return outlist
        else:
            return outlist
    except:
        log.error('An error occured while trying to verify'+
                    ' the outputs existance for inlist '+repr(inlist))
        return None                
 def showList(self, rc):
     """
     This primitive will log the list of files in the stacking list matching
     the current inputs and 'purpose' value.
     
     :param purpose: 
     :type purpose: string
     """
     
     # Instantiate the log
     log = gemLog.getGeminiLog(logType=rc["logType"],
                               logLevel=rc["logLevel"])
     
     sidset = set()
     purpose = rc["purpose"]
     if purpose is None:
         purpose = ""
     # print "pG710"
     if purpose == "all":
         allsids = rc.get_stack_ids()
         # print "pG713:", repr(allsids)
         for sid in allsids:
             sidset.add(sid)
     else:
         for inp in rc.inputs:
             sidset.add(purpose+IDFactory.generate_stackable_id(inp.ad))
     for sid in sidset:
         stacklist = rc.get_list(sid) #.filelist
         log.status("List for stack id=%s" % sid)
         if len(stacklist) > 0:
             for f in stacklist:
                 log.status("   %s" % os.path.basename(f))
         else:
             log.status("No datasets in list")
     
     yield rc