Skip to content

Commit 0b3c1c0

Browse files
committed
change API to accept variable-sized input sequences and return H of the same sequence length
1 parent 690c9e4 commit 0b3c1c0

File tree

6 files changed

+270
-186
lines changed

6 files changed

+270
-186
lines changed

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "mag-net-hub"
3-
version = "0.0.8"
3+
version = "0.0.9"
44
authors = [
55
{ name = "Wilhelm Kirchgässner" },
66
]

src_py/magnethub/loss.py

+17-8
Original file line numberDiff line numberDiff line change
@@ -75,27 +75,36 @@ def __call__(self, b_field, frequency, temperature):
7575
The frequency operation point(s) in Hz
7676
temperature: scalar or 1D array-like
7777
The temperature operation point(s) in °C
78-
78+
7979
Return
8080
------
8181
p, h: (X,) np.array, (X, Y) np.ndarray
8282
The estimated power loss (p) in W/m³ and the estimated magnetic field strength (h) in A/m.
8383
"""
8484
if b_field.ndim == 1:
8585
b_field = b_field.reshape(1, -1)
86+
original_seq_len = b_field.shape[-1]
8687

88+
L = self.mdl.expected_seq_len
8789
if b_field.shape[-1] != L:
8890
actual_len = b_field.shape[-1]
8991
query_points = np.arange(L)
9092
support_points = np.arange(actual_len) * L / actual_len
91-
b_field = np.row_stack([np.interp(query_points, support_points, b_field[i]) for i in range(b_field.shape[0])])
93+
# TODO Does a vectorized form of 1d interpolation exist?
94+
b_field = np.row_stack(
95+
[np.interp(query_points, support_points, b_field[i]) for i in range(b_field.shape[0])]
96+
)
9297

9398
p, h_seq = self.mdl(b_field, frequency, temperature)
9499

95-
# may interpolate to 1024 samples if h_seq too short
96-
if h_seq.shape[-1] != L:
97-
actual_len = h_seq.shape[-1]
98-
query_points = np.arange(L)
99-
support_points = np.arange(actual_len) * L / actual_len
100-
h_seq = np.row_stack([np.interp(query_points, support_points, h_seq[i]) for i in range(h_seq.shape[0])])
100+
if h_seq is not None:
101+
assert (
102+
h_seq.ndim == 2
103+
), f"H sequence has ndim={h_seq.ndim}, but 2 were expected with (#periods, #samples-per-period)"
104+
# may interpolate to original sample size if h_seq too short or too long
105+
if h_seq.shape[-1] != original_seq_len:
106+
actual_len = h_seq.shape[-1]
107+
query_points = np.arange(original_seq_len)
108+
support_points = np.arange(actual_len) * original_seq_len / actual_len
109+
h_seq = np.row_stack([np.interp(query_points, support_points, h_seq[i]) for i in range(h_seq.shape[0])])
101110
return p, h_seq

src_py/magnethub/paderborn.py

+2
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,8 @@ class PaderbornModel:
479479
arXiv preprint arXiv:2401.11488
480480
481481
"""
482+
483+
expected_seq_len = 1024 # the expected sequence length
482484

483485
def __init__(self, model_path, material):
484486
self.model_path = model_path

0 commit comments

Comments
 (0)