Skip to main content

Solar and Storage

All Contributors

A Python Library to run solar and storage optimization. This uses mixed integer linear programming and maximises revenue made by charging and discharging the battery. The model uses variable prices and a solar generation profile.

Installation

pip install solar-and-storage

Development

This repository uses uv for local development and CI (pyproject.toml + uv.lock).

uv sync
uv run pytest src/tests
uv run ruff check .

Example

Import the packages

import numpy as np

from solar_and_storage import SolarAndStorage

Make the fake price and solar data

# make prices
prices = np.zeros(24) + 30
prices[6:19] = 40
prices[9] = 50
prices[12:14] = 30
prices[16:18] = 50
prices[17] = 60

# make solar profile
solar = np.zeros(24)
solar[8:16] = 2.0
solar[10:14] = 4.0

Then run optimization

solar_and_storage = SolarAndStorage(prices=prices, solar_generation=list(solar))
solar_and_storage.run_optimization()
result_df = solar_and_storage.get_results()

Now plot the data

fig = solar_and_storage.get_figure()

fig.show(rendered="browser")

Example1

The first plot shows the solar profile, the second shows the prices that day. The third shows the battery profile. Finally the fourth shows profit. You can see that the battery charged from the solar site at the end of the solar maximum

Starting with stored energy

Use current_soc to set the starting battery state of charge as a fraction of the battery capacity. For example, a half-full battery can discharge during an initial high-price period:

prices = np.zeros(24)
prices[0] = 100
solar = np.zeros(24)

solar_and_storage = SolarAndStorage(
    prices=prices,
    solar_generation=list(solar),
    current_soc=0.5,
    battery_eta_charge=1,
    battery_eta_discharge=1,
)
result_df = solar_and_storage.get_results()

Current SOC example

Thanks

Thanks you to the follow repos for inspiration

Contributors ✨

Thanks goes to these wonderful people (emoji key):

Peter Dudfield
Peter Dudfield

💻
gilbertgong
gilbertgong

💻
davidhuanggg
davidhuanggg

💻

This project follows the all-contributors specification. Contributions of any kind welcome!

Metadata

Release files for solar-and-storage 0.0.19

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

Source distribution (sdist)

Source distribution for solar-and-storage 0.0.19
File Size Uploaded Provenance Actions
solar_and_storage-0.0.19.tar.gz 8.1 kB Without provenance Details for solar_and_storage-0.0.19.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for solar-and-storage 0.0.19
File Interpreter ABI Platform Actions
solar_and_storage-0.0.19-py3-none-any.whl Python 3 none any Details for solar_and_storage-0.0.19-py3-none-any.whl

Total release size: 14.3 kB

Release files / solar_and_storage-0.0.19.tar.gz

Download URL solar_and_storage-0.0.19.tar.gz
Size 8.1 kB
Tags Source
SHA-256 checksum
How to use checksums
e785af4f65e2397f02597d10fb9ef517d565f9560626ab3b60b64efc8e9f088c
BLAKE2b-256 checksum
How to use checksums
45ee132cc260a282938f752626a478eac2ef7f64e2f5471337b215c2065b32d0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.6 {"installer":{"name":"uv","version":"0.13.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / solar_and_storage-0.0.19-py3-none-any.whl

Download URL solar_and_storage-0.0.19-py3-none-any.whl
Size 6.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a27a069328149d657340cc9bb053a23b4855f6cb1a89c9020cbda3c8497f6dfb
BLAKE2b-256 checksum
How to use checksums
a8a7ff7566cc522fe9accd949c94f130453aeafc9952a6b6e49959a3461ff7fc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.6 {"installer":{"name":"uv","version":"0.13.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for solar-and-storage 0.0.19

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