esmvaltool/diag_scripts/ocean/diagnostic_timeseries.py
def multi_model_time_series(
        cfg,
        metadata,
):
    """
    Make a time series plot showing several models.

    This function makes a simple plot for an indivudual model.
    The cfg is the opened global config,
    metadata is the metadata dictionairy.
    """
    ####
    # Load the data for each layer as a separate cube
    model_cubes = {}
    layers = {}
    for filename in sorted(metadata):
        cube = iris.load_cube(filename)
        cube = diagtools.bgc_units(cube, metadata[filename]['short_name'])

        cubes = diagtools.make_cube_layer_dict(cube)
        model_cubes[filename] = cubes
        for layer in cubes:
            layers[layer] = True

    # Load image format extention
    image_extention = diagtools.get_image_format(cfg)

    # Make a plot for each layer
    for layer in layers:

        title = ''
        z_units = ''
        plot_details = {}
        cmap = plt.cm.get_cmap('viridis')

        # Plot each file in the group
        for index, filename in enumerate(sorted(metadata)):
            if len(metadata) > 1:
                color = cmap(index / (len(metadata) - 1.))
            else:
                color = 'blue'

            # Take a moving average, if needed.
            if 'moving_average' in cfg:
                cube = moving_average(model_cubes[filename][layer],
                                      cfg['moving_average'])
            else:
                cube = model_cubes[filename][layer]

            if 'MultiModel' in metadata[filename]['dataset']:
                timeplot(
                    cube,
                    c=color,
                    # label=metadata[filename]['dataset'],
                    ls=':',
                    lw=2.,
                )
                plot_details[filename] = {
                    'c': color,
                    'ls': ':',
                    'lw': 2.,
                    'label': metadata[filename]['dataset']
                }
            else:
                timeplot(
                    cube,
                    c=color,
                    # label=metadata[filename]['dataset'])
                    ls='-',
                    lw=2.,
                )
                plot_details[filename] = {
                    'c': color,
                    'ls': '-',
                    'lw': 2.,
                    'label': metadata[filename]['dataset']
                }

            title = metadata[filename]['long_name']
            if layer != '':
                if model_cubes[filename][layer].coords('depth'):
                    z_units = model_cubes[filename][layer].coord('depth').units
                else:
                    z_units = ''
        # Add title, legend to plots
        if layer:
            title = ' '.join([title, '(', str(layer), str(z_units), ')'])
        plt.title(title)
        plt.legend(loc='best')
        plt.ylabel(str(model_cubes[filename][layer].units))

        # Saving files:
        if cfg['write_plots']:
            path = diagtools.get_image_path(
                cfg,
                metadata[filename],
                prefix='MultipleModels_',
                suffix='_'.join(['timeseries', str(layer) + image_extention]),
                metadata_id_list=[
                    'field', 'short_name', 'preprocessor', 'diagnostic',
                    'start_year', 'end_year'
                ],
            )

        # Resize and add legend outside thew axes.
        plt.gcf().set_size_inches(9., 6.)
        diagtools.add_legend_outside_right(
            plot_details, plt.gca(), column_width=0.15)

        logger.info('Saving plots to %s', path)
        plt.savefig(path)
        plt.close()

    Make a time series plot showing several models.

    This function makes a simple plot for an indivudual model.
    The cfg is the opened global config,
    metadata is the metadata dictionairy.
    
