biomass_transport: fix cost calculation and get from remote
This commit is contained in:
parent
d428c1b77d
commit
6711d721b9
@ -186,11 +186,11 @@ rule build_biomass_potentials:
|
|||||||
if config["sector"]["biomass_transport"]:
|
if config["sector"]["biomass_transport"]:
|
||||||
rule build_biomass_transport_costs:
|
rule build_biomass_transport_costs:
|
||||||
input:
|
input:
|
||||||
transport_cost_data=HTTP.remote("https://publications.jrc.ec.europa.eu/repository/bitstream/JRC98626/biomass%20potentials%20in%20europe_web%20rev.pdf", keep_local=True)
|
transport_cost_data=HTTP.remote("publications.jrc.ec.europa.eu/repository/bitstream/JRC98626/biomass potentials in europe_web rev.pdf", keep_local=True)
|
||||||
output:
|
output:
|
||||||
supply_chain1="resources/biomass_transport_costs_supply_chain1.csv",
|
supply_chain1="resources/biomass_transport_costs_supply_chain1.csv",
|
||||||
supply_chain2="resources/biomass_transport_costs_supply_chain2.csv",
|
supply_chain2="resources/biomass_transport_costs_supply_chain2.csv",
|
||||||
transport_costs="resources/biomass_transport_costs.csv",
|
biomass_transport_costs="resources/biomass_transport_costs.csv",
|
||||||
threads: 1
|
threads: 1
|
||||||
resources: mem_mb=1000
|
resources: mem_mb=1000
|
||||||
benchmark: "benchmarks/build_biomass_transport_costs"
|
benchmark: "benchmarks/build_biomass_transport_costs"
|
||||||
|
@ -16,52 +16,75 @@ assuming as an approximation energy content of wood pellets
|
|||||||
import pandas as pd
|
import pandas as pd
|
||||||
import tabula as tbl
|
import tabula as tbl
|
||||||
|
|
||||||
ENERGY_CONTENT = 4.8 # unit MWh/tonne (assuming wood pellets)
|
ENERGY_CONTENT = 4.8 # unit MWh/t (wood pellets)
|
||||||
|
|
||||||
|
def get_countries():
|
||||||
|
|
||||||
|
pandas_options = dict(
|
||||||
|
skiprows=list(range(6)),
|
||||||
|
header=None,
|
||||||
|
index_col=0
|
||||||
|
)
|
||||||
|
|
||||||
|
return tbl.read_pdf(
|
||||||
|
str(snakemake.input.transport_cost_data),
|
||||||
|
pages="145",
|
||||||
|
multiple_tables=False,
|
||||||
|
pandas_options=pandas_options
|
||||||
|
)[0].index
|
||||||
|
|
||||||
|
|
||||||
|
def get_cost_per_tkm(page, countries):
|
||||||
|
|
||||||
|
pandas_options = dict(
|
||||||
|
skiprows=range(6),
|
||||||
|
header=0,
|
||||||
|
sep=' |,',
|
||||||
|
engine='python',
|
||||||
|
index_col=False,
|
||||||
|
)
|
||||||
|
|
||||||
|
sc = tbl.read_pdf(
|
||||||
|
str(snakemake.input.transport_cost_data),
|
||||||
|
pages=page,
|
||||||
|
multiple_tables=False,
|
||||||
|
pandas_options=pandas_options
|
||||||
|
)[0]
|
||||||
|
sc.index = countries
|
||||||
|
sc.columns = sc.columns.str.replace("€", "EUR")
|
||||||
|
|
||||||
|
return sc
|
||||||
|
|
||||||
|
|
||||||
def build_biomass_transport_costs():
|
def build_biomass_transport_costs():
|
||||||
|
|
||||||
df_list = tbl.read_pdf(
|
countries = get_countries()
|
||||||
snakemake.input.transport_cost_data,
|
|
||||||
pages="145-147",
|
|
||||||
multiple_tables=True,
|
|
||||||
)
|
|
||||||
|
|
||||||
countries = df_list[0][0].iloc[6:].rename(index=lambda x: x + 1)
|
|
||||||
|
|
||||||
# supply chain 1
|
sc1 = get_cost_per_tkm(146, countries)
|
||||||
df = df_list[1].copy().rename(index=countries.to_dict())
|
sc2 = get_cost_per_tkm(147, countries)
|
||||||
df.rename(
|
|
||||||
columns=df.iloc[:6].apply(lambda col: col.str.cat(sep=" "), axis=0).to_dict(),
|
|
||||||
inplace=True,
|
|
||||||
)
|
|
||||||
df = df.iloc[6:]
|
|
||||||
df.loc[6] = df.loc[6].str.replace("€", "EUR")
|
|
||||||
|
|
||||||
# supply chain 2
|
sc1.to_csv(snakemake.output.supply_chain1)
|
||||||
df2 = df_list[2].copy().rename(index=countries.to_dict())
|
sc2.to_csv(snakemake.output.supply_chain2)
|
||||||
df2.rename(
|
|
||||||
columns=df2.iloc[:6].apply(lambda col: col.str.cat(sep=" "), axis=0).to_dict(),
|
|
||||||
inplace=True,
|
|
||||||
)
|
|
||||||
df2 = df2.iloc[6:]
|
|
||||||
df2.loc[6] = df2.loc[6].str.replace("€", "EUR")
|
|
||||||
|
|
||||||
df.to_csv(snakemake.output.supply_chain1)
|
# take mean of both supply chains
|
||||||
df2.to_csv(snakemake.output.supply_chain1)
|
to_concat = [sc1["EUR/km/ton"], sc2["EUR/km/ton"]]
|
||||||
|
transport_costs = pd.concat(to_concat, axis=1).mean(axis=1)
|
||||||
|
|
||||||
transport_costs = pd.concat([df["per km/ton"], df2["per km/ton"]], axis=1).drop(6)
|
# convert tonnes to MWh
|
||||||
transport_costs = transport_costs.astype(float, errors="ignore").mean(axis=1)
|
|
||||||
|
|
||||||
# convert unit to EUR/MWh
|
|
||||||
transport_costs /= ENERGY_CONTENT
|
transport_costs /= ENERGY_CONTENT
|
||||||
transport_costs = pd.DataFrame(transport_costs, columns=["cost [EUR/(km MWh)]"])
|
transport_costs.name = "EUR/km/MWh"
|
||||||
|
|
||||||
# rename
|
# rename country names
|
||||||
transport_costs.rename({"UK": "GB", "XK": "KO", "EL": "GR"}, inplace=True)
|
to_rename = {
|
||||||
|
"UK": "GB",
|
||||||
|
"XK": "KO",
|
||||||
|
"EL": "GR"
|
||||||
|
}
|
||||||
|
transport_costs.rename(to_rename, inplace=True)
|
||||||
|
|
||||||
|
# add missing Norway with data from Sweden
|
||||||
|
transport_costs["NO"] = transport_costs["SE"]
|
||||||
|
|
||||||
# add missing Norway
|
|
||||||
transport_costs.loc["NO"] = transport_costs.loc["SE"]
|
|
||||||
transport_costs.to_csv(snakemake.output.transport_costs)
|
transport_costs.to_csv(snakemake.output.transport_costs)
|
||||||
|
|
||||||
|
|
||||||
|
@ -1613,7 +1613,7 @@ def add_biomass(n, costs):
|
|||||||
biomass_potentials = pd.read_csv(snakemake.input.biomass_potentials, index_col=0)
|
biomass_potentials = pd.read_csv(snakemake.input.biomass_potentials, index_col=0)
|
||||||
|
|
||||||
transport_costs = pd.read_csv(
|
transport_costs = pd.read_csv(
|
||||||
snakemake.input.biomass_transport,
|
snakemake.input.biomass_transport_costs,
|
||||||
index_col=0,
|
index_col=0,
|
||||||
squeeze=True
|
squeeze=True
|
||||||
)
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user