Exemplo n.º 1
0
    # ------------------------------------------------------------------------ #
    generate_pycallgraphs = False
    if (generate_pycallgraphs):
        import pycallgraph
        pycallgraph.start_trace()

    if args.intelligence:
        typeIndex = gdpgutil.cluster_by_groupid(allinputs)
        # If super intelligence, it would determine ordering. Now, recipes in
        # simple order, (i.e. the order of values()).
        allinputs = typeIndex.values()
    else:
        nl = []
        for inp in allinputs:
            try:
                ad = AstroData(inp)
            except:
                # note: should we raise an exception here?
                err = "Can't Load Dataset: %s" % inp
                log.warning(err)
                continue
            nl.append(ad)
            ad = None #danger of accidentally using this!

        try:
            assert(nl)
            allinputs = [nl]               # Why is allinputs blown away here?
        except AssertionError:
            msg = "No AstroData objects were created."
            log.warning(msg)
            raise IOError, msg
Exemplo n.º 2
0
def ADUToElectron(filelist, odir, oprefix):
    """
     This is a function to convert the ADU counts to electrons
     by multiply the pixel values by the gain.
     Arguments:
       filelist: A python list of FITS filenames
       odir:     Directory pathname for output FITS files
       oprefix:  Prefix for output filenames. Example: If input filename
                 is 'S20100323S0012.fits' and 'oprefix' is 'n', the output 
                 name will be 'nS20100323S0012.fits'
    """

    # Loop through the files in filelist
    for filename in filelist:
        # Open the file as an AstroData object
        adinput = AstroData(filename, mode='readonly')

        # Verify whether the data has already been converted to electrons
        if adinput.phuValue('ELECTRON') != None:
            print "WARNING: File %s has already been converted to electrons"\
                   % filename
            return

        outputname = oprefix + os.path.basename(filename)
        ofile = os.path.join(odir,outputname)
        if os.access(ofile, os.F_OK): os.remove(ofile)

        # Prepare a new output
        #    Propagate PHU and MDF (if applicable) to output.
        #    No pixel extensions yet.
        #    Set output file name.
        #    No overwrite allowed. (default mode for prepOutput)
        #
        # prepOutput copies the adinput PHU and set the name of the new
        # file represented by adout to ofile.

        adout = prepOutput(adinput, ofile)

        # Get the gain values to apply
        # adinput.gain() returns a list, one value for each science extension.
        gain = adinput.gain()

        # Use the deepcopy function to create a true copy and ensure that
        # the original is not modified.s

        adc = deepcopy(adinput) 

        # Multiply each science extension by the gain.
        # Append new extension to already prepared output.
        for extension,g,xn in zip(adc, gain, range(len(gain))):
            extension.data = extension.data * g

            adout.append(data=extension.data, header=extension.header)

        # Update PHU with timestamps
        adout.phuSetKeyValue('ELECTRON', fits_utc(), 
            comment='UT Modified with convertToElectrons')
        adout.phuSetKeyValue('GEM-TLM', fits_utc(), 
            comment='UT Last modification with GEMINI')

        # Write to disk.  The filename was specified when 
        # prepOutput was called.
        adout.write()

        # Close files
        adout.close()
        adc.close()
        adinput.close()