-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest_dem.py
executable file
·89 lines (74 loc) · 3.63 KB
/
test_dem.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
# ===============================================================================
# Copyright 2017 dgketchum
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ===============================================================================
import os
import unittest
from rasterio import open as rasopen
from bounds import RasterBounds
from dem import AwsDem
from sat_image.image import Landsat8
class AwsDemTestCase(unittest.TestCase):
def setUp(self):
home = os.path.expanduser('~')
irr = os.path.join('IrrigationGIS')
tst = os.path.join('tests', 'gridmet')
self.dir_name_LC8 = os.path.join(tst, 'LC80380272014227LGN01')
self.raster = os.path.join(self.dir_name_LC8, 'LE07_clip_L1TP_039027_20130726_20160907_01_T1_B3.TIF')
def test_dem(self):
l8 = Landsat8(self.dir_name_LC8)
polygon = l8.get_tile_geometry()
profile = l8.rasterio_geometry
bb = RasterBounds(affine_transform=profile['affine'],
profile=profile, latlon=True)
dem = AwsDem(zoom=10, target_profile=profile, bounds=bb, clip_object=polygon)
elev = dem.terrain(attribute='slope',
out_file='/home/dgketchum/IrrigationGIS/tests/mapzen_'
'{}_{}.tif'.format(l8.target_wrs_path,
l8.target_wrs_row))
self.assertEqual(elev.shape, (1, 7429, 8163))
aspect = dem.terrain(attribute='aspect')
self.assertEqual(aspect.shape, (7429, 8163))
slope = dem.terrain(attribute='slope')
self.assertEqual(slope.shape, (1, 7429, 8163))
def test_other_raster_dem(self):
with rasopen(self.raster) as src:
profile = src.profile
bound_box = RasterBounds(affine_transform=profile['affine'],
profile=profile)
dem = AwsDem(zoom=10, target_profile=profile, bounds=bound_box)
dem.terrain(attribute='elevation',
out_file='/home/dgketchum/IrrigationGIS/tests/mapzen_'
'image_clip_dem.tif')
def test_other_raster_slope(self):
with rasopen(self.raster) as src:
profile = src.profile
bound_box = RasterBounds(affine_transform=profile['affine'],
profile=profile)
dem = AwsDem(zoom=10, target_profile=profile, bounds=bound_box)
dem.terrain(attribute='slope',
out_file='/home/dgketchum/IrrigationGIS/tests/mapzen_'
'image_clip_slope.tif')
def test_other_raster_aspect(self):
with rasopen(self.raster) as src:
profile = src.profile
bound_box = RasterBounds(affine_transform=profile['affine'],
profile=profile)
dem = AwsDem(zoom=10, target_profile=profile, bounds=bound_box)
dem.terrain(attribute='aspect',
out_file='/home/dgketchum/IrrigationGIS/tests/mapzen_'
'image_clip_aspect.tif')
if __name__ == '__main__':
unittest.main()
# ===============================================================================