Skip to content

Commit 6c80156

Browse files
committed
feat: implement proper merge_bands functionality + comprehensive tests
BREAKING CHANGE: merge_bands parameter now correctly creates separate files per band when False Features: - Implement proper separate band file saving (merge_bands=False) - Add 4 comprehensive pytest tests for merge_bands functionality - Tests verify: single vs separate files, band counts, file shapes Tests: - test_merge_bands_geotiff: verifies merge_bands=True creates 1 file with 3 bands - test_separate_bands_geotiff: verifies merge_bands=False creates 3 files with 1 band each - test_merge_bands_numpy: verifies 3D array (3,h,w) for merged - test_separate_bands_numpy: verifies 3 2D arrays (h,w) for separate - All 53 tests passing (4 new merge_bands tests added) Documentation: - Update SAVE_PARAMETERS.md with clear merge_bands explanation - Remove Provider Selection section from README (no need to compare providers) - Add merge_bands_demo.py example demonstrating both modes - Keep models/ directory name (industry standard for Pydantic models) Quality: - Run make clean to remove build artifacts - All linting passing (ruff, flake8, mypy) - Fixed line length and type errors - Professional code structure maintained
1 parent 18cb634 commit 6c80156

File tree

6 files changed

+1168
-93
lines changed

6 files changed

+1168
-93
lines changed

