def test_get_streams(self):
        files = ["small25", "morocco", "tunez", "jebja30"]
        for file in files:
            # Cargamos objeto network guardado previamente
            net_path = infolder + "/{0}_network.net".format(file)
            net = Network(net_path)

            # Exportamos canales a shapefile
            out_shp = outfolder + "/{0}_str.shp".format(file)
            out_con_shp = outfolder + "/{0}_strc.shp".format(file)
            net.export_to_shp(out_shp)
            net.export_to_shp(out_con_shp, True)
    def test_get_streams(self):
        files = ["small25", "tunez", "jebja30"]
        for file in files:
            # Cargamos objeto network guardado previamente
            net_path = infolder + "/{0}_net.dat".format(file)
            net = Network(net_path)

            # Exportamos canales a shapefile
            out_shp = outfolder + "/{0}_str.shp".format(file)
            out_con_shp = outfolder + "/{0}_strcon.shp".format(file)
            net.export_to_shp(out_shp)
            net.export_to_shp(out_con_shp, True)
            computed = [os.path.exists(out_shp), os.path.exists(out_con_shp)]
            self.assertEqual(computed, [True, True])
示例#3
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)