예제 #1
0
def taylor_statistics(p, r):       
    # Calculate bias (B)
    bias = np.mean(p) - np.mean(r)
    # Calculate correlation coefficient
    ccoef = np.corrcoef(p,r)
    ccoef = ccoef[0]
    # Calculate centered root-mean-square (RMS) difference (E')^2
    crmsd = [0.0, sm.centered_rms_dev(p,r)]
    # Calculate standard deviation of predicted field w.r.t N (sigma_p)
    sdevp = np.std(p)    
    # Calculate standard deviation of reference field w.r.t N (sigma_r)
    sdevr = np.std(r)
    sdev = [sdevr, sdevp];
    # Store statistics in a dictionary
    stats = {'ccoef': ccoef, 'crmsd': crmsd, 'sdev': sdev, 'bias': bias}
    return stats
예제 #2
0
    # Read data from pickle file
    data = load_obj('target_data')
    pred = data.pred1['data']
    ref = data.ref['data']

    # Get bias
    stats['bias'] = sm.bias(pred, ref)
    print('Bias = ' + str(stats['bias']))

    # Get Root-Mean-Square-Deviation (RMSD)
    stats['rmsd'] = sm.rmsd(pred, ref)
    print('RMSD = ' + str(stats['rmsd']))

    # Get Centered Root-Mean-Square-Deviation (CRMSD)
    stats['crmsd'] = sm.centered_rms_dev(pred, ref)
    print('CRMSD = ' + str(stats['crmsd']))

    # Get Standard Deviation (SDEV)
    stats['sdev'] = np.std(pred)
    print('SDEV = ' + str(stats['sdev']))

    # Get correlation coefficient (r)
    ccoef = np.corrcoef(pred, ref)
    stats['ccoef'] = ccoef[0, 1]
    print('r = ' + str(stats['ccoef']))

    # Get Non-Dimensional Skill Score (SS)
    stats['ss'] = sm.skill_score_murphy(pred, ref)
    print('SS (Murphy) = ' + str(stats['ss']))
예제 #3
0
def target_statistics(predicted, reference, field='', norm=False):
    '''
    Calculates the statistics needed to create a target diagram as 
    described in Jolliff et al. (2009) using the data provided in the 
    predicted field (PREDICTED) and the reference field (REFERENCE).
    
    The statistics are returned in the STATS dictionary.

    If a dictionary is provided for PREDICTED or REFERENCE, then 
    the name of the field must be supplied in FIELD.
 
    The function currently supports dictionaries, lists, and np.ndarray,
    types for the PREDICTED and REFERENCE variables.
 
    Input:
    PREDICTED : predicted field
    REFERENCE : reference field
    FIELD     : name of field to use in PREDICTED and REFERENCE dictionaries
                (optional)
    NORM      : logical flag specifying statistics are to be normalized 
                with respect to standard deviation of reference field
                = True,  statistics are normalized
                = False, statistics are not normalized
 
    Output:
    STATS          : dictionary containing statistics
    STATS['bias']  : bias (B)
    STATS['crmsd'] : centered root-mean-square (RMS) differences (E')
    STATS['rmsd']  : total RMS difference (RMSD)
 
    Each of these outputs are one-dimensional with the same length.
 
    Reference:
 
    Jolliff, J. K., J. C. Kindle, I. Shulman, B. Penta, M. Friedrichs, 
      R. Helber, and R. Arnone (2009), Skill assessment for coupled 
      biological/physical models of marine systems, J. Mar. Sys., 76(1-2),
      64-82, doi:10.1016/j.jmarsys.2008.05.014

    Author: Peter A. Rochford
        Symplectic, LLC
        www.thesymplectic.com
        [email protected]

    Created on Nov 24, 2016
    '''
    import numpy as np
    from skill_metrics import centered_rms_dev

    # Check for valid arguments
    if isinstance(predicted, dict):
        if field == '':
            raise ValueError('FIELD argument not supplied.')
        if field in predicted:
            p = predicted[field]
        else:
            raise ValueError('Field is not in PREDICTED dictionary: ' + field)
    elif isinstance(predicted, list):
        p = np.array(predicted)
    elif isinstance(predicted, np.ndarray):
        p = predicted
    else:
        raise ValueError('PREDICTED argument must be a dictionary.')

    if isinstance(reference, dict):
        if field == '':
            raise ValueError('FIELD argument not supplied.')
        if field in reference:
            r = reference[field]
        else:
            raise ValueError('Field is not in REFERENCE dictionary: ' + field)
    elif isinstance(reference, list):
        r = np.array(reference)
    elif isinstance(reference, np.ndarray):
        r = reference
    else:
        raise ValueError('REFERENCE argument must be a dictionary.')

    # Check that dimensions of predicted and reference fields match
    #ToDo: Implement check

    # Calculate bias (B)
    bias = np.mean(p) - np.mean(r)

    # Calculate centered root-mean-square (RMS) difference (E')
    crmsd = centered_rms_dev(p, r)

    # Calculate RMS difference (RMSD)
    rmsd = np.sqrt(np.sum(np.square(np.subtract(p, r))) / float(p.size))

    # Normalize if requested
    if norm == True:
        sigma_ref = np.std(r)
        bias = bias / sigma_ref
        crmsd = crmsd / sigma_ref
        rmsd = rmsd / sigma_ref

    # Store statistics in a dictionary
    stats = {'bias': bias, 'crmsd': crmsd, 'rmsd': rmsd}
    if norm == True:
        stats['type'] = 'normalized'
    else:
        stats['type'] = 'unnormalized'

    return stats
