Skip to main content

Pyharp: Python-first High-performance Atmosphere Radiation Package

build License

Pyharp is the one-stop tool for calculating the radiation flux of planetary atmospheres, from terrestrial to giant planets. Detailed documentation and examples are available at https://pyharp.readthedocs.io.

Installation

Pyharp can be installed via pip:

pip install pyharp

We support Linux and Mac operation systems with Python version 3.10+.


Spectroscopy workflow

Pyharp also includes pyharp.spectra, a pure-Python spectroscopy workflow for HITRAN line data, HITRAN CIA data, single-state absorption spectra, transmittance products, diagnostic plots, and gas-mixture overview figures. The former standalone spectra library now lives under the pyharp.spectra namespace.

The main library entry points are available from pyharp.spectra:

from pathlib import Path

from pyharp.spectra import (
    AbsorptionSpectrum,
    SpectroscopyConfig,
    SpectralBandConfig,
    compute_absorption_spectrum,
)

band = SpectralBandConfig(
    name="single_state",
    wavenumber_min_cm1=20.0,
    wavenumber_max_cm1=2500.0,
    resolution_cm1=1.0,
)
config = SpectroscopyConfig(
    output_path=Path("output/h2o_absorption_300K_1bar.nc"),
    hitran_cache_dir=Path("hitran"),
    species_name="H2O",
)
spectrum: AbsorptionSpectrum = compute_absorption_spectrum(
    config=config,
    band=band,
    temperature_k=300.0,
    pressure_pa=1.0e5,
)

SpectroscopyConfig.hitran_cache_dir stores downloaded HITRAN line and CIA files. SpectroscopyConfig.output_path controls where NetCDF products are written by CLI helpers and is also used to create parent output directories.

H2O continuum calculations use the MT_CKD_H2O coefficient file at external/MT_CKD_H2O/data/absco-ref_wv-mt-ckd.nc relative to the Pyharp repository root. It is tracked as a Git submodule. Clone Pyharp with submodules to fetch it immediately:

git clone --recurse-submodules https://github.com/chengcli/pyharp

If you already cloned Pyharp, initialize the submodule from the repository root:

git submodule update --init --recursive external/MT_CKD_H2O

If you are using command line argument outside of pyharp, clone MT_CKD directly:

mkdir -p external && cd external && git clone https://github.com/AER-RC/MT_CKD_H2O

The pyharp-dump CLI writes NetCDF spectroscopy products for single species, CIA pairs, and gas mixtures:

pyharp-dump xsection --species H2O --temperature-k 300 --pressure-bar 1 --wn-range=20,2500
pyharp-dump xsection --pair H2-H2 --temperature-k 300 --pressure-bar 1 --wn-range=20,10000
pyharp-dump xsection --pair H2-H2 --cia-model xiz --h2-state eq --temperature-k 300 --pressure-bar 1 --wn-range=20,10000
pyharp-dump transmission --species H2O --path-length-km 1 --wn-range=20,2500

Use repeated --wn-range=min,max values to write one NetCDF file per band. When you also pass --output, pyharp appends _<wnmin>_<wnmax> to the requested stem for each generated file. Use --output-dir to place auto-generated filenames under a different directory without overriding the filename pattern. For state-grid dumps, the auto-generated state section is written as <min_temp>_<max_temp>K_<min_pres>_<max_pres>bar, where temperature bounds come from the full (temperature + del_temperature) grid. Use --temperature-k and --pressure-bar as paired comma-separated vectors, for example --temperature-k 300,400 --pressure-bar 1,10. Add --del-temperature-k to evaluate temperature anomalies around each base state, for example --del-temperature-k -10,-5,0,5,10. Dump outputs are written on (del_temperature, pressure, wavenumber), include a temperature(pressure) variable for the base temperatures, store the pressure coordinate in Pa, and still retain degenerate del_temperature and pressure dimensions when only one state is requested. Across pyharp.spectra, wavenumber ranges are interpreted as inclusive at both ends: --wn-range=20,22 with 1 cm^-1 resolution samples 20, 21, and 22. See the pyharp-dump CLI documentation for the full command reference, output naming conventions, and NetCDF schema.

Plotting diagnostics are available from one entry point, pyharp-plot. It provides CIA binary coefficient, molecular cross-section, attenuation, transmission, and overview plot subcommands:

pyharp-plot binary --pair H2-H2 --temperature-k 300 --wn-range=20,10000
pyharp-plot binary --pair H2-H2 --cia-model 2018 --h2-state eq --temperature-k 300 --wn-range=20,10000
pyharp-plot binary --pair H2-H2 --cia-model xiz --h2-state eq --temperature-k 300 --wn-range=20,10000
pyharp-plot xsection --species CO2 --temperature-k 300 --pressure-bar 1 --wn-range=20,2500
pyharp-plot attenuation --species CO2 --temperature-k 300 --pressure-bar 1 --wn-range=20,2500
pyharp-plot transmission --composition H2O:0.1,H2:0.9 --temperature-k 300 --pressure-bar 1 --path-length-km 1 --wn-range=25,2500
pyharp-plot overview --species H2O CO2 --temperature-k 300 --pressure-bar 1 --wn-range=20,2500 --wn-range=2500,10000

Use --pair for CIA pairs, --species for molecules, and --composition for gas mixtures such as H2O:0.1,H2:0.9. All plot commands accept --wn-range=min,max; overview accepts multiple --wn-range values for multi-page PDFs. These ranges include both endpoints, so adjacent repeated ranges such as 20,2500 and 2500,10000 both include 2500. Use --output to choose the output path. Without --output, plots are written under --output-dir (default output/) with names derived from the target, plot type, temperature, pressure, and wavenumber range. For plot commands that use pressure, --temperature-k and --pressure-bar also accept matched comma-separated vectors such as --temperature-k 300,400 --pressure-bar 1,10. pyharp-plot then runs one plot per (T,P) pair in parallel. For xsection, attenuation, and transmission, one explicit --output path reused across multiple state pairs is expanded with _<temperature>K_<pressure>bar suffixes. For overview, all state/range pages are combined into one PDF.

Molecular line calculations also accept --broadening-composition BROADENER:FRACTION,..., for example air:0.8,self:0.2 or H2:0.85,He:0.15. If a requested foreign broadener is unavailable in the HITRAN table for the active absorber, Pyharp falls back to air for that fraction.

CIA pair workflows now derive the backend directly from --cia-model:

  • --cia-model auto keeps the built-in HITRAN default filename mapping under hitran/
  • --cia-model 2011 resolves H2-H2_2011.cia or H2-He_2011.cia from HITRAN
  • --cia-model 2018 --h2-state eq|nm resolves H2-H2_eq_2018.cia or H2-H2_nm_2018.cia from HITRAN
  • --cia-model xiz|orton --h2-state eq|nm selects one of the legacy H2-H2 or H2-He tables under orton_xiz_cia/

If a requested HITRAN pair/model/state combination does not have a configured file, pyharp raises an error rather than silently falling back to another CIA dataset. HITRAN 2011 does not distinguish eq vs nm, while xiz and orton require an explicit H2 spin-state choice through --h2-state.

See the pyharp-plot CLI documentation for command-specific options and more examples.

Supported built-in HITRAN line species are CH4, CO2, H2, H2O, H2S, N2, and NH3. Built-in CIA pair resolution includes the self pairs for these species where HITRAN CIA data is configured, plus CO2-CH4, CO2-H2, H2-He, and N2-CH4.

pyharp.spectra does not provide a fixed reference-column radiative-transfer experiment. Use the core Pyharp radiative-transfer APIs for column RT calculations, and use pyharp.spectra for spectroscopy inputs, diagnostics, single-state products, and overview plots.


Development

If you want to further develop Pyharp, you will need to install it locally, which allows you to modify the source code and test. Open a Linux or Mac terminal and clone this repo using the following command:

git clone https://github.com/chengcli/pyharp

This will copy all source files into your local computer. You will need to install a few system libraries before installing Pyharp. All following instructions are executed under the pyharp/ directory.

System required for building locally

  • Python 3.10+
  • Linux or macOS
  • netCDF
  • python virtual environment (venv)

MacOS installation

brew install netcdf

RedHat installation

sudo yum install netcdf

Ubuntu installation

sudo apt-get install libnetcdf-dev

Build C++ library

After you completed the installation steps, you can build the pyharp library. We will build the package in-place, meaning that the build (binary files) are located under pyharp/build/bin. To do so, make a new directory named build