README.md

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ Python package for downloading satellite imagery from multiple sources with a st
2323
- [SAR for All-Weather Monitoring](#sar-for-all-weather-monitoring)
2424
- [Multi-Area Batch Processing](#multi-area-batch-processing)
2525
- [Advanced Features](#advanced-features)
26-
- [Provider Selection](#provider-selection)
2726
- [Overlapping Tile Handling](#overlapping-tile-handling)
2827
- [S3 Storage](#s3-storage)
2928
- [Development](#development)
@@ -251,24 +250,6 @@ for idx, area in areas.iterrows():
251250

252251
## Advanced Features
253252

254-
### Provider Selection
255-
256-
Different providers have different characteristics:
257-
258-
```python
259-
# Microsoft Planetary Computer (MPC)
260-
# - Global coverage, always available
261-
# - Authentication token handled automatically
262-
processing_params = ProcessingParams(satellite='S2MPC')
263-
264-
# Element84 (E84)
265-
# - Better for US/Americas
266-
# - Different band scaling
267-
processing_params = ProcessingParams(satellite='S2E84')
268-
```
269-
270-
See [SATELLITE_SOURCES.md](docs/SATELLITE_SOURCES.md) for provider details.
271-
272253
### Overlapping Tile Handling
273254

274255
By default, overlapping satellite passes from the same day are merged:

docs/SAVE_PARAMETERS.md

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -207,25 +207,31 @@ enable_compression=False # No compression (faster but larger)
207207
**Required**: No
208208
**Default**: `True`
209209

210-
Merge all bands into single multi-band file vs. separate files per band.
210+
Control whether to save all bands in a single multi-band file or as separate single-band files.
211211

212212
```python
213-
merge_bands=True # Single file with multiple bands (recommended)
213+
merge_bands=True # Single multi-band file (recommended)
214214
merge_bands=False # Separate file per band
215215
```
216216

217-
**Single file** (merge_bands=True):
217+
**Single multi-band file** (merge_bands=True):
218218
```
219-
S2MPC_2024-06-15_merged_copenhagen.tif
219+
S2MPC_2024-06-15_merged_copenhagen.tif # Contains all bands (RGB, NIR, etc.)
220220
```
221+
- GeoTIFF: Single file with multiple bands (e.g., 3 bands for RGB)
222+
- NumPy: Single 3D array with shape (bands, height, width)
223+
- Recommended for most use cases
221224

222-
**Separate files** (merge_bands=False):
225+
**Separate single-band files** (merge_bands=False):
223226
```
224227
S2MPC_2024-06-15_red_copenhagen.tif
225228
S2MPC_2024-06-15_green_copenhagen.tif
226229
S2MPC_2024-06-15_blue_copenhagen.tif
227230
S2MPC_2024-06-15_nir_copenhagen.tif
228231
```
232+
- GeoTIFF: One file per band, each containing a single band
233+
- NumPy: One 2D array per band with shape (height, width)
234+
- Useful when processing bands individually or for specialized workflows
229235

230236
## Naming
231237

examples/merge_bands_demo.py

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
"""
2+
Demonstration of merge_bands parameter functionality.
3+
4+
This example shows the difference between:
5+
- merge_bands=True: Saves all bands in a single multi-band file
6+
- merge_bands=False: Saves each band as a separate single-band file
7+
"""
8+
9+
from shapely.geometry import box
10+
11+
from sat_data_acquisition import ProcessingParams, SaveParams, SatDataClient
12+
13+
# Define a small area of interest (Copenhagen, Denmark)
14+
bbox = box(12.5683, 55.6761, 12.5783, 55.6811)
15+
16+
# ===== Example 1: Merged Bands (Default) =====
17+
print("Example 1: Saving as merged multi-band files")
18+
print("=" * 60)
19+
20+
save_params_merged = SaveParams(
21+
output_path="./data/merged_example",
22+
save_to_local=True,
23+
save_as_geotiff=True,
24+
save_as_numpy=True,
25+
merge_bands=True, # Default - saves single multi-band file
26+
)
27+
28+
processing_params = ProcessingParams(
29+
satellite="S2MPC",
30+
search_method="geometry",
31+
start_date="2024-06-01",
32+
end_date="2024-06-05",
33+
max_cloud_cover=20,
34+
bands=["red", "green", "blue"],
35+
)
36+
37+
client = SatDataClient()
38+
39+
print("Downloading and saving merged files...")
40+
for item_data in client.get_data(
41+
geometry=bbox,
42+
processing_params=processing_params,
43+
save_params=save_params_merged,
44+
identifier="copenhagen",
45+
):
46+
print(f" Saved merged file for {item_data['datetime']}")
47+
48+
print("\nOutput structure (merged):")
49+
print(" data/merged_example/S2MPC/2024/tiff/")
50+
print(" └── S2MPC_2024-06-02_merged_copenhagen.tif (3 bands in 1 file)")
51+
print(" data/merged_example/S2MPC/2024/npy/")
52+
print(" └── S2MPC_2024-06-02_merged_copenhagen.npy (shape: 3, h, w)")
53+
print()
54+
55+
# ===== Example 2: Separate Band Files =====
56+
print("\nExample 2: Saving as separate band files")
57+
print("=" * 60)
58+
59+
save_params_separate = SaveParams(
60+
output_path="./data/separate_example",
61+
save_to_local=True,
62+
save_as_geotiff=True,
63+
save_as_numpy=True,
64+
merge_bands=False, # Saves separate file per band
65+
)
66+
67+
print("Downloading and saving separate band files...")
68+
for item_data in client.get_data(
69+
geometry=bbox,
70+
processing_params=processing_params,
71+
save_params=save_params_separate,
72+
identifier="copenhagen",
73+
):
74+
print(f" Saved separate band files for {item_data['datetime']}")
75+
76+
print("\nOutput structure (separate):")
77+
print(" data/separate_example/S2MPC/2024/tiff/")
78+
print(" ├── S2MPC_2024-06-02_red_copenhagen.tif (1 band)")
79+
print(" ├── S2MPC_2024-06-02_green_copenhagen.tif (1 band)")
80+
print(" └── S2MPC_2024-06-02_blue_copenhagen.tif (1 band)")
81+
print(" data/separate_example/S2MPC/2024/npy/")
82+
print(" ├── S2MPC_2024-06-02_red_copenhagen.npy (shape: h, w)")
83+
print(" ├── S2MPC_2024-06-02_green_copenhagen.npy (shape: h, w)")
84+
print(" └── S2MPC_2024-06-02_blue_copenhagen.npy (shape: h, w)")
85+
print()
86+
87+
# ===== Recommendations =====
88+
print("\nRecommendations:")
89+
print("=" * 60)
90+
print("• Use merge_bands=True (default) for:")
91+
print(" - Standard remote sensing workflows")
92+
print(" - Visualization and analysis in QGIS/ArcGIS")
93+
print(" - Machine learning with multi-band inputs")
94+
print(" - More efficient storage and faster loading")
95+
print()
96+
print("• Use merge_bands=False when:")
97+
print(" - Processing bands individually")
98+
print(" - Only using a subset of bands in downstream tasks")
99+
print(" - Integrating with systems expecting single-band files")
100+
print(" - Need flexibility to work with bands separately")

0 commit comments

Comments
 (0)