Giter Site home page Giter Site logo

skillmetrics's Introduction

Skill Metrics Project

This package contains a collection of functions for calculating the skill of model predictions against observations. It includes metrics such as root-mean-square-error (RMSE) difference, centered root-mean-square (RMS) difference, and skill score (SS), as well as a collection of functions for producing target and Taylor diagrams. The more valuable feature of the package are the plotting functions for target and Taylor diagrams and the ability to easily customize the diagrams.

Features

  • Statistical metrics such as root-mean-square-error (RMSE) difference, centered root-mean-square (RMS) difference, and skill score (SS)
  • Functions to calculate statistical metrics for target & Taylor diagrams
  • Target Diagrams
  • Taylor Diagrams
  • Options to control plot features such as color of labels and lines, width of lines, choice of markers, etc.
  • Output of graphics to any supported matplotlib format (default PNG).

Installation

To install the package simply use the pip3 command:

% pip3 install SkillMetrics

If you are upgrading the package then include the upgrade option:

% pip3 install SkillMetrics --upgrade

Note that the SkillMetrics package now only supports Python 3 because Python 2 has been depricated. Use of pip may not successfully install the latest version of the package.

Example Scripts

A primer on Taylor diagrams is provided as well as a 6-page description of target and Taylor diagrams as visual tools to aid in the analysis of model predictive skill. The figures used in the latter were generated with the SkillMetrics package. There is also an "Examples" folder that contains a collection of example Python scripts showing how to produce target and Taylor diagrams in a variety of formats on the Wiki Home page. There are multiple examples for target and Taylor diagrams that successively progress from very simple to more customized figures. These series of examples provide an easy tutorial on how to use the various options of the target_diagram and taylor_diagram functions. They also provide a quick reference in future for how to produce the diagrams with specific features.

There is also a simple program all_stats.py available via the Wiki that provides examples of how to calculate the various skill metrics used or available in the package. All the calculated skill metrics are written to a spreadsheet file for easy viewing and manipulation: Excel for a Windows operating system, Comma Separated Value (CSV) for a Macintosh operating system (MacOS). The Python code is kept to a minimum.

Example Diagrams

The diagrams produced by the example scripts are in Portable Network Graphics (PNG) format and have the same file name as the script with a .png suffix. The PNG files created can be viewed by following the links shown below. This is a useful starting point for users looking to identify the best example from which to begin creating a diagram for their specific need by modifying the accompanying Python script.

Target Diagrams

Taylor Diagrams

Here is a sample of the target and Taylor diagrams you'll find in the above examples:

target diagram Taylor diagram

FAQ

A list of Frequently Asked Questions (FAQ) is maintained on the Wiki. Users are encouraged to look there for solutions to problems they may encounter when using the package.

Available Metrics

Here is a list of currently supported metrics. Examples of how to obtain them can be found in the all_stats.py program. A far more extensive list of statistical metrics can be calculated using the SeqMetrics package.

Metric Description
bias Mean error
BS Brier score
BSS Brier skill score
CRMSD centered root-mean-square error deviation
KGE09 Kling-Gupta efficiency 2009
KGE12 Kling-Gupta efficiency 2012
NSE Nash-Sutcliffe efficiency
r Correlation coefficient
RMSD root-mean-square error deviation
SDEV standard deviation
SS Murphy's skill score

How to cite SkillMetrics

