| 1267 | # effects in general convolution. |
| 1268 | |
| 1269 | def convolve(background, s): |
| 1270 | # Modifies the contents of the 'background' array. |
| 1271 | # This implementation of convolution replaces the original |
| 1272 | # implementation based on 'np.convolve'. Seems to work as fast |
| 1273 | # as the original implementation. |
| 1274 | s_len = len(s) |
| 1275 | n_beg = (s_len - 1) // 2 |
| 1276 | A = s.sum() |
| 1277 | source = np.hstack( |
| 1278 | ( |
| 1279 | np.zeros(n_beg, dtype=background.dtype), |
| 1280 | background, |
| 1281 | np.zeros(s_len - n_beg, dtype=background.dtype), |
| 1282 | ) |
| 1283 | ) |
| 1284 | for n in range(len(background)): |
| 1285 | background[n] = np.sum(source[n : n + s_len] * s) / A |
| 1286 | |
| 1287 | convolve(background, s) |
| 1288 | |