Пример #1
0
def save_ref_pixel_blocks(grid, half_patch_size, ifg_paths, params):
    """
    xxxx
    
    :param grid: List of tuples (y, x) corresponding reference pixel grids
    :param half_patch_size: Patch size in pixels corresponding to reference pixel grids
    :param ifg_paths: List of interferogram paths
    :param params: Parameters dictionary corresponding to config file
    
    :return xxxx
    """
    log.info('Saving ref pixel blocks')
    outdir = params[cf.TMPDIR]
    for pth in ifg_paths:
        ifg = Ifg(pth)
        ifg.open(readonly=True)
        ifg.nodata_value = params[cf.NO_DATA_VALUE]
        ifg.convert_to_nans()
        ifg.convert_to_mm()
        for y, x in grid:
            data = ifg.phase_data[y - half_patch_size:y + half_patch_size + 1,
                                  x - half_patch_size:x + half_patch_size + 1]

            data_file = join(
                outdir, 'ref_phase_data_{b}_{y}_{x}.npy'.format(
                    b=os.path.basename(pth).split('.')[0], y=y, x=x))
            np.save(file=data_file, arr=data)
        ifg.close()
    log.info('Saved ref pixel blocks')
Пример #2
0
class IfgTests(unittest.TestCase):
    """Unit tests for the Ifg/interferogram class."""

    def setUp(self):
        self.ifg = Ifg(join(SML_TEST_TIF, 'geo_060619-061002_unw.tif'))
        self.ifg.open()
        self.ifg.nodata_value = 0

    def test_headers_as_attr(self):
        for a in ['ncols', 'nrows', 'x_first', 'x_step',
                  'y_first', 'y_step', 'wavelength', 'master', 'slave']:
            self.assertTrue(getattr(self.ifg, a) is not None)

    def test_convert_to_nans(self):
        self.ifg.convert_to_nans()
        self.assertTrue(self.ifg.nan_converted)

    def test_xylast(self):
        # ensure the X|Y_LAST header element has been created
        self.assertAlmostEqual(self.ifg.x_last, 150.9491667)
        self.assertAlmostEqual(self.ifg.y_last, -34.23)

    def test_num_cells(self):
        # test cell size from header elements
        data = self.ifg.phase_band.ReadAsArray()
        ys, xs = data.shape
        exp_ncells = ys * xs
        self.assertEqual(exp_ncells, self.ifg.num_cells)

    def test_shape(self):
        self.assertEqual(self.ifg.shape, self.ifg.phase_data.shape)

    def test_nan_count(self):
        num_nan = 0
        for row in self.ifg.phase_data:
            for v in row:
                if isnan(v):
                    num_nan += 1
        if self.ifg.nan_converted:
            self.assertEqual(num_nan, self.ifg.nan_count)
        else:
            self.assertEqual(num_nan, 0)

    def test_phase_band(self):
        data = self.ifg.phase_band.ReadAsArray()
        self.assertEqual(data.shape, (72, 47) )

    def test_nan_fraction(self):
        # NB: source data lacks 0 -> NaN conversion
        data = self.ifg.phase_data
        data = where(data == 0, nan, data) # fake 0 -> nan for the count below

        # manually count # nan cells
        nans = 0
        ys, xs = data.shape
        for y, x in product(range(ys), range(xs)):
            if isnan(data[y, x]):
                nans += 1
        del data

        num_cells = float(ys * xs)
        self.assertTrue(nans > 0)
        self.assertTrue(nans <= num_cells)
        self.assertEqual(nans / num_cells, self.ifg.nan_fraction)

    def test_xy_size(self):
        self.assertFalse(self.ifg.ncols is None)
        self.assertFalse(self.ifg.nrows is None)

        # test with tolerance from base 90m cell
        # within 2% of cells over small?
        self.assertTrue(self.ifg.y_size > 88.0)
        self.assertTrue(self.ifg.y_size < 92.0, 'Got %s' % self.ifg.y_size)

        width = 76.9 # from nearby Pirate coords
        self.assertTrue(self.ifg.x_size > 0.97 * width)  # ~3% tolerance
        self.assertTrue(self.ifg.x_size < 1.03 * width)

    def test_centre_latlong(self):
        lat_exp = self.ifg.y_first + \
                  (int(self.ifg.nrows / 2) * self.ifg.y_step)
        long_exp = self.ifg.x_first + \
                   (int(self.ifg.ncols / 2) * self.ifg.x_step)
        self.assertEqual(lat_exp, self.ifg.lat_centre)
        self.assertEqual(long_exp, self.ifg.long_centre)

    def test_centre_cell(self):
        self.assertEqual(self.ifg.x_centre, 23)
        self.assertEqual(self.ifg.y_centre, 36)

    def test_time_span(self):
        self.assertAlmostEqual(self.ifg.time_span, 0.287474332649)

    def test_wavelength(self):
        self.assertEqual(self.ifg.wavelength, 0.0562356424)