1- """
2- filters.py
3- Builds Planet API search filters dynamically for multiple AOIs, multiple date ranges,
4- cloud cover, and sun angle thresholds.
5- """
1+ (
2+ " filters.py Builds Planet API search filters dynamically for multiple AOIs,"
3+ "multiple date ranges, cloud cover, and sun angle thresholds."
4+ )
65
76from datetime import datetime
87from typing import List , Tuple , Dict , Any
98from shapely .geometry import Polygon , mapping
109
1110
1211def geometry_filter (aoi : Polygon ) -> Dict [str , Any ]:
13- """
14- Convert a shapely Polygon into a Planet GeometryFilter.
15-
16- Args:
17- aoi (Polygon): The area of interest.
18-
19- Returns:
20- dict: GeometryFilter for Planet API.
21- """
12+ (
13+ " Convert a shapely Polygon into a Planet GeometryFilter. Args: aoi (Polygon):"
14+ "The area of interest. Returns: dict: GeometryFilter for Planet API."
15+ )
2216 return {"type" : "GeometryFilter" , "field_name" : "geometry" , "config" : mapping (aoi )}
2317
2418
2519def date_range_filter (start : datetime , end : datetime ) -> Dict [str , Any ]:
26- """
27- Convert a start/end datetime into a Planet DateRangeFilter.
28-
29- Args:
30- start (datetime): Start date.
31- end (datetime): End date.
32-
33- Returns:
34- dict: DateRangeFilter for Planet API.
35- """
20+ (
21+ " Convert a start/end datetime into a Planet DateRangeFilter. Args: start"
22+ "(datetime): Start date. end (datetime): End date. Returns: dict:"
23+ "DateRangeFilter for Planet API."
24+ )
3625 return {
3726 "type" : "DateRangeFilter" ,
3827 "field_name" : "acquired" ,
@@ -44,15 +33,10 @@ def date_range_filter(start: datetime, end: datetime) -> Dict[str, Any]:
4433
4534
4635def cloud_cover_filter (max_cloud : float ) -> Dict [str , Any ]:
47- """
48- Filter scenes by maximum cloud cover fraction.
49-
50- Args:
51- max_cloud (float): Max cloud fraction (0.0-1.0).
52-
53- Returns:
54- dict: RangeFilter for cloud_cover.
55- """
36+ (
37+ " Filter scenes by maximum cloud cover fraction. Args: max_cloud (float): Max"
38+ "cloud fraction (0.0-1.0). Returns: dict: RangeFilter for cloud_cover."
39+ )
5640 return {
5741 "type" : "RangeFilter" ,
5842 "field_name" : "cloud_cover" ,
@@ -61,15 +45,10 @@ def cloud_cover_filter(max_cloud: float) -> Dict[str, Any]:
6145
6246
6347def sun_angle_filter (min_sun_angle : float ) -> Dict [str , Any ]:
64- """
65- Filter scenes by minimum sun angle.
66-
67- Args:
68- min_sun_angle (float): Minimum sun angle in degrees.
69-
70- Returns:
71- dict: RangeFilter for sun elevation.
72- """
48+ (
49+ " Filter scenes by minimum sun angle. Args: min_sun_angle (float): Minimum sun"
50+ "angle in degrees. Returns: dict: RangeFilter for sun elevation."
51+ )
7352 return {
7453 "type" : "RangeFilter" ,
7554 "field_name" : "sun_elevation" ,
@@ -83,19 +62,14 @@ def build_filters(
8362 max_cloud : float = 0.5 ,
8463 min_sun_angle : float = 0.0 ,
8564) -> Dict [str , Any ]:
86- """
87- Build a Planet API search filter combining multiple AOIs, date ranges,
88- cloud cover, and sun angle constraints.
89-
90- Args:
91- aois (List[Polygon]): List of AOI polygons.
92- date_ranges (List[Tuple[datetime, datetime]]): List of start/end date tuples.
93- max_cloud (float): Maximum cloud fraction.
94- min_sun_angle (float): Minimum sun elevation in degrees.
95-
96- Returns:
97- dict: Combined Planet API filter ready for pagination.
98- """
65+ (
66+ " Build a Planet API search filter combining multiple AOIs, date ranges, cloud"
67+ "cover, and sun angle constraints. Args: aois (List[Polygon]): List of AOI"
68+ "polygons. date_ranges (List[Tuple[datetime, datetime]]): List of start/end date"
69+ "tuples. max_cloud (float): Maximum cloud fraction. min_sun_angle (float):"
70+ "Minimum sun elevation in degrees. Returns: dict: Combined Planet API filter"
71+ "ready for pagination."
72+ )
9973 # Combine multiple AOIs with OrFilter
10074 if len (aois ) == 1 :
10175 geom_filter = geometry_filter (aois [0 ])
0 commit comments