Metadata-Version: 2.1
Name: torchrtm
Version: 1.5.1
Summary: Torch-based Vegetation Radiative Transfer Model library (PROSPECT, SAIL, SMAC)
Home-page: https://github.com/Schimasuperbra/torchrtm
Author: Peng Sun, Marco D. Visser
Author-email: sunpeng18@mails.ucas.ac.cn
License: MIT
Project-URL: Source, https://github.com/Schimasuperbra/torchrtm
Project-URL: Bug Tracker, https://github.com/Schimasuperbra/torchrtm/issues
Keywords: radiative transfer,PROSAIL,SMAC,torch,remote sensing,inversion
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Science/Research
Classifier: Topic :: Scientific/Engineering :: Atmospheric Science
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: torch >=2.0.0
Requires-Dist: numpy >=1.18
Requires-Dist: pandas >=1.1
Requires-Dist: scipy >=1.5
Requires-Dist: matplotlib
Requires-Dist: tqdm

# TorchRTM: A PyTorch-based Radiative Transfer Modeling Toolkit

[![PyPI version](https://badge.fury.io/py/torchrtm.svg)](https://pypi.org/project/torchrtm/)

TorchRTM is a GPU-accelerated, modular, and research-ready radiative transfer modeling (RTM) library built on top of PyTorch. It implements the full soil–leaf–canopy–atmosphere modelling chain (PROSPECT, 4SAIL, and SMAC) as native PyTorch tensor operations, enabling seamless integration with deep learning workflows.

This repository accompanies the paper:

> **TorchRTM: A high-performance vegetation RTM framework for deep learning integration**

## Installation

```bash
pip install torchrtm
```

Requires Python ≥ 3.9 and PyTorch ≥ 2.0.

## Quick Start

### Leaf Reflectance (PROSPECT)

```python
import torch
from torchrtm.leaf.prospect import prospect5b, prospectd

# PROSPECT-5B: traits = [Cab, Car, Cbrown, Cw, Cm]
traits = torch.tensor([[40.0, 8.0, 0.0, 0.01, 0.009]])
N = torch.tensor([1.5])  # leaf structure parameter
rho, tau = prospect5b(traits, N)
# rho: leaf reflectance (1, 2101), tau: transmittance (1, 2101)

# PROSPECT-D: traits = [Cab, Car, Canth, Cbrown, Cw, Cm]
traits_d = torch.tensor([[40.0, 8.0, 0.0, 0.0, 0.01, 0.009]])
rho_d, tau_d = prospectd(traits_d, N)
```

### Canopy Reflectance (PROSAIL)

```python
from torchrtm.models.models import prosail

n = 100  # batch size
traits = torch.tensor([[40.0, 8.0, 0.0, 0.01, 0.009]] * n)
N       = torch.tensor([1.5] * n)
LIDFa   = torch.tensor([-0.35] * n)
LIDFb   = torch.tensor([-0.15] * n)
lai     = torch.tensor([3.0] * n)
q       = torch.tensor([0.01] * n)
tts     = torch.tensor([30.0] * n)  # solar zenith
tto     = torch.tensor([10.0] * n)  # view zenith
psi     = torch.tensor([0.0] * n)   # relative azimuth
alpha   = torch.tensor([40.0] * n)
psoil   = torch.tensor([1.0] * n)

result = prosail(traits, N, LIDFa, LIDFb, lai, q,
                 tts, tto, psi, alpha, psoil,
                 batch_size=n, prospect_type='prospect5b')
# result shape: (7, 2101, n) — 7 reflectance components
```

### Atmospheric Correction (SMAC)

```python
from torchrtm.atmosphere.smac import smac
from torchrtm.data_loader import load_smac_sensor

coefs, wl = load_smac_sensor("Sentinel2A-MSI")
tts = torch.tensor([30.0])
tto = torch.tensor([10.0])
psi = torch.tensor([0.0])
Ta_s, Ta_o, T_g, ra_dd, ra_so, ta_ss, ta_sd, ta_oo, ta_do = smac(tts, tto, psi, coefs)
```

### LUT-based Retrieval

```python
from torchrtm.retrival.fastLUT import Torchlut_pred

# xb: LUT spectra (N, D), y: LUT parameters (N, P), xq: query spectra (M, D)
preds = Torchlut_pred(xb, xq, y, k=5, device="cpu", agg="weighted")
```

## Available Sensors (SMAC)

`Sentinel2A-MSI`, `Sentinel2B-MSI`, `Sentinel3A-OLCI`, `Sentinel3B-OLCI`, `LANDSAT4-TM`, `LANDSAT5-TM`, `LANDSAT7-ETM`, `LANDSAT8-OLI`, `TerraAqua-MODIS`

## Testing

Install test dependencies and run:

```bash
pip install pytest
python -m pytest tests/test_torchrtm.py -v
```

The test suite covers data loaders, PROSPECT (5B/D/PRO), PROSAIL, SMAC, LUT retrieval, Inverse Net, math utilities, and full integration pipelines.

## Supplementary Code

- **`Start_Tutorial/`** — Reproduces the examples in the paper.
  [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/Schimasuperbra/torchrtm/blob/main/Start_Tutorial/quick_start.ipynb)

- **`Translation_Fidelity/`** — Evaluates consistency of TorchRTM outputs against other RTM implementations.

## Citation

If you use TorchRTM in your research, please cite:

```
Peng Sun, Peter van Bodegom, Marco Visser. TorchRTM: A high-performance vegetation RTM package for deep learning integration. Authorea. 15 January 2026.
DOI: https://doi.org/10.22541/au.176849838.80131044/v1
```

## License

MIT
