transforms.costs
Transform IAM techno-economic output into PyPSA cost tables.
Based on the technology mapping, extract cost parameters from the IAM output, from PyPSA costs or directly set them from values specified in the mapping.
The extraction of individual cost parameters is source-specific and lives in each Coupler subclass.
The shared functions (which live here) — provide the conversion/mapping and merging tools.
Unit factors are centrally defined in iampypsa.units (re-exported below
for convenience) so any IAM or PyPSA coupler can swap the conversion table without touching transforms.
add_discount_rate(costs, discount_rate, *, source='IAM', reference='p_r')
¶
Add a discount rate row for every technology that does not already have one.
source/reference annotate provenance; pass them through from the Coupler's config
so the same transform serves any IAM without code edits.
Source code in src/iampypsa/transforms/costs.py
annotate_cost_rows(costs, *, parameter, unit, factor=1.0)
¶
Annotate parameter/unit onto a cost-row frame, optionally scaling value by factor.
Source code in src/iampypsa/transforms/costs.py
apply_overrides(costs, overrides)
¶
Update and insert overrides onto costs by (technology, parameter).
Rows whose key is absent from costs are added; for keys present in both,
value/unit/source/further description are overwritten from overrides.
Source code in src/iampypsa/transforms/costs.py
broadcast_fuel_prices(costs, tech_fuel_map, *, tech_col='technology', param_col='parameter')
¶
Turn per-fuel fuel price rows into one fuel row per technology.
Each technology in tech_fuel_map (canonical technology → fuel) gets a copy of its
fuel's price row; technologies absent from the map get a synthesized fuel: 0 row (they
consume no priced primary-energy carrier). No-op when the map is absent.
Source code in src/iampypsa/transforms/costs.py
build_fixed_value_overrides(technology_mapping, *, source='fixed')
¶
Return overrides for technology-mapping entries with a fixed-value spec.
A "fixed-value" entry is one whose per-parameter source is a dict of the shape
{value: <number>, unit: <str>, comment: <str>}, setting a fixed value directly.
unit and comment are optional and default to "".
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
technology_mapping
|
Mapping[str, Any]
|
The parsed technology-mapping YAML (carrier → spec). |
required |
source
|
str
|
Value to write into the output |
'fixed'
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
Long frame |
Source code in src/iampypsa/transforms/costs.py
build_iam_techdata(technology_mapping, iam_costs_long, *, source='IAM')
¶
Map IAM-sourced parameter values onto target carriers, keeping the region dimension.
Flattens technology_mapping (via build_technology_sources), keeps the IAM entries,
and merges each (canonical, parameter) against iam_costs_long. Raises if an
IAM-declared entry has no matching data — those must be declared PyPSA or
{value: ...} instead. Tags provenance columns consumed by apply_overrides.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
technology_mapping
|
Mapping[str, Any]
|
The parsed technology-mapping YAML (carrier → spec). |
required |
iam_costs_long
|
DataFrame
|
Long-format IAM cost table with columns
|
required |
source
|
str
|
Value to write into the output |
'IAM'
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
Long frame |
Source code in src/iampypsa/transforms/costs.py
build_pypsa_techdata(technology_mapping, pypsa_costs_long, *, source='PyPSA')
¶
Pull values from the model's own baseline cost table for PyPSA entries.
Silently drops (technology, parameter) pairs absent from pypsa_costs_long — a
structurally-expected gap (e.g. no fuel cost for storage) filled later via
prepare_costs's fill_values, not a real override.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
technology_mapping
|
Mapping[str, Any]
|
The parsed technology-mapping YAML (carrier → spec). |
required |
pypsa_costs_long
|
DataFrame
|
The PyPSA model's own long-format baseline cost table, columns
|
required |
source
|
str
|
Value to write into the output |
'PyPSA'
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
Long frame |
Source code in src/iampypsa/transforms/costs.py
convert_investment_to_input_capacity_basis(costs, eta_exponents=DEFAULT_ETA_EXPONENTS)
¶
Convert per-output-kW investment to per-input-kW by multiplying by efficiency**exp.
Some IAMs report investment per kW of output capacity; PyPSA needs per kW of input
(p_nom). For each technology in eta_exponents, investment is multiplied by
efficiency ** exp (exp=1 uses eta directly; exp=0.5 takes the one-way value out of a
pre-squared round-trip efficiency).