Skip to article frontmatterSkip to article content

Aviso notification for DT data availability

This notebook shows how to check the data availablility for the Weather-Induced Extremes Digital Twin (Extremes DT) using the ECMWF Aviso package.

🚀 Launch in JupyterHub

Credit: The pyaviso package is provided by the European Centre for Medium-Range Weather Forecasts (ECMWF).

Install the pyaviso package

!pip  install  pyaviso --quiet

Import pyaviso

Import pyaviso and other useful libraries. Defining constants and functions.

from datetime import datetime
from pprint import pprint as pp

from pyaviso import NotificationManager, user_config
LISTENER_EVENT = "data"  # Event for the listener, options are mars and dissemination
TRIGGER_TYPE = "function"  # Type of trigger for the listener

Defining the data to be notified

The following request describes the data whose availability we want to be notified

REQUEST = {
    "class": "d1",
#    "dataset": "extremes-dt",
    "expver": "0001",
    "stream": "wave",
    "type": "fc",
    "time": "00",
    "step": "0",
    "levtype": "sfc",
#    "levelist": "",
#    "param": "168"   
}  # Request configuration for the listener

Aviso configuration

CONFIG = {
    "notification_engine": {
        "host": "aviso.lumi.apps.dte.destination-earth.eu",
        "port": 443,
        "https": True,
    },
    "configuration_engine": {
        "host": "aviso.lumi.apps.dte.destination-earth.eu",
        "port": 443,
        "https": True,
    },
    "schema_parser": "generic",
    "remote_schema": True,
    "auth_type": "none",
    "quiet" : True
}  # manually defined configuration

Searching for old notifications

Ssearching for old notifications where available. This way users can explicitly replay past notifications and executes triggers.

import sys
START_DATE = datetime(2020, 12, 12)  # Start date for the notification listener
def triggered_function(notification):
    """
    Function for the listener to trigger.
    """
    
    #pp(notification)
    # Access the date field
    date_str = notification['request']['date']    

    # Convert the date string to a datetime object
    date_obj = datetime.strptime(date_str, '%Y%m%d')
    formatted_date = date_obj.strftime('%Y-%m-%d')
    pp("ExtremeDT data available=>" + formatted_date)
    
    
def create_hist_listener():
    """
    Creates and returns a listener configuration.
    """

    trigger = {
        "type": TRIGGER_TYPE,
        "function": triggered_function,
    }  # Define the trigger for the listener
    
    # Return the complete listener configuration
    return {"event": LISTENER_EVENT, "request": REQUEST, "triggers": [trigger]}
try:
    listener = create_hist_listener()  # Create listener configuration
    listeners_config = {"listeners": [listener]}  # Define listeners configuration
    config = user_config.UserConfig(**CONFIG)
    print("loaded config:")
    pp(CONFIG)
    nmh = NotificationManager()  # Initialize the NotificationManager

    nmh.listen(
        listeners=listeners_config, from_date=START_DATE, config=config
    )  # Start listening
except Exception as e:
    print(f"Failed to initialize the Notification Manager: {e}")
loaded config:
{'auth_type': 'none',
 'configuration_engine': {'host': 'aviso.lumi.apps.dte.destination-earth.eu',
                          'https': True,
                          'port': 443},
 'notification_engine': {'host': 'aviso.lumi.apps.dte.destination-earth.eu',
                         'https': True,
                         'port': 443},
 'quiet': True,
 'remote_schema': True,
 'schema_parser': 'generic'}
'ExtremeDT data available=>2025-03-18'
'ExtremeDT data available=>2025-03-17'
'ExtremeDT data available=>2025-03-16'
'ExtremeDT data available=>2025-03-15'
'ExtremeDT data available=>2025-03-14'
'ExtremeDT data available=>2025-03-13'
'ExtremeDT data available=>2025-03-12'
'ExtremeDT data available=>2025-03-11'
'ExtremeDT data available=>2025-03-10'
'ExtremeDT data available=>2025-03-09'
'ExtremeDT data available=>2025-03-08'
'ExtremeDT data available=>2025-03-07'
'ExtremeDT data available=>2025-03-06'
'ExtremeDT data available=>2025-03-05'
'ExtremeDT data available=>2025-03-04'
'ExtremeDT data available=>2025-03-03'
'ExtremeDT data available=>2025-03-02'
'ExtremeDT data available=>2025-03-01'
'ExtremeDT data available=>2025-02-28'
'ExtremeDT data available=>2025-02-27'
'ExtremeDT data available=>2025-02-26'
'ExtremeDT data available=>2025-02-25'
'ExtremeDT data available=>2025-02-24'
'ExtremeDT data available=>2025-02-23'
'ExtremeDT data available=>2025-02-22'
'ExtremeDT data available=>2025-02-21'
'ExtremeDT data available=>2025-02-20'