Skip to content

NRCan/pypsa-canada

PyPSA-Canada

Keywords

Python, Optimization, Linopy, Power Systems

Project Description

pypsa_canada is a workflow-based modeling framework for power system analysis in Canada, built on top of PyPSA (Python for Power System Analysis). This tool enables comprehensive energy system optimization and planning for Canadian electricity grids.

Key Features:

  • Scenario-based modeling: Define and run multiple power system scenarios with customizable configurations
  • Multi-temporal analysis: Support for both long-term planning and operational dispatch modeling
  • Representative days: Efficient modeling using representative time periods to reduce computational complexity
  • Flexible network modeling: Model power systems at various spatial scales (national, provincial, regional)
  • Component integration: Handle diverse energy system components including generators, storage units, loads, and transmission links
  • Cost optimization: Incorporate detailed capital, operational, and fuel cost data with multiple cost scenarios
  • Constraint management: Apply custom constraints including capacity limits, emission targets, and policy requirements
  • Workflow automation: Snakemake-based pipeline for reproducible and scalable analysis

This framework has been applied to analyze Canadian power system scenarios including the Atlantic Loop initiative and Saskatchewan grid integration.

Usage

Overview

pypsa_canada provides a command-line interface to run power system optimization workflows. The tool processes scenario configuration files (YAML) and executes a series of automated tasks including network creation, data loading, constraint application, and optimization solving.

Basic Workflow

The typical workflow involves:

  1. Prepare input data: Network components (buses, generators, loads, etc.), cost data, and constraints
  2. Define scenario: Create a YAML configuration file specifying model parameters and assumptions
  3. Run optimization: Execute the workflow using the CLI
  4. Analyze results: Review outputs including optimal dispatch, capacity expansion, and system costs

Command-Line Interface

Run a scenario with:

pypsa_canada run -f config/[your-scenario].yaml

Available example scenarios in the example/scenarios/ directory:

  • minimal_model.yaml: Minimal network used for testing purposes

Advanced Options

  • Unlock stale workflows: If a previous run was interrupted, unlock with:
    pypsa_canada run -f scenarios/[scenario].yaml --unlock
  • View workflow graph: Visualize the computational workflow (requires additional setup by installing graphviz)
    pypsa_canada dag -f scenarios/[scenario].yaml

Data Organization

  • data/: Input data including network components, costs, and constraints
  • config/: YAML configuration files defining model scenarios
  • ressources/: Intermediate network files generated during workflow
  • results/: Optimization results and outputs

Installation

Before starting the installation process: 0. Clone the following project/library pypsa_canada: For GitHub users:

$ git clone https://github.com/NRCan/pypsa-canada.git

For NRCAN internal users:

$ git clone https://nrcan-eets-cev-renouvelable-devops@dev.azure.com/nrcan-eets-cev-renouvelable-devops/Canadian_Scenarios_Analysis/_git/pypsa_canada
  1. Create the virtual environment with either Conda or Python with Python 3.11

1-a) **For Anaconda/Miniconda users only, create a virtual environment with the following command:

$(base) conda create --name pypsa_cad_p312 python=3.12.10

1-b) **For Python users only, assuming you have a Python 3.12 installed, execute the following command to create a new virtual environment:

$(base) python -m venv pypsa_cad_p312

1-b) Proceed to activate the environment

  1. Go into the project folder
(env)  >> cd [PROJECT_DIR]
  1. Install the package/library:
(pypsa-cad_py312)  >> pip install -e .[dev]

Following these steps, most dependencies should be installed and you should be able to use pypsa_canada

Example (From the project folder)

  1. Go into the project folder
(env)  >> cd [ROOT_DIR]/example
  1. To execute an example
(pypsa-cad_py312)  >> pypsa_canada run -f scenarios\Canada-National-no-CER.yaml
  1. If the process is stale, you will need to unlock it with the following command
(pypsa-cad_py312)  >> pypsa_canada run -f scenarios\Canada-National-no-CER.yaml --unlock

Developers

Pre-commit hooks are used within this project. The pre-commit hooks will be enforced through a pipeline during the pull request (PR). If it fails, the PR will be rejected. To validate if your changes are meeting the minimum standard, you should execute the following. If there are any issues, resolve them and commit again.

(pypsa-canada_py312)  >> pre-commit run --all-files --hook-stage manual

Licence

PyPSA MIT License : https://github.com/PyPSA/PyPSA/blob/master/LICENSE.txt pypsa-eur License: https://github.com/PyPSA/pypsa-eur/tree/master/LICENSES

Rights

Copyright CanmetENERGY - Varennes, NRCan, Goverment of Canada

Authors

  • Steven Wong (Natural Resources Canada - CanmetENERGY)
  • Nathan De Matos (Natural Resources Canada - CanmetENERGY)
  • Michel Bui (Natural Resources Canada - CanmetENERGY)
  • Sophie Pelland (Natural Resources Canada - CanmetENERGY)
  • Matheus Zambroni De Souza (Natural Resources Canada - CanmetENERGY)
  • Adrien Prigent (Natural Resources Canada - CanmetENERGY)
  • Serban Ivanescu (Natural Resources Canada - CanmetENERGY)

Contact Information

Getting Further Information

https://pypsa.readthedocs.io/en/latest/index.html

About

No description, website, or topics provided.

Resources

License

Code of conduct

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages