Skip to main content

Torch-based Vegetation Radiative Transfer Model library (PROSPECT, SAIL, SMAC)

Project description

TorchRTM: A PyTorch-based Radiative Transfer Model

PyPI version

TorchRTM is a flexible and efficient package designed for simulating radiative transfer in the atmosphere, vegetation, and soil systems, based on the PROSAIL model. It leverages GPU-accelerated computations and integrates various atmospheric correction models, including SMAC for top-of-atmosphere reflectance estimation. This package is particularly suitable for remote sensing and environmental monitoring applications and is build for pyTorch integration.


Features

  • GPU Acceleration: Built with PyTorch in mind, TorchRTM offers GPU inference to speed up simulations.
  • SMAC Integration: Perform atmospheric correction using the Simplified Model for Atmospheric Correction (SMAC).
  • PROSAIL Model: Integrates the PROSAIL radiative transfer model for canopy reflectance simulations.
  • Flexible Inputs: Handles both batch and individual simulations of canopy and atmospheric parameters.
  • Retrieval Component: Includes a fast and flexible trait retrieval system, offering both neural network (NN)-based inference and Look-Up Table (LUT)-based matching.

Installation

Prerequisites

Ensure that you have Python 3.9+ and PyTorch installed. If you need PyTorch, follow the installation instructions from the official site.

Install TorchRTM

You can install TorchRTM directly from GitHub:

pip install torchrtm

Usage

1. Simulating Canopy Reflectance

The prosail_shell_v2 function can be used to simulate the canopy reflectance based on input vegetation parameters.

<<<<<<< HEAD
from torchrtm.models import prosail
=======
from torchrtm.models import prosail_shell_v2
import torch
# Simulate canopy reflectance
B=10000
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")

traits=torch.tensor([[40.0, 8.0, 0.0, 0.01, 0.008]] * B).to(device)
N=torch.tensor([1.5] * B).to(device)
LIDFa=torch.tensor([-0.3] * B).to(device)
LIDFb=torch.tensor([-0.1] * B).to(device)
lai=torch.tensor([3.0] * B).to(device)
q=torch.tensor([0.5] * B).to(device)
tts=torch.tensor([30.0] * B).to(device)
tto=torch.tensor([20.0] * B).to(device)
psi=torch.tensor([10.0] * B).to(device)
alpha=torch.tensor([40.0] * B).to(device)

psoil=torch.tensor([0.5] * B).to(device)
<<<<<<< HEAD
toc = prosail(traits,N,LIDFa,LIDFb,lai,q,tts,tto,psi,alpha,psoil,batch_size=100000,use_prospectd=False,lidtype=2)
=======
toc = prosail_shell_v2(traits,N,LIDFa,LIDFb,lai,q,tts,tto,psi,alpha,psoil,batch_size=100000,use_prospectd=False,lidtype=2)

2. Atmospheric Correction with SMAC

Use the smac function to apply atmospheric correction using the SMAC model.

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

# Load sensor-specific coefficients
sensor_name = "Sentinel2A-MSI"
coefs = load_smac_sensor(sensor_name)

# Set atmospheric parameters
tts = torch.tensor([30.0])
tto = torch.tensor([20.0])
psi = torch.tensor([10.0])

# Apply SMAC atmospheric correction
ttetas, ttetav, tg, s, atm_ref, tdir_tts, tdif_tts, tdir_ttv, tdif_ttv = smac(tts, tto, psi, coefs)

3. Converting TOC to TOA Reflectance

Use the toc_to_toa function to convert Top-of-Canopy (TOC) reflectance to Top-of-Atmosphere (TOA) reflectance.

from torchrtm.atmosphere.smac import toc_to_toa

# Convert TOC to TOA reflectance
R_TOC, R_TOA = toc_to_toa(toc, sm_wl, ta_ss, ta_sd, ta_oo, ta_do, ra_so, ra_dd, T_g, return_toc=True)

Tests

This package includes a set of unit tests to ensure the correctness of all key components. To run the tests, use pytest:

pytest

Contributing

Contributions to TorchRTM are welcome! Please fork this repository, create a new branch, and submit a pull request. Make sure to include tests for any new features or bug fixes.


License

This project is licensed under the MIT License.


Acknowledgments

To be added.

Project details


Download files

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

Source Distribution

torchrtm-1.2.0.tar.gz (433.7 kB view details)

Uploaded Source

Built Distribution

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

torchrtm-1.2.0-py3-none-any.whl (435.1 kB view details)

Uploaded Python 3

File details

Details for the file torchrtm-1.2.0.tar.gz.

File metadata

  • Download URL: torchrtm-1.2.0.tar.gz
  • Upload date:
  • Size: 433.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.8.18

File hashes

Hashes for torchrtm-1.2.0.tar.gz
Algorithm Hash digest
SHA256 66c6547c81e92d4d744386241ce6277f0939353f080268935fb092396d1803f0
MD5 29444265ba7ca75da6dc1cd8244fc548
BLAKE2b-256 414bc3791a8ac819612e0ac67fbd9bca0e037bc79c9b434319448eac7c98f904

See more details on using hashes here.

File details

Details for the file torchrtm-1.2.0-py3-none-any.whl.

File metadata

  • Download URL: torchrtm-1.2.0-py3-none-any.whl
  • Upload date:
  • Size: 435.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.8.18

File hashes

Hashes for torchrtm-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6aecb83298821accf1ceec89a21b80b3fa68de8eb65057298fbeb001ebf048cf
MD5 4ae225af8ddcbf73d30a621190dae68b
BLAKE2b-256 24bb043b94e6dc1466ad9be7796fd8d315e9a1afc1886c1461b47cf2f8245406

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