-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget_cds.py
More file actions
79 lines (71 loc) · 2.76 KB
/
get_cds.py
File metadata and controls
79 lines (71 loc) · 2.76 KB
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
"""Download AOD550 data from CAMS and save it to a netCDF file
format: 18 is day 1 and 42 is day 2 sunset hours
output: input/cams_AOD550_{today_str}{run}0000.grib'
Data availability (HH:MM)
CAMS Global analyses and forecasts:
00 UTC forecast data availability guaranteed by 10:00 UTC
12 UTC forecast data availability guaranteed by 22:00 UTC
"""
import cdsapi
import datetime
import os
import logging
logging.basicConfig(
level=logging.INFO,
datefmt= '%Y-%m-%d %H:%M:%S',
)
run = "00"
run = run.zfill(2)
today = datetime.date.today() #- datetime.timedelta(days=1)
today_str = today.strftime("%Y%m%d")
def get_cams_aod(today, run, city, today_str, input_path):
if os.path.exists(f'{input_path}/cams_AOD550_{today_str}{run}0000_{city}.grib'):
logging.info("CAMS grib already exists. Skipping download.")
return
else:
if city == "Reading":
client = cdsapi.Client()
today_str = today.strftime("%Y%m%d")
dataset = "cams-global-atmospheric-composition-forecasts"
request = {
"date": [f"{today}/{today}"],
"time": [f"{run}:00"],
"leadtime_hour": [
"18",
"42"
],
"type": ["forecast"],
"data_format": "grib",
"variable": [
"black_carbon_aerosol_optical_depth_550nm",
"dust_aerosol_optical_depth_550nm",
"organic_matter_aerosol_optical_depth_550nm",
"total_aerosol_optical_depth_550nm"
],
"area": [53, -2, 49, 0]
}
elif city =='HongKong':
client = cdsapi.Client()
today_str = today.strftime("%Y%m%d")
dataset = "cams-global-atmospheric-composition-forecasts"
request = {
"date": [f"{today}/{today}"],
"time": [f"{run}:00"],
"leadtime_hour": [
"24",
"48"
],
"type": ["forecast"],
"data_format": "grib",
"variable": [
"black_carbon_aerosol_optical_depth_550nm",
"dust_aerosol_optical_depth_550nm",
"organic_matter_aerosol_optical_depth_550nm",
"total_aerosol_optical_depth_550nm"
],
"area": [23, 113, 21, 115]
}
else:
logging.error("City not supported. Please use 'Reading' or 'HongKong'.")
raise ValueError("City not supported. Please use 'Reading' or 'HongKong'.")
client.retrieve(dataset, request,f'{input_path}/cams_AOD550_{today_str}{run}0000_{city}.grib')