def create_RED45_mosaic(obsid, overwrite=False): gp_root = io.get_ground_projection_root() logger.info('Processing the EDR data associated with ' + obsid) mos_path = gp_root / obsid / f'{obsid}_mosaic_RED45.cub' # bail out if exists: if mos_path.exists() and not overwrite: print(f'{mos_path} already exists and I am not allowed to overwrite.') return obsid, True products = get_RED45_mosaic_inputs(obsid, gp_root) for prod in products: prod.download() nocal_hi(prod) norm_paths = [] for channel_products in [products[:2], products[2:]]: norm_paths.append(stitch_cubenorm(*channel_products)) # handmos part norm4, norm5 = norm_paths im0 = CubeFile.open(str(norm4)) # use CubeFile to get lines and samples # get binning mode from label bin_ = int( getkey(from_=str(norm4), objname="isiscube", grpname="instrument", keyword="summing")) # because there is a gap btw RED4 & 5, nsamples need to first make space # for 2 cubs then cut some overlap pixels try: handmos(from_=str(norm4), mosaic=str(mos_path), nbands=1, outline=1, outband=1, create='Y', outsample=1, nsamples=im0.samples * 2 - 48 // bin_, nlines=im0.lines) except ProcessError as e: print("STDOUT:", e.stdout) print("STDERR:", e.stderr) im0 = CubeFile.open(str(norm5)) # use CubeFile to get lines and samples # deal with the overlap gap between RED4 & 5: handmos(from_=str(norm5), mosaic=str(mos_path), outline=1, outband=1, create='N', outsample=im0.samples - 48 // bin_ + 1) for norm in [norm4, norm5]: norm.unlink() return obsid, True
def clem_or_wac(img_name): ''' Reads in image, reads extension, Python arrays are y, x instead of isis x, y => take the transpose of the image data array totally rewrite this so that the function only does 1 thing, not two. Ideally the function should only differentiate between wac and clm files, not do math. ''' image = CubeFile.open(source_dir+img_name) # pysis.cubefile.CubeFile if img_name[-7:-4] == 'wac': wac_320 = image.apply_numpy_specials()[0].T print wac_320 wac_415 = image.apply_numpy_specials()[2].T # tell pandas to handle the very negative numbers wac_320_over_415 = wac_320/wac_415 #print wac_320_over_415 return img_name[-7:-4], wac_320_over_415 #return img_name[-7:-4], wac_415 elif img_name[-7:-4] == 'clm': clm_950 = image.apply_numpy_specials()[3].T clm_750 = image.apply_numpy_specials()[1].T clm_950_over_750 = clm_950/clm_750 print clm_950 # tell pandas to handle the very negative numbers return img_name[-7:-4], clm_950_over_750 #return img_name[-7:-4], clm_750 else: print 'This is not a input cube that works with this script.'
def main(): parser = ArgumentParser(description='Generate volume estimates using WAC DTM') parser.add_argument('image', metavar='cub', help='the topo cube file(s) (.cub) to process') parser.add_argument('mask', metavar='cub', help='the mask that outlines the roi for volume calculation') parser.add_argument('--pixelscale', '-p', default=100, help='pixelscale of input images in meters per pixel') parser.add_argument('--referenceplane', '-r', default=0, help='plane of reference for volume calculation at an elevation') args = parser.parse_args() # args.image # args.mask # args.pixelscale # args.referenceplane # open and read in WAC DTM cube file topo_image = CubeFile.open(args.image) # open and read in mask file (tif or png) mask_image = Image.open(args.mask) # Check to see that the files are the same size => this doesn't work #print "samples match:", topo_image.samples == mask_image.samples #print "lines match:", topo_image.lines == mask_image.lines get_volume(topo_image, mask_image, args)
def create_RED45_mosaic(obsid, overwrite=False): gp_root = io.get_ground_projection_root() logger.info('Processing the EDR data associated with ' + obsid) mos_path = gp_root / obsid / f'{obsid}_mosaic_RED45.cub' # bail out if exists: if mos_path.exists() and not overwrite: print(f'{mos_path} already exists and I am not allowed to overwrite.') return obsid, True products = get_RED45_mosaic_inputs(obsid, gp_root) for prod in products: prod.download() nocal_hi(prod) norm_paths = [] for channel_products in [products[:2], products[2:]]: norm_paths.append(stitch_cubenorm(*channel_products)) # handmos part norm4, norm5 = norm_paths im0 = CubeFile.open(str(norm4)) # use CubeFile to get lines and samples # get binning mode from label bin_ = int(getkey(from_=str(norm4), objname="isiscube", grpname="instrument", keyword="summing")) # because there is a gap btw RED4 & 5, nsamples need to first make space # for 2 cubs then cut some overlap pixels try: handmos(from_=str(norm4), mosaic=str(mos_path), nbands=1, outline=1, outband=1, create='Y', outsample=1, nsamples=im0.samples * 2 - 48 // bin_, nlines=im0.lines) except ProcessError as e: print("STDOUT:", e.stdout) print("STDERR:", e.stderr) im0 = CubeFile.open(str(norm5)) # use CubeFile to get lines and samples # deal with the overlap gap between RED4 & 5: handmos(from_=str(norm5), mosaic=str(mos_path), outline=1, outband=1, create='N', outsample=im0.samples - 48 // bin_ + 1) for norm in [norm4, norm5]: norm.unlink() return obsid, True
def make_cloud_plot(image_list, color, groupname): ''' Just pass one of the image_list ''' for img_name in image_list: roi_name = os.path.basename(img_name)[:-8] base_path = img_name[:-8] image1 = CubeFile.open(img_name) # pysis.cubefile.CubeFile wac_320 = image1.apply_numpy_specials()[0].T wac_360 = image1.apply_numpy_specials()[1].T wac_415 = image1.apply_numpy_specials()[2].T wac_566 = image1.apply_numpy_specials()[3].T image2 = CubeFile.open(base_path+'_clm.cub') # pysis.cubefile.CubeFile clm_750 = image2.apply_numpy_specials()[1].T clm_950 = image2.apply_numpy_specials()[3].T clm_415 = image2.apply_numpy_specials()[0].T xaxis = wac_320/wac_415 yaxis = clm_950/clm_750 plt.scatter(xaxis, yaxis, marker='.', label=(roi_name), c=color, edgecolor=color)
def main(): parser = ArgumentParser(description='Create plots for topo data') parser.add_argument('image', metavar='cub', help='the cube file(s) (.cub) to process, no NULL pixels') parser.add_argument('--units', '-u', default='Elevation (m)', help='Pixel units of the input image') parser.add_argument('--contours', '-c', default=True, help='set to True for contour lines') parser.add_argument('--cinterval', '-i', default='10', help='interval in meters for contour lines') args = parser.parse_args() img = CubeFile.open(args.image) color_plot_2D(img, args)
def main(): parser = ArgumentParser(description='Create plots for topo data') #parser.add_argument('image', metavar='cub', # help='the cube file(s) (.cub) to process, no NULL pixels') parser.add_argument('outname', help='the output filename, no extension') parser.add_argument('GLD_slice', metavar='cub', help='the WAC GLD100 slice to use (full path) (.cub)') parser.add_argument('--type', '-t', default='2D', help='type of plot: 2D or 3D') parser.add_argument('--contours', '-c', default=True, help='set to True for contour lines') parser.add_argument('--cinterval', '-i', default='10', help='interval in meters for contour lines') args = parser.parse_args() minlat, maxlat, minlon, maxlon = get_center_lat_lon() center_lat = minlat + (maxlat - minlat)/2 center_lon = minlon + (maxlon - minlon)/2 # TODO: equirectangular is hardcoded at the moment # TODO: orthographic gives incorrect output... why? isis.maptemplate(map='wac_GLD100.map', projection='equirectangular', clat=center_lat, clon=center_lon, rngopt='user', resopt='mpp', resolution=100, minlat=minlat, maxlat=maxlat, minlon=minlon, maxlon=maxlon) isis.map2map(from_=args.GLD_slice, map='wac_GLD100.map', to=args.outname+'.cub', matchmap='true') img = CubeFile.open(args.outname+'.cub') if args.type == '2D': color_plot_2D(img, args) if args.type == '3D': color_topo_3D(img, args) img.data # np array with the image data
def test_cubefile(): filename = os.path.join(DATA_DIR, 'pattern.cub') image = CubeFile.open(filename) assert image.filename == filename assert image.bands == 1 assert image.lines == 90 assert image.samples == 90 assert image.tile_lines == 128 assert image.tile_samples == 128 assert image.format == 'Tile' assert image.dtype == numpy.dtype('float32') assert image.base == 0.0 assert image.multiplier == 1.0 assert image.start_byte == 65536 assert image.shape == (1, 90, 90) assert image.size == 8100 assert image.data.shape == (1, 90, 90) assert image.data.size == 8100 expected = numpy.loadtxt(os.path.join(DATA_DIR, 'pattern.txt'), skiprows=2) assert_almost_equal(image.data[0], expected)
def main(): parser = ArgumentParser(description='Create plots for topo data') parser.add_argument('image', metavar='cub', help='the cube file(s) (.cub) to process, no NULL pixels') parser.add_argument('outname', help='the output filename, no extension') parser.add_argument('--type', '-t', default='2D', help='type of plot: 2D or 3D') parser.add_argument('--contours', '-c', default=True, help='set to True for contour lines') parser.add_argument('--cinterval', '-i', default='10', help='interval in meters for contour lines') args = parser.parse_args() img = CubeFile.open(args.image) if args.type == '2D': color_plot_2D(img, args) if args.type == '3D': color_topo_3D(img, args) img.data # np array with the image data
# In[57]: some_unlits['emission1'] = some_unlits.id.map(f) # In[58]: some_lits.emission1 # In[59]: some_unlits.emission1 # In[1]: from pysis import CubeFile # In[3]: cube = CubeFile.open("/Users/klay6683/Dropbox/data/ciss/SOI/N1467345444_2.map.dst.cal.cub") # In[ ]:
def main(): parser = ArgumentParser(description='Basic input') #parser.add_argument('rootpath', # help='the root path with the directory of images') parser.add_argument('csv_file', help='csv input file with profile parameters') parser.add_argument('--interp_type', '-i', help='nearest_neighbor or cubic') args = parser.parse_args() parameters = read_csv_data(args.csv_file) print parameters.size # DEBUG nadir_image = CubeFile.open('M177514916_2m_crop.cub') nadir_image_data = nadir_image.apply_scaling()[0].T.astype(np.float64) for i in range(0, parameters.size): image = CubeFile.open(parameters['image_filename'][i]) # pysis.cubefile.CubeFile # image_size = image.samples # in python arrays are [line, sample] instead of [sample, line] # Transpose to fix: # image_data = image.apply_scaling()[0].T.astype(np.float64) # type = numpy.ndarray image_data = image.apply_numpy_specials()[0].T.astype(np.float64) print np.min(image_data), np.max(image_data), np.mean(image_data) print parameters['image_filename'][i] x, x0, x1, y, y1, y0 = get_lines(i, parameters) zi = get_profile(image_data, x, y) x,y = np.round(x).astype(np.int), np.round(y).astype(np.int) v = np.max(image_data) from itertools import combinations_with_replacement for dx, dy in combinations_with_replacement(xrange(-5, 5), 2): image_data[x+dx, y+dy] = v if dx == dy: continue image_data[x+dy, y+dx] = v\ #-- Plot... # plt.subplots returns fig, ax # fig is the matplotlib.figure.Figure object # ax can be either a single axis object or an array of axis objects # if more than one subplot was created. The dimensions of the resulting # array can be controlled with the squeeze keyword, see above. plt.figure(0) dem_axis = plt.subplot2grid((2,2), (0,0), colspan=1) image_axis = plt.subplot2grid((2,2), (0,1), colspan=1) profile_axis = plt.subplot2grid((2,2), (1,0), colspan=2) # fig, axes = plt.subplots(nrows=2) dem_axis.imshow(image_data.T) # Transpose done here dem_axis.plot([x0, x1], [y0, y1], 'w-') dem_axis.xaxis.tick_top() dem_axis.set_xlabel('samples') dem_axis.xaxis.set_label_position('top') dem_axis.set_ylabel('lines') # print dem_axis.get_ylim() # (2000.0, -500.0) # print dem_axis.get_xlim() # (-500.0, 2000.0) dem_axis.set_ylim(image.lines, 0) dem_axis.set_xlim(0, image.samples) print dem_axis.get_ylim() # debug print dem_axis.get_xlim() # debug image_axis.imshow(nadir_image_data.T, cmap='gray') # Transpose done here # cmap ='gray' looks washed out...' image_axis.plot([x0, x1], [y0, y1], 'r-') image_axis.set_ylim(nadir_image.lines, 0) image_axis.set_xlim(0, nadir_image.samples) image_axis.set_title('image') # IMAGE xy SCALE image_scale = 2 # units = meters per pixel # Create x axis vector to put plot in units of meters xi = np.arange(0, len(zi)*image_scale, image_scale) profile_axis.plot(xi, zi) profile_axis.set_xlabel('meters', fontsize=14) profile_axis.set_ylabel('elevation [meters]', fontsize=14) profile_axis.set_title('profile ' + parameters['id'][i], fontsize=14) profile_axis.axis('tight') # TODO: set aspect ratio for the topo profiles # axes[1].set_aspect('equal') profile_axis.set_aspect(5) plt.show() plt.savefig(str(i) + 'name.png', dpi=200)
def get_img_stats(name): cube = CubeFile.open(name) return band_means(cube.data), band_stds(cube.data)
def main(): parser = ArgumentParser(description='Basic input') parser.add_argument('csv_file', help='csv input file with locations') parser.add_argument('cube_file', help='cubefile to get values from') parser.add_argument('output_file', help='.csv for data') args = parser.parse_args() image = CubeFile.open(args.cube_file) # pysis.cubefile.CubeFile print 'image samples = %i' % image.samples print 'image lines = %i' % image.lines # python is y, x in an array instead of isis x, y, thus take the transpose of the # image data array #image_data = image.apply_scaling()[0].T.astype(np.float64) # type = numpy.ndarray #image_data = image.apply_scaling()[0].T #applies scaling and Transposes #image_data = image.data[0].T # gets data and transposes image_data = image.apply_scaling()[0].T.astype(np.int) points = read_csv_data(args.csv_file) # Prepare our csv output file data_out = csv.writer( open(args.output_file, 'wb'), delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL) data_out.writerow(['area_id', 'latitude', 'longitude', 'box_size_pixels', 'mean', 'stdev', 'boxsize']) # TODO: grab image resolution? # Calculate the stats for each region for i in range(0, len(points)): latitude = points['latitude'][i] longitude = points['longitude'][i] boxsize = points['box_size_pixels'][i] print 'boxsize = %i' % boxsize center_sample, center_line = get_sample_line(args.cube_file, latitude, longitude) print center_sample, center_line #debug # -1 is for the translation between isis and python # isis starts at 0 # python starts at 1 if boxsize == 1: offset = 0 area = image_data[center_sample-1, center_line-1] # isis => python pixel conversion print center_sample-1, center_line-1 print 'pixel value = %i' % area else: offset = int(boxsize/2) x0, x1 = center_sample-offset , center_sample+offset y0, y1 = center_line-offset, center_line+offset area = image_data[x0-1:x1-1, y0-1:y1-1] # isis => python pixel conversion data_out.writerow([ points['area_id'][i], points['latitude'][i], points['longitude'][i], area.mean(), area.std(), points['box_size_pixels'][i] ])