
Security News
The Hidden Blast Radius of the Axios Compromise
The Axios compromise shows how time-dependent dependency resolution makes exposure harder to detect and contain.
torchrtm
Advanced tools
TorchRTM is a GPU-accelerated, modular, and research-ready radiative transfer modeling (RTM) library built on top of PyTorch.
It integrates:
TorchRTM is ideal for remote sensing, vegetation trait retrieval, radiative transfer simulation, environmental monitoring, machine learning and RTM-based inversion workflows.
pip install torchrtm
This README includes complete usage documentation for:
TorchRTM provides a unified PROSAIL implementation:
from torchrtm.models import prosail
rho, tau = prospectd(traits, N, alpha=alpha, print_both=True)
# also supports: prospect5b / prospectpro
| Name | Type | Description |
|---|---|---|
traits | Tensor (batch, n_traits) | Leaf biochemical parameters (Cab, Car, Cbrown, Cw, Cm, etc.) |
N | Tensor (batch) | Leaf structure parameter |
alpha | Tensor | Leaf transmittance parameter (commonly 40°) |
print_both | bool | if print both of rho,tau, if not only output rho |
traits must be provided in a fixed parameter order depending on the PROSPECT model version:
Cab, Car, Cbrown, Cw, CmCab, Car, Cbrown, Cw, Cm, CanthCab, Car, Cbrown, Cw, Canth, Prot, CbcA tensor of size:
(batch, spectral_length), (batch, spectral_length)
Containing:
| Output | Description |
|---|---|
rho | Leaf reflectance spectrum computed by the PROSPECT model (leaf-scale bi-directional reflectance). |
tau | Leaf transmittance spectrum computed by the PROSPECT model (leaf-scale bi-directional transmittance). |
prosail(
traits, N, LIDFa, LIDFb, lai, q,
tts, tto, psi, tran_alpha, psoil,
batch_size=0, prospect_type='prospect5b', lidtype=1
)
| Name | Type | Description |
|---|---|---|
traits | Tensor (batch, n_traits) | Leaf biochemical parameters (Cab, Car, Cbrown, Cw, Cm, etc.) |
N | Tensor (batch) | Leaf structure parameter |
LIDFa / LIDFb | Tensor | Leaf inclination distribution parameters |
lai | Tensor | Leaf Area Index |
q | Tensor | Hotspot parameter |
tts | Tensor | Solar zenith angle (degrees) |
tto | Tensor | Observer zenith angle (degrees) |
psi | Tensor | Relative azimuth angle (degrees) |
tran_alpha | Tensor | Leaf transmittance parameter (commonly 40°) |
psoil | Tensor | Soil moisture parameter |
batch_size | int | Processing batch size (for GPU memory control) |
prospect_type | str | "prospect5b", "prospectd", "prospectpro" |
lidtype | int | LIDF type (1–4) |
A tensor of size:
(batch, spectral_length, 7)
Containing:
| Output | Description |
|---|---|
| RDDT | Reflectance for Diffuse-Downward Transmission |
| RSDT | Reflectance for Solar-Downward Transmission |
| RDOT | Reflectance for Diffuse Outgoing Transmission |
| RSOT | Reflectance for Solar Outgoing Transmission |
| TSD | Total Solar Downward Transmission |
| TDD | Total Diffuse Downward Transmission |
| RDD | Reflectance for Diffuse-Downward Irradiance |
from torchrtm.models import prosail
import torch
B = 5000
device = "cuda"
traits = torch.rand(B, 5).to(device)
N = torch.rand(B).to(device)
LIDFa = torch.zeros(B).to(device)
LIDFb = torch.zeros(B).to(device)
lai = torch.ones(B).to(device) * 3
q = torch.ones(B).to(device) * 0.5
tts = torch.ones(B).to(device) * 30
tto = torch.ones(B).to(device) * 20
psi = torch.ones(B).to(device) * 10
alpha = torch.ones(B).to(device) * 40
psoil = torch.ones(B).to(device) * 0.5
toc = prosail(
traits, N, LIDFa, LIDFb, lai, q,
tts, tto, psi, alpha, psoil,
batch_size=5000,
prospect_type="prospect5b",
lidtype=2
)
print(toc.shape)
TorchRTM supports SMAC for TOA correction.
from torchrtm.atmosphere.smac import smac
from torchrtm.data_loader import load_smac_sensor
coefs, sm_wl = load_smac_sensor("S2A")
Ta_s, Ta_o, T_g, ra_dd, ra_so, ta_ss, ta_sd, ta_oo, ta_do = smac(
tts=torch.tensor([30.0]),
tto=torch.tensor([20.0]),
psi=torch.tensor([10.0]),
coefs=coefs
)
from torchrtm.atmosphere.smac import toc_to_toa
R_TOC, R_TOA = toc_to_toa(
toc, sm_wl - 400,
ta_ss, ta_sd, ta_oo, ta_do,
ra_so, ra_dd, T_g
)
Generates millions of simulated samples using PROSPECT, PROSAIL, or ATOM.
from torchrtm.utils.torch_utils import Torchlut
Torchlut() — API DocumentationTorchlut(
model='prospect5b',
table_size=500000,
std=0,
batch=10000,
wavelength=None,
sensor_name='LANDSAT4-TM',
sail_prospect='prospectd',
use_atom=False,
para_addr=None
)
| Parameter | Description |
|---|---|
model | "prospect5b", "prospectd", "prospectpro", "prosail" |
table_size | Number of samples to generate |
std | Gaussian noise standard deviation |
batch | Simulation batch size |
wavelength | Select specific wavelength indices |
sensor_name | Used when use_atom=True |
sail_prospect | Leaf model used inside PROSAIL |
use_atom | Enable ATOM (PROSAIL + SMAC) |
para_addr | Parameter range configuration |
When use_atom=True, the following sensor spectral-response files are supported:
LANDSAT4-TMLANDSAT5-TMLANDSAT7-ETMLANDSAT8-OLISentinel2A-MSISentinel2B-MSISentinel3A-OLCISentinel3B-OLCITerraAqua-MODISref_list # reflectance (TOC or TOA)
para_list # parameter vectors
ref, params = Torchlut(
model="prospectd",
table_size=100000,
batch=5000,
std=0.01
)
Fast, block-wise KNN retrieval optimized for LUT inversion.
from torchrtm.utils.torch_utils import Torchlut_pred
Torchlut_pred() — API DocumentationTorchlut_pred(
xb, xq, y,
k=5,
distance_order=2,
xb_block=1000,
batch_size=200,
device="cuda"
)
| Parameter | Description |
|---|---|
xb | Database features (N, D) |
xq | Query features (M, D) |
y | Database target values (N,) or (N, D_out) |
k | Number of nearest neighbors |
distance_order | 1 = Manhattan, 2 = Euclidean, etc. We recommand to set it as 9 |
xb_block | Split xb to avoid GPU OOM |
batch_size | Query batch size |
device | cuda / cpu |
preds: shape (M,) or (M, D_out)
Supports multi-million LUT inference on consumer GPUs.
preds = Torchlut_pred(
xb=torch.tensor(ref),
xq=torch.tensor(query_ref),
y=torch.tensor(params),
k=5,
device="cuda"
)
# Step 1: Build LUT
ref_lut, para_lut = Torchlut(model="prospectd", table_size=300000)
# Step 2: Convert measured reflectance to tensor
xq = torch.tensor(measured_ref)
# Step 3: KNN retrieval
pred = Torchlut_pred(
xb=torch.tensor(ref_lut),
xq=xq,
y=torch.tensor(para_lut),
k=5
)
PRs and issues are welcome!
Please include tests and clear descriptions.
MIT License.
FAQs
Torch-based Vegetation Radiative Transfer Model library (PROSPECT, SAIL, SMAC)
We found that torchrtm demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
The Axios compromise shows how time-dependent dependency resolution makes exposure harder to detect and contain.

Research
A supply chain attack on Axios introduced a malicious dependency, plain-crypto-js@4.2.1, published minutes earlier and absent from the project’s GitHub releases.

Research
Malicious versions of the Telnyx Python SDK on PyPI delivered credential-stealing malware via a multi-stage supply chain attack.