Exemplo n.º 1
0
def taylor_diagram(*args, **kwargs):
    '''
    Plot a Taylor diagram from statistics of different series.
    
    taylor_diagram(STDs,RMSs,CORs,keyword=value)
    
    The first 3 arguments must be the inputs as described below followed by
    keywords in the format OPTION = value. An example call to the function 
    would be:
    
    taylor_diagram(STDs,RMSs,CORs,markerdisplayed='marker')
    
    INPUTS:
    STDs: Standard deviations
    RMSs: Centered Root Mean Square Difference 
    CORs: Correlation
    
    Each of these inputs are one-dimensional with the same length. First
    index corresponds to the reference series for the diagram. For 
    example STDs[1] is the standard deviation of the reference series 
    and STDs[2:N] are the standard deviations of the other series. Note 
    that only the latter are plotted.
 
    Note that by definition the following relation must be true for all 
    series i:

     RMSs(i) = sqrt(STDs(i).^2 + STDs(1)^2 - 2*STDs(i)*STDs(1).*CORs(i))

    This relation is checked if the checkStats option is used, and if not 
    verified an error message is sent. This relation is not checked by
    default. Please see Taylor's JGR article for more informations about 
    this relation.
    
    OUTPUTS:
    None.
    
    LIST OF OPTIONS:
    For an exhaustive list of options to customize your diagram, call the 
    function without arguments at a Python command line:
    % python
    >>> import skill_metrics as sm
    >>> sm.taylor_diagram()
    
    Reference:
 
    Taylor, K. E. (2001), Summarizing multiple aspects of model 
      performance in a single diagram, J. Geophys. Res., 106(D7),
      7183-7192, doi:10.1029/2000JD900719.
    
    Author: Peter A. Rochford
            Symplectic, LLC
            www.thesymplectic.com
            [email protected]

    Created on Dec 3, 2016
    '''

    # Check for number of arguments
    nargin = len(args)
    STDs, RMSs, CORs = _get_taylor_diagram_arguments(*args, **kwargs)
    if nargin == 0: return

    # Get options
    option = get_taylor_diagram_options(CORs, **kwargs)

    # Check the input statistics if requested.
    if option['checkstats'] == 'on':
        check_taylor_stats(STDs[1:], RMSs[1:], CORs[1:], 0.01)

    # Express statistics in polar coordinates.
    rho = STDs
    theta = np.arccos(CORs)

    #  Get axis values for plot
    axes, cax = get_taylor_diagram_axes(rho, option)

    # Plot axes for target diagram
    if option['overlay'] == 'off':
        # Draw circles about origin
        overlay_taylor_diagram_circles(axes, cax, option)

        # Draw lines emanating from origin
        overlay_taylor_diagram_lines(axes, cax, option)

        # Plot axes for Taylor diagram
        ax = plot_taylor_axes(axes, cax, option)

        # Plot marker on axis indicating observation STD
        plot_taylor_obs(ax, STDs[0], axes, option)

    # Plot data points. Note that only rho[1:N] and theta[1:N] are
    # plotted.
    X = np.multiply(rho[1:], np.cos(theta[1:]))
    Y = np.multiply(rho[1:], np.sin(theta[1:]))

    lowcase = option['markerdisplayed'].lower()
    if lowcase == 'marker':
        plot_pattern_diagram_markers(X, Y, option)
    elif lowcase == 'colorbar':
        plot_pattern_diagram_colorbar(X, Y, RMSs[1:], option)
    else:
        raise ValueError('Unrecognized option: ' + option['markerdisplayed'])
Exemplo n.º 2
0
    # Calculate statistics for target diagram
    target_stats1 = sm.target_statistics(data.pred1, data.ref, 'data')

    # Write statistics to Excel file for a single data set
    filename = 'target_stats.xlsx'
    sm.write_target_stats(filename, target_stats1, overwrite='on')

    # Calculate statistics for Taylor diagram
    # The first array element corresponds to the reference series
    # for the while the second is that for the predicted series.
    taylor_stats1 = sm.taylor_statistics(data.pred1, data.ref, 'data')
    taylor_stats2 = sm.taylor_statistics(data.pred2, data.ref, 'data')
    taylor_stats3 = sm.taylor_statistics(data.pred3, data.ref, 'data')

    # Write statistics to Excel file
    filename = 'taylor_stats.xlsx'
    data = [taylor_stats1, taylor_stats2, taylor_stats3]
    title = ['Expt. 1', 'Expt. 2', 'Expt. 3']
    label = ['Observed', 'M1', 'M2', 'M3']
    sm.write_taylor_stats(filename,
                          data,
                          title=title,
                          label=label,
                          overwrite=True)

    # Check statistics for Taylor diagram
    diff = sm.check_taylor_stats(taylor_stats1['sdev'], taylor_stats1['crmsd'],
                                 taylor_stats1['ccoef'])
    print('Difference in Taylor statistics = ' + str(diff))