Skip to content

Commit

Permalink
Include userdefined energy carrier if they are in the json file
Browse files Browse the repository at this point in the history
  • Loading branch information
Bachibouzouk committed Apr 28, 2024
1 parent 84d6ddd commit 76be8ad
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 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 @@ -1813,6 +1818,47 @@ 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

0 comments on commit 76be8ad

Please sign in to comment.