Peter A. Rochford (2016) SkillMetrics: A Python package for calculating the skill of model predictions against observations, http://github.com/PeterRochford/SkillMetrics

  @misc{rochfordskillmetrics, 
    title={SkillMetrics: A Python package for calculating the skill of model predictions against observations}, 
    author={Peter A. Rochford}, 
    year={2016}, 
    url={http://github.com/PeterRochford/SkillMetrics}, 

Guidelines to contribute

  1. In the description of your Pull Request (PR) explain clearly what it implements/fixes and your changes. Possibly give an example in the description of the PR.
  2. Give your pull request a helpful title that summarises what your contribution does.
  3. Write unit tests for your code and make sure the existing backward compatibility tests pass.
  4. Make sure your code is properly commented and documented. Each public method needs to be documented as the existing ones.

skillmetrics's People

Contributors

adlzanchetta avatar andreas-h avatar kevinwuwu avatar peterrochford avatar tamitoto avatar timcera avatar vinodkatmos avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

skillmetrics's Issues

Use different marker symbols in example taylor13.py

Hi,

I was wondering if it is possible to specify different marker symbols when plotting two datasets, as in example taylor13.py, and show this symbol in the legend. For instance, set markersymbol='*' for the ERA5 dataset.

Thanks!

Typo or bug? "first array element corresponds to the reference series "

# 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')

The comment there seems to disagree with the call. The call is ordered as prediction then reference but the comment suggests the other way around.

Not installing in Google Colab

Hello guys!
I'm trying to install the package in the Google Colab environment but I keep receiving this:

Collecting SkillMetrics
  Downloading https://files.pythonhosted.org/packages/6f/f0/0365c196295c6f4356298b1369c9121c71d90b52755807751d00d2a6fff6/SkillMetrics-1.1.7.tar.gz (44kB)
     |████████████████████████████████| 51kB 2.6MB/s 
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.

Does anyone know why?
Thank you in advance!

No module named 'xlsxwriter'

When installing with pip, I got this error:

ModuleNotFoundError: No module named 'xlsxwriter'

and

Command "python setup.py egg_info" failed with error code 1 in /private/var/folders/vz/pb7jltq97mx9v1qybf7y94j00000gp/T/pip-install-cebhv67f/SkillMetrics/

This was solved by installing the xlsxwriter (pip install xlsxwriter) before installing SkillMetrics. But just wanted to post in case others saw this same error.

Cannot change the label

This is a great package but my label are not readable. How can I change the font and size of "correlation coefficient" and STD?
555

check_taylor_stats not working properly

I think I found an issue in 'check_taylor_stats.py' and I will try to describe it in the following.

I am using numpy version 1.18.5 and python 3.6.9 64-bit. The version of 'check_taylor_stats' I used is copied at the bottom.

I want to raise the error of incompatible data, so I define data that is clearly not fulfilling

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

So if I define

STDs = [1,5,3,2]

CRMSDs = [1,7,6,4]

CORs = [6,8,3,1]

, which are some random values in a list, then my 'difference' list is

array([103., 44., 15])

So we get differences much above our threshold of 0.01. But as far as I understand it, we want the difference to be close to zero, so that we can be sure that

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

Next, the 'index' for these differences is

(array([0, 1, 2]),)

, which is clearly not empty.

But the function will only raise an error 'if not index', so if the 'index' is an empty list. So it doesn't raise an error for my random data. Am I overlooking something?

In the other direction, if my differences are very small, so that I can be sure that the data is correct, for example with:

STDs = [1.0, 1.4325136021271947, 1.0617690033008276, 1.4678603104077521, 1.1292483168466108, 1.9391992365319153, 0.7424689187296046, 1.190407099774292]
CRMSDs = [0.25735399231579914, 0.4455591033096046, 0.5688032547358672, 0.8937130204486814, 0.6372916529557612, 1.3136761418162093, 0.6242831508114802, 0.800117230131112]
CORs = [1.0, 0.9960018185865716, 0.8494391285508488, 0.8024915283990488, 0.8275686942766974, 0.7824746978593649, 0.7822082605692278, 0.7463335364755743]

I get the differences

array([3.63507139e-15, 8.57879111e-16, 1.66799715e-15, 2.32355360e-15, 7.71995646e-16, 4.27305282e-16, 8.67107592e-16])

which are all well below the threshold.

But now I think this is part of the problem; the variable 'index' looks like this

(array([], dtype=int64),)

which also doesn't count as empty, because of its shape, so 'if not index' also is not the case. So I am not able to raise the error so far. I can only raise it if I define

index = []

I would change if not index to

if len(index[0]) != 0:
, but I see that this has also shortcomings, if somehow 'index' even so is a list and not an array.

But for now, it will raise an error for me if one of the differences is above the threshold.

The function 'check_taylor_stats.py' I used:


import numpy as np



def check_taylor_stats(STDs, CRMSDs, CORs, threshold = 0.01):

'''

Checks input statistics satisfy Taylor diagram relation to <1%.



Function terminates with an error if not satisfied. The threshold is

the ratio of the difference between the statistical metrics and the

centered root mean square difference:



abs(CRMSDs^2 - (STDs^2 + STDs(1)^2 - 2*STDs*STDs(1)*CORs))/CRMSDs^2



Note that the first element of the statistics vectors must contain

the value for the reference field.



INPUTS:

STDs : Standard deviations

CRMSDs : Centered Root Mean Square Difference 

CORs : Correlation

threshold : limit for acceptance, e.g. 0.1 for 10% (default 0.01)



OUTPUTS:

None.



Author: Peter A. Rochford

Symplectic, LLC

www.thesymplectic.com

[email protected]



Created on Dec 3, 2016

'''

if threshold < 1e-7:

raise ValueError('threshold value must be positive: ' + str(threshold))



diff = np.square(CRMSDs[1:]) \

- (np.square(STDs[1:]) + np.square(STDs[0]) \

- 2.0*STDs[0]*np.multiply(STDs[1:],CORs[1:]))

diff = np.abs(np.divide(diff,np.square(CRMSDs[1:])))

index = np.where(diff > threshold)


if not index:

ii = np.where(diff != 0)

if len(ii) == len(diff):

raise ValueError('Incompatible data\nYou must have:' +

'\nCRMSDs - sqrt(STDs.^2 + STDs[0]^2 - ' +

'2*STDs*STDs[0].*CORs) = 0 !')

else:

raise ValueError('Incompatible data indices: {}'.format(ii) +

'\nYou must have:\nCRMSDs - sqrt(STDs.^2 + STDs[0]^2 - ' +

'2*STDs*STDs[0].*CORs) = 0 !')



return diff

Set limits for the angular coordinate in the Taylor diagrams

Hi,

Is it possible to set the limits of the angular coordinate (theta) in the polar plots. Let's say, show only the plot for correlation values greater than 0.5? It is often the case that data points cluster around some values, and then large parts of the plot are empty. It would be great to be able to zoom in to a region of interest.

Thank!

Change colours of markerlegend='on'

L.S.,

When markerlegend='on' in sm.taylor_diagram(), by default the markers get a blue, red and green colour. How do I modify these colours?

Secondly, it seems like that markerlegend also sorts the constructed Taylor points. In my case it is sorted for dh: 1000, dh: 250 and dh: 500 which is fine, however:

  • 'dh: 250, dt: 0:02:30, R: 50000' is labeled blue while it must be red,
  • 'dh: 500, dt: 0:02:30, R: 50000' is labeled red while it must be green,
  • 'dh: 500, dt: 0:02:30, R: 70000' is labeled red while it must be green.

I hopy anybody can help me with these two items.

Outdated numpy dependancy

Good Day,

The latest version of SkillMetrics that I can install with pip crashes when I try to plot target diagrams with this numpy error below. I see this issue is resolved on GitHub as I couldn't trace back the numpy code line giving the issue from: get_target_diagram_axes.py:116. Is it possible to make a new version of installable by pip so this issue can be avoided?

Thanks!

`---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
Cell In[21], line 3
1 ## My package seems to be out-dated. Using np.asscalar = depreciated but not on GitHub. See if can copy code and use this?
----> 3 target_diagram(np.array(bias_tot),np.array(crmsd_tot),np.array(rmsd_tot), markerLabel = label_tot,
4 markerLabelColor = 'k', markerLegend = 'on', markersymbol = symbols_tot,
5 markerSize=5, markerColor = color_tot,
6 ticks = np.arange(-2,2.5,0.5),
7 axismax = 2.0,
8 circles = [0.5,1,2],
9 circleLineSpec = 'k--', circleLineWidth = 0.5)
11 # plt.savefig(os.path.join(outdir, f'TargetDiagram_allvars_{tdate}_max2.png'), dpi=600, bbox_inches="tight")
12 # plt.close()

File P:\11206304-futuremares\python_scripts\plot_results3D\WQ_validation\target_diagram.py:232, in target_diagram(*args, **kwargs)
229 option = get_target_diagram_options(**kwargs)
231 # Get axis values for plot
--> 232 axes = get_target_diagram_axes(RMSDs,Bs,option)
234 # Overlay circles
235 overlay_target_diagram_circles(ax, option)

File ~\Anaconda3\envs\dfm_tools_env\lib\site-packages\skill_metrics\get_target_diagram_axes.py:116, in get_target_diagram_axes(x, y, option)
114 # Set tick labels at 0 to blank
115 index = np.where(abs(xtick) < 1.e-7)
--> 116 index = np.asscalar(index[0])
117 xlabel[index] = ''
119 # Set y tick labels

File ~\Anaconda3\envs\dfm_tools_env\lib\site-packages\numpy_init_.py:311, in getattr(attr)
308 from .testing import Tester
309 return Tester
--> 311 raise AttributeError("module {!r} has no attribute "
312 "{!r}".format(name, attr))

AttributeError: module 'numpy' has no attribute 'asscalar'`

custom control marker color

When I try to custom control marker color like this:

MARKERS = {
"EC-Earth3": {
        "labelColor": "k",
        "symbol": "+",
        "size": 9,
        "faceColor": "#b4ddd4",
        "edgeColor": "#b4ddd4"
}
}

The following error occurred:

Traceback (most recent call last):
  File "E:\GEO\pyproject\taylor_dia.py", line 137, in <module>
    sm.taylor_diagram(sdev, crmsd, ccoef, markers=MARKERS, markerLegend='on',labelrms= 'RMSE')
  File "C:\Users\user\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\skill_metrics\taylor_diagram.py", line 388, in taylor_diagram
    plot_pattern_diagram_markers(ax, X, Y, options)
  File "C:\Users\user\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\skill_metrics\plot_pattern_diagram_markers.py", line 107, in plot_pattern_diagram_markers
    h = ax.plot(X[i],Y[i],marker[i], markersize = markersize[i],
  File "C:\Users\user\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\matplotlib\axes\_axes.py", line 1662, in plot
    lines = [*self._get_lines(*args, data=data, **kwargs)]
  File "C:\Users\user\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\matplotlib\axes\_base.py", line 311, in __call__
    yield from self._plot_args(
  File "C:\Users\user\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\matplotlib\axes\_base.py", line 454, in _plot_args
    linestyle, marker, color = _process_plot_format(
  File "C:\Users\user\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\matplotlib\axes\_base.py", line 197, in _process_plot_format
    raise ValueError(
ValueError: '+#b4ddd4' is not a valid format string (unrecognized character '#')

I finaly found the solution:
the code in get_single_markers.py in line 43:

    # Iterate through keys in dictionary
    for key in markers:
        color = markers[key]['faceColor']
        symbol = markers[key]['symbol']
        SymbolColor = symbol + color
        marker.append(SymbolColor)
        markersize.append(markers[key]['size'])
        markerfacecolor.append(color)
        markeredgecolor.append(markers[key]['edgeColor'])
        markerlabel.append(key) # store label
        labelcolor.append(markers[key]['labelColor'])

should change into:

     # Iterate through keys in dictionary
    for key in markers:
        color = markers[key]['faceColor']
        symbol = markers[key]['symbol']
        marker.append(symbol)
        markersize.append(markers[key]['size'])
        markerfacecolor.append(color)
        markeredgecolor.append(markers[key]['edgeColor'])
        markerlabel.append(key) # store label
        labelcolor.append(markers[key]['labelColor'])

because it seems that matplotlib only suport symbol + color in 1 letter (eg: 'or','xg',etc)

Missing setup.py

The setup.py file was deleted in commit 983d66d which means the package can no longer be pip installed

bold ticks

Hi,
Great thanks to make available such great and flexible python scripts!

I would like to increase the font size of labels and ticks on each axis.

May you kindly help me with it?

With regards
Santanu

Request: Need to be able to change marker shape as well as color on the Taylor diagrams

Thank you for this tool! However, I'm running into a particularly annoying issue:

I need to be able to have specifically colored points for each particular model I'm comparing to the reference. I've solved this particular issue by using the "overlay" option and plotting each single model individually on the plot with the color tuple as the markerColor specification. Here's an example:

DJF_NP_ua_taylorplot

HOWEVER. Now I need to have different marker shapes as well as marker colors! Ideally, there would be a markerShape flag that would allow you to specify markerShape="x" vs markerShape="." etc. as well as defining markerColor="blue" or whatever. I had hoped that the using the existing markerLegend option would be sufficient, but for some reason it doesn't like my pre-defined color tuples in combination with this option.

For reference, here's my existing code:

        #Initialize the plot
        ts=sm.taylor_statistics(store_mod[d],rean_ref)
        mod_col=rgb_order[0]

        ref_sd[0]=ts['sdev'][0]
        ref_sd[1]=ts['sdev'][1]

        ref_rm[0]=ts['crmsd'][0]
        ref_rm[1]=ts['crmsd'][1]

        ref_cc[0]=ts['ccoef'][0]
        ref_cc[1]=ts['ccoef'][1]

        sm.taylor_diagram(ref_sd,ref_rm,ref_cc,styleOBS='-.',widthOBS=3,markerlabel=['REAN',d],
                         markerSize=30,tickRMS = tr,axismax=am,markerColor=mod_col) 

        i=1
       #Add the other points
        for d in comb_list[1:]:
            
            ts=sm.taylor_statistics(store_mod[d],rean_ref)
            mod_col=rgb_order[i]
            ref_sd[0]=ts['sdev'][0]
            ref_sd[1]=ts['sdev'][1]
            ref_rm[0]=ts['crmsd'][0]
            ref_rm[1]=ts['crmsd'][1]
            ref_cc[0]=ts['ccoef'][0]
            ref_cc[1]=ts['ccoef'][1]
            sm.taylor_diagram(ref_sd,ref_rm,ref_cc,styleOBS='-.',widthOBS=3,markerlabel=['REAN',d],
                             markerSize=30,markerColor=mod_col,overlay='on')    
            i+=1

local variable 'markercolor' referenced before assignment

When trying to use a legend (e.g. examples 5 and 9) I get this error:

skill_metrics/plot_pattern_diagram_markers.pyc in plot_pattern_diagram_markers(X, Y, option)
72 marker.append(symbol + color)
73 rgba = clr.to_rgb(color) + (alpha,)
---> 74 markercolor.append(rgba)
75
76 # Plot markers at data points

UnboundLocalError: local variable 'markercolor' referenced before assignment

Sample taylor1.py doesn't work

python2 taylor1.py
Traceback (most recent call last):
  File "taylor1.py", line 101, in <module>
    sm.taylor_diagram(sdev,crmsd,ccoef)
  File "/usr/local/lib/python2.7/site-packages/skill_metrics/taylor_diagram.py", line 91, in taylor_diagram
    overlay_taylor_diagram_circles(axes,cax,option)
  File "/usr/local/lib/python2.7/site-packages/skill_metrics/overlay_taylor_diagram_circles.py", line 51, in overlay_taylor_diagram_circles
    xunit[inds[1:3:2]] = np.zeros(2)
ValueError: shape mismatch: value array of shape (2,) could not be broadcast to indexing result of shape (1,)

Range of values on the standard deviation axis do not adjust during overlay

I am preparing a Taylor diagram by plotting my observed data first before running a loop to overlay results from other models.

The problem I have is that the vertical and horizontal axis (Standard deviation) do not adjust to include new data that are outside the range of the diagram. Find below an image of the problem I'm having. How do I fix this?
image

Plot taylor_diagram inside subplots

Hello,
I was looking to plot the taylor diagram inside matplotlib's subplots. Something like:

thresholds = [-1, 1, 2, 5, 10, 20, 30]
_,ax = plt.subplots(figsize=(3*len(thresholds), 3), ncols=len(thresholds))

for i, threshold in enumerate(thresholds):
    mask = tar > threshold
    stats = sm.taylor_statistics(pred[mask], tar[mask])
    sdev = np.array([stats['sdev'][0], stats['sdev'][1]])
    crmsd = np.array([stats['crmsd'][0], stats['crmsd'][1],])                     
    ccoef = np.array([stats['ccoef'][0], stats['ccoef'][1]])

    sm.taylor_diagram(sdev,crmsd,ccoef,markerLabel=['Target','Pred'],markerLegend='on', ax=ax[i])
plt.show()

I don't see taylor_diagram supporting ax arguement. Do let me know if there is already some (even hacky) way to do this.
Thanks !!

How can I show normalized std on the diagram?

Hi,

I want to show normalized standard deviation (observed std/predicted std) so that ref value of 1 is where variability matches between observations and prediction. This is useful when I put multiple data sets on the diagram where ref values are different for each data sets unless they are normalized.

I wonder if you could tell me how to show the normalized std.

Thanks in advance,

-DJ

Error with cmapzdata functionality

Hello,

I appreciate the detailed instructions and examples for this useful package. My question is about plotting using the cmapzdata option, which appears to only correspond to the total RMSD values of a dataset, even when specifying a separate list or array of values. Below I've copied a minimal example from a dataset that I am working with.

Latitude Bias CRMSD RMSD
32 0.3 0.5 0.9
36 0.4 0.6 1.1
40 0.5 1.0 1.5

Below is the code that I am using to plot this small dataset, and the result.

lat = [32, 36, 40]
bias = [0.3, 0.4, 0.5]
crmsd = [0.4, 0.6, 1.1]
rmsd = [0.5, 1.0, 1.5]

sm.target_diagram(np.array(bias),np.array(crmsd),np.array(rmsd),
                  markerDisplayed='colorBar', titleColorbar='Latitude',
                  cmapzdata=lat, cmap='viridis', cmap_marker='o',
                  markersize=35)
cmapzdata_example_1 copy

My issue is that when lat is reversed, I get the exact same results. However, the order of the colors are reversed when the value of rmsd is reversed as well, rather than the user input in the target_diagram function.

I'm a new user to this package, so apologies if I've missed something. Any help is greatly appreciated.

RMSD title location

I want to modify the location of the title 'RMSD'. It is now above the first arc of RMSD. But I want to get the title below the arc.

cmap is not use!!!

I am glad that the author can create such an excellent package, but after updating to the latest version, parameters such as cmap and cmap_marker are still unavailable

pkl to csv

sir, i have a csv file of my model datasets i need to make the tailor diagram but your example code only read a pkl file is there any way i can change my csv to pkl

Potential pull request: plotting Taylor diagrams as subplots

Congratulations for this amazing package @PeterRochford !

I've been using it for a time, but recently I found some apparent limitations that did not allowed me to get to the result I wanted:

  1. I was not able to have multiple Taylor plots in a single Figure;
  2. The curved "correlation coefficient" label sometimes have overlapping letters depending on the font used, maybe a linear option could be available;
  3. There was not a clear way to set the colors of the x and y (left/bottom) frames.

So I added some functions to the package that allow me to overcome these issues in a way that does not affect the current implementation. I also added an example to illustrate how to use the new functions that produces the following figure:
taylor14

If you believe this is a good add to the project, I would be more than happy to properly document it following the commenting standards of the project and submit a pull request.
Please let me know your thoughts and thanks for sharing your code!

request

Is there a way to add bias to the Taylor diagram? Like the attached image

om7a0

Issue with numpy function

Hi,

Many thanks for making available such a great package!

I got the following error message:
File "/home/ivan/python_3.9.0/lib/python3.9/site-packages/skill_metrics/target_diagram.py", line 64, in target_diagram
axes = get_target_diagram_axes(RMSDs,Bs,option)
File "/home/ivan/python_3.9.0/lib/python3.9/site-packages/skill_metrics/get_target_diagram_axes.py", line 116, in get_target_diagram_axes
index = np.asscalar(index[0])
File "/home/ivan/python_3.9.0/lib/python3.9/site-packages/numpy/init.py", line 311, in getattr
raise AttributeError("module {!r} has no attribute "
AttributeError: module 'numpy' has no attribute 'asscalar

I have Python 3.6.9 and numpy 1.23.3. I searched for this error message, and it seems that "asscalar" function was deprecated in numpy version 1.16

Best regards,

Ivan

Error when many marker/colors are needed

Hi there,

I think I found an issue when many markers need to be displayed (I'm not an heavy user of this library, so maybe I'm just missing something...).

Here is a MRE:

import skill_metrics
import numpy as np

size = 10
skill_metrics.taylor_diagram(
    np.random.randn(size),
    np.random.randn(size),
    np.random.uniform(size=size),
    alpha=0.0,
    axismax=4,
    colCOR="k",
    colOBS="k",
    colRMS="m",
    colSTD="b",
    markerLabel=[str(i) for i in range(size)],
    markerLegend="on",
    markerSize=10,
    markerobs="o",
    styleCOR="--",
    styleOBS="--",
    styleRMS=":",
    styleSTD="-.",
    tickRMS=np.linspace(0, 4, 5),
    tickSTD=np.linspace(0, 4, 5),
    titleCOR="on",
    titleOBS="0",
    titleRMS="on",
    titleRMSDangle=40.0,
    titleSTD="on",
    widthCOR=0.5,
    widthOBS=2,
    widthRMS=2,
    widthSTD=1.0,
)
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Cell In[1], line 5
      2 import numpy as np
      4 size = 10
----> 5 skill_metrics.taylor_diagram(
      6     np.random.randn(size),
      7     np.random.randn(size),
      8     np.random.uniform(size=size),
      9     alpha=0.0,
     10     axismax=4,
     11     colCOR="k",
     12     colOBS="k",
     13     colRMS="m",
     14     colSTD="b",
     15     markerLabel=[str(i) for i in range(size)],
     16     markerLegend="on",
     17     markerSize=10,
     18     markerobs="o",
     19     styleCOR="--",
     20     styleOBS="--",
     21     styleRMS=":",
     22     styleSTD="-.",
     23     tickRMS=np.linspace(0, 4, 5),
     24     tickSTD=np.linspace(0, 4, 5),
     25     titleCOR="on",
     26     titleOBS="0",
     27     titleRMS="on",
     28     titleRMSDangle=40.0,
     29     titleSTD="on",
     30     widthCOR=0.5,
     31     widthOBS=2,
     32     widthRMS=2,
     33     widthSTD=1.0,
     34 )

File ~/mambaforge/envs/eqc/lib/python3.10/site-packages/skill_metrics/taylor_diagram.py:385, in taylor_diagram(*args, **kwargs)
    383 lowcase = options['markerdisplayed'].lower()
    384 if lowcase == 'marker':
--> 385     plot_pattern_diagram_markers(ax, X, Y, options)
    386 elif lowcase == 'colorbar':
    387     nZdata = len(options['cmapzdata'])

File ~/mambaforge/envs/eqc/lib/python3.10/site-packages/skill_metrics/plot_pattern_diagram_markers.py:90, in plot_pattern_diagram_markers(ax, X, Y, option)
     88 for i, xval in enumerate(X):
     89     if abs(X[i]) <= limit and abs(Y[i]) <= limit:
---> 90         h = ax.plot(X[i],Y[i],marker[i], markersize = markerSize,
     91              markerfacecolor = markercolor[i],
     92              markeredgecolor = markercolor[i][0:3] + (1.0,),
     93              markeredgewidth = 2)
     94         hp += tuple(h)
     95         labelcolor.append(option['markerlabelcolor'])

File ~/mambaforge/envs/eqc/lib/python3.10/site-packages/matplotlib/axes/_axes.py:1688, in Axes.plot(self, scalex, scaley, data, *args, **kwargs)
   1445 """
   1446 Plot y versus x as lines and/or markers.
   1447
   (...)
   1685 (``'green'``) or hex strings (``'#008000'``).
   1686 """
   1687 kwargs = cbook.normalize_kwargs(kwargs, mlines.Line2D)
-> 1688 lines = [*self._get_lines(*args, data=data, **kwargs)]
   1689 for line in lines:
   1690     self.add_line(line)

File ~/mambaforge/envs/eqc/lib/python3.10/site-packages/matplotlib/axes/_base.py:311, in _process_plot_var_args.__call__(self, data, *args, **kwargs)
    309     this += args[0],
    310     args = args[1:]
--> 311 yield from self._plot_args(
    312     this, kwargs, ambiguous_fmt_datakey=ambiguous_fmt_datakey)

File ~/mambaforge/envs/eqc/lib/python3.10/site-packages/matplotlib/axes/_base.py:454, in _process_plot_var_args._plot_args(self, tup, kwargs, return_kwargs, ambiguous_fmt_datakey)
    451 if len(tup) > 1 and isinstance(tup[-1], str):
    452     # xy is tup with fmt stripped (could still be (y,) only)
    453     *xy, fmt = tup
--> 454     linestyle, marker, color = _process_plot_format(
    455         fmt, ambiguous_fmt_datakey=ambiguous_fmt_datakey)
    456 elif len(tup) == 3:
    457     raise ValueError('third arg must be a format string')

File ~/mambaforge/envs/eqc/lib/python3.10/site-packages/matplotlib/axes/_base.py:190, in _process_plot_format(fmt, ambiguous_fmt_datakey)
    188 elif c in mcolors.get_named_colors_mapping():
    189     if color is not None:
--> 190         raise ValueError(errfmt.format(fmt, "two color symbols"))
    191     color = c
    192     i += 1

ValueError: 'pgray' is not a valid format string (two color symbols)

Incorrect paper reference in wiki

Hello:

This is about:
https://github.com/PeterRochford/SkillMetrics/wiki

I think for:
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

I think you actually mean this instead:

https://doi.org/10.1016/j.jmarsys.2008.05.014

Jolliff, J. K., J. C. Kindle, I. Shulman, B. Penta, M. Friedrichs, R. Helber, and R. Arnone (2009), Summary diagrams for coupled hydrodynamic-ecosystem model skill assessment, J. Mar. Sys., 76(1-2), 64-82, doi:10.1016/j.jmarsys.2008.05.014

Your authors name, page numbers, and volume number are correct, but the paper title and doi are incorrect.

SC

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.