2023-03-06 08:27:45 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
2024-02-19 15:21:48 +00:00
|
|
|
# SPDX-FileCopyrightText: : 2020-2024 The PyPSA-Eur Authors
|
2023-03-06 17:49:23 +00:00
|
|
|
#
|
|
|
|
# SPDX-License-Identifier: MIT
|
2021-07-02 09:07:35 +00:00
|
|
|
"""
|
|
|
|
Reads biomass transport costs for different countries of the JRC report.
|
|
|
|
|
|
|
|
"The JRC-EU-TIMES model.
|
|
|
|
Bioenergy potentials
|
|
|
|
for EU and neighbouring countries."
|
|
|
|
(2015)
|
|
|
|
|
|
|
|
converts them from units 'EUR per km/ton' -> 'EUR/ (km MWh)'
|
|
|
|
|
|
|
|
assuming as an approximation energy content of wood pellets
|
|
|
|
|
|
|
|
@author: bw0928
|
|
|
|
"""
|
|
|
|
import pandas as pd
|
|
|
|
|
2021-08-09 14:30:38 +00:00
|
|
|
ENERGY_CONTENT = 4.8 # unit MWh/t (wood pellets)
|
2021-07-02 09:07:35 +00:00
|
|
|
|
2021-08-09 14:30:38 +00:00
|
|
|
|
2024-09-10 18:51:28 +00:00
|
|
|
def get_cost_per_tkm(pdf, datapage, countrypage):
|
|
|
|
"""
|
|
|
|
Extracts the cost tables from the JRC report PDF.
|
|
|
|
|
|
|
|
https://publications.jrc.ec.europa.eu/repository/bitstream/JRC98626/biomass%20potentials%20in%20europe_web%20rev.pdf
|
|
|
|
- pdf (str): The filepath of the PDF file containing the data.
|
|
|
|
- datapage (int): The page number of the data table in the PDF.
|
|
|
|
- countrypage (int): The page number of the table containing the country indices in the PDF.
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
- pandas.DataFrame: The data table with the cost per tkm for biomass transport, indexed by country.
|
|
|
|
|
|
|
|
Raises:
|
|
|
|
- ImportError: If tabula-py and platform are not installed.
|
|
|
|
"""
|
|
|
|
try:
|
|
|
|
import platform
|
|
|
|
|
|
|
|
import tabula as tbl
|
|
|
|
except:
|
|
|
|
ImportError("Please install tabula-py and platform")
|
|
|
|
|
|
|
|
system = platform.system()
|
|
|
|
encoding = "cp1252" if system == "Windows" else "utf-8"
|
|
|
|
|
|
|
|
# Obtain countries:
|
|
|
|
pandas_options_country = dict(
|
2024-04-20 10:09:54 +00:00
|
|
|
skiprows=range(6), header=None, index_col=0, encoding=encoding
|
2023-10-30 13:18:25 +00:00
|
|
|
)
|
2021-08-09 14:30:38 +00:00
|
|
|
|
2024-09-10 18:51:28 +00:00
|
|
|
countries = tbl.read_pdf(
|
|
|
|
pdf,
|
|
|
|
pages=countrypage,
|
2021-08-09 14:30:38 +00:00
|
|
|
multiple_tables=False,
|
2024-09-10 18:51:28 +00:00
|
|
|
pandas_options=pandas_options_country,
|
2024-04-20 10:09:54 +00:00
|
|
|
encoding=encoding,
|
2021-08-09 14:30:38 +00:00
|
|
|
)[0].index
|
2021-07-02 09:07:35 +00:00
|
|
|
|
2024-09-10 18:51:28 +00:00
|
|
|
# Obtain data tables
|
|
|
|
pandas_options_data = dict(
|
2021-08-09 14:30:38 +00:00
|
|
|
skiprows=range(6),
|
|
|
|
header=0,
|
|
|
|
sep=" |,",
|
|
|
|
engine="python",
|
|
|
|
index_col=False,
|
2024-04-20 10:09:54 +00:00
|
|
|
encoding=encoding,
|
2021-07-02 09:07:35 +00:00
|
|
|
)
|
2021-08-09 14:30:38 +00:00
|
|
|
|
|
|
|
sc = tbl.read_pdf(
|
2024-09-10 18:51:28 +00:00
|
|
|
pdf,
|
|
|
|
pages=datapage,
|
2021-08-09 14:30:38 +00:00
|
|
|
multiple_tables=False,
|
2024-09-10 18:51:28 +00:00
|
|
|
pandas_options=pandas_options_data,
|
2024-04-20 10:09:54 +00:00
|
|
|
encoding=encoding,
|
2021-08-09 14:30:38 +00:00
|
|
|
)[0]
|
|
|
|
sc.index = countries
|
|
|
|
sc.columns = sc.columns.str.replace("€", "EUR")
|
2023-03-06 08:27:45 +00:00
|
|
|
|
2021-08-09 14:30:38 +00:00
|
|
|
return sc
|
2021-07-02 09:07:35 +00:00
|
|
|
|
|
|
|
|
2021-08-09 14:30:38 +00:00
|
|
|
def build_biomass_transport_costs():
|
2024-09-10 18:51:28 +00:00
|
|
|
# Optional build from JRC report pdf, requires tabula and java dependencies.
|
|
|
|
# Update `pdf` path to the JRC report if needed.
|
|
|
|
# sc1 = get_cost_per_tkm(pdf = "report.pdf", datapage=146, countrypage=145)
|
|
|
|
# sc2 = get_cost_per_tkm(pdf = "report.pdf", datapage=147, countrypage=145)
|
|
|
|
|
|
|
|
# Use extracted csv from JRC report
|
|
|
|
# https://publications.jrc.ec.europa.eu/repository/bitstream/JRC98626/biomass%20potentials%20in%20europe_web%20rev.pdf
|
|
|
|
# Pages 146 (144) for supply chain 1 and 147 (145) for supply chain 2
|
|
|
|
sc1 = pd.read_csv(snakemake.input.sc1, index_col=0, skiprows=2)
|
|
|
|
sc2 = pd.read_csv(snakemake.input.sc2, index_col=0, skiprows=2)
|
2021-07-02 09:07:35 +00:00
|
|
|
|
2021-08-09 14:30:38 +00:00
|
|
|
# take mean of both supply chains
|
|
|
|
to_concat = [sc1["EUR/km/ton"], sc2["EUR/km/ton"]]
|
|
|
|
transport_costs = pd.concat(to_concat, axis=1).mean(axis=1)
|
|
|
|
|
|
|
|
# convert tonnes to MWh
|
2021-07-02 09:07:35 +00:00
|
|
|
transport_costs /= ENERGY_CONTENT
|
2021-08-09 14:30:38 +00:00
|
|
|
transport_costs.name = "EUR/km/MWh"
|
|
|
|
|
|
|
|
# rename country names
|
2024-09-10 10:32:42 +00:00
|
|
|
to_rename = {"UK": "GB", "EL": "GR"}
|
2021-08-09 14:30:38 +00:00
|
|
|
transport_costs.rename(to_rename, inplace=True)
|
2021-07-02 09:07:35 +00:00
|
|
|
|
2021-08-09 14:30:38 +00:00
|
|
|
# add missing Norway with data from Sweden
|
|
|
|
transport_costs["NO"] = transport_costs["SE"]
|
2021-07-02 09:07:35 +00:00
|
|
|
|
2021-09-24 12:59:53 +00:00
|
|
|
transport_costs.to_csv(snakemake.output[0])
|
2021-07-02 09:07:35 +00:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2023-10-30 13:18:25 +00:00
|
|
|
if "snakemake" not in globals():
|
|
|
|
from _helpers import mock_snakemake
|
|
|
|
|
2024-04-20 10:14:24 +00:00
|
|
|
snakemake = mock_snakemake("build_biomass_transport_costs")
|
2023-10-30 13:18:25 +00:00
|
|
|
|
2021-07-12 10:31:18 +00:00
|
|
|
build_biomass_transport_costs()
|