-
Notifications
You must be signed in to change notification settings - Fork 66
/
Copy pathtest_ImageLayer.py
87 lines (76 loc) · 3.12 KB
/
test_ImageLayer.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
import unittest
import numpy as np
import rasterio as rio
import mesa_geo as mg
class TestImageLayer(unittest.TestCase):
def setUp(self) -> None:
self.src_shape = (3, 500, 500)
self.dst_shape = (3, 400, 583)
self.src_crs = "epsg:4326"
self.dst_crs = "epsg:3857"
self.src_transform = rio.transform.Affine(
0.0006333333333759583,
0.00,
-122.26638888878,
0.00,
-0.00031777777779916507,
43.01472222189958,
)
self.dst_transform = rio.transform.Affine(
60.43686114587856,
0.00,
-13610632.15223135,
0.00,
-60.43686114587856,
5314212.987773206,
)
self.src_bounds = [
-122.26638888878,
42.855833333,
-121.94972222209202,
43.01472222189958,
]
self.dst_bounds = [
-13610632.15223135,
5290053.890954778,
-13575380.980144441,
5314212.987773206,
]
self.src_resolution = (0.0006333333333759583, 0.00031777777779916507)
self.dst_resolution = (60.43686114587856, 60.43686114587856)
self.image_layer = mg.ImageLayer(
values=np.random.uniform(low=0, high=255, size=self.src_shape),
crs=self.src_crs,
total_bounds=self.src_bounds,
)
def tearDown(self) -> None:
pass
def test_to_crs(self):
transformed_image_layer = self.image_layer.to_crs(self.dst_crs)
self.assertEqual(transformed_image_layer.crs, self.dst_crs)
self.assertEqual(transformed_image_layer.height, self.dst_shape[1])
self.assertEqual(transformed_image_layer.width, self.dst_shape[2])
self.assertTrue(
transformed_image_layer.transform.almost_equals(self.dst_transform)
)
np.testing.assert_almost_equal(
transformed_image_layer.total_bounds, self.dst_bounds
)
np.testing.assert_almost_equal(
transformed_image_layer.resolution, self.dst_resolution
)
# no change to original layer
self.assertEqual(self.image_layer.crs, self.src_crs)
self.assertEqual(self.image_layer.height, self.src_shape[1])
self.assertEqual(self.image_layer.width, self.src_shape[2])
self.assertTrue(self.image_layer.transform.almost_equals(self.src_transform))
np.testing.assert_almost_equal(self.image_layer.total_bounds, self.src_bounds)
np.testing.assert_almost_equal(self.image_layer.resolution, self.src_resolution)
def test_to_crs_inplace(self):
self.image_layer.to_crs(self.dst_crs, inplace=True)
self.assertEqual(self.image_layer.crs, self.dst_crs)
self.assertEqual(self.image_layer.height, self.dst_shape[1])
self.assertEqual(self.image_layer.width, self.dst_shape[2])
self.assertTrue(self.image_layer.transform.almost_equals(self.dst_transform))
np.testing.assert_almost_equal(self.image_layer.total_bounds, self.dst_bounds)
np.testing.assert_almost_equal(self.image_layer.resolution, self.dst_resolution)