|
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 |
@@ -74,6 +77,8 @@ def all(dict_values): |
74 | 77 | # C1.check_input_values(dict_values) |
75 | 78 | # todo Check, whether files (demand, generation) are existing |
76 | 79 |
|
| 80 | + process_user_energy_carrier_weights(dict_values) |
| 81 | + |
77 | 82 | # Adds costs to each asset and sub-asset, adds time series to assets |
78 | 83 | process_all_assets(dict_values) |
79 | 84 |
|
@@ -1850,6 +1855,50 @@ def treat_multiple_flows(dict_asset, dict_values, parameter): |
1850 | 1855 | dict_asset[parameter].update({"values_info": values_info}) |
1851 | 1856 |
|
1852 | 1857 |
|
| 1858 | +def process_user_energy_carrier_weights(dict_values): |
| 1859 | + """ |
| 1860 | + Parameters |
| 1861 | + ---------- |
| 1862 | + dict_asset: |
| 1863 | + dictionary of the asset |
| 1864 | + """ |
| 1865 | + if WEIGHTS_ENERGY_CARRIER in dict_values: |
| 1866 | + |
| 1867 | + SCHEMA = { |
| 1868 | + "type": "object", |
| 1869 | + "properties": { |
| 1870 | + "objects": { |
| 1871 | + "type": "object", |
| 1872 | + "additionalProperties": { |
| 1873 | + "type": "object", |
| 1874 | + "properties": { |
| 1875 | + UNIT: {"type": "string"}, |
| 1876 | + VALUE: {"type": "number"}, |
| 1877 | + "energy_carrier_unit": {"type": "string"}, |
| 1878 | + "information source": {"type": "string"}, |
| 1879 | + "CO2 per energy_carrier_unit": {"type": "number"}, |
| 1880 | + }, |
| 1881 | + "required": [ |
| 1882 | + UNIT, |
| 1883 | + VALUE, |
| 1884 | + ], |
| 1885 | + }, |
| 1886 | + } |
| 1887 | + }, |
| 1888 | + } |
| 1889 | + |
| 1890 | + try: |
| 1891 | + jsonschema.validate(dict_values[WEIGHTS_ENERGY_CARRIER], SCHEMA) |
| 1892 | + valid_json = True |
| 1893 | + except jsonschema.exceptions.ValidationError: |
| 1894 | + valid_json = False |
| 1895 | + # TODO log validation error |
| 1896 | + |
| 1897 | + if valid_json is True: |
| 1898 | + DEFAULT_WEIGHTS_ENERGY_CARRIERS.update(dict_values[WEIGHTS_ENERGY_CARRIER]) |
| 1899 | + logging.info("Added user custom energy carrier weights") |
| 1900 | + |
| 1901 | + |
1853 | 1902 | # reads timeseries specifically when the need comes from a multiple or output busses situation |
1854 | 1903 | # returns the timeseries. Does not update any dictionary |
1855 | 1904 | def get_timeseries_multiple_flows(settings, dict_asset, file_name, header): |
|
0 commit comments