ReliabilityDiagram


NameReliabilityDiagram JSON
Version 0.0.3 PyPI version JSON
download
home_pagehttps://github.com/clecoz/ReliabilityDiagram
SummaryA package which provides the contingency table and all the other ingredients required to plot a reliability diagram. A reliability diagram is a diagnostic plot which helps to understand the joint distribution of forecasts and observations for probabilistic forecasts of a dichotomous event (i.e., yes/no event).
upload_time2023-06-01 19:09:01
maintainer
docs_urlNone
authorNaveen Goutham, Camille Le Coz
requires_python
licenseApache License 2.0
keywords reliability table contingency table reliability diagram attributes diagram reliability resolution forecast attributes brier score ensemble forecast forecast climatology python
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Documentation  

A package which provides the **contigency table** and all the other ingredients required to plot a reliability diagram. We also provide examples to show how this package could be used to create customized reliability diagrams based on user requirements.

**For documentation, please refer to https://github.com/clecoz/ReliabilityDiagram** 

A reliability diagram is a diagnostic plot to understand the quality of a probabilistic forecast for categorical events. An example of a categorical event can be the probability for the daily average temperature in Paris to be in the lower tercile of the climatological distribution. Obtaining a contingency table is an essential first step in producing a reliability diagram. A contingency table is a matrix indicating the number of times an event forecasted with a certain probability occurs (or not). The probabilities are usually binned. A contingency table is produced by first binning the sample according to forecast probability, and then by computing the frequency of the observed event for all of the forecasts in each bin. A typical contingency table is shown below:

| Forecast probability | Events observed | Events not observed |
| :----:               |    :----:       |        :----:       |
| 0.0 - 0.2            | y1              | x1                  |
| 0.2 - 0.4            | y2              | x2                  |
| 0.4 - 0.6            | y3              | x3                  |
| 0.6 - 0.8            | y4              | x4                  |
| 0.8 - 1.0            | y5              | x5                  |

A reliability diagram plots the observed frequency against the forecast probability for each bin. The points are generally plotted at the midpoints of the bins. A perfectly reliable forecasting system has points lying on the 45° diagonal line, indicating that the forecast probability is essentially equal to observed frequency on average. Climatological frequency line is drawn horizontally at a location corresponding to the event's probability, for e.g. the climatological frequency of a tercile is 1/3 and that of decile is 1/10. Similarly, the average forecast porbability line is drawn vertically corresponding to the event. The smaller the distance between the points and the diagonal line, the higher is the reliability of the forecasting system. The larger the distance between the points and the horizontal climatological line, the higher is the resolution of the forecasting system. The line that bisects the angle between the perfect reliability line (i.e., the diagonal) and the horizontal climatological line is called the no skill line. On this line, the reliability and the resolution components become equal and so the forecast skill (measured using Brier Skill Score ([5], [2], [3])) becomes equal to that of climatology. Accordingly, the points located within the shaded region (see examples below) contribute positively to skill. For a more detailed description of the reliability diagram, the reader is referred to section 9.4.4 of Chapter 9 in [3] or section 4b in [4] or section 4.3 in [5].  

_References_:

[1] Sanders, F., 1963: On Subjective Probability Forecasting. Journal of Applied Meteorology and Climatology, 2 (2), 191–201, https://doi.org/10.1175/1520-0450(1963)002<0191:OSPF>2.0.CO;2, URL https://journals.ametsoc.org/view/journals/apme/2/2/1520-0450_1963_002_0191_ospf_2_0_co_2.xml, publisher: American Meteorological Society Section: Journal of Applied Meteorology and Climatology.

[2] Jolliffe, I., and D. Stephenson, 2003: Forecast Verification: A Practitioner’s Guide in Atmospheric Science. Wiley, URL https://books.google.cm/books?id=cjS9kK8IWbwC

[3] Wilks, D. S., 2019: Chapter 9 - forecast verification. In Statistical methods in the atmospheric sciences. 4th ed., Elsevier, Cambridge.

