--- title: ECMWF WMS Maps layout: post excerpt: A fun little web map data source. thumbnail: /assets/blog/ecmwf_wms/thumbnail.jpg social_image: /assets/blog/ecmwf_wms/thumbnail.jpg image_class: invertable alt: A map centered on London with a colourful overlay showing weather data. head: | --- I currently work at [ECMF](https://www.ecmwf.int/) and lately I found out that we make [a WMS service available for some of our data](https://confluence.ecmwf.int/pages/viewpage.action?pageId=473850311). So here's a little web map using this data.
This is just a quick demo to see how it works but to make something more featured you'd need to handle things like passing the correct times and other variables to each layer and how to surface that in the UI. Here's a bit of code to iterate through the layers returned by the WMS `GetCapabilities` endpoint so you can see what's available. Here I'm using `token=public` but you can substitute that for an ECMWF API key to possiblity get more layers. You can also in principle open this in things like QGIS but I struggled to get it to work well with the time dimension. ```python import xmltodict r = requests.get("https://eccharts.ecmwf.int/wms/?token=public&request=GetCapabilities&version=1.3.0") t = xmltodict.parse(r.text) layers = t['WMS_Capabilities']['Capability']['Layer']["Layer"] print("Layer keys: ", layers[0].keys()) def handle_dimension(ds): if not isinstance(ds, list): ds = [ds] return [d["@name"] for d in ds] for layer in layers: info = dict( name=layer["Name"], title = layer["Title"], dimensions = handle_dimension(layer["Dimension"]) if "Dimension" in layer else None, ) print(f"{info},") ``` which prints something like: ```json {'name': 'z500_field', 'title': '500 hPa geopotential', 'dimensions': ['time']}, {'name': 'ws850_public', 'title': '850 hPa wind speed (Public)', 'dimensions': ['time']}, {'name': 'composition_aod550', 'title': 'Aerosol optical depth at 550 nm (provided by CAMS, the Copernicus Atmosphere Monitoring Service)', 'dimensions': ['time']}, {'name': 'composition_europe_pol_alder_forecast_surface', 'title': 'Alder pollen (provided by CAMS)', 'dimensions': ['time', 'originating_centre', 'stream', 'type', 'level']}, {'name': 'composition_europe_nh3_forecast_surface', 'title': 'Ammonia (provided by CAMS)', 'dimensions': ['time', 'originating_centre', 'stream', 'type', 'level']}, ... ``` Some of the the layers are only produced at certain times and I haven't written any code to handle that properly it you see empty layers that's likely the cause. You can see there are also other dimensions like `['time', 'originating_centre', 'stream', 'type', 'level']` that you can add.