mkdir build

All build files will be generated and placed under this directory. It is completely safe to delete the whole directory if you want another build. cd to build and cmake

cd build
cmake ..

This command tells the cmake command to look for CMakeFiles.txt in the parent directory, and start configuring the compile environment. Then compile the code by

make -j4

This comman will use 4 cores to compile the code in parallel. Once complete, all executable files will be placed in build/bin.

Build python package locally (dev mode)

The python library can be installed by running the following command in the root directory:

pip install -e .

Test the installation

To test the installation, import pyharp in a python shell:

import pyharp

The build is successful if you do not see any error messages.


Contributing

Contributions are welcome! Please open an issue or PR if you’d like to:

  • Find a bug
  • Suggest new functions
  • Add examples
  • Improve documentation
  • Expand test coverage

Contact

Maintained by @chengcli — feel free to reach out with ideas, feedback, or collaboration proposals.

Metadata

Release files for pyharp 2.7.6

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distributions (wheels)

Table of built distributions (wheels) for pyharp 2.7.6
File
pyharp-2.7.6-cp313-cp313-manylinux_2_27_x86_64.whl CPython 3.13 CPython 3.13 Linux glibc 2.27+ x86-64 Details
pyharp-2.7.6-cp313-cp313-macosx_15_0_arm64.whl CPython 3.13 CPython 3.13 macOS 15.0+ ARM64 Details
pyharp-2.7.6-cp312-cp312-manylinux_2_27_x86_64.whl CPython 3.12 CPython 3.12 Linux glibc 2.27+ x86-64 Details
pyharp-2.7.6-cp312-cp312-macosx_15_0_arm64.whl CPython 3.12 CPython 3.12 macOS 15.0+ ARM64 Details
pyharp-2.7.6-cp311-cp311-manylinux_2_27_x86_64.whl CPython 3.11 CPython 3.11 Linux glibc 2.27+ x86-64 Details
pyharp-2.7.6-cp311-cp311-macosx_15_0_arm64.whl CPython 3.11 CPython 3.11 macOS 15.0+ ARM64 Details
pyharp-2.7.6-cp310-cp310-manylinux_2_27_x86_64.whl CPython 3.10 CPython 3.10 Linux glibc 2.27+ x86-64 Details
pyharp-2.7.6-cp310-cp310-macosx_15_0_arm64.whl CPython 3.10 CPython 3.10 macOS 15.0+ ARM64 Details

Total release size: 163.1 MB

Release files / pyharp-2.7.6-cp313-cp313-manylinux_2_27_x86_64.whl

Download URL pyharp-2.7.6-cp313-cp313-manylinux_2_27_x86_64.whl
Size 35.6 MB
Tags CPython 3.13 Linux glibc 2.27+ x86-64
SHA-256 checksum
How to use checksums
61f09e36c4e67f3632a49662e012607a0bf9e30cd71e9577164fe5a31f47df26
BLAKE2b-256 checksum
How to use checksums
479bab7aadba81003b0478db79ad412367acbf77c7625f66472113584c18bfac
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / pyharp-2.7.6-cp313-cp313-macosx_15_0_arm64.whl

Download URL pyharp-2.7.6-cp313-cp313-macosx_15_0_arm64.whl
Size 5.2 MB
Tags CPython 3.13 macOS 15.0+ ARM64
SHA-256 checksum
How to use checksums
82972d19211e0c43fcf8bca69a53ef6f6ca2895f81f41971af5e76ade2bed5f8
BLAKE2b-256 checksum
How to use checksums
e0041497d5528227de4d9b89d74da0d68d8927019ef85673cd3cb712f9aebae6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / pyharp-2.7.6-cp312-cp312-manylinux_2_27_x86_64.whl

Download URL pyharp-2.7.6-cp312-cp312-manylinux_2_27_x86_64.whl
Size 35.6 MB
Tags CPython 3.12 Linux glibc 2.27+ x86-64
SHA-256 checksum
How to use checksums
736f746624369878aff4b43ef92887aeb26353e7efc02a0feb70005559dc9cb9
BLAKE2b-256 checksum
How to use checksums
1b1071e958ec5384459e5bf1731cd921c126ccc3810f82ee6962ded5be5c1c0a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / pyharp-2.7.6-cp312-cp312-macosx_15_0_arm64.whl

