io.iamc
Read REMIND/IAM output from the IAMC .mif exchange format.
An .mif is a ;-separated table with five id columns
Model;Scenario;Region;Variable;Unit followed by one column per year; rows are one
variable × region combination. A trailing ; in each line produces a spurious unnamed
column, which is dropped on read. All five id columns are lower-cased on import so callers
reference them uniformly as model, scenario, region, variable, unit.
assemble_variable_set is the generic layer between the IAMC long frame and the
token-labelled frames the Coupler classes consume. It knows nothing about REMIND — it
receives a mapping dict (variable → token label) and an optional derived dict for
linear combinations (e.g. pc = Coal|w/o CC − IGCC − CHP).
assemble_variable_set(df, mapping, *, label_col='technology', derived=None, to_unit=None)
¶
Map IAMC variables to token labels and compute derived linear combinations.
Generic — no REMIND-specific knowledge. Receives a long IAMC frame (from
read_iamc) plus caller-supplied mappings, returns
[year, region, <label_col>, value, unit].
Parameters¶
df:
Long IAMC frame with [region, variable, unit, year, value] columns.
mapping:
{variable_name: token_label} — direct one-to-one assignments.
label_col:
Column name for the output token column ("technology" by default).
derived:
{token: [(coefficient, variable_name), ...]} — linear combinations built from
variables in df (which may also appear in mapping). Missing component
variables propagate NaN (the row is dropped).
to_unit:
Target unit string. Source unit is read homogeneously from the unit column of
df; unit_factor(src, to_unit) is applied. Pass None to keep the
source unit unchanged.
Returns¶
pd.DataFrame
[year, region, <label_col>, value, unit], sorted by year/region/token.
Source code in src/iampypsa/io/iamc.py
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 | |
list_iamc_variables(path, sep=';')
¶
List the IAMC variable names present in a .mif file (sorted).
Source code in src/iampypsa/io/iamc.py
parse_currency_year(unit)
¶
Extract the reference year from a unit string such as 'US$2017/kW' → 2017.
Building block for future automatic currency-year handling (deflating IAMC cost units to a common reference year). Not yet wired into the cost pipeline.
Source code in src/iampypsa/io/iamc.py
read_iamc(path, variables=None, sep=';')
¶
Read an IAMC .mif file into a tidy long DataFrame.
Returns columns [model, scenario, region, variable, unit, year, value]; NA
entries and rows with NaN value are dropped. Pass variables to filter early
(before the expensive melt) on the ~167k-row files typical of REMIND output.