Skip to content

Commit

Permalink
renaming
Browse files Browse the repository at this point in the history
  • Loading branch information
k-rieck committed Jan 16, 2024
1 parent 516c48f commit d79518f
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 82 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Data Collection for Scenario Comparison with Pyam."""
"""Data Collection for Scenario Comparison."""
# clean
import glob
import datetime
Expand All @@ -15,9 +15,9 @@
from hisim import log


class PyamDataCollector:
class ResultDataCollector:

"""PyamDataCollector class which collects and concatenate the pyam data from the system_setups/results."""
"""ResultDataCollector class which collects and concatenate the result data from the system_setups/results."""

def __init__(
self,
Expand All @@ -31,7 +31,7 @@ def __init__(
) -> None:
"""Initialize the class."""
result_folder = folder_from_which_data_will_be_collected
self.pyam_data_folder = os.path.join(
self.result_data_folder = os.path.join(
result_folder,
os.pardir,
"results_for_scenario_comparison",
Expand All @@ -47,43 +47,43 @@ def __init__(
result_path=result_folder
)

if data_processing_mode == PyamDataProcessingModeEnum.PROCESS_ALL_DATA:
if data_processing_mode == ResultDataProcessingModeEnum.PROCESS_ALL_DATA:

parameter_key = None

elif (
data_processing_mode
== PyamDataProcessingModeEnum.PROCESS_FOR_DIFFERENT_BUILDING_SIZES
== ResultDataProcessingModeEnum.PROCESS_FOR_DIFFERENT_BUILDING_SIZES
):
parameter_key = "conditioned_floor_area_in_m2"

elif (
data_processing_mode
== PyamDataProcessingModeEnum.PROCESS_FOR_DIFFERENT_BUILDING_CODES
== ResultDataProcessingModeEnum.PROCESS_FOR_DIFFERENT_BUILDING_CODES
):
parameter_key = "building_code"

elif (
data_processing_mode
== PyamDataProcessingModeEnum.PROCESS_FOR_DIFFERENT_PV_AZIMUTH_ANGLES
== ResultDataProcessingModeEnum.PROCESS_FOR_DIFFERENT_PV_AZIMUTH_ANGLES
):
parameter_key = "pv_azimuth"

elif (
data_processing_mode
== PyamDataProcessingModeEnum.PROCESS_FOR_DIFFERENT_PV_TILT_ANGLES
== ResultDataProcessingModeEnum.PROCESS_FOR_DIFFERENT_PV_TILT_ANGLES
):
parameter_key = "pv_tilt"

elif (
data_processing_mode
== PyamDataProcessingModeEnum.PROCESS_FOR_DIFFERENT_SHARE_OF_MAXIMUM_PV
== ResultDataProcessingModeEnum.PROCESS_FOR_DIFFERENT_SHARE_OF_MAXIMUM_PV
):
parameter_key = "share_of_maximum_pv_power"

elif (
data_processing_mode
== PyamDataProcessingModeEnum.PROCESS_FOR_DIFFERENT_NUMBER_OF_DWELLINGS
== ResultDataProcessingModeEnum.PROCESS_FOR_DIFFERENT_NUMBER_OF_DWELLINGS
):
parameter_key = "number_of_dwellings_per_building"

Expand Down Expand Up @@ -179,7 +179,7 @@ def clean_result_directory_from_unfinished_results(self, result_path: str) -> No
"""When a result folder does not contain the finished_flag, it will be removed from the system_setups/result folder."""
list_of_unfinished_folders = []
with open(
os.path.join(self.pyam_data_folder, "failed_simualtions.txt"),
os.path.join(self.result_data_folder, "failed_simualtions.txt"),
"a",
encoding="utf-8",
) as file:
Expand Down Expand Up @@ -221,7 +221,7 @@ def filter_results_that_failed_to_heat_or_cool_building_sufficiently(
list_of_unsuccessful_folders = []
with open(
os.path.join(
self.pyam_data_folder,
self.result_data_folder,
"succeeded_simulations_that_showed_too_high_or_too_low_building_temps.txt",
),
"a",
Expand Down Expand Up @@ -402,13 +402,13 @@ def import_data_from_file(

all_csv_files = []

if analyze_yearly_or_hourly_data == PyamDataTypeEnum.HOURLY:
if analyze_yearly_or_hourly_data == ResultDataTypeEnum.HOURLY:
kind_of_data_set = "hourly"
elif analyze_yearly_or_hourly_data == PyamDataTypeEnum.YEARLY:
elif analyze_yearly_or_hourly_data == ResultDataTypeEnum.YEARLY:
kind_of_data_set = "yearly"
elif analyze_yearly_or_hourly_data == PyamDataTypeEnum.DAILY:
elif analyze_yearly_or_hourly_data == ResultDataTypeEnum.DAILY:
kind_of_data_set = "daily"
elif analyze_yearly_or_hourly_data == PyamDataTypeEnum.MONTHLY:
elif analyze_yearly_or_hourly_data == ResultDataTypeEnum.MONTHLY:
kind_of_data_set = "monthly"
else:
raise ValueError(
Expand Down Expand Up @@ -591,7 +591,7 @@ def read_csv_and_generate_pandas_dataframe(
)

filename = self.store_pyam_data_with_the_right_name_and_in_the_right_path(
pyam_data_folder=self.pyam_data_folder,
result_data_folder=self.result_data_folder,
simulation_duration_key=simulation_duration_key,
time_resolution_of_data_set=time_resolution_of_data_set,
parameter_key=parameter_key,
Expand All @@ -600,20 +600,20 @@ def read_csv_and_generate_pandas_dataframe(

def store_pyam_data_with_the_right_name_and_in_the_right_path(
self,
pyam_data_folder: str,
result_data_folder: str,
simulation_duration_key: str,
time_resolution_of_data_set: Any,
parameter_key: Optional[str] = None,
) -> str:
"""Store csv files in the pyam data folder with the right filename and path."""

if time_resolution_of_data_set == PyamDataTypeEnum.HOURLY:
if time_resolution_of_data_set == ResultDataTypeEnum.HOURLY:
kind_of_data_set = "hourly"
elif time_resolution_of_data_set == PyamDataTypeEnum.YEARLY:
elif time_resolution_of_data_set == ResultDataTypeEnum.YEARLY:
kind_of_data_set = "yearly"
elif time_resolution_of_data_set == PyamDataTypeEnum.DAILY:
elif time_resolution_of_data_set == ResultDataTypeEnum.DAILY:
kind_of_data_set = "daily"
elif time_resolution_of_data_set == PyamDataTypeEnum.MONTHLY:
elif time_resolution_of_data_set == ResultDataTypeEnum.MONTHLY:
kind_of_data_set = "monthly"
else:
raise ValueError(
Expand All @@ -622,13 +622,13 @@ def store_pyam_data_with_the_right_name_and_in_the_right_path(

if parameter_key is not None:
path_for_file = os.path.join(
pyam_data_folder,
result_data_folder,
f"data_with_different_{parameter_key}s",
f"simulation_duration_of_{simulation_duration_key}_days",
)
else:
path_for_file = os.path.join(
pyam_data_folder,
result_data_folder,
"data_with_all_parameters",
f"simulation_duration_of_{simulation_duration_key}_days",
)
Expand Down Expand Up @@ -877,7 +877,7 @@ def go_through_all_pyam_data_folders_and_check_if_module_configs_are_double_some
return list_of_pyam_folders_which_have_only_unique_configs


class PyamDataTypeEnum(enum.Enum):
class ResultDataTypeEnum(enum.Enum):

"""PyamDataTypeEnum class.
Expand All @@ -890,7 +890,7 @@ class PyamDataTypeEnum(enum.Enum):
YEARLY = "yearly"


