An open API service indexing awesome lists of open source software.

https://github.com/robintw/rtwrtm

Monte Carlo Ray Tracing Radiative Transfer Model (RTM)
https://github.com/robintw/rtwrtm

Last synced: 3 months ago
JSON representation

Monte Carlo Ray Tracing Radiative Transfer Model (RTM)

Awesome Lists containing this project

README

          

# RTWRTM

This is the code for the RTWRTM model, a very simple ray-tracing Radiative Transfer Model written as part of my MSc thesis. It is *not* suitable for any production use in any way - but may be useful to others in seeing how Radiative Transfer Models can be implemented.

The thesis I wrote is available in the `docs` folder, along with an extract from the thesis showing how each individual ray is treated.

The code is written in IDL, and has been tested using IDL 8.5. To run it, load IDL and change to the directory containing the code and then run something like the following:

```
result = RUN_RTM(0, 0, 0)
```

This will produce results with the default parameterisation with *no* cloud in the sky. To include the pre-defined cloud, change the values of `0, 0, 0` to `x, y, 1` where `x` and `y` are the location of the centre of the cloud on the grid.

If you're interested in a model that can do this sort of thing *properly* then investigate the Discrete Anisotropic Radiative Transfer model (DART) - see http://www.cesbio.ups-tlse.fr/us/dart.html.

---

## Python version

The IDL code has been ported to Python with NumPy/Numba for significantly better performance. See `demo.ipynb` for an interactive walkthrough.

### Installation

```bash
pip install numba numpy scipy matplotlib jupyter
```

### Running

**Command line:**

```bash
# Default run (no cloud)
python run_rtm.py

# With cloud centred at grid position (10, 10)
python run_rtm.py --cloud 10 10

# Show a plot after the run
python run_rtm.py --plot

# More iterations for a smoother spectrum
python run_rtm.py --iterations 50000 --plot
```

**Python API:**

```python
from run_rtm import run_rtm

result = run_rtm(n_iterations=50000, day_of_year=172, lat=51.5, lon=-0.1)

result['wavelengths'] # 122 band centres, 0.3–4.0 μm
result['vertical'] # irradiance arriving vertically (W m⁻² μm⁻¹)
result['left'] # arriving from the left
result['right'] # arriving from the right
result['total_hits'] # total sensor hits across all wavelengths
```

### File structure

| File | Purpose |
|---|---|
| `run_rtm.py` | Main simulation function + CLI entry point |
| `rtm_core.py` | Numba-JIT ray tracer (the hot loop) |
| `rtm_constants.py` | Spectral data arrays and helper functions |
| `demo.ipynb` | Jupyter notebook demo |

### Performance

The Numba JIT compiler runs on the first call (~10 s), then uses a disk cache for all subsequent calls (~1 s overhead). The simulation parallelises over iterations using all available CPU cores.

| Iterations | Sensor hits | Time |
|---:|---:|---:|
| 1,000 | ~230 | 0.1 s |
| 5,000 | ~1,000 | 0.5 s |
| 10,000 | ~1,900 | 1.4 s |
| 50,000 | ~12,000 | 5 s |
| 100,000 | ~21,000 | 10 s |
| 500,000 | ~105,000 | 53 s |

The hit rate is ~0.2% per iteration — rays must scatter to reach the sensor. More iterations give a smoother spectrum.