def ngc1851_image(): """ Plot an image of NGC 1851 for the paper. """ image_root = '/u/jlu/data/gsaoi/commission/reduce/ngc1851/combo/ngc1851' # Load up the PSF stars file to get the coordinates. stars = atpy.Table(image_root + '_psf_stars_pixel.txt', type='ascii') stars.Xarc = stars.X * scale stars.Yarc = stars.Y * scale scale = 0.00995 # gc = aplpy.FITSFigure(image_file) # gc.show_grayscale() img = pyfits.getdata(image_root + '.fits') img = img_scale.log(img, scale_min=0, scale_max=1e4) #img = img_scale.sqrt(img, scale_min=500, scale_max=5e4) # img = img_scale.linear(img, scale_min=500, scale_max=4e4) xmin = ((0 - cooPix[0]) * scale * -1.0) + cooAsec[0] xmax = ((img.shape[1] - cooPix[0]) * scale * -1.0) + cooAsec[0] ymin = ((0 - cooPix[1]) * scale) + cooAsec[1] ymax = ((img.shape[0] - cooPix[1]) * scale) + cooAsec[1] extent = [xmin, xmax, ymin, ymax] py.clf() py.imshow(img, extent=extent, cmap=py.cm.gray_r)
def mosaic_kp(): """ Make a mosaic of our NIRC2 data on W51, one per filter. """ hepochs = ['09jun26', '09jun26', '09jun26', '09jun26'] kepochs = ['09jun10', '09jun10', '09jun10', '09jun26'] lepochs = ['09jun26', '09jun26', '09jun26', '09jun26'] cooStarsH = ['f1_psf0', 'f2_psf0', 'f3_psf0', 'f4_psf0'] cooStarsK = ['f1_psf0', 'f2_psf0', 'f3_psf0', 'f4_psf0'] cooStarsL = ['f1_psf1', 'f2_psf0', 'f3_psf2', 'f4_psf1'] cooStarsH = ['E4-1', 'E8-1', 'N5-1', 'W6-2'] cooStarsK = ['E4-1', 'E8-1', 'N5-1', 'W6-2'] cooStarsL = ['S0-1', 'E8-1', 'W7-1', 'W9-1'] scaleMinH = [0, 0, 0, 0] scaleMinK = [0, 0, 0, 0] scaleMinL = [1000, 1100, 1200, 1250] scaleMaxH = [6000, 6000, 5000, 6000] scaleMaxK = [6500, 6500, 6500, 5500] scaleMaxL = [1600, 1300, 1400, 1600] img = np.zeros((2400, 2400, 3), dtype=float) imgH = np.zeros((2400, 2400), dtype=float) imgK = np.zeros((2400, 2400), dtype=float) imgL = np.zeros((2400, 2400), dtype=float) origin = np.array([1200.0, 1200.0]) labelFile = '/u/jlu/data/w51/source_list/w51a_label.dat' labels = starTables.Labels(labelFile=labelFile) dataRoot = '/u/jlu/data/w51/' py.clf() foo = range(len(hepochs)) for ii in foo[::-1]: # for ii in range(1): rootH = '%s/%s/combo/mag%s_w51a_f%d_h' % \ (dataRoot, hepochs[ii], hepochs[ii], ii+1) rootK = '%s/%s/combo/mag%s_w51a_f%d_kp' % \ (dataRoot, kepochs[ii], kepochs[ii], ii+1) rootL = '%s/%s/combo/mag%s_w51a_f%d_lp' % \ (dataRoot, lepochs[ii], lepochs[ii], ii+1) # Load up the images h, hhdr = pyfits.getdata(rootH + '.fits', header=True) k, khdr = pyfits.getdata(rootK + '.fits', header=True) l, lhdr = pyfits.getdata(rootL + '.fits', header=True) hint = hhdr['ITIME'] * hhdr['COADDS'] kint = khdr['ITIME'] * khdr['COADDS'] lint = lhdr['ITIME'] * lhdr['COADDS'] # Make the arrays into the largest size. h_new = np.zeros((img.shape[0], img.shape[1]), dtype=float) k_new = np.zeros((img.shape[0], img.shape[1]), dtype=float) l_new = np.zeros((img.shape[0], img.shape[1]), dtype=float) h_new[0:h.shape[0], 0:h.shape[1]] = h k_new[0:k.shape[0], 0:k.shape[1]] = k l_new[0:l.shape[0], 0:l.shape[1]] = l # Load up the coo stars tmpH = open(rootH + '.coo').readline().split() cooH = np.array([float(tmpH[0]), float(tmpH[1])]) tmpK = open(rootK + '.coo').readline().split() cooK = np.array([float(tmpK[0]), float(tmpK[1])]) tmpL = open(rootL + '.coo').readline().split() cooL = np.array([float(tmpL[0]), float(tmpL[1])]) # Get the coordinates of each coo star in arcsec. idxH = np.where(labels.name == cooStarsH[ii])[0][0] idxK = np.where(labels.name == cooStarsK[ii])[0][0] idxL = np.where(labels.name == cooStarsL[ii])[0][0] asecH = np.array([labels.x[idxH], labels.y[idxH]]) asecK = np.array([labels.x[idxK], labels.y[idxK]]) asecL = np.array([labels.x[idxL], labels.y[idxL]]) scale = np.array([-0.00995, 0.00995]) # Now figure out the necessary shifts originH = cooH - asecH/scale originK = cooK - asecK/scale originL = cooL - asecL/scale # Shift the J and H images to be lined up with K-band shiftL = origin - originL shiftK = origin - originK shiftH = origin - originH l = interp.shift(l_new, shiftL[::-1]) k = interp.shift(k_new, shiftK[::-1]) h = interp.shift(h_new, shiftH[::-1]) print shiftH print shiftL xx, yy = np.meshgrid(np.arange(img.shape[0]), np.arange(img.shape[1])) idx = np.where((h >= 1) & (k >= 1) & (l >= 1)) # Trim off the bottom 10 rows where there is data ymin = yy[idx[0], idx[1]].min() ydx = np.where(yy[idx[0],idx[1]] > (ymin+10))[0] idx = (idx[0][ydx], idx[1][ydx]) img[idx[0],idx[1],0] = img_scale.log(l[idx[0],idx[1]], scale_min=scaleMinL[ii], scale_max=scaleMaxL[ii]) img[idx[0],idx[1],1] = img_scale.log(k[idx[0], idx[1]], scale_min=scaleMinK[ii], scale_max=scaleMaxK[ii]) img[idx[0],idx[1],2] = img_scale.log(h[idx[0], idx[1]], scale_min=scaleMinH[ii], scale_max=scaleMaxH[ii]) imgH[idx[0], idx[1]] = h[idx[0], idx[1]] / hint imgK[idx[0], idx[1]] = k[idx[0], idx[1]] / kint imgL[idx[0], idx[1]] = l[idx[0], idx[1]] / lint # Fix scaling of first image. if ii == 0: imgK[idx[0], idx[1]] -= 0.4 # Save on memory l = None k = None h = None l_new = None k_new = None h_new = None # Define the axes xaxis = np.arange(-0.5, img.shape[1]+0.5, 1) xaxis = ((xaxis - origin[0]) * scale[0]) yaxis = np.arange(-0.5, img.shape[0]+0.5, 1) yaxis = ((yaxis - origin[1]) * scale[1]) extent = [xaxis[0], xaxis[-1], yaxis[0], yaxis[-1]] # py.figure(1) # py.imshow(img[:,:,0], extent=extent, cmap=py.cm.gray) # py.axis('equal') py.figure(2) py.imshow(img[:,:,1], extent=extent, cmap=py.cm.gray) py.axis('equal') # py.figure(3) # py.imshow(img[:,:,2], extent=extent, cmap=py.cm.gray) # py.axis('equal') foo = raw_input('Continue?') gcutil.rmall(['w51a_h_mosaic.fits', 'w51a_k_mosaic.fits', 'w51a_l_mosaic.fits']) pyfits.writeto('w51a_h_mosaic.fits', imgH) pyfits.writeto('w51a_k_mosaic.fits', imgK) pyfits.writeto('w51a_l_mosaic.fits', imgL)
def mosaic_kp(): """ Make a mosaic of our NIRC2 data on W51, one per filter. """ hepochs = ['09jun26', '09jun26', '09jun26', '09jun26'] kepochs = ['09jun10', '09jun10', '09jun10', '09jun26'] lepochs = ['09jun26', '09jun26', '09jun26', '09jun26'] cooStarsH = ['f1_psf0', 'f2_psf0', 'f3_psf0', 'f4_psf0'] cooStarsK = ['f1_psf0', 'f2_psf0', 'f3_psf0', 'f4_psf0'] cooStarsL = ['f1_psf1', 'f2_psf0', 'f3_psf2', 'f4_psf1'] cooStarsH = ['E4-1', 'E8-1', 'N5-1', 'W6-2'] cooStarsK = ['E4-1', 'E8-1', 'N5-1', 'W6-2'] cooStarsL = ['S0-1', 'E8-1', 'W7-1', 'W9-1'] scaleMinH = [0, 0, 0, 0] scaleMinK = [0, 0, 0, 0] scaleMinL = [1000, 1100, 1200, 1250] scaleMaxH = [6000, 6000, 5000, 6000] scaleMaxK = [6500, 6500, 6500, 5500] scaleMaxL = [1600, 1300, 1400, 1600] img = np.zeros((2400, 2400, 3), dtype=float) imgH = np.zeros((2400, 2400), dtype=float) imgK = np.zeros((2400, 2400), dtype=float) imgL = np.zeros((2400, 2400), dtype=float) origin = np.array([1200.0, 1200.0]) labelFile = '/u/jlu/data/w51/source_list/w51a_label.dat' labels = starTables.Labels(labelFile=labelFile) dataRoot = '/u/jlu/data/w51/' py.clf() foo = range(len(hepochs)) for ii in foo[::-1]: # for ii in range(1): rootH = '%s/%s/combo/mag%s_w51a_f%d_h' % \ (dataRoot, hepochs[ii], hepochs[ii], ii+1) rootK = '%s/%s/combo/mag%s_w51a_f%d_kp' % \ (dataRoot, kepochs[ii], kepochs[ii], ii+1) rootL = '%s/%s/combo/mag%s_w51a_f%d_lp' % \ (dataRoot, lepochs[ii], lepochs[ii], ii+1) # Load up the images h, hhdr = pyfits.getdata(rootH + '.fits', header=True) k, khdr = pyfits.getdata(rootK + '.fits', header=True) l, lhdr = pyfits.getdata(rootL + '.fits', header=True) hint = hhdr['ITIME'] * hhdr['COADDS'] kint = khdr['ITIME'] * khdr['COADDS'] lint = lhdr['ITIME'] * lhdr['COADDS'] # Make the arrays into the largest size. h_new = np.zeros((img.shape[0], img.shape[1]), dtype=float) k_new = np.zeros((img.shape[0], img.shape[1]), dtype=float) l_new = np.zeros((img.shape[0], img.shape[1]), dtype=float) h_new[0:h.shape[0], 0:h.shape[1]] = h k_new[0:k.shape[0], 0:k.shape[1]] = k l_new[0:l.shape[0], 0:l.shape[1]] = l # Load up the coo stars tmpH = open(rootH + '.coo').readline().split() cooH = np.array([float(tmpH[0]), float(tmpH[1])]) tmpK = open(rootK + '.coo').readline().split() cooK = np.array([float(tmpK[0]), float(tmpK[1])]) tmpL = open(rootL + '.coo').readline().split() cooL = np.array([float(tmpL[0]), float(tmpL[1])]) # Get the coordinates of each coo star in arcsec. idxH = np.where(labels.name == cooStarsH[ii])[0][0] idxK = np.where(labels.name == cooStarsK[ii])[0][0] idxL = np.where(labels.name == cooStarsL[ii])[0][0] asecH = np.array([labels.x[idxH], labels.y[idxH]]) asecK = np.array([labels.x[idxK], labels.y[idxK]]) asecL = np.array([labels.x[idxL], labels.y[idxL]]) scale = np.array([-0.00995, 0.00995]) # Now figure out the necessary shifts originH = cooH - asecH / scale originK = cooK - asecK / scale originL = cooL - asecL / scale # Shift the J and H images to be lined up with K-band shiftL = origin - originL shiftK = origin - originK shiftH = origin - originH l = interp.shift(l_new, shiftL[::-1]) k = interp.shift(k_new, shiftK[::-1]) h = interp.shift(h_new, shiftH[::-1]) print shiftH print shiftL xx, yy = np.meshgrid(np.arange(img.shape[0]), np.arange(img.shape[1])) idx = np.where((h >= 1) & (k >= 1) & (l >= 1)) # Trim off the bottom 10 rows where there is data ymin = yy[idx[0], idx[1]].min() ydx = np.where(yy[idx[0], idx[1]] > (ymin + 10))[0] idx = (idx[0][ydx], idx[1][ydx]) img[idx[0], idx[1], 0] = img_scale.log(l[idx[0], idx[1]], scale_min=scaleMinL[ii], scale_max=scaleMaxL[ii]) img[idx[0], idx[1], 1] = img_scale.log(k[idx[0], idx[1]], scale_min=scaleMinK[ii], scale_max=scaleMaxK[ii]) img[idx[0], idx[1], 2] = img_scale.log(h[idx[0], idx[1]], scale_min=scaleMinH[ii], scale_max=scaleMaxH[ii]) imgH[idx[0], idx[1]] = h[idx[0], idx[1]] / hint imgK[idx[0], idx[1]] = k[idx[0], idx[1]] / kint imgL[idx[0], idx[1]] = l[idx[0], idx[1]] / lint # Fix scaling of first image. if ii == 0: imgK[idx[0], idx[1]] -= 0.4 # Save on memory l = None k = None h = None l_new = None k_new = None h_new = None # Define the axes xaxis = np.arange(-0.5, img.shape[1] + 0.5, 1) xaxis = ((xaxis - origin[0]) * scale[0]) yaxis = np.arange(-0.5, img.shape[0] + 0.5, 1) yaxis = ((yaxis - origin[1]) * scale[1]) extent = [xaxis[0], xaxis[-1], yaxis[0], yaxis[-1]] # py.figure(1) # py.imshow(img[:,:,0], extent=extent, cmap=py.cm.gray) # py.axis('equal') py.figure(2) py.imshow(img[:, :, 1], extent=extent, cmap=py.cm.gray) py.axis('equal') # py.figure(3) # py.imshow(img[:,:,2], extent=extent, cmap=py.cm.gray) # py.axis('equal') foo = raw_input('Continue?') gcutil.rmall( ['w51a_h_mosaic.fits', 'w51a_k_mosaic.fits', 'w51a_l_mosaic.fits']) pyfits.writeto('w51a_h_mosaic.fits', imgH) pyfits.writeto('w51a_k_mosaic.fits', imgK) pyfits.writeto('w51a_l_mosaic.fits', imgL)