def cal_image(filepath,plot = True,path=None,band='gp',source='BD710031',bias=None,dark=None,flat=None): if not path: path = set_path() if length(bias) == 1: bias = make_bias(path=path) if length(dark) == 1: dark = make_dark(path=path) if length(flat) == 1: flat = make_flat(path=path,band=band,bias=bias,dark=dark) image0, header0 = qi.readimage(filepath) refh = h.pyfits.getheader(filepath) im = h.pyfits.open(filepath) newim = h.hcongrid((im[0].data-dark-bias)/flat, im[0].header,refh) if plot: qi.display_image(newim) return newim,header0
def stack_ims(path=None,band='gp',source='NGC188',bias=None,dark=None,flat=None): if not path: path = set_path() if length(bias) == 1: bias = make_bias(path=path) if length(dark) == 1: dark = make_dark(path=path) if length(flat) == 1: flat = make_flat(path=path,band=band,bias=bias,dark=dark) files,sz = tp.get_files(dir=path, tag=source+'.'+band) # Designate reference file reffile = files[sz/2] image0, header0 = qi.readimage(reffile) ysz, xsz = np.shape(image0) refim = h.pyfits.open(reffile) refh = h.pyfits.getheader(reffile) stack = np.zeros((xsz,ysz,sz)) for i in range(sz): im = h.pyfits.open(files[i]) newim = h.hcongrid((im[0].data-dark-bias)/flat, im[0].header,refh) stack[:,:,i] = newim final = np.median(stack, axis=2) return final,refh
def get_fiber_flux(file,fwhm=20,threshold=100): image,header = qi.readimage(file,plot=False) mean, median, std = sigma_clipped_stats(image, sigma=3.0) source = daofind(image - median, fwhm=fwhm, threshold=threshold*std) xcen = np.int(np.round(source['xcentroid'][0])) ycen = np.int(np.round(source['ycentroid'][0])) plt.plot([xcen],[ycen],'rx',markersize=20) params = fitgaussian(image) y,x = params[1],params[2] apdict = tp.optimal_aperture(x,y,image,[150,160]) return apdict
# 3) Post cable repair, determine if repair improves fluxcable:fluxbase # KO/JS 6/14/16: Drew from fiberphot.py and thacherphot.py, modified for purpose import thacherphot as tp import numpy as np import matplotlib.pyplot as plt from length import length import quick_image as qi import glob from fitgaussian import * from astropy.stats import sigma_clipped_stats path = '/Users/ONeill/Dropbox/Observatory/Data/minerva/FiberTests/' files = glob.glob(path+"lamp2*fit") image,header = qi.readimage(files[0],plot=True,siglo=2,sighi=2) params = fitgaussian(image) #using params make model: amplitude, x center, y center, x width, y width, angle rotated #using thacherphot to overplot contours of gaussian #for every x y pixel have data value and model value, so subtract from each other and find residuals - should just look like noise fit = gaussian(*params) level = (np.max(image) - np.median(image))*np.array([0.95,0.5,0.1]) plt.figure(1) plt.contour(fit(*indices(image.shape)),level,colors='blue') def find_flux(image): model = fit(*indices(image.shape)) qi.display_image(model)