Skip to main content

Geometry-based solar potential, irradiance, and solar PV energy calculations in Python without external APIs.

Project description

pysunerg-calc

Geometry-based solar potential, irradiance, and solar PV energy calculations in Python—just math, physics, and data classes; no external APIs needed.

PyPI version MIT License Python Package Tests

  • Accurate solar geometry: Compute sun position (declination, hour angle, altitude, azimuth, zenith) for any latitude, longitude, and datetime.
  • Instantaneous PV power calculation: Use panel specs and solar irradiance to compute real-time output.
  • Energy output estimation: Predict daily, yearly, or custom-period PV system yield.

Formulas

Step Equation
Declination δ = 23.45 × sin[(360/365) × (n − 81)]
Hour angle H = 15 × (solar-time-hours − 12)
Altitude sin(α) = sin(δ) sin(φ) + cos(δ) cos(φ) cos(H)
Azimuth sin(Az) = cos(δ) sin(H) / cos(α)
Irradiance I = I₀ × sin(α) (for horizontal surface, clear sky)

References:


Installation

pip install pysunergy-calc

Usage

from pysunergy_calc import (
    compute_solar_potential,
    compute_panel_power,
    estimate_energy_produced,
)

# Example 1: Sun position and irradiance in New York on August 15, 2025, at 16:00 UTC
from datetime import datetime, timezone
sun = compute_solar_potential(
    40.7128,          # latitude
    -74.0060,         # longitude
    datetime(2025, 8, 15, 16, 0, 0, tzinfo=timezone.utc) # UTC date/time
)
print(sun)
# SolarPosition(
#     declination=..., hour_angle=..., altitude=..., azimuth=..., zenith=..., irradiance=...
# )

# Example 2: Compute panel output at that instant
area = 1.6      # m² (panel area)
efficiency = 0.20  # 20% PV efficiency
power_W = compute_panel_power(area, efficiency, sun.irradiance)
print(power_W)

# Example 3: Estimate daily energy (kWh) for your panel
average_irradiance = 5 * 1000 / 24  # e.g., 5kWh/m²/day avg ≈ 208 W/m² avg
daily_kWh = estimate_energy_produced(
    area,
    efficiency,
    average_irradiance,
    24,      # hours in a day
    0.75     # typical performance ratio (losses)
)
print(daily_kWh)

API Reference

compute_solar_potential(lat: float, lon: float, date: datetime) -> SolarPosition

  • All angles are in degrees.
  • irradiance is in W/m² (horizontal surface).
  • Calculates solar declination, hour angle, altitude, azimuth, zenith, and irradiance for a specified location/time.

compute_panel_power(area: float, efficiency: float, irradiance: float) -> float

  • area: Panel area (m²)
  • efficiency: Panel efficiency (0...1)
  • irradiance: Solar irradiance (W/m²)
  • Returns instantaneous PV output power (W).

estimate_energy_produced(area: float, efficiency: float, average_irradiance: float, period_hours: float, performance_ratio: float=0.75) -> float

  • Estimates total energy output for your system and conditions, in kWh over the specified period.
  • Typical performance_ratio is 0.75–0.85 (accounts for temperature, dust, inverter).
  • Average irradiance is entered in W/m².

Development & Testing

  • 100% Python, type-annotated and PEP 621 compliant.
  • Full Pytest test suite included.
  • To develop and run tests:
uv pip install --group dev
pytest
  • Code is linted/formatted automatically with ruff.

License

MIT © Abdullah Waqar


pysunergy-calc is not affiliated with nor endorsed by pveducation.org, palmetto.com, Sunbase, or EcoFlow. Reference links are for scientific documentation and transparency only.

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

pysunergy_calc-1.0.3.tar.gz (19.0 kB view details)

Uploaded Source

Built Distribution

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

pysunergy_calc-1.0.3-py3-none-any.whl (7.0 kB view details)

Uploaded Python 3

File details

Details for the file pysunergy_calc-1.0.3.tar.gz.

File metadata

  • Download URL: pysunergy_calc-1.0.3.tar.gz
  • Upload date:
  • Size: 19.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.5

File hashes

Hashes for pysunergy_calc-1.0.3.tar.gz
Algorithm Hash digest
SHA256 9dd2028a87c214f64e8b64087ae7c0a359991b104fa466d6ad48263f5c09ea9a
MD5 d244d3bf316ec8fb61278113740fd833
BLAKE2b-256 bd0d1b01b004426da41e59f08da295d07882b33c17e39f9c6f708a31937393ef

See more details on using hashes here.

File details

Details for the file pysunergy_calc-1.0.3-py3-none-any.whl.

File metadata

  • Download URL: pysunergy_calc-1.0.3-py3-none-any.whl
  • Upload date:
  • Size: 7.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.5

File hashes

Hashes for pysunergy_calc-1.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 8bd123d9835426aa99dbeec9f267be929413e17c0d7078ad81a1014610419119
MD5 14c05aca1a4cb008759f6884409aa22c
BLAKE2b-256 6ff76989db389735e71c361cbc6edce9d4f90cd687e4a8dc4e99b9e58a3d3433

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