Skip to content

Commit

Permalink
Merge branch 'CIF-286-CAMS' of https://github.com/wri/cities-cif into…
Browse files Browse the repository at this point in the history
… CIF-286-CAMS
  • Loading branch information
weiqi-tori committed Oct 24, 2024
2 parents 964554e + bd177d6 commit a3af050
Showing 1 changed file with 18 additions and 11 deletions.
29 changes: 18 additions & 11 deletions city_metrix/layers/cams.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,36 @@


class Cams(Layer):
def __init__(self, start_date="2023-01-01", end_date="2023-12-01", **kwargs):
def __init__(self, start_date="2023-01-01", end_date="2023-12-01", species, **kwargs):
super().__init__(**kwargs)
self.start_date = start_date
self.end_date = end_date
if species in ("particulate_matter_2.5um", "particulate_matter_10um", "carbon_monoxide", "nitrogen_dioxide", "ozone", "sulphur_dioxide"):
self.species = species
else:
raise Exception("Selected species not supported")

def get_data(self, bbox):
min_lon, min_lat, max_lon, max_lat = bbox

c = cdsapi.Client()
c.retrieve(
'cams-global-reanalysis-eac4',
{
'variable': [
"2m_temperature", "mean_sea_level_pressure",
"particulate_matter_2.5um", "particulate_matter_10um",
"carbon_monoxide", "nitrogen_dioxide", "ozone", "sulphur_dioxide"

],
query_dict = {
"model_level": ["60"],
"date": [f"{self.start_date}/{self.end_date}"],
'time': ['00:00', '03:00', '06:00', '09:00', '12:00', '15:00', '18:00', '21:00'],
'area': [max_lat, min_lon, min_lat, max_lon],
'data_format': 'netcdf_zip',
},
}
if self.species in ("particulate_matter_2.5um", "particulate_matter_10um"):
query_dict['variable'] = [self.species]
else:
query_dict['variable'] = [
"2m_temperature", "mean_sea_level_pressure", self.species
]

c.retrieve(
'cams-global-reanalysis-eac4',
query_dict,
'cams_download.zip')

# extract the ZIP file
Expand All @@ -52,6 +58,7 @@ def get_data(self, bbox):
else dataarray
for dataarray in dataarray_list
]

# drop coordinate ['latitude','longitude'] if uses 360 degree system
dataarray_list = [
dataarray.drop_vars(['latitude', 'longitude'])
Expand Down

0 comments on commit a3af050

Please sign in to comment.