Make a time series plot showing several models.
This function makes a simple plot for an indivudual model.
The cfg is the opened global config,
metadata is the metadata dictionairy.
Make a time series plot showing several models . This function makes a simple plot for an indivudual model . The cfg is the opened global config metadata is the metadata dictionairy .
def multi_model_time_series(
        cfg,
        metadata,
):
    model_cubes = {}
    layers = {}
    for filename in sorted(metadata):
        cube = iris.load_cube(filename)
        cube = diagtools.bgc_units(cube, metadata[filename]['short_name'])
        cubes = diagtools.make_cube_layer_dict(cube)
        model_cubes[filename] = cubes
        for layer in cubes:
            layers[layer] = True
    image_extention = diagtools.get_image_format(cfg)
    for layer in layers:
        title = ''
        z_units = ''
        plot_details = {}
        cmap = plt.cm.get_cmap('viridis')
        for index, filename in enumerate(sorted(metadata)):
            if len(metadata) > 1:
                color = cmap(index / (len(metadata) - 1.))
            else:
                color = 'blue'
            if 'moving_average' in cfg:
                cube = moving_average(model_cubes[filename][layer],
                                      cfg['moving_average'])
            else:
                cube = model_cubes[filename][layer]
            if 'MultiModel' in metadata[filename]['dataset']:
                timeplot(
                    cube,
                    c=color,
                    ls=':',
                    lw=2.,
                )
                plot_details[filename] = {
                    'c': color,
                    'ls': ':',
                    'lw': 2.,
                    'label': metadata[filename]['dataset']
                }
            else:
                timeplot(
                    cube,
                    c=color,
                    ls='-',
                    lw=2.,
                )
                plot_details[filename] = {
                    'c': color,
                    'ls': '-',
                    'lw': 2.,
                    'label': metadata[filename]['dataset']
                }
            title = metadata[filename]['long_name']
            if layer != '':
                if model_cubes[filename][layer].coords('depth'):
                    z_units = model_cubes[filename][layer].coord('depth').units
                else:
                    z_units = ''
        if layer:
            title = ' '.join([title, '(', str(layer), str(z_units), ')'])
        plt.title(title)
        plt.legend(loc='best')
        plt.ylabel(str(model_cubes[filename][layer].units))
        if cfg['write_plots']:
            path = diagtools.get_image_path(
                cfg,
                metadata[filename],
                prefix='MultipleModels_',
                suffix='_'.join(['timeseries', str(layer) + image_extention]),
                metadata_id_list=[
                    'field', 'short_name', 'preprocessor', 'diagnostic',
                    'start_year', 'end_year'
                ],
            )
        plt.gcf().set_size_inches(9., 6.)
        diagtools.add_legend_outside_right(
            plot_details, plt.gca(), column_width=0.15)
        logger.info('Saving plots to %s', path)
        plt.savefig(path)
        plt.close()
def multi_model_time_series ( cfg , metadata , ) : model_cubes = { } layers = { } for filename in sorted ( metadata ) : cube = iris . load_cube ( filename ) cube = diagtools . bgc_units ( cube , metadata [ filename ] [ 'short_name' ] ) cubes = diagtools . make_cube_layer_dict ( cube ) model_cubes [ filename ] = cubes for layer in cubes : layers [ layer ] = True image_extention = diagtools . get_image_format ( cfg ) for layer in layers : title = '' z_units = '' plot_details = { } cmap = plt . cm . get_cmap ( 'viridis' ) for index , filename in enumerate ( sorted ( metadata ) ) : if len ( metadata ) > 1 : color = cmap ( index / ( len ( metadata ) - 1. ) ) else : color = 'blue' if 'moving_average' in cfg : cube = moving_average ( model_cubes [ filename ] [ layer ] , cfg [ 'moving_average' ] ) else : cube = model_cubes [ filename ] [ layer ] if 'MultiModel' in metadata [ filename ] [ 'dataset' ] : timeplot ( cube , c = color , ls = ':' , lw = 2. , ) plot_details [ filename ] = { 'c' : color , 'ls' : ':' , 'lw' : 2. , 'label' : metadata [ filename ] [ 'dataset' ] } else : timeplot ( cube , c = color , ls = '-' , lw = 2. , ) plot_details [ filename ] = { 'c' : color , 'ls' : '-' , 'lw' : 2. , 'label' : metadata [ filename ] [ 'dataset' ] } title = metadata [ filename ] [ 'long_name' ] if layer != '' : if model_cubes [ filename ] [ layer ] . coords ( 'depth' ) : z_units = model_cubes [ filename ] [ layer ] . coord ( 'depth' ) . units else : z_units = '' if layer : title = ' ' . join ( [ title , '(' , str ( layer ) , str ( z_units ) , ')' ] ) plt . title ( title ) plt . legend ( loc = 'best' ) plt . ylabel ( str ( model_cubes [ filename ] [ layer ] . units ) ) if cfg [ 'write_plots' ] : path = diagtools . get_image_path ( cfg , metadata [ filename ] , prefix = 'MultipleModels_' , suffix = '_' . join ( [ 'timeseries' , str ( layer ) + image_extention ] ) , metadata_id_list = [ 'field' , 'short_name' , 'preprocessor' , 'diagnostic' , 'start_year' , 'end_year' ] , ) plt . gcf ( ) . set_size_inches ( 9. , 6. ) diagtools . add_legend_outside_right ( plot_details , plt . gca ( ) , column_width = 0.15 ) logger . info ( 'Saving plots to %s' , path ) plt . savefig ( path ) plt . close ( )
Make a time series plot showing several models.
Make a time series plot showing several models .
"""
    Make a time series plot showing several models.

    This function makes a simple plot for an indivudual model.
    The cfg is the opened global config,
    metadata is the metadata dictionairy.
    """ #### # Load the data for each layer as a separate cube # Load image format extention # Make a plot for each layer # Plot each file in the group # Take a moving average, if needed. # label=metadata[filename]['dataset'], # label=metadata[filename]['dataset']) # Add title, legend to plots # Saving files: # Resize and add legend outside thew axes.
cfg
metadata