|
25 | 25 | import os |
26 | 26 | import sys |
27 | 27 | import pprint as pp |
| 28 | +import jsonschema |
28 | 29 | import pandas as pd |
29 | 30 | import warnings |
30 | 31 | from multi_vector_simulator.version import version_num |
|
37 | 38 | FILENAME, |
38 | 39 | HEADER, |
39 | 40 | JSON_PROCESSED, |
| 41 | + WEIGHTS_ENERGY_CARRIER, |
| 42 | + DEFAULT_WEIGHTS_ENERGY_CARRIERS, |
40 | 43 | ) |
41 | 44 |
|
42 | 45 | from multi_vector_simulator.utils.exceptions import MaximumCapValueInvalid |
@@ -70,6 +73,8 @@ def all(dict_values): |
70 | 73 | # C1.check_input_values(dict_values) |
71 | 74 | # todo Check, whether files (demand, generation) are existing |
72 | 75 |
|
| 76 | + process_user_energy_carrier_weights(dict_values) |
| 77 | + |
73 | 78 | # Adds costs to each asset and sub-asset, adds time series to assets |
74 | 79 | process_all_assets(dict_values) |
75 | 80 |
|
@@ -1744,6 +1749,47 @@ def treat_multiple_flows(dict_asset, dict_values, parameter): |
1744 | 1749 | dict_asset[parameter].update({"values_info": values_info}) |
1745 | 1750 |
|
1746 | 1751 |
|
| 1752 | +def process_user_energy_carrier_weights(dict_values): |
| 1753 | + """ |
| 1754 | + Parameters |
| 1755 | + ---------- |
| 1756 | + dict_asset: |
| 1757 | + dictionary of the asset |
| 1758 | + """ |
| 1759 | + if WEIGHTS_ENERGY_CARRIER in dict_values: |
| 1760 | + |
| 1761 | + SCHEMA = { |
| 1762 | + "type": "object", |
| 1763 | + "properties": { |
| 1764 | + "objects": { |
| 1765 | + "type": "object", |
| 1766 | + "additionalProperties": { |
| 1767 | + "type": "object", |
| 1768 | + "properties": { |
| 1769 | + UNIT: {"type": "string"}, |
| 1770 | + VALUE: {"type": "number"}, |
| 1771 | + "energy_carrier_unit": {"type": "string"}, |
| 1772 | + "information source": {"type": "string"}, |
| 1773 | + "CO2 per energy_carrier_unit": {"type": "number"}, |
| 1774 | + }, |
| 1775 | + "required": [UNIT, VALUE,], |
| 1776 | + }, |
| 1777 | + } |
| 1778 | + }, |
| 1779 | + } |
| 1780 | + |
| 1781 | + try: |
| 1782 | + jsonschema.validate(dict_values[WEIGHTS_ENERGY_CARRIER], SCHEMA) |
| 1783 | + valid_json = True |
| 1784 | + except jsonschema.exceptions.ValidationError: |
| 1785 | + valid_json = False |
| 1786 | + # TODO log validation error |
| 1787 | + |
| 1788 | + if valid_json is True: |
| 1789 | + DEFAULT_WEIGHTS_ENERGY_CARRIERS.update(dict_values[WEIGHTS_ENERGY_CARRIER]) |
| 1790 | + logging.info("Added user custom energy carrier weights") |
| 1791 | + |
| 1792 | + |
1747 | 1793 | # reads timeseries specifically when the need comes from a multiple or output busses situation |
1748 | 1794 | # returns the timeseries. Does not update any dictionary |
1749 | 1795 | def get_timeseries_multiple_flows(settings, dict_asset, file_name, header): |
|
0 commit comments