Metadata-Version: 2.4
Name: pypsa-cl
Version: 0.1.0
Summary: Long-term capacity expansion model of the Chilean National Electricity System (SEN), built on PyPSA
Author: Ministry of Energy of Chile - Unit of Planning and Climate Change
License-Expression: MIT
Project-URL: Homepage, https://github.com/paredes-vergara/PyPSA-CL
Project-URL: Source, https://github.com/paredes-vergara/PyPSA-CL
Project-URL: Issues, https://github.com/paredes-vergara/PyPSA-CL/issues
Project-URL: Changelog, https://github.com/paredes-vergara/PyPSA-CL/blob/main/CHANGELOG.md
Keywords: pypsa,energy,power systems,capacity expansion,energy planning,Chile,PELP
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Science/Research
Classifier: Natural Language :: English
Classifier: Natural Language :: Spanish
Classifier: Operating System :: Microsoft :: Windows
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Topic :: Scientific/Engineering
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: pypsa<1.4,>=1.3
Requires-Dist: linopy<0.10,>=0.9
Requires-Dist: numpy>=1.24
Requires-Dist: pandas>=2.0
Requires-Dist: xarray>=2023.1
Requires-Dist: openpyxl>=3.1
Requires-Dist: psutil>=5.9
Requires-Dist: tkcalendar>=1.6
Requires-Dist: Pillow>=10.0
Provides-Extra: gurobi
Requires-Dist: gurobipy>=11.0; extra == "gurobi"
Provides-Extra: highs
Requires-Dist: highspy>=1.7; extra == "highs"
Dynamic: license-file

# PyPSA-CL — Long-Term Capacity Expansion Model of the Chilean National Electricity System

