Hi All, I am working on surface albedo data. Is there any function using which I can download the data as well as extract a time series and plot the graph. 

Thank you


3 Comments

  1. Hi Kevin Marsh 

     Yes I tried the one that you shared but I am getting the following error. Could you please help in resolving it. 
    Also, I wish to know if I want to download the data instead of getting figure as an output, should I put the command 'return data' in The end?


    Traceback (most recent call last): File "/opt/cdstoolbox/cdscompute/cdscompute/cdshandlers/services/handler.py", line 59, in handle_request result
    = cached(context.method, proc, context, context.args, context.kwargs) File "/opt/cdstoolbox/cdscompute/cdscompute/caching.py", line 108, in cached
    result = proc(context, *context.args, **context.kwargs) File "/opt/cdstoolbox/cdscompute/cdscompute/services.py", line 124, in __call__ return p
    (*args, **kwargs) File "/opt/cdstoolbox/cdscompute/cdscompute/services.py", line 60, in __call__ return self.proc(context, *args, **kwargs) File
    "/home/cds/cdsservices/services/retrieve.py", line 200, in execute **retrieve_kwargs File "/opt/cdstoolbox/cdscompute/cdscompute/context.py",
    line 301, in call return c.call(service, *args, **kwargs).value File "/opt/cdstoolbox/cdsworkflows/cdsworkflows/future.py", line 76, in value
    raise self._result cdsworkflows.error.ClientError: None
  2. Hi, The workflow is working for me 

    and to download the data you would add @ct.output.download() at the start and return 'data_daily' along with the figure:


    import cdstoolbox as ct

    # Defining an application layout with 3 input collumns locate above the outputs.
    layout = {
        'input_ncols': 3,
        'output_align': 'bottom'
    }

    # Dictionary of selectable variables
    variables = {
        'Near-Surface Air Temperature': '2m_temperature',
        'Eastward Near-Surface Wind': '10m_u_component_of_wind',
        'Northward Near-Surface Wind': '10m_v_component_of_wind',
        'Sea Level Pressure': 'mean_sea_level_pressure',
        'Sea Surface Temperature': 'sea_surface_temperature',
    }

    # Define the main application function
    @ct.application(
        title='Extract a time series and plot graph',
        layout=layout,
        description='Plot the the time series of a user selected variable at a user selected location.'
    )
    @ct.input.dropdown('var', label='Variable', values=variables.keys(), description='Sample variables')
    @ct.input.text('lon', label='Longitude', type=float, default=75., description='Decimal degrees')
    @ct.input.text('lat', label='Latitude', type=float, default=43., description='Decimal degrees')
    @ct.output.livefigure()

    @ct.output.download()


    def plot_time_series(var, lon, lat):
        """
        Application main steps:

        - set the application layout with 3 columns for the input and output at the bottom
        - retrieve a variable over a defined time range
        - select a location, defined by longitude and latitude coordinates
        - compute the daily average
        - show the result as a timeseries on an interactive chart

        """

        # Retrieve the selected variable for a predefined time range at a spatial resolution of 3' x 3'.
        data = ct.catalogue.retrieve(
            'reanalysis-era5-single-levels',
            {
                'variable': variables[var],
                'grid': ['3', '3'],
                'product_type': 'reanalysis',
                'year': [
                    '2008', '2009', '2010',
                    '2011', '2012', '2013',
                    '2014', '2015', '2016',
                    '2017'
                ],
                'month': [
                    '01', '02', '03', '04', '05', '06',
                    '07', '08', '09', '10', '11', '12'
                ],
                'day': [
                    '01', '02', '03', '04', '05', '06',
                    '07', '08', '09', '10', '11', '12',
                    '13', '14', '15', '16', '17', '18',
                    '19', '20', '21', '22', '23', '24',
                    '25', '26', '27', '28', '29', '30',
                    '31'
                ],
                'time': ['00:00', '06:00', '12:00', '18:00'],
            }
        )

        # Location selection

        # Extract the closest point to selected lon/lat (no interpolation).
        # If wrong number is set for latitude, the closest available one is chosen:
        # e.g. if lat = 4000 -> lat = 90.
        # If wrong number is set for longitude, first a wrap in [-180, 180] is made,
        # then the closest one present is chosen:
        # e.g. if lon = 200 -> lat = -160.
        data_sel = ct.geo.extract_point(data, lon=lon, lat=lat)

        # Daily mean on selection
        data_daily = ct.climate.daily_mean(data_sel)

        # Plot the daily data
        fig = ct.chart.line(data_daily)

        return fig, data_daily