[4] Goutham, N., Plougonven, R., Omrani, H., Parey, S., Tankov, P., Tantet, A., Hitchcock, P., & Drobinski, P. (2022). How Skillful Are the European Subseasonal Predictions of Wind Speed and Surface Temperature?, Monthly Weather Review, 150(7), 1621-1637. Retrieved Sep 25, 2022, from https://journals.ametsoc.org/view/journals/mwre/150/7/MWR-D-21-0207.1.xml

[5] Coelho, C. A. S., B. Brown, L. Wilson, M. Mittermaier, and B. Casati, 2019: Forecast verification for S2S timescales. Sub-Seasonal to Seasonal Prediction: The Gap between Weather and Climate Forecasting, A. Robertson, and F. Vitart, Eds., Elsevier, 337–361, Chapter: 16.

[6] Brier, G. W., 1950: Verification of forecasts expressed in terms of probability. 3.

---
## _Installation:_

```sh
pip install ReliabilityDiagram
```
---
## _Parameters:_

**observation**: numpy.ndarray, shape (nsim,)  
Observation/truth for nsim events.

**forecast**: numpy.ndarray, shape (nsim,mem_fc)  
Ensemble forecasts with ensemble size mem_fc for the same nsim events.

**climatology**: numpy.ndarray, shape (nsim,mem_cl)  
Climatology for the same nsim events with mem_cl the number of years considered.  

**event_lbound**: int or float  
The lower bound for the event considered.  
E.g. 1: If the event considered is lower tercile, then event_lbound value is 0.  
E.g. 2: If the event considered is upper tercile, then event_lbound value is 2/3.  
_NOTE_: The value should be in the range of 0 to 1. This value should be lesser than the value of event_ubound.

**event_ubound**: int or float  
The upper bound for the event considered.  
E.g. 1: If the event considered is lower tercile, then event_ubound value is 1/3.  
E.g. 2: If the event considered is upper tercile, then event_ubound value is 1.  
_NOTE_: The value should be in the range of 0 to 1. This value should be greater than the value of event_lbound.
            
**closed_ends**: str, optional  
The bounds (upper and/or lower) to include in the event formulation. Options: 'left', 'right', 'none', 'both'.  
E.g. 1: If closed_ends = 'left', then the event becomes event_lbound <= event < event_ubound.  
E.g. 2: If closed_ends = 'both', then the event becomes event_lbound <= event <= event_ubound.  
_NOTE_: The default value is 'both'. The value is case sensitive.  
_NOTE_: This option is overwritten when event_lbound=0 or event_ubound=1 in order to include the forecast values that are outside the bounds of the climatology.  

**nbins**: int, optional  
Number of bins to stratify the forecasts into. The default is 5.  
_NOTE_: The bins are of equal width. The number of bins should be lesser than the dimension of observation.
            
**weights**: numpy.ndarray, shape (nsim,mem_fc), optional  
The weights of the members of the ensemble forecast. It should have the same shape as the forecast data.

---
## _Method(s):_

**contingency_table()**:  
This method computes the contingency table for the defined event.  
_Returns_: Contingency table having shape (nbins,2) where the first column corresponds to the "yes" event and the second column corresponds to the "no" event.

**observed_frequency()**:  
_Returns_: The observed relative frequency for each bin. This is required for plotting the reliability diagram.  

**confidence_intervals()**:  
_Returns_: This function returns the lower and the upper confidence intervals, respectively, corresponding to the observed frequency. This is required for plotting the reliability diagram.

**forecast_attributes()**:  
This method computes the Brier Score along with the reliability and the resolution attributes using the contingency table.  
_Returns_: Brier Score, Reliability, Resolution.

---
## _Demonstration:_

