def plot_method_differences(strain_dictionary, average_strains, region, outdir, outfile): """Useful for dilatation and max shear based on values in the color bar""" pygmt.makecpt(C="polar", T="-300/300/2", G="-1.0/1.0", D="o", H=outdir+"/mycpt.cpt"); fig = pygmt.Figure(); proj = 'M2.2i' numrows = 2; numcols = 2; with fig.subplot(nrows=numrows, ncols=numcols, figsize=("7i", "6i"), frame="lrtb"): for i in range(numrows): # row number starting from 0 for j in range(numcols): # column number starting from 0 index = i * numcols + j # index number starting from 0 with fig.set_panel(panel=index): # sets the current panel fig.basemap(region=region, projection=proj, B=["WeSn", "2.0"]); fig.coast(region=region, projection=proj, N='1', W='1.0p,black', S='lightblue'); for counter, name in enumerate(strain_dictionary.keys()): if counter == index: plotting_data = np.subtract(strain_dictionary[name][2], average_strains); netcdf_read_write.produce_output_netcdf(strain_dictionary[name][0], strain_dictionary[name][1], plotting_data, 'per year', outdir + "/temp.grd"); fig.grdimage(outdir+'/temp.grd', projection=proj, region=region, C=outdir+"/mycpt.cpt"); fig.coast(region=region, projection=proj, N='1', W='1.0p,black', S='lightblue'); fig.text(position="BL", text=name+" minus mean", region=region, D='0/0.1i'); fig.colorbar(D="JCR+w4.0i+v+o0.7i/-0.5i", C=outdir+"/mycpt.cpt", G="-300/300", B=["x50", "y+L\"Nanostr/yr\""]); print("Saving Method Differences as %s." % outfile); fig.savefig(outfile); return;
def output_manager_coseismic(x, y, average_coseismic, outdir): rwr.produce_output_netcdf(x, y, average_coseismic, 'mm', outdir + '/coseismic.grd') netcdf_plots.produce_output_plot(outdir + '/coseismic.grd', 'LOS Displacement', outdir + '/coseismic.png', 'disp (mm)') return
def compare_grid_means(MyParams, filename, statistics_function, mask=None): """ A driver for taking the mean of several grid quantities The function for taking the mean/std is passed in `mask` has format [filename, cutoff_value] if you want to mask based on a particular computation result. """ strain_values_dict = velocity_io.read_multiple_strain_files( MyParams, filename) lons, lats, my_means, my_stds = compute_grid_statistics( strain_values_dict, statistics_function) if mask: [_, _, masking_values] = netcdf_read_write.read_any_grd(mask[0]) my_means = utilities.mask_by_value(my_means, masking_values, mask[1]) netcdf_read_write.produce_output_netcdf( lons, lats, my_means, 'per year', MyParams.outdir + "/means_" + filename) netcdf_read_write.produce_output_netcdf( lons, lats, my_stds, 'per year', MyParams.outdir + "/deviations_" + filename) if "dila" in filename or "max_shear" in filename: pygmt_plots.plot_method_differences( strain_values_dict, my_means, MyParams.range_strain, MyParams.outdir, MyParams.outdir + "/separate_plots_" + filename.split('.')[0] + '.png') return
def stack_corr_for_ref_unwrapped_isce(intf_files, rowref, colref, ts_output_dir, label=""): # WE MAKE SIGNAL SPREAD FOR CUT IMAGES cor_files = [ i.replace("fully_processed.unwrappedphase", "cut.cor") for i in intf_files ] # get for isce netcdfname = ts_output_dir + '/signalspread_cut_ref' + label + '.nc' cor_value = np.nan cor_data = readmytupledata.reader_isce(cor_files) a = stack_corr.stack_corr(cor_data, cor_value) rwr.produce_output_netcdf(cor_data.xvalues, cor_data.yvalues, a, 'Percentage', netcdfname) netcdf_plots.produce_output_plot( netcdfname, 'Signal Spread above cor=' + str(cor_value), ts_output_dir + '/signalspread_cut_ref' + label + '.png', 'Percentage of coherence', aspect=1 / 4, invert_yaxis=False, dot_points=[[colref], [rowref]]) signal_spread_ref = a[rowref, colref] print("Signal Spread of the reference pixel = %.2f " % signal_spread_ref) if signal_spread_ref < 50: print( "WARNING: Your reference pixel has very low coherence. Consider picking a different one." ) print("STOPPING ON PURPOSE.") sys.exit(0) return
def combine_all_files(datestr, input_dirs, output_dir): print("\nCombining files for date %s" % datestr) filename = input_dirs[0] + "/" + datestr + ".grd" xdata, ydata, zdata0 = read_netcdf3(filename) filename1 = input_dirs[1] + "/" + datestr + ".grd" xdata, ydata, zdata1 = read_netcdf3(filename1) zdata_total = np.zeros(np.shape(zdata0)) for j in range(len(ydata)): if np.mod(j, 200) == 0: print(j) for k in range(len(xdata)): vector = [zdata0[j][k], zdata1[j][k]] # , zdata2[j][k], zdata3[j][k], zdata4[j][k], zdata5[j][k], zdata6[j][k] ]; zdata_total[j][k] = np.sum(vector) output_file = output_dir + "/" + datestr + ".grd" output_plot = output_dir + "/" + datestr + ".png" produce_output_netcdf(xdata, ydata, zdata_total, "mm", output_file) netcdf_plots.produce_output_plot(output_file, datestr, output_plot, "mm", aspect=1.0, invert_yaxis=True, vmin=-50, vmax=100) return
def drive_tape(myParams): # generic steps indir = "../compearth/surfacevel2strain/matlab_output/" print("Producing gridded dataset of: ") x, y, tt, tp, pp = input_tape( indir, "cascadia_d02_q03_q06_b1_2D_s1_u1_strain.dat", "cascadia_d02_q03_q06_b1_2D_s1_u1_Dtensor_6entries.dat") [I2nd, max_shear, _, e1, e2, v00, v01, v10, v11, dilatation] = compute_tape(tt, tp, pp) # second invariant newx, newy, newI2nd = nn_interp(x, y, I2nd, myParams.coord_box, myParams.grid_inc) output_tape(newx, newy, newI2nd, myParams.outdir, "I2nd.nc") # dilatation newx, newy, newdila = nn_interp(x, y, dilatation, myParams.coord_box, myParams.grid_inc) output_tape(newx, newy, newdila, myParams.outdir, "dila.nc") # max shear newx, newy, newmax = nn_interp(x, y, max_shear, myParams.coord_box, myParams.grid_inc) output_tape(newx, newy, newmax, myParams.outdir, "max_shear.nc") # azimuth azimuth = strain_tensor_toolbox.max_shortening_azimuth( e1, e2, v00, v01, v10, v11) newx, newy, newaz = nn_interp(x, y, azimuth, myParams.coord_box, myParams.grid_inc) netcdf_read_write.produce_output_netcdf(newx, newy, newaz, 'degrees', myParams.outdir + 'azimuth.nc') write_tape_eigenvectors(x, y, e1, e2, v00, v01, v10, v11) return
def cut_resampled_grid(outdir, filename, variable, config_params): # This is for metadata like lon, lat, and lookvector # Given an isce file and a set of bounds to cut the file, # Produce the isce data and gmtsar netcdf that match each pixel. temp = isce_read_write.read_scalar_data(outdir + "/" + filename) print("Shape of the " + variable + " file: ", np.shape(temp)) xbounds = [ float(config_params.xbounds.split(',')[0]), float(config_params.xbounds.split(',')[1]) ] ybounds = [ float(config_params.ybounds.split(',')[0]), float(config_params.ybounds.split(',')[1]) ] cut_grid = mask_and_interpolate.cut_grid(temp, xbounds, ybounds, fractional=True, buffer_rows=3) print("Shape of the cut lon file: ", np.shape(cut_grid)) nx = np.shape(cut_grid)[1] ny = np.shape(cut_grid)[0] isce_read_write.write_isce_data(cut_grid, nx, ny, "FLOAT", outdir + '/cut_' + variable + '.gdal') rwr.produce_output_netcdf(np.array(range(0, nx)), np.array(range(0, ny)), cut_grid, "degrees", outdir + '/cut_' + variable + '.nc') return
def drive_signal_spread_isce(corr_files, cutoff, output_dir, output_filename): cor_data = rmd.reader_isce(corr_files); a = stack_corr(cor_data, cutoff); netcdf_read_write.produce_output_netcdf(cor_data.xvalues, cor_data.yvalues, a, 'Percentage', output_dir+'/' + output_filename); netcdf_plots.produce_output_plot(output_dir + '/' + output_filename, 'Signal Spread above cor=' + str(cutoff), output_dir + '/signalspread_full.png', 'Percentage of coherence', aspect=1 / 4, invert_yaxis=False); return;
def write_APS_to_files(xdata, ydata, aps_array, dates, iteration): nsar = np.shape(aps_array)[0] for i in range(nsar): filename = "APS_" + str(dates[i]) + "_IT" + str(iteration) + ".grd" netcdf_read_write.produce_output_netcdf(xdata, ydata, aps_array[i][:][:], '', filename) netcdf_read_write.flip_if_necessary(filename) return
def drive_signal_spread_calculation(corr_files, cutoff, output_dir, output_filename): print("Making stack_corr") output_file = output_dir + "/" + output_filename mytuple = rmd.reader(corr_files) a = stack_corr(mytuple, cutoff) # if unwrapped files, we use Nan to show when it was unwrapped successfully. netcdf_read_write.produce_output_netcdf(mytuple.xvalues, mytuple.yvalues, a, 'Percentage', output_file) netcdf_plots.produce_output_plot(output_file, 'Signal Spread', output_dir + '/signalspread.png', 'Percentage of coherence (out of ' + str(len(corr_files)) + ' images)', aspect=1.2); return;
def dummy_signal_spread(intfs, output_dir, output_filename): """ Make a perfect signal spread for passing to other applications """ print("Making a dummy signal spread that matches interferograms' dimensions (perfect 100)."); output_filename = output_dir + "/" + output_filename; [xdata, ydata, zdata] = netcdf_read_write.read_netcdf4(intfs[0]); a = np.add(np.zeros(np.shape(zdata)), 100); netcdf_read_write.produce_output_netcdf(xdata, ydata, a, 'Percentage', output_filename, dtype=np.float32) netcdf_plots.produce_output_plot(output_filename, 'Signal Spread', output_dir + '/signalspread.png', 'Percentage of coherence (out of ' + str(len(intfs)) + ' images)', aspect=1.2); return;
def generate_reflon_reflat(velfile, veldir, rowref, colref): # In this part, I sometimes need to flip the x-axis of the input array to make sense with geographic coordinates. # I suspect that for ascending orbits, this may not be necessary. # Worth checking if it introduces bugs. # Here we will use GMTSAR to geocode a small region including the reference pixel. # We extract the latitude and longitude of the reference pixel. refpoint_file = 'reference_point.grd' # names only here. directory gets added later. ref_ll_name = 'ref_ll' # These are temporary files. ref_ll = ref_ll_name + '.grd' [xdata, ydata, zdata] = netcdf_read_write.read_any_grd(velfile) # Flipping the x-axis direction and the data itself. Required for descending data, unsure about ascending. # All of this will change with better grid referencing in the future. colref = len(xdata) - 1 - colref # rowref = len(ydata)-1-rowref; zdata = np.fliplr(zdata) # In general we can figure this out from the flight_angle. print("\nHello! Your reference pixel is (row,col) = (%d, %d)" % (rowref, colref)) print("Its velocity is %.2f mm/yr\n" % zdata[rowref][colref]) print("Its azimuth is %.2f " % ydata[rowref]) print("Its range is %.2f \n\n" % xdata[colref]) rowarray = np.array([ydata[rowref], ydata[rowref + 1]]) colarray = np.array([xdata[colref], xdata[colref + 1]]) plt.figure() plt.imshow(zdata, vmin=-20, vmax=20, cmap='jet') plt.plot(colref, rowref, '.', markersize=10, color='k') plt.savefig('refpoint.eps') zarray = np.array([[0.0, 0.01], [0.01, 0.01]]) netcdf_read_write.produce_output_netcdf(colarray, rowarray, zarray, 'mm/yr', veldir + '/' + refpoint_file) netcdf_read_write.flip_if_necessary(veldir + '/' + refpoint_file) subprocess.call( ['geocode_mod.csh', refpoint_file, ref_ll, ref_ll_name, veldir], shell=False) [xll, yll, _] = netcdf_read_write.read_any_grd(veldir + '/' + ref_ll) latref = yll[0] lonref = xll[0] print("\nReference Location is: ", lonref, latref) subprocess.call(['rm', veldir + '/' + ref_ll_name + '.png'], shell=False) subprocess.call(['rm', veldir + '/' + ref_ll_name + '.kml'], shell=False) return [lonref, latref]
def output_manager_simple_stack(x, y, velocities, rowref, colref, signal_spread_data, outdir): rwr.produce_output_netcdf(x, y, velocities, 'mm/yr', outdir + '/velo_simple_stack.grd') netcdf_plots.produce_output_plot(outdir + '/velo_simple_stack.grd', 'LOS Velocity ', outdir + '/velo_simple_stack.png', 'velocity (mm/yr)') stacking_utilities.report_on_refpixel(rowref, colref, signal_spread_data, outdir) return
def intf_stack_to_grds(xdata, ydata, corrected_intfs, date_pairs, out_dir): print("Writing corrected interferograms to file. ") zdim, rowdim, coldim = np.shape(corrected_intfs) for i in range(zdim): item_name = date_pairs[i] netcdfname = out_dir + '/' + item_name + '_unwrap.grd' netcdf_read_write.produce_output_netcdf(xdata, ydata, corrected_intfs[i][:][:], 'unwrapped_phase', netcdfname) netcdf_read_write.flip_if_necessary(netcdfname) return
def multiply_file_by_minus1(filename, new_filename): print("multiplying %s by -1 " % filename) x, y, z = netcdf_read_write.read_netcdf4(filename) z = np.multiply(z, -1) netcdf_read_write.produce_output_netcdf(x, y, z, "mm/yr", new_filename, dtype=np.float32) return
def signal_spread_to_mask(ss_file, cutoff, mask_file): """ Given a signal spread file, make a nice mask that we can use for plotting.""" [xdata, ydata, zdata] = netcdf_read_write.read_netcdf3(ss_file); mask_response = np.zeros(np.shape(zdata)); for i in range(len(ydata)): for j in range(len(xdata)): if zdata[i][j] >= cutoff: mask_response[i][j] = 1; else: mask_response[i][j] = np.nan; netcdf_read_write.produce_output_netcdf(xdata, ydata, mask_response, 'unitless', mask_file); return;
def test_read_write_cycle(filename): # A TEST OF READ/WRITE FUNCTIONS # Step 1: Read ISCE interferogram as phase # Step 2: Write it as ISCE format data # Step 3: Read ISCE interferogram again # Step 4: Write as .grd # Step 5: make plot. # RESULT: PRETTY GOOD! There is a flipup between the ISCE/GMTSAR conventions, # but it might never really be a problem. # Step 1: read phase slc = isce_read_write.read_phase_data(filename) print("Shape of slc is ", np.shape(slc)) isce_read_write.plot_complex_data(filename, aspect=1 / 10, outname="original.png") # Step 2: write ISCE data file ny, nx = np.shape(slc) # dtype = 'FLOAT'; isce_written = "isce_written_phase.phase" isce_read_write.write_isce_data(slc, nx, ny, dtype="FLOAT", filename=isce_written) # Step 3: read phase again. phase = isce_read_write.read_scalar_data(isce_written + ".vrt") print("Shape of phase is ", np.shape(phase)) isce_read_write.plot_scalar_data("isce_written_phase.phase", colormap='rainbow', aspect=1 / 10, outname="isce_written_phase.png") # Step 4: write that phase as grd. netcdfname = "netcdf_written_phase.grd" xdata = np.arange(0, nx) ydata = np.arange(0, ny) phase = np.flipud(phase) # THIS SEEMS TO BE NECESSARY TO SWITCH BETWEEN CONVENTIONS. GRD PLOTS ARE UPSIDE DOWN FROM ISCE. netcdf_read_write.produce_output_netcdf(xdata, ydata, phase, "radians", netcdfname) # Step 5: look at what's inside; netcdf_plots.produce_output_plot(netcdfname, "phase", "grdstyle_phase.png", "radians", aspect=1 / 10) return
def make_vels_from_ts_grids(param_dictionary, ts_slice_files): """ Given existing TS grid files, create an estimate of velocity. """ mydata = rmd.reader_from_ts(ts_slice_files) # read filelist of time series grids vel = nsbas.Velocities_from_TS(mydata) rwr.produce_output_netcdf( mydata.xvalues, mydata.yvalues, vel, 'mm/yr', param_dictionary["ts_output_dir"] + '/velo_nsbas.grd') netcdf_plots.produce_output_plot( param_dictionary["ts_output_dir"] + '/velo_nsbas.grd', 'LOS Velocity', param_dictionary["ts_output_dir"] + '/velo_nsbas.png', 'velocity (mm/yr)') return
def make_vel_unc_from_ts_grids(ts_slice_files, outdir): """ Given existing TS grid files, create an estimate of velocity uncertainty. I have called this function from outside of the program. Can be called separately. """ mydata = rmd.reader_from_ts(ts_slice_files) # read filelist of time series grids unc = velo_uncertainties.empirical_uncertainty(mydata) rwr.produce_output_netcdf(mydata.xvalues, mydata.yvalues, unc, 'mm/yr', outdir + '/velo_unc.grd') netcdf_plots.produce_output_plot(outdir + '/velo_unc.grd', 'LOS Uncertainty', outdir + '/velo_unc.png', 'Uncertainty (mm/yr)') return
def drive_velocity(param_dict, intf_files, coh_files): intf_tuple, coh_tuple, baseline_tuple = param_dict["reader"]( intf_files, coh_files, param_dict["baseline_file"], param_dict["ts_type"], param_dict["dem_error"]) [_, _, signal_spread_tuple ] = rwr.read_any_grd(param_dict["signal_spread_filename"]) velocities, metrics = nsbas.Velocities(param_dict, intf_tuple, signal_spread_tuple, baseline_tuple, coh_tuple) rwr.produce_output_netcdf(intf_tuple.xvalues, intf_tuple.yvalues, velocities, 'mm/yr', param_dict["ts_output_dir"] + '/velo_nsbas.grd') netcdf_plots.produce_output_plot( param_dict["ts_output_dir"] + '/velo_nsbas.grd', 'LOS Velocity', param_dict["ts_output_dir"] + '/velo_nsbas.png', 'velocity (mm/yr)') return
def read_and_reapply_mask(mask): # re-apply the mask unw_grd = netcdf_read_write.read_netcdf4("unwrap.grd") unw_grd = np.multiply(unw_grd, mask) xdata = range(0, np.shape(unw_grd)[1]) ydata = range(0, np.shape(unw_grd)[0]) netcdf_read_write.produce_output_netcdf(xdata, ydata, unw_grd, 'radians', 'unwrap_masked.grd') netcdf_plots.produce_output_plot('unwrap_masked.grd', 'Unwrapped Phase', 'unw_masked.png', 'phase', aspect=1.0, invert_yaxis=False) return
def write_output_metrics(param_dict, intf_tuple, metrics): """Unpack the dictionary that contains output metrics (if any), write into files. """ if param_dict["dem_error"]: gridshape = np.shape(metrics) Kz_grid = np.zeros(gridshape) for i in range(gridshape[0]): for j in range(gridshape[1]): if "Kz_error" in metrics[i][j].keys(): Kz_grid[i][j] = metrics[i][j]["Kz_error"] rwr.produce_output_netcdf( intf_tuple.xvalues, intf_tuple.yvalues, Kz_grid, 'm', param_dict["ts_output_dir"] + '/kz_error.grd') netcdf_plots.produce_output_plot( param_dict["ts_output_dir"] + '/kz_error.grd', 'DEM Error', param_dict["ts_output_dir"] + '/kz_error.png', 'DEM Error (m)') return
def mask_by_value(outdir, grid1, grid2, cutoff_value): # grid1 = usually azimuth deviations # grid2 = usually I2nd lon1, lat1, val1 = netcdf_read_write.read_any_grd(outdir + "/deviations_" + grid1 + ".nc") lon2, lat2, val2 = netcdf_read_write.read_any_grd(outdir + "/means_" + grid2 + ".nc") masked_vals = np.zeros(np.shape(val2)) for i in range(len(lon1)): for j in range(len(lat1)): if abs(val2[j][i]) > cutoff_value: masked_vals[j][i] = val1[j][i] else: masked_vals[j][i] = np.nan netcdf_read_write.produce_output_netcdf( lon1, lat1, masked_vals, 'per yr', outdir + "/deviations_" + grid1 + ".nc") return
def cut_and_write_out_igram(real, imag, corr, cut_rowcol): """Cut imag, real, and corr arrays; write them in lots of formats.""" real = real[cut_rowcol[0]:cut_rowcol[1], cut_rowcol[2]:cut_rowcol[3]] imag = imag[cut_rowcol[0]:cut_rowcol[1], cut_rowcol[2]:cut_rowcol[3]] corr = corr[cut_rowcol[0]:cut_rowcol[1], cut_rowcol[2]:cut_rowcol[3]] phase = np.arctan2(imag, real) complex_numbers = np.float32(real) + 1j * np.float32(imag) cor32 = np.float32(corr) xdata = range(0, np.shape(phase)[1]) ydata = range(0, np.shape(phase)[0]) (ny, nx) = np.shape(phase) netcdf_read_write.produce_output_netcdf(xdata, ydata, phase, 'radians', 'phase.grd', dtype=float) netcdf_read_write.produce_output_netcdf(xdata, ydata, corr, 'corr', 'corr.grd', dtype=float) netcdf_plots.produce_output_plot('phase.grd', 'Phase', 'phase.png', 'phase', aspect=1.0, invert_yaxis=False) netcdf_plots.produce_output_plot('corr.grd', 'Coherence', 'corr.png', 'corr', aspect=1.0, cmap='binary_r', invert_yaxis=False) isce_read_write.write_isce_data(complex_numbers, nx, ny, 'CFLOAT', 'cut_slc.int') isce_read_write.write_isce_data(cor32, nx, ny, 'FLOAT', 'cut_cor.cor') return
def phase_interpolation(phase): """Perform phase interpolation""" interp_array = mask_and_interpolate.interpolate_2d(phase) xdata = range(0, np.shape(phase)[1]) ydata = range(0, np.shape(phase)[0]) netcdf_read_write.produce_output_netcdf(xdata, ydata, interp_array, 'radians', 'phase_interp.grd', dtype=float) netcdf_plots.produce_output_plot('phase_interp.grd', 'Phase', 'phase_interp.png', 'phase', aspect=1.0, invert_yaxis=False) return interp_array
def make_outlier_mask_for_stack(filelist, maskfile, outlier_cutoff=1e4): """ Make a mask that is ones and nans Given a co-registered stack If a pixel is above the outlier cutoff in any image of the stack, make a nanmask that masks that pixel. """ filename = filelist[1] x, y, z = netcdf_read_write.read_any_grd( filename) # just to get the shape of the outputs crazy_mask = np.ones(np.shape(z)) for ifile in filelist: print(ifile) x, y, ztemp = netcdf_read_write.read_any_grd(ifile) for i in range(len(y)): for j in range(len(x)): if abs(ztemp[i][j]) > outlier_cutoff: crazy_mask[i][j] = np.nan # Put all the crazy pixels into a mask (across all images in the stack). netcdf_read_write.produce_output_netcdf(x, y, crazy_mask, "", maskfile) return
def output_item(xdata, ydata, zdata, corrected_zdata, zarray, corrarray, demarray, item, outdir): item_name = item.split('/')[-1] item_name_short = item_name.split('unwrap.grd')[0] netcdfname = outdir + '/' + item_name netcdf_read_write.produce_output_netcdf(xdata, ydata, corrected_zdata, 'unwrapped_phase', netcdfname) netcdf_read_write.flip_if_necessary(netcdfname) plt.figure() plt.plot(demarray, zarray, '.') plt.plot(demarray, corrarray, '.r', alpha=0.15) plt.ylabel('phase') plt.xlabel('topo') plt.title('Initial and Corrected Phase vs. Topography') plt.savefig('intf_all/atm_topo_corrected.grd' + '/phase_topo_' + item_name_short + '.png') plt.close() plt.figure() plt.subplot(1, 2, 1) plt.imshow(zdata, cmap='hsv', vmin=np.min(zarray), vmax=np.max(zarray)) plt.title('Before Correction') plt.gca().invert_yaxis() plt.gca().invert_xaxis() plt.subplot(1, 2, 2) plt.imshow(corrected_zdata, cmap='hsv', vmin=np.min(zarray), vmax=np.max(zarray)) plt.title('After Correction') plt.gca().invert_yaxis() plt.gca().invert_xaxis() cb = plt.colorbar() cb.set_label("Unwrapped Phase (radians)", size=12) plt.savefig(outdir + '/imshow_' + item_name_short + '.png') plt.close() return
def multiply_igram_by_coherence_mask(after_filtering, after_filtering_corr, cutoff): """Multiply by coherence mask""" phase = isce_read_write.read_phase_data(after_filtering) corr = isce_read_write.read_scalar_data(after_filtering_corr) coherence_mask = mask_and_interpolate.make_coherence_mask(corr, cutoff) masked_phase = mask_and_interpolate.apply_coherence_mask( phase, coherence_mask) xdata = range(0, np.shape(phase)[1]) ydata = range(0, np.shape(phase)[0]) netcdf_read_write.produce_output_netcdf(xdata, ydata, phase, 'radians', 'phase_filtered.grd') netcdf_read_write.produce_output_netcdf(xdata, ydata, masked_phase, 'radians', 'phase_masked.grd', dtype=float) netcdf_read_write.produce_output_netcdf(xdata, ydata, corr, 'corr', 'corr.grd', dtype=float) netcdf_plots.produce_output_plot('phase_filtered.grd', 'Phase', 'phase_filtered.png', 'phase', aspect=1.0, invert_yaxis=False) netcdf_plots.produce_output_plot('phase_masked.grd', 'Phase', 'phase_masked.png', 'phase', aspect=1.0, invert_yaxis=False) netcdf_plots.produce_output_plot('corr.grd', 'Coherence', 'corr.png', 'corr', aspect=1.0, cmap='binary_r', invert_yaxis=False) return masked_phase, coherence_mask
def output_tape(lon, lat, vals, outdir, file): netcdf_read_write.produce_output_netcdf(lon, lat, vals, 'per yr', outdir + file) print("Success fitting wavelet-generated data to the required grid!") return
def outputs_2d(xdata, ydata, rot, exx, exy, eyy, MyParams, myVelfield): print("------------------------------\nWriting 2d outputs:") velocity_io.write_stationvels(myVelfield, MyParams.outdir + "tempgps.txt") [I2nd, max_shear, dilatation, azimuth ] = strain_tensor_toolbox.compute_derived_quantities(exx, exy, eyy) [e1, e2, v00, v01, v10, v11] = strain_tensor_toolbox.compute_eigenvectors(exx, exy, eyy) netcdf_read_write.produce_output_netcdf(xdata, ydata, exx, 'microstrain', MyParams.outdir + 'exx.nc') netcdf_read_write.produce_output_netcdf(xdata, ydata, exy, 'microstrain', MyParams.outdir + 'exy.nc') netcdf_read_write.produce_output_netcdf(xdata, ydata, eyy, 'microstrain', MyParams.outdir + 'eyy.nc') netcdf_read_write.produce_output_netcdf(xdata, ydata, azimuth, 'degrees', MyParams.outdir + 'azimuth.nc') netcdf_read_write.produce_output_netcdf(xdata, ydata, I2nd, 'per yr', MyParams.outdir + 'I2nd.nc') netcdf_read_write.produce_output_netcdf(xdata, ydata, rot, 'per yr', MyParams.outdir + 'rot.nc') netcdf_read_write.produce_output_netcdf(xdata, ydata, dilatation, 'per yr', MyParams.outdir + 'dila.nc') netcdf_read_write.produce_output_netcdf(xdata, ydata, max_shear, 'per yr', MyParams.outdir + 'max_shear.nc') print("Max I2: %f " % (np.amax(I2nd))) print("Min/Max rot: %f, %f " % (np.nanmin(rot), np.nanmax(rot))) # get grid eigenvectors for plotting [positive_eigs, negative_eigs] = get_grid_eigenvectors(xdata, ydata, e1, e2, v00, v01, v10, v11) velocity_io.write_gmt_format(positive_eigs, MyParams.outdir + 'positive_eigs.txt') velocity_io.write_gmt_format(negative_eigs, MyParams.outdir + 'negative_eigs.txt') # PYGMT PLOTS pygmt_plots.plot_rotation(MyParams.outdir + 'rot.nc', myVelfield, MyParams.range_strain, MyParams.outdir, MyParams.outdir + 'rotation.png') pygmt_plots.plot_dilatation(MyParams.outdir + 'dila.nc', MyParams.range_strain, MyParams.outdir, positive_eigs, negative_eigs, MyParams.outdir + 'dilatation.png') pygmt_plots.plot_I2nd(MyParams.outdir + 'I2nd.nc', MyParams.range_strain, MyParams.outdir, positive_eigs, negative_eigs, MyParams.outdir + 'I2nd.png') pygmt_plots.plot_maxshear(MyParams.outdir + 'max_shear.nc', MyParams.range_strain, MyParams.outdir, positive_eigs, negative_eigs, MyParams.outdir + 'max_shear.png') pygmt_plots.plot_azimuth(MyParams.outdir + 'azimuth.nc', MyParams.range_strain, MyParams.outdir, positive_eigs, negative_eigs, MyParams.outdir + 'azimuth.png') return