Skip to main content

pvlib/
lib.rs

1//! # pvlib-rust
2//!
3//! A Rust port of [pvlib-python](https://github.com/pvlib/pvlib-python), the
4//! open-source solar photovoltaic modeling library. The crate covers the full
5//! PV simulation pipeline: solar position, clear-sky irradiance, transposition,
6//! incidence-angle modifier, cell temperature, and DC/AC power.
7//!
8//! ## Feature flags
9//!
10//! - `pvgis` (default) — enables network I/O for PVGIS and NREL SAM helpers
11//!   in [`iotools`]. Pulls in `reqwest` with `rustls-tls`. Disable with
12//!   `default-features = false` to build the pure-compute parts of the
13//!   library on targets where blocking HTTP is not available
14//!   (e.g. `wasm32-unknown-unknown`).
15//!
16//! ## Quick start — batch simulation
17//!
18//! ```no_run
19//! use chrono::TimeZone;
20//! use chrono_tz::US::Mountain;
21//! use pvlib::batch::{BatchModelChain, WeatherSeries};
22//! use pvlib::irradiance::DiffuseModel;
23//! use pvlib::Location;
24//!
25//! let location = Location::try_new(39.74, -105.18, Mountain, 1830.0, "Golden, CO").unwrap();
26//!
27//! let mc = BatchModelChain::pvwatts(location, 30.0, 180.0, 5000.0)
28//!     .with_gamma_pdc(-0.004)
29//!     .with_inverter(5000.0, 0.96)
30//!     .with_albedo(0.2)
31//!     .with_transposition(DiffuseModel::Perez)
32//!     .with_auto_decomposition(true)
33//!     .with_system_losses(0.14);
34//!
35//! # let times = Vec::<chrono::DateTime<chrono_tz::Tz>>::new();
36//! # let zeros = vec![0.0_f64; times.len()];
37//! let weather = WeatherSeries {
38//!     times,
39//!     ghi: zeros.clone(), dni: zeros.clone(), dhi: zeros.clone(),
40//!     temp_air: zeros.clone(), wind_speed: zeros.clone(),
41//!     albedo: None,
42//! };
43//!
44//! let results = mc.run(&weather).unwrap();
45//! println!("Annual energy: {:.0} kWh", results.total_energy_wh() / 1000.0);
46//! ```
47//!
48//! See the [README](https://github.com/p-vbordei/pvlib-rust) for the full
49//! Quick Start, step-by-step usage, and the comparison with pvlib-python.
50//!
51//! ## Algorithm notes
52//!
53//! - [`irradiance::dirint`] and [`irradiance::dirint_series`] are faithful
54//!   ports of `pvlib.irradiance.dirint`, including the full 6×6×7×5
55//!   coefficient tensor. The scalar version uses the `delta_kt' = -1`
56//!   fallback bin; call the series version for time-aware persistence.
57//! - [`clearsky::detect_clearsky`] is a faithful port of the Reno–Hansen
58//!   (2016) windowed 5-criterion algorithm with iterative α rescaling.
59//! - [`bifacial`] exposes the real 2-D view-factor primitives
60//!   (`vf_row_sky_2d`, `vf_row_sky_2d_integ`, `vf_row_ground_2d`,
61//!   `vf_row_ground_2d_integ`, `unshaded_ground_fraction`,
62//!   `solar_projection_tangent`) used inside
63//!   `pvlib.bifacial.infinite_sheds`, plus a composed rear-irradiance
64//!   helper [`bifacial::rear_irradiance_sheds`]. The front-face /
65//!   shadow-fraction pipeline of the full `get_irradiance_poa` is
66//!   tracked in `ROADMAP.md`.
67
68// Private data tables for algorithms that require large coefficient sets.
69mod dirint_coeffs;
70
71pub mod location;
72pub mod solarposition;
73pub mod atmosphere;
74pub mod clearsky;
75pub mod irradiance;
76pub mod temperature;
77pub mod iam;
78pub mod tracking;
79pub mod pvsystem;
80pub mod inverter;
81pub mod modelchain;
82pub mod bifacial;
83pub mod singlediode;
84pub mod iotools;
85pub mod shading;
86pub mod soiling;
87pub mod snow;
88pub mod spectrum;
89pub mod scaling;
90pub mod albedo;
91pub mod pvarray;
92pub mod transformer;
93pub mod ivtools;
94pub mod batch;
95
96// ---------------------------------------------------------------------------
97// Crate-root re-exports for the common entry points. Users can write
98// `pvlib::Location` instead of `pvlib::location::Location`, etc.
99// ---------------------------------------------------------------------------
100
101pub use location::{Location, LocationError};
102pub use batch::{BatchModelChain, WeatherSeries, SimulationSeries};
103pub use modelchain::{ModelChain, ModelChainConfig, ModelChainResult, WeatherInput};
104pub use pvsystem::{PVSystem, Array, Mount, FixedMount, SingleAxisTrackerMount};