@@ -75,27 +75,36 @@ def __call__(self, b_field, frequency, temperature):
75
75
The frequency operation point(s) in Hz
76
76
temperature: scalar or 1D array-like
77
77
The temperature operation point(s) in °C
78
-
78
+
79
79
Return
80
80
------
81
81
p, h: (X,) np.array, (X, Y) np.ndarray
82
82
The estimated power loss (p) in W/m³ and the estimated magnetic field strength (h) in A/m.
83
83
"""
84
84
if b_field .ndim == 1 :
85
85
b_field = b_field .reshape (1 , - 1 )
86
+ original_seq_len = b_field .shape [- 1 ]
86
87
88
+ L = self .mdl .expected_seq_len
87
89
if b_field .shape [- 1 ] != L :
88
90
actual_len = b_field .shape [- 1 ]
89
91
query_points = np .arange (L )
90
92
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
+ )
92
97
93
98
p , h_seq = self .mdl (b_field , frequency , temperature )
94
99
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 ])])
101
110
return p , h_seq
0 commit comments