Skip to content

Commit 76be8ad

Browse files
committed
Include userdefined energy carrier if they are in the json file
1 parent 84d6ddd commit 76be8ad

1 file changed

Lines changed: 46 additions & 0 deletions

File tree

src/multi_vector_simulator/C0_data_processing.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import os
2626
import sys
2727
import pprint as pp
28+
import jsonschema
2829
import pandas as pd
2930
import warnings
3031
from multi_vector_simulator.version import version_num
@@ -37,6 +38,8 @@
3738
FILENAME,
3839
HEADER,
3940
JSON_PROCESSED,
41+
WEIGHTS_ENERGY_CARRIER,
42+
DEFAULT_WEIGHTS_ENERGY_CARRIERS,
4043
)
4144

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

80+
process_user_energy_carrier_weights(dict_values)
81+
7782
# Adds costs to each asset and sub-asset, adds time series to assets
7883
process_all_assets(dict_values)
7984

@@ -1813,6 +1818,47 @@ def treat_multiple_flows(dict_asset, dict_values, parameter):
18131818
dict_asset[parameter].update({"values_info": values_info})
18141819

18151820

1821+
def process_user_energy_carrier_weights(dict_values):
1822+
"""
1823+
Parameters
1824+
----------
1825+
dict_asset:
1826+
dictionary of the asset
1827+
"""
1828+
if WEIGHTS_ENERGY_CARRIER in dict_values:
1829+
1830+
SCHEMA = {
1831+
"type": "object",
1832+
"properties": {
1833+
"objects": {
1834+
"type": "object",
1835+
"additionalProperties": {
1836+
"type": "object",
1837+
"properties": {
1838+
UNIT: {"type": "string"},
1839+
VALUE: {"type": "number"},
1840+
"energy_carrier_unit": {"type": "string"},
1841+
"information source": {"type": "string"},
1842+
"CO2 per energy_carrier_unit": {"type": "number"},
1843+
},
1844+
"required": [UNIT, VALUE,],
1845+
},
1846+
}
1847+
},
1848+
}
1849+
1850+
try:
1851+
jsonschema.validate(dict_values[WEIGHTS_ENERGY_CARRIER], SCHEMA)
1852+
valid_json = True
1853+
except jsonschema.exceptions.ValidationError:
1854+
valid_json = False
1855+
# TODO log validation error
1856+
1857+
if valid_json is True:
1858+
DEFAULT_WEIGHTS_ENERGY_CARRIERS.update(dict_values[WEIGHTS_ENERGY_CARRIER])
1859+
logging.info("Added user custom energy carrier weights")
1860+
1861+
18161862
# reads timeseries specifically when the need comes from a multiple or output busses situation
18171863
# returns the timeseries. Does not update any dictionary
18181864
def get_timeseries_multiple_flows(settings, dict_asset, file_name, header):

0 commit comments

Comments
 (0)