Exemplo n.º 1
0
import sys
sys.path.append("/opt/gemini_python")
from astrodata import AstroData
import urllib2, urllib

# This is a GMOS_N imaging science dataset
ad = AstroData("/home/callen/SVN-AD/gemini_python/test_data/calsearch/N20110531S0114.fits")

desc_dict = {'instrument':ad.instrument().for_db(),
             'observation_type': ad.observation_type().for_db(),
             'data_label':ad.data_label().for_db(),
             'detector_x_bin':ad.detector_x_bin().for_db(),
             'detector_y_bin':ad.detector_y_bin().for_db(),
             'read_speed_setting':ad.read_speed_setting().for_db(),
             'gain_setting':ad.gain_setting().for_db(),
             'amp_read_area':ad.amp_read_area().for_db(),
             'ut_datetime':ad.ut_datetime().for_db(),
             'exposure_time':ad.exposure_time().for_db(),
             'object': ad.object().for_db(),
             'filter_name':ad.filter_name().for_db(),
             'focal_plane_mask':ad.focal_plane_mask().for_db(),
             }

print repr(desc_dict)
type_list = ad.types
ad.close()

sequence = [('descriptors', desc_dict), ('types', type_list)]
postdata = urllib.urlencode(sequence)

#postdata = urllib.urlencode({"hello":1.})
Exemplo n.º 2
0
def main():
    options, args, parser = handleClArgs()

    # If clean, call superclean to clear out cache and kill old reduce
    # and adcc processes.
    if options.clean:
        print "\nRestoring redux to default state:" + \
              "\nall stack and calibration associations will be lost;" + \
              "\nall temporary files will be removed.\n"
        subprocess.call(["superclean", "--safe"])
        print
        sys.exit()

    # Get local site
    if time.timezone / 3600 == 10:      # HST = UTC + 10
        localsite = GEMINI_NORTH
    elif time.timezone / 3600 == 4:     # CST = UTC + 4
        localsite = GEMINI_SOUTH
    else:
        print "ERROR - timezone is not HST or CST. Local site cannot " + \
              "be determined"
        sys.exit()

    # Check arguments
    if len(args) < 1:
        print "ERROR - No input file specified"
        parser.print_help()
        sys.exit()
    elif len(args) > 2:
        print "ERROR - Too many arguments"
        parser.print_help()
        sys.exit()
    elif len(args) == 2:
        date = gemini_date(args[0])
        if date != "":
            prefix = OBSPREF[localsite] + date + "S"
        else:
            print "ERROR - Date %s not recognized." % args[0]
            parser.print_help()
            sys.exit()

        filenm = prefix + "%04i" % int(args[1])
    else:
        filenm = args[0]

    # Get file prefix from user; otherwise, use auto    
    prefix = "auto"
    if options.prefix:
        prefix = options.prefix

    # Get data directory from user or from site defaults
    directory = "."
    if options.directory:
        directory = options.directory
    else:
        if os.path.exists(OPSDATAPATH[localsite]):
            directory = OPSDATAPATH[localsite]
        elif os.path.exists(OPSDATAPATHBKUP[localsite]):
            directory = OPSDATAPATHBKUP[localsite]
        else:
            print "Cannot find %s or %s. Please specify a directory." % \
                  (OPSDATAPATH[localsite], OPSDATAPATHBKUP[localsite])
    directory = directory.rstrip("/") + "/"

    # Check for stacking option
    recipe = None
    if options.stack:

        # Check for _forStack image in local directory
        if os.path.exists(filenm):
            stack_filenm = os.path.basename(filenm)
        else:
            stack_filenm = filenm

        imgpath = image_path(stack_filenm, ".", 
                             prefix=prefix, localsite=localsite,
                             suffix="_forStack")
        if imgpath is None:
            # If not found, check for raw image in specified directory
            # and use full reduction recipe
            imgpath = image_path(filenm, directory, 
                                 prefix=prefix, localsite=localsite)
            recipe = "qaReduceAndStack"
        else:
            # If found, just use stacking recipe
            recipe = "qaStack"
    else:
        imgpath = image_path(filenm, directory, 
                             prefix=prefix, localsite=localsite)

    if imgpath is None:
        print "\nFile %s was not found.\n" % filenm
        sys.exit()

    imgname = os.path.basename(imgpath)
    print "Image path: "+imgpath

    # Check that file is GMOS LONGSLIT or IMAGE; other types are not yet supported
    # (but do allow biases and flats, too)
    try:
        ad = AstroData(imgpath)
    except IOError:
        print "\nProblem accessing file %s.\n" % filenm
        sys.exit()

    try:
        fp_mask = ad.focal_plane_mask()
    except:
        fp_mask = None

    if "RAW" not in ad.types and "PREPARED" in ad.types:
        print "AstroDataType 'RAW'  not found in types."
        print "AstroDataType 'PREPARED' found in types."
        print "\nFile %s appears to have been processed." % imgname
        print "redux halting ..."
        sys.exit()
    if "GMOS" not in ad.types:
        print "\nFile %s is not a GMOS file." % imgname
        print "Only GMOS longslit and images can be reduced at this time.\n"
        sys.exit()
    elif "GMOS_DARK" in ad.types:
        print "\nFile %s is a GMOS dark." % imgname
        print "Only GMOS longslit and images can be reduced at this time.\n"
        sys.exit()
    elif ("GMOS_IMAGE" in ad.types and
          fp_mask!="Imaging"):
        print "\nFile %s is a slit image." % imgname
        print "Only GMOS longslit and images can be reduced at this time.\n"
        sys.exit()
    elif (("GMOS_IMAGE" in ad.types and
           fp_mask=="Imaging" and 
           "GMOS_DARK" not in ad.types) or 
          "GMOS_BIAS" in ad.types or 
          "GMOS_IMAGE_FLAT" in ad.types or 
          "GMOS_LS" in ad.types):

        # Test for 3-amp mode with e2vDD CCDs. NOT commissioned.
        dettype = ad.phu_get_key_value("DETTYPE")
        if dettype=="SDSU II e2v DD CCD42-90":
            namps = ad.phu_get_key_value("NAMPS")
            if namps is not None and int(namps)==1:
                print "\nERROR: The GMOS e2v detectors should " \
                      "not use 3-amp mode!"
                print "Please set the GMOS CCD Readout Characteristics " \
                      "to use 6 amplifiers.\n"
                sys.exit()

        print "\nBeginning reduction for file %s, %s\n" % (imgname,
                                                           ad.data_label()) 
        if options.upload:
            context = "QA,upload"
        else:
            context = "QA"

        # Check for an alternate recipe for science reductions
        if ("GMOS_IMAGE" in ad.types and
            "GMOS_BIAS" not in ad.types and 
            "GMOS_IMAGE_FLAT" not in ad.types and
            recipe is not None):
            reduce_cmd = ["reduce",
                          "-r", recipe,
                          "--context",context,
                          "--loglevel","stdinfo",
                          "--logfile","gemini.log",
                          "-p", "clobber=True",
                          imgpath]
        else:
            # Otherwise call reduce with auto-selected reduction recipe
            reduce_cmd = ["reduce", 
                          "--context",context,
                          "--loglevel","stdinfo",
                          "--logfile","gemini.log",
                          "-p", "clobber=True",
                          imgpath]
            
        subprocess.call(reduce_cmd)

        print ""

    else:
        print "\nFile %s is not a supported type." % imgname
        print "Only GMOS longslit and images can be reduced at this time.\n"
        sys.exit()