forked from EarthObservation/RVT_py
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_rvt_tile.py
121 lines (111 loc) · 5.49 KB
/
test_rvt_tile.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
from pathlib import Path
import rvt.tile
import rvt.vis
import rvt.default
import numpy as np
# pytest rvt.tile.save_rvt_visualization_tile_by_tile
dem_path = Path(r"test_data\TM1_564_146.tif")
default_values = rvt.default.DefaultValues()
default_values.tile_size = (100, 100)
default_values.tile_size_limit = 100*100
def test_rvt_slope_tile_by_tile() -> None:
out_slope_float_path = Path(default_values.get_slope_path(dem_path))
out_slope_8bit_path = Path(default_values.get_slope_path(dem_path, True))
rvt.tile.save_rvt_visualization_tile_by_tile(
rvt_visualization=rvt.default.RVTVisualization.SLOPE,
rvt_default=default_values,
dem_path=dem_path,
output_dir_path=dem_path.parent,
save_float=True,
save_8bit=True
)
slope_float_tile_by_tile_arr = rvt.default.get_raster_arr(out_slope_float_path.as_posix())["array"]
slope_8bit_tile_by_tile_arr = rvt.default.get_raster_arr(out_slope_8bit_path.as_posix())["array"]
dem_arr_dict = rvt.default.get_raster_arr(dem_path.as_posix())
slope_arr = default_values.get_slope(
dem_arr=dem_arr_dict["array"],
resolution_x=dem_arr_dict["resolution"][0],
resolution_y=dem_arr_dict["resolution"][1],
no_data=dem_arr_dict["no_data"]
)
slope_8bit_arr = default_values.float_to_8bit(float_arr=slope_arr, visualization=rvt.default.RVTVisualization.SLOPE)
assert np.array_equal(slope_float_tile_by_tile_arr, slope_arr, equal_nan=True)
assert np.array_equal(slope_8bit_tile_by_tile_arr, slope_8bit_arr, equal_nan=True)
def test_rvt_hillshade_tile_by_tile() -> None:
out_hillshade_float_path = Path(default_values.get_hillshade_path(dem_path))
out_hillshade_8bit_path = Path(default_values.get_hillshade_path(dem_path, True))
rvt.tile.save_rvt_visualization_tile_by_tile(
rvt_visualization=rvt.default.RVTVisualization.HILLSHADE,
rvt_default=default_values,
dem_path=dem_path,
output_dir_path=dem_path.parent,
save_float=True,
save_8bit=True
)
hillshade_float_tile_by_tile_arr = rvt.default.get_raster_arr(out_hillshade_float_path.as_posix())["array"]
hillshade_8bit_tile_by_tile_arr = rvt.default.get_raster_arr(out_hillshade_8bit_path.as_posix())["array"]
dem_arr_dict = rvt.default.get_raster_arr(dem_path.as_posix())
hillshade_arr = default_values.get_hillshade(
dem_arr=dem_arr_dict["array"],
resolution_x=dem_arr_dict["resolution"][0],
resolution_y=dem_arr_dict["resolution"][1],
no_data=dem_arr_dict["no_data"]
)
hillshade_8bit_arr = default_values.float_to_8bit(
float_arr=hillshade_arr, visualization=rvt.default.RVTVisualization.HILLSHADE
)
assert np.array_equal(hillshade_float_tile_by_tile_arr, hillshade_arr, equal_nan=True)
assert np.array_equal(hillshade_8bit_tile_by_tile_arr, hillshade_8bit_arr, equal_nan=True)
def test_rvt_svf_tile_by_tile() -> None:
out_svf_float_path = Path(default_values.get_svf_path(dem_path))
out_svf_8bit_path = Path(default_values.get_svf_path(dem_path, True))
rvt.tile.save_rvt_visualization_tile_by_tile(
rvt_visualization=rvt.default.RVTVisualization.SKY_VIEW_FACTOR,
rvt_default=default_values,
dem_path=dem_path,
output_dir_path=dem_path.parent,
save_float=True,
save_8bit=True
)
svf_float_tile_by_tile_arr = rvt.default.get_raster_arr(out_svf_float_path.as_posix())["array"]
svf_8bit_tile_by_tile_arr = rvt.default.get_raster_arr(out_svf_8bit_path.as_posix())["array"]
dem_arr_dict = rvt.default.get_raster_arr(dem_path.as_posix())
svf_arr = default_values.get_sky_view_factor(
dem_arr=dem_arr_dict["array"],
resolution=dem_arr_dict["resolution"][0],
no_data=dem_arr_dict["no_data"]
)["svf"]
svf_8bit_arr = default_values.float_to_8bit(
float_arr=svf_arr, visualization=rvt.default.RVTVisualization.SKY_VIEW_FACTOR
)
assert np.array_equal(svf_float_tile_by_tile_arr, svf_arr, equal_nan=True)
assert np.array_equal(svf_8bit_tile_by_tile_arr, svf_8bit_arr, equal_nan=True)
def test_rvt_multi_hillshade_tile_by_tile() -> None:
out_mhs_float_path = Path(default_values.get_multi_hillshade_path(dem_path))
out_mhs_8bit_path = Path(default_values.get_multi_hillshade_path(dem_path, True))
rvt.tile.save_rvt_visualization_tile_by_tile(
rvt_visualization=rvt.default.RVTVisualization.MULTI_HILLSHADE,
rvt_default=default_values,
dem_path=dem_path,
output_dir_path=dem_path.parent,
save_float=True,
save_8bit=True
)
mhs_float_tile_by_tile_arr = rvt.default.get_raster_arr(out_mhs_float_path.as_posix())["array"]
mhs_8bit_tile_by_tile_arr = rvt.default.get_raster_arr(out_mhs_8bit_path.as_posix())["array"]
dem_arr_dict = rvt.default.get_raster_arr(dem_path.as_posix())
mhs_arr = default_values.get_multi_hillshade(
dem_arr=dem_arr_dict["array"],
resolution_x=dem_arr_dict["resolution"][0],
resolution_y=dem_arr_dict["resolution"][1],
no_data=dem_arr_dict["no_data"]
)
mhs_8bit_arr = default_values.float_to_8bit(
float_arr=dem_arr_dict["array"],
visualization=rvt.default.RVTVisualization.MULTI_HILLSHADE,
x_res=dem_arr_dict["resolution"][0],
y_res=dem_arr_dict["resolution"][1],
no_data=dem_arr_dict["no_data"]
)
assert np.array_equal(mhs_float_tile_by_tile_arr, mhs_arr, equal_nan=True)
assert np.array_equal(mhs_8bit_tile_by_tile_arr, mhs_8bit_arr, equal_nan=True)