-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathtest_vector_pipeline.py
72 lines (56 loc) · 2.27 KB
/
test_vector_pipeline.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# Requires a HydroBasins and MERIT data:
# export DATA_PATH="Library/Application Support/rabpro/"
# mkdir -p "$HOME/$DATA_PATH"
# cp -r ./tests/data/MERIT_Hydro ./tests/data/HydroBasins "$HOME/$DATA_PATH"
import rabpro
from pyproj import CRS
import geopandas as gpd
from rabpro import utils as ru
def test_profiler():
shp_path = r"tests/data/test_coords.shp"
csv_path = r"tests/data/test_coords.csv"
coords_file = gpd.read_file(shp_path)
# read from csv path
rpo_csv = rabpro.profiler(csv_path)
assert str(type(rpo_csv)) == "<class 'rabpro.core.profiler'>"
# read from shp path
rpo_shp = rabpro.profiler(shp_path)
assert str(type(rpo_shp)) == "<class 'rabpro.core.profiler'>"
# read from tuple
rpo_tuple = rabpro.profiler(
(coords_file["latitude"][0], coords_file["longitude"][0])
)
assert str(type(rpo_tuple)) == "<class 'rabpro.core.profiler'>"
# read from gdf
rpo_gdf = rabpro.profiler(coords_file)
assert str(type(rpo_gdf)) == "<class 'rabpro.core.profiler'>"
# read from non-4326 gdf
rpo_gdf_non4326 = rabpro.profiler(coords_file.to_crs(CRS.from_epsg(3857)))
assert str(type(rpo_gdf_non4326)) == "<class 'rabpro.core.profiler'>"
# setting da
rpo_da = rabpro.profiler((56.22659, -130.87974), da=1994)
assert str(type(rpo_da)) == "<class 'rabpro.core.profiler'>"
def test_delineate_basin():
csv_path = r"tests/data/test_coords.csv"
rpo_hydrobasins = rabpro.profiler(csv_path)
rpo_hydrobasins.delineate_basin()
assert (
str(type(rpo_hydrobasins.watershed))
== "<class 'geopandas.geodataframe.GeoDataFrame'>"
)
assert rpo_hydrobasins.watershed.shape[0] > 0
rpo_merit = rabpro.profiler(csv_path, da=1994)
rpo_merit.delineate_basin(force_merit=True)
assert (
str(type(rpo_merit.watershed))
== "<class 'geopandas.geodataframe.GeoDataFrame'>"
)
assert rpo_merit.watershed.shape[0] > 0
def test_elev_profile():
dps = ru.get_datapaths(force=True)
ru.build_virtual_rasters(dps)
csv_path = r"tests/data/test_coords.csv"
rpo = rabpro.profiler(csv_path, da=1994)
rpo.elev_profile(dist_to_walk_km=5)
assert str(type(rpo.flowline)) == "<class 'geopandas.geodataframe.GeoDataFrame'>"
assert rpo.flowline.shape[0] > 0