Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/co2 emission coefficients #957

Draft
wants to merge 2 commits into
base: dev
Choose a base branch
from
Draft
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
15 changes: 15 additions & 0 deletions docs/energy_co2_conversion_factors.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
energy_carrier_name,unit,value,energy_carrier_unit,information source,CO2 per energy_carrier_unit
Biodiesel,kWh_eleq/l,0.06290669,l,,0
Crude_oil,kWh_eleq/kg,11.63042204,kg,,0
Diesel,kWh_eleq/l,9.48030688,l,"https://epact.energy.gov/fuel-conversion-factors, conversion gallon->4.546092 l",0
Electricity,kWh_eleq/kWh_el,1,kWh_el,,0
Ethane,kWh_eleq/l,5.149767951,l,,0
Ethanol,kWh_eleq/l,0.04242544,l,,0
Gas,kWh_eleq/m3,0.00933273,l,"https://epact.energy.gov/fuel-conversion-factors, conversion gallon->4.546092 l",0
Gasoline,kWh_eleq/l,8.735753974,l,,0
H2,kWh_eleq/kgH2,33.47281985,kgH2,"https://epact.energy.gov/fuel-conversion-factors",0
Heat,KWh_eleq/kWh_therm,1.0002163,kWh_therm,,0
Kerosene,kWh_eleq/l,8.908073954,l,,0
LNG,kWh_eleq/kg,12.69270292,kg,,0
LPG,kWh_eleq/l,6.472821609,l,,0
Natural_gas,kWh_eleq/m3,0.00933273,l,"https://epact.energy.gov/fuel-conversion-factors, conversion gallon->4.546092 l",0
9 changes: 5 additions & 4 deletions prepare_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@
os.path.join(".", pgk_data_src), os.path.join(pkg_data_folder, pkg_data_dest)
)
# Move the MVS parameters from the docs into the package_data folder
shutil.copyfile(
os.path.join(".", "docs", "MVS_parameters_list.csv"),
os.path.join(pkg_data_folder, "MVS_parameters_list.csv"),
)
for doc_file in ("MVS_parameters_list.csv", "energy_co2_conversion_factors.csv"):
shutil.copyfile(
os.path.join(".", "docs", doc_file),
os.path.join(pkg_data_folder, doc_file),
)

# Rebuild the package
os.system("python setup.py sdist bdist_wheel")
Expand Down
49 changes: 49 additions & 0 deletions src/multi_vector_simulator/C0_data_processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import os
import sys
import pprint as pp
import jsonschema
import pandas as pd
import warnings
from multi_vector_simulator.version import version_num
Expand All @@ -37,6 +38,8 @@
FILENAME,
HEADER,
JSON_PROCESSED,
WEIGHTS_ENERGY_CARRIER,
DEFAULT_WEIGHTS_ENERGY_CARRIERS,
)

from multi_vector_simulator.utils.exceptions import MaximumCapValueInvalid
Expand Down Expand Up @@ -74,6 +77,8 @@ def all(dict_values):
# C1.check_input_values(dict_values)
# todo Check, whether files (demand, generation) are existing

process_user_energy_carrier_weights(dict_values)

# Adds costs to each asset and sub-asset, adds time series to assets
process_all_assets(dict_values)

Expand Down Expand Up @@ -1850,6 +1855,50 @@ def treat_multiple_flows(dict_asset, dict_values, parameter):
dict_asset[parameter].update({"values_info": values_info})


def process_user_energy_carrier_weights(dict_values):
"""
Parameters
----------
dict_asset:
dictionary of the asset
"""
if WEIGHTS_ENERGY_CARRIER in dict_values:

SCHEMA = {
"type": "object",
"properties": {
"objects": {
"type": "object",
"additionalProperties": {
"type": "object",
"properties": {
UNIT: {"type": "string"},
VALUE: {"type": "number"},
"energy_carrier_unit": {"type": "string"},
"information source": {"type": "string"},
"CO2 per energy_carrier_unit": {"type": "number"},
},
"required": [
UNIT,
VALUE,
],
},
}
},
}

try:
jsonschema.validate(dict_values[WEIGHTS_ENERGY_CARRIER], SCHEMA)
valid_json = True
except jsonschema.exceptions.ValidationError:
valid_json = False
# TODO log validation error