예제 #4
0
def taylor_statistics(predicted, reference, field=''):
    '''
    Calculates the statistics needed to create a Taylor diagram as 
    described in Taylor (2001) using the data provided in the predicted 
    field (PREDICTED) and the reference field (REFERENCE).
    
    The statistics are returned in the STATS dictionary.

    If a dictionary is provided for PREDICTED or REFERENCE, then 
    the name of the field must be supplied in FIELD.
  
    The function currently supports dictionaries, lists, and np.ndarray,
    types for the PREDICTED and REFERENCE variables.
 
    Input:
    PREDICTED : predicted field
    REFERENCE : reference field
    FIELD     : name of field to use in PREDICTED and REFERENCE dictionaries
                (optional)
    NORM      : logical flag specifying statistics are to be normalized 
                with respect to standard deviation of reference field
                = True,  statistics are normalized
                = False, statistics are not normalized
 
    Output:
    STATS          : dictionary containing statistics
    STATS['ccoef'] : correlation coefficients (R)
    STATS['crmsd'] : centered root-mean-square (RMS) differences (E')
    STATS['sdev']  : standard deviations
 
    Each of these outputs are one-dimensional with the same length. 
    First index corresponds to the reference series for the diagram. 
    For example SDEV[1] is the standard deviation of the reference 
    series (sigma_r) and SDEV[2:N] are the standard deviations of the 
    other (predicted) series.
 
    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
    '''
    import numpy as np
    from skill_metrics import centered_rms_dev

    # Check for valid arguments
    if isinstance(predicted, dict):
        if field == '':
            raise ValueError('FIELD argument not supplied.')
        if field in predicted:
            p = predicted[field]
        else:
            raise ValueError('Field is not in PREDICTED dictionary: ' + field)
    elif isinstance(predicted, list):
        p = np.array(predicted)
    elif isinstance(predicted, np.ndarray):
        p = predicted
    else:
        raise ValueError('PREDICTED argument must be a dictionary.')

    if isinstance(reference, dict):
        if field == '':
            raise ValueError('FIELD argument not supplied.')
        if field in reference:
            r = reference[field]
        else:
            raise ValueError('Field is not in REFERENCE dictionary: ' + field)
    elif isinstance(reference, list):
        r = np.array(reference)
    elif isinstance(reference, np.ndarray):
        r = reference
    else:
        raise ValueError('REFERENCE argument must be a dictionary.')

    # Check that dimensions of predicted and reference fields match
    #ToDo: Implement check

    # Calculate correlation coefficient
    ccoef = np.corrcoef(p, r)
    ccoef = ccoef[0]

    # Calculate centered root-mean-square (RMS) difference (E')^2
    crmsd = [0.0, centered_rms_dev(p, r)]

    # Calculate standard deviation of predicted field w.r.t N (sigma_p)
    sdevp = np.std(p)

    # Calculate standard deviation of reference field w.r.t N (sigma_r)
    sdevr = np.std(r)
    sdev = [sdevr, sdevp]

    # Store statistics in a dictionary
    stats = {'ccoef': ccoef, 'crmsd': crmsd, 'sdev': sdev}
    return stats