예제 #1
0
    def test_actual_arrays(self):
        known_raster_file = resource_filename("tidegates.testing.polygons_to_raster", "test_zones_raster.tif")
        known_raster = utils.load_data(known_raster_file, 'raster')
        raster = utils.polygons_to_raster(self.testfile, "GeoID", **self.kwargs)
        arrays = utils.rasters_to_arrays(raster, known_raster)
        arcpy.management.Delete(raster)

        nptest.assert_array_almost_equal(*arrays)
예제 #2
0
    def test_actual_arrays(self):
        known_raster_file = resource_filename(
            "tidegates.testing.polygons_to_raster", "test_zones_raster.tif")
        known_raster = utils.load_data(known_raster_file, 'raster')
        raster = utils.polygons_to_raster(self.testfile, "GeoID",
                                          **self.kwargs)
        arrays = utils.rasters_to_arrays(raster, known_raster)
        arcpy.management.Delete(raster)

        nptest.assert_array_almost_equal(*arrays)
예제 #3
0
    def test_process(self):
        raster = utils.polygons_to_raster(self.testfile, "GeoID", **self.kwargs)
        nt.assert_true(isinstance(raster, arcpy.Raster))

        array = utils.rasters_to_arrays(raster, squeeze=True)
        arcpy.management.Delete(raster)

        flat_arr = array.flatten()
        bins = numpy.bincount(flat_arr[flat_arr > 0])
        nptest.assert_array_almost_equal(numpy.unique(array), self.known_values)
        nptest.assert_array_almost_equal(bins[bins > 0], self.known_counts)
        nt.assert_tuple_equal(array.shape, self.known_shape)
예제 #4
0
    def test_process(self):
        raster = utils.polygons_to_raster(self.testfile, "GeoID",
                                          **self.kwargs)
        nt.assert_true(isinstance(raster, arcpy.Raster))

        array = utils.rasters_to_arrays(raster, squeeze=True)
        arcpy.management.Delete(raster)

        flat_arr = array.flatten()
        bins = numpy.bincount(flat_arr[flat_arr > 0])
        nptest.assert_array_almost_equal(numpy.unique(array),
                                         self.known_values)
        nptest.assert_array_almost_equal(bins[bins > 0], self.known_counts)
        nt.assert_tuple_equal(array.shape, self.known_shape)
예제 #5
0
    def test_multiple_args(self):
        arrays = utils.rasters_to_arrays(self.rasterfile1,
                                         self.rasterfile2,
                                         self.rasterfile3,
                                         squeeze=True)

        nt.assert_true(isinstance(arrays, list))
        nt.assert_equal(len(arrays), 3)

        for a, kn in zip(
                arrays,
            [self.known_array1, self.known_array2, self.known_array3]):
            nt.assert_true(isinstance(a, numpy.ndarray))
            nptest.assert_array_almost_equal(a, kn)
예제 #6
0
    def test_multiple_args(self):
        arrays = utils.rasters_to_arrays(
            self.rasterfile1,
            self.rasterfile2,
            self.rasterfile3,
            squeeze=True
        )

        nt.assert_true(isinstance(arrays, list))
        nt.assert_equal(len(arrays), 3)

        for a, kn in zip(arrays, [self.known_array1, self.known_array2, self.known_array3]):
            nt.assert_true(isinstance(a, numpy.ndarray))
            nptest.assert_array_almost_equal(a, kn)
예제 #7
0
def test_clip_dem_to_zones():
    demfile = resource_filename("tidegates.testing.clip_dem_to_zones", 'test_dem.tif')
    zonefile = resource_filename("tidegates.testing.clip_dem_to_zones", "test_zones_raster_small.tif")
    raster = utils.clip_dem_to_zones(demfile, zonefile)

    zone_r = utils.load_data(zonefile, 'raster')

    arrays = utils.rasters_to_arrays(raster, zone_r)

    dem_a, zone_a = arrays[0], arrays[1]
    arcpy.management.Delete(raster)

    nt.assert_true(isinstance(raster, arcpy.Raster))

    known_shape = (146, 172)
    nt.assert_tuple_equal(dem_a.shape, zone_a.shape)
예제 #8
0
def test_clip_dem_to_zones():
    demfile = resource_filename("tidegates.testing.clip_dem_to_zones",
                                'test_dem.tif')
    zonefile = resource_filename("tidegates.testing.clip_dem_to_zones",
                                 "test_zones_raster_small.tif")
    raster = utils.clip_dem_to_zones(demfile, zonefile)

    zone_r = utils.load_data(zonefile, 'raster')

    arrays = utils.rasters_to_arrays(raster, zone_r)

    dem_a, zone_a = arrays[0], arrays[1]
    arcpy.management.Delete(raster)

    nt.assert_true(isinstance(raster, arcpy.Raster))

    known_shape = (146, 172)
    nt.assert_tuple_equal(dem_a.shape, zone_a.shape)
예제 #9
0
    def test_already_a_raster(self):
        raster = arcpy.Raster(self.rasterpath)
        x = utils.load_data(raster, 'raster')
        nt.assert_true(isinstance(x, arcpy.Raster))

        nptest.assert_array_almost_equal(*utils.rasters_to_arrays(x, raster))
예제 #10
0
 def test_int_array(self):
     array = utils.rasters_to_arrays(self.rasterfile3, squeeze=True)
     nt.assert_true(isinstance(array, numpy.ndarray))
     nptest.assert_array_almost_equal(array, self.known_array3)
예제 #11
0
 def test_with_missing_values_squeeze(self):
     array = utils.rasters_to_arrays(self.rasterfile2, squeeze=True)
     nt.assert_true(isinstance(array, numpy.ndarray))
     nptest.assert_array_almost_equal(array, self.known_array2)
예제 #12
0
 def test_one_raster(self):
     array = utils.rasters_to_arrays(self.rasterfile1)
     nt.assert_true(isinstance(array, list))
     nt.assert_equal(len(array), 1)
     nptest.assert_array_almost_equal(array[0], self.known_array1)
예제 #13
0
    def test_already_a_raster(self):
        raster = arcpy.Raster(self.rasterpath)
        x = utils.load_data(raster, 'raster')
        nt.assert_true(isinstance(x, arcpy.Raster))

        nptest.assert_array_almost_equal(*utils.rasters_to_arrays(x, raster))
예제 #14
0
 def test_int_array(self):
     array = utils.rasters_to_arrays(self.rasterfile3, squeeze=True)
     nt.assert_true(isinstance(array, numpy.ndarray))
     nptest.assert_array_almost_equal(array, self.known_array3)
예제 #15
0
 def test_with_missing_values_squeeze(self):
     array = utils.rasters_to_arrays(self.rasterfile2, squeeze=True)
     nt.assert_true(isinstance(array, numpy.ndarray))
     nptest.assert_array_almost_equal(array, self.known_array2)
예제 #16
0
 def test_one_raster(self):
     array = utils.rasters_to_arrays(self.rasterfile1)
     nt.assert_true(isinstance(array, list))
     nt.assert_equal(len(array), 1)
     nptest.assert_array_almost_equal(array[0], self.known_array1)