Created
November 16, 2012 10:43
-
-
Save nhmc/4086332 to your computer and use it in GitHub Desktop.
Calculate the background and RMS of an astronomical image
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
def calc_bg(a): | |
""" Estimate the background level and rms. """ | |
good = ~np.isnan(a) | |
assert good.sum(), 'no good pixels!' | |
# poor man's source detection... | |
vmax = np.percentile(a[good], 80) | |
c0 = a[good] < vmax | |
temp = a[good][c0] | |
bg = np.median(temp) | |
# now find the rms in the background | |
belowbg = temp[temp < bg] | |
# remove lowest 2% to get rid of any outliers | |
flo = np.percentile(belowbg, 2) | |
belowbg = belowbg[belowbg > flo] | |
rms = np.concatenate([belowbg, 2*bg - belowbg]).std() | |
return bg, rms |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks, I wasn't able to find this for a long time.