def main(): stack_path = './data/stacks/' stack_fname = 'enderlin_velocity_stack.hdf5' pre_transect_fname = 'landsat_pre_transect.npy' transect_fname = 'landsat_transect.npy' landsat8_raster_fname = './data/landsat8/LC08_L1TP_066017_20140224_20170306_01_T1/LC08_L1TP_066017_20140224_20170306_01_T1_B1.TIF' # Load Stack header hdr = ice.RasterInfo(stackfile=stack_path + stack_fname) # Load landsat 8 Raster e = hdr.extent proj_win = [e[0], e[3], e[1], e[2]] raster = ice.Raster(rasterfile=landsat8_raster_fname, projWin=proj_win) # Get reference x, y points to extract centerline from x, y = get_transect_points(raster, stack_path + pre_transect_fname) # plot_transect(raster, x, y, 'Hand crafted transect') xs, ys = resample_transect(raster, x, y) # Save transect s = 100 # Start point along transect (bottom is very noisy) np.save(stack_path + transect_fname, [xs[s:], ys[s:]]) plot_transect(raster, xs[s:], ys[s:], 'Columbia Manual Centerline Transect')
def calc_optimal_proj_win(path, rasterfiles): """ Find the window of maximum extent shared by all Rasters in dataset. Parameters ---------- path: str Path to directory storing all rasters rasterfiles: list List with the name of each rasterfile in the path Return ------ proj_win: list Optimal projection window for the data, with form [min_x, max_y, max_x, min_y] """ min_x, max_x, min_y, max_y = [], [], [], [] for rasterfile in rasterfiles: extent = ice.RasterInfo(path + rasterfile).extent min_x.append(extent[0]) max_x.append(extent[1]) min_y.append(extent[2]) max_y.append(extent[3]) return [max(min_x), min(max_y), min(max_x), max(min_y)]
def main(): enderlin_data_path = './data/enderlin2018/' stack_path = './data/stacks/' stack_fname = 'enderlin_velocity_stack.hdf5' landsat8_raster_fname = './data/landsat8/LC08_L1TP_066017_20140224_20170306_01_T1/LC08_L1TP_066017_20140224_20170306_01_T1_B1.TIF' # Get all raster files from manifest rasterfiles = [] with open(enderlin_data_path + 'MANIFEST.TXT', 'r') as f: for line in f: rasterfiles.append(line.split()[0]) # plot_with_landsat(landsat8_raster_fname, enderlin_data_path + rasterfiles[0], 'Enderlin velocity on Landsat 8 Image') # Get dates and data from files init_tdec, init_data = [], [] for rasterfile in rasterfiles: # Parse date from filename date = rasterfile.split('_')[1] tdec = ice.datestr2tdec(yy=int(date[0:4]), mm=int(date[4:6]), dd=int(date[6:8])) init_tdec.append(tdec) # Load file and get data raster = ice.Raster(rasterfile=enderlin_data_path + rasterfile) print(raster.hdr.extent) # Data is flipped - not sure why init_data.append(np.flip(raster.data, axis=0)) # Create Stack hdr = ice.RasterInfo(rasterfile=enderlin_data_path + rasterfiles[0]) stack = ice.Stack(stack_path + stack_fname, mode='w', init_tdec=np.array(init_tdec), init_rasterinfo=hdr) stack.fid.create_dataset("data", data=np.array(init_data)) stack.fid.close() plot_mean_with_landsat(landsat8_raster_fname, stack_path + stack_fname, "Mean Velocity")
def main(args): # Get rasterinfo if args.rasterfile.endswith('.h5'): stack = ice.Stack(args.rasterfile) hdr = stack.hdr tdec = stack.tdec else: hdr = ice.RasterInfo(args.rasterfile, match=args.match) tdec = None print('Image shape: (%d, %d)' % (hdr.ny, hdr.nx)) print('Geographic extent: %f %f %f %f' % tuple(hdr.extent)) print('Geographic spacing: (dy = %f, dx = %f)' % (hdr.dy, hdr.dx)) if tdec is not None: print('Time span: %f -> %f' % (tdec[0], tdec[-1])) print('Median time spacing: %f' % np.median(np.diff(tdec))) print('EPSG:', hdr.epsg)
def main(args): # Check if nothing is passed if args.projWin is None and args.srcWin is None and args.tWin is None: print('No cropping parameters provided.') return # Load stack stack = ice.Stack(args.stackfile) # Construct spatial slices if args.projWin is not None: # Unpack projWin parameters x0, y0, x1, y1 = args.projWin # Convert geographic coordinates to image coordinates i0, j0 = stack.hdr.xy_to_imagecoord(x0, y0) i1, j1 = stack.hdr.xy_to_imagecoord(x1, y1) islice = slice(i0, i1) jslice = slice(j0, j1) elif args.srcWin is not None: # Unpack srcWin parameters j0, i0, xsize, ysize = args.srcWin j1 = j0 + xsize i1 = i0 + ysize islice = slice(i0, i1) jslice = slice(j0, j1) else: islice = slice(0, stack.Ny) jslice = slice(0, stack.Nx) # Construct temporal subset if provided tdec = stack.tdec if args.tWin is not None: t0, tf = args.tWin k0 = np.argmin(np.abs(tdec - t0)) k1 = np.argmin(np.abs(tdec - tf)) tslice = slice(k0, k1) tdec = tdec[tslice] else: tslice = slice(0, stack.Nt) # Make meshgrid of coordinates X, Y = stack.hdr.meshgrid() # Apply slices if islice is not None and jslice is not None: X = X[islice, jslice] Y = Y[islice, jslice] # Create RasterInfo header hdr = ice.RasterInfo(X=X, Y=Y) # Create output stack ostack = ice.Stack(args.output, mode='w') ostack.initialize(tdec, hdr, data=True, weights=True, chunks=(1, args.chunks[0], args.chunks[1])) # Manually fill in the data try: ostack['data'][:, :, :] = stack['data'][tslice, islice, jslice] except KeyError: ostack['data'][:, :, :] = stack['igram'][tslice, islice, jslice] ostack['weights'][:, :, :] = stack['weights'][tslice, islice, jslice]
def main(): # Options choose_start_end = False save_transect = True smooth = True head = None terminus = None # Penalty for not following path of highest velocity # (prevents path from taking shortcuts) penalty = 12 if not choose_start_end: head = (671, 2035) # (row, col) terminus = (1958, 1406) # (row, col) # Open velocity Stack and get data print('Getting Stack mean ...............................................') stack_path = './data/stacks/' stack_fname = 'columbia_surface_velocities.hdf5' mean_fname = 'mean_columbia_surface_velocities.tif' transect_fname = 'columbia_centerline_transect.npy' mean, hdr = get_stack_mean(stack_path, stack_fname, mean_fname) # Find velocity inverse inv = 1 / mean**penalty # Request start and stop if not provided print('Getting path start and end points ................................') if head is None: head = get_point(mean, 'Please identify the glacier head', hdr) print('Columbia Glacier head at row, col =', head) if terminus is None: terminus = get_point(mean, 'Please identify the terminus', hdr) print('Columbia Glacier terminus at row, col =', terminus) # Dijkstra's shortest path print('Finding transect .................................................') start = time.time() transect, vis = dijkstra_transect(inv, head, terminus) dt = time.time() - start print('Found transect in', int(dt), 'seconds.') if smooth: transect = moving_avg(transect[0], transect[1]) hdr = ice.RasterInfo(stackfile=stack_path + stack_fname) tx, ty = hdr.imagecoord_to_xy(transect[0], transect[1]) plot_transect_visited(mean, hdr, tx, ty, vis) plot_transect_landsat(mean, hdr, tx, ty) print('Transect length:', int(ice.compute_path_length(tx, ty)[-1]), 'm') # Save path to file if save_transect: print( 'Saving transect to file ..........................................' ) np.save(stack_path + transect_fname, [tx, ty])