Skip to main content

pytrunc


pypi conda-forge github downloads

tests docs license pixi ruff

A python package for the truncation of scattering phase functions in radiative transfer applications

Mustapha Moulana
HYGEOS website
Documentation


Features

  • Analytic scattering phase functions: Henyey-Greenstein, two-term Henyey-Greenstein and Fournier-Forand
  • Phase function Legendre moments, computed numerically for an arbitrary phase function or analytically for the Henyey-Greenstein family
  • Truncation of the forward peak with the delta-m method of Wiscombe (1977) and the geometrical truncation (GT) method of Iwabuchi and Suzuki (2009)
  • Truncation results returned as xarray datasets, gathering the approximated and truncated phase functions, the truncation factor, the truncation angle and the exact and truncated moments
  • Numerical utilities: Legendre polynomials and their derivatives, Bessel functions of the first kind, and a Lobatto quadrature with cached abscissas and weights, for accurate integration of strongly peaked phase functions on a limited number of angles

Installation

The installation can be performed using one of the following commands:

$ conda install -c conda-forge pytrunc
$ pip install pytrunc
$ pip install git+https://github.com/hygeos/pytrunc.git

Quickstart

Truncate a Henyey-Greenstein phase function with the delta-m method and get the result as an xarray dataset:

>>> import numpy as np
>>> from pytrunc.phase import henyey_greenstein
>>> from pytrunc.truncation import delta_m_phase_approx
>>> theta = np.linspace(0., 180., 1801)  # scattering angles in degrees
>>> phase = henyey_greenstein(theta, g=0.85, normalize=2)
>>> ds = delta_m_phase_approx(phase, theta, m_max=20)
>>> ds['f'].values
array(0.03874944)

The same phase function truncated with the GT method, using the last moment as the truncation fraction:

>>> from pytrunc.phase import calc_moments
>>> from pytrunc.truncation import gt_phase_approx
>>> chi = calc_moments(phase, theta, m_max=20, normalize=True)
>>> ds = gt_phase_approx(phase, theta, trunc_frac=chi[20])
>>> ds['f'].values, ds['theta_f'].values
(array(0.03874944), array(7.1))

Examples

Truncation of a realistic water cloud phase function (Mie calculation at 500 nm, effective radius of 8 µm) with the delta-m method:

Show figure
>>> ...
>>> from pytrunc.truncation import delta_m_phase_approx
>>> m_max = 20  # stream / term number
>>> # phase_exact -> P11 of a liquid cloud at 500nm, effective radius of 8 micrometers
>>> # theta -> the phase angles in degrees
>>> ds = delta_m_phase_approx(phase_exact, theta, m_max)  # return an xarray dataset
>>> ...

The same phase function truncated with the geometrical truncation (GT) method:

Show figure
>>> ...
>>> from pytrunc.truncation import gt_phase_approx
>>> from pytrunc.phase import calc_moments
>>> m_max = 20  # stream / term number
>>> # phase_exact -> P11 of a liquid cloud at 500nm, effective radius of 8 micrometers
>>> # theta -> the phase angles in degrees
>>> chi = calc_moments(phase_exact, theta, m_max=m_max, normalize=True)  # the phase moments
>>> f = chi[m_max]  # the truncation factor
>>> ds = gt_phase_approx(phase_exact, theta, f)  # return an xarray dataset
>>> ...

Documentation

The complete documentation is available at hygeos.github.io/pytrunc. It includes example notebooks (truncation of a realistic water cloud phase function, Lobatto quadrature, and the validation against Iwabuchi and Suzuki (2009)) and the full API reference. The docstrings are also available from the built-in help function, e.g. help(delta_m_phase_approx).

License

Pytrunc is licensed under the Apache License 2.0, see LICENSE.txt.

Download files

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

Source Distribution

pytrunc-2.0.0.tar.gz (372.0 kB view details)

Uploaded Source

Built Distribution

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

pytrunc-2.0.0-py3-none-any.whl (367.6 kB view details)

Uploaded Python 3

File details

Details for the file pytrunc-2.0.0.tar.gz.

File metadata

  • Download URL: pytrunc-2.0.0.tar.gz
  • Upload date:
  • Size: 372.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for pytrunc-2.0.0.tar.gz
Algorithm Hash digest
SHA256 5cd210c94fa5152bd6b98ef446b6171ade2391e071c2c9fdbc01fc7bc5ecd866
MD5 ebe89d813361cabc1d19fddc85581f5e
BLAKE2b-256 9345a9ff1372f32417790b013ee2c85b656235346b9d16000d4026597e67625d

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytrunc-2.0.0.tar.gz:

Publisher: push_pypi.yml on hygeos/pytrunc

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pytrunc-2.0.0-py3-none-any.whl.

File metadata

  • Download URL: pytrunc-2.0.0-py3-none-any.whl
  • Upload date:
  • Size: 367.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for pytrunc-2.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2a559289c75f6fc0ac81bdfba3f9a849cf2708367ca1c9385b8066c3162783f3
MD5 df5d5a92cccdf14f84bb7fa1e76615b7
BLAKE2b-256 86b819a1e8d8ae54256e19ef49775697946b0a084629f0b347623ddacf825e88

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytrunc-2.0.0-py3-none-any.whl:

Publisher: push_pypi.yml on hygeos/pytrunc

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

2.0.0 This release

2 files

1.1.0

2 files

1.0.1

2 files

1.0.0

2 files

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