示例#1
0
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_xy(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(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 len(skip_file) > 0:
        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]
示例#2
0
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_xy(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(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];
示例#3
0
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
示例#4
0
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]