Skip to content

Commit 850ac22

Browse files
Merge pull request #22 from upb-lea/simplified_pro_file_writing
Simplified pro file writing
2 parents 0db0380 + 0480847 commit 850ac22

1 file changed

Lines changed: 75 additions & 86 deletions

File tree

materialdatabase/material_data_base_classes.py

Lines changed: 75 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,82 @@ def material_data_interpolation_to_dto(self, material_name: str, fundamental_fre
8989
return MaterialCurve(material_name, material_mu_r_initial, material_flux_density_vec, material_mu_r_imag_vec, material_mu_r_real_vec,
9090
saturation_flux_density, boundary_frequency=fundamental_frequency, boundary_temperature=temperature)
9191

92+
def get_permeability_data(self, temperature: float, frequency: float, material_name: str, datatype: str, datasource: str = None,
93+
measurement_setup: str = None, plot_interpolation: bool = False):
94+
"""
95+
Read permeability data from the material database.
96+
97+
:param temperature: temperature in °C
98+
:type temperature: float
99+
:param frequency: Frequency in Hz
100+
:type frequency: float
101+
:param material_name: "N95","N87"....
102+
:type material_name: str
103+
:param datatype: "complex_permeability", "complex_permittivity" or "Steinmetz"
104+
:type datatype: str
105+
:param datasource: "measurements" or "manufacturer_datasheet"
106+
:type datasource: str
107+
:param measurement_setup: name of measuerement setup
108+
:type measurement_setup: str
109+
:param plot_interpolation: enables interpolation for plots
110+
:type plot_interpolation: bool
111+
:return:
112+
"""
113+
self.mdb_print(f"{material_name=}\n")
114+
self.mdb_print(f"{datatype=}\n")
115+
self.mdb_print(f"{measurement_setup=}\n")
116+
117+
if datasource == MaterialDataSource.ManufacturerDatasheet:
118+
permeability_data = self.data[f"{material_name.value}"][f"{datasource.value}"]["permeability_data"]
119+
elif datasource == MaterialDataSource.Measurement:
120+
permeability_data = self.data[f"{material_name.value}"]["measurements"][f"{datatype.value}"][f"{measurement_setup.value}"]["measurement_data"]
121+
# mdb_print(f"{permeability_data = }")
122+
# mdb_print(f"{len(permeability_data[1]['b']), len(permeability_data[0]['mu_r']) = }")
123+
124+
# create_permeability_neighbourhood
125+
nbh = create_permeability_neighbourhood_measurement(temperature, frequency, permeability_data)
126+
# mdb_print(f"{nbh = }")
127+
# mdb_print(f"{len(nbh['T_low_f_low']['b']), len(nbh['T_low_f_low']['mu_r']) = }")
128+
129+
b_ref, mu_r = interpolate_b_dependent_quantity_in_temperature_and_frequency(temperature, frequency,
130+
nbh["T_low_f_low"]["temperature"], nbh["T_high_f_low"]["temperature"],
131+
nbh["T_low_f_low"]["frequency"], nbh["T_low_f_high"]["frequency"],
132+
nbh["T_low_f_low"]["flux_density"], nbh["T_low_f_low"]["mu_r_abs"],
133+
nbh["T_high_f_low"]["flux_density"], nbh["T_high_f_low"]["mu_r_abs"],
134+
nbh["T_low_f_high"]["flux_density"], nbh["T_low_f_high"]["mu_r_abs"],
135+
nbh["T_high_f_high"]["flux_density"], nbh["T_high_f_high"]["mu_r_abs"],
136+
y_label="rel. amplitude permeability", plot=plot_interpolation)
137+
138+
b_ref, mu_phi_deg = interpolate_b_dependent_quantity_in_temperature_and_frequency(temperature, frequency,
139+
nbh["T_low_f_low"]["temperature"],
140+
nbh["T_high_f_low"]["temperature"],
141+
nbh["T_low_f_low"]["frequency"],
142+
nbh["T_low_f_high"]["frequency"],
143+
nbh["T_low_f_low"]["flux_density"],
144+
nbh["T_low_f_low"]["mu_phi_deg"],
145+
nbh["T_high_f_low"]["flux_density"],
146+
nbh["T_high_f_low"]["mu_phi_deg"],
147+
nbh["T_low_f_high"]["flux_density"],
148+
nbh["T_low_f_high"]["mu_phi_deg"],
149+
nbh["T_high_f_high"]["flux_density"],
150+
nbh["T_high_f_high"]["mu_phi_deg"],
151+
y_label="hyst. loss angle in deg", plot=plot_interpolation)
152+
153+
# Convert to cartesian
154+
mu_real_from_polar, mu_imag_from_polar = [], []
155+
for n in range(len(b_ref)):
156+
cartesian = rect(mu_r[n], mu_phi_deg[n])
157+
mu_real_from_polar.append(cartesian[0])
158+
mu_imag_from_polar.append(cartesian[1])
159+
mu_r_real = mu_real_from_polar
160+
mu_r_imag = mu_imag_from_polar
161+
162+
return b_ref, mu_r_real, mu_r_imag
163+
92164
def permeability_data_to_pro_file(self, temperature: float, frequency: float, material_name: str, datatype: str, datasource: str = None,
93165
measurement_setup: str = None, parent_directory: str = "", plot_interpolation: bool = False):
94166
"""
95-
Read permeability data from the material database.
167+
Write permeability data from the material database in apro file.
96168
97169
:param temperature: temperature in °C
98170
:type temperature: float
@@ -123,91 +195,8 @@ def permeability_data_to_pro_file(self, temperature: float, frequency: float, ma
123195

124196
check_input_permeability_data(datasource, material_name, temperature, frequency)
125197

126-
if datasource == MaterialDataSource.Measurement or datasource == MaterialDataSource.ManufacturerDatasheet:
127-
self.mdb_print(f"{material_name=}\n")
128-
self.mdb_print(f"{datatype=}\n")
129-
self.mdb_print(f"{measurement_setup=}\n")
130-
131-
if datasource == MaterialDataSource.ManufacturerDatasheet:
132-
permeability_data = self.data[f"{material_name.value}"][f"{datasource.value}"]["permeability_data"]
133-
elif datasource == MaterialDataSource.Measurement:
134-
permeability_data = self.data[f"{material_name.value}"]["measurements"][f"{datatype.value}"][f"{measurement_setup.value}"]["measurement_data"]
135-
# mdb_print(f"{permeability_data = }")
136-
# mdb_print(f"{len(permeability_data[1]['b']), len(permeability_data[0]['mu_r']) = }")
137-
138-
# create_permeability_neighbourhood
139-
nbh = create_permeability_neighbourhood_measurement(temperature, frequency, permeability_data)
140-
# mdb_print(f"{nbh = }")
141-
# mdb_print(f"{len(nbh['T_low_f_low']['b']), len(nbh['T_low_f_low']['mu_r']) = }")
142-
143-
b_ref, mu_r = interpolate_b_dependent_quantity_in_temperature_and_frequency(temperature, frequency,
144-
nbh["T_low_f_low"]["temperature"], nbh["T_high_f_low"]["temperature"],
145-
nbh["T_low_f_low"]["frequency"], nbh["T_low_f_high"]["frequency"],
146-
nbh["T_low_f_low"]["flux_density"], nbh["T_low_f_low"]["mu_r_abs"],
147-
nbh["T_high_f_low"]["flux_density"], nbh["T_high_f_low"]["mu_r_abs"],
148-
nbh["T_low_f_high"]["flux_density"], nbh["T_low_f_high"]["mu_r_abs"],
149-
nbh["T_high_f_high"]["flux_density"], nbh["T_high_f_high"]["mu_r_abs"],
150-
y_label="rel. amplitude permeability", plot=plot_interpolation)
151-
152-
b_ref, mu_phi_deg = interpolate_b_dependent_quantity_in_temperature_and_frequency(temperature, frequency,
153-
nbh["T_low_f_low"]["temperature"],
154-
nbh["T_high_f_low"]["temperature"],
155-
nbh["T_low_f_low"]["frequency"],
156-
nbh["T_low_f_high"]["frequency"],
157-
nbh["T_low_f_low"]["flux_density"],
158-
nbh["T_low_f_low"]["mu_phi_deg"],
159-
nbh["T_high_f_low"]["flux_density"],
160-
nbh["T_high_f_low"]["mu_phi_deg"],
161-
nbh["T_low_f_high"]["flux_density"],
162-
nbh["T_low_f_high"]["mu_phi_deg"],
163-
nbh["T_high_f_high"]["flux_density"],
164-
nbh["T_high_f_high"]["mu_phi_deg"],
165-
y_label="hyst. loss angle in deg", plot=plot_interpolation)
166-
167-
# Convert to cartesian
168-
mu_real_from_polar, mu_imag_from_polar = [], []
169-
for n in range(len(b_ref)):
170-
cartesian = rect(mu_r[n], mu_phi_deg[n])
171-
mu_real_from_polar.append(cartesian[0])
172-
mu_imag_from_polar.append(cartesian[1])
173-
mu_r_real = mu_real_from_polar
174-
mu_r_imag = mu_imag_from_polar
175-
176-
# elif datasource == MaterialDataSource.ManufacturerDatasheet:
177-
# permeability_data = self.data[f"{material_name.value}"][f"{datasource.value}"]["permeability_data"]
178-
#
179-
# # create_permeability_neighbourhood
180-
# nbh = create_permeability_neighbourhood_datasheet(temperature, frequency, permeability_data)
181-
#
182-
# b_ref, mu_r_real = interpolate_b_dependent_quantity_in_temperature_and_frequency(temperature, frequency,
183-
# nbh["T_low_f_low"]["temperature"],
184-
# nbh["T_high_f_low"]["temperature"],
185-
# nbh["T_low_f_low"]["frequency"],
186-
# nbh["T_low_f_high"]["frequency"],
187-
# nbh["T_low_f_low"]["flux_density"],
188-
# nbh["T_low_f_low"]["mu_r_real"],
189-
# nbh["T_high_f_low"]["flux_density"],
190-
# nbh["T_high_f_low"]["mu_r_real"],
191-
# nbh["T_low_f_high"]["flux_density"],
192-
# nbh["T_low_f_high"]["mu_r_real"],
193-
# nbh["T_high_f_high"]["flux_density"],
194-
# nbh["T_high_f_high"]["mu_r_real"], plot=plot_interpolation)
195-
#
196-
# b_ref, mu_r_imag = interpolate_b_dependent_quantity_in_temperature_and_frequency(temperature, frequency,
197-
# nbh["T_low_f_low"]["temperature"],
198-
# nbh["T_high_f_low"]["temperature"],
199-
# nbh["T_low_f_low"]["frequency"],
200-
# nbh["T_low_f_high"]["frequency"],
201-
# nbh["T_low_f_low"]["flux_density"],
202-
# nbh["T_low_f_low"]["mu_r_imag"],
203-
# nbh["T_high_f_low"]["flux_density"],
204-
# nbh["T_high_f_low"]["mu_r_imag"],
205-
# nbh["T_low_f_high"]["flux_density"],
206-
# nbh["T_low_f_high"]["mu_r_imag"],
207-
# nbh["T_high_f_high"]["flux_density"],
208-
# nbh["T_high_f_high"]["mu_r_imag"], plot=plot_interpolation)
209-
#
210-
# self.mdb_print(f"{b_ref, mu_r_real, mu_r_imag=}")
198+
b_ref, mu_r_real, mu_r_imag = self.get_permeability_data(temperature, frequency, material_name, datatype, datasource,
199+
measurement_setup, plot_interpolation)
211200

212201
# Write the .pro-file
213202
export_data(parent_directory=parent_directory, file_format="pro", b_ref_vec=list(b_ref), mu_r_real_vec=list(mu_r_real), mu_r_imag_vec=list(mu_r_imag),

0 commit comments

Comments
 (0)