Readers
File reading support functions for PyPSA-China-PIK workflow.
This module provides functions for reading and processing yearly load projections from REMIND data, with support for sector coupling (electric vehicles) and flexible data format handling.
aggregate_sectoral_loads(yearly_proj, config)
Aggregate REMIND load sectors according to the model configuration.
Sectors that are NOT enabled for independent modeling will be aggregated into the main electricity load. For example, if EV sector is not enabled as an independent sector (enabled: false), its load will be added to the AC load in the aggregation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
yearly_proj
|
DataFrame
|
REMIND output with columns ['province', 'sector', '2020', '2025', ...]. Each row represents one sector's load for one province across all years. |
required |
config
|
dict
|
Configuration dict with structure: - sectors.electric_vehicles.enabled: bool (whether to model EV as independent sector) - sectors.sector_mapping.base: list (always-included sectors, e.g., ['ac']) - sectors.sector_mapping.electric_vehicles: list (EV sectors, e.g., ['ev_pass', 'ev_freight']) |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
DataFrame with provinces as index and years as columns, containing total annual |
DataFrame
|
load (MWh) summed across sectors that should be aggregated. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If sector_mapping is missing or no matching sectors found. |
Source code in workflow/scripts/readers.py
read_yearly_load_projections(file_path='resources/data/load/Province_Load_2020_2060.csv', conversion=1.0, config=None)
Read and process yearly load projections from CSV files.
Supports both simple load data and REMIND sector-coupled data with electric vehicle integration. Automatically detects data format and applies appropriate processing.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_path
|
PathLike
|
Path to the yearly projections CSV file. Defaults to "resources/data/load/Province_Load_2020_2060.csv". |
'resources/data/load/Province_Load_2020_2060.csv'
|
conversion
|
float
|
Conversion factor to apply to the data (e.g., to MWh). Defaults to 1.0. |
1.0
|
config
|
dict
|
Configuration dictionary for sector processing. Required when processing REMIND data with sector columns. Should contain 'sectors' and 'sector_mapping' keys. |
None
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
pd.DataFrame: Processed load projections data with: - Province names as index (for simple data) or columns - Year columns as integers - Data converted by the conversion factor |
Raises:
| Type | Description |
|---|---|
ValueError
|
If required columns are missing or configuration is invalid |
FileNotFoundError
|
If the input file does not exist |
Examples:
>>> # REMIND data with electric vehicles
>>> config = {
... "sectors": {"electric_vehicles": True},
... "sector_mapping": {
... "base": ["ac"],
... "electric_vehicles": ["ev_freight", "ev_pass"]
... }
... }
>>> data = read_yearly_load_projections("remind_data.csv", config=config)