Code and data for "Coupling rooftop photovoltaics with electric vehicle charging accelerates decarbonisation"
This repository contains the implementation and data for our research.
- π EV Charging Demand Prediction Models: LSTM, ARIMA, and baseline models (FCNN, FGN) for forecasting electric vehicle charging patterns
- π Multi-City Dataset: Charging behavior data from 40+ cities worldwide
- π Meta-Learning Framework: Implementation of meta-learning approaches for cross-city charging demand prediction
- β‘ Baseline Comparisons: Multiple baseline models for comprehensive performance evaluation
- Multi-Model Approach: Implements LSTM, ARIMA, FCNN, FGN, and meta-learning variants
- Global Dataset: Covers diverse charging patterns across different cities and climates
- Meta-Learning: Cross-city knowledge transfer for improved prediction accuracy
- Comprehensive Evaluation: Multiple baseline models for robust performance comparison
- Python β₯ 3.8
- See
requirements.txtfor the complete list of Python package dependencies
- Windows 10/11
- macOS 10.15 or higher
- Linux (Ubuntu 18.04 or higher)
- Python 3.8.10
- PyTorch 1.9.0
- CUDA 11.1 (for GPU acceleration)
- Minimum: 8GB RAM, 4GB free disk space
- Recommended: 16GB RAM, 8GB free disk space
- GPU: NVIDIA GPU with CUDA support (optional, for faster training)
- Install Python 3.8+ from python.org
- Install Git from git-scm.com
-
Clone the repository:
git clone https://github.com/IntelligentSystemsLab/SolarCityEV.git cd SolarCityEV -
Create a virtual environment (recommended):
python -m venv venv # On Windows: venv\Scripts\activate # On macOS/Linux: source venv/bin/activate
-
Install dependencies:
# Option 1: Install from requirements.txt (recommended) pip install -r requirements.txt # Option 2: Install PyTorch separately (if needed) pip install torch torchvision torchaudio
-
Verify installation:
python -c "import torch; print(torch.__version__)"
- On a normal desktop computer (8GB RAM, SSD): 5-10 minutes
- On a slower machine (4GB RAM, HDD): 10-15 minutes
Option 1: Using the shell script (Recommended)
# Make the script executable (first time only, on macOS/Linux)
chmod +x run.sh
# Run with default parameters (London, 300 epochs)
./run.sh
# Run with custom parameters
./run.sh --city London --epochs 100 --lr 0.001
# Run with multiple cities and divide modes
./run.sh --city London Paris NewYork --divide_mode by_month by_day
# See all available options
./run.sh --helpNote: On Windows, you can use Git Bash or WSL to run the shell script, or use Option 2 (Python directly).
Option 2: Using Python directly
# From project root directory
python code/run.py
# With custom parameters
python code/run.py --city London --epochs 100 --support_epochs 5 --lr 0.005
# With multiple cities and divide modes
python code/run.py --city London Paris --divide_mode by_month by_day --epochs 100
# See all available options
python code/run.py --help--city: City name(s) in English (default: London). Can specify multiple cities. Available cities include: London, Warsaw, Washington, Copenhagen, SaoPaulo, Melbourne, Toronto, Oslo, Paris, Sydney, Munich, Stockholm, SanFrancisco, Berlin, LosAngeles, Shenzhen, Ottawa, Honolulu, TelAviv, Milan, Johannesburg, NewYork, Vienna, Rome, Zurich, Montreal, Seattle, Helsinki, Miami, Dubai, Dublin, Amsterdam, Athens, Reykjavik, Madrid, Boston, etc.- Example:
--city Londonor--city London Paris NewYork
- Example:
--epochs: Number of training epochs (default: 300)--support_epochs: Number of support epochs (default: 5)--custom_epochs: Number of custom epochs (default: 5)--lr: Learning rate (default: 0.005)--divide_mode: Data division mode(s) (default: by_month). Can specify multiple modes:by_monthand/orby_day- Example:
--divide_mode by_monthor--divide_mode by_month by_day
- Example:
--folder_path: Data folder path (default: charging_data/by_station)--seed: Random seed for reproducibility (default: 2023)--batch_size: Batch size (default: None, uses default batch size)--print_details: Print detailed training information
Note: When multiple cities and/or divide_modes are specified, the script will iterate over all combinations. For example, --city London Paris --divide_mode by_month by_day will run 4 experiments (2 cities Γ 2 modes).
The demo will:
- Display a formatted header with configuration summary
- Show progress for each experiment (e.g., "Experiment 1/4")
- Load charging data from specific cities (e.g., London)
- Train meta-learning models with LSTM architecture
- Display training progress with tqdm progress bars
- Show evaluation metrics after each experiment
- Display a summary table at the end with all experiment results
- Save results to
results/directory - Generate log files with detailed results in
results/log_desktop.txt
Example output format:
================================================================================
Meta-Learning Training for EV Charging Demand Prediction
================================================================================
π
Start Time: 2025-01-12 18:30:00
π Configuration:
Cities: London (1 city/cities)
...
================================================================================
π¬ Experiment 1/1
City: London (δΌ¦ζ¦)
Divide Mode: by_month
================================================================================
...
β
Experiment 1/1 completed in 15m 30s
Metrics (RMSE, MAE, MAPE, MedAE, R2, EVS): [0.123, ...]
================================================================================
Experiment Summary
================================================================================
...
- On a normal desktop computer (8GB RAM, CPU): 15-30 minutes
- With GPU acceleration: 5-10 minutes
- On a slower machine (4GB RAM): 30-60 minutes
-
Prepare your data:
- Place your data files in the
data/directory - Follow the same format as the existing data files
- Ensure data is properly formatted (see data format section below)
- Place your data files in the
-
Configure parameters:
- Use command-line arguments (recommended):
--city,--epochs,--lr, etc. - Or modify hyperparameters in
code/model/train.pyfor advanced customization
- Use command-line arguments (recommended):
-
Run training:
# Using shell script (from project root) ./run.sh --city London --epochs 300 # Or using Python directly python code/run.py --city London --epochs 300
-
Run specific models:
# Run ARIMA baseline cd code python run_arima.py # Run all baseline models (FCNN, FGN, etc.) python run_baselines.py # Run main meta-learning training with custom parameters python run.py --city London --epochs 300 --lr 0.005
Your data should be in NumPy format (.npy files) with the following structure:
- Training data:
train_data.npy - Test data:
test_data.npy - Data shape: (samples, features, time_steps)
- Edit
code/model/train.pyfor LSTM model parameters - Modify
code/run_arima.pyfor ARIMA model settings - Update
code/run_baselines.pyfor baseline model configurations
All output files are saved in the results/ directory:
- Model checkpoints:
results/model/pt_files/(if model saving is enabled) - Prediction results:
results/data/pre_result_<divide_mode>/<city>_<timestamp>.csv - Baseline results:
results/baselines/<baseline_name>/<city>_<timestamp>.csv - Training logs:
results/log_desktop.txt(main training log) - Baseline logs:
results/log_<baseline>_test.txtorresults/log_<baseline>.txt
-
Download the complete dataset:
- Ensure all city data is present in
data/charging_data/by_station/ - Verify data integrity and format
- Ensure all city data is present in
-
Run the complete experiment:
# From project root directory ./run.sh --city London --epochs 300 # Or using Python directly python code/run.py --city London --epochs 300
-
Generate all baseline comparisons:
# From project root directory cd code python run_baselines.py
-
Run ARIMA experiments:
# From project root directory cd code python run_arima.py
- All quantitative results from the manuscript should be reproducible
- Model performance metrics will be displayed in the console
- Figures and visualizations will be saved automatically
- Results will match the values reported in the paper (within small numerical precision differences)
- If you encounter memory issues, reduce batch size in model configuration
- For GPU issues, ensure CUDA is properly installed and compatible
- Check data format if loading errors occur
This project is licensed under the MIT License - see the LICENSE file for details.
For questions or issues, please open an issue on GitHub.