|
1 | | -import pytest |
| 1 | +import unittest |
2 | 2 | import numpy as np |
3 | | -from shapely.geometry import Polygon |
4 | | -from planet_overlap.analysis import compute_intersections |
5 | | - |
6 | | -def test_intersection_area(): |
7 | | - poly1 = Polygon([(-1,0), (0,1), (1,0), (0,-1)]) |
8 | | - poly2 = Polygon([(0,0), (1,1), (2,0), (1,-1)]) |
9 | | - area_matrix = compute_intersections([poly1, poly2]) |
10 | | - assert area_matrix.shape == (2,2) |
11 | | - assert area_matrix[0,1] > 0 |
12 | | - assert area_matrix[1,0] == area_matrix[0,1] |
| 3 | +from planet_overlap import analysis |
| 4 | + |
| 5 | +class TestAnalysisMultiTile(unittest.TestCase): |
| 6 | + |
| 7 | + def setUp(self): |
| 8 | + # Example mock data: 2 tiles, 2 scenes each |
| 9 | + self.all_properties = [ |
| 10 | + [ |
| 11 | + {"ground_control": True, "quality_category": "standard", "view_angle": 2.5, |
| 12 | + "acquired": "2023-06-15T10:15:00Z", "sun_elevation": 45.0, |
| 13 | + "cloud_cover": 0.2, "satellite_id": "A", "instrument": "Planetscope"}, |
| 14 | + {"ground_control": True, "quality_category": "standard", "view_angle": 1.0, |
| 15 | + "acquired": "2023-06-15T11:00:00Z", "sun_elevation": 50.0, |
| 16 | + "cloud_cover": 0.1, "satellite_id": "B", "instrument": "Planetscope"} |
| 17 | + ], |
| 18 | + [ |
| 19 | + {"ground_control": True, "quality_category": "standard", "view_angle": 2.0, |
| 20 | + "acquired": "2023-06-16T09:45:00Z", "sun_elevation": 60.0, |
| 21 | + "cloud_cover": 0.3, "satellite_id": "C", "instrument": "Planetscope"}, |
| 22 | + {"ground_control": True, "quality_category": "standard", "view_angle": 1.5, |
| 23 | + "acquired": "2023-06-16T10:30:00Z", "sun_elevation": 55.0, |
| 24 | + "cloud_cover": 0.4, "satellite_id": "D", "instrument": "Planetscope"} |
| 25 | + ] |
| 26 | + ] |
| 27 | + |
| 28 | + self.all_geometries = [ |
| 29 | + [ |
| 30 | + {"coordinates": [[[-121, 38], [-121, 38.1], [-120.9, 38.1], [-120.9, 38], [-121, 38]]]}, |
| 31 | + {"coordinates": [[[-121, 38.2], [-121, 38.3], [-120.9, 38.3], [-120.9, 38.2], [-121, 38.2]]]} |
| 32 | + ], |
| 33 | + [ |
| 34 | + {"coordinates": [[[-121.5, 38.5], [-121.5, 38.6], [-121.4, 38.6], [-121.4, 38.5], [-121.5, 38.5]]]}, |
| 35 | + {"coordinates": [[[-121.6, 38.7], [-121.6, 38.8], [-121.5, 38.8], [-121.5, 38.7], [-121.6, 38.7]]]} |
| 36 | + ] |
| 37 | + ] |
| 38 | + |
| 39 | + self.all_ids = [ |
| 40 | + ["tile1_scene1", "tile1_scene2"], |
| 41 | + ["tile2_scene1", "tile2_scene2"] |
| 42 | + ] |
| 43 | + |
| 44 | + def test_multi_tile_processing(self): |
| 45 | + gdf = analysis.process_tiles(self.all_properties, self.all_geometries, self.all_ids) |
| 46 | + self.assertEqual(len(gdf), 4) |
| 47 | + self.assertIn("view_angle", gdf.columns) |
| 48 | + self.assertIn("sun_angle", gdf.columns) |
| 49 | + self.assertTrue(np.all(gdf["view_angle"] < 3)) |
| 50 | + self.assertTrue(np.all(gdf["max_sun_diff"] >= 0)) |
| 51 | + |
| 52 | +if __name__ == "__main__": |
| 53 | + unittest.main() |
0 commit comments