if valid_json is True:
DEFAULT_WEIGHTS_ENERGY_CARRIERS.update(dict_values[WEIGHTS_ENERGY_CARRIER])
logging.info("Added user custom energy carrier weights")


# reads timeseries specifically when the need comes from a multiple or output busses situation
# returns the timeseries. Does not update any dictionary
def get_timeseries_multiple_flows(settings, dict_asset, file_name, header):
Expand Down
95 changes: 22 additions & 73 deletions src/multi_vector_simulator/utils/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"""

import os
import pandas as pd
from copy import deepcopy

from multi_vector_simulator.utils.constants_json_strings import *
Expand Down Expand Up @@ -309,79 +310,27 @@
},
}

ENERGY_CARRIER_UNIT = "energy_carrier_unit"
DEFAULT_WEIGHTS_ENERGY_CARRIERS = {
"LNG": {
UNIT: "kWh_eleq/kg",
VALUE: 12.69270292,
ENERGY_CARRIER_UNIT: "kg",
},
"Crude_oil": {
UNIT: "kWh_eleq/kg",
VALUE: 11.63042204,
ENERGY_CARRIER_UNIT: "kg",
},
"Diesel": {
UNIT: "kWh_eleq/l",
VALUE: 9.48030688,
ENERGY_CARRIER_UNIT: "l",
}, # https://epact.energy.gov/fuel-conversion-factors, conversion gallon->4.546092 l
"Kerosene": {
UNIT: "kWh_eleq/l",
VALUE: 8.908073954,
ENERGY_CARRIER_UNIT: "l",
},
"Gasoline": {
UNIT: "kWh_eleq/l",
VALUE: 8.735753974,
ENERGY_CARRIER_UNIT: "l",
},
"LPG": {
UNIT: "kWh_eleq/l",
VALUE: 6.472821609,
ENERGY_CARRIER_UNIT: "l",
},
"Ethane": {
UNIT: "kWh_eleq/l",
VALUE: 5.149767951,
ENERGY_CARRIER_UNIT: "l",
},
"H2": {
UNIT: "kWh_eleq/kgH2",
VALUE: 33.47281985,
ENERGY_CARRIER_UNIT: "kgH2",
}, # https://epact.energy.gov/fuel-conversion-factors
"Electricity": {
UNIT: "kWh_eleq/kWh_el",
VALUE: 1,
ENERGY_CARRIER_UNIT: "kWh_el",
},
"Biodiesel": {
UNIT: "kWh_eleq/l",
VALUE: 0.06290669,
ENERGY_CARRIER_UNIT: "l",
},
"Ethanol": {
UNIT: "kWh_eleq/l",
VALUE: 0.04242544,
ENERGY_CARRIER_UNIT: "l",
},
"Natural_gas": {
UNIT: "kWh_eleq/m3",
VALUE: 0.00933273,
ENERGY_CARRIER_UNIT: "l",
}, # https://epact.energy.gov/fuel-conversion-factors, conversion gallon->4.546092 l
"Gas": {
UNIT: "kWh_eleq/m3",
VALUE: 0.00933273,
ENERGY_CARRIER_UNIT: "l",
}, # https://epact.energy.gov/fuel-conversion-factors, conversion gallon->4.546092 l
"Heat": {
UNIT: "KWh_eleq/kWh_therm",
VALUE: 1.0002163,
ENERGY_CARRIER_UNIT: "kWh_therm",
},
}
WEIGHTS_ENERGY_CARRIER = "weights_energy_carrier"

try:
energy_carriers_file = "energy_co2_conversion_factors.csv"
FILE_PATH = os.path.join(
os.path.dirname(
os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
),
"docs",
)
if os.path.exists(FILE_PATH):
FILE_PATH = PACKAGE_DATA_PATH

df = pd.read_csv(
os.path.join(FILE_PATH, "energy_co2_conversion_factors.csv"), index_col=0
)

DEFAULT_WEIGHTS_ENERGY_CARRIERS = df.to_dict(orient="index")
except FileNotFoundError:
DEFAULT_WEIGHTS_ENERGY_CARRIERS = None


# dict keys in results_json file
TIMESERIES = "timeseries"
Expand Down
Loading