Skip to content

Commit

Permalink
Initial add
Browse files Browse the repository at this point in the history
  • Loading branch information
tnipen committed Aug 9, 2015
0 parents commit 7017d0f
Show file tree
Hide file tree
Showing 22 changed files with 4,944 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
*.pyc
dist
build
*.egg-info
*~
.coverage
cover
.*.swp
95 changes: 95 additions & 0 deletions .pbuilderrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
# Based on https://wiki.ubuntu.com/PbuilderHowto (2015-04-21, last edited by osamu)
# License: http://creativecommons.org/licenses/by-sa/3.0/
# Support for ccache based on http://failshell.io/devel/pbuilder-and-ccache-howto/

# Codenames for Debian suites according to their alias. Update these when
# needed.
UNSTABLE_CODENAME="sid"
TESTING_CODENAME="jessie"
STABLE_CODENAME="wheezy"
STABLE_BACKPORTS_SUITE="$STABLE_CODENAME-backports"

# List of Debian suites.
DEBIAN_SUITES=($UNSTABLE_CODENAME $TESTING_CODENAME $STABLE_CODENAME
"unstable" "testing" "stable")

# List of Ubuntu suites. Update these when needed.
UBUNTU_SUITES=("trusty" "precise" "lucid")

# Mirrors to use. Update these to your preferred mirror.
DEBIAN_MIRROR="ftp.us.debian.org"
UBUNTU_MIRROR="mirrors.kernel.org"

# Optionally use the changelog of a package to determine the suite to use if
# none set.
if [ -z "${DIST}" ] && [ -r "debian/changelog" ]; then
DIST=$(dpkg-parsechangelog | awk '/^Distribution: / {print $2}')
DIST="${DIST%%-*}"
# Use the unstable suite for certain suite values.
if $(echo "experimental UNRELEASED" | grep -q $DIST); then
DIST="$UNSTABLE_CODENAME"
fi
# Use the stable suite for stable-backports.
if $(echo "$STABLE_BACKPORTS_SUITE" | grep -q $DIST); then
DIST="$STABLE_CODENAME"
fi
fi

# Optionally set a default distribution if none is used. Note that you can set
# your own default (i.e. ${DIST:="unstable"}).
: ${DIST:="$(lsb_release --short --codename)"}

# Optionally change Debian release states in $DIST to their names.
case "$DIST" in
unstable)
DIST="$UNSTABLE_CODENAME"
;;
testing)
DIST="$TESTING_CODENAME"
;;
stable)
DIST="$STABLE_CODENAME"
;;
esac

# Optionally set the architecture to the host architecture if none set. Note
# that you can set your own default (i.e. ${ARCH:="i386"}).
: ${ARCH:="$(dpkg --print-architecture)"}

NAME="$DIST"
if [ -n "${ARCH}" ]; then
NAME="$NAME-$ARCH"
DEBOOTSTRAPOPTS=("--arch" "$ARCH" "${DEBOOTSTRAPOPTS[@]}")
fi
BASETGZ="/var/cache/pbuilder/$NAME-base.tgz"
# Optionally, set BASEPATH (and not BASETGZ) if using cowbuilder
# BASEPATH="/var/cache/pbuilder/$NAME/base.cow/"
DISTRIBUTION="$DIST"
BUILDRESULT="/var/cache/pbuilder/$NAME/result/"
APTCACHE="/var/cache/pbuilder/$NAME/aptcache/"
BUILDPLACE="/var/cache/pbuilder/build/"

if $(echo ${DEBIAN_SUITES[@]} | grep -q $DIST); then
# Debian configuration
MIRRORSITE="http://$DEBIAN_MIRROR/debian/"
COMPONENTS="main contrib non-free"
DEBOOTSTRAPOPTS=("${DEBOOTSTRAPOPTS[@]}" "--keyring=/usr/share/keyrings/debian-archive-keyring.gpg")

elif $(echo ${UBUNTU_SUITES[@]} | grep -q $DIST); then
# Ubuntu configuration
MIRRORSITE="http://$UBUNTU_MIRROR/ubuntu/"
COMPONENTS="main restricted universe multiverse"
DEBOOTSTRAPOPTS=("${DEBOOTSTRAPOPTS[@]}" "--keyring=/usr/share/keyrings/ubuntu-archive-keyring.gpg")
else
echo "Unknown distribution: $DIST"
exit 1
fi

# ccache
export CCACHE_DIR="/var/cache/pbuilder/ccache/$DIST"
export PATH="/usr/lib/ccache:${PATH}"
mkdir -p "${CCACHE_DIR}"
chown -R 1234:root "${CCACHE_DIR}"
chmod 755 "${CCACHE_DIR}"
EXTRAPACKAGES=ccache
BINDMOUNTS="${CCACHE_DIR}"
23 changes: 23 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
language: python
python:
- "2.7_with_system_site_packages"

install:
- sudo apt-get install libblas-dev
- sudo apt-get install liblapack-dev
- sudo apt-get install gfortran
- sudo apt-get install -qq python-numpy python-scipy python-matplotlib
- pip install coveralls
- sudo python setup.py build
- sudo python setup.py install

