Skip to content
Merged
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
64 changes: 35 additions & 29 deletions src/muse/outputs/mca.py
Original file line number Diff line number Diff line change
Expand Up @@ -770,14 +770,13 @@ def sector_fuel_costs(
data_agent["category"] = a.category
data_agent["sector"] = getattr(sector, "name", "unnamed")
data_agent["year"] = output_year
if len(data_agent) > 0 and len(data_agent.technology.values) > 0:
data_sector.append(data_agent.groupby("technology").fillna(0))
data_agent = multiindex_to_coords(data_agent, "timeslice").to_dataframe(
"fuel_consumption_costs"
)
if not data_agent.empty:
data_sector.append(data_agent)
Comment on lines +773 to +777
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks ok, but it is doing something different than before. I assume this is correct, but I'm not sure why it is.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, ok, you are combining it with what it was being done afterwards. OK, looks fine.

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

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

Expand Down Expand Up @@ -820,11 +819,12 @@ def sector_capital_costs(
data_agent["category"] = a.category
data_agent["sector"] = getattr(sector, "name", "unnamed")
data_agent["year"] = output_year
a = data_agent.to_dataframe("capital_costs")
if len(a) > 0 and len(a.technology.values) > 0:
b = a.reset_index()
b = b[b["capital_costs"] != 0]
data_sector.append(b)
data_agent = multiindex_to_coords(data_agent, "timeslice").to_dataframe(
"capital_costs"
)
if not data_agent.empty:
data_sector.append(data_agent)

if len(data_sector) > 0:
output = pd.concat(data_sector, sort=True).reset_index()
else:
Expand Down Expand Up @@ -886,14 +886,14 @@ def sector_emission_costs(
data_agent["category"] = a.category
data_agent["sector"] = getattr(sector, "name", "unnamed")
data_agent["year"] = output_year
if len(data_agent) > 0 and len(data_agent.technology.values) > 0:
data_sector.append(data_agent.groupby("technology").fillna(0))
if len(data_sector) > 0:
output = pd.concat(
[u.to_dataframe("emission_costs") for u in data_sector], sort=True
)
output = output.reset_index()
data_agent = multiindex_to_coords(data_agent, "timeslice").to_dataframe(
"emission_costs"
)
if not data_agent.empty:
data_sector.append(data_agent)

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

Expand Down Expand Up @@ -935,7 +935,7 @@ def capacity_to_service_demand(demand, technologies):
technologies = getattr(sector, "technologies", [])
agents = sorted(getattr(sector, "agents", []), key=attrgetter("name"))
retro = [a for a in agents if a.category == "retrofit"]
new = [a for a in agents if a.category == "new"]
new = [a for a in agents if a.category == "newcapa"]
agents = retro if len(retro) > 0 else new
if len(technologies) > 0:
for agent in agents:
Expand Down Expand Up @@ -1091,12 +1091,15 @@ def capacity_to_service_demand(demand, technologies):
data_agent["category"] = agent.category
data_agent["sector"] = getattr(sector, "name", "unnamed")
data_agent["year"] = output_year
if len(data_agent) > 0 and len(data_agent.technology.values) > 0:
data_sector.append(data_agent.groupby("technology").fillna(0))
if len(data_sector) > 0:
output = pd.concat([u.to_dataframe("LCOE") for u in data_sector], sort=True)
output = output.reset_index()
data_agent = data_agent.fillna(0)
data_agent = multiindex_to_coords(data_agent, "timeslice").to_dataframe(
"LCOE"
)
if not data_agent.empty:
data_sector.append(data_agent)

if len(data_sector) > 0:
output = pd.concat(data_sector, sort=True).reset_index()
else:
output = pd.DataFrame()
return output
Expand Down Expand Up @@ -1137,7 +1140,7 @@ def capacity_to_service_demand(demand, technologies):
technologies = getattr(sector, "technologies", [])
agents = sorted(getattr(sector, "agents", []), key=attrgetter("name"))
retro = [a for a in agents if a.category == "retrofit"]
new = [a for a in agents if a.category == "new"]
new = [a for a in agents if a.category == "newcapa"]
agents = retro if len(retro) > 0 else new
if len(technologies) > 0:
for agent in agents:
Expand Down Expand Up @@ -1301,10 +1304,13 @@ def capacity_to_service_demand(demand, technologies):
data_agent["category"] = agent.category
data_agent["sector"] = getattr(sector, "name", "unnamed")
data_agent["year"] = output_year
if len(data_agent) > 0 and len(data_agent.technology.values) > 0:
data_sector.append(data_agent.groupby("technology").fillna(0))
data_agent = multiindex_to_coords(data_agent, "timeslice").to_dataframe(
"capital_costs"
)
if not data_agent.empty:
data_sector.append(data_agent)
if len(data_sector) > 0:
output = pd.concat([u.to_dataframe("EAC") for u in data_sector], sort=True)
output = pd.concat(data_sector, sort=True)
output = output.reset_index()

else:
Expand Down