Skip to content

Commit 14979f5

Browse files
committed
interpolation_mode parameter for technodata
1 parent a2db431 commit 14979f5

3 files changed

Lines changed: 16 additions & 3 deletions

File tree

docs/inputs/toml.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,13 @@ A sector accepts these attributes:
292292

293293
Defaults to "last".
294294

295+
*interpolation*
296+
Interpolation method used to fill missing years in the *technodata* (defaults to "linear").
297+
Available interpolation methods depend on the underlying `scipy method's kind attribute`_.
298+
Years outside the data range will always be back/forward filled with the closest available data.
299+
300+
.. _scipy method's kind attribute: https://docs.scipy.org/doc/scipy/reference/generated/scipy.interpolate.interp1d.html
301+
295302
*dispatch_production*
296303
The method used to calculate supply of commodities after investments have been made.
297304

src/muse/readers/toml.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -646,7 +646,7 @@ def read_technodata(
646646
time_framework: Sequence[int] | None = None,
647647
commodities: str | Path | None = None,
648648
regions: Sequence[str] | None = None,
649-
**kwargs,
649+
interpolation_mode: str = "linear",
650650
) -> xr.Dataset:
651651
"""Helper function to create technodata for a given sector."""
652652
from muse.readers.csv import read_technologies, read_trade
@@ -741,5 +741,5 @@ def read_technodata(
741741
technologies["year"] = "year", years
742742

743743
year = sorted(set(time_framework).union(technologies.year.data.tolist()))
744-
technologies = technologies.interp(year=year, **kwargs)
744+
technologies = technologies.interp(year=year, method=interpolation_mode)
745745
return technologies

src/muse/sectors/sector.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,15 @@ def factory(cls, name: str, settings: Any) -> Sector:
3737
raise RuntimeError(f"Missing 'subsectors' section in sector {name}")
3838
if len(sector_settings["subsectors"]._asdict()) == 0:
3939
raise RuntimeError(f"Empty 'subsectors' section in sector {name}")
40+
interpolation_mode = sector_settings.pop("interpolation_mode", "linear")
4041

4142
# Read technologies
42-
technologies = read_technodata(settings, name, settings.time_framework)
43+
technologies = read_technodata(
44+
settings,
45+
name,
46+
settings.time_framework,
47+
interpolation_mode=interpolation_mode,
48+
)
4349

4450
# Create subsectors
4551
subsectors = [

0 commit comments

Comments
 (0)