Exemplo n.º 1
0
if __name__ == "__main__":

    try:
        _core.is_isis3_initialized()
    except:
        print "ISIS3 has not been initialized. Please do so. Now."
        sys.exit(1)

    parser = argparse.ArgumentParser()
    parser.add_argument("-d",
                        "--data",
                        help="Source cube file",
                        required=True,
                        type=str,
                        nargs='+')

    args = parser.parse_args()

    source = args.data

    for file_name in source:
        if file_name[-3:].upper() != "CUB":
            print "Not a ISIS cube file file. Skipping '%s'" % file_name
        else:
            out_file_tiff = "%s.tif" % file_name[:-4]
            importexport.isis2std_grayscale(file_name,
                                            out_file_tiff,
                                            minimum=None,
                                            maximum=None)
Exemplo n.º 2
0
            continue
        elif len(filters) > 0 and (filter1.upper() not in filters and filter2.upper() not in filters):
            continue
        elif len(require_width) > 0 and str(width) not in require_width:
            continue
        elif len(require_height) > 0 and str(height) not in require_height:
            continue
        else:
            matching_files.append(f)

    values = []
    for f in matching_files:
        _min, _max = mathandstats.get_data_min_max(f)
        values.append(_min)
        values.append(_max)
        print _min, _max


    minimum = np.min(values)
    maximum = np.max(values)

    print "Minimun:", minimum, "Maximum:", maximum
    #maximum -= ((maximum - minimum) * 0.45)
    #minimum += ((maximum - minimum) * 0.35)

    for f in matching_files:
        totiff = f[:-4]+".tif"
        print totiff
        importexport.isis2std_grayscale(f, totiff, minimum=minimum, maximum=maximum)

Exemplo n.º 3
0
def process_pds_data_file(lbl_file_name,
                          is_verbose=False,
                          skip_if_cub_exists=False,
                          init_spice=True,
                          nocleanup=False,
                          additional_options={}):
    product_id = info.get_product_id(lbl_file_name)

    out_file_tiff = "%s.tif" % output_filename(lbl_file_name)
    out_file_cub = "%s.cub" % output_filename(lbl_file_name)

    if skip_if_cub_exists and os.path.exists(out_file_cub):
        print "File %s exists, skipping processing" % out_file_cub
        return

    if "ringplane" in additional_options:
        is_ringplane = additional_options["ringplane"].upper() in ("TRUE",
                                                                   "YES")
    else:
        is_ringplane = False

    source_dirname = os.path.dirname(lbl_file_name)
    if source_dirname == "":
        source_dirname = "."

    work_dir = "%s/work" % source_dirname
    if not os.path.exists(work_dir):
        os.mkdir(work_dir)

    if is_verbose:
        print "Importing to cube..."
    else:
        printProgress(0, 9, prefix="%s: " % lbl_file_name)
    s = cassini.ciss2isis(lbl_file_name,
                          "%s/__%s_raw.cub" % (work_dir, product_id))
    if is_verbose:
        print s

    if is_verbose:
        print "Filling in Gaps..."
    else:
        printProgress(1, 9, prefix="%s: " % lbl_file_name)
    s = mathandstats.fillgap("%s/__%s_raw.cub" % (work_dir, product_id),
                             "%s/__%s_fill0.cub" % (work_dir, product_id))
    if is_verbose:
        print s

    if init_spice is True:
        if is_verbose:
            print "Initializing Spice..."
        else:
            printProgress(2, 9, prefix="%s: " % lbl_file_name)
        s = cameras.spiceinit("%s/__%s_fill0.cub" % (work_dir, product_id),
                              is_ringplane)
        if is_verbose:
            print s

    if is_verbose:
        print "Calibrating cube..."
    else:
        printProgress(3, 9, prefix="%s: " % lbl_file_name)
    s = cassini.cisscal("%s/__%s_fill0.cub" % (work_dir, product_id),
                        "%s/__%s_cal.cub" % (work_dir, product_id))
    if is_verbose:
        print s

    if is_verbose:
        print "Running Noise Filter..."
    else:
        printProgress(4, 9, prefix="%s: " % lbl_file_name)
    s = filters.noisefilter("%s/__%s_cal.cub" % (work_dir, product_id),
                            "%s/__%s_stdz.cub" % (work_dir, product_id))
    if is_verbose:
        print s

    if is_verbose:
        print "Filling in Nulls..."
    else:
        printProgress(5, 9, prefix="%s: " % lbl_file_name)
    s = filters.lowpass("%s/__%s_stdz.cub" % (work_dir, product_id),
                        "%s/__%s_fill.cub" % (work_dir, product_id))
    if is_verbose:
        print s

    if is_verbose:
        print "Removing Frame-Edge Noise..."
    else:
        printProgress(6, 9, prefix="%s: " % lbl_file_name)
    s = trimandmask.trim("%s/__%s_fill.cub" % (work_dir, product_id),
                         "%s" % (out_file_cub))
    if is_verbose:
        print s

    if is_verbose:
        print "Exporting TIFF..."
    else:
        printProgress(7, 9, prefix="%s: " % lbl_file_name)
    s = importexport.isis2std_grayscale("%s" % (out_file_cub),
                                        "%s" % (out_file_tiff))
    if is_verbose:
        print s

    if nocleanup is False:
        if is_verbose:
            print "Cleaning up..."
        else:
            printProgress(8, 9, prefix="%s: " % lbl_file_name)
        map(os.unlink, glob.glob('%s/__%s*.cub' % (work_dir, product_id)))
    else:
        if is_verbose:
            print "Skipping clean up..."
        else:
            printProgress(8, 9, prefix="%s: " % lbl_file_name)

    if not is_verbose:
        printProgress(9, 9, prefix="%s: " % lbl_file_name)
