Skip to content

Commit ae8ca93

Browse files
Update T2P chi-sq definition for ML fitting (#1604)
* other definition of stdQ for T2P chi2 * change stdQ definition
1 parent 619e8f7 commit ae8ca93

1 file changed

Lines changed: 12 additions & 7 deletions

File tree

sotodlib/tod_ops/t2pleakage.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,7 @@ def get_t2p_coeffs_in_freq(aman, T_sig_name='dsT', Q_sig_name='demodQ', U_sig_na
357357
U_fs = rfft(aman[U_sig_name], axis=1)
358358

359359
fit_mask = (fit_freq_range[0] < freqs) & (freqs < fit_freq_range[1])
360+
wn_mask = (wn_freq_range[0] < freqs) & (freqs < wn_freq_range[1])
360361

361362
if ML_fit:
362363
x = np.real(I_fs[:, fit_mask])
@@ -365,14 +366,21 @@ def get_t2p_coeffs_in_freq(aman, T_sig_name='dsT', Q_sig_name='demodQ', U_sig_na
365366
coeffsQ = np.sum(x * yQ, axis=1) / np.sum(x**2, axis=1)
366367
coeffsU = np.sum(x * yU, axis=1) / np.sum(x**2, axis=1)
367368

368-
stdQ = np.sqrt(np.sum((yQ - coeffsQ[:, np.newaxis] * x)**2, axis=1) / (x.shape[1] - 1))
369-
stdU = np.sqrt(np.sum((yU - coeffsU[:, np.newaxis] * x)**2, axis=1) / (x.shape[1] - 1))
369+
stdQ = np.std(Q_fs[:, wn_mask] - coeffsQ[:, np.newaxis] * I_fs[:, wn_mask], axis=1)
370+
stdU = np.std(U_fs[:, wn_mask] - coeffsU[:, np.newaxis] * I_fs[:, wn_mask], axis=1)
370371

371372
errorsQ = stdQ / np.sqrt(np.sum(x**2, axis=1))
372373
errorsU = stdU / np.sqrt(np.sum(x**2, axis=1))
373374

374-
redchi2sQ = np.sum((yQ - coeffsQ[:, np.newaxis] * x) ** 2 / stdQ[:, np.newaxis] ** 2, axis=1) / (x.shape[1] - 1)
375-
redchi2sU = np.sum((yU - coeffsU[:, np.newaxis] * x) ** 2 / stdU[:, np.newaxis] ** 2, axis=1) / (x.shape[1] - 1)
375+
redchi2sQ = np.sum(
376+
(yQ - coeffsQ[:, np.newaxis] * x) ** 2 / stdQ[:, np.newaxis] ** 2,
377+
axis=1
378+
) / (x.shape[1] - 1)
379+
redchi2sU = np.sum(
380+
(yU - coeffsU[:, np.newaxis] * x) ** 2 / stdU[:, np.newaxis] ** 2,
381+
axis=1
382+
) / (x.shape[1] - 1)
383+
376384
else:
377385
coeffsQ = np.zeros(aman.dets.count)
378386
errorsQ = np.zeros(aman.dets.count)
@@ -381,9 +389,6 @@ def get_t2p_coeffs_in_freq(aman, T_sig_name='dsT', Q_sig_name='demodQ', U_sig_na
381389
errorsU = np.zeros(aman.dets.count)
382390
redchi2sU = np.zeros(aman.dets.count)
383391

384-
385-
wn_mask = (wn_freq_range[0] < freqs) & (freqs < wn_freq_range[1])
386-
387392
def leakage_model(B, x):
388393
return B[0] * x
389394

0 commit comments

Comments
 (0)