Skip to content

Instantly share code, notes, and snippets.

@autocorr
Last active August 29, 2015 14:14
Show Gist options
  • Save autocorr/e07fdb47a733aec57b65 to your computer and use it in GitHub Desktop.
Save autocorr/e07fdb47a733aec57b65 to your computer and use it in GitHub Desktop.
Something dark
def make_dark(infilen, targetfilen, outfilen='masterdark'):
# step 1: median stack the darks
darklist = open(infilen,'r')
darklist = darklist.readlines()
n = len(darklist)
fits = pyfits.open(darklist[0])
darkheader = fits[0].header
imdark = fits[0].data
date = darkheader['DATE']
date = date[0:10]
yimsize = np.array(np.shape(imdark))[1]
ximsize = np.array(np.shape(imdark))[2]
darkarray = np.zeros((yimsize,ximsize,n),dtype=np.float32)
print "Creating master dark frame..."
for i in xrange(0,n):
fits = pyfits.open(darklist[i])
im = fits[0].data
if len(im.shape) == 3: #check for data cubes
assert not np.any(np.isnan(im))
im = np.median(im, axis=0) #if data cube, then median frames
darkarray[:,:,i]=im
med_dark = np.median(darkarray,axis=2)
darkname = targetfilen + '_' + date + outfilen + '.fits'
pyfits.writeto(darkname, med_dark, darkheader, clobber=True)
return med_dark
if __name__ == '__main__':
infile = sys.argv[1]
target = sys.argv[6]
make_dark(infile, target)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment