Download necessary CAMS data#
First, you have to register and install the CAMS api from: CDS api site
import os, sys
import numpy as np
import pandas
from scipy.interpolate import interp1d
import xarray as xr
import calendar
import matplotlib.pyplot as plt
import logging
import calendar, datetime
import cdsapi
opj = os.path.join
odir = '/data/cams/france'
latmax,lonmin,latmin,lonmax = 52.,-6.,41,10
odir = '/data/cams/world'
latmax,lonmin,latmin,lonmax = 90,-180,-90,180
year=2023
for month in range(10,13):
date_start='{:4d}-{:02d}-{:02d}'.format(year,month,1)
date_end='{:4d}-{:02d}-{:02d}'.format(year,month,calendar.monthrange(year, month)[1])
name = '{:4d}-{:02d}'.format(year,month)
filepath = opj(odir,'cams_forecast_'+name+'.nc')
if os.path.exists(filepath):
continue
print(filepath)
type='forecast'
variable = [
'10m_u_component_of_wind', '10m_v_component_of_wind',
'2m_temperature',
'mean_sea_level_pressure', 'surface_pressure',
'ammonium_aerosol_optical_depth_550nm', 'black_carbon_aerosol_optical_depth_550nm',
'dust_aerosol_optical_depth_550nm',
'nitrate_aerosol_optical_depth_550nm', 'organic_matter_aerosol_optical_depth_550nm',
'sea_salt_aerosol_optical_depth_550nm',
'secondary_organic_aerosol_optical_depth_550nm', 'sulphate_aerosol_optical_depth_550nm',
'total_aerosol_optical_depth_1240nm',
'total_aerosol_optical_depth_469nm',
'total_aerosol_optical_depth_550nm',
'total_aerosol_optical_depth_670nm',
'total_aerosol_optical_depth_865nm',
'total_column_carbon_monoxide',
'total_column_methane',
'total_column_nitrogen_dioxide',
'total_column_ozone', 'total_column_water_vapour']
area = [latmax,lonmin,latmin,lonmax]
c = cdsapi.Client()
c.retrieve(
'cams-global-atmospheric-composition-forecasts',
{
'date': date_start + '/' + date_end,
'type': type,
'format': 'netcdf'
,
'variable': variable,
'time': ['00:00', '12:00'],
'leadtime_hour': ['0', '3', '6', '9'],
'area': area,
},
filepath)