diff --git a/tests/_files/build_datapackage_goal/.gitkeep b/tests/_files/build_datapackage_goal/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/tests/_files/build_datapackage_goal/data/elements/.gitkeep b/tests/_files/build_datapackage_goal/data/elements/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/tests/_files/build_datapackage_goal/data/elements/bus.csv b/tests/_files/build_datapackage_goal/data/elements/bus.csv deleted file mode 100644 index f7f51a1..0000000 --- a/tests/_files/build_datapackage_goal/data/elements/bus.csv +++ /dev/null @@ -1,4 +0,0 @@ -name;type;balanced -electricity;bus;True -heat;bus;True -ch4;bus;True diff --git a/tests/_files/build_datapackage_goal/data/elements/modex_tech_generator_gas.csv b/tests/_files/build_datapackage_goal/data/elements/modex_tech_generator_gas.csv deleted file mode 100644 index 67056b3..0000000 --- a/tests/_files/build_datapackage_goal/data/elements/modex_tech_generator_gas.csv +++ /dev/null @@ -1,2 +0,0 @@ -type;carrier;tech;condensing_efficiency;electric_efficiency;thermal_efficiency;capacity;carrier_cost;name;region;year;electricity_bus;heat_bus;fuel_bus -extraction_turbine;gas;generator_gas;[0.16, 0.3, 0.5];[0.35, 0.35, 0.4];[0.5, 0.5, 0.45];330.2;[25.9, 25.9, 49.36];BB_gas_generator_gas;BB;[2016, 2030, 2050];electricity;heat;ch4 diff --git a/tests/_files/build_datapackage_goal/data/elements/modex_tech_photovoltaic_utility.csv b/tests/_files/build_datapackage_goal/data/elements/modex_tech_photovoltaic_utility.csv deleted file mode 100644 index 13844c1..0000000 --- a/tests/_files/build_datapackage_goal/data/elements/modex_tech_photovoltaic_utility.csv +++ /dev/null @@ -1,2 +0,0 @@ -type;carrier;tech;profile;lifetime;fixed_costs;name;region;year;bus -volatile;solar;photovoltaic_utility;photovoltaic_BB;[25.4, 30.0, 30.0];[10280.0, 8600.0, 6340.0];BB_solar_photovoltaic_utility;BB;[2016, 2030, 2050];electricity diff --git a/tests/_files/build_datapackage_goal/data/elements/modex_tech_storage_battery.csv b/tests/_files/build_datapackage_goal/data/elements/modex_tech_storage_battery.csv deleted file mode 100644 index bf889e3..0000000 --- a/tests/_files/build_datapackage_goal/data/elements/modex_tech_storage_battery.csv +++ /dev/null @@ -1,2 +0,0 @@ -type;carrier;tech;capacity;fixed_costs;name;region;year;invest_relation_output_capacity;bus -storage;Lithium;storage_battery;17.8;[1, 2, 3];BB_Lithium_storage_battery;BB;[2016, 2030, 2050];3.3;electricity diff --git a/tests/_files/build_datapackage_goal/data/elements/modex_tech_wind_turbine_onshore.csv b/tests/_files/build_datapackage_goal/data/elements/modex_tech_wind_turbine_onshore.csv deleted file mode 100644 index 85cb5eb..0000000 --- a/tests/_files/build_datapackage_goal/data/elements/modex_tech_wind_turbine_onshore.csv +++ /dev/null @@ -1,2 +0,0 @@ -type;carrier;tech;profile;lifetime;fixed_costs;name;region;year;bus -volatile;wind;wind_turbine_onshore;onshore_BB;[25.4, 30.0, 30.0];[23280.0, 12600.0, 11340.0];BB_wind_wind_turbine_onshore;BB;[2016, 2030, 2050];electricity diff --git a/tests/_files/build_datapackage_goal/data/periods/periods.csv b/tests/_files/build_datapackage_goal/data/periods/periods.csv deleted file mode 100644 index d26cc7a..0000000 --- a/tests/_files/build_datapackage_goal/data/periods/periods.csv +++ /dev/null @@ -1,10 +0,0 @@ -timeindex;periods;timeincrement -2016-01-01 00:00:00;0;1 -2016-01-01 01:00:00;0;1 -2016-01-01 02:00:00;0;1 -2030-01-01 00:00:00;1;1 -2030-01-01 01:00:00;1;1 -2030-01-01 02:00:00;1;1 -2050-01-01 00:00:00;2;1 -2050-01-01 01:00:00;2;1 -2050-01-01 02:00:00;2;1 diff --git a/tests/_files/build_datapackage_goal/data/sequences/.gitkeep b/tests/_files/build_datapackage_goal/data/sequences/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/tests/_files/build_datapackage_goal/data/sequences/modex_tech_generator_gas_sequence.csv b/tests/_files/build_datapackage_goal/data/sequences/modex_tech_generator_gas_sequence.csv deleted file mode 100644 index 609dad5..0000000 --- a/tests/_files/build_datapackage_goal/data/sequences/modex_tech_generator_gas_sequence.csv +++ /dev/null @@ -1 +0,0 @@ -timeindex diff --git a/tests/_files/build_datapackage_goal/data/sequences/modex_tech_photovoltaic_utility_sequence.csv b/tests/_files/build_datapackage_goal/data/sequences/modex_tech_photovoltaic_utility_sequence.csv deleted file mode 100644 index ca66885..0000000 --- a/tests/_files/build_datapackage_goal/data/sequences/modex_tech_photovoltaic_utility_sequence.csv +++ /dev/null @@ -1,10 +0,0 @@ -timeindex;photovoltaic_BB -2016-01-01T00:00:00;0.0 -2016-01-01T01:00:00;0.0 -2016-01-01T02:00:00;0.16 -2030-01-01T00:00:00;0.0 -2030-01-01T01:00:00;0.0 -2030-01-01T02:00:00;0.3 -2050-01-01T00:00:00;0.0 -2050-01-01T01:00:00;0.0 -2050-01-01T02:00:00;0.5 diff --git a/tests/_files/build_datapackage_goal/data/sequences/modex_tech_storage_battery_sequence.csv b/tests/_files/build_datapackage_goal/data/sequences/modex_tech_storage_battery_sequence.csv deleted file mode 100644 index 609dad5..0000000 --- a/tests/_files/build_datapackage_goal/data/sequences/modex_tech_storage_battery_sequence.csv +++ /dev/null @@ -1 +0,0 @@ -timeindex diff --git a/tests/_files/build_datapackage_goal/data/sequences/modex_tech_wind_turbine_onshore_sequence.csv b/tests/_files/build_datapackage_goal/data/sequences/modex_tech_wind_turbine_onshore_sequence.csv deleted file mode 100644 index 0770eff..0000000 --- a/tests/_files/build_datapackage_goal/data/sequences/modex_tech_wind_turbine_onshore_sequence.csv +++ /dev/null @@ -1,10 +0,0 @@ -timeindex;onshore_BB -2016-01-01T00:00:00;0.0516 -2016-01-01T01:00:00;0.051 -2016-01-01T02:00:00;0.0444 -2030-01-01T00:00:00;0.0526 -2030-01-01T01:00:00;0.051 -2030-01-01T02:00:00;0.0444 -2050-01-01T00:00:00;0.0536 -2050-01-01T01:00:00;0.051 -2050-01-01T02:00:00;0.0444 diff --git a/tests/_files/build_datapackage_goal/datapackage.json b/tests/_files/build_datapackage_goal/datapackage.json deleted file mode 100644 index 54b357b..0000000 --- a/tests/_files/build_datapackage_goal/datapackage.json +++ /dev/null @@ -1,508 +0,0 @@ -{ - "profile": "tabular-data-package", - "resources": [ - { - "encoding": "utf-8", - "format": "csv", - "mediatype": "text/csv", - "name": "modex_tech_storage_battery_sequence", - "path": "data/sequences/modex_tech_storage_battery_sequence.csv", - "profile": "tabular-data-resource", - "schema": { - "fields": [ - { - "format": "default", - "name": "timeindex", - "type": "string" - } - ], - "foreignKeys": [], - "missingValues": [ - "" - ] - } - }, - { - "encoding": "utf-8", - "format": "csv", - "mediatype": "text/csv", - "name": "modex_tech_generator_gas_sequence", - "path": "data/sequences/modex_tech_generator_gas_sequence.csv", - "profile": "tabular-data-resource", - "schema": { - "fields": [ - { - "format": "default", - "name": "timeindex", - "type": "string" - } - ], - "foreignKeys": [], - "missingValues": [ - "" - ] - } - }, - { - "encoding": "utf-8", - "format": "csv", - "mediatype": "text/csv", - "name": "modex_tech_wind_turbine_onshore_sequence", - "path": "data/sequences/modex_tech_wind_turbine_onshore_sequence.csv", - "profile": "tabular-data-resource", - "schema": { - "fields": [ - { - "format": "default", - "name": "timeindex", - "type": "string" - }, - { - "format": "default", - "name": "onshore_BB", - "type": "number" - } - ], - "foreignKeys": [], - "missingValues": [ - "" - ] - } - }, - { - "encoding": "utf-8", - "format": "csv", - "mediatype": "text/csv", - "name": "modex_tech_photovoltaic_utility_sequence", - "path": "data/sequences/modex_tech_photovoltaic_utility_sequence.csv", - "profile": "tabular-data-resource", - "schema": { - "fields": [ - { - "format": "default", - "name": "timeindex", - "type": "string" - }, - { - "format": "default", - "name": "photovoltaic_BB", - "type": "number" - } - ], - "foreignKeys": [], - "missingValues": [ - "" - ] - } - }, - { - "encoding": "utf-8", - "format": "csv", - "mediatype": "text/csv", - "name": "periods", - "path": "data/periods/periods.csv", - "profile": "tabular-data-resource", - "schema": { - "fields": [ - { - "format": "default", - "name": "timeindex", - "type": "string" - }, - { - "format": "default", - "name": "periods", - "type": "integer" - }, - { - "format": "default", - "name": "timeincrement", - "type": "integer" - } - ], - "foreignKeys": [], - "missingValues": [ - "" - ] - } - }, - { - "encoding": "utf-8", - "format": "csv", - "mediatype": "text/csv", - "name": "bus", - "path": "data/elements/bus.csv", - "profile": "tabular-data-resource", - "schema": { - "fields": [ - { - "format": "default", - "name": "name", - "type": "string" - }, - { - "format": "default", - "name": "type", - "type": "string" - }, - { - "format": "default", - "name": "balanced", - "type": "boolean" - } - ], - "foreignKeys": [], - "missingValues": [ - "" - ], - "primaryKey": "name" - } - }, - { - "encoding": "utf-8", - "format": "csv", - "mediatype": "text/csv", - "name": "modex_tech_storage_battery", - "path": "data/elements/modex_tech_storage_battery.csv", - "profile": "tabular-data-resource", - "schema": { - "fields": [ - { - "format": "default", - "name": "type", - "type": "string" - }, - { - "format": "default", - "name": "carrier", - "type": "string" - }, - { - "format": "default", - "name": "tech", - "type": "string" - }, - { - "format": "default", - "name": "capacity", - "type": "number" - }, - { - "format": "default", - "name": "fixed_costs", - "type": "array" - }, - { - "format": "default", - "name": "name", - "type": "string" - }, - { - "format": "default", - "name": "region", - "type": "string" - }, - { - "format": "default", - "name": "year", - "type": "array" - }, - { - "format": "default", - "name": "invest_relation_output_capacity", - "type": "number" - }, - { - "format": "default", - "name": "bus", - "type": "string" - } - ], - "foreignKeys": [ - { - "fields": "bus", - "reference": { - "fields": "name", - "resource": "bus" - } - } - ], - "missingValues": [ - "" - ], - "primaryKey": "name" - } - }, - { - "encoding": "utf-8", - "format": "csv", - "mediatype": "text/csv", - "name": "modex_tech_generator_gas", - "path": "data/elements/modex_tech_generator_gas.csv", - "profile": "tabular-data-resource", - "schema": { - "fields": [ - { - "format": "default", - "name": "type", - "type": "string" - }, - { - "format": "default", - "name": "carrier", - "type": "string" - }, - { - "format": "default", - "name": "tech", - "type": "string" - }, - { - "format": "default", - "name": "condensing_efficiency", - "type": "array" - }, - { - "format": "default", - "name": "electric_efficiency", - "type": "array" - }, - { - "format": "default", - "name": "thermal_efficiency", - "type": "array" - }, - { - "format": "default", - "name": "capacity", - "type": "number" - }, - { - "format": "default", - "name": "carrier_cost", - "type": "array" - }, - { - "format": "default", - "name": "name", - "type": "string" - }, - { - "format": "default", - "name": "region", - "type": "string" - }, - { - "format": "default", - "name": "year", - "type": "array" - }, - { - "format": "default", - "name": "electricity_bus", - "type": "string" - }, - { - "format": "default", - "name": "heat_bus", - "type": "string" - }, - { - "format": "default", - "name": "fuel_bus", - "type": "string" - } - ], - "foreignKeys": [ - { - "fields": "electricity_bus", - "reference": { - "fields": "name", - "resource": "bus" - } - }, - { - "fields": "heat_bus", - "reference": { - "fields": "name", - "resource": "bus" - } - }, - { - "fields": "fuel_bus", - "reference": { - "fields": "name", - "resource": "bus" - } - } - ], - "missingValues": [ - "" - ], - "primaryKey": "name" - } - }, - { - "encoding": "utf-8", - "format": "csv", - "mediatype": "text/csv", - "name": "modex_tech_photovoltaic_utility", - "path": "data/elements/modex_tech_photovoltaic_utility.csv", - "profile": "tabular-data-resource", - "schema": { - "fields": [ - { - "format": "default", - "name": "type", - "type": "string" - }, - { - "format": "default", - "name": "carrier", - "type": "string" - }, - { - "format": "default", - "name": "tech", - "type": "string" - }, - { - "format": "default", - "name": "profile", - "type": "string" - }, - { - "format": "default", - "name": "lifetime", - "type": "array" - }, - { - "format": "default", - "name": "fixed_costs", - "type": "array" - }, - { - "format": "default", - "name": "name", - "type": "string" - }, - { - "format": "default", - "name": "region", - "type": "string" - }, - { - "format": "default", - "name": "year", - "type": "array" - }, - { - "format": "default", - "name": "bus", - "type": "string" - } - ], - "foreignKeys": [ - { - "fields": "bus", - "reference": { - "fields": "name", - "resource": "bus" - } - }, - { - "fields": "profile", - "reference": { - "resource": "modex_tech_photovoltaic_utility_sequence" - } - } - ], - "missingValues": [ - "" - ], - "primaryKey": "name" - } - }, - { - "encoding": "utf-8", - "format": "csv", - "mediatype": "text/csv", - "name": "modex_tech_wind_turbine_onshore", - "path": "data/elements/modex_tech_wind_turbine_onshore.csv", - "profile": "tabular-data-resource", - "schema": { - "fields": [ - { - "format": "default", - "name": "type", - "type": "string" - }, - { - "format": "default", - "name": "carrier", - "type": "string" - }, - { - "format": "default", - "name": "tech", - "type": "string" - }, - { - "format": "default", - "name": "profile", - "type": "string" - }, - { - "format": "default", - "name": "lifetime", - "type": "array" - }, - { - "format": "default", - "name": "fixed_costs", - "type": "array" - }, - { - "format": "default", - "name": "name", - "type": "string" - }, - { - "format": "default", - "name": "region", - "type": "string" - }, - { - "format": "default", - "name": "year", - "type": "array" - }, - { - "format": "default", - "name": "bus", - "type": "string" - } - ], - "foreignKeys": [ - { - "fields": "bus", - "reference": { - "fields": "name", - "resource": "bus" - } - }, - { - "fields": "profile", - "reference": { - "resource": "modex_tech_wind_turbine_onshore_sequence" - } - } - ], - "missingValues": [ - "" - ], - "primaryKey": "name" - } - } - ] -} diff --git a/tests/setup_mock.py b/tests/setup_mock.py new file mode 100644 index 0000000..933de4e --- /dev/null +++ b/tests/setup_mock.py @@ -0,0 +1,252 @@ +import collections +from unittest import mock + +import pandas as pd +from data_adapter.preprocessing import Adapter + +Mock = collections.namedtuple( + typename="Mock", + field_names=["mock_adapter", "process_adapter_map", "parameter_map"], +) + + +def define_mock(): + """ + Defines a Mock to be used in tests + Returns + Mock tuple with mappers + ------- + + """ + + def mock_get_process(process_name): + """ + Adding side effects and .scalar and .timeseries + Parameters + ---------- + process_name + + Returns + ------- + mocked function .get_process for Adapter + + """ + if process_name == "modex_tech_storage_battery": + process_mock = mock.Mock() + process_mock.scalars = pd.DataFrame( + { + "region": {0: "BB", 1: "BB", 2: "BB"}, + "year": {0: 2016, 1: 2030, 2: 2050}, + "capacity": {0: 17.8, 1: 17.8, 2: 17.8}, + "invest_relation_output_capacity": {0: 3.3, 1: 3.3, 2: 3.3}, + "tech": { + 0: "storage_battery", + 1: "storage_battery", + 2: "storage_battery", + }, + "carrier": { + 0: "Lithium", + 1: "Lithium", + 2: "Lithium", + }, + "fixed_costs": {0: 1, 1: 2, 2: 3}, + } + ) + process_mock.timeseries = pd.DataFrame() + return process_mock + elif process_name == "modex_tech_generator_gas": + process_mock = mock.Mock() + + process_mock.scalars = pd.DataFrame( + { + "region": {0: "BB", 1: "BB", 2: "BB"}, + "year": {0: 2016, 1: 2030, 2: 2050}, + "installed_capacity": { + 0: 330.2, + 1: 330.2, + 2: 330.2, + }, + "emission_factor": { + 0: 0.2, + 1: 0.2, + 2: 0.2, + }, + "fuel_costs": {0: 25.9, 1: 25.9, 2: 49.36}, + "tech": { + 0: "generator_gas", + 1: "generator_gas", + 2: "generator_gas", + }, + "carrier": { + 0: "gas", + 1: "gas", + 2: "gas", + }, + "condensing_efficiency": { + 0: 0.16, + 1: 0.3, + 2: 0.5, + }, + "electric_efficiency": {0: 0.35, 1: 0.35, 2: 0.4}, + "thermal_efficiency": {0: 0.5, 1: 0.5, 2: 0.45}, + } + ) + + process_mock.timeseries = pd.DataFrame() + return process_mock + elif process_name == "modex_tech_wind_turbine_onshore": + process_mock = mock.Mock() + process_mock.scalars = pd.DataFrame( + { + "region": {0: "BB", 1: "BB", 2: "BB"}, + "year": {0: 2016, 1: 2030, 2: 2050}, + "installed_capacity": { + 0: 5700.03, + 1: 5700.03375, + 2: 5700.03375, + }, + "fixed_costs": {0: 23280.0, 1: 12600.0, 2: 11340.0}, + "lifetime": {0: 25.4, 1: 30.0, 2: 30.0}, + "wacc": {0: 0.07, 1: 0.07, 2: 0.07}, + "tech": { + 0: "wind_turbine_onshore", + 1: "wind_turbine_onshore", + 2: "wind_turbine_onshore", + }, + "carrier": { + 0: "wind", + 1: "wind", + 2: "wind", + }, + } + ) + process_mock.timeseries = pd.DataFrame( + { + "onshore_BB": { + "2016-01-01T00:00:00": 0.0516, + "2016-01-01T01:00:00": 0.051, + "2016-01-01T02:00:00": 0.0444, + "2030-01-01T00:00:00": 0.0526, + "2030-01-01T01:00:00": 0.051, + "2030-01-01T02:00:00": 0.0444, + "2050-01-01T00:00:00": 0.0536, + "2050-01-01T01:00:00": 0.051, + "2050-01-01T02:00:00": 0.0444, + }, + } + ) + return process_mock + elif process_name == "modex_tech_photovoltaic_utility": + process_mock = mock.Mock() + process_mock.scalars = pd.DataFrame( + { + "region": {0: "BB", 1: "BB", 2: "BB"}, + "year": {0: 2016, 1: 2030, 2: 2050}, + "installed_capacity": { + 0: 9700.03, + 1: 10700.03375, + 2: 12700.03375, + }, + "fixed_costs": {0: 10280.0, 1: 8600.0, 2: 6340.0}, + "lifetime": {0: 25.4, 1: 30.0, 2: 30.0}, + "wacc": {0: 0.07, 1: 0.07, 2: 0.07}, + "tech": { + 0: "photovoltaic_utility", + 1: "photovoltaic_utility", + 2: "photovoltaic_utility", + }, + "carrier": { + 0: "solar", + 1: "solar", + 2: "solar", + }, + } + ) + process_mock.timeseries = pd.DataFrame( + { + "photovoltaic_BB": { + "2016-01-01T00:00:00": 0.0, + "2016-01-01T01:00:00": 0.0, + "2016-01-01T02:00:00": 0.16, + "2030-01-01T00:00:00": 0.0, + "2030-01-01T01:00:00": 0.0, + "2030-01-01T02:00:00": 0.30, + "2050-01-01T00:00:00": 0.0, + "2050-01-01T01:00:00": 0.0, + "2050-01-01T02:00:00": 0.50, + }, + } + ) + return process_mock + elif process_name == "modex_tech_Load": + process_mock = mock.Mock() + process_mock.scalars = pd.DataFrame( + { + "region": {0: "BB", 1: "BB", 2: "BB"}, + "year": {0: 2016, 1: 2030, 2: 2050}, + "amount": {0: 1, 1: 1, 2: 2}, + "carrier": { + 0: "electricity", + 1: "electricity", + 2: "electricity", + }, + } + ) + process_mock.timeseries = pd.DataFrame( + { + "Load_BB": { + "2016-01-01T00:00:00": 1.0, + "2016-01-01T01:00:00": 1.0, + "2016-01-01T02:00:00": 1.16, + "2030-01-01T00:00:00": 1.0, + "2030-01-01T01:00:00": 1.0, + "2030-01-01T02:00:00": 1.30, + "2050-01-01T00:00:00": 1.0, + "2050-01-01T01:00:00": 1.0, + "2050-01-01T02:00:00": 1.50, + }, + } + ) + return process_mock + + # Create a mock adapter object for testing + mock_adapter = mock.Mock(spec=Adapter) + # Mock the required methods and attributes of the Adapter + mock_adapter.get_structure.return_value = { + "modex_tech_storage_battery": { + "default": {"inputs": ["electricity"], "outputs": []} + }, + "modex_tech_generator_gas": { + "default": {"inputs": ["ch4"], "outputs": ["electricity"]}, + }, + "modex_tech_wind_turbine_onshore": { + "default": {"inputs": ["onshore"], "outputs": ["electricity"]} + }, + "modex_tech_photovoltaic_utility": { + "default": {"inputs": [], "outputs": ["electricity"]} + }, + "modex_tech_Load": {"default": {"inputs": ["electricity"], "outputs": []}}, + } + + mock_adapter.get_process.side_effect = mock_get_process + + process_adapter_map = { + "modex_tech_generator_gas": "ExtractionTurbineAdapter", + "modex_tech_storage_battery": "StorageAdapter", + "modex_tech_wind_turbine_onshore": "VolatileAdapter", + "modex_tech_photovoltaic_utility": "VolatileAdapter", + "modex_tech_Load": "LoadAdapter", + } + parameter_map = { + "DEFAULT": { + "marginal_cost": "variable_costs", + "fixed_cost": "fixed_costs", + "capacity_cost": "capital_costs", + }, + "ExtractionTurbineAdapter": { + "carrier_cost": "fuel_costs", + "capacity": "installed_capacity", + }, + "modex_tech_wind_turbine_onshore": {"profile": "onshore"}, + } + return Mock(mock_adapter, process_adapter_map, parameter_map) diff --git a/tests/test_build_datapackage.py b/tests/test_build_datapackage.py index 0b95993..023ee80 100644 --- a/tests/test_build_datapackage.py +++ b/tests/test_build_datapackage.py @@ -1,6 +1,4 @@ -import collections import os -from unittest import mock import pandas import pandas as pd @@ -8,227 +6,13 @@ from data_adapter.databus import download_collection from data_adapter.preprocessing import Adapter from pandas import Timestamp +from setup_mock import define_mock from utils import PATH_TEST_FILES, check_if_csv_dirs_equal from data_adapter_oemof.build_datapackage import DataPackage, refactor_timeseries path_default = PATH_TEST_FILES / "_files" -Mock = collections.namedtuple( - typename="Mock", - field_names=["mock_adapter", "process_adapter_map", "parameter_map"], -) - - -def define_mock(): - """ - Defines a Mock to be used in tests - Returns - Mock tuple with mappers - ------- - - """ - - def mock_get_process(process_name): - """ - Adding side effects and .scalar and .timeseries - Parameters - ---------- - process_name - - Returns - ------- - mocked function .get_process for Adapter - - """ - if process_name == "modex_tech_storage_battery": - process_mock = mock.Mock() - process_mock.scalars = pd.DataFrame( - { - "region": {0: "BB", 1: "BB", 2: "BB"}, - "year": {0: 2016, 1: 2030, 2: 2050}, - "capacity": {0: 17.8, 1: 17.8, 2: 17.8}, - "invest_relation_output_capacity": {0: 3.3, 1: 3.3, 2: 3.3}, - "tech": { - 0: "storage_battery", - 1: "storage_battery", - 2: "storage_battery", - }, - "carrier": { - 0: "Lithium", - 1: "Lithium", - 2: "Lithium", - }, - "fixed_costs": {0: 1, 1: 2, 2: 3}, - } - ) - process_mock.timeseries = pd.DataFrame() - return process_mock - elif process_name == "modex_tech_generator_gas": - process_mock = mock.Mock() - - process_mock.scalars = pd.DataFrame( - { - "region": {0: "BB", 1: "BB", 2: "BB"}, - "year": {0: 2016, 1: 2030, 2: 2050}, - "installed_capacity": { - 0: 330.2, - 1: 330.2, - 2: 330.2, - }, - "emission_factor": { - 0: 0.2, - 1: 0.2, - 2: 0.2, - }, # Todo: not implemented in any Facade yet?! - "fuel_costs": {0: 25.9, 1: 25.9, 2: 49.36}, - "tech": { - 0: "generator_gas", - 1: "generator_gas", - 2: "generator_gas", - }, - "carrier": { - 0: "gas", - 1: "gas", - 2: "gas", - }, - "condensing_efficiency": { - 0: 0.16, - 1: 0.3, - 2: 0.5, - }, - "electric_efficiency": {0: 0.35, 1: 0.35, 2: 0.4}, - "thermal_efficiency": {0: 0.5, 1: 0.5, 2: 0.45}, - } - ) - - process_mock.timeseries = pd.DataFrame() - return process_mock - elif process_name == "modex_tech_wind_turbine_onshore": - process_mock = mock.Mock() - process_mock.scalars = pd.DataFrame( - { - "region": {0: "BB", 1: "BB", 2: "BB"}, - "year": {0: 2016, 1: 2030, 2: 2050}, - "installed_capacity": { - 0: 5700.03, - 1: 5700.03375, - 2: 5700.03375, - }, - "fixed_costs": {0: 23280.0, 1: 12600.0, 2: 11340.0}, - "lifetime": {0: 25.4, 1: 30.0, 2: 30.0}, - "wacc": {0: 0.07, 1: 0.07, 2: 0.07}, - "tech": { - 0: "wind_turbine_onshore", - 1: "wind_turbine_onshore", - 2: "wind_turbine_onshore", - }, - "carrier": { - 0: "wind", - 1: "wind", - 2: "wind", - }, - } - ) - process_mock.timeseries = pd.DataFrame( - { - "onshore_BB": { - "2016-01-01T00:00:00": 0.0516, - "2016-01-01T01:00:00": 0.051, - "2016-01-01T02:00:00": 0.0444, - "2030-01-01T00:00:00": 0.0526, - "2030-01-01T01:00:00": 0.051, - "2030-01-01T02:00:00": 0.0444, - "2050-01-01T00:00:00": 0.0536, - "2050-01-01T01:00:00": 0.051, - "2050-01-01T02:00:00": 0.0444, - }, - } - ) - return process_mock - elif process_name == "modex_tech_photovoltaic_utility": - process_mock = mock.Mock() - process_mock.scalars = pd.DataFrame( - { - "region": {0: "BB", 1: "BB", 2: "BB"}, - "year": {0: 2016, 1: 2030, 2: 2050}, - "installed_capacity": { - 0: 9700.03, - 1: 10700.03375, - 2: 12700.03375, - }, - "fixed_costs": {0: 10280.0, 1: 8600.0, 2: 6340.0}, - "lifetime": {0: 25.4, 1: 30.0, 2: 30.0}, - "wacc": {0: 0.07, 1: 0.07, 2: 0.07}, - "tech": { - 0: "photovoltaic_utility", - 1: "photovoltaic_utility", - 2: "photovoltaic_utility", - }, - "carrier": { - 0: "solar", - 1: "solar", - 2: "solar", - }, - } - ) - process_mock.timeseries = pd.DataFrame( - { - "photovoltaic_BB": { - "2016-01-01T00:00:00": 0.0, - "2016-01-01T01:00:00": 0.0, - "2016-01-01T02:00:00": 0.16, - "2030-01-01T00:00:00": 0.0, - "2030-01-01T01:00:00": 0.0, - "2030-01-01T02:00:00": 0.30, - "2050-01-01T00:00:00": 0.0, - "2050-01-01T01:00:00": 0.0, - "2050-01-01T02:00:00": 0.50, - }, - } - ) - return process_mock - - # Create a mock adapter object for testing - mock_adapter = mock.Mock(spec=Adapter) - # Mock the required methods and attributes of the Adapter - mock_adapter.get_structure.return_value = { - "modex_tech_storage_battery": { - "default": {"inputs": ["electricity"], "outputs": []} - }, - "modex_tech_generator_gas": { - "default": {"inputs": ["ch4"], "outputs": ["electricity"]}, - }, - "modex_tech_wind_turbine_onshore": { - "default": {"inputs": ["onshore"], "outputs": ["electricity"]} - }, - "modex_tech_photovoltaic_utility": { - "default": {"inputs": ["onshore"], "outputs": ["electricity"]} - }, - } - - mock_adapter.get_process.side_effect = mock_get_process - - process_adapter_map = { - "modex_tech_generator_gas": "ExtractionTurbineAdapter", - "modex_tech_storage_battery": "StorageAdapter", - "modex_tech_wind_turbine_onshore": "VolatileAdapter", - "modex_tech_photovoltaic_utility": "VolatileAdapter", - } - parameter_map = { - "DEFAULT": { - "marginal_cost": "variable_costs", - "fixed_cost": "fixed_costs", - "capacity_cost": "capital_costs", - }, - "ExtractionTurbineAdapter": { - "carrier_cost": "fuel_costs", - "capacity": "installed_capacity", - }, - "modex_tech_wind_turbine_onshore": {"profile": "onshore"}, - } - return Mock(mock_adapter, process_adapter_map, parameter_map) - def test_refactor_timeseries(): timeseries = pandas.DataFrame(