```python
import ReliabilityDiagram as rd
import numpy as np
import matplotlib.pyplot as pl
```
----
### Example - 1:
* Create case data
###### Input
```python
nobs = 5000   # number of events
nclim = 30    # number of years considered in climatology
nfc = 51      # ensemble size of the forecasts

clima = np.random.normal(loc=0,scale=10,size=(nobs,nclim))   # climatology (follows the same normal distribution for all events)
obs = np.random.normal(loc=0,scale=10,size=(nobs))           # observations drawn from the same distribution as climatology
fcast = np.random.normal(loc=obs+np.random.normal(loc=3,scale=5,size=(nobs)) ,scale=5,size=(nfc,nobs)).T   # forecasts (also generated by a normal distribution 
                                                                                                           # s.t. ensemble mean = observations + bias + noise)
```
* Compute contingency table and forecast attributes
###### Input
```python
data = rd.ReliabilityDiagram(obs,fcast,clima,0,1/4,closed_ends='both',nbins=10)  # example for lower quartile
```

###### Input
```python
c_table = data.contingency_table()    
print(c_table)
```
###### Output

    array([[ 113., 2955.],
           [  78.,  268.],
           [  77.,  147.],
           [  86.,   94.],
           [  82.,   76.],
           [  92.,   42.],
           [ 109.,   34.],
           [ 124.,   22.],
           [ 140.,   16.],
           [ 429.,   16.]])

###### Input
```python
bs, rel, res = data.forecast_attributes()
print(bs, rel, res)
```

###### Output

    0.08890199999999998 0.007429976189885926 0.11377197618988595
    
* Plot reliability diagram

###### Input
```python
# Compute needed elements for diagram
yi = data.bins + (data.bins[1]-data.bins[0])/2   # mid-points of the bins
oi = data.observed_frequency()
ci_low, ci_upp = data.confidence_intervals()
wti = np.sum(c_table,axis=1)/np.sum(c_table) 

# Elements for plot
xd = yd = [0,1]
q = data.ub - data.lb
clim_x = clim_y = [q,q]
sk_line = [q/2,(1-q)/2+q]

# Plot
# (in this example, the lower quartile is underforecasted)
fig = pl.figure(figsize=(7,5))
pl.plot(xd,yd,color='black',linestyle=':',linewidth=0.5)
pl.plot(xd,clim_y,color='black',linestyle=':',linewidth=0.5)
pl.plot(clim_x,yd,color='black',linestyle=':',linewidth=0.5)
pl.plot(xd,sk_line,color='black',linestyle='--',linewidth=0.5)
pl.fill_between(xd,xd,sk_line,facecolor='grey',alpha=0.2)
pl.fill_betweenx(yd,yd,clim_x,facecolor='grey',alpha=0.2)
pl.scatter(yi,oi,s=wti*10000,color='deepskyblue',marker='o',alpha=0.5,edgecolors='none')
pl.plot(yi,oi,color='deepskyblue',linestyle='-',linewidth=0.8)
pl.errorbar(yi,oi,yerr=[oi - ci_low, ci_upp - oi],ecolor='deepskyblue',elinewidth=0.8,alpha=0.5)
pl.ylim(0.0,1.0)
pl.xlim(0.0,1.0)
pl.ylabel('Observed frequency \np(o|y)',fontsize=11)
pl.xlabel('Forecast probability \ny',fontsize=11)
pl.title("Lower quartile ")
pl.tight_layout()
```

###### Output

![png](example1.png)
    
----

### Example - 2:

###### Input
```python
fcast2 = np.random.normal(loc=obs+np.random.normal(loc=0,scale=3,size=(nobs)) ,scale=5,size=(nfc,nobs)).T   
```

###### Input
```python
data_lt = rd.ReliabilityDiagram(obs,fcast2,clima,0,1/3,closed_ends='both',nbins=10)  # example for the lower tercile
data_ut = rd.ReliabilityDiagram(obs,fcast2,clima,2/3,1,closed_ends='both',nbins=10)  # example for the upper tercile
```

* Plot reliability diagram

