Skip to main content

irradpy2

irradpy2 is a Python package for solar irradiance data acquisition, processing, modeling, separation, forecasting, and evaluation.

The package provides a consistent interface for working with ground-based observations, gridded meteorological data, clear-sky irradiance models, clear-sky detection methods, irradiance separation models, and forecasting methods.

Features

  • Download ground-based solar irradiance observations
  • Download gridded and reanalysis meteorological data
  • Prepare multi-source data for irradiance analysis
  • Run clear-sky irradiance models
  • Detect clear-sky periods
  • Estimate diffuse and direct irradiance components
  • Forecast global horizontal irradiance
  • Calculate common evaluation metrics
  • Visualize model and observation results

Installation

After the package is released on PyPI:

pip install irradpy2

For local development:

pip install -e .

Package Structure

irradpy2
├── clear_sky
├── csd
├── forecast
├── getgridded
├── getirrad
├── separation
└── tool.py
Module Description
getirrad Download ground-based solar irradiance observations
getgridded Download gridded and reanalysis meteorological data
clear_sky Calculate clear-sky GHI, DNI, and DHI
csd Detect clear-sky periods
separation Separate GHI into diffuse and direct components
forecast Forecast global horizontal irradiance
tool Data processing, evaluation, and visualization utilities

Data Acquisition

Ground-based observations

Ground observation downloaders are available from irradpy2.getirrad.

from irradpy2.getirrad import download_bsrn, download_midc, download_srml

Example:

from irradpy2.getirrad import download_bsrn

download_bsrn(
    site="CAB",
    begin="2025-01-01",
    end="2025-12-31",
    username="your_bsrn_username",
    password="your_bsrn_password",
    save_path="cab_2025.csv",
)

Gridded meteorological data

Gridded and reanalysis downloaders are available from irradpy2.getgridded.

from irradpy2.getgridded import download_merra2, download_era5, download_cams

Some data sources require external accounts or API credentials:

  • BSRN account for BSRN data
  • NASA Earthdata account for MERRA-2 data
  • Copernicus ADS credentials for CAMS data

Clear-Sky Irradiance Models

The clear_sky module provides models for estimating clear-sky GHI, DNI, and DHI.

from irradpy2.clear_sky import TJ, Simplified_Solis, rest2v5

The models use NumPy arrays or pandas Series as inputs and return irradiance components.

ghi_clear, dni_clear, dhi_clear = TJ(sza, datetime)
ghi_clear, dni_clear, dhi_clear = Simplified_Solis(
    sza,
    datetime,
    press,
    aod700,
    wv,
)
ghi_clear, dni_clear, dhi_clear = rest2v5(
    sza,
    datetime,
    press,
    albedo,
    ang_alpha,
    ang_beta,
    ozone,
    NO2,
    wv,
)

Preparing Clear-Sky Model Inputs

prepare_clearsky prepares a combined dataset from ground observations and MERRA-2 auxiliary data.

It performs the following operations:

  • identifies time columns
  • builds a complete time index
  • aligns ground and MERRA-2 data
  • interpolates meteorological variables
  • converts atmospheric variables
  • calculates the solar zenith angle
from irradpy2.tool import read_csv, prepare_clearsky

ground_data = read_csv("ground_data.csv")
merra2_data = read_csv("merra2_data.csv")

data = prepare_clearsky(
    ground_data,
    merra2_data,
    latitude=39.742,
    longitude=-105.18,
    begin="2023-01-01",
    end="2023-01-01",
)

Common output columns include:

UTC
ghi
dni
dhi
sza
press
albedo
wv
aod700
ang_alpha
ang_beta
ozone_input

The sza column produced by prepare_clearsky is expressed in radians for use by the clear-sky models.

Clear-Sky Detection

Clear-sky detection methods are available from irradpy2.csd.

from irradpy2.csd import Ellis2018CSD

csd = Ellis2018CSD(
    observed_ghi,
    clear_sky_ghi,
)

Detection results can be visualized with:

from irradpy2.tool import plot_csd

plot_csd(
    data,
    ghi_col="ghi",
    clear_col="ghi_clear",
    csd_col="csd",
)

Irradiance Separation

Irradiance separation methods estimate diffuse and direct irradiance components from GHI.

from irradpy2.separation import engerer2

kd, dhi, dni = engerer2(
    ghi,
    datetime,
    latitude,
    longitude,
    averaging_period=1,
)

The separation results can be evaluated against observed DHI and DNI using the functions in irradpy2.tool.

GHI Forecasting

Forecasting methods are available from irradpy2.forecast.

