Skip to main content

Python wrapper for the Hector simple climate model

Project description

PyPI Version

PyPI Python Versions

Docs

Launch Binder

JOSS

Zenodo

pyhector is a Python interface for the simple global climate carbon-cycle model Hector.

pyhector makes the simple climate model Hector easily installable and usable from Python and can for example be used in the analysis of mitigation scenarios, in integrated assessment models, complex climate model emulation, and uncertainty analyses.

Hector is written in C++ and developed at the Pacific Northwest National Laboratory. The model description is published in

Hartin, C. A., Patel, P., Schwarber, A., Link, R. P., and Bond-Lamberty, B. P.: A simple object-oriented and open-source model for scientific and policy analyses of the global climate system – Hector v1.0, Geosci. Model Dev., 8, 939-955, doi:10.5194/gmd-8-939-2015, 2015.

See the Hector repository and wiki for further information.

The Python interface pyhector is developed by Sven Willner and Robert Gieseke at the Potsdam Institute for Climate Impact Research.

Pyhector uses pybind11 to wrap Hector’s API. The version of Hector used can be read using Pyhector’s __hector_version__ field.

Installation

Prerequisites

Hector requires Boost, so to install and use pyhector you need to have the filesystem and system modules of Boost version 1.52 or later installed (see also the Hector build instructions).

On Ubuntu/Debian these can be installed by invoking

sudo apt-get install libboost-filesystem-dev libboost-system-dev

On macOS Boost is available through the Homebrew package manager, it might be advisable to use a Homebrew installed Python for installing pyhector:

brew install boost

Windows is (as Hector) in principle supported but not yet tested for pyhector. Pull request with installation notes for Windows are welcome.

Install using pip

You can simply install pyhector from PyPI by invoking

pip install pyhector

Usage

This repository also contains a Jupyter Notebook you can run live and experiment with, courtesy of the Binder project. The notebook can be viewed as a static version using nbviewer.

Basic example

import pyhector

output = pyhector.run(pyhector.rcp26)

Advanced example

import pyhector
from pyhector import rcp26, rcp45, rcp60, rcp85

import matplotlib.pyplot as plt

for rcp in [rcp26, rcp45, rcp60, rcp85]:
    output = pyhector.run(rcp, {"core": {"endDate": 2100}})
    temp = output["temperature.Tgav"]
    # Adjust to 1850 - 1900 reference period
    temp = temp.loc[1850:] - temp.loc[1850:1900].mean()
    temp.plot(label=rcp.name.split("_")[0])
plt.title("Global mean temperature")
plt.ylabel("°C over pre-industrial (1850-1900 mean)")
plt.legend(loc="best")
plt.show()
Temperature Plot of RCP scenarios

Development

For local development you can clone the repository, update the dependencies and install in a virtual environment with pip.

git clone https://github.com/openclimatedata/pyhector.git --recursive
cd pyhector
python3 -m venv venv
./venv/bin/pip install --editable .

To update pyhector and all submodules you can run

git pull --recurse-submodules
git submodule update --init --recursive
./venv/bin/pip install --editable .

Tests can be run locally with

python setup.py test

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyhector-2.3.0.0.tar.gz (1.8 MB view details)

Uploaded Source

File details

Details for the file pyhector-2.3.0.0.tar.gz.

File metadata

  • Download URL: pyhector-2.3.0.0.tar.gz
  • Upload date:
  • Size: 1.8 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.7.3

File hashes

Hashes for pyhector-2.3.0.0.tar.gz
Algorithm Hash digest
SHA256 03fa8ebcfbc211793a0f2a82d3ffa52755b9f3b6cb571a265d66fc91be47c8f3
MD5 90a0f50ac067c169724b3c75c88a511e
BLAKE2b-256 8e3b99839a9f30a769f8fe771b53b69ef13bd8f8df00d0d721127571b41030c6

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page