예제 #1
0
    def _get_fft_complex_data(self, cdata):
        """
        Transform the complex image data to phase history data.

        Parameters
        ----------
        cdata : numpy.ndarray

        Returns
        -------
        numpy.ndarray
        """

        return fftshift(fft2_sicd(cdata, self.sicd))
예제 #2
0
def create_deskewed_transform(reader, dimension=0, suffix='.sarpy.cache'):
    """
    Performs the Fourier transform of the deskewed entirety of the given
    ComplexImageReader contents.

    Parameters
    ----------
    reader : SICDTypeCanvasImageReader
        The reader object.
    dimension : int
        One of [0, 1], which dimension to deskew along.
    suffix : None|str
        The suffix for the created file name (created using the tempfile module).

    Returns
    -------
    (str, numpy.ndarray, numpy.ndarray)
        A file name, numpy memmap of the given object, and mean along the given dimension.
        Care should be taken to ensure that the file is deleted when the usage is complete.
    """

    # set up a true file for the memmap
    # NB: it should be noted that the tempfile usage which clean themselves up
    #     cannot (as of 2021-04-23) be opened multiple times on Windows, which
    #     means that such a "file" cannot be used in conjunction with a numpy
    #     memmap.
    data_size = reader.data_size
    sicd = reader.get_sicd()
    _, file_name = mkstemp(suffix=suffix, text=False)
    logger.debug('Creating temp file % s' % file_name)
    # set up the memmap
    memmap = numpy.memmap(file_name, dtype='complex64', mode='r+', offset=0, shape=data_size)
    calculator = DeskewCalculator(
        reader.base_reader, dimension=dimension, index=reader.index,
        apply_deskew=True, apply_deweighting=False, apply_off_axis=False)
    mean_value = numpy.zeros((data_size[0], ), dtype='float64') if dimension == 0 else \
        numpy.zeros((data_size[1],), dtype='float64')

    # we'll proceed in blocks of approximately this number of pixels
    pixels_threshold = 2**20
    # is our whole reader sufficiently small to just do it all in one fell-swoop?
    if data_size[0]*data_size[1] <= 4*pixels_threshold:
        data = fftshift(fft2_sicd(calculator[:, :], sicd))
        memmap[:, :] = data
        mean_value[:] = numpy.mean(numpy.abs(data), axis=1-dimension)
        return file_name, memmap, mean_value

    # fetch full rows, and transform then shift along the row direction
    block_size = int(numpy.ceil(pixels_threshold/data_size[1]))
    start_col = 0
    while start_col < data_size[1]:
        end_col = min(start_col+block_size, data_size[1])
        data = fftshift(fft_sicd(calculator[:, start_col:end_col], 0, sicd), axes=0)
        memmap[:, start_col:end_col] = data
        if dimension == 0:
            mean_value += numpy.sum(numpy.abs(data), axis=1)
        start_col = end_col
    # fetch full columns, and transform then shift along the column direction
    block_size = int(numpy.ceil(pixels_threshold/data_size[0]))
    start_row = 0
    while start_row < data_size[0]:
        end_row = min(start_row+block_size, data_size[0])
        data = fftshift(fft_sicd(memmap[start_row:end_row, :], 1, sicd), axes=1)
        memmap[start_row:end_row, :] = data
        if dimension == 1:
            mean_value += numpy.sum(numpy.abs(data), axis=0)
        start_row = end_row

    if dimension == 0:
        mean_value /= data_size[1]
    else:
        mean_value /= data_size[0]
    return file_name, memmap, mean_value
