-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
102 lines (80 loc) · 3.37 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
"""主程式"""
import logging
from src.api.sentinel_api import S5PFetcher
from src.processing.data_processor import S5Processor
from src.utils.logger import setup_logging
from src.utils.richer import rich_print
from src.utils.catalog import ProductClassInput, ProductTypeInput, ProductType
from src.config.settings import setup_directory_structure, FILTER_BOUNDARY
from src.visualization.gif_nc import animate_data
logger = logging.getLogger(__name__)
def fetch_data(file_class: ProductClassInput,
file_type: ProductTypeInput,
start_date: str,
end_date: str):
"""下載數據的工作流程"""
try:
fetcher = S5PFetcher(max_workers=3)
rich_print(f"正在獲取 sentinel-5p 衛星數據 ({ProductType[file_type].display_name}) from {start_date} to {end_date} ...")
products = fetcher.fetch_data(
file_class=file_class,
file_type=file_type,
start_date=start_date,
end_date=end_date,
boundary=FILTER_BOUNDARY,
limit=None
)
if products:
if rich_print("是否要下載數據?", confirm=True):
rich_print(f"開始下載 sentinel-5p 衛星數據 ({ProductType[file_type].display_name}) from {start_date} to {end_date} ...")
fetcher.parallel_download(products)
rich_print("數據下載完成!")
else:
rich_print("已取消下載操作")
else:
rich_print("找不到符合條件的數據")
except Exception as e:
error_message = f"下載數據失敗: {str(e)}"
rich_print(error_message)
logger.error(error_message)
def process_data(file_class: ProductClassInput,
file_type: ProductTypeInput,
start_date: str,
end_date: str):
"""處理數據的工作流程"""
try:
if rich_print("是否要處理數據?", confirm=True):
rich_print(f"建立 sentinel-5p 衛星數據 ({ProductType[file_type].display_name}) 處理器 ...")
processor = S5Processor(
interpolation_method='kdtree',
resolution=0.02,
mask_value=0.5
)
rich_print(f"正在處理 sentinel-5p 衛星數據 ({ProductType[file_type].display_name}) from {start_date} to {end_date} ...")
processor.process_each_data(
file_class=file_class,
file_type=file_type,
start_date=start_date,
end_date=end_date,
use_taiwan_mask=True)
rich_print("數據完成處理")
else:
rich_print("已取消處理操作")
except Exception as e:
error_message = f"處理數據失敗: {str(e)}"
rich_print(error_message)
logger.error(error_message)
def main():
# 設定參數
start, end = '2023-01-01', '2023-12-31'
# 設定輸入輸出配置
setup_logging()
setup_directory_structure(file_type='NO2___', start_date=start, end_date=end)
# 下載數據
fetch_data(file_class='OFFL', file_type='NO2___', start_date=start, end_date=end)
# 處理數據
# process_data(file_class='OFFL', file_type='SO2___', start_date=start, end_date=end)
# 動畫
# animate_data(file_type='SO2___', start_date=start, end_date=end)
if __name__ == "__main__":
main()