A long-term generation, storage and transmission capacity expansion model of
Chile's National Electricity System (*Sistema Eléctrico Nacional*, SEN, 234
nodes), built on [PyPSA](https://pypsa.org/). The model was developed for the
Long-Term Energy Planning process (*Planificación Energética de Largo Plazo*,
PELP 2028-2032).

The optimisation co-optimises investment and hourly operation across multiple
representative periods, subject to system-level operating constraints (inertia,
operating reserve), build-rate limits, CO₂ emission caps, unserved-energy limits
and discrete transmission expansion. A detailed hydraulic network couples hydro
generation to water balances, inflows and irrigation.

## Repository layout

```
.
├── src/
│   └── pypsa_cl/        Python package
│       ├── main.py      Entry point and epoch/scenario driver
│       ├── GUI.py       Scenario and epoch configuration interface
│       ├── tools.py     Data loaders, constraints and result exporters
│       ├── cli.py       `pypsa-cl` command
│       └── assets/      GUI images
├── data/                Input workbooks (not tracked; see below)
├── outputs/             Model outputs (generated at run time)
├── pyproject.toml
├── CHANGELOG.md
├── LICENSE
└── README.md
```

## Installation

The model requires Python 3.10 or newer (with Tk, which the standard Windows
installer includes) and a mixed-integer linear programming solver supported by
PyPSA. The open-source [HiGHS](https://highs.dev/) solver is installed
automatically and is the default; [Gurobi](https://www.gurobi.com/) (licence
required), CPLEX and CBC can also be selected. The GUI is developed and tested
on Windows.

### From PyPI

```bash
python -m venv .venv
source .venv/bin/activate        # Windows: .venv\Scripts\activate
pip install pypsa-cl             # with Gurobi: pip install "pypsa-cl[gurobi]"
pypsa-cl                         # downloads the input data on first run, then opens the GUI
```

### From source

```bash
git clone https://github.com/paredes-vergara/PyPSA-CL.git
cd PyPSA-CL
pip install -e .                 # or: pip install -e ".[gurobi]"
```

## Working folder

The model writes its results to an `outputs/` folder inside a *working folder*.
The working folder is:

1. the folder given by the `PYPSA_CL_ROOT` environment variable, if set;
2. otherwise, the current directory if it contains `data/`;
3. otherwise, the repository root when running from a source checkout;
4. otherwise, the current directory.

```
my-pelp-run/
├── data/        Optional: your own copy of the input workbooks (see below)
└── outputs/     Created automatically
```

## Input data

The model reads the following workbooks:

| File                       | Contents                                            |
| -------------------------- | --------------------------------------------------- |
| `Topology.xlsx`            | Buses, lines and generator/storage technical data   |
| `Loads.xlsx`               | Demand time series by node and scenario             |
| `Profiles.xlsx`            | Variable renewable and CSP availability profiles    |
| `Costs.xlsx`               | Fuel prices and generation/storage investment costs |
| `Hydraulic network.xlsx`   | Water nodes, links and reservoirs                   |
| `Water time series.xlsx`   | Inflow and irrigation series                        |
| `Policy levers.xlsx`       | CO₂ tax, coal phase-out and expansion schedules     |

These workbooks (about 245 MB) are too large for the PyPI package, so they are
published separately on Zenodo
([doi:10.5281/zenodo.24204230](https://doi.org/10.5281/zenodo.24204230)) and **downloaded automatically the first time
the model runs**. Each download is checked against its SHA-256 checksum. To
fetch them without starting the model, run `pypsa-cl --download-data`;
`pypsa-cl --data-dir` shows where they are stored.

The data folder is:

1. the folder given by the `PYPSA_CL_DATA_DIR` environment variable, if set;
2. otherwise, the `data/` folder of the working folder, if it exists;
3. otherwise, `~/.pypsa-cl/data-v<data version>` (shared by all working folders).

Workbooks already present in the data folder are used as they are and never
overwritten, so you can run the model with your own modified inputs by placing
all seven workbooks in `data/`. Only missing workbooks are downloaded. The
download source can be changed with the `PYPSA_CL_DATA_URL` environment variable
(a base URL under which the files are served by name).

The GUI header logo and network map ship with the package; files named
`logo_PELP.png` or `sen_network.png` placed in `data/` take precedence.

Disclaimer: Although the data for CSP and hydro ROR candidate generators is present in the Topology file, these candidates were not implemented in this version due to time constraints. These candidates should be implemented in the Final Report version.

## Usage

### Interactive (GUI)

```bash
cd my-pelp-run          # working folder: results go to my-pelp-run/outputs/
pypsa-cl                # equivalent: python -m pypsa_cl
```

The interface lets you queue one or more **global scenarios**, each composed of
one or more **investment epochs**. Preset scenario packages (`E1`-`N3`)
auto-fill and lock the six component selectors (demand, climate, hydrology, fuel
price, generation investment cost, storage investment cost); the *Otro* option
unlocks free configuration. Scenarios can be executed sequentially or in
parallel (one independent process per scenario, with a configurable RAM limit).

### Headless (single scenario)

A single scenario can be run without the GUI by supplying its configuration as
JSON:

```bash
pypsa-cl --scenario-json path/to/scenario.json
```

Output location is controlled by the `PYPSA_CL_OUTPUTS_DIR` environment
variable; when unset, results are written under `outputs/` in the working folder.
Run `pypsa-cl --help` for a summary of the command-line options.

## Versioning

Releases follow the stages of the PELP 2028-2032 process: `0.1.x` corresponds to
the Preliminary Report, `0.2.x` to the Final Report and `1.0.0` to the Definitive
Report. See [CHANGELOG.md](https://github.com/paredes-vergara/PyPSA-CL/blob/main/CHANGELOG.md).

## Outputs

Each run writes the following CSV files to the output folder:

| File                          | Contents                                             |
| ----------------------------- | ---------------------------------------------------- |
| `generation_results.csv`      | Dispatch per asset and snapshot, with reserve, available and curtailment columns |
| `transmission_results.csv`    | Flows per line and snapshot                          |
| `generation_expansion.csv`    | Generation and storage expansion per epoch           |
| `transmission_expansion.csv`  | Transmission expansion per epoch                     |
| `installed_capacity.csv`      | Installed capacity per epoch                          |
| `system_costs.csv`            | System cost breakdown                                |
| `nodal_marginal_prices.csv`   | Nodal marginal prices                                |
| `run_metadata_log.csv`        | Parameters, solver settings and timings per epoch    |
| `progress.json`               | Live run status for monitoring                        |

In multi-scenario runs the outputs are concatenated into the same files, ordered
by scenario and identified by the `global_scenario` column.

## Acknowledgements

Developed by the Unit of Planning and Climate Change (*Unidad de Planificación y
Cambio Climático*), Division of Strategic Planning and Sustainable Development,
Ministry of Energy of Chile.

## License

Released under the MIT License. See [LICENSE](https://github.com/paredes-vergara/PyPSA-CL/blob/main/LICENSE).
