Fix RMS explosion near strong sources - #431
Conversation
| if cnt > 198: # use MAD | ||
| sub_arr = arr[a:b, c:d] | ||
| cm = np.nanmedian(sub_arr) | ||
| cr = np.nanmedian(np.abs(sub_arr - cm)) * 1.4826 |
There was a problem hiding this comment.
Would it be an idea to factor this out into a separate function. This code snippet now appears three times in this function (lines 1027-1030, 1035-1039, and 1044-1048); the latter with an explanation of what MAD actually is.
There was a problem hiding this comment.
Please note that in the first case sub_arr = arr[a:b, c:d], and in two other cases MAD is computed on arr[a:b, c:d][pix_unmasked], so the input is different. But I have used scipy instead on manual calculation.
|
After a fresh look: I think it is better, but still can explode. Maybe instead of median we could risk a rank operator set for some lower quartile here. Or something similar. (Median is a special case of a rank operator targetting at the middle of the set). |
When
bstatfails to converge withincnt > 198, the algorithm fell back to the unclipped mean and std (cm = m; cr = r). In regions containing bright sources, the unclipped std is inflated by source brightness, resulting in local RMS "explosions".