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

Large diffs are not rendered by default.

758 changes: 379 additions & 379 deletions docs/tutorial-code/0-new-decision-metric/Results/MCAMetric_Supply.csv

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions docs/tutorial-code/0-new-decision-metric/settings.toml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ commodities_out = '{path}/technodata/power/CommOut.csv'
agents = '{path}/technodata/Agents.csv'
existing_capacity = '{path}/technodata/power/ExistingCapacity.csv'
lpsolver = "scipy"
demand_share = "standard_demand"

[sectors.gas]
type = 'default'
Expand All @@ -89,6 +90,7 @@ commodities_out = '{path}/technodata/gas/CommOut.csv'
agents = '{path}/technodata/Agents.csv'
existing_capacity = '{path}/technodata/gas/ExistingCapacity.csv'
lpsolver = "scipy"
demand_share = "standard_demand"

[sectors.residential_presets]
type = 'presets'
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

6 changes: 1 addition & 5 deletions src/muse/investments.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,11 +310,7 @@ def scipy_match_demand(

from muse.constraints import ScipyAdapter

df_technologies = (
technologies.to_dataframe()
.drop(["month", "day", "hour"], axis=1, errors="ignore")
.reset_index()
)
df_technologies = technologies.to_dataframe()

if "timeslice" in costs.dims and timeslice_op is not None:
costs = timeslice_op(costs)
Expand Down
63 changes: 19 additions & 44 deletions src/muse/outputs/mca.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def quantity(
from muse.registration import registrator
from muse.sectors import AbstractSector
from muse.timeslices import QuantityType, convert_timeslice, drop_timeslice
from muse.utilities import multiindex_to_coords

OUTPUT_QUANTITY_SIGNATURE = Callable[
[xr.Dataset, list[AbstractSector], KwArg(Any)], Union[xr.DataArray, pd.DataFrame]
Expand Down Expand Up @@ -396,26 +397,16 @@ def sector_supply(sector: AbstractSector, market: xr.Dataset, **kwargs) -> pd.Da
data_agent["category"] = a.category
data_agent["sector"] = getattr(sector, "name", "unnamed")

a = data_agent.to_dataframe("supply")
a = multiindex_to_coords(data_agent, "timeslice").to_dataframe("supply")
a["comm_usage"] = a["comm_usage"].apply(lambda x: x.name)
if len(a) > 0 and len(a.technology.values) > 0:
b = a.drop(
["month", "day", "hour"], axis=1, errors="ignore"
).reset_index()
b = b[b["supply"] != 0]
data_sector.append(b)
if len(data_sector) > 0:
output = pd.concat([u for u in data_sector], sort=True)
if not a.empty:
data_sector.append(a[a["supply"] != 0])

if len(data_sector) > 0:
output = pd.concat(data_sector, sort=True).reset_index()
else:
output = pd.DataFrame()

# Combine timeslice columns into a single column, if present
if "hour" in output.columns:
output["timeslice"] = list(zip(output["month"], output["day"], output["hour"]))
output = output.drop(["month", "day", "hour"], axis=1)

return output.reset_index()
return output


@register_output_quantity(name=["yearly_supply"])
Expand Down Expand Up @@ -572,12 +563,9 @@ def capacity(agents):
data_sector.append(b)

if len(data_sector) > 0:
output = pd.concat([u for u in data_sector], sort=True)

output = pd.concat(data_sector, sort=True).reset_index()
else:
output = pd.DataFrame()
output = output.reset_index()

return output


Expand Down Expand Up @@ -643,26 +631,19 @@ def sector_consumption(
data_agent["agent"] = a.name
data_agent["category"] = a.category
data_agent["sector"] = getattr(sector, "name", "unnamed")
a = data_agent.to_dataframe("consumption")

a = multiindex_to_coords(data_agent, "timeslice").to_dataframe(
"consumption"
)
a["comm_usage"] = a["comm_usage"].apply(lambda x: x.name)
if len(a) > 0 and len(a.technology.values) > 0:
b = a.drop(
["month", "day", "hour"], axis=1, errors="ignore"
).reset_index()
b = b[b["consumption"] != 0]
data_sector.append(b)
if len(data_sector) > 0:
output = pd.concat([u for u in data_sector], sort=True)
if not a.empty:
data_sector.append(a[a["consumption"] != 0])

if len(data_sector) > 0:
output = pd.concat(data_sector, sort=True).reset_index()
else:
output = pd.DataFrame()

# Combine timeslice columns into a single column, if present
if "hour" in output.columns:
output["timeslice"] = list(zip(output["month"], output["day"], output["hour"]))
output = output.drop(["month", "day", "hour"], axis=1)

return output.reset_index()
return output


@register_output_quantity(name=["yearly_consumption"])
Expand Down Expand Up @@ -729,12 +710,9 @@ def sectory_consumption(
b = b[b["consumption"] != 0]
data_sector.append(b)
if len(data_sector) > 0:
output = pd.concat([u for u in data_sector], sort=True)

output = pd.concat(data_sector, sort=True).reset_index()
else:
output = pd.DataFrame()
output = output.reset_index()

return output


Expand Down Expand Up @@ -848,12 +826,9 @@ def sector_capital_costs(
b = b[b["capital_costs"] != 0]
data_sector.append(b)
if len(data_sector) > 0:
output = pd.concat([u for u in data_sector], sort=True)
output = output.reset_index()

output = pd.concat(data_sector, sort=True).reset_index()
else:
output = pd.DataFrame()

return output


Expand Down
Loading