Download URL pyharp-2.7.6-cp312-cp312-macosx_15_0_arm64.whl
Size 5.2 MB
Tags CPython 3.12 macOS 15.0+ ARM64
SHA-256 checksum
How to use checksums
6c7475c20b702c5955a2b57cb3a7a6171aaf4dd0d0d7ac2d72f4dab825943968
BLAKE2b-256 checksum
How to use checksums
24ce3bf3e1cd201c12777a83f6db181c8f37b05e537441a58480fe4cf3363361
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / pyharp-2.7.6-cp311-cp311-manylinux_2_27_x86_64.whl

Download URL pyharp-2.7.6-cp311-cp311-manylinux_2_27_x86_64.whl
Size 35.5 MB
Tags CPython 3.11 Linux glibc 2.27+ x86-64
SHA-256 checksum
How to use checksums
a52733437b41b7ad9e7188cdcf6a09290bd92031872f9252685d731dbb9e7534
BLAKE2b-256 checksum
How to use checksums
6c1190e00bdf2b568d46f4ebb1d9911deb19343e11da4761a37aa0a1707f0304
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / pyharp-2.7.6-cp311-cp311-macosx_15_0_arm64.whl

Download URL pyharp-2.7.6-cp311-cp311-macosx_15_0_arm64.whl
Size 5.2 MB
Tags CPython 3.11 macOS 15.0+ ARM64
SHA-256 checksum
How to use checksums
427af705e3882e31d2e60d07a1c4a6da8bafffdb6ad28fcbb50d267835821004
BLAKE2b-256 checksum
How to use checksums
7adecc8941e021b2286b9afe1a3f6578c7228b86d6012bb12893ecda0f6e982c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / pyharp-2.7.6-cp310-cp310-manylinux_2_27_x86_64.whl

Download URL pyharp-2.7.6-cp310-cp310-manylinux_2_27_x86_64.whl
Size 35.4 MB
Tags CPython 3.10 Linux glibc 2.27+ x86-64
SHA-256 checksum
How to use checksums
85a10cc4ae9726a03243f2b38cee52d189bdb68fbb65127755d752e70659931c
BLAKE2b-256 checksum
How to use checksums
15996b431c191c09615c3473ebded285f9992fec160b17ed6b5cdcfe08c043cf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / pyharp-2.7.6-cp310-cp310-macosx_15_0_arm64.whl

Download URL pyharp-2.7.6-cp310-cp310-macosx_15_0_arm64.whl
Size 5.2 MB
Tags CPython 3.10 macOS 15.0+ ARM64
SHA-256 checksum
How to use checksums
ec88118916316e30702471629bad35e162b209dc722fc17a5c53d09418d5c7be
BLAKE2b-256 checksum
How to use checksums
620394b906373af4a37b4e7566f8b5eea1e6936d3ae4ebe3d69087b257e5db00
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release history Release notifications | RSS feed

This release

2.7.6 This release

8 release files

2.6.5

8 release files

2.6.1

8 release files

2.5.8

8 release files

2.5.7

8 release files

2.5.4

8 release files

2.5.2

8 release files

2.5.0

8 release files

2.4.8

8 release files

2.4.6

8 release files

2.4.5

8 release files

2.4.4

8 release files

2.4.0

8 release files

2.3.9

8 release files

2.3.8

8 release files

2.3.7

8 release files

2.3.6

4 release files

2.3.5

8 release files

2.3.4

8 release files

2.3.2

4 release files

2.3.1

8 release files

2.3.0

8 release files

2.2.0

8 release files

2.0.5

8 release files

2.0.4

8 release files

1.9.5

5 release files

1.9.0

10 release files

1.8.8

10 release files

1.8.7

10 release files

1.8.6

10 release files

1.8.1

10 release files

1.7.7

10 release files

1.7.6

10 release files

1.7.4

10 release files

1.7.2

10 release files

1.7.1

10 release files

1.7.0

5 release files

1.6.8

10 release files

1.6.7

10 release files

1.6.4

10 release files

1.6.3

10 release files

1.6.2

10 release files

1.6.1

10 release files

1.5.2

10 release files

1.5.1

10 release files

1.5.0

5 release files

1.4.3

5 release files

1.4.2

10 release files

1.3.14

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page