Skip to main content

PV-Forecasting Toolkit

Project description

Phorecast ML

Python License Deep Learning PV Forecasting

A Python library for photovoltaic (PV) power forecasting using deep learning models and specialized time-series preprocessing tools.

The library provides modular building blocks for:

  • preprocessing PV time-series data
  • generating training datasets
  • training deep learning forecasting models
  • generating PV power forecasts

The current implementation includes an LSTM-based forecasting model built on TensorFlow / Keras.


Table of Contents


Overview

phorecast_ml is designed as a machine learning foundation layer for photovoltaic forecasting.

It focuses on:

  • preparing PV time-series datasets
  • creating structured training data
  • training deep learning forecasting models

The design follows a simple API pattern similar to scikit-learn, with methods such as fit() and predict().

This makes the models easy to integrate into forecasting pipelines.


Features

Forecasting Models

  • LSTM-based neural network model
  • configurable architecture
  • training via TensorFlow/Keras

Data Processing

Tools for preparing time-series data:

  • window generation
  • dataset creation
  • train/test splitting
  • TensorFlow dataset generation

Solar Data Utilities

  • solar position calculation using pvlib
  • solar-based data filtering
  • preprocessing utilities for photovoltaic datasets

Custom Evaluation

Includes custom metrics and loss functions:

  • wmape
  • sum_difference

Architecture Overview

The library is structured into four main components:

Data Input
   │
   ▼
Preprocessing
(windowing, filtering, solar features)
   │
   ▼
Dataset Generation
(X / y creation)
   │
   ▼
Deep Learning Model
(LSTM)
   │
   ▼
Predictions

The architecture separates data preparation, model training, and forecast generation.


Project Structure

phorecast_ml/
  __init__.py

  model/
    BaseModel.py
    LSTM.py
    __init__.py

  preprocessing/
    dataset.py
    dataset_splitting.py
    filtering.py
    solar.py
    windowing.py

  metrics/
    sum_difference.py
    weighted_mean_absolute_percentage_error.py

  losses/
    sum_difference_loss.py

tests/
  static.py
  test_dataset.py
  test_dataset.csv

pyproject.toml
requirements.txt
README.md
LICENSE

Installation

Requirements

  • Python >= 3.12

Install from repository

git clone https://github.com/<organization>/phorecast-ml.git
cd phorecast-ml
pip install .

Install from PyPI (if published)

pip install phorecast-ml

Usage

Basic Model Training

import phorecast_ml

model = phorecast_ml.model.LSTM(
    units=128,
    depth=4,
    learning_rate=1e-3,
    epochs=100,
    patience=10,
    metrics=["mae", "wmape"],
)

model.fit(X_train, y_train)

predictions = model.predict(X_test)

Example Workflow

Typical forecasting pipeline:

  1. Prepare PV time-series data
  2. Attach solar position features
  3. Filter invalid or noisy data
  4. Generate time windows
  5. Convert windows into training datasets
  6. Train the forecasting model
  7. Generate predictions

Create Time Windows

from phorecast_ml.preprocessing.windowing import windowing, get_dataset_from_windows

windows = windowing(dataframe, window_size=24, stride=6, max_missing=6)

(X, y), indices = get_dataset_from_windows(
    windows,
    target="Target"
)

Attach Solar Features

from phorecast_ml.preprocessing.solar import attach_solar_positions

dataframe = attach_solar_positions(
    data=dataframe,
    latitude=0.0,
    longitude=0.0,
    height=0.0
)

Filter Dataset

from phorecast_ml.preprocessing.filtering import solar_position_filter

filtered = solar_position_filter(
    data=dataframe,
    independent_variables=["feature_1", "feature_2", "elevation"],
    target="Target"
)

Train/Test Split

from phorecast_ml.preprocessing.dataset_splitting import split_windows

train_windows, test_windows = split_windows(
    windows,
    test_ratio=0.25,
    weeks_in_test=1,
    factor=7,
    distinct=False
)

Dependencies

Primary dependencies:

  • numpy
  • pandas
  • tensorflow
  • keras
  • pvlib

Additional libraries used in the code:

  • scikit-learn (sklearn.linear_model.LinearRegression)

Current Scope

The current implementation focuses on an LSTM-based forecasting model for photovoltaic power prediction.

The repository currently provides tools for:

  • preprocessing photovoltaic time-series data
  • generating training datasets
  • training deep learning forecasting models
  • generating predictions

Future improvements may include:

  • additional forecasting model architectures
  • expanded preprocessing utilities
  • improved documentation
  • additional unit tests

Running Tests

Tests can be executed using:

pytest

Contributing

Contributions are welcome.

Typical improvements include:

  • improving documentation
  • adding new forecasting models
  • improving preprocessing pipelines
  • adding unit tests

Suggested workflow:

fork repository
create feature branch
commit changes
submit pull request

License

This project is licensed under the terms specified in the LICENSE file.

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

phorecast_ml-0.2.2.tar.gz (17.2 kB view details)

Uploaded Source

Built Distribution

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

phorecast_ml-0.2.2-py3-none-any.whl (16.4 kB view details)

Uploaded Python 3

File details

Details for the file phorecast_ml-0.2.2.tar.gz.

File metadata

  • Download URL: phorecast_ml-0.2.2.tar.gz
  • Upload date:
  • Size: 17.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for phorecast_ml-0.2.2.tar.gz
Algorithm Hash digest
SHA256 5583c3d47a184454275dbafa5779a8ca43cb4fbe28117072ed5a332bf1e75b40
MD5 d93cd7352bfdb2bf1c2e29ceb027f744
BLAKE2b-256 785c867122fda924c55f4ada94f1a73d15f0e53a41868ac64610a614883b4b92

See more details on using hashes here.

File details

Details for the file phorecast_ml-0.2.2-py3-none-any.whl.

File metadata

  • Download URL: phorecast_ml-0.2.2-py3-none-any.whl
  • Upload date:
  • Size: 16.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for phorecast_ml-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 e2cc2063a6e9117eda104fb8036046d72fa69f93fd8de32e1ab31163d339d263
MD5 1879d63c6c5e1d80fc2e8a7ee1bfc409
BLAKE2b-256 0c07a70cbb5c0a06babe96cb3a16524d36a8beb444d2da8fd8a4dc4de4823474

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