@@ -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
0 commit comments