Skip to content

Using verif as a module

Thomas Nipen edited this page Jan 11, 2017 · 1 revision

verif can also be used as a module within python.

Using metrics

Here is an example computing a simple deterministic score, such as mean absolute error:

import numpy as np
import verif.data
import verif.input
import verif.interval
import verif.metric

# Set up random forecasts and observations
obs = np.random.randn(100,20,5)
fcst = obs + np.random.randn(100,20,5)*0.2 + 0.3

metric = verif.metric.Mae()
score = metric.compute_from_obs_fcst(obs, fcst)
print score

This will work for any metric that is a subclass of verif.metric.ObsFcstBased. The next example computes the score for a metric based on a 2x2 contingency table, and will work for any metric that is a subclass of verif.metric.Contingency. This example computes the Equitable Threat Score for a set of observations and forecasts exceeding 2.0:

metric = verif.metric.Ets()
# Set up the interval [2.0, infinity]
interval = verif.interval.Interval(2.0, np.inf, True, True)

score = metric.compute_from_obs_fcst(obs, fcst, interval)
print score

Using plots

import numpy as np
import verif.data
import verif.input
import verif.metric
import verif.variable

# Set up random forecasts and observations
obs = np.random.randn(100,20,5)
fcst = obs + np.random.randn(100,20,5)*0.2 + 0.3
variable = verif.variable.Variable("Temperature", "Degrees C")
input = verif.input.Fake(obs, fcst, variable=variable)
data = verif.data.Data(input)

# Create output
metric = verif.metric.Ets()
output = verif.output.Standard(metric)
output.axis = verif.axis.Threshold()
output.thresholds = range(-5,6)
output.plot(data)
Clone this wiki locally