def parse(self): try: import sarpy.io.complex as cf except ImportError: raise Exception( 'You need to install sarpy from NGA - https://github.com/ngageoint/sarpy to work with SICD data' ) self._sicdmeta = cf.open(self.sicd).sicdmeta self.populateMetadata()
def load_image(self, image_index): img_filename = self.image_names[image_index] if os.path.splitext(img_filename)[-1] == 'nitf': cdata = cf.open(img_filename).read_chip() img = remap.density(cdata) else: img = skimage.io.imread(img_filename) if len(img.shape) == 2: img = img[..., np.newaxis] return img.astype(np.float32)/255.0
def init_from_fname_and_canvas_size( self, fname, # type: str canvas_ny, # type: int canvas_nx, # type: int scale_to_fit_canvas=False, # type: bool ): self.fname = fname self.reader_object = sarpy_complex.open(fname) self.full_image_nx = self.reader_object.sicd_meta.ImageData.FullImage.NumCols self.full_image_ny = self.reader_object.sicd_meta.ImageData.FullImage.NumRows self.canvas_nx = canvas_nx self.canvas_ny = canvas_ny self.scale_to_fit_canvas = scale_to_fit_canvas self.update_canvas_display_image_from_full_image()
def run(self): cl = self.cl # type: AlgorithmChain.ChainLedger params = self.params # type: dict # Add your algorithm code here # Open file fname = params['filename'] if fname.startswith('~'): fname = os.path.expanduser(fname) ro = cf.open(fname) cl.add_to_metadata('sarpy_reader', ro) # Do not edit below this line return cl
def callback_select_file(self, event): sicd_fname = self.image_info_panel.file_selector.event_select_file(event) self.app_variables.sicd_fname = sicd_fname self.app_variables.sicd_reader_object = sarpy_complex.open(sicd_fname) meticon_helper = SicdMetaIconHelper(self.app_variables.sicd_reader_object.sicd_meta) data_container = meticon_helper.data_container self.metaicon.create_from_metaicon_data_container(data_container) popup = tkinter.Toplevel(self.master) selected_region_popup = SelectedRegionPanel(popup, self.app_variables) self.app_variables.sicd_reader_object = ComplexImageReader(self.app_variables.sicd_fname) selected_region_popup.image_canvas.canvas.set_image_reader(self.app_variables.sicd_reader_object) self.master.wait_window(popup) selected_region_complex_data = self.app_variables.selected_region_complex_data fft_complex_data = self.get_fft_complex_data(self.app_variables.sicd_reader_object.base_reader, selected_region_complex_data) self.app_variables.fft_complex_data = fft_complex_data self.app_variables.fft_display_data = remap.density(fft_complex_data) fft_reader = NumpyImageReader(self.app_variables.fft_display_data) self.frequency_vs_degree_panel.canvas.set_image_reader(fft_reader) self.frequency_vs_degree_panel.canvas.set_current_tool_to_edit_shape() self.frequency_vs_degree_panel.canvas.variables.current_shape_id = self.frequency_vs_degree_panel.canvas.variables.select_rect_id self.frequency_vs_degree_panel.canvas.modify_existing_shape_using_image_coords(self.frequency_vs_degree_panel.canvas.variables.select_rect_id, self.get_fft_image_bounds()) canvas_drawing_bounds = self.frequency_vs_degree_panel.canvas.image_coords_to_canvas_coords(self.frequency_vs_degree_panel.canvas.variables.select_rect_id) self.frequency_vs_degree_panel.canvas.variables.shape_drag_xy_limits[str(self.frequency_vs_degree_panel.canvas.variables.select_rect_id)] = canvas_drawing_bounds self.app_variables.fft_canvas_bounds = self.frequency_vs_degree_panel.canvas.get_shape_canvas_coords(self.frequency_vs_degree_panel.canvas.variables.select_rect_id) self.frequency_vs_degree_panel.canvas.show_shape(self.frequency_vs_degree_panel.canvas.variables.select_rect_id) filtered_numpy_reader = NumpyImageReader(self.get_filtered_image()) self.filtered_panel.canvas.set_image_reader(filtered_numpy_reader) self.image_info_panel.chip_size_panel.nx.set_text(numpy.shape(selected_region_complex_data)[1]) self.image_info_panel.chip_size_panel.ny.set_text(numpy.shape(selected_region_complex_data)[0]) self.update_phase_history_selection() self.metaviewer.create_w_sicd(self.app_variables.sicd_reader_object.base_reader.sicd_meta) self.frequency_vs_degree_panel.update() self.frequency_vs_degree_panel.update_x_axis(start_val=-10, stop_val=10, label="Polar Angle (degrees)") self.frequency_vs_degree_panel.update_y_axis(start_val=7.409, stop_val=11.39, label="Frequency (GHz)")
def populateImage(self): import sarpy.io.complex as cf img = cf.open(self.sicd) data = img.read_chip() if self._sicdmeta.SCPCOA.SideOfTrack.startswith('R'): viewarr = data else: viewarr = data[:, ::-1] data.T.tofile(self.output) rawImage = isceobj.createSlcImage() rawImage.setByteOrder('l') rawImage.setFilename(self.output) rawImage.setAccessMode('read') rawImage.setWidth(self.frame.getNumberOfSamples()) rawImage.setXmax(self.frame.getNumberOfSamples()) rawImage.setXmin(0) self.getFrame().setImage(rawImage)
def set_reader_file(self, fname): self.base_reader = sarpy_complex.open(fname) self.full_image_nx = self.base_reader.sicd_meta.ImageData.FullImage.NumCols self.full_image_ny = self.base_reader.sicd_meta.ImageData.FullImage.NumRows
def add_node(k, v): for key, val in v.items(): new_key = k + "_" + key if "RcvChannels" in new_key: stop = 1 if isinstance(val, OrderedDict): tree.insert(k, 1, new_key, text=key) add_node(new_key, val) else: tree.insert(k, 1, new_key, text=key + ": " + str(val)) sicd_fname = askopenfilename(initialdir=os.path.expanduser("~")) reader_object = sarpy_complex.open(sicd_fname) sicd_meta_dict = reader_object.sicd_meta.to_dict() def insertv2(k, v): print("k: " + k) for key, val in v.items(): print("k: " + k) print("key: " + key) new_key = k + "_" + key print("new key: " + new_key) if isinstance(val, dict): insertv2(new_key, val)
""" Just a quick demo to show the basics of how to use SarPy """ import matplotlib.pyplot as plt import sarpy.io.complex as cf import sarpy.visualization.remap as remap # Open file fname = 'C:/Temp/my_sicd.nitf' ro = cf.open(fname) # Access SICD metadata (even if file read is not in SICD format) print(ro.sicd_meta ) # Displays metadata from file in SICD format in human-readable form print(ro.sicd_meta.CollectionInfo.CollectorName ) # extracting fields from metadata ############### # Read complex pixel data from file # cdata = ro[:] # Reads all complex data from file # Read every 10th pixel: cdata = ro[::10, ::10] fig, axs = plt.subplots(nrows=1, ncols=3, figsize=(12, 4)) axs[0].imshow(remap.density(cdata), cmap='gray') # Display subsampled image # Reads every other row and column from the first thousand rows and columns: cdata = ro[:1000:2, :1000:2] axs[1].imshow(remap.density(cdata), cmap='gray') # Display subsampled image
def create_from_fname(self, fname): self.fname = fname reader_object = sarpy_complex.open(fname) self.create_from_sicd(reader_object.sicd_meta)