Skip to content

Conversation

17-sugiyama
Copy link
Contributor

This PR adds a function to t2pleakage.py.
The new function restrict_dets_from_t2p_fit restricts detectors based on the t2p fit stats.
It has three options of t2p fit parameters: redchi2, error, and lam.

Here I show the example TOD of one detector with bad t2p fit. (obs_1712141864_satp1_1111111)
Sometimes residual noise in demodQ/U is quite large due to bad t2p correlation.
image

This figure shows the histograms of redchi2s in observations with good and bad t2p correlation.
This implies that we can cut the detectors of large t2p residuals based on redchi2s or other fit parameters.
image

Assuming the valid chi2 value is 0.1<chi2<3.0, I have cut the detectors in 262 observations.
The number of detectors is reduced from about 3300 to 2700; about 600 (18%) detectors are discarded.

Copy link
Contributor

@msilvafe msilvafe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few changes requested which should make it compatible with a preprocess workflow and format it more like the rest of the repo.

The lower and upper limit of acceptable leakage coefficient.
"""
if t2p_aman is None:
t2p_aman = aman.t2p_stats
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not guaranteed to exist. I think you should wrap this in a try-except and raise a useful error.

Comment on lines +348 to +359
redchi2s : bool
If True, restrict detectors based on redchi2s values.
error : bool
If True, restrict detectors based on fit errors of lamQ and lamU.
lam : bool
If True, restrict detectors based on the amplitude of lamQ and lamU.
redchi2s_lims : tuple
The lower and upper limit of acceptable redchi2s.
error_lims : tuple
The lower and upper limit of acceptable errors.
lam_lims : tuple
The lower and upper limit of acceptable leakage coefficient.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where are redchi2, error, and lam defined? Refer to appropriate docstring or define here.

Also I think you should just make these be 3 variables and have them default to None and otherwise pass a tuple for the values. In the if redchi2s: line for instance if redchi2s is not it will pass this block, if it's a tuple it will be True and behave as intended.

else:
raise ValueError('no leakage coefficients found in axis manager')

def restrict_dets_from_t2p_fit(aman, t2p_aman=None, redchi2s=True, error=True, lam=False,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename to get_t2p_cuts

lam_t2p = np.sqrt(t2p_aman.lamQ**2 + t2p_aman.lamU**2)
mask_lam = (lam_lims[0] < lam_t2p) & (lam_t2p < lam_lims[1])
mask = np.logical_and(mask, mask_lam)
aman.restrict('dets', aman.dets.vals[mask])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should only restrict in-place optionally. Add an argument in_place which if true restricts as is done here and if false does not and returns mask.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants