Skip to content

Commit 3347429

Browse files
committed
feat: Complete multi-satellite API integration and optimize usage
This commit implements the integration of three satellite data sources: - Sentinel-5P for air pollutants and trace gases - MODIS for aerosol optical depth measurements - ERA5 for meteorological reanalysis data Key improvements: - Unified API design across all satellite platforms - Consistent data processing pipeline (fetch → download → process) - Optimized parallel downloading with progress tracking - Added automatic file retention management - Enhanced documentation with usage examples The implementation includes quality control filters and standardized visualization outputs for each data source, making satellite data more accessible for environmental analysis.
1 parent c1ce61b commit 3347429

27 files changed

+2144
-1415
lines changed

.env.example

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Copernicus Open Access Hub API credentials
2+
COPERNICUS_USERNAME=your_username
3+
COPERNICUS_PASSWORD=your_password
4+
5+
# NASA EARTHDATA credentials
6+
EARTHDATA_USERNAME=your_username
7+
EARTHDATA_PASSWORD=your_password
8+
9+
# CDS API credentials
10+
CDSAPI_URL=https://cds.climate.copernicus.eu/api/v2
11+
CDSAPI_KEY=your_key

README.md

Lines changed: 184 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
## <div align="center">Satellite_S5P</div>
1+
## <div align="center">Satellite Data Processing Toolkit</div>
22

33
<div align="center">
44

@@ -8,37 +8,67 @@
88
</div>
99

1010
<div align="center">
11-
<a href="https://github.com/Alex870521"><img src="https://cdn.simpleicons.org/github/0A66C2" width="3%" alt="GitHub"></a>
11+
<a href="https://github.com/Alex870521"><img src="https://cdn.simpleicons.org/github/0A66C2" width="3%" alt="LinkedIn"></a>
1212
<span style="margin: 0 1%"></span>
1313
<a href="https://www.linkedin.com/in/Alex870521/"><img src="https://cdn.simpleicons.org/linkedin/0A66C2" width="3%" alt="LinkedIn"></a>
1414
<span style="margin: 0 1%"></span>
1515
<a href="https://medium.com/@alex870521"><img src="https://cdn.simpleicons.org/medium/0A66C2" width="3%" alt="Medium"></a></div>
1616

1717
---
1818

19-
A Python toolkit for retrieving, processing, and visualizing Sentinel-5P satellite data, with a focus on air pollutants like NO₂, CO, SO₂, O₃, and HCHO.
19+
A comprehensive Python toolkit for retrieving, processing, and visualizing satellite data from multiple sources: Sentinel-5P, MODIS, and ERA5. This toolkit focuses on atmospheric data including air pollutants (NO₂, CO, SO₂, O₃, HCHO), aerosol optical depth, and meteorological parameters.
2020

2121
## <div align="center">Features</div>
2222

23-
- Automated data retrieval from Copernicus Open Access Hub
24-
- Advanced data processing with interpolation and quality control
25-
- High-quality visualization of pollutant concentration maps
26-
- Time series analysis capabilities
27-
- Built-in file retention management to prevent storage overflow
23+
- **Multi-platform Support**:
24+
- **Sentinel-5P**: Trace gases and air pollutants
25+
- **MODIS**: Aerosol optical depth (AOD) measurements
26+
- **ERA5**: Reanalysis of atmospheric, land, and oceanic climate variables
27+
28+
- **Unified Data Access**:
29+
- Automated data retrieval from Copernicus Open Access Hub, NASA Earthdata, and Climate Data Store
30+
- Consistent API across different data sources
31+
32+
- **Advanced Processing**:
33+
- Quality control and filtering
34+
- Spatial interpolation and regridding
35+
- Temporal aggregation
36+
- Station-based data extraction
37+
38+
- **Visualization**:
39+
- High-quality concentration and parameter maps
40+
- Customizable geographic boundaries
41+
- Time series analysis capabilities
42+
43+
- **Resource Management**:
44+
- Efficient download handling with caching
45+
- Built-in file retention management
2846

