Пример #1
0
 def test_output_file_written(self):
     small_test_ifgs = common.small_data_setup()
     extents = [150.91, -34.229999976, 150.949166651, -34.17]
     resolutions = [0.001666666, .001, 0.002, 0.0025, .01]
     for res in resolutions:
         for s in small_test_ifgs:
             resampled_temp_tif = tempfile.mktemp(suffix='.tif',
                                                 prefix='resampled_')
             gdal_python.resample_nearest_neighbour(s.data_path, extents,
                                                    [res, -res],
                                                    resampled_temp_tif)
             self.assertTrue(os.path.exists(resampled_temp_tif))
             os.remove(resampled_temp_tif)
Пример #2
0
    def check_same_resampled_output(self, extents, extents_str, res,
                                    small_test_ifgs):
        cmd = ['gdalwarp', '-overwrite', '-srcnodata', 'None',
               '-q', '-r', 'near', '-te'] \
              + extents_str

        if res[0]:
            new_res_str = [str(r) for r in res]
            cmd += ['-tr'] + new_res_str
        for s in small_test_ifgs:
            temp_tif = tempfile.mktemp(suffix='.tif')
            t_cmd = cmd + [s.data_path, temp_tif]
            subprocess.check_call(t_cmd)
            resampled_ds = gdal.Open(temp_tif)
            resampled_ref = resampled_ds.ReadAsArray()

            resampled_temp_tif = tempfile.mktemp(suffix='.tif',
                                                 prefix='resampled_')
            resampled = gdal_python.resample_nearest_neighbour(s.data_path,
                                                               extents, res,
                                                               resampled_temp_tif)
            np.testing.assert_array_almost_equal(resampled_ref, resampled[0, :, :])
            try:
                os.remove(temp_tif)
            except PermissionError:
                print("File opened by another process.")

            try:
                os.remove(resampled_temp_tif)  # also proves file was written
            except PermissionError:
                print("File opened by another process.")
Пример #3
0
    def test_resampled_tif_has_metadata(self):
        small_test_ifgs = common.small_data_setup()

        # minX, minY, maxX, maxY = extents
        extents = [150.91, -34.229999976, 150.949166651, -34.17]
        for s in small_test_ifgs:

            resampled_temp_tif = tempfile.mktemp(suffix='.tif',
                                                prefix='resampled_')
            gdal_python.resample_nearest_neighbour(
                s.data_path, extents, [None, None], resampled_temp_tif)
            dst_ds = gdal.Open(resampled_temp_tif)
            md = dst_ds.GetMetadata()
            self.assertDictEqual(md, s.meta_data)
            try:
                os.remove(resampled_temp_tif)
            except PermissionError:
                print("File opened by another process.")
Пример #4
0
 def test_small_data_crop_vs_resample(self):
     small_test_ifgs = common.small_data_setup()
     # minX, minY, maxX, maxY = extents
     extents = [150.91, -34.229999976, 150.949166651, -34.17]
     for s in small_test_ifgs:
         clipped = gdal_python.crop(s.data_path, extents)[0]
         resampled_temp_tif = tempfile.mktemp(suffix='.tif',
                                             prefix='resampled_')
         resampled = gdal_python.resample_nearest_neighbour(
             s.data_path, extents, [None, None], resampled_temp_tif)
         self.assertTrue(os.path.exists(resampled_temp_tif))
         np.testing.assert_array_almost_equal(resampled[0, :, :], clipped)
         os.remove(resampled_temp_tif)