Skip to content

Fix RMS explosion near strong sources - #431

Merged
gmloose merged 3 commits into
lofar-astron:masterfrom
AlexKurek:Fix-RMS-explosion-near-strong-sources
Sep 8, 2026
Merged

Fix RMS explosion near strong sources#431
gmloose merged 3 commits into
lofar-astron:masterfrom
AlexKurek:Fix-RMS-explosion-near-strong-sources

Conversation

@AlexKurek

Copy link
Copy Markdown
Contributor

When bstat fails to converge within cnt > 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".

Comment thread bdsf/rmsimage.py Outdated
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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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.

@gmloose gmloose left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Nice!

@gmloose
gmloose merged commit 111339b into lofar-astron:master Sep 8, 2026
1 check passed
@AlexKurek
AlexKurek deleted the Fix-RMS-explosion-near-strong-sources branch September 8, 2026 12:40
@AlexKurek

AlexKurek commented Sep 9, 2026

Copy link
Copy Markdown
Contributor Author

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).

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