Skip to content

Commit

Permalink
change API to accept variable-sized input sequences and return H of t…
Browse files Browse the repository at this point in the history
…he same sequence length
  • Loading branch information
wkirgsn committed May 24, 2024
1 parent 690c9e4 commit 0b3c1c0
Show file tree
Hide file tree
Showing 6 changed files with 270 additions and 186 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "mag-net-hub"
version = "0.0.8"
version = "0.0.9"
authors = [
{ name = "Wilhelm Kirchgässner" },
]
Expand Down
25 changes: 17 additions & 8 deletions src_py/magnethub/loss.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,27 +75,36 @@ def __call__(self, b_field, frequency, temperature):
The frequency operation point(s) in Hz
temperature: scalar or 1D array-like
The temperature operation point(s) in °C
Return
------
p, h: (X,) np.array, (X, Y) np.ndarray
The estimated power loss (p) in W/m³ and the estimated magnetic field strength (h) in A/m.
"""
if b_field.ndim == 1:
b_field = b_field.reshape(1, -1)
original_seq_len = b_field.shape[-1]

L = self.mdl.expected_seq_len
if b_field.shape[-1] != L:
actual_len = b_field.shape[-1]
query_points = np.arange(L)
support_points = np.arange(actual_len) * L / actual_len
b_field = np.row_stack([np.interp(query_points, support_points, b_field[i]) for i in range(b_field.shape[0])])
# TODO Does a vectorized form of 1d interpolation exist?
b_field = np.row_stack(
[np.interp(query_points, support_points, b_field[i]) for i in range(b_field.shape[0])]
)

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

# may interpolate to 1024 samples if h_seq too short
if h_seq.shape[-1] != L:
actual_len = h_seq.shape[-1]
query_points = np.arange(L)
support_points = np.arange(actual_len) * L / actual_len
h_seq = np.row_stack([np.interp(query_points, support_points, h_seq[i]) for i in range(h_seq.shape[0])])
if h_seq is not None:
assert (
h_seq.ndim == 2
), f"H sequence has ndim={h_seq.ndim}, but 2 were expected with (#periods, #samples-per-period)"
# may interpolate to original sample size if h_seq too short or too long
if h_seq.shape[-1] != original_seq_len:
actual_len = h_seq.shape[-1]
query_points = np.arange(original_seq_len)
support_points = np.arange(actual_len) * original_seq_len / actual_len
h_seq = np.row_stack([np.interp(query_points, support_points, h_seq[i]) for i in range(h_seq.shape[0])])
return p, h_seq
2 changes: 2 additions & 0 deletions src_py/magnethub/paderborn.py
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,8 @@ class PaderbornModel:
arXiv preprint arXiv:2401.11488
"""

expected_seq_len = 1024 # the expected sequence length

def __init__(self, model_path, material):
self.model_path = model_path
Expand Down
Loading

0 comments on commit 0b3c1c0

Please sign in to comment.