-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #83 from SPF-OST/82-create-scenario-csvs-from-ini-…
…file 82 create scenario csvs from ini file
- Loading branch information
Showing
27 changed files
with
390 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,82 @@ | ||
import abc as _abc | ||
import dataclasses as _dc | ||
import pathlib as _pl | ||
import typing as _tp | ||
|
||
import pandas as _pd | ||
|
||
import optihood.IO.groupScenarioWriter as _gsw | ||
import optihood.IO.individualScenarioWriter as _isw | ||
import optihood.entities as _ent | ||
|
||
|
||
@_dc.dataclass() | ||
class ScenarioCreator: | ||
""" Can be used to get data directly without writing to file using 'ScenarioCreator.get_scenario()'. | ||
The building_nrs are only used for the individual scenarios. | ||
""" | ||
config_file_path: _pl.Path | ||
version: _tp.Literal['grouped', 'individual'] | ||
nr_of_buildings: int = 1 | ||
building_nrs: int = 0 | ||
data: dict[str, _pd.DataFrame] = _dc.field(init=False) | ||
|
||
def __post_init__(self): | ||
if self.version == 'grouped': | ||
self.get_scenario = self._get_grouped_scenario | ||
elif self.version == 'individual': | ||
self.get_scenario = self._get_individual_scenario | ||
|
||
def _get_grouped_scenario(self): | ||
data = _gsw.create_scenario_file(self.config_file_path, self.nr_of_buildings) | ||
return data | ||
|
||
def _get_individual_scenario(self): | ||
data = _isw.create_scenario_file(self.config_file_path, self.building_nrs, self.nr_of_buildings) | ||
return data | ||
|
||
@_abc.abstractmethod | ||
def _write_scenario_to_file(self, file_path: _pl.Path) -> None: | ||
pass | ||
|
||
def write(self, file_path: _pl.Path) -> None: | ||
self.data = self.get_scenario() | ||
self._write_scenario_to_file(file_path) | ||
|
||
def write_prepared_data_and_sheets_to_excel(excel_file_path: str, excel_data: dict): | ||
# better to use pathlib paths. | ||
|
||
class ScenarioFileWriterExcel(ScenarioCreator): | ||
def _write_scenario_to_file(self, file_path: _pl.Path) -> None: | ||
write_prepared_data_and_sheets_to_excel(file_path, self.data) | ||
|
||
|
||
class ScenarioFileWriterCSV(ScenarioCreator): | ||
def __post_init__(self): | ||
super().__post_init__() | ||
paths = _ent.CsvInputFilePathsRelative | ||
self.relative_file_paths = { | ||
_ent.NodeKeys.buses: paths.buses, | ||
_ent.NodeKeys.grid_connection: paths.grid_connection, | ||
_ent.NodeKeys.commodity_sources: paths.commodity_sources, | ||
_ent.NodeKeys.solar: paths.solar, | ||
_ent.NodeKeys.transformers: paths.transformers, | ||
_ent.NodeKeys.demand: paths.demand, | ||
_ent.NodeKeys.storages: paths.storages, | ||
_ent.NodeKeys.stratified_storage: paths.stratified_storage, | ||
_ent.NodeKeys.profiles: paths.profiles, | ||
} | ||
|
||
def _write_scenario_to_file(self, folder_path: _pl.Path) -> None: | ||
for key, path in self.relative_file_paths.items(): | ||
file_path = folder_path / path | ||
write_to_csv(file_path, self.data[key]) | ||
|
||
|
||
def write_prepared_data_and_sheets_to_excel(excel_file_path: _pl.Path, excel_data: dict): | ||
# maybe this can be inlined? | ||
with _pd.ExcelWriter(excel_file_path, engine='openpyxl') as writer: | ||
for sheet, data in excel_data.items(): | ||
data.to_excel(writer, sheet_name=sheet, index=False) | ||
|
||
|
||
def write_to_csv(file_path: _pl.Path, data_sheet: _pd.DataFrame) -> None: | ||
data_sheet.to_csv(file_path) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
,label,building,excess,excess costs,active | ||
0,gridBus,1,0,,1 | ||
1,gridBus,2,0,,1 | ||
2,gridBus,3,0,,1 | ||
3,gridBus,4,0,,1 | ||
4,electricityProdBus,1,0,,1 | ||
5,electricityProdBus,2,0,,1 | ||
6,electricityProdBus,3,0,,1 | ||
7,electricityProdBus,4,0,,1 | ||
8,electricityInBus,1,0,,1 | ||
9,electricityInBus,2,0,,1 | ||
10,electricityInBus,3,0,,1 | ||
11,electricityInBus,4,0,,1 | ||
12,shDemandBus,1,0,,1 | ||
13,shDemandBus,2,0,,1 | ||
14,shDemandBus,3,0,,1 | ||
15,shDemandBus,4,0,,1 | ||
16,dhwDemandBus,1,0,,1 | ||
17,dhwDemandBus,2,0,,1 | ||
18,dhwDemandBus,3,0,,1 | ||
19,dhwDemandBus,4,0,,1 | ||
20,shSourceBus,1,0,,1 | ||
21,shSourceBus,2,0,,1 | ||
22,shSourceBus,3,0,,1 | ||
23,shSourceBus,4,0,,1 | ||
24,dhwStorageBus,1,0,,1 | ||
25,dhwStorageBus,2,0,,1 | ||
26,dhwStorageBus,3,0,,1 | ||
27,dhwStorageBus,4,0,,1 | ||
28,electricityBus,1,1,-0.09,1 | ||
29,electricityBus,2,1,-0.09,1 | ||
30,electricityBus,3,1,-0.09,1 | ||
31,electricityBus,4,1,-0.09,1 | ||
32,spaceHeatingBus,1,0,,1 | ||
33,spaceHeatingBus,2,0,,1 | ||
34,spaceHeatingBus,3,0,,1 | ||
35,spaceHeatingBus,4,0,,1 | ||
36,domesticHotWaterBus,1,0,,1 | ||
37,domesticHotWaterBus,2,0,,1 | ||
38,domesticHotWaterBus,3,0,,1 | ||
39,domesticHotWaterBus,4,0,,1 |
5 changes: 5 additions & 0 deletions
5
tests/test_writers/expected_files/group_csvs/commodity_sources.csv
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
,label,building,to,variable costs,CO2 impact,active | ||
0,electricityResource,1,gridBus,0.204,..\excels\basic_example\electricity_impact.csv,1 | ||
1,electricityResource,2,gridBus,0.204,..\excels\basic_example\electricity_impact.csv,1 | ||
2,electricityResource,3,gridBus,0.204,..\excels\basic_example\electricity_impact.csv,1 | ||
3,electricityResource,4,gridBus,0.204,..\excels\basic_example\electricity_impact.csv,1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
,label,building,active,from,fixed,nominal value,building model | ||
0,electricityDemand,1,1,electricityInBus,1,1, | ||
1,electricityDemand,2,1,electricityInBus,1,1, | ||
2,electricityDemand,3,1,electricityInBus,1,1, | ||
3,electricityDemand,4,1,electricityInBus,1,1, | ||
4,spaceHeatingDemand,1,1,shDemandBus,1,1, | ||
5,spaceHeatingDemand,2,1,shDemandBus,1,1, | ||
6,spaceHeatingDemand,3,1,shDemandBus,1,1, | ||
7,spaceHeatingDemand,4,1,shDemandBus,1,1, | ||
8,domesticHotWaterDemand,1,1,dhwDemandBus,1,1, | ||
9,domesticHotWaterDemand,2,1,dhwDemandBus,1,1, | ||
10,domesticHotWaterDemand,3,1,dhwDemandBus,1,1, | ||
11,domesticHotWaterDemand,4,1,dhwDemandBus,1,1, |
25 changes: 25 additions & 0 deletions
25
tests/test_writers/expected_files/group_csvs/grid_connection.csv
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
,label,building,from,to,efficiency | ||
0,gridElectricity,1,gridBus,electricityInBus,1 | ||
1,gridElectricity,2,gridBus,electricityInBus,1 | ||
2,gridElectricity,3,gridBus,electricityInBus,1 | ||
3,gridElectricity,4,gridBus,electricityInBus,1 | ||
4,electricitySource,1,electricityProdBus,electricityBus,1 | ||
5,electricitySource,2,electricityProdBus,electricityBus,1 | ||
6,electricitySource,3,electricityProdBus,electricityBus,1 | ||
7,electricitySource,4,electricityProdBus,electricityBus,1 | ||
8,producedElectricity,1,electricityBus,electricityInBus,1 | ||
9,producedElectricity,2,electricityBus,electricityInBus,1 | ||
10,producedElectricity,3,electricityBus,electricityInBus,1 | ||
11,producedElectricity,4,electricityBus,electricityInBus,1 | ||
12,shSource,1,shSourceBus,spaceHeatingBus,1 | ||
13,shSource,2,shSourceBus,spaceHeatingBus,1 | ||
14,shSource,3,shSourceBus,spaceHeatingBus,1 | ||
15,shSource,4,shSourceBus,spaceHeatingBus,1 | ||
16,spaceHeating,1,spaceHeatingBus,shDemandBus,1 | ||
17,spaceHeating,2,spaceHeatingBus,shDemandBus,1 | ||
18,spaceHeating,3,spaceHeatingBus,shDemandBus,1 | ||
19,spaceHeating,4,spaceHeatingBus,shDemandBus,1 | ||
20,domesticHotWater,1,domesticHotWaterBus,dhwDemandBus,1 | ||
21,domesticHotWater,2,domesticHotWaterBus,dhwDemandBus,1 | ||
22,domesticHotWater,3,domesticHotWaterBus,dhwDemandBus,1 | ||
23,domesticHotWater,4,domesticHotWaterBus,dhwDemandBus,1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
,name,path | ||
0,weather_data,..\excels\basic_example\weather.csv | ||
0,demand_profiles,..\excels\basic_example\demand_profiles |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
,label,building,from,to,connect,electrical_consumption,peripheral_losses,latitude,longitude,tilt,azimuth,eta_0,a_1,a_2,temp_collector_inlet,delta_temp_n,capacity_max,capacity_min,lifetime,maintenance,installation,planification,invest_base,invest_cap,heat_impact,elec_impact,impact_cap,active | ||
0,pv,1,,electricityProdBus,,,0.05,47.49,7.59,30,180,,,,,40,500,0.4,30,0.02,0,0,17950,1103,0,0,1131,1.0 | ||
1,pv,2,,electricityProdBus,,,0.05,47.49,7.59,30,180,,,,,40,500,0.4,30,0.02,0,0,17950,1103,0,0,1131,1.0 | ||
2,pv,3,,electricityProdBus,,,0.05,47.49,7.59,30,180,,,,,40,500,0.4,30,0.02,0,0,17950,1103,0,0,1131,1.0 | ||
3,pv,4,,electricityProdBus,,,0.05,47.49,7.59,30,180,,,,,40,500,0.4,30,0.02,0,0,17950,1103,0,0,1131,1.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
,label,building,active,from,to,efficiency inflow,efficiency outflow,initial capacity,capacity min,capacity max,capacity loss,lifetime,maintenance,installation,planification,invest_base,invest_cap,heat_impact,elec_impact,impact_cap | ||
0,electricalStorage,1,1,electricityProdBus,electricityBus,0.9,0.86,0,0,1000000,0,15,0,0,0,5138,981,0,0,28.66 | ||
1,electricalStorage,2,1,electricityProdBus,electricityBus,0.9,0.86,0,0,1000000,0,15,0,0,0,5138,981,0,0,28.66 | ||
2,electricalStorage,3,1,electricityProdBus,electricityBus,0.9,0.86,0,0,1000000,0,15,0,0,0,5138,981,0,0,28.66 | ||
3,electricalStorage,4,1,electricityProdBus,electricityBus,0.9,0.86,0,0,1000000,0,15,0,0,0,5138,981,0,0,28.66 | ||
4,shStorage,1,1,shSourceBus,spaceHeatingBus,,,0,0,1000000,,20,0,0,0,1092,1.41,0,0,0.49 | ||
5,shStorage,2,1,shSourceBus,spaceHeatingBus,,,0,0,1000000,,20,0,0,0,1092,1.41,0,0,0.49 | ||
6,shStorage,3,1,shSourceBus,spaceHeatingBus,,,0,0,1000000,,20,0,0,0,1092,1.41,0,0,0.49 | ||
7,shStorage,4,1,shSourceBus,spaceHeatingBus,,,0,0,1000000,,20,0,0,0,1092,1.41,0,0,0.49 | ||
8,dhwStorage,1,1,dhwStorageBus,domesticHotWaterBus,,,0,0,1000000,,20,0,0,0,2132,6.88,0,0,0.49 | ||
9,dhwStorage,2,1,dhwStorageBus,domesticHotWaterBus,,,0,0,1000000,,20,0,0,0,2132,6.88,0,0,0.49 | ||
10,dhwStorage,3,1,dhwStorageBus,domesticHotWaterBus,,,0,0,1000000,,20,0,0,0,2132,6.88,0,0,0.49 | ||
11,dhwStorage,4,1,dhwStorageBus,domesticHotWaterBus,,,0,0,1000000,,20,0,0,0,2132,6.88,0,0,0.49 |
3 changes: 3 additions & 0 deletions
3
tests/test_writers/expected_files/group_csvs/stratified_storage.csv
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
,label,diameter,temp_h,temp_c,temp_env,inflow_conversion_factor,outflow_conversion_factor,s_iso,lamb_iso,alpha_inside,alpha_outside | ||
0,shStorage,1,35,15,15,1,1,100,0.03,100,10 | ||
1,dhwStorage,1,60,15,15,1,1,100,0.03,100,10 |
Oops, something went wrong.