def output_filename(file_name): dirname = os.path.dirname(file_name) if len(dirname) > 0: dirname += "/" product_id = info.get_product_id(file_name) target = info.get_target(file_name) filter1, filter2 = info.get_filters(file_name) image_time = info.get_image_time(file_name) out_file = "{dirname}{product_id}_{target}_{filter1}_{filter2}_{image_date}".format( dirname=dirname, product_id=product_id[2:-4], target=target, filter1=filter1, filter2=filter2, image_date=image_time.strftime('%Y-%m-%d_%H.%M.%S')) return out_file
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)
def test_get_product_id_cub(self): assert info.get_product_id(TestIsis3Galileo.CUB_FILE) == "25I0045"
def test_get_product_id_lbl(self): assert info.get_product_id(TestIsis3Galileo.LBL_FILE) == "25I0045"
is_verbose = args.verbose match_stretch = args.match red_cub_file, r_min, r_max = process_file(args.red) green_cub_file, g_min, g_max = process_file(args.green) blue_cub_file, b_min, b_max = process_file(args.blue) a = np.array([r_min, r_max, g_min, g_max, b_min, b_max]) min = np.min(a) max = np.max(a) print "Max:", max print "Min:", min red_product_id = info.get_product_id(red_cub_file) green_product_id = info.get_product_id(green_cub_file) blue_product_id = info.get_product_id(blue_cub_file) targets = get_target_filename_portion(red_cub_file, green_cub_file, blue_cub_file) output_tiff = "%s_%s_%s_%s_RGB-composed.tif" % ( red_product_id, green_product_id, blue_product_id, targets) s = importexport.isis2std_rgb(red_cub_file, green_cub_file, blue_cub_file, output_tiff, minimum=min, maximum=max, match_stretch=match_stretch)
def test_get_product_id_cub(self): assert info.get_product_id(TestIsis3Voyager.CUB_FILE) == "1739S2-001"
def process_data_file(lbl_file_name, require_target, require_filters, require_width, require_height, metadata_only, is_verbose, skip_existing, init_spice, nocleanup, additional_options): source = utils.guess_from_filename_prefix(lbl_file_name) source_dirname = os.path.dirname(source) if source_dirname == "": source_dirname = "." if not os.path.exists(source): print "File %s does not exist" % source else: print_if_verbose("Processing %s" % source, is_verbose) target = info.get_target(source) print_if_verbose("Target: %s" % target, is_verbose) product_id = info.get_product_id(source) print_if_verbose("Product ID: %s" % product_id, is_verbose) try: filter1, filter2 = info.get_filters(source) except: filter1, filter2 = (None, None) print_if_verbose("Filter #1: %s" % filter1, is_verbose) print_if_verbose("Filter #2: %s" % filter2, is_verbose) width = info.get_num_line_samples(source) height = info.get_num_lines(source) lines = info.get_num_lines(source) print_if_verbose("Lines: %s" % lines, is_verbose) line_samples = info.get_num_line_samples(source) print_if_verbose("Samples per line: %s" % line_samples, is_verbose) image_date = info.get_image_time(source) print_if_verbose("Image Date: %s" % image_date, is_verbose) out_file_base = utils.output_filename(source) out_file_tiff = "%s.tif" % out_file_base print_if_verbose("Output Tiff: %s" % out_file_tiff, is_verbose) out_file_cub = "%s.cub" % out_file_base print_if_verbose("Output Cube: %s" % out_file_cub, is_verbose) if metadata_only: return if skip_existing and os.path.exists(out_file_cub) and os.path.exists( out_file_tiff): print "Output exists, skipping." return if require_target is not None and not require_target.upper( ) == target.upper(): print "Target mismatch, exiting." return if require_filters is not None and not (filter1 in require_filters or filter2 in require_filters): print "Filter mismatch, exiting." return if require_height is not None and not (str(height) in require_height): print "Height filter mismatch, exiting" if require_width is not None and not (str(width) in require_width): print "Width filter mismatch, exiting" utils.process_pds_data_file(source, is_verbose=is_verbose, init_spice=init_spice, nocleanup=nocleanup, additional_options=additional_options)
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)
def test_get_product_id_cub(self): assert info.get_product_id( TestIsis3Info.CUB_FILE) == "1_N1489034146.123"
def test_get_product_id_lbl(self): assert info.get_product_id( TestIsis3Info.LBL_FILE) == "1_N1489034146.123"
def process_pds_data_file(from_file_name, is_verbose=False, skip_if_cub_exists=False, init_spice=True, nocleanup=False, additional_options={}): #out_file = output_filename(from_file_name) #out_file_tiff = "%s.tif" % out_file #out_file_cub = "%s.cub" % out_file num_steps = 14 if "projection" in additional_options: projection = additional_options["projection"] else: projection = "equirectangular" 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) product_id = info.get_product_id(from_file_name) mapped_dir = "%s/work/mapped" % source_dirname if not os.path.exists(mapped_dir): os.mkdir(mapped_dir) if is_verbose: print "Importing to cube..." else: printProgress(0, num_steps, prefix="%s: " % from_file_name) s = juno.junocam2isis(from_file_name, "%s/__%s_raw.cub" % (work_dir, product_id)) if is_verbose: print s if "vt" in additional_options: trim_pixels = int(additional_options["vt"]) if is_verbose: print "Trimming Framelets..." print "Vertical trimming: %d pixels" % trim_pixels else: printProgress(0, num_steps, prefix="%s: " % from_file_name) trim_cubes(work_dir, product_id, trim_pixels=trim_pixels) if init_spice is True: if is_verbose: print "Initializing Spice..." else: printProgress(1, num_steps, prefix="%s: " % from_file_name) cub_files = glob.glob('%s/__%s_raw_*.cub' % (work_dir, product_id)) for cub_file in cub_files: s = cameras.spiceinit(cub_file, is_ringplane=False, spkpredict=True, ckpredicted=True, cknadir=True) if is_verbose: print s mid_num = int( round( len(glob.glob('%s/__%s_raw_*.cub' % (work_dir, product_id))) / 3.0 / 2.0)) mid_file = "%s/__%s_raw_GREEN_00%d.cub" % (work_dir, product_id, mid_num) map_file = "%s/__%s_map.cub" % (work_dir, product_id) if is_verbose: print "Starting Map..." else: printProgress(2, num_steps, prefix="%s: " % from_file_name) s = cameras.cam2map(mid_file, map_file, projection=projection) if is_verbose: print s if is_verbose: print "Map Projecting Stripes..." else: printProgress(3, num_steps, prefix="%s: " % from_file_name) cub_files = glob.glob('%s/__%s_raw_*.cub' % (work_dir, product_id)) for cub_file in cub_files: try: # Not all of them will work. bn = os.path.basename(cub_file) out_file = "%s/%s" % (mapped_dir, bn) s = cameras.cam2map(cub_file, out_file, map=map_file, resolution="MAP") if is_verbose: print s except: pass # Probably shouldn't eat the exception here. if is_verbose: print "Assembling Red Mosaic..." else: printProgress(4, num_steps, prefix="%s: " % from_file_name) out_file_red = assemble_mosaic("RED", source_dirname, product_id, is_verbose) if is_verbose: print "Assembling Green Mosaic..." else: printProgress(5, num_steps, prefix="%s: " % from_file_name) out_file_green = assemble_mosaic("GREEN", source_dirname, product_id, is_verbose) if is_verbose: print "Assembling Blue Mosaic..." else: printProgress(6, num_steps, prefix="%s: " % from_file_name) out_file_blue = assemble_mosaic("BLUE", source_dirname, product_id, is_verbose) if "histeq" in additional_options and additional_options["histeq"].upper( ) in ("TRUE", "YES"): if is_verbose: print "Running histogram equalization on map projected cubes..." else: printProgress(7, num_steps, prefix="%s: " % from_file_name) histeq_cube(out_file_red, work_dir, product_id) histeq_cube(out_file_green, work_dir, product_id) histeq_cube(out_file_blue, work_dir, product_id) if is_verbose: print "Exporting Map Projected Tiffs..." else: printProgress(8, num_steps, prefix="%s: " % from_file_name) export(out_file_red, is_verbose) export(out_file_green, is_verbose) export(out_file_blue, is_verbose) if is_verbose: print "Camera Projecting Mosaics..." else: printProgress(9, num_steps, prefix="%s: " % from_file_name) pad_file = "%s/__%s_raw_GREEN_00%d_padded.cub" % (work_dir, product_id, mid_num) utility.pad(mid_file, pad_file, top=2300, right=0, bottom=2300, left=0) out_file_red_cam = "%s/%s_%s_Recammed.cub" % (source_dirname, product_id, "RED") cameras.map2cam(out_file_red, out_file_red_cam, pad_file) out_file_green_cam = "%s/%s_%s_Recammed.cub" % (source_dirname, product_id, "GREEN") cameras.map2cam(out_file_green, out_file_green_cam, pad_file) out_file_blue_cam = "%s/%s_%s_Recammed.cub" % (source_dirname, product_id, "BLUE") cameras.map2cam(out_file_blue, out_file_blue_cam, pad_file) if "histeq" in additional_options and additional_options["histeq"].upper( ) in ("TRUE", "YES"): if is_verbose: print "Running histogram equalization on camera projected cubes..." else: printProgress(10, num_steps, prefix="%s: " % from_file_name) histeq_cube(out_file_red_cam, work_dir, product_id) histeq_cube(out_file_green_cam, work_dir, product_id) histeq_cube(out_file_blue_cam, work_dir, product_id) if is_verbose: print "Exporting Camera Projected Tiffs..." else: printProgress(11, num_steps, prefix="%s: " % from_file_name) export(out_file_red_cam, is_verbose) export(out_file_green_cam, is_verbose) export(out_file_blue_cam, is_verbose) if is_verbose: print "Exporting Color Camera Projected Tiff..." else: printProgress(12, num_steps, prefix="%s: " % from_file_name) out_file_cam_rgb_tiff = "%s/%s_RGB.tif" % (source_dirname, product_id) s = importexport.isis2std_rgb(from_cube_red=out_file_red_cam, from_cube_green=out_file_green_cam, from_cube_blue=out_file_blue_cam, to_tiff=out_file_cam_rgb_tiff) if is_verbose: print s if nocleanup is False: if is_verbose: print "Cleaning up..." else: printProgress(13, num_steps, prefix="%s: " % from_file_name) clean_dir(work_dir, product_id) clean_dir(mapped_dir, product_id) dirname = os.path.dirname(out_file_red) if len(dirname) > 0: dirname += "/" if os.path.exists("%sprint.prt" % dirname): os.unlink("%sprint.prt" % dirname) else: if is_verbose: print "Skipping clean up..." else: printProgress(13, num_steps, prefix="%s: " % from_file_name) if not is_verbose: printProgress(14, num_steps, prefix="%s: " % from_file_name)