Search Factory¶
Overview¶
The sat_download.factories.search module provides factory functions for creating SatelliteImage objects from raw API response data.
API Reference¶
Main Factory¶
get_satellite_image
¶
Factory function to create a SatelliteImage object based on collection type and metadata.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
collection
|
COLLECTIONS
|
The satellite collection enum indicating the source platform |
required |
data
|
dict
|
Dictionary containing metadata about the satellite image |
required |
Returns:
| Type | Description |
|---|---|
SatelliteImage
|
A standardized satellite image object with extracted metadata |
Notes
This function delegates to specialized parsers for each collection type. The 'Name' field in the data dictionary is required for all collection types.
Source code in sat_download\factories\search.py
Specialized Parsers¶
get_sentinel2
¶
Parse Sentinel-2 image metadata from filename.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
satellite
|
str
|
The satellite platform name ('Sentinel-2') |
required |
name
|
str
|
The original filename containing metadata components |
required |
Returns:
| Type | Description |
|---|---|
SatelliteImage
|
A standardized satellite image object with extracted metadata |
Notes
Extracts date, satellite brother (A/B), UUID, and tile information from standard Sentinel-2 filename format.
Source code in sat_download\factories\search.py
get_sentinel3
¶
Parse Sentinel-3 image metadata from filename.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
satellite
|
str
|
The satellite platform name ('Sentinel-3') |
required |
name
|
str
|
The original filename containing metadata components |
required |
Returns:
| Type | Description |
|---|---|
SatelliteImage
|
A standardized satellite image object with extracted metadata |
Notes
Extracts date, satellite brother (A/B), UUID, and tile information from standard Sentinel-3 filename format.
Source code in sat_download\factories\search.py
get_landsat_8
¶
Parse Landsat-8 image metadata from filename.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
satellite
|
str
|
The satellite platform name ('Landsat-8') |
required |
name
|
str
|
The original filename containing metadata components |
required |
Returns:
| Type | Description |
|---|---|
SatelliteImage
|
A standardized satellite image object with extracted metadata |
Notes
Extracts date, satellite collection number, UUID, and tile information from standard Landsat-8 filename format.
Source code in sat_download\factories\search.py
Factory Flow¶
flowchart TD
A[get_satellite_image] --> B{Collection Type?}
B -->|SENTINEL_2| C[get_sentinel2]
B -->|SENTINEL_3| D[get_sentinel3]
B -->|LANDSAT_8| E[get_landsat_8]
C --> F[SatelliteImage]
D --> F
E --> F
Usage Examples¶
Basic Usage¶
from sat_download.factories.search import get_satellite_image
from sat_download.enums import COLLECTIONS
# Sentinel-2 data from API response
api_data = {
'Name': 'S2A_MSIL2A_20240115T105421_N0510_R051_T30TWM_20240115T142543.SAFE'
}
# Create SatelliteImage object
image = get_satellite_image(COLLECTIONS.SENTINEL_2, api_data)
print(f"Date: {image.date}") # 20240115
print(f"Tile: {image.tile}") # 30TWM
print(f"Sensor: {image.sensor}") # Sentinel-2
print(f"File: {image.filename}") # S2A_MSIL2A_20240115T105421_N0510_R051_T30TWM_20240115T142543.zip
Landsat 8 Example¶
from sat_download.factories.search import get_satellite_image
from sat_download.enums import COLLECTIONS
# Landsat 8 data from API response
api_data = {
'Name': 'LC08_L1TP_203033_20240115_20240125_02_T1'
}
# Create SatelliteImage object
image = get_satellite_image(COLLECTIONS.LANDSAT_8, api_data)
print(f"Date: {image.date}") # 20240115
print(f"Tile: {image.tile}") # 20303320240115
print(f"Sensor: {image.sensor}") # Landsat-8
print(f"File: {image.filename}") # LC08_L1TP_203033_20240115_20240125_02_T1.tar
Filename Formats¶
Sentinel-2 Format¶
S2A_MSIL2A_20240115T105421_N0510_R051_T30TWM_20240115T142543.SAFE
│ │ │ │ │ │ │
│ │ │ │ │ │ └─ Processing timestamp
│ │ │ │ │ └─ Tile ID (T30TWM)
│ │ │ │ └─ Relative orbit
│ │ │ └─ Processing baseline
│ │ └─ Acquisition date/time
│ └─ Product type (MSIL2A)
└─ Satellite (S2A = Sentinel-2A)
Landsat 8 Format¶
LC08_L1TP_203033_20240115_20240125_02_T1
│ │ │ │ │ │ │
│ │ │ │ │ │ └─ Collection tier (T1)
│ │ │ │ │ └─ Collection number
│ │ │ │ └─ Processing date
│ │ │ └─ Acquisition date
│ │ └─ Path/Row (203/033)
│ └─ Product type (L1TP)
└─ Satellite (LC08 = Landsat 8)
Adding New Satellite Support¶
To add support for a new satellite, create a parser function:
def get_new_satellite(satellite: str, name: str) -> SatelliteImage:
"""
Parse metadata from new satellite filename format.
Parameters
----------
satellite : str
The satellite platform name
name : str
The original filename
Returns
-------
SatelliteImage
Standardized satellite image object
"""
# Parse filename components
components = name.split('_')
# Extract metadata
date = components[DATE_POSITION]
brother = components[SATELLITE_POSITION][-1]
uuid = f"{date}_{components[SATELLITE_POSITION]}"
tile = components[TILE_POSITION]
return SatelliteImage(
uuid=uuid,
date=date,
sensor=satellite,
brother=brother,
identifier=f"{satellite}{brother}",
tile=tile,
filename=f"{name}.zip"
)
Then update get_satellite_image():
def get_satellite_image(collection: COLLECTIONS, data: dict) -> SatelliteImage:
if collection == COLLECTIONS.NEW_SATELLITE:
result = get_new_satellite(collection.value, data['Name'])
# ... existing cases
return result
Design Pattern¶
This module implements the Factory Method Pattern:
get_satellite_image()is the factory method- Specialized parsers handle collection-specific logic
- All return the same
SatelliteImagetype
See: Design Patterns
References¶
- SatelliteImage - Output data type
- COLLECTIONS - Collection identifiers
- Sentinel-2 Naming Convention
- Landsat Naming Convention