class PyamDataProcessingModeEnum(enum.Enum):
class ResultDataProcessingModeEnum(enum.Enum):

"""PyamDataProcessingModeEnum class.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Data Processing and Plotting for Scenario Comparison with Pyam."""
"""Data Processing and Plotting for Scenario Comparison."""


import glob
Expand All @@ -18,19 +18,19 @@
from ordered_set import OrderedSet
import seaborn as sns

from hisim.postprocessing.scenario_evaluation.pyam_data_collection import (
PyamDataTypeEnum,
PyamDataProcessingModeEnum,
from hisim.postprocessing.scenario_evaluation.result_data_collection import (
ResultDataTypeEnum,
ResultDataProcessingModeEnum,
)
from hisim.postprocessing.chartbase import ChartFontsAndSize
from hisim import log

# TODO: debugging needed


class PyAmChartGenerator:
class ScenarioChartGenerator:

"""PyamChartGenerator class."""
"""ScenarioChartGenerator class."""

def __init__(
self,
Expand All @@ -49,50 +49,50 @@ def __init__(

self.datetime_string = datetime.datetime.now().strftime("%Y%m%d_%H%M")
self.show_plot_legend: bool = True
if data_processing_mode == PyamDataProcessingModeEnum.PROCESS_ALL_DATA:
if data_processing_mode == ResultDataProcessingModeEnum.PROCESS_ALL_DATA:

data_path_strip = "data_with_all_parameters"
result_path_strip = "results_for_all_parameters"
self.show_plot_legend = False

elif (
data_processing_mode
== PyamDataProcessingModeEnum.PROCESS_FOR_DIFFERENT_BUILDING_CODES
== ResultDataProcessingModeEnum.PROCESS_FOR_DIFFERENT_BUILDING_CODES
):
data_path_strip = "data_with_different_building_codes"
result_path_strip = "results_different_building_codes"

elif (
data_processing_mode
== PyamDataProcessingModeEnum.PROCESS_FOR_DIFFERENT_BUILDING_SIZES
== ResultDataProcessingModeEnum.PROCESS_FOR_DIFFERENT_BUILDING_SIZES
):
data_path_strip = "data_with_different_conditioned_floor_area_in_m2s"
result_path_strip = "results_different_conditioned_floor_area_in_m2s"

elif (
data_processing_mode
== PyamDataProcessingModeEnum.PROCESS_FOR_DIFFERENT_PV_AZIMUTH_ANGLES
== ResultDataProcessingModeEnum.PROCESS_FOR_DIFFERENT_PV_AZIMUTH_ANGLES
):
data_path_strip = "data_with_different_pv_azimuths"
result_path_strip = "results_different_pv_azimuths"

elif (
data_processing_mode
== PyamDataProcessingModeEnum.PROCESS_FOR_DIFFERENT_PV_TILT_ANGLES
== ResultDataProcessingModeEnum.PROCESS_FOR_DIFFERENT_PV_TILT_ANGLES
):
data_path_strip = "data_with_different_pv_tilts"
result_path_strip = "results_different_pv_tilts"

elif (
data_processing_mode
== PyamDataProcessingModeEnum.PROCESS_FOR_DIFFERENT_SHARE_OF_MAXIMUM_PV
== ResultDataProcessingModeEnum.PROCESS_FOR_DIFFERENT_SHARE_OF_MAXIMUM_PV
):
data_path_strip = "data_with_different_share_of_maximum_pv_powers"
result_path_strip = "results_different_share_of_maximum_pv_powers"

elif (
data_processing_mode
== PyamDataProcessingModeEnum.PROCESS_FOR_DIFFERENT_NUMBER_OF_DWELLINGS
== ResultDataProcessingModeEnum.PROCESS_FOR_DIFFERENT_NUMBER_OF_DWELLINGS
):
data_path_strip = "data_with_different_number_of_dwellings_per_buildings"
result_path_strip = "results_different_number_of_dwellings_per_buildings"
Expand Down Expand Up @@ -139,7 +139,7 @@ def __init__(

self.make_plots_with_specific_kind_of_data(
time_resolution_of_data_set=time_resolution_of_data_set,
pyam_dataframe=pandas_dataframe,
pandas_dataframe=pandas_dataframe,
simulation_duration_key=simulation_duration_to_check,
variables_to_check=variables_to_check,
)
Expand All @@ -158,13 +158,13 @@ def get_dataframe_and_create_pandas_dataframe_for_all_data(
) -> Tuple[pd.DataFrame, str, str, List[str]]:
"""Get csv data and create pyam dataframes."""

if time_resolution_of_data_set == PyamDataTypeEnum.HOURLY:
if time_resolution_of_data_set == ResultDataTypeEnum.HOURLY:
kind_of_data_set = "hourly"
elif time_resolution_of_data_set == PyamDataTypeEnum.YEARLY:
elif time_resolution_of_data_set == ResultDataTypeEnum.YEARLY:
kind_of_data_set = "yearly"
elif time_resolution_of_data_set == PyamDataTypeEnum.DAILY:
elif time_resolution_of_data_set == ResultDataTypeEnum.DAILY:
kind_of_data_set = "daily"
elif time_resolution_of_data_set == PyamDataTypeEnum.MONTHLY:
elif time_resolution_of_data_set == ResultDataTypeEnum.MONTHLY:
kind_of_data_set = "monthly"
else:
raise ValueError(
Expand Down Expand Up @@ -214,16 +214,16 @@ def get_dataframe_and_create_pandas_dataframe_for_all_data(
def make_plots_with_specific_kind_of_data(
self,
time_resolution_of_data_set: Any,
pyam_dataframe: pd.DataFrame,
pandas_dataframe: pd.DataFrame,
simulation_duration_key: str,
variables_to_check: List[str],
) -> None:
"""Make plots for different kind of data."""

log.information(f"Simulation duration: {simulation_duration_key} days.")

if pyam_dataframe.empty:
raise ValueError("Pyam dataframe is empty.")
if pandas_dataframe.empty:
raise ValueError("Dataframe is empty.")

sub_results_folder = f"simulation_duration_of_{simulation_duration_key}_days"
sub_sub_results_folder = (
Expand Down Expand Up @@ -254,7 +254,7 @@ def make_plots_with_specific_kind_of_data(

# filter the dataframe according to variable
filtered_data = self.filter_pandas_dataframe(
dataframe=pyam_dataframe, variable_to_check=variable_to_check
dataframe=pandas_dataframe, variable_to_check=variable_to_check
)
# get unit of variable
try:
Expand All @@ -265,7 +265,7 @@ def make_plots_with_specific_kind_of_data(
else:
unit = "-"

if time_resolution_of_data_set == PyamDataTypeEnum.YEARLY:
if time_resolution_of_data_set == ResultDataTypeEnum.YEARLY:
kind_of_data_set = "yearly"

# get statistical data
Expand Down Expand Up @@ -295,7 +295,7 @@ def make_plots_with_specific_kind_of_data(

try:
self.make_scatter_plot_for_pandas_dataframe(
full_pandas_dataframe=pyam_dataframe,
full_pandas_dataframe=pandas_dataframe,
filtered_data=filtered_data,
y_data_variable=self.path_addition,
)
Expand All @@ -314,18 +314,18 @@ def make_plots_with_specific_kind_of_data(
)

elif time_resolution_of_data_set in (
PyamDataTypeEnum.HOURLY,
PyamDataTypeEnum.DAILY,
PyamDataTypeEnum.MONTHLY,
ResultDataTypeEnum.HOURLY,
ResultDataTypeEnum.DAILY,
ResultDataTypeEnum.MONTHLY,
):

if time_resolution_of_data_set == PyamDataTypeEnum.HOURLY:
if time_resolution_of_data_set == ResultDataTypeEnum.HOURLY:
kind_of_data_set = "hourly"
line_plot_marker_size = 2
elif time_resolution_of_data_set == PyamDataTypeEnum.DAILY:
elif time_resolution_of_data_set == ResultDataTypeEnum.DAILY:
kind_of_data_set = "daily"
line_plot_marker_size = 3
elif time_resolution_of_data_set == PyamDataTypeEnum.MONTHLY:
elif time_resolution_of_data_set == ResultDataTypeEnum.MONTHLY:
kind_of_data_set = "monthly"
line_plot_marker_size = 5

Expand Down Expand Up @@ -830,21 +830,6 @@ def filter_pandas_dataframe(
)
return filtered_dataframe

def decide_for_scenario_or_variable_comparison(
self, filtered_data: pyam.IamDataFrame
) -> str:
"""Decide for each plot what will be compared, different scenarios or different variales."""

if len(filtered_data.scenario) == 1 and len(filtered_data.variable) > 1:
comparison_mode = "variable"
elif len(filtered_data.scenario) > 1 and len(filtered_data.variable) == 1:
comparison_mode = "scenario"
else:
raise ValueError(
f"No comparison mode could be determined. There are {len(filtered_data.scenario)} scenarios and {len(filtered_data.variable)} variables filtered."
)

return comparison_mode

def get_statistics_of_data_and_write_to_excel(
self, filtered_data: pd.DataFrame, path_to_save: str, kind_of_data_set: str,
Expand Down
Loading

0 comments on commit d79518f

Please sign in to comment.