Skip to content

Commit 5e6aa0c

Browse files
author
BriannaLind
committed
reformat strings
1 parent e7f189f commit 5e6aa0c

File tree

10 files changed

+161
-193
lines changed

10 files changed

+161
-193
lines changed

reformat_strings.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# filename: reformat_strings.py
2+
# Usage: python reformat_strings.py
3+
4+
import re
5+
from pathlib import Path
6+
from textwrap import wrap
7+
8+
SRC_DIR = Path("src/planet_overlap")
9+
MAX_LINE = 79
10+
11+
STRING_PATTERN = re.compile(r'(?P<quote>["\']{3}|["\'])(?P<content>.*?)(?P=quote)', re.DOTALL)
12+
13+
def split_long_string(s, max_length=MAX_LINE):
14+
"""Split a string into multiple concatenated strings <= max_length."""
15+
lines = wrap(s, width=max_length, break_long_words=False, replace_whitespace=False)
16+
# Wrap each line in quotes
17+
return "(\n " + "\n ".join(f'"{line}"' for line in lines) + "\n)"
18+
19+
def process_file(file_path):
20+
with open(file_path, "r", encoding="utf-8") as f:
21+
content = f.read()
22+
23+
def replacer(match):
24+
quote = match.group("quote")
25+
text = match.group("content")
26+
# Only process if longer than max
27+
if "\n" in text or len(text) > MAX_LINE:
28+
# Remove internal newlines to avoid double line breaks
29+
text_clean = " ".join(line.strip() for line in text.splitlines())
30+
return split_long_string(text_clean)
31+
return match.group(0)
32+
33+
new_content = STRING_PATTERN.sub(replacer, content)
34+
35+
with open(file_path, "w", encoding="utf-8") as f:
36+
f.write(new_content)
37+
38+
print(f"Processed {file_path}")
39+
40+
def main():
41+
for py_file in SRC_DIR.rglob("*.py"):
42+
process_file(py_file)
43+
44+
if __name__ == "__main__":
45+
main()

src/planet_overlap/__init__.py

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
1-
"""
2-
planet_overlap
3-
4-
Smart PlanetScope imagery querying and analysis with:
5-
- Conditional spatial tiling
6-
- Robust retry handling
7-
- Progress tracking
8-
- Multi-AOI support
9-
- Point buffering
10-
"""
1+
(
2+
" planet_overlap Smart PlanetScope imagery querying and analysis with: -"
3+
"Conditional spatial tiling - Robust retry handling - Progress tracking - Multi-"
4+
"AOI support - Point buffering"
5+
)
116

127
__version__ = "0.1.0"

src/planet_overlap/analysis.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,10 @@ def calculate_intersections(
8080
min_sun_angle: float = 0,
8181
area_threshold: float = 25.0,
8282
) -> Tuple[np.ndarray, np.ndarray]:
83-
"""
84-
Compute pairwise intersected areas and sun angle differences between polygons.
85-
Only compares polygons from the same instrument and different satellites.
86-
"""
83+
(
84+
" Compute pairwise intersected areas and sun angle differences between polygons."
85+
"Only compares polygons from the same instrument and different satellites."
86+
)
8787
n = len(polygons)
8888
area_2d = np.zeros((n, n), dtype=np.float32)
8989
sun_diff_2d = np.zeros((n, n), dtype=np.float32)
@@ -117,9 +117,9 @@ def process_tiles(
117117
min_view_angle: float = 3,
118118
min_sun_angle: float = 0,
119119
) -> gpd.GeoDataFrame:
120-
"""
121-
Process multiple tiles/datasets and return a unified GeoDataFrame.
122-
"""
120+
(
121+
" Process multiple tiles/datasets and return a unified GeoDataFrame."
122+
)
123123
merged_properties = []
124124
merged_geometries = []
125125
merged_ids = []

src/planet_overlap/client.py

Lines changed: 23 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,11 @@
1-
"""
2-
client.py - Entry point for running Planet Overlap analysis.
3-
4-
This script:
5-
1. Reads AOI GeoJSON files.
6-
2. Applies filters (geometry, date, cloud cover, sun angle).
7-
3. Handles spatial and temporal tiling automatically.
8-
4. Calls pagination module to fetch imagery.
9-
5. Calls analysis module to compute overlaps and sun angles.
10-
6. Stores output to configurable directory.
11-
12-
Supports multiple AOIs and multiple date ranges.
13-
"""
1+
(
2+
" client.py - Entry point for running Planet Overlap analysis. This script: 1."
3+
"Reads AOI GeoJSON files. 2. Applies filters (geometry, date, cloud cover, sun"
4+
"angle). 3. Handles spatial and temporal tiling automatically. 4. Calls"
5+
"pagination module to fetch imagery. 5. Calls analysis module to compute"
6+
"overlaps and sun angles. 6. Stores output to configurable directory. Supports"
7+
"multiple AOIs and multiple date ranges."
8+
)
149