Exemplo n.º 4
0
def process_pds_data_file(from_file_name, is_verbose=False, skip_if_cub_exists=False, init_spice=True,  nocleanup=False, additional_options={}):
    product_id = info.get_product_id(from_file_name)

    out_file_tiff = "%s.tif" % output_filename(from_file_name)
    out_file_cub = "%s.cub" % output_filename(from_file_name)

    if skip_if_cub_exists and os.path.exists(out_file_cub):
        print "File %s exists, skipping processing" % out_file_cub
        return

    if "ringplane" in additional_options:
        is_ringplane = additional_options["ringplane"].upper() in ("TRUE", "YES")
    else:
        is_ringplane = False

    source_dirname = os.path.dirname(from_file_name)
    if source_dirname == "":
        source_dirname = "."

    work_dir = "%s/work" % source_dirname
    if not os.path.exists(work_dir):
        os.mkdir(work_dir)

    if is_verbose:
        print "Importing to cube..."
    else:
        printProgress(0, 11, prefix="%s: "%from_file_name)
    s = voyager.voy2isis(from_file_name, "%s/__%s_raw.cub"%(work_dir, product_id))
    if is_verbose:
        print s

    if is_verbose:
        print "Finding Reseaus..."
    else:
        printProgress(1, 11, prefix="%s: "%from_file_name)
    s = geometry.findrx("%s/__%s_raw.cub"%(work_dir, product_id))
    if is_verbose:
        print s

    if is_verbose:
        print "Removing Reseaus..."
    else:
        printProgress(2, 11, prefix="%s: "%from_file_name)
    s = geometry.remrx("%s/__%s_raw.cub"%(work_dir, product_id),
                       "%s/__%s_remrx.cub" % (work_dir, product_id),
                       action="BILINEAR")
    if is_verbose:
        print s

    try:
        if init_spice is True:
            if is_verbose:
                print "Initializing Spice..."
            else:
                printProgress(3, 11, prefix="%s: "%from_file_name)
            s = cameras.spiceinit("%s/__%s_remrx.cub" % (work_dir, product_id), is_ringplane)
            if is_verbose:
                print s

        if is_verbose:
            print "Calibrating cube..."
        else:
            printProgress(4, 11, prefix="%s: "%from_file_name)
        s = voyager.voycal("%s/__%s_raw.cub"%(work_dir, product_id),
                                "%s/__%s_cal.cub"%(work_dir, product_id))
        if is_verbose:
            print s

        # TODO: Determine when to run this (on Io approach) and do so
        #if is_verbose:
        #    print "Plasma torus irradiation correction..."
        #else:
        #    printProgress(4, 11, prefix="%s: "%from_file_name)
        #s = voyager.voycal("%s/__%s_cal.cub"%(work_dir, product_id),
        #                        "%s/__%s_ramp.cub"%(work_dir, product_id))

        #if is_verbose:
        #    print s

        last_cube = "%s/__%s_cal.cub"%(work_dir, product_id)
    except:
        if is_verbose:
            traceback.print_exc(file=sys.stdout)
        last_cube = "%s/__%s_remrx.cub" % (work_dir, product_id)

    if is_verbose:
        print "Filling in Gaps..."
    else:
        printProgress(5, 11, prefix="%s: "%from_file_name)
    s = mathandstats.fillgap(last_cube,
                       "%s/__%s_fill.cub" % (work_dir, product_id))
    if is_verbose:
        print s

    if is_verbose:
        print "Stretch Fix..."
    else:
        printProgress(5, 11, prefix="%s: "%from_file_name)
    s = utility.stretch("%s/__%s_fill.cub" % (work_dir, product_id),
                       "%s/__%s_stretch.cub" % (work_dir, product_id))
    if is_verbose:
        print s

    if is_verbose:
        print "Running Noise Filter..."
    else:
        printProgress(6, 11, prefix="%s: "%from_file_name)
    s = filters.noisefilter("%s/__%s_stretch.cub"%(work_dir, product_id),
                            "%s/__%s_stdz.cub"%(work_dir, product_id))
    if is_verbose:
        print s

    if is_verbose:
        print "Filling in Nulls..."
    else:
        printProgress(7, 11, prefix="%s: "%from_file_name)
    s = filters.lowpass("%s/__%s_stdz.cub"%(work_dir, product_id),
                        "%s/__%s_fill0.cub"%(work_dir, product_id))
    if is_verbose:
        print s

    if is_verbose:
        print "Removing Frame-Edge Noise..."
    else:
        printProgress(8, 11, prefix="%s: "%from_file_name)
    s = trimandmask.trim("%s/__%s_fill0.cub"%(work_dir, product_id),
                         out_file_cub,
                         top=2,
                         right=2,
                         bottom=2,
                         left=2)
    if is_verbose:
        print s

    """
    if is_verbose:
        print "Trimming Corners..."
    else:
        printProgress(9, 11, prefix="%s: "%from_file_name)
    s = trimandmask.circle("%s/__%s_noise.cub" % (work_dir, product_id),
                        out_file_cub,
                        rad=500)
    if is_verbose:
        print s
    """

    if is_verbose:
        print "Exporting TIFF..."
    else:
        printProgress(9, 11, prefix="%s: "%from_file_name)
    s = importexport.isis2std_grayscale("%s"%(out_file_cub),
                                    "%s"%(out_file_tiff))
    if is_verbose:
        print s

    if nocleanup is False:
        if is_verbose:
            print "Cleaning up..."
        else:
            printProgress(10, 11, prefix="%s: "%from_file_name)
        map(os.unlink, glob.glob('%s/__%s*.cub'%(work_dir, product_id)))
    else:
        if is_verbose:
            print "Skipping clean up..."
        else:
            printProgress(10, 11, prefix="%s: "%from_file_name)

    dirname = os.path.dirname(out_file_tiff)
    if len(dirname) > 0:
        dirname += "/"
    if os.path.exists("%sprint.prt"%dirname):
        os.unlink("%sprint.prt"%dirname)


    if not is_verbose:
        printProgress(11, 11, prefix="%s: "%from_file_name)
Exemplo n.º 5
0
def export(out_file_cub, is_verbose=False):
    out_file_tiff = "%s.tif" % out_file_cub[:-4]
    s = importexport.isis2std_grayscale("%s" % (out_file_cub),
                                        "%s" % (out_file_tiff))
    if is_verbose:
        print s