Skip to content

Commit 7a82d9c

Browse files
author
BriannaLind
committed
hard to say
1 parent bd21a33 commit 7a82d9c

File tree

1 file changed

+36
-16
lines changed

1 file changed

+36
-16
lines changed

src/planet_overlap/pagination.py

Lines changed: 36 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
from typing import List, Tuple, Union
44

55
# Thresholds
6-
POLYGON_AREA_THRESHOLD_KM2 = 2500
7-
DATE_RANGE_THRESHOLD_DAYS = 30
8-
POINT_DATE_THRESHOLD_DAYS = 3 * 365
9-
MAX_SCENES_PER_REQUEST = 500
6+
POLYGON_AREA_THRESHOLD_KM2 = 2500 # AOI > 2500 km² triggers spatial tiling
7+
DATE_RANGE_THRESHOLD_DAYS = 30 # Polygons: split if range >30 days
8+
POINT_DATE_THRESHOLD_DAYS = 3 * 365 # Points: split if range >3 years (~1095 days)
9+
MAX_SCENES_PER_REQUEST = 500 # Max scenes per slice
1010

1111

1212
def estimate_scene_count(days: int, avg_scenes_per_day: float = 1.0) -> int:
@@ -17,25 +17,27 @@ def estimate_scene_count(days: int, avg_scenes_per_day: float = 1.0) -> int:
1717
def tile_dates(
1818
start: datetime, end: datetime, is_point: bool = False
1919
) -> List[Tuple[datetime, datetime]]:
20-
"""Break a date range into smaller slices if it exceeds thresholds.
20+
"""
21+
Break a date range into smaller slices if it exceeds thresholds.
2122
2223
Args:
23-
start: Start datetime
24-
end: End datetime
25-
is_point: True if input is a point, False for polygons/AOIs
24+
start: start datetime
25+
end: end datetime
26+
is_point: True if the input is a point, False for polygons/AOIs
2627
2728
Returns:
2829
List of (start, end) tuples
2930
"""
3031
total_days = (end - start).days + 1
31-
slices = []
32+
slices: List[Tuple[datetime, datetime]] = []
3233

3334
threshold_days = (
3435
POINT_DATE_THRESHOLD_DAYS if is_point else DATE_RANGE_THRESHOLD_DAYS
3536
)
3637
if total_days <= threshold_days:
3738
return [(start, end)]
3839

40+
# Split into slices
3941
slice_length = min(threshold_days, total_days)
4042
current_start = start
4143
while current_start <= end:
@@ -47,17 +49,28 @@ def tile_dates(
4749

4850

4951
def tile_aoi(geom: Union[Polygon, Point]) -> List[Polygon]:
50-
"""Split a polygon into ~1°x1° tiles if AOI is large.
51-
Points are returned as buffered polygons."""
52+
"""
53+
Split a polygon into ~1°x1° tiles if AOI is large.
54+
Points are returned as buffered polygons automatically.
55+
56+
Args:
57+
geom: AOI polygon or point
58+
59+
Returns:
60+
List of Polygons for API requests
61+
"""
5262
if isinstance(geom, Point):
63+
# buffer a small area around the point (~0.01 degrees)
5364
return [geom.buffer(0.01)]
5465

66+
# Check area (approximation using degrees -> km²)
5567
lon_min, lat_min, lon_max, lat_max = geom.bounds
5668
area_km2 = (lon_max - lon_min) * (lat_max - lat_min) * 111**2
5769
if area_km2 <= POLYGON_AREA_THRESHOLD_KM2:
5870
return [geom]
5971

60-
tiles = []
72+
# Split polygon into 1°x1° tiles
73+
tiles: List[Polygon] = []
6174
lat = lat_min
6275
while lat < lat_max:
6376
lon = lon_min
@@ -84,9 +97,16 @@ def fetch_planet_data(
8497
max_cloud: float = 0.5,
8598
min_sun_angle: float = 0.0,
8699
):
87-
"""Main entry point to fetch Planet data,
88-
automatically tiling AOIs or temporal ranges."""
89-
ids, geometries, properties = [], [], []
100+
"""
101+
Main entry point to fetch Planet data, automatically tiling AOIs or
102+
temporal ranges when thresholds are exceeded.
103+
104+
Returns:
105+
ids, geometries, properties
106+
"""
107+
ids: List[str] = []
108+
geometries: List[dict] = []
109+
properties: List[dict] = []
90110

91111
for geom in aois:
92112
is_point = isinstance(geom, Point)
@@ -97,7 +117,7 @@ def fetch_planet_data(
97117
date_slices = tile_dates(start, end, is_point=is_point)
98118

99119
for s_start, s_end in date_slices:
100-
# Mock data for demonstration
120+
# Example: mock appending data
101121
ids.append(f"scene_{s_start.strftime('%Y%m%d')}")
102122
geometries.append(tile.__geo_interface__)
103123
properties.append(

0 commit comments

Comments
 (0)