1510
# client.py
1611
import logging
@@ -24,16 +19,11 @@
2419
def prepare_filters(
2520
geojson_paths: List[str], date_ranges: List[Tuple[str, str]]
2621
) -> dict:
27-
"""
28-
Build filters for multiple AOIs and date ranges.
29-
30-
Args:
31-
geojson_paths: List of file paths to AOI geojsons.
32-
date_ranges: List of (start_date, end_date) tuples.
33-
34-
Returns:
35-
Dictionary containing combined filters.
36-
"""
22+
(
23+
" Build filters for multiple AOIs and date ranges. Args: geojson_paths: List of"
24+
"file paths to AOI geojsons. date_ranges: List of (start_date, end_date) tuples."
25+
"Returns: Dictionary containing combined filters."
26+
)
3727
filters = build_filters(geojson_paths, date_ranges)
3828
logging.info(
3929
"Filters prepared for %d AOIs/date ranges", len(filters.get("config", []))
@@ -42,31 +32,22 @@ def prepare_filters(
4232

4333

4434
def load_aois(geojson_paths: List[str]):
45-
"""
46-
Load AOIs from GeoJSON files.
47-
48-
Args:
49-
geojson_paths: List of AOI geojson paths.
50-
51-
Returns:
52-
List of AOI geometries.
53-
"""
35+
(
36+
" Load AOIs from GeoJSON files. Args: geojson_paths: List of AOI geojson paths."
37+
"Returns: List of AOI geometries."
38+
)
5439
aois = [load_aoi(path) for path in geojson_paths]
5540
logging.info("Loaded %d AOIs", len(aois))
5641
return aois
5742

5843

5944
def run_client(geojson_paths: List[str], date_ranges: List[Tuple[str, str]]):
60-
"""
61-
Full client workflow: load AOIs, prepare filters, and return filters + AOIs.
62-
63-
Args:
64-
geojson_paths: List of AOI GeoJSON paths.
65-
date_ranges: List of (start_date, end_date) tuples.
66-
67-
Returns:
68-
Tuple of (filters dict, list of AOI geometries)
69-
"""
45+
(
46+
" Full client workflow: load AOIs, prepare filters, and return filters + AOIs."
47+
"Args: geojson_paths: List of AOI GeoJSON paths. date_ranges: List of"
48+
"(start_date, end_date) tuples. Returns: Tuple of (filters dict, list of AOI"
49+
"geometries)"
50+
)
7051
aois = load_aois(geojson_paths)
7152
filters = prepare_filters(geojson_paths, date_ranges)
7253
# Use filters downstream; previously 'combined_filter' was unused

src/planet_overlap/filters.py

Lines changed: 29 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,27 @@
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

76
from datetime import datetime
87
from typing import List, Tuple, Dict, Any
98
from shapely.geometry import Polygon, mapping
109

1110

1211
def 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

2519
def 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

4635
def 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

6347
def 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])

src/planet_overlap/geometry.py

Lines changed: 20 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
"""
2-
geometry.py
3-
Handles AOI (Area of Interest) loading, point detection, buffering,
4-
and preparation for Planet API requests.
5-
Supports single/multiple AOIs, points, and polygons.
6-
"""
1+
(
2+
" geometry.py Handles AOI (Area of Interest) loading, point detection,"
3+
"buffering, and preparation for Planet API requests. Supports single/multiple"
4+
"AOIs, points, and polygons."
5+
)
76

87
from pathlib import Path
98
from shapely.geometry import Point, Polygon
@@ -16,15 +15,11 @@
1615

1716

1817
def load_aoi(paths: List[Union[str, Path]]) -> List[Polygon]:
19-
"""
20-
Load AOIs from multiple GeoJSON files or single polygons.
21-
22-
Args:
23-
paths (List[str | Path]): List of GeoJSON file paths
24-
25-
Returns:
26-
List[Polygon]: List of polygons representing AOIs
27-
"""
18+
(
19+
" Load AOIs from multiple GeoJSON files or single polygons. Args: paths"
20+
"(List[str | Path]): List of GeoJSON file paths Returns: List[Polygon]: List of"
21+
"polygons representing AOIs"
22+
)
2823
aois: List[Polygon] = []
2924
for path in paths:
3025
path = Path(path)
@@ -44,16 +39,12 @@ def load_aoi(paths: List[Union[str, Path]]) -> List[Polygon]:
4439

4540

4641
def buffer_points(points: List[Point], buffer_deg: float = 0.01) -> List[Polygon]:
47-
"""
48-
Converts points into small polygons (buffers) for Planet requests.
49-
50-
Args:
51-
points (List[Point]): List of shapely Point objects
52-
buffer_deg (float): Buffer radius in degrees (default 0.01 ~1 km)
53-
54-
Returns:
55-
List[Polygon]: Buffered polygons
56-
"""
42+
(
43+
" Converts points into small polygons (buffers) for Planet requests. Args:"
44+
"points (List[Point]): List of shapely Point objects buffer_deg (float): Buffer"
45+
"radius in degrees (default 0.01 ~1 km) Returns: List[Polygon]: Buffered"
46+
"polygons"
47+
)
5748
buffered = [pt.buffer(buffer_deg) for pt in points]
5849
logger.info(
5950
f"Buffered {len(points)} points into polygons with {buffer_deg}° radius"
@@ -62,15 +53,10 @@ def buffer_points(points: List[Point], buffer_deg: float = 0.01) -> List[Polygon
6253

6354

6455
def unify_aois(aois: List[Polygon]) -> Polygon:
65-
"""
66-
Merge multiple AOIs into a single polygon if needed.
67-
68-
Args:
69-
aois (List[Polygon]): List of polygons
70-
71-
Returns:
72-
Polygon: Single merged polygon
73-
"""
56+
(
57+
" Merge multiple AOIs into a single polygon if needed. Args: aois"
58+
"(List[Polygon]): List of polygons Returns: Polygon: Single merged polygon"
59+
)
7460
merged = unary_union(aois)
7561
if isinstance(merged, Polygon):
7662
return merged

src/planet_overlap/logger.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33

44

55
def setup_logger(log_file: str | None = None):
6-
"""
7-
Configure logging for console and optional file output.
8-
"""
6+
(
7+
" Configure logging for console and optional file output."
8+
)
99
handlers = [logging.StreamHandler(sys.stdout)]
1010

1111
if log_file:

0 commit comments

Comments
 (0)