Skip to main content

High-performance Atmospheric Radiation Package

Project description

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 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 lower-inclusive and upper-exclusive: --wn-range=20,22 with 1 cm^-1 resolution samples 20 and 21, not 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 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 are lower-inclusive and upper-exclusive. 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.

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.

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

pyharp-2.3.5-cp313-cp313-manylinux_2_27_x86_64.whl (31.2 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.27+ x86-64

pyharp-2.3.5-cp313-cp313-macosx_15_0_arm64.whl (4.8 MB view details)

Uploaded CPython 3.13macOS 15.0+ ARM64

pyharp-2.3.5-cp312-cp312-manylinux_2_27_x86_64.whl (31.2 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.27+ x86-64

pyharp-2.3.5-cp312-cp312-macosx_15_0_arm64.whl (4.8 MB view details)

Uploaded CPython 3.12macOS 15.0+ ARM64

pyharp-2.3.5-cp311-cp311-manylinux_2_27_x86_64.whl (31.2 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.27+ x86-64

pyharp-2.3.5-cp311-cp311-macosx_15_0_arm64.whl (4.8 MB view details)

Uploaded CPython 3.11macOS 15.0+ ARM64

pyharp-2.3.5-cp310-cp310-manylinux_2_27_x86_64.whl (31.1 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.27+ x86-64

pyharp-2.3.5-cp310-cp310-macosx_15_0_arm64.whl (4.8 MB view details)

Uploaded CPython 3.10macOS 15.0+ ARM64

File details

Details for the file pyharp-2.3.5-cp313-cp313-manylinux_2_27_x86_64.whl.

File metadata

File hashes

Hashes for pyharp-2.3.5-cp313-cp313-manylinux_2_27_x86_64.whl
Algorithm Hash digest
SHA256 fced38c4deecdf4a573d5a3729520178eced338c5324daf92c3f24a149f50b4f
MD5 aef0c70609c1d00be5a3a08853f25ff4
BLAKE2b-256 e4e5849222a587b5aec82a3eedd77d56f4a1df6bf10a81a9328b739f1fafe3dc

See more details on using hashes here.

File details

Details for the file pyharp-2.3.5-cp313-cp313-macosx_15_0_arm64.whl.

File metadata

File hashes

Hashes for pyharp-2.3.5-cp313-cp313-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 03a3bf4c631c675aa025c03fa0578622fc83191c3f16993ec9ad85cbfe4495f4
MD5 e54efda7ba97338adaa2dcf1812ce64d
BLAKE2b-256 86da8c2cc2a21326364eb18faba8ab4f23362475f969339e1e5efd26c22fe5d0

See more details on using hashes here.

File details

Details for the file pyharp-2.3.5-cp312-cp312-manylinux_2_27_x86_64.whl.

File metadata

File hashes

Hashes for pyharp-2.3.5-cp312-cp312-manylinux_2_27_x86_64.whl
Algorithm Hash digest
SHA256 945f6d1683f663a963012d5123162e65b54c07f5e3b8c6ccf3290305b1567ece
MD5 c8efceab5c981a136673308081909d82
BLAKE2b-256 5c729b03d10b9d92f95f2d6aeb292c28a5914d6b49dba417e9a9964fd7e68d3d

See more details on using hashes here.

File details

Details for the file pyharp-2.3.5-cp312-cp312-macosx_15_0_arm64.whl.

File metadata

File hashes

Hashes for pyharp-2.3.5-cp312-cp312-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 091a47038f479b8f2f96e4d0d2024fd3abdf0859f6075baea2bfdfdab453b685
MD5 592ed19fcf620fde8a702a8e1a7a5842
BLAKE2b-256 3183a456fedaed5ed087f06befce2defde5b0365f18e705643bfb230f9b2d0ce

See more details on using hashes here.

File details

Details for the file pyharp-2.3.5-cp311-cp311-manylinux_2_27_x86_64.whl.

File metadata

File hashes

Hashes for pyharp-2.3.5-cp311-cp311-manylinux_2_27_x86_64.whl
Algorithm Hash digest
SHA256 a8e00d5cb6acaefee834a799de4fa5e7c5443e7443bbd4b15be77ff8b689466e
MD5 ef17ecbd05110e3e9953e0c4d6e4537f
BLAKE2b-256 a65d0a6dd9ecef19bb7c6a8147366fc4bb80186387c5c633e77d2c2b7424a562

See more details on using hashes here.

File details

Details for the file pyharp-2.3.5-cp311-cp311-macosx_15_0_arm64.whl.

File metadata

File hashes

Hashes for pyharp-2.3.5-cp311-cp311-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 803bdbc6a296b8ed5a0333ecaedc8d1b1204ee1b60f823bb90ccdc7fc2acefcc
MD5 f682955ed0f59985747859df8532fc37
BLAKE2b-256 7e82f71c0bb1a3c35b4127e77b154ba39493c2518aae0256f97fdc5340c391d4

See more details on using hashes here.

File details

Details for the file pyharp-2.3.5-cp310-cp310-manylinux_2_27_x86_64.whl.

File metadata

File hashes

Hashes for pyharp-2.3.5-cp310-cp310-manylinux_2_27_x86_64.whl
Algorithm Hash digest
SHA256 16d29e6017c4eb7c1a4d9327c3238e17247a7e9cf522bc206df4dd35623ad9b7
MD5 44e980ddea96f9ccd52aedc2771f7f3e
BLAKE2b-256 54e5bc8f5146b6a6b3e5055e7ef0374c2302cb04d9a76d56e6367fc3494ab5b0

See more details on using hashes here.

File details

Details for the file pyharp-2.3.5-cp310-cp310-macosx_15_0_arm64.whl.

File metadata

File hashes

Hashes for pyharp-2.3.5-cp310-cp310-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 e82ea02c18db7eb48f0998c24a59a7163482184d7e0906a79e17406727e7d47d
MD5 c9a97cc9ed322542dfc56ff1c9a9e9bd
BLAKE2b-256 ef1432934c72dd306ff03ba1a28aaf5bf6b314d3f713085d2293a4a9aea4700b

See more details on using hashes here.

Supported by

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