Skip to content

Commit

Permalink
pep coding changes
Browse files Browse the repository at this point in the history
  • Loading branch information
gituser789 committed Nov 27, 2023
1 parent 0d5c9aa commit f16eeb9
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions femmt/logparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,32 @@
from enum import Enum
from dataclasses import dataclass


class SweepTypes(Enum):
SingleSweep = "single_sweeps"


@dataclass
class WindingData:
flux: complex
turns: int
self_inductance: complex
#magnetic_field_energy: complex # Was removed as the magnetic_field_energy is no more part of the result_log
voltage: complex
current: complex
active_power: float
reactive_power: float
apparent_power: float


@dataclass
class SweepData:
frequency: int # should be float?
frequency: float
core_eddy_losses: float
core_hyst_losses: float
winding_losses: float
windings: List[WindingData]


@dataclass
class FileData:
file_path: str
Expand All @@ -39,6 +42,7 @@ class FileData:
core_2daxi_total_volume: float
total_cost: float


class FEMMTLogParser:
"""Class to parse the electromagnetic_results_log file created by FEMMT.
Creates a class structure from the file in order to easy access the data and create plots.
Expand All @@ -61,7 +65,9 @@ def __init__(self, file_paths_dict: Dict):
self.data[name] = self.parse_file(file_path, SweepTypes.SingleSweep)

def plot_frequency_sweep_losses(self, data_names: List[str], loss_parameter: str, plot_label: str = "") -> None:
"""Example function for a possible sweep plot. Sweeps over the frequency of different simulations from one or multiple files.
"""
Example function for a possible sweep plot. Sweeps over the frequency of different simulations from
one or multiple files.
:param data_names: Name of the data (keys of data dict). If the list is empty every key will be taken.
:param loss_parameter: Name of the variable from SweepData as str which will be set on the y-axis.
Expand All @@ -88,8 +94,11 @@ def plot_frequency_sweep_losses(self, data_names: List[str], loss_parameter: str
plt.ylabel(loss_parameter)
plt.show()

def plot_frequency_sweep_winding_params(self, data_names: str, winding_number: int, winding_parameter: str, plot_label: str = "") -> None:
"""Example function for a possible sweep plot. Sweeps over the frequency of different simulations from one or multiple files.
def plot_frequency_sweep_winding_params(self, data_names: str, winding_number: int, winding_parameter: str,
plot_label: str = "") -> None:
"""
Example function for a possible sweep plot. Sweeps over the frequency of different simulations from
one or multiple files.
:param data_names: Name of the data (keys of data dict). If the list is empty every key will be taken.
:type data_names: str
Expand All @@ -99,9 +108,6 @@ def plot_frequency_sweep_winding_params(self, data_names: str, winding_number: i
:type plot_label: str
:param winding_parameter:
:type winding_parameter: str
:return: None
:rtype: None
"""
if len(data_names) == 0:
data_names = self.data.keys()
Expand Down Expand Up @@ -133,8 +139,10 @@ def plot_frequency_sweep_winding_params(self, data_names: str, winding_number: i

@staticmethod
def get_log_files_from_working_directories(working_directories: List[str]) -> Dict:
""" Returns a dict containing the log files for each given working directory together with the name of the directory as key.
For every working directory the local path to the log file is working_directory/results/log_electro_magnetic.json
"""
Returns a dict containing the log files for each given working directory together with the name of the
directory as key. For every working directory the local path to the log file
is working_directory/results/log_electro_magnetic.json
:param working_directories: Working directories.
:return: Dictionary with the name of the directory as key and the log.json as value.
Expand Down Expand Up @@ -191,7 +199,6 @@ def parse_file(file_path: str, sweep_type: SweepTypes) -> FileData:
"flux": FEMMTLogParser.parse_complex(current_winding["flux"]),
"turns": current_winding["number_turns"],
"self_inductance": FEMMTLogParser.parse_complex(current_winding["self_inductance"]),
# "magnetic_field_energy": FEMMTLogParser.parse_complex(current_winding["mag_field_energy"]), # Was removed as the magnetic_field_energy is no more part of the result_log
"voltage": FEMMTLogParser.parse_complex(current_winding["V"]),
"current": FEMMTLogParser.parse_complex(current_winding["I"]),
"active_power": current_winding["P"],
Expand Down Expand Up @@ -227,4 +234,3 @@ def parse_file(file_path: str, sweep_type: SweepTypes) -> FileData:
}

return FileData(**total)

0 comments on commit f16eeb9

Please sign in to comment.