Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@
"module": "muse",
"args": ["--model", "multiple_agents"]
},
{
"name": "Model: default_timeslice",
"type": "python",
"request": "launch",
"module": "muse",
"args": ["--model", "default_timeslice"]
},
{
"name": "model/settings.toml",
"type": "debugpy",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
ProcessName,RegionName,Time,ObjSort,month,day,hour,UtilizationFactor,MinimumServiceFactor
Unit,-,Year,-,-,-,-,-,-
gasCCGT,R1,2020,upper,all-year,all-week,night,1,1
gasCCGT,R1,2020,upper,all-year,all-week,morning,1,2
gasCCGT,R1,2020,upper,all-year,all-week,afternoon,1,3
gasCCGT,R1,2020,upper,all-year,all-week,early-peak,1,4
gasCCGT,R1,2020,upper,all-year,all-week,late-peak,1,5
gasCCGT,R1,2020,upper,all-year,all-week,evening,1,6
gasCCGT,R1,2020,upper,all-year,all-week,morning,1,1
gasCCGT,R1,2020,upper,all-year,all-week,afternoon,1,1
gasCCGT,R1,2020,upper,all-year,all-week,early-peak,1,1
gasCCGT,R1,2020,upper,all-year,all-week,late-peak,1,1
gasCCGT,R1,2020,upper,all-year,all-week,evening,1,1
windturbine,R1,2020,upper,all-year,all-week,night,1,1
windturbine,R1,2020,upper,all-year,all-week,morning,1,1
windturbine,R1,2020,upper,all-year,all-week,afternoon,1,1
Expand Down
11 changes: 7 additions & 4 deletions src/muse/investments.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,12 +346,15 @@ def scipy_match_demand(
},
)
if not res.success:
getLogger(__name__).critical(res.message)
print(f"in sector containing {df_technologies.technology[0]}")
msg = (
res.message
+ "\n"
+ f"Error in sector containing {df_technologies.technology.unique()}"
)
getLogger(__name__).critical(msg)
raise GrowthOfCapacityTooConstrained

solution = cast(Callable[[np.ndarray], xr.Dataset], adapter.to_muse)(res.x)
return solution
return cast(Callable[[np.ndarray], xr.Dataset], adapter.to_muse)(res.x)


