Exemplo n.º 1
0
 def test_create_load(self):
     dem_files = ['tunez', 'tunez2', 'small25']
     for filename in dem_files:
         fd = Flow("data/fd_{0}.tif".format(filename))
         st = Network(fd, 1000)
         computed = [
             st.get_dims(),
             st.get_size(),
             st.get_ncells(),
             st.get_cellsize(),
             st.get_geotransform(),
             st.get_projection()
         ]
         expected = [
             fd.get_dims(),
             fd.get_size(),
             fd.get_ncells(),
             fd.get_cellsize(),
             fd.get_geotransform(),
             fd.get_projection()
         ]
         self.assertTrue(computed, expected)
Exemplo n.º 2
0
    def test_empty_network(self):
        net = Network()

        # Test PRaster properties
        self.assertEqual(net.get_cellsize(), (1.0, -1.0))
        self.assertEqual(net.get_dims(), (1, 1))
        self.assertEqual(net.get_size(), (1, 1))
        self.assertEqual(net.get_extent(), (0.0, 1.0, 0.0, 1.0))
        self.assertEqual(net.get_geotransform(),
                         (0.0, 1.0, 0.0, 1.0, 0.0, -1.0))
        self.assertEqual(net.get_ncells(), 1)
        self.assertEqual(net.get_projection(), "")

        # Test PRaster functions
        self.assertEqual(net.cell_2_ind(0, 0), .0)
        self.assertEqual(net.cell_2_xy(0, 0), (0.5, 0.5))
        self.assertEqual(net.xy_2_cell(1, 1), (0, 1))
        self.assertEqual(net.ind_2_cell(0), (0, 0))

        # Test saving functions
        path = outfolder + "/net_delete.dat"
        net.save(path)
        self.assertEqual(os.path.exists(path), True)
        if os.path.exists(path):
            os.remove(path)

        path = outfolder + "/points_delete.txt"
        net.export_to_points(path)
        self.assertEqual(os.path.exists(path), True)
        if os.path.exists(path):
            os.remove(path)

        path = outfolder + "/shp_delete.shp"
        net.export_to_shp(path)
        self.assertEqual(os.path.exists(path), True)
        if os.path.exists(path):
            os.remove(path)

        path = outfolder + "/chi_delete.shp"
        net.get_chi_shapefile(path, 0)
        self.assertEqual(os.path.exists(path), True)
        if os.path.exists(path):
            os.remove(path)

        # Test other functions
        self.assertEqual(
            np.array_equal(net.get_streams(False),
                           np.array([1]).reshape(1, 1)), True)
        self.assertEqual(
            np.array_equal(net.get_stream_segments(False),
                           np.array([0]).reshape(1, 1)), True)
        self.assertEqual(
            np.array_equal(net.get_stream_orders("strahler", False),
                           np.array([1]).reshape(1, 1)), True)
        self.assertEqual(
            np.array_equal(net.get_stream_orders('shreeve', False),
                           np.array([1]).reshape(1, 1)), True)
        self.assertEqual(
            np.array_equal(net.get_stream_orders('dinosaur', False),
                           np.array([1]).reshape(1, 1)), True)
        self.assertEqual(
            np.array_equal(net.get_stream_poi("heads", "XY"),
                           np.array([]).reshape(0, 2)), True)
        self.assertEqual(
            np.array_equal(net.get_stream_poi("heads", "CELL"),
                           np.array([]).reshape(0, 2)), True)
        self.assertEqual(
            np.array_equal(net.get_stream_poi("heads", "IND"), np.array([])),
            True)
        self.assertEqual(
            np.array_equal(net.get_stream_poi("confluences", "XY"),
                           np.array([]).reshape(0, 2)), True)
        self.assertEqual(
            np.array_equal(net.get_stream_poi("confluences", "CELL"),
                           np.array([]).reshape(0, 2)), True)
        self.assertEqual(
            np.array_equal(net.get_stream_poi("confluences", "IND"),
                           np.array([])), True)
        self.assertEqual(
            np.array_equal(net.get_stream_poi("outlets", "XY"),
                           np.array([]).reshape(0, 2)), True)
        self.assertEqual(
            np.array_equal(net.get_stream_poi("outlets", "CELL"),
                           np.array([]).reshape(0, 2)), True)
        self.assertEqual(
            np.array_equal(net.get_stream_poi("outlets", "IND"), np.array([])),
            True)
        self.assertEqual(
            np.array_equal(net.get_stream_poi("dinosaur", "dinosaur"),
                           np.array([]).reshape(0, 2)), True)
        self.assertEqual(
            np.array_equal(net.snap_points(np.array((5, 5)).reshape(1, 2)),
                           np.array([[0.5, 0.5]])), True)
        self.assertEqual(net.is_inside(0, 0), False)
        net.calculate_gradients(0)