def main(iargs=None): inps = cmd_line_parse(iargs) # Calculate look angle atr = readfile.read_attribute(inps.file) dem = None if inps.dem_file: dem = readfile.read(inps.dem_file, datasetName='height')[0] angle = ut.incidence_angle(atr, dem=dem, dimension=2) # Geo coord if 'Y_FIRST' in atr.keys(): print( 'Input file is geocoded, only center incident angle is calculated: ' ) print(angle) length = int(atr['LENGTH']) width = int(atr['WIDTH']) angle_mat = np.zeros((length, width), np.float32) angle_mat[:] = angle angle = angle_mat atr['FILE_TYPE'] = 'mask' atr['UNIT'] = 'degree' if 'REF_DATE' in atr.keys(): atr.pop('REF_DATE') if not inps.outfile: inps.outfile = 'incidenceAngle.h5' writefile.write(angle, out_file=inps.outfile, metadata=atr) return inps.outfile
def read_geometry(inps): ts_obj = timeseries(inps.timeseries_file) ts_obj.open(print_msg=False) # 2D / 3D geometry if inps.geom_file: geom_obj = geometry(inps.geom_file) geom_obj.open() print(('read 2D incidenceAngle,slantRangeDistance from {} file:' ' {}').format(geom_obj.name, os.path.basename(geom_obj.file))) inps.incAngle = geom_obj.read(datasetName='incidenceAngle', print_msg=False).flatten() inps.rangeDist = geom_obj.read(datasetName='slantRangeDistance', print_msg=False).flatten() if 'bperp' in geom_obj.datasetNames: print('read 3D bperp from {} file: {} ...'.format(geom_obj.name, os.path.basename(geom_obj.file))) inps.pbase = geom_obj.read(datasetName='bperp', print_msg=False).reshape((geom_obj.numDate, -1)) inps.pbase -= inps.pbase[ts_obj.refIndex] else: print('read mean bperp from {} file'.format(ts_obj.name)) inps.pbase = ts_obj.pbase.reshape((-1, 1)) # 0D geometry else: print('read mean incidenceAngle,slantRangeDistance,bperp value from {} file'.format(ts_obj.name)) inps.incAngle = ut.incidence_angle(ts_obj.metadata, dimension=0) inps.rangeDist = ut.range_distance(ts_obj.metadata, dimension=0) inps.pbase = ts_obj.pbase.reshape((-1, 1)) inps.sinIncAngle = np.sin(inps.incAngle * np.pi / 180.) return inps
def get_los_geometry(self, insar_obj, print_msg=False): lat, lon = self.get_stat_lat_lon(print_msg=print_msg) # get LOS geometry if isinstance(insar_obj, str): # geometry file atr = readfile.read_attribute(insar_obj) coord = ut.coordinate(atr, lookup_file=insar_obj) y, x = coord.geo2radar(lat, lon, print_msg=print_msg)[0:2] box = (x, y, x + 1, y + 1) inc_angle = readfile.read(insar_obj, datasetName='incidenceAngle', box=box, print_msg=print_msg)[0][0, 0] az_angle = readfile.read(insar_obj, datasetName='azimuthAngle', box=box, print_msg=print_msg)[0][0, 0] head_angle = ut.azimuth2heading_angle(az_angle) elif isinstance(insar_obj, dict): # use mean inc/head_angle from metadata inc_angle = ut.incidence_angle(insar_obj, dimension=0, print_msg=print_msg) head_angle = float(insar_obj['HEADING']) # for old reading of los.rdr band2 data into headingAngle directly if (head_angle + 180.) > 45.: head_angle = ut.azimuth2heading_angle(head_angle) else: raise ValueError( 'input insar_obj is neight str nor dict: {}'.format(insar_obj)) return inc_angle, head_angle
def get_incidence_angle(self, box=None): if not self.extraMetadata or 'Y_FIRST' in self.extraMetadata.keys(): return None if 'height' in self.dsNames: dem = readfile.read(self.datasetDict['height'], datasetName='height')[0] else: dem = None data = ut.incidence_angle(self.extraMetadata, dem=dem, dimension=2, print_msg=False) if box is not None: data = data[box[1]:box[3], box[0]:box[2]] return data
def main(iargs=None): inps = cmd_line_parse(iargs) # 1. Extract the common area of two input files # Basic info atr1 = readfile.read_attribute(inps.file[0]) atr2 = readfile.read_attribute(inps.file[1]) if any('X_FIRST' not in i for i in [atr1, atr2]): sys.exit('ERROR: Not all input files are geocoded.') k1 = atr1['FILE_TYPE'] print('Input 1st file is ' + k1) # Common AOI in lalo west, east, south, north = get_overlap_lalo(atr1, atr2) lon_step = float(atr1['X_STEP']) lat_step = float(atr1['Y_STEP']) width = int(round((east - west) / lon_step)) length = int(round((south - north) / lat_step)) # Read data in common AOI: LOS displacement, heading angle, incident angle u_los = np.zeros((2, width * length)) heading = [] incidence = [] for i in range(len(inps.file)): fname = inps.file[i] print('---------------------') print('reading ' + fname) atr = readfile.read_attribute(fname) [x0, x1] = ut.coord_geo2radar([west, east], atr, 'lon') [y0, y1] = ut.coord_geo2radar([north, south], atr, 'lat') V = readfile.read(fname, box=(x0, y0, x1, y1))[0] u_los[i, :] = V.flatten(0) heading_angle = float(atr['HEADING']) if heading_angle < 0.: heading_angle += 360. print('heading angle: ' + str(heading_angle)) heading_angle *= np.pi / 180. heading.append(heading_angle) inc_angle = float(ut.incidence_angle(atr, dimension=0)) inc_angle *= np.pi / 180. incidence.append(inc_angle) # 2. Project displacement from LOS to Horizontal and Vertical components # math for 3D: cos(theta)*Uz - cos(alpha)*sin(theta)*Ux + sin(alpha)*sin(theta)*Uy = Ulos # math for 2D: cos(theta)*Uv - sin(alpha-az)*sin(theta)*Uh = Ulos #Uh_perp = 0.0 # This could be easily modified to support multiple view geometry # (e.g. two adjcent tracks from asc & desc) to resolve 3D # Design matrix A = np.zeros((2, 2)) for i in range(len(inps.file)): A[i, 0] = np.cos(incidence[i]) A[i, 1] = np.sin(incidence[i]) * np.sin(heading[i] - inps.azimuth) A_inv = np.linalg.pinv(A) u_vh = np.dot(A_inv, u_los) u_v = np.reshape(u_vh[0, :], (length, width)) u_h = np.reshape(u_vh[1, :], (length, width)) # 3. Output # Attributes atr = atr1.copy() atr['WIDTH'] = str(width) atr['LENGTH'] = str(length) atr['X_FIRST'] = str(west) atr['Y_FIRST'] = str(north) atr['X_STEP'] = str(lon_step) atr['Y_STEP'] = str(lat_step) print('---------------------') outname = inps.outfile[0] print('writing vertical component to file: ' + outname) writefile.write(u_v, out_file=outname, metadata=atr) outname = inps.outfile[1] print('writing horizontal component to file: ' + outname) writefile.write(u_h, out_file=outname, metadata=atr) print('Done.') return