def project_image_to_ground(self, im_points, projection_type='HAE', **kwargs): """ Transforms image coordinates to ground plane ECF coordinate via the algorithm(s) described in SICD Image Projections document. Parameters ---------- im_points : numpy.ndarray|list|tuple the image coordinate array projection_type : str One of `['PLANE', 'HAE', 'DEM']`. Type `DEM` is a work in progress. kwargs The keyword arguments for the :func:`sarpy.geometry.point_projection.image_to_ground` method. Returns ------- numpy.ndarray Ground Plane Point (in ECF coordinates) corresponding to the input image coordinates. See Also -------- sarpy.geometry.point_projection.image_to_ground """ if 'use_structure_coa' not in kwargs: kwargs['use_structure_coa'] = True return point_projection.image_to_ground( im_points, self, projection_type=projection_type, **kwargs)
def calculate_wake_distance(self): horizontal_line_image_coords = self.image_canvas.canvas.canvas_shape_coords_to_image_coords(self.variables.horizontal_line_id) sicd_meta = self.variables.image_reader.base_reader.sicd_meta points = np.asarray(np.reshape(horizontal_line_image_coords, (2, 2))) ecf_ground_points = point_projection.image_to_ground(points, sicd_meta) geo_ground_point_1 = geocoords.ecf_to_geodetic((ecf_ground_points[0, 0], ecf_ground_points[0, 1], ecf_ground_points[0, 2])) geo_ground_point_2 = geocoords.ecf_to_geodetic((ecf_ground_points[1, 0], ecf_ground_points[1, 1], ecf_ground_points[1, 2])) distance = math.sqrt( (ecf_ground_points[0, 0] - ecf_ground_points[1, 0])**2 + (ecf_ground_points[0, 1] - ecf_ground_points[1, 1])**2 + (ecf_ground_points[0, 2] - ecf_ground_points[1, 2])**2) return distance
def _update_geo_data(sicd): """ Populates the GeoData. Parameters ---------- sicd : SICDType Returns ------- None """ ecf = point_projection.image_to_ground( [sicd.ImageData.SCPPixel.Row, sicd.ImageData.SCPPixel.Col], sicd) sicd.GeoData.SCP = SCPType(ECF=ecf) # LLH implicitly populated
def sarpy2ortho(ro, pix, decimation=10): nx = ro.sicdmeta.ImageData.FullImage.NumCols ny = ro.sicdmeta.ImageData.FullImage.NumRows nx_dec = round(nx / decimation) ny_dec = round(ny / decimation) xv, yv = np.meshgrid(range(nx), range(ny), indexing='xy') xv = xv[::decimation, ::decimation] yv = yv[::decimation, ::decimation] npix = xv.size xv = np.reshape(xv, (npix, 1)) yv = np.reshape(yv, (npix, 1)) im_points = np.concatenate([yv, xv], axis=1) ground_coords = image_to_ground(im_points, ro.sicdmeta) ground_coords = ecf_to_geodetic(ground_coords) minx = np.min(ground_coords[:, 1]) maxx = np.max(ground_coords[:, 1]) miny = np.min(ground_coords[:, 0]) maxy = np.max(ground_coords[:, 0]) xi, yi = create_ground_grid(minx, maxx, miny, maxy, nx_dec, ny_dec) ground_coords[:, [0, 1]] = ground_coords[:, [1, 0]] pix = np.reshape(pix, npix) gridded = griddata(ground_coords[:, 0:2], pix, (xi, yi), method='nearest').astype(np.uint8) ul = [maxy, minx] lr = [miny, maxx] extent = [ul, lr] extent_poly = bounds_2_shapely_polygon(min_x=minx, max_x=maxx, min_y=miny, max_y=maxy) geot = world_poly_to_geo_t(extent_poly, npix_x=nx_dec, npix_y=ny_dec) return gridded, extent, geot
def callback_save_kml(self, event): kml_save_fname = tkinter.filedialog.asksaveasfilename( initialdir=os.path.expanduser("~/Downloads")) kml_util = KmlUtil() canvas_shapes = self.canvas_demo_image_panel.canvas.variables.shape_ids for shape_id in canvas_shapes: image_coords = self.canvas_demo_image_panel.canvas.get_shape_image_coords( shape_id) shape_type = self.canvas_demo_image_panel.canvas.get_shape_type( shape_id) if image_coords: sicd_meta = self.canvas_demo_image_panel.canvas.variables.canvas_image_object.reader_object.sicdmeta image_points = numpy.zeros((int(len(image_coords) / 2), 2)) image_points[:, 0] = image_coords[0::2] image_points[:, 1] = image_coords[1::2] ground_points_ecf = point_projection.image_to_ground( image_points, sicd_meta) ground_points_latlon = geocoords.ecf_to_geodetic( ground_points_ecf) world_y_coordinates = ground_points_latlon[:, 0] world_x_coordinates = ground_points_latlon[:, 1] xy_point_list = [ (x, y) for x, y in zip(world_x_coordinates, world_y_coordinates) ] if shape_id == self.canvas_demo_image_panel.canvas.variables.zoom_rect_id: pass elif shape_type == self.canvas_demo_image_panel.canvas.variables.select_rect_id: pass elif shape_type == self.canvas_demo_image_panel.canvas.SHAPE_TYPES.POINT: kml_util.add_point(str(shape_id), xy_point_list[0]) elif canvas_shapes == self.canvas_demo_image_panel.canvas.SHAPE_TYPES.LINE: kml_util.add_linestring(str(shape_id), xy_point_list) elif shape_type == self.canvas_demo_image_panel.canvas.SHAPE_TYPES.POLYGON: kml_util.add_polygon(str(shape_id), xy_point_list) elif shape_type == self.canvas_demo_image_panel.canvas.SHAPE_TYPES.RECT: kml_util.add_polygon(str(shape_id), xy_point_list) kml_util.write_to_file(kml_save_fname)
def correct_scp(): scp_pixel = sicd.ImageData.SCPPixel.get_array() scp_ecf = point_projection.image_to_ground(scp_pixel, sicd) sicd.GeoData.SCP.ECF = scp_ecf
def create_ortho( self, output_ny, output_nx, ): input_image_data = self.display_image display_image_nx = input_image_data.shape[1] display_image_ny = input_image_data.shape[0] image_points = np.zeros((display_image_nx * display_image_ny, 2)) canvas_coords_1d = np.zeros(2 * display_image_nx * display_image_ny) tmp_x_vals = np.arange(0, display_image_ny) tmp_y_vals = np.zeros(display_image_ny) for x in range(display_image_nx): start_index = display_image_ny * 2 * x + 1 end_index = start_index + display_image_ny * 2 canvas_coords_1d[start_index:end_index:2] = tmp_x_vals canvas_coords_1d[display_image_ny * x * 2::2][0:display_image_ny] = tmp_y_vals + x full_image_coords = self.canvas_coords_to_full_image_yx( canvas_coords_1d) image_points[:, 0] = full_image_coords[0::2] image_points[:, 1] = full_image_coords[1::2] sicd_meta = self.reader_object.sicd_meta ground_points_ecf = point_projection.image_to_ground( image_points, sicd_meta) ground_points_latlon = geocoords.ecf_to_geodetic(ground_points_ecf) world_y_coordinates = ground_points_latlon[:, 0] world_x_coordinates = ground_points_latlon[:, 1] x = np.ravel(world_x_coordinates) y = np.ravel(world_y_coordinates) z = np.ravel(np.transpose(input_image_data)) ground_x_grid, ground_y_grid = self._create_ground_grid( min(x), max(x), min(y), max(y), output_nx, output_ny) ortho_image = interp.griddata((x, y), z, (ground_x_grid, ground_y_grid), method='nearest') s = np.zeros((output_nx * output_ny, 3)) s[:, 0] = ground_y_grid.ravel() s[:, 1] = ground_x_grid.ravel() s[:, 2] = ground_points_latlon[0, 2] s_ecf = geocoords.geodetic_to_ecf(s) gridded_image_pixels = point_projection.ground_to_image( s_ecf, sicd_meta) full_image_coords_y = full_image_coords[0::2] full_image_coords_x = full_image_coords[1::2] mask = np.ones_like(gridded_image_pixels[0][:, 0]) indices_1 = np.where( gridded_image_pixels[0][:, 0] < min(full_image_coords_y)) indices_2 = np.where( gridded_image_pixels[0][:, 1] < min(full_image_coords_x)) indices_3 = np.where( gridded_image_pixels[0][:, 0] > max(full_image_coords_y)) indices_4 = np.where( gridded_image_pixels[0][:, 1] > max(full_image_coords_x)) mask[indices_1] = 0 mask[indices_2] = 0 mask[indices_3] = 0 mask[indices_4] = 0 mask_2d = np.reshape(mask, (output_ny, output_nx)) return ortho_image * mask_2d
def update_geodata(sicd): # type: (SICDType) -> None ecf = point_projection.image_to_ground([sicd.ImageData.SCPPixel.Row, sicd.ImageData.SCPPixel.Col], sicd) sicd.GeoData.SCP = SCPType(ECF=ecf) # LLH will be populated
def update_geodata(): ecf = point_projection.image_to_ground( [t_sicd.ImageData.SCPPixel.Row, t_sicd.ImageData.SCPPixel.Col], t_sicd) t_sicd.GeoData.SCP = SCPType(ECF=ecf) # LLH will be populated