from irradpy2.forecast import (
    forecast_persistence,
    forecast_arima,
    forecast_rnn,
    forecast_lstm,
    forecast_informer,
)

Example:

from irradpy2.forecast import forecast_lstm

ori_data, pre_data = forecast_lstm(
    datetime,
    ghi,
    seq_len=72,
    horizon=6,
    epochs=10,
    batch_size=64,
)

The forecasting functions return the original and predicted GHI data with their corresponding timestamps.

Data Processing Tools

Common time-series utilities are provided in irradpy2.tool.

from irradpy2.tool import (
    read_csv,
    select_series,
    resample_series,
    merge_series,
    merge_columns,
)

Example:

from irradpy2.tool import read_csv, resample_series

data = read_csv("irradiance.csv")

hourly_data = resample_series(
    data,
    time_col="UTC",
    cols=["ghi"],
    freq="1h",
    agg="mean",
    lower_limit=0,
)

Multiple time-series datasets can be aligned using:

from irradpy2.tool import merge_series

merged_data = merge_series(
    [ground_data, merra2_data, cams_data],
    time_col="UTC",
    dropna=True,
)

Solar Geometry

The solar zenith angle can be calculated using:

from irradpy2.tool import cal_zen

data = cal_zen(
    data,
    latitude=39.742,
    longitude=-105.18,
    time_col="UTC",
    zen_col="zen",
)

cal_zen returns the solar zenith angle in degrees.

Evaluation Metrics

The package provides the following evaluation metrics:

  • Mean Squared Error
  • Root Mean Squared Error
  • Mean Absolute Error
  • Mean Bias Error
  • Coefficient of Determination
from irradpy2.tool import cal_metrics

metrics = cal_metrics(
    data,
    obs_col="ghi",
    pred_col="ghi_pred",
)

print(metrics)

Individual metrics are also available:

from irradpy2.tool import cal_mse, cal_rmse, cal_mae, cal_mbe, cal_r2

The MBE definition used by irradpy2 is:

MBE = mean(predicted - observed)

Therefore:

  • positive MBE indicates overestimation
  • negative MBE indicates underestimation

Visualization

The utility module provides several plotting functions:

from irradpy2.tool import (
    plot_columns,
    plot_clearsky,
    plot_csd,
    plot_series,
)

For example, observed and predicted GHI can be compared using:

from irradpy2.tool import plot_series

plot_series(
    data,
    obs_col="ghi",
    pred_col="ghi_pred",
    obs_label="Observed GHI",
    pred_label="Predicted GHI",
    title="GHI Forecast",
    ylabel=r"GHI [W m$^{-2}$]",
)

Data Conventions

The package generally follows these conventions:

Variable Meaning Typical unit
UTC UTC timestamp datetime
ghi Global horizontal irradiance W m⁻²
dni Direct normal irradiance W m⁻²
dhi Diffuse horizontal irradiance W m⁻²
zen Solar zenith angle degree
sza Solar zenith angle used by clear-sky models radian
press Atmospheric pressure hPa or mb
wv Precipitable water model-dependent
aod700 Aerosol optical depth at 700 nm dimensionless
albedo Surface albedo dimensionless

Source datasets may use different time-column names. The utility functions support common names including:

Metadata

Release files for irradpy2 1.0.8

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for irradpy2 1.0.8
File Size Uploaded Provenance Actions
irradpy2-1.0.8.tar.gz 143.3 kB Without provenance Details for irradpy2-1.0.8.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for irradpy2 1.0.8
File Interpreter ABI Platform Actions
irradpy2-1.0.8-py3-none-any.whl Python 3 none any Details for irradpy2-1.0.8-py3-none-any.whl

Total release size: 379.6 kB

Release files / irradpy2-1.0.8.tar.gz

Download URL irradpy2-1.0.8.tar.gz
Size 143.3 kB
Tags Source
SHA-256 checksum
How to use checksums
73224f488c7dff5c1cbc635c58215e5b1a4f76b4bd79424486b64684c9315b37
BLAKE2b-256 checksum
How to use checksums
af5f94b9f8c0d8b1840737bd4ebf305bf2bb826bc07723c8b313a575f2d7fb1d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.4

Release files / irradpy2-1.0.8-py3-none-any.whl

Download URL irradpy2-1.0.8-py3-none-any.whl
Size 236.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b1b53eeab4c61ab1f86871d32035af75acfffe97211cccf01e765ae2a8cbc53b
BLAKE2b-256 checksum
How to use checksums
dba3d1ee271bd67051e7d4ba56e25bcc3d6c19d9f6cdeccc19d62b83f302e088
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.4

Security for irradpy2 1.0.8

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page