Merge pull request #76 from euronion/patch-1

Update make_summary for pandas-0.25 compatability.
This commit is contained in:
FabianHofmann 2019-10-25 15:41:29 +02:00 committed by GitHub
commit 7e3ea94a53
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -62,6 +62,13 @@ idx = pd.IndexSlice
opt_name = {"Store": "e", "Line" : "s", "Transformer" : "s"}
def _add_indexed_rows(df, raw_index):
new_index = df.index|pd.MultiIndex.from_product(raw_index)
if isinstance(new_index, pd.Index):
new_index = pd.MultiIndex.from_tuples(new_index)
return df.reindex(new_index)
def assign_carriers(n):
if "carrier" not in n.loads:
@ -82,16 +89,17 @@ def assign_carriers(n):
if "EU gas store" in n.stores.index and n.stores.loc["EU gas Store","carrier"] == "":
n.stores.loc["EU gas Store","carrier"] = "gas Store"
def calculate_costs(n,label,costs):
for c in n.iterate_components(n.branch_components|n.controllable_one_port_components^{"Load"}):
capital_costs = c.df.capital_cost*c.df[opt_name.get(c.name,"p") + "_nom_opt"]
capital_costs_grouped = capital_costs.groupby(c.df.carrier).sum()
costs = costs.reindex(costs.index|pd.MultiIndex.from_product([[c.list_name],["capital"],capital_costs_grouped.index]))
# Index tuple(s) indicating the newly to-be-added row(s)
raw_index = tuple([[c.list_name],["capital"],list(capital_costs_grouped.index)])
costs = _add_indexed_rows(costs, raw_index)
costs.loc[idx[c.list_name,"capital",list(capital_costs_grouped.index)],label] = capital_costs_grouped.values
costs.loc[idx[raw_index],label] = capital_costs_grouped.values
if c.name == "Link":
p = c.pnl.p0.multiply(n.snapshot_weightings,axis=0).sum()
@ -137,8 +145,12 @@ def calculate_energy(n,label,energy):
return energy
def include_in_summary(summary, multiindexprefix, label, item):
summary = summary.reindex(summary.index | pd.MultiIndex.from_product([[p] for p in multiindexprefix] + [item.index]))
summary.loc[idx[tuple(multiindexprefix + [list(item.index)])], label] = item.values
# Index tuple(s) indicating the newly to-be-added row(s)
raw_index = tuple([multiindexprefix,list(item.index)])
summary = _add_indexed_rows(summary, raw_index)
summary.loc[idx[raw_index], label] = item.values
return summary
def calculate_capacity(n,label,capacity):
@ -180,8 +192,11 @@ def calculate_supply(n,label,supply):
s = c.pnl.p[items].max().multiply(c.df.loc[items,'sign']).groupby(c.df.loc[items,'carrier']).sum()
supply = supply.reindex(supply.index|pd.MultiIndex.from_product([[i],[c.list_name],s.index]))
supply.loc[idx[i,c.list_name,list(s.index)],label] = s.values
# Index tuple(s) indicating the newly to-be-added row(s)
raw_index = tuple([[i],[c.list_name],list(s.index)])
supply = _add_indexed_rows(supply, raw_index)
supply.loc[idx[raw_index],label] = s.values
for c in n.iterate_components(n.branch_components):
@ -223,8 +238,11 @@ def calculate_supply_energy(n,label,supply_energy):
s = c.pnl.p[items].sum().multiply(c.df.loc[items,'sign']).groupby(c.df.loc[items,'carrier']).sum()
supply_energy = supply_energy.reindex(supply_energy.index|pd.MultiIndex.from_product([[i],[c.list_name],s.index]))
supply_energy.loc[idx[i,c.list_name,list(s.index)],label] = s.values
# Index tuple(s) indicating the newly to-be-added row(s)
raw_index = tuple([[i],[c.list_name],list(s.index)])
supply_energy = _add_indexed_rows(supply_energy, raw_index)
supply_energy.loc[idx[raw_index],label] = s.values
for c in n.iterate_components(n.branch_components):