Skip to content

Commit

Permalink
Merge pull request #7 from upb-lea/develop
Browse files Browse the repository at this point in the history
pycodestyle and ruff lint tests
  • Loading branch information
gituser789 authored Dec 12, 2023
2 parents 0863ab8 + 1714675 commit 84ba506
Show file tree
Hide file tree
Showing 18 changed files with 210 additions and 167 deletions.
9 changes: 9 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,15 @@ jobs:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2

- name: check linting using pycodestyle
run: |
pip install pycodestyle
pip install pytest
pycodestyle $(git ls-files '*.py')
pip install ruff
ruff check $(git ls-files '*.py')
- name: install materialdatabase package
run: |
pip install -e .
Expand Down
2 changes: 1 addition & 1 deletion materialdatabase/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
from materialdatabase.material_data_base_classes import *
from materialdatabase.enumerations import *
from materialdatabase.constants import *
from materialdatabase.dtos import *
from materialdatabase.dtos import *
3 changes: 1 addition & 2 deletions materialdatabase/dtos.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import numpy as np



@dataclass
class MaterialCurve:
"""
Expand All @@ -18,4 +17,4 @@ class MaterialCurve:
material_mu_r_real_vec: np.ndarray
saturation_flux_density: float
boundary_temperature: float
boundary_frequency: float
boundary_frequency: float
6 changes: 2 additions & 4 deletions materialdatabase/enumerations.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,9 @@ class Company(str, Enum):
UPB = "Paderborn University"



class Manufacturer(str, Enum):
"""Sets the source from where data is taken.
"""
"""Sets the source from where data is taken."""

TDK = "TDK"
Ferroxcube = "Ferroxcube"
DMEGC = "DMEGC"
Expand Down Expand Up @@ -102,4 +101,3 @@ class CuboidDirectoryName(str, Enum):
(a and b can be exchanged, because A = a*b)
"""
DMR96A_2 = "C_25.0x2.0x15.0"

Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,3 @@

b_ref, mu_r, mu_phi_deg = process_permeability_data(b_ref, mu_r, mu_phi_deg,
smooth_data=True, crop_data=False, plot_data=True)

