diff --git a/city_metrix/layers/cams.py b/city_metrix/layers/cams.py index f3e3a4c..b1fbf08 100644 --- a/city_metrix/layers/cams.py +++ b/city_metrix/layers/cams.py @@ -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 @@ -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'])