pvlib-rust
A Rust port of pvlib-python — the open-source solar photovoltaic modeling library.
pvlib-rust provides the same algorithms, accuracy, and modeling capabilities as pvlib-python, with Rust's performance and safety guarantees. It covers the full PV simulation pipeline: from solar position and clear-sky irradiance through module temperature and single-diode physics to DC/AC power output.
Features
- 156 public functions across 23 modules
- 302 tests with end-to-end validation
- Full simulation pipeline via
ModelChain - Multiple model options at each step (transposition, temperature, IAM, inverter)
- Weather file I/O (TMY3, EPW) and PVGIS API client
- IV curve fitting and single-diode model parameter extraction
- No unsafe code
Quick Start
Add to your Cargo.toml:
[]
= { = "https://github.com/p-vbordei/pvlib-rust" }
Full System Simulation
use TimeZone;
use USMountain;
use Location;
use ;
use ;
// Define location and system
let location = new;
let array = Array ;
let system = new;
// Create ModelChain with PVWatts configuration
let mc = with_pvwatts;
// Run simulation
let weather = WeatherInput ;
let result = mc.run_model_from_weather.unwrap;
println!;
println!;
println!;
Step-by-Step Usage
use ;
// Solar position (NREL SPA algorithm)
let location = new;
let time = USMountain.with_ymd_and_hms.unwrap;
let solpos = location.get_solarposition.unwrap;
// Airmass
let am_rel = get_relative_airmass;
let pressure = alt2pres;
let am_abs = get_absolute_airmass;
// Clear sky irradiance (Ineichen model)
let cs = location.get_clearsky;
// Irradiance decomposition
let = erbs;
// Angle of incidence on tilted surface
let aoi = aoi;
// Incidence angle modifier
let iam_loss = physical;
// Cell temperature
let = sapm_cell_temperature;
Modules
Core Physics
| Module | Description | Key Functions |
|---|---|---|
solarposition |
Solar position (SPA + analytical) | get_solarposition, declination_spencer71, hour_angle, solar_zenith_analytical |
atmosphere |
Atmospheric properties | get_relative_airmass, alt2pres, gueymard94_pw, kasten96_lt, windspeed_powerlaw |
clearsky |
Clear sky irradiance | ineichen, haurwitz, bird, simplified_solis |
irradiance |
Irradiance transposition & decomposition | aoi, perez, haydavies, erbs, disc, dirindex, get_total_irradiance |
location |
Location with convenience methods | get_solarposition, get_clearsky, get_airmass |
System Modeling
| Module | Description | Key Functions |
|---|---|---|
temperature |
Cell/module temperature | sapm_cell_temperature, pvsyst_cell_temperature, faiman, fuentes, noct_sam, ross |
iam |
Incidence angle modifiers | ashrae, physical, martin_ruiz, schlick, sapm |
pvsystem |
PV system & single-diode params | calcparams_desoto, calcparams_cec, calcparams_pvsyst, sapm |
singlediode |
Single-diode equation solvers | bishop88, bishop88_mpp, bishop88_i_from_v, i_from_v, v_from_i |
inverter |
Inverter models | pvwatts_ac, sandia, adr, pvwatts_multi, sandia_multi |
tracking |
Single-axis tracker | singleaxis, calc_surface_orientation |
modelchain |
End-to-end simulation pipeline | run_model_from_weather, run_model_from_poa, with_pvwatts, with_sapm |
Advanced Features
| Module | Description | Key Functions |
|---|---|---|
bifacial |
Bifacial irradiance | get_irradiance_infinite_sheds |
shading |
Row-to-row shading | masking_angle, ground_angle, projected_solar_zenith_angle, shaded_fraction1d |
soiling |
Soiling losses | hsu, kimber, accumulation_model |
snow |
Snow coverage & losses | fully_covered_nrel, coverage_nrel, dc_loss_nrel |
spectrum |
Spectral mismatch | spectral_mismatch_modifier, spectral_factor_sapm, spectral_factor_caballero |
scaling |
Geographic smoothing | wvm_smoothing |
albedo |
Surface albedo | inland_water_dvoracek, surface_albedo |
pvarray |
Module efficiency models | pvefficiency_adr, huld |
transformer |
Transformer losses | simple_efficiency |
I/O & Data
| Module | Description | Key Functions |
|---|---|---|
iotools |
Weather data I/O | read_tmy3, read_epw, get_pvgis_tmy, get_pvgis_hourly, retrieve_sam |
ivtools |
IV curve fitting | fit_sandia_simple, fit_desoto, rectify_iv_curve |
ModelChain Configuration
The ModelChain supports multiple model selections:
| Step | Options |
|---|---|
| Transposition | Isotropic, Hay-Davies, Perez, Klucher, Reindl |
| Temperature | SAPM, PVsyst, Faiman, Fuentes, NOCT_SAM, PVWatts |
| IAM (AOI) | Physical (Fresnel), ASHRAE, Martin-Ruiz, SAPM, No loss |
| Spectral | No loss |
| DC Model | PVWatts |
| AC Model | PVWatts, Sandia, ADR |
| Losses | PVWatts, No loss |
Factory constructors:
ModelChain::with_pvwatts()— PVWatts DC/AC, Physical AOI, Perez transpositionModelChain::with_sapm()— SAPM temperature, ASHRAE AOI, Hay-Davies transpositionModelChain::with_config()— fully custom model selection
Weather Data
Read TMY3 files
let data = read_tmy3.unwrap;
println!;
for record in &data.records
Read EPW files
let data = read_epw.unwrap;
Fetch from PVGIS API
let tmy = get_pvgis_tmy.unwrap;
References
This library implements algorithms from peer-reviewed solar energy literature:
- Solar Position: NREL Solar Position Algorithm (Reda & Andreas, 2004), Spencer (1971)
- Clear Sky: Ineichen & Perez (2002), Bird (1981), Haurwitz (1945), Simplified Solis (Ineichen, 2008)
- Irradiance: Perez et al. (1990), Hay & Davies (1980), Erbs et al. (1982), DISC (Maxwell, 1987)
- Temperature: SAPM (King et al., 2004), PVsyst, Faiman (2008), Fuentes (1987), Ross (1980)
- IAM: Martin & Ruiz (2001), De Soto et al. (2006), ASHRAE
- Single Diode: Bishop (1988), De Soto et al. (2006)
- Inverter: PVWatts (Dobos, 2014), Sandia (King et al., 2007), ADR (Driesse, 2023)
- Tracking: Marion & Dobos (2013)
- Soiling: HSU (Coello & Boyle, 2019), Kimber et al. (2006)
- Bifacial: Infinite sheds model (Mikofski et al., 2019)
Comparison with pvlib-python
pvlib-rust covers the core simulation pipeline of pvlib-python. Some differences:
- Data structures: Uses Rust structs and enums instead of pandas DataFrames
- Single timestep: Functions operate on single values (no vectorized operations over time series yet)
- IO tools: Covers TMY3, EPW, and PVGIS; pvlib-python has 20+ additional data source adapters
- No spectral irradiance model: SPECTRL2 is not yet ported (requires extensive lookup tables)
Building & Testing
License
Licensed under either of:
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT License (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Acknowledgments
This project is a Rust port of pvlib-python, developed by the pvlib community. All credit for the underlying algorithms and models goes to the original authors and the pvlib-python contributors.