###### Input
```python
# Compute needed elements for diagram
c_table_lt = data_lt.contingency_table()
wti_lt = np.sum(c_table_lt,axis=1)/np.sum(c_table_lt)
oi_lt = data_lt.observed_frequency()
ci_low_lt, ci_upp_lt = data_lt.confidence_intervals()

c_table_ut = data_ut.contingency_table()
wti_ut = np.sum(c_table_ut,axis=1)/np.sum(c_table_ut)
oi_ut = data_ut.observed_frequency()
ci_low_ut, ci_upp_ut = data_ut.confidence_intervals()

yi = data_lt.bins + (data_lt.bins[1]-data_lt.bins[0])/2  # both have the same bins for the forecast probabilities (same nbins)

# Other elements for plot
xd = yd = [0,1]
q = 1/3   # tercile
clim_x = clim_y = [q,q]
sk_line = [q/2,(1-q)/2+q]

# Plot
# (in this example, the model is underconfident)
fig = pl.figure(figsize=(7,5))
pl.plot(xd,yd,color='black',linestyle=':',linewidth=0.5)
pl.plot(xd,clim_y,color='black',linestyle=':',linewidth=0.5)
pl.plot(clim_x,yd,color='black',linestyle=':',linewidth=0.5)
pl.plot(xd,sk_line,color='black',linestyle='--',linewidth=0.5)
pl.fill_between(xd,xd,sk_line,facecolor='grey',alpha=0.2)
pl.fill_betweenx(yd,yd,clim_x,facecolor='grey',alpha=0.2)
pl.scatter(yi,oi_lt,s=wti_lt*10000,color='deepskyblue',marker='o',alpha=0.5,edgecolors='none')
pl.plot(yi,oi_lt,color='deepskyblue',linestyle='-',linewidth=0.8, label="lower tercile")
pl.errorbar(yi,oi_lt,yerr=[oi_lt - ci_low_lt, ci_upp_lt - oi_lt],ecolor='deepskyblue',elinewidth=0.8,alpha=0.5)
pl.scatter(yi,oi_ut,s=wti_ut*10000,color='orange',marker='o',alpha=0.5,edgecolors='none')
pl.plot(yi,oi_ut,color='orange',linestyle='-',linewidth=0.8, label="upper tercile")
pl.errorbar(yi,oi_ut,yerr=[oi_ut - ci_low_ut, ci_upp_ut - oi_ut],ecolor='orange',elinewidth=0.8,alpha=0.5)
pl.ylim(0.0,1.0)
pl.xlim(0.0,1.0)
pl.legend()
pl.ylabel('Observed frequency \np(o|y)',fontsize=11)
pl.xlabel('Forecast probability \ny',fontsize=11)
pl.title("Terciles")
pl.tight_layout()
```

###### Output