예제 #3
0
    def update_displayed_selection(self):
        def get_extent(coords):
            return min(coords[0::2]), max(coords[0::2]), min(coords[1::2]), max(coords[1::2])

        def draw_row_delta_lines():
            deltak1 = (row_count - 1)*(0.5 + the_sicd.Grid.Row.SS*the_sicd.Grid.Row.DeltaK1) + 1
            deltak2 = (row_count - 1)*(0.5 + the_sicd.Grid.Row.SS*the_sicd.Grid.Row.DeltaK2) + 1

            self.frequency_panel.canvas.modify_existing_shape_using_image_coords(
                self.variables.row_deltak1, (deltak1, 0, deltak1, col_count))
            self.frequency_panel.canvas.modify_existing_shape_using_image_coords(
                self.variables.row_deltak2, (deltak2, 0, deltak2, col_count))

        def draw_col_delta_lines():
            deltak1 = (col_count - 1)*(0.5 + the_sicd.Grid.Col.SS*the_sicd.Grid.Col.DeltaK1) + 1
            deltak2 = (col_count - 1)*(0.5 + the_sicd.Grid.Col.SS*the_sicd.Grid.Col.DeltaK2) + 1

            self.frequency_panel.canvas.modify_existing_shape_using_image_coords(
                self.variables.col_deltak1, (0, deltak1, row_count, deltak1))
            self.frequency_panel.canvas.modify_existing_shape_using_image_coords(
                self.variables.col_deltak2, (0, deltak2, row_count, deltak2))

        def draw_row_bandwidth_lines():
            try:
                delta_kcoa_center = the_sicd.Grid.Row.DeltaKCOAPoly(row_phys, col_phys)
            except Exception:
                delta_kcoa_center = 0.0

            row_bw_low = (row_count - 1)*(
                    0.5 + the_sicd.Grid.Row.SS*(delta_kcoa_center - 0.5*the_sicd.Grid.Row.ImpRespBW)) + 1
            row_bw_high = (row_count - 1)*(
                    0.5 + the_sicd.Grid.Row.SS*(delta_kcoa_center + 0.5*the_sicd.Grid.Row.ImpRespBW)) + 1

            row_bw_low = (row_bw_low % row_count)
            row_bw_high = (row_bw_high % row_count)

            self.frequency_panel.canvas.modify_existing_shape_using_image_coords(
                self.variables.row_line_low, (row_bw_low, 0, row_bw_low, col_count))
            self.frequency_panel.canvas.modify_existing_shape_using_image_coords(
                self.variables.row_line_high, (row_bw_high, 0, row_bw_high, col_count))

        def draw_col_bandwidth_lines():
            try:
                delta_kcoa_center = the_sicd.Grid.Col.DeltaKCOAPoly(row_phys, col_phys)
            except Exception:
                delta_kcoa_center = 0.0

            col_bw_low = (col_count - 1) * (
                    0.5 + the_sicd.Grid.Col.SS*(delta_kcoa_center - 0.5*the_sicd.Grid.Col.ImpRespBW)) + 1
            col_bw_high = (col_count - 1) * (
                    0.5 + the_sicd.Grid.Col.SS*(delta_kcoa_center + 0.5*the_sicd.Grid.Col.ImpRespBW)) + 1

            col_bw_low = (col_bw_low % col_count)
            col_bw_high = (col_bw_high % col_count)

            self.frequency_panel.canvas.modify_existing_shape_using_image_coords(
                self.variables.col_line_low, (0, col_bw_low, row_count, col_bw_low))
            self.frequency_panel.canvas.modify_existing_shape_using_image_coords(
                self.variables.col_line_high, (0, col_bw_high, row_count, col_bw_high))

        threshold = self.image_panel.canvas.variables.config.select_size_threshold
        select_id = self.image_panel.canvas.variables.select_rect.uid
        rect_coords = self.image_panel.canvas.get_shape_image_coords(select_id)
        extent = get_extent(rect_coords)  # left, right, bottom, top
        row_count = extent[1] - extent[0]
        col_count = extent[3] - extent[2]

        the_sicd = self.variables.image_reader.get_sicd()
        row_phys, col_phys = get_physical_coordinates(
            the_sicd, 0.5*(extent[0]+extent[1]), 0.5*(extent[2]+extent[3]))

        if row_count < threshold or col_count < threshold:
            junk_data = numpy.zeros((100, 100), dtype='uint8')
            self.frequency_panel.set_image_reader(NumpyImageReader(junk_data))
            self._initialize_bandwidth_lines()
        else:
            image_data = self.variables.image_reader.base_reader[extent[0]:extent[1], extent[2]:extent[3]]
            if image_data is not None:
                self.frequency_panel.set_image_reader(
                    NumpyImageReader(remap.density(fftshift(fft2_sicd(image_data, the_sicd)))))
                self._initialize_bandwidth_lines()
                draw_row_delta_lines()
                draw_col_delta_lines()
                draw_row_bandwidth_lines()
                draw_col_bandwidth_lines()
            else:
                junk_data = numpy.zeros((100, 100), dtype='uint8')
                self.frequency_panel.set_image_reader(NumpyImageReader(junk_data))
                self._initialize_bandwidth_lines()