@register_investment(name=["cvxopt"])
Expand Down
35 changes: 24 additions & 11 deletions src/muse/objectives.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,25 @@ def efficiency(
return result


def _represent_hours(market: xr.Dataset, search_space: xr.DataArray) -> xr.DataArray:
"""Retrieves the appropriate value for represent_hours.

Args:
market: The simulation market.
search_space: The search space for new tehcnologies.

Returns:
DataArray with the hours of each timeslice.
"""
from muse.timeslices import represent_hours

if "represent_hours" in market:
return market.represent_hours
if "represent_hours" in search_space.coords:
return search_space.represent_hours
return represent_hours(market.timeslice)


@register_objective(name="capacity")
def capacity_to_service_demand(
agent: Agent,
Expand All @@ -240,21 +259,13 @@ def capacity_to_service_demand(
**kwargs,
) -> xr.DataArray:
"""Minimum capacity required to fulfill the demand."""
from muse.timeslices import represent_hours

params = agent.filter_input(
technologies[["utilization_factor", "fixed_outputs"]],
year=agent.forecast_year,
region=agent.region,
technology=search_space.replacement,
).drop_vars("technology")
if "represent_hours" in market:
hours = market.represent_hours
elif "represent_hours" in search_space.coords:
hours = search_space.represent_hours
else:
hours = represent_hours(market.timeslice)

hours = _represent_hours(market, search_space)
max_hours = hours.max() / hours.sum()

commodity_output = params.fixed_outputs.sel(commodity=demand.commodity)
Expand Down Expand Up @@ -544,7 +555,9 @@ def lifetime_levelized_cost_of_energy(
):
"""Levelized cost of energy (LCOE) of technologies over their lifetime.

It follows the `simplified LCOE` given by NREL.
It follows the `simplified LCOE` given by NREL. The LCOE is set to zero for those
timeslices where the production is zero, normally due to a zero utilisation
factor.

Arguments:
agent: The agent of interest
Expand Down Expand Up @@ -669,7 +682,7 @@ def lifetime_levelized_cost_of_energy(
+ fixed_and_variable_costs
) / (denominator.sel(commodity=products).sum("commodity") * rates).sum("year")

return results
return results.where(np.isfinite(results)).fillna(0.0)


@register_objective(name="NPV")
Expand Down
18 changes: 7 additions & 11 deletions src/muse/readers/csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -913,16 +913,12 @@ def check_utilization_not_all_zero(data, filename):
"""A technology needs to have a utilization factor defined for every
timeslice. Please check file {}.""".format(filename)
)
else:
utilization_sum = data.groupby(["technology", "region", "year"]).sum()

# Add small value to 0 utilization factors to avoid numerical problems
if utilization_sum.utilization_factor.any() == 0:
data.loc[data.utilization_factor == 0, "utilization_factor"] = (
data.loc[data.utilization_factor == 0, "utilization_factor"] + 0.01
)
raise ValueError(
"""A technology can not have a utilization factor of 0 for every
timeslice. Please check file {}.""".format(filename)
)
utilization_sum = data.groupby(["technology", "region", "year"]).sum()

if (utilization_sum.utilization_factor == 0).any():
raise ValueError(
"""A technology can not have a utilization factor of 0 for every
timeslice. Please check file {}.""".format(filename)
)
return data
14 changes: 7 additions & 7 deletions tests/example_outputs/default_timeslice/Gas/Capacity/2020.csv
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
asset,year,region,installed,technology,capacity
0,2020,R1,2020,gassupply1,15.00000000000
0,2025,R1,2020,gassupply1,71.09630000000
0,2030,R1,2020,gassupply1,63.59630000000
0,2035,R1,2020,gassupply1,56.09630000000
0,2040,R1,2020,gassupply1,56.09630000000
0,2045,R1,2020,gassupply1,56.09630000000
0,2050,R1,2020,gassupply1,56.09630000000
0,2059,R1,2020,gassupply1,56.09630000000
0,2025,R1,2020,gassupply1,17.57780000000
0,2030,R1,2020,gassupply1,10.07780000000
0,2035,R1,2020,gassupply1,2.57780000000
0,2040,R1,2020,gassupply1,2.57780000000
0,2045,R1,2020,gassupply1,2.57780000000
0,2050,R1,2020,gassupply1,2.57780000000
0,2059,R1,2020,gassupply1,2.57780000000
14 changes: 7 additions & 7 deletions tests/example_outputs/default_timeslice/Gas/Capacity/2025.csv
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
asset,year,region,installed,technology,capacity
0,2025,R1,2020,gassupply1,71.09630000000
0,2030,R1,2020,gassupply1,63.59630000000
0,2035,R1,2020,gassupply1,56.09630000000
0,2040,R1,2020,gassupply1,56.09630000000
0,2045,R1,2020,gassupply1,56.09630000000
0,2050,R1,2020,gassupply1,56.09630000000
0,2059,R1,2020,gassupply1,56.09630000000
0,2025,R1,2020,gassupply1,17.57780000000
0,2030,R1,2020,gassupply1,10.07780000000
0,2035,R1,2020,gassupply1,2.57780000000
0,2040,R1,2020,gassupply1,2.57780000000
0,2045,R1,2020,gassupply1,2.57780000000
0,2050,R1,2020,gassupply1,2.57780000000
0,2059,R1,2020,gassupply1,2.57780000000
19 changes: 13 additions & 6 deletions tests/example_outputs/default_timeslice/Gas/Capacity/2030.csv
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
asset,year,region,installed,technology,capacity
0,2030,R1,2020,gassupply1,63.59630000000
0,2035,R1,2020,gassupply1,56.09630000000
0,2040,R1,2020,gassupply1,56.09630000000
0,2045,R1,2020,gassupply1,56.09630000000
0,2050,R1,2020,gassupply1,56.09630000000
0,2059,R1,2020,gassupply1,56.09630000000
0,2030,R1,2020,gassupply1,10.07780000000
0,2035,R1,2020,gassupply1,2.57780000000
0,2040,R1,2020,gassupply1,2.57780000000
0,2045,R1,2020,gassupply1,2.57780000000
0,2050,R1,2020,gassupply1,2.57780000000
0,2059,R1,2020,gassupply1,2.57780000000
1,2035,R1,2030,gassupply1,2.70670000000
1,2040,R1,2030,gassupply1,2.70670000000
1,2045,R1,2030,gassupply1,2.70670000000
1,2050,R1,2030,gassupply1,2.70670000000
1,2059,R1,2030,gassupply1,2.70670000000
1,2060,R1,2030,gassupply1,2.70670000000
1,2069,R1,2030,gassupply1,2.70670000000
17 changes: 12 additions & 5 deletions tests/example_outputs/default_timeslice/Gas/Capacity/2035.csv
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
asset,year,region,installed,technology,capacity
0,2035,R1,2020,gassupply1,56.09630000000
0,2040,R1,2020,gassupply1,56.09630000000
0,2045,R1,2020,gassupply1,56.09630000000
0,2050,R1,2020,gassupply1,56.09630000000
0,2059,R1,2020,gassupply1,56.09630000000
0,2035,R1,2020,gassupply1,2.57780000000
0,2040,R1,2020,gassupply1,2.57780000000
0,2045,R1,2020,gassupply1,2.57780000000
0,2050,R1,2020,gassupply1,2.57780000000
0,2059,R1,2020,gassupply1,2.57780000000
1,2035,R1,2030,gassupply1,2.70670000000
1,2040,R1,2030,gassupply1,2.70670000000
1,2045,R1,2030,gassupply1,2.70670000000
1,2050,R1,2030,gassupply1,2.70670000000
1,2059,R1,2030,gassupply1,2.70670000000
1,2060,R1,2030,gassupply1,2.70670000000
1,2069,R1,2030,gassupply1,2.70670000000
14 changes: 10 additions & 4 deletions tests/example_outputs/default_timeslice/Gas/Capacity/2040.csv
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
asset,year,region,installed,technology,capacity
0,2040,R1,2020,gassupply1,56.09630000000
0,2045,R1,2020,gassupply1,56.09630000000
0,2050,R1,2020,gassupply1,56.09630000000
0,2059,R1,2020,gassupply1,56.09630000000
0,2040,R1,2020,gassupply1,2.57780000000
0,2045,R1,2020,gassupply1,2.57780000000
0,2050,R1,2020,gassupply1,2.57780000000
0,2059,R1,2020,gassupply1,2.57780000000
1,2040,R1,2030,gassupply1,2.70670000000
1,2045,R1,2030,gassupply1,2.70670000000
1,2050,R1,2030,gassupply1,2.70670000000
1,2059,R1,2030,gassupply1,2.70670000000
1,2060,R1,2030,gassupply1,2.70670000000
1,2069,R1,2030,gassupply1,2.70670000000
11 changes: 8 additions & 3 deletions tests/example_outputs/default_timeslice/Gas/Capacity/2045.csv
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
asset,year,region,installed,technology,capacity
0,2045,R1,2020,gassupply1,56.09630000000
0,2050,R1,2020,gassupply1,56.09630000000
0,2059,R1,2020,gassupply1,56.09630000000
0,2045,R1,2020,gassupply1,2.57780000000
0,2050,R1,2020,gassupply1,2.57780000000
0,2059,R1,2020,gassupply1,2.57780000000
1,2045,R1,2030,gassupply1,2.70670000000
1,2050,R1,2030,gassupply1,2.70670000000
1,2059,R1,2030,gassupply1,2.70670000000
1,2060,R1,2030,gassupply1,2.70670000000
1,2069,R1,2030,gassupply1,2.70670000000
11 changes: 8 additions & 3 deletions tests/example_outputs/default_timeslice/Gas/Capacity/2050.csv
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
asset,year,region,installed,technology,capacity
0,2050,R1,2020,gassupply1,56.09630000000
0,2055,R1,2020,gassupply1,56.09630000000
0,2059,R1,2020,gassupply1,56.09630000000
0,2050,R1,2020,gassupply1,2.57780000000
0,2055,R1,2020,gassupply1,2.57780000000
0,2059,R1,2020,gassupply1,2.57780000000
1,2050,R1,2030,gassupply1,2.70670000000
1,2055,R1,2030,gassupply1,2.70670000000
1,2059,R1,2030,gassupply1,2.70670000000
1,2060,R1,2030,gassupply1,2.70670000000
1,2069,R1,2030,gassupply1,2.70670000000
16 changes: 10 additions & 6 deletions tests/example_outputs/default_timeslice/MCACapacity.csv
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,30 @@ A1,5.00000000000,R1,0,2020,R1,residential,gasboiler,retrofit,2025
A1,19.00000000000,R1,16,2020,R1,residential,heatpump,retrofit,2025
A1,1.00000000000,R1,0,2020,R1,power,gasCCGT,retrofit,2025
A1,1.10000000000,R1,9,2020,R1,power,windturbine,retrofit,2025
A1,71.09630000000,R1,0,2020,R1,gas,gassupply1,retrofit,2025
A1,17.57780000000,R1,0,2020,R1,gas,gassupply1,retrofit,2025
A1,4.10000000000,R1,0,2025,R1,residential,gasboiler,retrofit,2030
A1,19.00000000000,R1,8,2020,R1,residential,heatpump,retrofit,2030
A1,6.90000000000,R1,9,2025,R1,residential,heatpump,retrofit,2030
A1,1.10000000000,R1,0,2020,R1,power,windturbine,retrofit,2030
A1,1.54330000000,R1,1,2025,R1,power,windturbine,retrofit,2030
A1,63.59630000000,R1,0,2020,R1,gas,gassupply1,retrofit,2030
A1,10.07780000000,R1,0,2020,R1,gas,gassupply1,retrofit,2030
A1,4.10000000000,R1,0,2025,R1,residential,gasboiler,retrofit,2035
A1,6.90000000000,R1,14,2025,R1,residential,heatpump,retrofit,2035
A1,25.00000000000,R1,15,2030,R1,residential,heatpump,retrofit,2035
A1,1.10000000000,R1,0,2020,R1,power,windturbine,retrofit,2035
A1,1.54330000000,R1,1,2025,R1,power,windturbine,retrofit,2035
A1,1.68610000000,R1,2,2030,R1,power,windturbine,retrofit,2035
A1,56.09630000000,R1,0,2020,R1,gas,gassupply1,retrofit,2035
A1,2.57780000000,R1,0,2020,R1,gas,gassupply1,retrofit,2035
A1,2.70670000000,R1,1,2030,R1,gas,gassupply1,retrofit,2035
A1,0.91000000000,R1,0,2035,R1,residential,gasboiler,retrofit,2040
A1,25.00000000000,R1,7,2030,R1,residential,heatpump,retrofit,2040
A1,16.09000000000,R1,8,2035,R1,residential,heatpump,retrofit,2040
A1,1.10000000000,R1,0,2020,R1,power,windturbine,retrofit,2040
A1,1.54330000000,R1,1,2025,R1,power,windturbine,retrofit,2040
A1,1.68610000000,R1,2,2030,R1,power,windturbine,retrofit,2040
A1,2.01780000000,R1,3,2035,R1,power,windturbine,retrofit,2040
A1,56.09630000000,R1,0,2020,R1,gas,gassupply1,retrofit,2040
A1,2.57780000000,R1,0,2020,R1,gas,gassupply1,retrofit,2040
A1,2.70670000000,R1,1,2030,R1,gas,gassupply1,retrofit,2040
A1,0.91000000000,R1,0,2035,R1,residential,gasboiler,retrofit,2045
A1,16.09000000000,R1,7,2035,R1,residential,heatpump,retrofit,2045
A1,31.00000000000,R1,8,2040,R1,residential,heatpump,retrofit,2045
Expand All @@ -36,12 +38,14 @@ A1,1.54330000000,R1,1,2025,R1,power,windturbine,retrofit,2045
A1,1.68610000000,R1,2,2030,R1,power,windturbine,retrofit,2045
A1,2.01780000000,R1,3,2035,R1,power,windturbine,retrofit,2045
A1,2.08150000000,R1,4,2040,R1,power,windturbine,retrofit,2045
A1,56.09630000000,R1,0,2020,R1,gas,gassupply1,retrofit,2045
A1,2.57780000000,R1,0,2020,R1,gas,gassupply1,retrofit,2045
A1,2.70670000000,R1,1,2030,R1,gas,gassupply1,retrofit,2045
A1,31.00000000000,R1,0,2040,R1,residential,heatpump,retrofit,2050
A1,23.00000000000,R1,1,2045,R1,residential,heatpump,retrofit,2050
A1,1.54330000000,R1,0,2025,R1,power,windturbine,retrofit,2050
A1,1.68610000000,R1,1,2030,R1,power,windturbine,retrofit,2050
A1,2.01780000000,R1,2,2035,R1,power,windturbine,retrofit,2050
A1,2.08150000000,R1,3,2040,R1,power,windturbine,retrofit,2050
A1,2.37860000000,R1,4,2045,R1,power,windturbine,retrofit,2050
A1,56.09630000000,R1,0,2020,R1,gas,gassupply1,retrofit,2050
A1,2.57780000000,R1,0,2020,R1,gas,gassupply1,retrofit,2050
A1,2.70670000000,R1,1,2030,R1,gas,gassupply1,retrofit,2050
Loading