示例#1
0
文件: temp.py 项目: geolovic/topopy
"""

from topopy import DEM, Flow, Network, BNetwork, extract_points, Channel
import matplotlib.pyplot as plt
import numpy as np
from profiler import TProfile

# Test longitudinal profile
# Load profiles (TProfile)
prof_path = "/Users/vicen/Desktop/genil_profiler/scripts/files/graph_profiles.npy"
perfiles = np.load(prof_path, allow_pickle=True)
perfil = perfiles[0]

# Load channels (Channel)
net = Network("/Users/vicen/Desktop/genil_profiler/gisdata/genil_net.dat")
net.calculate_gradients(20, "slp")
heads = extract_points("/Users/vicen/Desktop/genil_profiler/gisdata/heads.shp",
                       "id")
canal = net.get_channel(heads[0])

fig, ax = plt.subplots()

# di = perfil.get_l()
# zi = perfil.get_z()
# ax.plot(di, zi, c="b")

# di2 = canal.get_d()
# zi2 = canal.get_z()
# ax.plot(di2, zi2, c="r")

slopes = perfil.get_slope()
示例#2
0
# -*- coding: utf-8 -*-
"""
Editor de Spyder

Este es un archivo temporal
"""

from topopy import Network, Channel
import ogr
import numpy as np
import matplotlib.pyplot as plt

# Test longitudinal profile
# Load profiles (TProfile)
net = Network("../data/in/tunez_net.dat")
net.calculate_gradients(20)
shp_path = "../data/in/tunez_channels.shp"

dataset = ogr.Open(shp_path)
layer = dataset.GetLayer(0)
canales = []

for n in range(layer.GetFeatureCount()):
    feat = layer.GetFeature(n)
    geom = feat.GetGeometryRef()
    head = geom.GetPoint(0)
    mouth = geom.GetPoint(geom.GetPointCount() - 1)
    canal = net.get_channel(head, mouth)
    canales.append(canal)

fig, ax = plt.subplots()
示例#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)