def main(argv): try: File = argv[0] atr = readfile.read_attribute(File) except: usage() sys.exit(1) try: outFile = argv[1] except: outFile = 'rangeDistance.h5' # Calculate look angle range_dis = ut.range_distance(atr, dimension=2) # Geo coord if 'Y_FIRST' in atr.keys(): print('Input file is geocoded, only center range distance is calculated: ') print(range_dis) length = int(atr['LENGTH']) width = int(atr['WIDTH']) range_dis_mat = np.zeros((length, width), np.float32) range_dis_mat[:] = range_dis range_dis = range_dis_mat print('writing >>> '+outFile) atr['FILE_TYPE'] = 'mask' atr['UNIT'] = 'm' try: atr.pop('REF_DATE') except: pass writefile.write(range_dis, out_file=outFile, metadata=atr) return outFile
def get_slant_range_distance(self, box=None): if not self.extraMetadata or 'Y_FIRST' in self.extraMetadata.keys(): return None data = ut.range_distance(self.extraMetadata, dimension=2, print_msg=False) if box is not None: data = data[box[1]:box[3], box[0]:box[2]] return data
def read_geometry(ts_file, geom_file=None, box=None): """Read the following geometry info in 0/2/3D Parameters: ts_file - str, path of time-series file geom_file - str, path of geometry file box - tuple of 4 int for (x0, y0, x1, y1) of the area of interest Returns: sin_inc_angle - 0/2D array, sin(inc_angle) range_dist - 0/2D array, slant range distance in meter pbase - 0/3D array, perp baseline in meter """ ts_obj = timeseries(ts_file) ts_obj.open(print_msg=False) # size if box: num_row = box[3] - box[1] num_col = box[2] - box[0] else: num_row = ts_obj.length num_col = ts_obj.width # 0/2/3D geometry if geom_file: geom_obj = geometry(geom_file) geom_obj.open() # 0/2D incidence angle / slant range distance if 'incidenceAngle' not in geom_obj.datasetNames: inc_angle = ut.incidence_angle(ts_obj.metadata, dimension=0) range_dist = ut.range_distance(ts_obj.metadata, dimension=0) else: print( 'read 2D incidenceAngle, slantRangeDistance from {} file: {}'. format(geom_obj.name, os.path.basename(geom_obj.file))) inc_angle = geom_obj.read(datasetName='incidenceAngle', box=box, print_msg=False).flatten() range_dist = geom_obj.read(datasetName='slantRangeDistance', box=box, print_msg=False).flatten() # 0/3D perp baseline if 'bperp' in geom_obj.datasetNames: print('read 3D bperp from {} file: {} ...'.format( geom_obj.name, os.path.basename(geom_obj.file))) dset_list = ['bperp-{}'.format(d) for d in ts_obj.dateList] pbase = geom_obj.read(datasetName=dset_list, box=box, print_msg=False).reshape( (ts_obj.numDate, -1)) pbase -= np.tile(pbase[ts_obj.refIndex, :].reshape(1, -1), (ts_obj.numDate, 1)) else: print('read mean bperp from {} file'.format(ts_obj.name)) pbase = ts_obj.pbase.reshape((-1, 1)) # 0D geometry else: print( 'read mean incidenceAngle, slantRangeDistance, bperp value from {} file' .format(ts_obj.name)) inc_angle = ut.incidence_angle(ts_obj.metadata, dimension=0) range_dist = ut.range_distance(ts_obj.metadata, dimension=0) pbase = ts_obj.pbase.reshape((-1, 1)) sin_inc_angle = np.sin(inc_angle * np.pi / 180.) return sin_inc_angle, range_dist, pbase