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

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!

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

solar_and_storage-0.0.16.tar.gz (7.8 kB view details)

Uploaded Source

Built Distribution

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

solar_and_storage-0.0.16-py3-none-any.whl (6.0 kB view details)

Uploaded Python 3

File details

Details for the file solar_and_storage-0.0.16.tar.gz.

File metadata

  • Download URL: solar_and_storage-0.0.16.tar.gz
  • Upload date:
  • Size: 7.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.12.0 {"installer":{"name":"uv","version":"0.12.0","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}

File hashes

Hashes for solar_and_storage-0.0.16.tar.gz
Algorithm Hash digest
SHA256 4ab73c5481c2e0b19ffa43415210f4cf6c548133e60a7ca7fd5fa152b6e518cd
MD5 d1671d46356d116d3d50e513138f7a7e
BLAKE2b-256 8a747dceb16c7257dd2e3fa1b780f4c82d2d199b4c2a99e5df3c6bc0df27e643

See more details on using hashes here.

File details

Details for the file solar_and_storage-0.0.16-py3-none-any.whl.

File metadata

  • Download URL: solar_and_storage-0.0.16-py3-none-any.whl
  • Upload date:
  • Size: 6.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.12.0 {"installer":{"name":"uv","version":"0.12.0","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}

File hashes

Hashes for solar_and_storage-0.0.16-py3-none-any.whl
Algorithm Hash digest
SHA256 e21e014d0ada6f693e51d37da63c66b96c881ee792bedceadfc26bcaecd0e539
MD5 5c4b87944699ad2bd29ca805e61d3f9e
BLAKE2b-256 d6d3fe93ba7d00d890b1a57026cf386eee4675c8dc4c7dae3da7823b82fec5bd

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 Sentry Error logging StatusPage Status page