def inputs(file_names, config_params): [xdata,ydata] = netcdf_read_write.read_grd_xy(file_names[0]); data_all=[]; date_pairs=[]; dates=[]; start_dt = dt.datetime.strptime(str(config_params.start_time),"%Y%m%d"); end_dt = dt.datetime.strptime(str(config_params.end_time),"%Y%m%d"); for ifile in file_names: # this happens to be in date order on my mac pairname=ifile.split('/')[-1][0:15]; image1=pairname.split('_')[0]; image2=pairname.split('_')[1]; image1_dt = dt.datetime.strptime(image1,"%Y%j"); image2_dt = dt.datetime.strptime(image2,"%Y%j"); if image1_dt>=start_dt and image1_dt<= end_dt: if image2_dt>=start_dt and image2_dt <= end_dt: data = netcdf_read_write.read_grd(ifile); data_all.append(data); date_pairs.append(pairname); # returning something like '2016292_2016316' for each intf dates.append(image1); dates.append(image2); dates=list(set(dates)); dates=sorted(dates); print(dates); print("Reading %d interferograms from %d acquisitions. " % (len(date_pairs), len(dates) ) ); return [xdata, ydata, data_all, dates, date_pairs];
def inputs(file_names, skip_file): try: [xdata, ydata] = netcdf_read_write.read_grd_xy(file_names[0]) # can read either netcdf3 or netcdf4. except TypeError: [xdata, ydata, _] = netcdf_read_write.read_netcdf4_xyz(file_names[0]) data_all = [] date_pairs = [] file_names = sorted(file_names) # To force into date-ascending order. for ifile in file_names: # Read the data try: data = netcdf_read_write.read_grd(ifile) except TypeError: [_, _, data] = netcdf_read_write.read_netcdf4_xyz(ifile) data_all.append(data) pairname = ifile.split('/')[-2][0:15] date_pairs.append(pairname) # returning something like '2016292_2016316' for each intf print(pairname) skip_intfs = [] if skip_file is not None: ifile = open(skip_file, 'r') for line in ifile: skip_intfs.append(line.split()[0]) ifile.close() return [xdata, ydata, data_all, date_pairs, skip_intfs]
def inputs(file_names, start_time, end_time, run_type): # Read the input grd files. Support for netcdf3 and netcdf4. try: [xdata, ydata] = netcdf_read_write.read_grd_xy(file_names[0]) except TypeError: [xdata, ydata, _] = netcdf_read_write.read_netcdf4_xyz(file_names[0]) data_all = [] date_pairs = [] dates = [] start_dt = dt.datetime.strptime(str(start_time), "%Y%m%d") end_dt = dt.datetime.strptime(str(end_time), "%Y%m%d") # Get the dates of the acquisitions from the file names. for ifile in file_names: # this happens to be in date order on my mac if run_type == 'test': # testing with Kang's format. "20171117_20171123/unwrap_new.grd" pairname = ifile.split('/')[-2] image1 = pairname.split('_')[0] image2 = pairname.split('_')[1] image1_dt = dt.datetime.strptime(image1, "%Y%m%d") image2_dt = dt.datetime.strptime(image2, "%Y%m%d") else: # the usual GMTSAR format pairname = ifile.split('/')[-1][0:15] image1 = pairname.split('_')[0] image2 = pairname.split('_')[1] image1_dt = dt.datetime.strptime(image1, "%Y%j") image2_dt = dt.datetime.strptime(image2, "%Y%j") if image1_dt >= start_dt and image1_dt <= end_dt: if image2_dt >= start_dt and image2_dt <= end_dt: try: data = netcdf_read_write.read_grd(ifile) except TypeError: [_, _, data] = netcdf_read_write.read_netcdf4_xyz(ifile) if run_type == "test": data_all.append(data * -0.0555 / 4 / np.pi) # mcandis preprocessing involves changing to LOS distances. print( "Converting phase to LOS (mm) with 55.5mm wavelength") else: data_all.append(data) pairname = dt.datetime.strftime( image1_dt, "%Y%j") + '_' + dt.datetime.strftime( image2_dt, "%Y%j") date_pairs.append(pairname) # returning something like '2016292_2016316' for each intf dates.append(dt.datetime.strftime(image1_dt, "%Y%j")) dates.append(dt.datetime.strftime(image2_dt, "%Y%j")) data_all = np.array(data_all) # this allows easy indexing later on. dates = list(set(dates)) dates = sorted(dates) print(date_pairs) print("Reading %d interferograms from %d acquisitions. " % (len(date_pairs), len(dates))) return [xdata, ydata, data_all, dates, date_pairs]
def inputs(file_names): [xdata, ydata] = netcdf_read_write.read_grd_xy(file_names[0]) data_all = [] for ifile in file_names: # this happens to be in date order on my mac data = netcdf_read_write.read_grd(ifile) data_all.append(data) date_pairs = [] for name in file_names: pairname = name.split('/')[-2][0:15] date_pairs.append(pairname) # returning something like '2016292_2016316' for each intf print(pairname) return [xdata, ydata, data_all, date_pairs]
def readGRD(file_type): # Read in SAR data from .grd formatted file # INPUT FILES MUST BE LOCATED IN A GMTSAR DIRECTORY! # Path_list format: # 20170426_20170520/corr.grd # 20170426_20170601/corr.grd # 20170426_20170613/corr.grd # ... # Get list of file paths path_list = glob.glob("*/" + file_type) print('Number of files to read: ' + str(len(path_list))) # Establish tuple tupleGRD = collections.namedtuple('GRD_data', ['path_list', 'xdata', 'ydata', 'zdata']) # Get dimensional data try: [xdata, ydata] = netcdf_read_write.read_grd_xy( path_list[0]) # can read either netcdf3 or netcdf4. except TypeError: [xdata, ydata] = netcdf_read_write.read_netcdf4_xy(path_list[0]) # Loop through path_list to read in target datafiles zdata = [] date_pairs = [] i = 0 for file in path_list: try: data = netcdf_read_write.read_grd(file) except TypeError: data = netcdf_read_write.read_netcdf4(file) zdata.append(data) pairname = file.split('/')[-2][0:19] date_pairs.append( pairname ) # returning something like '2016292_2016316' for each intf if i == floor(len(path_list) / 2): print('Halfway done reading...') myData = tupleGRD(path_list=np.array(path_list), xdata=np.array(xdata), ydata=np.array(ydata), zdata=np.array(zdata)) return myData
def reader_simple_format(file_names): """ An earlier reading function, works fast, useful for things like coherence statistics """ [xdata, ydata] = rwr.read_grd_xy(file_names[0]); data_all = []; for ifile in file_names: # this happens to be in date order on my mac data = rwr.read_grd(ifile); data_all.append(data); date_pairs = []; for name in file_names: pairname = name.split('/')[-2][0:15]; date_pairs.append(pairname); # returning something like '2016292_2016316' for each intf print(pairname) return [xdata, ydata, data_all, date_pairs];
def inputs(file_names): [xdata,ydata] = netcdf_read_write.read_grd_xy(file_names[0]); data_all=[]; for ifile in file_names: # this happens to be in date order on my mac data = netcdf_read_write.read_grd(ifile); data_all.append(data); date_pairs=[]; dates=[]; for name in file_names: pairname=name.split('/')[-1][0:15]; date_pairs.append(pairname); # returning something like '2016292_2016316' for each intf splitname=pairname.split('_'); dates.append(splitname[0]) dates.append(splitname[1]) dates=list(set(dates)); dates=sorted(dates); print(dates); print("%d interferograms read from %d acquisitions." % (len(date_pairs), len(dates)) ); return [xdata, ydata, data_all, dates, date_pairs];
def inputs(file_names): try: [xdata, ydata] = netcdf_read_write.read_grd_xy( file_names[0]) # can read either netcdf3 or netcdf4. except TypeError: [xdata, ydata] = netcdf_read_write.read_netcdf4_xy(file_names[0]) data_all = [] file_names = sorted(file_names) # To force into date-ascending order. titles = [] for ifile in file_names: # Read the data try: data = netcdf_read_write.read_grd(ifile) except TypeError: data = netcdf_read_write.read_netcdf4(ifile) data_all.append(data) # LOS_20161121_INT3.grd titles.append(ifile[-17:-9]) return [xdata, ydata, data_all, titles]
def main_function(): # GLOBAL PARAMETERS nfit=0 ivar=1 alt_ref=100 thresh_amp=0.2 subsampled_dem_grd="topo/topo_ra_subsampled_june.grd" # subsampled in the same way as the intf grd files. demfile="topo/topo_radar.hgt" example_rsc="rsc_files/example_sd.int.rsc" # INPUTS intf_list=glob.glob("intf_all/???????_???????"); print(intf_list); # [width, length] = readbin.write_gmtsar2roipac_topo(subsampled_dem_grd,demfile); # copying the demfile into roipac format just in case we've switched the master. # COMPUTE for data_dir in intf_list: print(data_dir); intf_name=data_dir.split('/')[1]; infile=data_dir+"/intf_sd.int"; infile_filtered=data_dir+"/intf_filt.int"; stratfile=data_dir+"/strat.unw" outfile=data_dir+"/out.int" outfile_filtered=data_dir+"/out_filtered.int" # Pretty standard GMTSAR files. phasefile=data_dir+"/phase.grd"; phasefilt_file=data_dir+"/phasefilt.grd"; ampfile=data_dir+"/amp.grd"; orig_phasefile=data_dir+"/orig_phase.grd"; orig_phasefilt_file=data_dir+"/orig_phasefilt.grd"; readbin.prep_files(phasefile, phasefilt_file, orig_phasefile, orig_phasefilt_file); # copy files into safekeeping if necessary # MAKE BINARY INTERFEROGRAMS [width, length] = readbin.write_gmtsar2roipac_phase(data_dir,orig_phasefile, orig_phasefilt_file, ampfile,infile,infile_filtered); # width=661; length=1524 # # # RUN THE FORTRAN print("\nRunning the fortran code to remove atmospheric artifacts from interferogram.") subprocess.call(['cp',example_rsc,data_dir+'/intf_sd.int.rsc'],shell=False); print("flatten_topo "+infile+" "+infile_filtered+" "+demfile+" "+outfile+" "+outfile_filtered+" "+str(nfit)+" "+str(ivar)+" "+str(alt_ref)+" "+str(thresh_amp)+" "+stratfile+"\n"); subprocess.call(["flatten_topo",infile,infile_filtered,demfile,outfile,outfile_filtered,str(nfit),str(ivar),str(alt_ref),str(thresh_amp),stratfile],shell=False); subprocess.call(['mv','ncycle_topo',data_dir+'/ncycle_topo'],shell=False); subprocess.call(['mv','ncycle_topo_az',data_dir+'/ncycle_topo_az'],shell=False); # Output handling. First reading 1D arrays [real,imag]=readbin.read_binary_roipac_real_imag(infile); [phase_early,amp_early]=readbin.real_imag2phase_amp(real,imag); [real,imag]=readbin.read_binary_roipac_real_imag(outfile); [phase_out,amp_late]=readbin.real_imag2phase_amp(real,imag); [real,imag]=readbin.read_binary_roipac_real_imag(outfile_filtered); [phasefilt_out,amp_late]=readbin.real_imag2phase_amp(real,imag); # 1d arrays # # Write the GRD files , fixing an issue with pixel node registration. [xdata_p,ydata_p]=netcdf_read_write.read_grd_xy(orig_phasefile); [xdata_pf,ydata_pf]=netcdf_read_write.read_grd_xy(orig_phasefilt_file); phase_out_grd=np.reshape(phase_out,(length,width)); phasefilt_out_grd=np.reshape(phasefilt_out,(length,width)); netcdf_read_write.produce_output_netcdf(xdata_p, ydata_p, phase_out_grd, 'radians', phasefile); netcdf_read_write.flip_if_necessary(phasefile); origrange=subprocess.check_output('gmt grdinfo -I- '+orig_phasefile,shell=True); # fixing pixel node registration issue. subprocess.call('gmt grdsample '+phasefile+' '+origrange.split()[0]+' -G'+phasefile+' -r', shell=True); netcdf_read_write.produce_output_netcdf(xdata_pf, ydata_pf, phasefilt_out_grd, 'radians', phasefilt_file); netcdf_read_write.flip_if_necessary(phasefilt_file); origrange=subprocess.check_output('gmt grdinfo -I- '+orig_phasefilt_file,shell=True); subprocess.call('gmt grdsample '+phasefilt_file+' '+origrange.split()[0]+' -G'+phasefilt_file+' -r', shell=True); # Making plot readbin.output_plots(phase_early, phasefilt_out, width, length, data_dir+"/"+intf_name+"_corrected.eps"); return;