2947
## <div align="center">Prerequisites</div>
3048

3149
Before using this toolkit, you need to complete the following steps:
3250

33-
1. **Copernicus Account Setup**:
51+
1. **Copernicus Account** (for Sentinel-5P and ERA5):
3452
- Register for a free account at [Copernicus Open Access Hub](https://scihub.copernicus.eu/dhus/#/home)
35-
- Save your username and password for API access
53+
- For ERA5, also register at [Climate Data Store](https://cds.climate.copernicus.eu/)
3654

37-
2. **Environment Configuration**:
55+
2. **NASA Earthdata Account** (for MODIS):
56+
- Register at [NASA Earthdata](https://urs.earthdata.nasa.gov/)
57+
58+
3. **Environment Configuration**:
3859
- Create a `.env` file in the project root directory with your credentials:
3960
```
61+
# Sentinel-5P credentials
4062
COPERNICUS_USERNAME=your_username
4163
COPERNICUS_PASSWORD=your_password
64+
65+
# ERA5 credentials
66+
CDSAPI_URL=https://cds.climate.copernicus.eu/api/v2
67+
CDSAPI_KEY=your_key
68+
69+
# NASA Earthdata credentials
70+
EARTHDATA_USERNAME=your_username
71+
EARTHDATA_PASSWORD=your_password
4272
```
4373
4474
## <div align="center">Installation</div>
@@ -56,81 +86,164 @@ pip install -r requirements.txt
5686

5787
## <div align="center">Usage</div>
5888

59-
### Fetching Satellite Data
89+
### Sentinel-5P Example
90+
6091
```python
61-
from src.api.sentinel_api import S5PFetcher
62-
63-
# Initialize fetcher
64-
fetcher = S5PFetcher(max_workers=3)
65-
66-
# Fetch products
67-
products = await fetcher.fetch_data(
68-
file_class='OFFL', # 'OFFL' for offline data, 'NRTI' for near-real-time
69-
file_type='NO2___', # Available types: 'NO2___', 'CO____', 'SO2___', 'O3__PR', 'HCHO__'
70-
start_date='2025-02-20',
71-
end_date='2025-03-06',
72-
boundary=(120, 122, 22, 25),
73-
limit=None
92+
"""SENTINEL-5P Data Processing Example"""
93+
from datetime import datetime
94+
from src.api import SENTINEL5PHub
95+
96+
# 1. Set parameters
97+
start_date, end_date = datetime(2025, 3, 1), datetime(2025, 3, 13)
98+
99+
# File class: 'NRTI' (Near Real-Time) or 'OFFL' (Offline processed)
100+
file_class = 'NRTI'
101+
102+
# Available file types: 'NO2___', 'O3____', 'CO____', 'SO2___', 'CH4___', 'CLOUD_', 'AER_AI'
103+
file_type = 'NO2___'
104+
105+
# Define region boundary (min_lon, max_lon, min_lat, max_lat)
106+
boundary = (120, 122, 22, 25)
107+
108+
# 2. Create data hub instance
109+
sentinel_hub = SENTINEL5PHub(max_workers=3)
110+
111+
# 3. Fetch data
112+
products = sentinel_hub.fetch_data(
113+
file_class=file_class,
114+
file_type=file_type,
115+
start_date=start_date,
116+
end_date=end_date,
117+
boundary=boundary
74118
)
75119

76-
# Download products
77-
fetcher.parallel_download(products)
78-
```
120+
# 4. Download data
121+
sentinel_hub.download_data(products)
79122

80-
Example output:
81-
```
82-
╭──────────────────────────────────────────────────────────────────────────────────────────────────╮
83-
│ Fetching sentinel-5p products (NO₂) from 2025-02-20 to 2025-03-06 ... │
84-
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
85-
╭──────────────────────────────────────── Found 7 Products ────────────────────────────────────────╮
86-
│ │
87-
│ Product Information │
88-
│┏━━━━━┳━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━┓ │
89-
│┃ No. ┃ Time ┃ Name ┃ Size ┃ │
90-
│┡━━━━━╇━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━┩ │
91-
││ 1 │ 2025-02-25T04:54:18 │ S5P_OFFL_L2__NO2____20250225T043243...50226T204825.nc │ 589.88 MB │ │
92-
││ 2 │ 2025-02-24T05:13:14 │ S5P_OFFL_L2__NO2____20250224T045140...50225T210805.nc │ 591.67 MB │ │
93-
││ 3 │ 2025-02-24T03:31:44 │ S5P_OFFL_L2__NO2____20250224T031009...50226T055814.nc │ 593.46 MB │ │
94-
││ 4 │ 2025-02-23T03:50:40 │ S5P_OFFL_L2__NO2____20250223T032906...50224T235016.nc │ 593.48 MB │ │
95-
││ 5 │ 2025-02-22T04:09:37 │ S5P_OFFL_L2__NO2____20250222T034802...50223T200228.nc │ 590.79 MB │ │
96-
││ 6 │ 2025-02-21T04:28:32 │ S5P_OFFL_L2__NO2____20250221T040659...50222T202822.nc │ 589.21 MB │ │
97-
││ 7 │ 2025-02-20T04:47:30 │ S5P_OFFL_L2__NO2____20250220T042555...50221T204529.nc │ 564.02 MB │ │
98-
│└─────┴─────────────────────┴───────────────────────────────────────────────────────┴───────────┘ │
99-
│ │
100-
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
123+
# 5. Process data
124+
sentinel_hub.process_data()
101125
```
102126

103-
### Processing Data
127+
### MODIS Example
128+
104129
```python
105-
from src.processing.data_processor import S5Processor
130+
"""MODIS Data Processing Example"""
131+
from datetime import datetime
132+
from src.api import MODISHub
133+
134+
# 1. Set parameters
135+
start_date, end_date = datetime(2025, 3, 1), datetime(2025, 3, 12)
106136

107-
# Initialize processor
108-
processor = S5Processor(
109-
interpolation_method='rbf',
110-
resolution=(5.5, 3.5), # Resolution in km
111-
mask_qc_value=0.5 # Quality control threshold
137+
# Product types: 'MOD04' (Terra) or 'MYD04' (Aqua)
138+
modis_product_type = "MYD04"
139+
140+
# 2. Create data hub instance
141+
modis_hub = MODISHub()
142+
143+
# 3. Fetch data
144+
products = modis_hub.fetch_data(
145+
file_type=modis_product_type,
146+
start_date=start_date,
147+
end_date=end_date
112148
)
113149

114-
# Process data
115-
processor.process_each_data(
116-
file_class='OFFL',
117-
file_type='NO2___',
118-
start_date='2025-02-20',
119-
end_date='2025-03-06',
150+
# 4. Download data
151+
modis_hub.download_data(products)
152+
153+
# 5. Process data
154+
modis_hub.process_data()
155+
```
156+
157+
### ERA5 Example
158+
159+
```python
160+
"""ERA5 Data Processing Example"""
161+
from datetime import datetime
162+
from src.api import ERA5Hub
163+
164+
# 1. Set parameters
165+
start_date, end_date = datetime(2025, 3, 1), datetime(2025, 3, 19)
166+
167+
# Variables to retrieve (more options available)
168+
variables = ['boundary_layer_height']
169+
170+
# Pressure levels in hPa (set to None for surface data only)
171+
pressure_levels = None
172+
173+
# Region boundary (min_lon, max_lon, min_lat, max_lat)
174+
boundary = (119, 123, 21, 26)
175+
176+
# Define observation stations
177+
STATIONS = [
178+
{"name": "FS", "lat": 22.6294, "lon": 120.3461}, # Kaohsiung Fengshan
179+
{"name": "NZ", "lat": 22.7422, "lon": 120.3339}, # Kaohsiung Nanzi
180+
{"name": "TH", "lat": 24.1817, "lon": 120.5956}, # Taichung
181+
{"name": "TP", "lat": 25.0330, "lon": 121.5654} # Taipei
182+
]
183+
184+
# 2. Create data hub instance
185+
era5_hub = ERA5Hub(timezone='Asia/Taipei')
186+
187+
# 3. Fetch data
188+
era5_hub.fetch_data(
189+
start_date=start_date,
190+
end_date=end_date,
191+
boundary=boundary,
192+
variables=variables,
193+
pressure_levels=pressure_levels,
194+
stations=STATIONS,
120195
)
196+
197+
# 4. Download data
198+
era5_hub.download_data()
199+
200+
# 5. Process data
201+
era5_hub.process_data()
121202
```
122203

123-
## <div align="center">Data Description</div>
204+
## <div align="center">Data Sources</div>
205+
206+
### Sentinel-5P
207+
- **Provider**: European Space Agency (ESA)
208+
- **Products**: NO₂, O₃, CO, SO₂, HCHO, Cloud, Aerosol Index
209+
- **Resolution**: 7 km x 3.5 km (at nadir)
210+
- **Frequency**: Daily global coverage
211+
212+
### MODIS
213+
- **Provider**: NASA
214+
- **Products**: Aerosol Optical Depth (AOD)
215+
- **Platforms**: Terra (MOD04) and Aqua (MYD04) satellites
216+
- **Resolution**: 10 km at nadir
217+
- **Frequency**: 1-2 days global coverage
218+
219+
### ERA5
220+
- **Provider**: European Centre for Medium-Range Weather Forecasts (ECMWF)
221+
- **Products**: Reanalysis dataset with 100+ atmospheric, land and oceanic parameters
222+
- **Resolution**: 0.25° x 0.25° global grid (about 31 km)
223+
- **Frequency**: Hourly data, monthly updates
224+
225+
## <div align="center">Processing Pipeline</div>
226+
227+
All data sources follow a consistent workflow:
228+
229+
1. **Data Discovery**: Query available products based on date range and region
230+
2. **Download Management**: Efficient parallel downloading with error handling
231+
3. **Quality Control**: Filtering based on data quality flags
232+
4. **Spatial Processing**:
233+
- Sentinel-5P: RBF interpolation of sparse satellite data
234+
- MODIS: Processing of gridded AOD values
235+
- ERA5: Extraction of point values for weather stations
236+
5. **Visualization**: Generation of standardized maps and plots
237+
6. **Export**: Structured data storage in NetCDF and CSV formats
238+
239+
## <div align="center">Automatic Data Management</div>
124240

125-
### NO2 Data Processing
126-
This toolkit processes nitrogen dioxide (NO2) and other pollutant data from satellite observations with these key features:
241+
The toolkit includes built-in data retention management to prevent disk space issues:
127242

128-
- **Quality Control**: Filters out low-quality measurements
129-
- **Spatial Interpolation**: Converts sparse satellite readings to regular grid
130-
- **Temporal Aggregation**: Daily, weekly, and monthly averages
131-
- **Visualization**: Generates high-quality maps and time series plots
132-
- **Data Export**: Creates NetCDF files compatible with other analysis tools
243+
- Automatically cleans files older than the configured retention period
244+
- Maintains directory structure while removing outdated files
245+
- Can be scheduled for periodic execution or triggered manually
133246

134247
## <div align="center">Contact</div>
135248

136-
For bug reports and feature requests please visit [GitHub Issues](https://github.com/Alex870521/Satellite_S5P/issues).
249+
For bug reports and feature requests please visit [GitHub Issues](https://github.com/Alex870521/Satellite_DataKit/issues).

0 commit comments

Comments
 (0)