44 changes: 22 additions & 22 deletions materialdatabase/material_data_base_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,9 @@ def permeability_data_to_pro_file(self, temperature: float, frequency: float, ma
:Example:
>>> import materialdatabase as mdb
>>> material_db = mdb.MaterialDatabase()
>>> b_ref, mu_r_real, mu_r_imag = material_db.permeability_data_to_pro_file(temperature=25, frequency=150000, material_name = "N95", datatype = "complex_permeability",
datasource = mdb.MaterialDataSource.ManufacturerDatasheet, parent_directory = "")
>>> b_ref, mu_r_real, mu_r_imag = material_db.permeability_data_to_pro_file(temperature=25, frequency=150000,
>>> material_name = "N95", datatype = "complex_permeability",
>>> datasource = mdb.MaterialDataSource.ManufacturerDatasheet, parent_directory = "")
"""

check_input_permeability_data(datasource, material_name, temperature, frequency)
Expand All @@ -111,7 +112,7 @@ def permeability_data_to_pro_file(self, temperature: float, frequency: float, ma
self.mdb_print(f"{material_name = }\n")
self.mdb_print(f"{datatype = }\n")
self.mdb_print(f"{measurement_setup = }\n")
permeability_data = self.data[f"{material_name.value}"][f"measurements"][f"{datatype.value}"][f"{measurement_setup.value}"][
permeability_data = self.data[f"{material_name.value}"]["measurements"][f"{datatype.value}"][f"{measurement_setup.value}"][
"measurement_data"]
# mdb_print(f"{permeability_data = }")
# mdb_print(f"{len(permeability_data[1]['b']), len(permeability_data[0]['mu_r']) = }")
Expand Down Expand Up @@ -371,7 +372,7 @@ def drop_down_list(self, material_name: str, comparison_type: str, datatype: str
"measurement_data"]
temp_list = []
freq_list = []
for j in range(len(curve_data_material)):
for _ in range(len(curve_data_material)):
for i in range(len(curve_data_material)):
temp_list.append(curve_data_material[i]["temperature"])

Expand Down Expand Up @@ -509,8 +510,7 @@ def compare_core_loss_frequency(self, matplotlib_widget, material_list: list, te
power_loss = []
color = color_list[i]
for m in range(len(curve_data_material)):
if curve_data_material[m]["temperature"] == temperature and curve_data_material[m][
"flux_density"] == flux:
if curve_data_material[m]["temperature"] == temperature and curve_data_material[m]["flux_density"] == flux:
frequency.append(curve_data_material[m]["frequency"])
power_loss.append(curve_data_material[m]["power_loss"])

Expand Down Expand Up @@ -588,22 +588,20 @@ def compare_permeability_measurement_data(self, matplotlib_widget, material_list
# axs[1].grid()
for i in range(len(material_list)):
curve_data_material = \
self.data[f"{material_list[i]}"]["measurements"]["complex_permeability"][measurement_name[i]][
"measurement_data"]
self.data[f"{material_list[i]}"]["measurements"]["complex_permeability"][measurement_name[i]]["measurement_data"]
material = material_list[i]
temperature = temperature_list[i]
frequency = frequency_list[i]
color = color_list[i]

for j in range(len(curve_data_material)):
for _ in range(len(curve_data_material)):
b = []
freq = []
mu_phi = []
mu_r = []

for k in range(len(curve_data_material)):
if curve_data_material[k]["frequency"] == frequency and curve_data_material[k][
"temperature"] == temperature:
if curve_data_material[k]["frequency"] == frequency and curve_data_material[k]["temperature"] == temperature:
b.append(curve_data_material[k]["flux_density"])
freq.append(curve_data_material[k]["frequency"])
mu_phi.append(curve_data_material[k]["mu_phi_deg"])
Expand Down Expand Up @@ -676,7 +674,7 @@ def compare_core_loss_flux_datasheet_measurement(self, matplotlib_widget, materi
frequency_d.append(curve_data_material_datasheet[j]["frequency"])
power_loss_d.append(curve_data_material_datasheet[j]["power_loss"])
for j in range(len(b_d)):
label = f"{material}", f"F={frequency_d[j]}Hz", f"T={temperature_datasheet}°C", f"Datasheet"
label = f"{material}", f"F={frequency_d[j]}Hz", f"T={temperature_datasheet}°C", "Datasheet"
lines = matplotlib_widget.axis.plot(b_d[j], power_loss_d[j], label=label, color=color_list[0],
linestyle=line_style[0])
mplcursors.cursor(lines)
Expand All @@ -693,7 +691,7 @@ def compare_core_loss_flux_datasheet_measurement(self, matplotlib_widget, materi
list_item["mu_r_abs"],
list_item["mu_phi_deg"]))
for j in range(len(b_m)):
label = f"{material}", f"F={frequency_m[j]}Hz", f"T={temperature_measurement}°C", f"Measurements"
label = f"{material}", f"F={frequency_m[j]}Hz", f"T={temperature_measurement}°C", "Measurements"
lines = matplotlib_widget.axis.plot(b_m[j], power_loss_m[j], label=label, color=color_list[1],
linestyle=line_style[1])
mplcursors.cursor(lines)
Expand Down Expand Up @@ -729,9 +727,8 @@ def load_permittivity_measurement(self, material_name: str, datasource: str = "m

try:
return self.data[material_name][datasource][datatype][measurement_setup]["measurement_data"]
except:
raise ValueError("Requested measurement data not available.")

except Exception as err:
raise ValueError("Requested measurement data not available.") from err

def get_permittivity(self, temperature: float, frequency: float, material_name: str,
datasource: str = "measurements",
Expand Down Expand Up @@ -760,7 +757,7 @@ def get_permittivity(self, temperature: float, frequency: float, material_name:
>>> import materialdatabase as mdb
>>> material_db = mdb.MaterialDatabase()
>>> epsilon_r, epsilon_phi_deg = material_db.get_permittivity(temperature= 25, frequency=150000, material_name = "N95", datasource = "measurements",
>>> datatype = mdb.MeasurementDataType.ComplexPermittivity, measurement_setup = "LEA_LK",interpolation_type = "linear")
>>> datatype = mdb.MeasurementDataType.ComplexPermittivity, measurement_setup = "LEA_LK",interpolation_type = "linear")
"""
# Load the chosen permittivity data from the database
Expand All @@ -781,8 +778,8 @@ def get_permittivity(self, temperature: float, frequency: float, material_name:
return epsilon_r, epsilon_phi_deg

def get_steinmetz(self, temperature: float, material_name: str, datasource: str = "measurements",
datatype: MeasurementDataType = MeasurementDataType.Steinmetz, measurement_setup: str = None,
interpolation_type: str = "linear"):
datatype: MeasurementDataType = MeasurementDataType.Steinmetz, measurement_setup: str = None,
interpolation_type: str = "linear"):
"""
Returns the complex permittivity for a certain operation point defined by temperature and frequency.
:param temperature:
Expand Down Expand Up @@ -813,9 +810,12 @@ def get_steinmetz(self, temperature: float, material_name: str, datasource: str
t_index_low = neighbourhood["T_low"]["temperature"]["index"]
t_high = neighbourhood["T_high"]["temperature"]["value"]
t_index_high = neighbourhood["T_high"]["temperature"]["index"]
alpha = my_polate_linear(a=t_low, b=t_high, f_a=list_of_steinmetz_dicts[t_index_low]["alpha"], f_b=list_of_steinmetz_dicts[t_index_high]["alpha"], x=temperature)
beta = my_polate_linear(a=t_low, b=t_high, f_a=list_of_steinmetz_dicts[t_index_low]["beta"], f_b=list_of_steinmetz_dicts[t_index_high]["beta"], x=temperature)
k = my_polate_linear(a=t_low, b=t_high, f_a=list_of_steinmetz_dicts[t_index_low]["k"], f_b=list_of_steinmetz_dicts[t_index_high]["k"], x=temperature)
alpha = my_polate_linear(a=t_low, b=t_high, f_a=list_of_steinmetz_dicts[t_index_low]["alpha"],
f_b=list_of_steinmetz_dicts[t_index_high]["alpha"], x=temperature)
beta = my_polate_linear(a=t_low, b=t_high, f_a=list_of_steinmetz_dicts[t_index_low]["beta"],
f_b=list_of_steinmetz_dicts[t_index_high]["beta"], x=temperature)
k = my_polate_linear(a=t_low, b=t_high, f_a=list_of_steinmetz_dicts[t_index_low]["k"],
f_b=list_of_steinmetz_dicts[t_index_high]["k"], x=temperature)
else:
raise NotImplementedError

Expand Down
Loading

0 comments on commit 84ba506

Please sign in to comment.