script:
- nosetests --with-coverage --cover-erase --cover-package=verif

after_success:
- coveralls

env:
- DIST=lucid

os: linux
24 changes: 24 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
Copyright (c) 2015 Weather Forecast Research Team
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the Weather Forecast Research Team nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE WEATHER FORECAST RESEARCH TEAM BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
129 changes: 129 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
Forecast verification software
==============================

.. image:: https://travis-ci.org/tnipen/verif.svg?branch=master
:target: https://travis-ci.org/tnipen/verif
.. image:: https://coveralls.io/repos/tnipen/verif/badge.svg?branch=master&service=github
:target: https://coveralls.io/github/tnipen/verif?branch=master

This software computes verification statistics for weather forecasts at point locations. It can be used to
document the quality of one forecasting system but can also be used to compare different weather models and/or
different post-processing methods.

The program works by parsing NetCDF files with observations and forecasts in a specific format (see "Input
files" below).

verif is a command-line tool that can therefore be used to automatically create verification figures.

Developed by Thomas Nipen, David Siuta, and Tim Chui.

.. image:: image.jpg
:alt: Example plots
:width: 400
:align: center

Features
--------

* Deterministic metrics such as MAE, bias, RMSE
* Threshold-based metrics such as the equitable threat score (ETS)
* Probabilistic metrics such as brier score, PIT-histogram, reliability diagrams
* Plot statistics as a function of date, forecast horizon, station elevation, latitude, or longitude
* Show statistics on maps
* Export to text
* Options to adjust font sizes, label positions, tick marks, legends, etc
* Anomaly statistics (relative to a baseline like climatology)
* Output to png, jeg, eps, etc and specify image dimensions and DPI.

For a full list run verif without arguments.

Requirements
------------

* Python
* matplotlib
* numpy
* scipy

Installation Instructions
-------------------------
To install, just execute:

.. code-block:: bash
python setup.py install
verif will then be installed /usr/local/share/python/ or where ever your python modules are
installed (Look for "Installing verif script to <some directory>" when installing). Be sure to add this directory
to your $PATH environment variable.

Example
-------
.. code-block:: bash
Fake data for testing the program is found in ./examples/. Use the following command to test:

.. code-block:: bash
verif examples/T_raw.nc examples/T_kf.nc -m mae
Text-based input
----------------
Two data formats are supported. A simple text format for deterministic forecasts has the following format:

.. code-block:: bash
date offset lat lon elev obs fcst
20150101 0 49.2 -122.1 92 3.4 2.1
20150101 1 49.2 -122.1 92 4.7 4.2
20150101 0 50.3 -120.3 150 0.2 -1.2
The first line must describe the columns. The following attributes are recognized: date (in YYYYMMDD), offset (in hours), lat
(in degrees), lon (in degrees), obs (observations), fcst (deterministic forecast). obs and fcst are required and a value of 0
is used for any missing column. The columns can be in any order.

NetCDF input
------------
For more advanced usage, the files must be in NetCDF and have dimensions and attributes as described below in the
example file. The format is still being decided but will be based on NetCDF/CF standard.

.. code-block:: bash
netcdf format {
dimensions :
date = UNLIMITED;
offset = 48;
station = 10;
ensemble = 21;
threshold = 11;
quantile = 11;
variables:
int id(station);
int offset(offset);
int date(date);
float threshold(threshold);
float quantile(quantile);
float lat(station);
float lon(station);
float elev(station);
float obs(date, offset, station); // Observations
float ens(date, offset, ensemble, station); // Ensemble forecast
float fcst(date, offset, station); // Deterministic forecast
float cdf(date, offset, threshold, station); // Accumulated prob at threshold
float pdf(date, offset, threshold, station); // Pdf at threshold
float x(date, offset, quantile, station); // Threshold corresponding to quantile
float pit(date, offset, station); // CDF for threshold=observation
global attributes:
: name = "raw"; // Used as configuration name
: long_name = "Temperature"; // Used to label plots
: standard_name = "air_temperature_2m";
: Units = "^oC";
: Conventions = "verif_1.0.0";
}
Copyright and license
---------------------

Copyright © 2015 UBC Weather Forecast Research Team. verif is licensed under the 3-clause BSD license. See LICENSE
file.
Binary file added examples/T_kf_0.nc
Binary file not shown.
Binary file added examples/T_raw_0.nc
Binary file not shown.
6 changes: 6 additions & 0 deletions examples/example.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
date offset lat lon elev obs fcst
20120101 0 1 1 1 12 13
20120101 1 0 0 1 13 14
20120101 22 0 0 2 5 4
20120101 0 1 1 0 10 11
20120101 3 2 2 1 2 3
Binary file added image.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
coverage:
#nosetests --with-coverage --cover-erase --cover-package=verif --cover-html --cover-branches
nosetests --with-coverage --cover-erase --cover-package=verif --cover-html

test:
nosetests
4 changes: 4 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
scipy
numpy
matplotlib
coveralls
Loading

0 comments on commit 7017d0f

Please sign in to comment.