![png](example2.png)




            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/clecoz/ReliabilityDiagram",
    "name": "ReliabilityDiagram",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "reliability table,contingency table,reliability diagram,attributes diagram,reliability,resolution,forecast attributes,brier score,ensemble forecast,forecast,climatology,python",
    "author": "Naveen Goutham, Camille Le Coz",
    "author_email": "naveen.goutham@outlook.com, camille.lecoz@laposte.net",
    "download_url": "https://files.pythonhosted.org/packages/b4/08/847f67a58568b495d4d2eb3c92f2678d3892e9b881b4b051849e78cdd528/ReliabilityDiagram-0.0.3.tar.gz",
    "platform": null,
    "description": "# Documentation  \n\nA package which provides the **contigency table** and all the other ingredients required to plot a reliability diagram. We also provide examples to show how this package could be used to create customized reliability diagrams based on user requirements.\n\n**For documentation, please refer to https://github.com/clecoz/ReliabilityDiagram** \n\nA reliability diagram is a diagnostic plot to understand the quality of a probabilistic forecast for categorical events. An example of a categorical event can be the probability for the daily average temperature in Paris to be in the lower tercile of the climatological distribution. Obtaining a contingency table is an essential first step in producing a reliability diagram. A contingency table is a matrix indicating the number of times an event forecasted with a certain probability occurs (or not). The probabilities are usually binned. A contingency table is produced by first binning the sample according to forecast probability, and then by computing the frequency of the observed event for all of the forecasts in each bin. A typical contingency table is shown below:\n\n| Forecast probability | Events observed | Events not observed |\n| :----:               |    :----:       |        :----:       |\n| 0.0 - 0.2            | y1              | x1                  |\n| 0.2 - 0.4            | y2              | x2                  |\n| 0.4 - 0.6            | y3              | x3                  |\n| 0.6 - 0.8            | y4              | x4                  |\n| 0.8 - 1.0            | y5              | x5                  |\n\nA reliability diagram plots the observed frequency against the forecast probability for each bin. The points are generally plotted at the midpoints of the bins. A perfectly reliable forecasting system has points lying on the 45\u00b0 diagonal line, indicating that the forecast probability is essentially equal to observed frequency on average. Climatological frequency line is drawn horizontally at a location corresponding to the event's probability, for e.g. the climatological frequency of a tercile is 1/3 and that of decile is 1/10. Similarly, the average forecast porbability line is drawn vertically corresponding to the event. The smaller the distance between the points and the diagonal line, the higher is the reliability of the forecasting system. The larger the distance between the points and the horizontal climatological line, the higher is the resolution of the forecasting system. The line that bisects the angle between the perfect reliability line (i.e., the diagonal) and the horizontal climatological line is called the no skill line. On this line, the reliability and the resolution components become equal and so the forecast skill (measured using Brier Skill Score ([5], [2], [3])) becomes equal to that of climatology. Accordingly, the points located within the shaded region (see examples below) contribute positively to skill. For a more detailed description of the reliability diagram, the reader is referred to section 9.4.4 of Chapter 9 in [3] or section 4b in [4] or section 4.3 in [5].  \n\n_References_:\n\n[1] Sanders, F., 1963: On Subjective Probability Forecasting. Journal of Applied Meteorology and Climatology, 2 (2), 191\u2013201, https://doi.org/10.1175/1520-0450(1963)002<0191:OSPF>2.0.CO;2, URL https://journals.ametsoc.org/view/journals/apme/2/2/1520-0450_1963_002_0191_ospf_2_0_co_2.xml, publisher: American Meteorological Society Section: Journal of Applied Meteorology and Climatology.\n\n[2] Jolliffe, I., and D. Stephenson, 2003: Forecast Verification: A Practitioner\u2019s Guide in Atmospheric Science. Wiley, URL https://books.google.cm/books?id=cjS9kK8IWbwC\n\n[3] Wilks, D. S., 2019: Chapter 9 - forecast verification. In Statistical methods in the atmospheric sciences. 4th ed., Elsevier, Cambridge.\n\n[4] Goutham, N., Plougonven, R., Omrani, H., Parey, S., Tankov, P., Tantet, A., Hitchcock, P., & Drobinski, P. (2022). How Skillful Are the European Subseasonal Predictions of Wind Speed and Surface Temperature?, Monthly Weather Review, 150(7), 1621-1637. Retrieved Sep 25, 2022, from https://journals.ametsoc.org/view/journals/mwre/150/7/MWR-D-21-0207.1.xml\n\n[5] Coelho, C. A. S., B. Brown, L. Wilson, M. Mittermaier, and B. Casati, 2019: Forecast verification for S2S timescales. Sub-Seasonal to Seasonal Prediction: The Gap between Weather and Climate Forecasting, A. Robertson, and F. Vitart, Eds., Elsevier, 337\u2013361, Chapter: 16.\n\n[6] Brier, G. W., 1950: Verification of forecasts expressed in terms of probability. 3.\n\n---\n## _Installation:_\n\n```sh\npip install ReliabilityDiagram\n```\n---\n## _Parameters:_\n\n**observation**: numpy.ndarray, shape (nsim,)  \nObservation/truth for nsim events.\n\n**forecast**: numpy.ndarray, shape (nsim,mem_fc)  \nEnsemble forecasts with ensemble size mem_fc for the same nsim events.\n\n**climatology**: numpy.ndarray, shape (nsim,mem_cl)  \nClimatology for the same nsim events with mem_cl the number of years considered.  \n\n**event_lbound**: int or float  \nThe lower bound for the event considered.  \nE.g. 1: If the event considered is lower tercile, then event_lbound value is 0.  \nE.g. 2: If the event considered is upper tercile, then event_lbound value is 2/3.  \n_NOTE_: The value should be in the range of 0 to 1. This value should be lesser than the value of event_ubound.\n\n**event_ubound**: int or float  \nThe upper bound for the event considered.  \nE.g. 1: If the event considered is lower tercile, then event_ubound value is 1/3.  \nE.g. 2: If the event considered is upper tercile, then event_ubound value is 1.  \n_NOTE_: The value should be in the range of 0 to 1. This value should be greater than the value of event_lbound.\n            \n**closed_ends**: str, optional  \nThe bounds (upper and/or lower) to include in the event formulation. Options: 'left', 'right', 'none', 'both'.  \nE.g. 1: If closed_ends = 'left', then the event becomes event_lbound <= event < event_ubound.  \nE.g. 2: If closed_ends = 'both', then the event becomes event_lbound <= event <= event_ubound.  \n_NOTE_: The default value is 'both'. The value is case sensitive.  \n_NOTE_: This option is overwritten when event_lbound=0 or event_ubound=1 in order to include the forecast values that are outside the bounds of the climatology.  \n\n**nbins**: int, optional  \nNumber of bins to stratify the forecasts into. The default is 5.  \n_NOTE_: The bins are of equal width. The number of bins should be lesser than the dimension of observation.\n            \n**weights**: numpy.ndarray, shape (nsim,mem_fc), optional  \nThe weights of the members of the ensemble forecast. It should have the same shape as the forecast data.\n\n---\n## _Method(s):_\n\n**contingency_table()**:  \nThis method computes the contingency table for the defined event.  \n_Returns_: Contingency table having shape (nbins,2) where the first column corresponds to the \"yes\" event and the second column corresponds to the \"no\" event.\n\n**observed_frequency()**:  \n_Returns_: The observed relative frequency for each bin. This is required for plotting the reliability diagram.  \n\n**confidence_intervals()**:  \n_Returns_: This function returns the lower and the upper confidence intervals, respectively, corresponding to the observed frequency. This is required for plotting the reliability diagram.\n\n**forecast_attributes()**:  \nThis method computes the Brier Score along with the reliability and the resolution attributes using the contingency table.  \n_Returns_: Brier Score, Reliability, Resolution.\n\n---\n## _Demonstration:_\n\n```python\nimport ReliabilityDiagram as rd\nimport numpy as np\nimport matplotlib.pyplot as pl\n```\n----\n### Example - 1:\n* Create case data\n###### Input\n```python\nnobs = 5000   # number of events\nnclim = 30    # number of years considered in climatology\nnfc = 51      # ensemble size of the forecasts\n\nclima = np.random.normal(loc=0,scale=10,size=(nobs,nclim))   # climatology (follows the same normal distribution for all events)\nobs = np.random.normal(loc=0,scale=10,size=(nobs))           # observations drawn from the same distribution as climatology\nfcast = np.random.normal(loc=obs+np.random.normal(loc=3,scale=5,size=(nobs)) ,scale=5,size=(nfc,nobs)).T   # forecasts (also generated by a normal distribution \n                                                                                                           # s.t. ensemble mean = observations + bias + noise)\n```\n* Compute contingency table and forecast attributes\n###### Input\n```python\ndata = rd.ReliabilityDiagram(obs,fcast,clima,0,1/4,closed_ends='both',nbins=10)  # example for lower quartile\n```\n\n###### Input\n```python\nc_table = data.contingency_table()    \nprint(c_table)\n```\n###### Output\n\n    array([[ 113., 2955.],\n           [  78.,  268.],\n           [  77.,  147.],\n           [  86.,   94.],\n           [  82.,   76.],\n           [  92.,   42.],\n           [ 109.,   34.],\n           [ 124.,   22.],\n           [ 140.,   16.],\n           [ 429.,   16.]])\n\n###### Input\n```python\nbs, rel, res = data.forecast_attributes()\nprint(bs, rel, res)\n```\n\n###### Output\n\n    0.08890199999999998 0.007429976189885926 0.11377197618988595\n    \n* Plot reliability diagram\n\n###### Input\n```python\n# Compute needed elements for diagram\nyi = data.bins + (data.bins[1]-data.bins[0])/2   # mid-points of the bins\noi = data.observed_frequency()\nci_low, ci_upp = data.confidence_intervals()\nwti = np.sum(c_table,axis=1)/np.sum(c_table) \n\n# Elements for plot\nxd = yd = [0,1]\nq = data.ub - data.lb\nclim_x = clim_y = [q,q]\nsk_line = [q/2,(1-q)/2+q]\n\n# Plot\n# (in this example, the lower quartile is underforecasted)\nfig = pl.figure(figsize=(7,5))\npl.plot(xd,yd,color='black',linestyle=':',linewidth=0.5)\npl.plot(xd,clim_y,color='black',linestyle=':',linewidth=0.5)\npl.plot(clim_x,yd,color='black',linestyle=':',linewidth=0.5)\npl.plot(xd,sk_line,color='black',linestyle='--',linewidth=0.5)\npl.fill_between(xd,xd,sk_line,facecolor='grey',alpha=0.2)\npl.fill_betweenx(yd,yd,clim_x,facecolor='grey',alpha=0.2)\npl.scatter(yi,oi,s=wti*10000,color='deepskyblue',marker='o',alpha=0.5,edgecolors='none')\npl.plot(yi,oi,color='deepskyblue',linestyle='-',linewidth=0.8)\npl.errorbar(yi,oi,yerr=[oi - ci_low, ci_upp - oi],ecolor='deepskyblue',elinewidth=0.8,alpha=0.5)\npl.ylim(0.0,1.0)\npl.xlim(0.0,1.0)\npl.ylabel('Observed frequency \\np(o|y)',fontsize=11)\npl.xlabel('Forecast probability \\ny',fontsize=11)\npl.title(\"Lower quartile \")\npl.tight_layout()\n```\n\n###### Output\n\n![png](example1.png)\n    \n----\n\n### Example - 2:\n\n###### Input\n```python\nfcast2 = np.random.normal(loc=obs+np.random.normal(loc=0,scale=3,size=(nobs)) ,scale=5,size=(nfc,nobs)).T   \n```\n\n###### Input\n```python\ndata_lt = rd.ReliabilityDiagram(obs,fcast2,clima,0,1/3,closed_ends='both',nbins=10)  # example for the lower tercile\ndata_ut = rd.ReliabilityDiagram(obs,fcast2,clima,2/3,1,closed_ends='both',nbins=10)  # example for the upper tercile\n```\n\n* Plot reliability diagram\n\n###### Input\n```python\n# Compute needed elements for diagram\nc_table_lt = data_lt.contingency_table()\nwti_lt = np.sum(c_table_lt,axis=1)/np.sum(c_table_lt)\noi_lt = data_lt.observed_frequency()\nci_low_lt, ci_upp_lt = data_lt.confidence_intervals()\n\nc_table_ut = data_ut.contingency_table()\nwti_ut = np.sum(c_table_ut,axis=1)/np.sum(c_table_ut)\noi_ut = data_ut.observed_frequency()\nci_low_ut, ci_upp_ut = data_ut.confidence_intervals()\n\nyi = data_lt.bins + (data_lt.bins[1]-data_lt.bins[0])/2  # both have the same bins for the forecast probabilities (same nbins)\n\n# Other elements for plot\nxd = yd = [0,1]\nq = 1/3   # tercile\nclim_x = clim_y = [q,q]\nsk_line = [q/2,(1-q)/2+q]\n\n# Plot\n# (in this example, the model is underconfident)\nfig = pl.figure(figsize=(7,5))\npl.plot(xd,yd,color='black',linestyle=':',linewidth=0.5)\npl.plot(xd,clim_y,color='black',linestyle=':',linewidth=0.5)\npl.plot(clim_x,yd,color='black',linestyle=':',linewidth=0.5)\npl.plot(xd,sk_line,color='black',linestyle='--',linewidth=0.5)\npl.fill_between(xd,xd,sk_line,facecolor='grey',alpha=0.2)\npl.fill_betweenx(yd,yd,clim_x,facecolor='grey',alpha=0.2)\npl.scatter(yi,oi_lt,s=wti_lt*10000,color='deepskyblue',marker='o',alpha=0.5,edgecolors='none')\npl.plot(yi,oi_lt,color='deepskyblue',linestyle='-',linewidth=0.8, label=\"lower tercile\")\npl.errorbar(yi,oi_lt,yerr=[oi_lt - ci_low_lt, ci_upp_lt - oi_lt],ecolor='deepskyblue',elinewidth=0.8,alpha=0.5)\npl.scatter(yi,oi_ut,s=wti_ut*10000,color='orange',marker='o',alpha=0.5,edgecolors='none')\npl.plot(yi,oi_ut,color='orange',linestyle='-',linewidth=0.8, label=\"upper tercile\")\npl.errorbar(yi,oi_ut,yerr=[oi_ut - ci_low_ut, ci_upp_ut - oi_ut],ecolor='orange',elinewidth=0.8,alpha=0.5)\npl.ylim(0.0,1.0)\npl.xlim(0.0,1.0)\npl.legend()\npl.ylabel('Observed frequency \\np(o|y)',fontsize=11)\npl.xlabel('Forecast probability \\ny',fontsize=11)\npl.title(\"Terciles\")\npl.tight_layout()\n```\n\n###### Output\n\n![png](example2.png)\n\n\n\n",
    "bugtrack_url": null,
    "license": "Apache License 2.0",
    "summary": "A package which provides the contingency table and all the other ingredients required to plot a reliability diagram. A reliability diagram is a diagnostic plot which helps to understand the joint distribution of forecasts and observations for probabilistic forecasts of a dichotomous event (i.e., yes/no event).",
    "version": "0.0.3",
    "project_urls": {
        "Homepage": "https://github.com/clecoz/ReliabilityDiagram"
    },
    "split_keywords": [
        "reliability table",
        "contingency table",
        "reliability diagram",
        "attributes diagram",
        "reliability",
        "resolution",
        "forecast attributes",
        "brier score",
        "ensemble forecast",
        "forecast",
        "climatology",
        "python"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "2c0df702decce2dda4768652718f31ec0a73b2a4b10291f9f1465e313657dc40",
                "md5": "ffa99918dbeec044f33cec03c5a539e0",
                "sha256": "6e18583f63e24397440bae8320d995207fda9342907d598042afaa1f06e10f2b"
            },
            "downloads": -1,
            "filename": "ReliabilityDiagram-0.0.3-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "ffa99918dbeec044f33cec03c5a539e0",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 12940,
            "upload_time": "2023-06-01T19:08:59",
            "upload_time_iso_8601": "2023-06-01T19:08:59.525622Z",
            "url": "https://files.pythonhosted.org/packages/2c/0d/f702decce2dda4768652718f31ec0a73b2a4b10291f9f1465e313657dc40/ReliabilityDiagram-0.0.3-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "b408847f67a58568b495d4d2eb3c92f2678d3892e9b881b4b051849e78cdd528",
                "md5": "a018932b6ba3f752e0e95e9a960246fb",
                "sha256": "8019955f6dacc816e3d626dd71ea36daf9ee050104b4e52c1d4d05f84b85b005"
            },
            "downloads": -1,
            "filename": "ReliabilityDiagram-0.0.3.tar.gz",
            "has_sig": false,
            "md5_digest": "a018932b6ba3f752e0e95e9a960246fb",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 12124,
            "upload_time": "2023-06-01T19:09:01",
            "upload_time_iso_8601": "2023-06-01T19:09:01.900425Z",
            "url": "https://files.pythonhosted.org/packages/b4/08/847f67a58568b495d4d2eb3c92f2678d3892e9b881b4b051849e78cdd528/ReliabilityDiagram-0.0.3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-06-01 19:09:01",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "clecoz",
    "github_project": "ReliabilityDiagram",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "reliabilitydiagram"
}
        
Elapsed time: 0.07869s