def make_color_ao_image(): h_img = pyfits.getdata(workdir + 'mag05jullgs_h_rot.fits') h_imgScl = img_scale.sqrt(h_img, scale_min=50, scale_max=5500) kp_img = pyfits.getdata(workdir + 'mag05jullgs_kp_rot.fits') kp_imgScl = img_scale.sqrt(kp_img, scale_min=10, scale_max=17000) lp_img = pyfits.getdata(workdir + 'mag05jullgs_lp_rot.fits') lp_imgScl = img_scale.sqrt(lp_img, scale_min=-100, scale_max=60000) sgra = np.array([540, 410]) scale = 0.00995 h_xextent = np.array([0, h_img.shape[0]]) h_yextent = np.array([0, h_img.shape[0]]) h_xextent = (h_xextent - sgra[0]) * -scale h_yextent = (h_yextent - sgra[1]) * scale h_extent = [h_xextent[0], h_xextent[-1], h_yextent[0], h_yextent[-1]] img = np.zeros((h_img.shape[0], h_img.shape[1], 3), dtype=float) img[:,:,0] = lp_imgScl img[:,:,1] = kp_imgScl img[:,:,2] = h_imgScl py.figure(4, figsize=(10, 10)) py.clf() py.subplots_adjust(left=0, right=1, bottom=0, top=1) py.imshow(img, extent=h_extent) ax = py.gca() py.setp(ax.get_xticklabels(), visible=False) py.setp(ax.get_yticklabels(), visible=False) py.xlim(5, -5) py.ylim(-4, 6) py.savefig(workdir + 'img_lgsao_color.png')
def make_color_ao_image(): h_img = pyfits.getdata(workdir + 'mag05jullgs_h_rot.fits') h_imgScl = img_scale.sqrt(h_img, scale_min=50, scale_max=5500) kp_img = pyfits.getdata(workdir + 'mag05jullgs_kp_rot.fits') kp_imgScl = img_scale.sqrt(kp_img, scale_min=10, scale_max=17000) lp_img = pyfits.getdata(workdir + 'mag05jullgs_lp_rot.fits') lp_imgScl = img_scale.sqrt(lp_img, scale_min=-100, scale_max=60000) sgra = np.array([540, 410]) scale = 0.00995 h_xextent = np.array([0, h_img.shape[0]]) h_yextent = np.array([0, h_img.shape[0]]) h_xextent = (h_xextent - sgra[0]) * -scale h_yextent = (h_yextent - sgra[1]) * scale h_extent = [h_xextent[0], h_xextent[-1], h_yextent[0], h_yextent[-1]] img = np.zeros((h_img.shape[0], h_img.shape[1], 3), dtype=float) img[:, :, 0] = lp_imgScl img[:, :, 1] = kp_imgScl img[:, :, 2] = h_imgScl py.figure(4, figsize=(10, 10)) py.clf() py.subplots_adjust(left=0, right=1, bottom=0, top=1) py.imshow(img, extent=h_extent) ax = py.gca() py.setp(ax.get_xticklabels(), visible=False) py.setp(ax.get_yticklabels(), visible=False) py.xlim(5, -5) py.ylim(-4, 6) py.savefig(workdir + 'img_lgsao_color.png')
def make_deep_ao_image(): img = pyfits.getdata(workdir + 'mag05jullgs_kp_rot.fits') imgScl = img_scale.sqrt(img, scale_min=200, scale_max=15000) sgra = np.array([538, 400]) scale = 0.00995 xextent = np.array([0, img.shape[0]]) yextent = np.array([0, img.shape[0]]) xextent = (xextent - sgra[0]) * -scale yextent = (yextent - sgra[1]) * scale extent = [xextent[0], xextent[-1], yextent[0], yextent[-1]] py.figure(2, figsize=(6, 6)) py.clf() py.subplots_adjust(left=0, right=1, bottom=0, top=1) py.imshow(imgScl, cmap=py.cm.gray, extent=extent) ax = py.gca() py.setp(ax.get_xticklabels(), visible=False) py.setp(ax.get_yticklabels(), visible=False) py.xlim(3.7, -2.3) py.ylim(-2.7, 3.3) py.savefig(workdir + 'img_lgsao_deep.png')
def make_speckle_image(): speckle = pyfits.getdata(workdir + 'mag04jul_rot.fits') speckImg = img_scale.sqrt(speckle, scale_min=0, scale_max=150) sgra = np.array([483, 612]) scale = 0.0102 xextent = np.array([0, speckImg.shape[0]]) yextent = np.array([0, speckImg.shape[0]]) xextent = (xextent - sgra[0]) * -scale yextent = (yextent - sgra[1]) * scale extent = [xextent[0], xextent[-1], yextent[0], yextent[-1]] py.figure(1, figsize=(6, 6)) py.clf() py.subplots_adjust(left=0, right=1, bottom=0, top=1) py.imshow(speckImg, cmap=py.cm.gray, extent=extent) ax = py.gca() py.setp(ax.get_xticklabels(), visible=False) py.setp(ax.get_yticklabels(), visible=False) py.axis('equal') py.xlim(3.7, -2.3) py.ylim(-2.8, 3.2) py.savefig(workdir + 'img_speckle.png')
def mosaic3color_ukidss(): """ Make a 3 color mosaic of our NIRC2 data on W51. """ root = '/u/jlu/data/w51/ukidss/g48.9-0.3/ukidss_rgb' j = pyfits.getdata(root + '_b_j.fits') h = pyfits.getdata(root + '_g_h.fits') k = pyfits.getdata(root + '_r_k.fits') scale = [-0.2, 0.2] img = np.zeros((j.shape[0], j.shape[1], 3), dtype=float) img[:,:,0] = img_scale.sqrt(k, scale_min=0, scale_max=10000) img[:,:,1] = img_scale.sqrt(h, scale_min=0, scale_max=10000) img[:,:,2] = img_scale.sqrt(j, scale_min=0, scale_max=10000) print img[:,:,0].min(), img[:,:,0].max() print img[:,:,1].min(), img[:,:,1].max() print img[:,:,2].min(), img[:,:,2].max() origin = [j.shape[1]/2.0, j.shape[0]/2.0] print origin # 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.clf() py.imshow(img, extent=extent) py.axis('equal') py.axis([60, -40, -30, 70]) py.xlabel('R.A. Offset (arcsec)') py.ylabel('Dec. Offset (arcsec)') py.title('UKIDSS JHK') py.savefig('/u/jlu/work/w51/maps/w51a_3color_ukidss.png')
def mosaic3color_ukidss(): """ Make a 3 color mosaic of our NIRC2 data on W51. """ root = '/u/jlu/data/w51/ukidss/g48.9-0.3/ukidss_rgb' j = pyfits.getdata(root + '_b_j.fits') h = pyfits.getdata(root + '_g_h.fits') k = pyfits.getdata(root + '_r_k.fits') scale = [-0.2, 0.2] img = np.zeros((j.shape[0], j.shape[1], 3), dtype=float) img[:, :, 0] = img_scale.sqrt(k, scale_min=0, scale_max=10000) img[:, :, 1] = img_scale.sqrt(h, scale_min=0, scale_max=10000) img[:, :, 2] = img_scale.sqrt(j, scale_min=0, scale_max=10000) print img[:, :, 0].min(), img[:, :, 0].max() print img[:, :, 1].min(), img[:, :, 1].max() print img[:, :, 2].min(), img[:, :, 2].max() origin = [j.shape[1] / 2.0, j.shape[0] / 2.0] print origin # 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.clf() py.imshow(img, extent=extent) py.axis('equal') py.axis([60, -40, -30, 70]) py.xlabel('R.A. Offset (arcsec)') py.ylabel('Dec. Offset (arcsec)') py.title('UKIDSS JHK') py.savefig('/u/jlu/work/w51/maps/w51a_3color_ukidss.png')
def coo_max(files, psfName, manual=True): py.close(1) py.figure(1, figsize=(10,10)) py.subplots_adjust(left=0.1, bottom=0.08, right=0.95, top=0.93) firstFramePos = None for _file in files: fileDir, fileName = os.path.split(_file) fileRoot, fileExt = os.path.splitext(fileName) # Make a max file _max = open(fileDir + fileRoot + '.max', 'w') _max.write('35000\n') _max.close() # Read in the image for display to select a coo star img, hdr = pyfits.getdata(_file, header=True) imgRescale = img_scale.sqrt(img, scale_min=400, scale_max=5000) fig = py.figure(1) foo = fig.gca().get_xlabel() if foo != '': psfName = foo print 'Getting from old plot:', psfName py.clf() py.imshow(imgRescale, aspect='equal', cmap=py.cm.gray) py.title('{0} PA={1:.0f}'.format(fileRoot, hdr['PA'])) fig.gca().set_xlabel('{0}'.format(psfName)) print 'Plotting: ', psfName py.ylabel('Press "p" for new star name.') fig.canvas.mpl_connect('key_press_event', key_press) starFound = False while not starFound: psfName = fig.gca().get_xlabel() print 'In while: ', psfName # Get the user selected PSF stars if firstFramePos == None or manual == True: pts = py.ginput(1, timeout=0) xinit = int(round(pts[0][0])) yinit = int(round(pts[0][1])) else: xinit = firstFramePos[0] yinit = firstFramePos[1] boxSize = 50 # Get an initial sub-image imgSub, xLo, yLo = get_sub_image(img, boxSize, xinit, yinit) # Find the maximum pixel value within this box... # assume this is the star and re-center up on it maxIdx = np.where(imgSub == imgSub.max()) xinit = xLo + maxIdx[1][0] yinit = yLo + maxIdx[0][0] # Get an sub-image centered on brightest pixel imgSub, xLo, yLo = get_sub_image(img, boxSize, xinit, yinit) yc, xc = scipy.ndimage.center_of_mass(imgSub) xc += xLo yc += yLo print '%s Centroid: x=%.2f y=%.2f' % (fileRoot, xc, yc) py.figure(2) py.clf() py.imshow(imgRescale, aspect='equal', cmap=py.cm.gray) py.plot([xc], [yc], 'kx', ms=10) py.xlim(xc - 30, xc + 30) py.ylim(yc - 30, yc + 30) py.figure(1) gaussInfo = psf.moments(imgSub, SubSize=5) g_height = gaussInfo[0] g_muX = gaussInfo[1] g_muY = gaussInfo[2] g_FWHMX = gaussInfo[3] g_FWHMY = gaussInfo[4] g_FWHM = gaussInfo[5] g_Ellip = gaussInfo[6] g_angle = gaussInfo[7] hdrout = '{0:5s} {1:5s} {2:5s} {3:5s} {4:5s} ' hdrout += '{5:5s} {6:4s} {7}\n' strout = '{0:5.2f} {1:5.2f} {2:5.2f} {3:5.2f} {4:5.2f} ' strout += '{5:5.2f} {6:4.2f} {7:.1f}\n' _gauss = open(fileDir + fileRoot + '.metrics', 'w') _gauss.write(hdrout.format('muX', 'muY', 'FWHMX', 'FWHMY', 'FWHM', 'Ellip', 'Angle', 'Height')) _gauss.write(strout.format(g_muX, g_muY, g_FWHMX, g_FWHMY, g_FWHM, g_Ellip, g_angle, g_height)) _gauss.close() # Make a max file _coo = open(fileDir + fileRoot + '.coo', 'w') _coo.write('{0:.2f} {1:.2f} {2}\n'.format(xc, yc, psfName)) _coo.close() if firstFramePos == None: firstFramePos = [xc, yc] starFound = True return
def mosaic3color(): """ Make a 3 color mosaic of our NIRC2 data on W51. """ 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 = [5500, 5500, 5500, 4500] # scaleMaxL = [1600, 1300, 1400, 1600] scaleMaxL = [2000, 2000, 2000, 2000] img = np.zeros((2400, 2400, 3), 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 = pyfits.getdata(rootH + '.fits') k = pyfits.getdata(rootK + '.fits') l = pyfits.getdata(rootL + '.fits') # 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.sqrt(l[idx[0],idx[1]], scale_min=scaleMinL[ii], scale_max=scaleMaxL[ii]) img[idx[0],idx[1],1] = img_scale.sqrt(k[idx[0], idx[1]], scale_min=scaleMinK[ii], scale_max=scaleMaxK[ii]) img[idx[0],idx[1],2] = img_scale.sqrt(h[idx[0], idx[1]], scale_min=scaleMinH[ii], scale_max=scaleMaxH[ii]) # Defin 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.imshow(img, extent=extent) py.axis('equal') foo = raw_input('Continue?') py.axis([7, -7, -7, 7]) py.savefig('/u/jlu/work/w51/maps/w51a_3color.png')
def arches_figure(): """ Plot a 3 panel figure showing seeing-limited, HST, and AO data on the Arches cluster to illustrate the power of AO. """ # ---------- # NIRC2 # ---------- hroot = 'mag06maylgs2_arch_f1_h' kroot = 'mag06maylgs2_arch_f1_kp' lroot = 'mag06maylgs2_arch_f1_lp' cooStar = 'f1_psf0' scaleMinH = 1000 scaleMinK = 800 scaleMinL = 600 scaleMaxH = 4500 scaleMaxK = 8000 scaleMaxL = 10000 img = np.zeros((1500, 1500, 3), dtype=float) origin = np.array([750.0, 750.0]) labelFile = '/u/ghezgroup/data/gc/source_list/label_arch.dat' labels = starTables.Labels(labelFile=labelFile) dataDir = '/u/ghezgroup/data/gc/06maylgs2/combo/' # Load up the images h = pyfits.getdata(dataDir + hroot + '.fits') k = pyfits.getdata(dataDir + kroot + '.fits') l = pyfits.getdata(dataDir + lroot + '.fits') # 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(dataDir + hroot + '.coo').readline().split() cooH = np.array([float(tmpH[0]), float(tmpH[1])]) tmpK = open(dataDir + kroot + '.coo').readline().split() cooK = np.array([float(tmpK[0]), float(tmpK[1])]) tmpL = open(dataDir + lroot + '.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 == cooStar)[0][0] idxK = np.where(labels.name == cooStar)[0][0] idxL = np.where(labels.name == cooStar)[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]) # gcutil.rmall(['arches_f1_h.fits', 'arches_f1_kp.fits', 'arches_f1_lp.fits']) # pyfits.writeto('arches_f1_h.fits', h) # pyfits.writeto('arches_f1_kp.fits', k) # pyfits.writeto('arches_f1_lp.fits', l) img[idx[0],idx[1],0] = img_scale.sqrt(l[idx[0],idx[1]], scale_min=scaleMinL, scale_max=scaleMaxL) img[idx[0],idx[1],1] = img_scale.sqrt(k[idx[0], idx[1]], scale_min=scaleMinK, scale_max=scaleMaxK) img[idx[0],idx[1],2] = img_scale.sqrt(h[idx[0], idx[1]], scale_min=scaleMinH, scale_max=scaleMaxH) # 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]] img_nirc2 = img ext_nirc2 = extent # ---------- # UKIDSS # ---------- scaleMinJ = 20 scaleMinH = 400 scaleMinK = 1000 scaleMaxJ = 5000 scaleMaxH = 35000 scaleMaxK = 90000 dataDir = '/u/jlu/data/arches/ukidss/' # Load up the images j = pyfits.getdata(dataDir + 'ukidss_arches_j.fits') h = pyfits.getdata(dataDir + 'ukidss_arches_h.fits') k = pyfits.getdata(dataDir + 'ukidss_arches_k.fits') img = np.zeros((j.shape[0], j.shape[1], 3), dtype=float) origin = [173, 198] scale = [-0.2, 0.2] xx, yy = np.meshgrid(np.arange(img.shape[0]), np.arange(img.shape[1])) img[:,:,0] = img_scale.sqrt(k, scale_min=scaleMinK, scale_max=scaleMaxK) img[:,:,1] = img_scale.sqrt(h, scale_min=scaleMinH, scale_max=scaleMaxH) img[:,:,2] = img_scale.sqrt(j, scale_min=scaleMinJ, scale_max=scaleMaxJ) # 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]] img_ukidss = img ext_ukidss = extent py.figure(2, figsize=(6,12)) py.clf() py.subplots_adjust(bottom=0.05, top=0.95, hspace=0.25) py.subplot(2, 1, 1) py.imshow(img_ukidss, extent=ext_ukidss) py.axis('equal') py.axis([4.5, -6.5, -6.5, 4.5]) py.title('UKIDSS JHK') py.xlabel('R.A. Offset (arcsec)') py.ylabel('Dec. Offset (arcsec)') py.subplot(2, 1, 2) py.imshow(img_nirc2, extent=ext_nirc2) py.axis('equal') py.axis([4.5, -6.5, -6.5, 4.5]) py.title("Keck AO HK'L'") py.xlabel('R.A. Offset (arcsec)') py.ylabel('Dec. Offset (arcsec)') py.savefig('arches_see_vs_ao.png')
def arches_figure(): """ Plot a 3 panel figure showing seeing-limited, HST, and AO data on the Arches cluster to illustrate the power of AO. """ # ---------- # NIRC2 # ---------- hroot = 'mag06maylgs2_arch_f1_h' kroot = 'mag06maylgs2_arch_f1_kp' lroot = 'mag06maylgs2_arch_f1_lp' cooStar = 'f1_psf0' scaleMinH = 1000 scaleMinK = 800 scaleMinL = 600 scaleMaxH = 4500 scaleMaxK = 8000 scaleMaxL = 10000 img = np.zeros((1500, 1500, 3), dtype=float) origin = np.array([750.0, 750.0]) labelFile = '/u/ghezgroup/data/gc/source_list/label_arch.dat' labels = starTables.Labels(labelFile=labelFile) dataDir = '/u/ghezgroup/data/gc/06maylgs2/combo/' # Load up the images h = pyfits.getdata(dataDir + hroot + '.fits') k = pyfits.getdata(dataDir + kroot + '.fits') l = pyfits.getdata(dataDir + lroot + '.fits') # 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(dataDir + hroot + '.coo').readline().split() cooH = np.array([float(tmpH[0]), float(tmpH[1])]) tmpK = open(dataDir + kroot + '.coo').readline().split() cooK = np.array([float(tmpK[0]), float(tmpK[1])]) tmpL = open(dataDir + lroot + '.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 == cooStar)[0][0] idxK = np.where(labels.name == cooStar)[0][0] idxL = np.where(labels.name == cooStar)[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]) # gcutil.rmall(['arches_f1_h.fits', 'arches_f1_kp.fits', 'arches_f1_lp.fits']) # pyfits.writeto('arches_f1_h.fits', h) # pyfits.writeto('arches_f1_kp.fits', k) # pyfits.writeto('arches_f1_lp.fits', l) img[idx[0], idx[1], 0] = img_scale.sqrt(l[idx[0], idx[1]], scale_min=scaleMinL, scale_max=scaleMaxL) img[idx[0], idx[1], 1] = img_scale.sqrt(k[idx[0], idx[1]], scale_min=scaleMinK, scale_max=scaleMaxK) img[idx[0], idx[1], 2] = img_scale.sqrt(h[idx[0], idx[1]], scale_min=scaleMinH, scale_max=scaleMaxH) # 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]] img_nirc2 = img ext_nirc2 = extent # ---------- # UKIDSS # ---------- scaleMinJ = 20 scaleMinH = 400 scaleMinK = 1000 scaleMaxJ = 5000 scaleMaxH = 35000 scaleMaxK = 90000 dataDir = '/u/jlu/data/arches/ukidss/' # Load up the images j = pyfits.getdata(dataDir + 'ukidss_arches_j.fits') h = pyfits.getdata(dataDir + 'ukidss_arches_h.fits') k = pyfits.getdata(dataDir + 'ukidss_arches_k.fits') img = np.zeros((j.shape[0], j.shape[1], 3), dtype=float) origin = [173, 198] scale = [-0.2, 0.2] xx, yy = np.meshgrid(np.arange(img.shape[0]), np.arange(img.shape[1])) img[:, :, 0] = img_scale.sqrt(k, scale_min=scaleMinK, scale_max=scaleMaxK) img[:, :, 1] = img_scale.sqrt(h, scale_min=scaleMinH, scale_max=scaleMaxH) img[:, :, 2] = img_scale.sqrt(j, scale_min=scaleMinJ, scale_max=scaleMaxJ) # 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]] img_ukidss = img ext_ukidss = extent py.figure(2, figsize=(6, 12)) py.clf() py.subplots_adjust(bottom=0.05, top=0.95, hspace=0.25) py.subplot(2, 1, 1) py.imshow(img_ukidss, extent=ext_ukidss) py.axis('equal') py.axis([4.5, -6.5, -6.5, 4.5]) py.title('UKIDSS JHK') py.xlabel('R.A. Offset (arcsec)') py.ylabel('Dec. Offset (arcsec)') py.subplot(2, 1, 2) py.imshow(img_nirc2, extent=ext_nirc2) py.axis('equal') py.axis([4.5, -6.5, -6.5, 4.5]) py.title("Keck AO HK'L'") py.xlabel('R.A. Offset (arcsec)') py.ylabel('Dec. Offset (arcsec)') py.savefig('arches_see_vs_ao.png')
def mosaic3color(): """ Make a 3 color mosaic of our NIRC2 data on W51. """ 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 = [5500, 5500, 5500, 4500] # scaleMaxL = [1600, 1300, 1400, 1600] scaleMaxL = [2000, 2000, 2000, 2000] img = np.zeros((2400, 2400, 3), 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 = pyfits.getdata(rootH + '.fits') k = pyfits.getdata(rootK + '.fits') l = pyfits.getdata(rootL + '.fits') # 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.sqrt(l[idx[0], idx[1]], scale_min=scaleMinL[ii], scale_max=scaleMaxL[ii]) img[idx[0], idx[1], 1] = img_scale.sqrt(k[idx[0], idx[1]], scale_min=scaleMinK[ii], scale_max=scaleMaxK[ii]) img[idx[0], idx[1], 2] = img_scale.sqrt(h[idx[0], idx[1]], scale_min=scaleMinH[ii], scale_max=scaleMaxH[ii]) # Defin 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.imshow(img, extent=extent) py.axis('equal') foo = raw_input('Continue?') py.axis([7, -7, -7, 7]) py.savefig('/u/jlu/work/w51/maps/w51a_3color.png')
def coo_max(files, psfName, manual=True): py.close(1) py.figure(1, figsize=(10, 10)) py.subplots_adjust(left=0.1, bottom=0.08, right=0.95, top=0.93) firstFramePos = None for _file in files: fileDir, fileName = os.path.split(_file) fileRoot, fileExt = os.path.splitext(fileName) # Make a max file _max = open(fileDir + fileRoot + '.max', 'w') _max.write('35000\n') _max.close() # Read in the image for display to select a coo star img, hdr = pyfits.getdata(_file, header=True) imgRescale = img_scale.sqrt(img, scale_min=400, scale_max=5000) fig = py.figure(1) foo = fig.gca().get_xlabel() if foo != '': psfName = foo print 'Getting from old plot:', psfName py.clf() py.imshow(imgRescale, aspect='equal', cmap=py.cm.gray) py.title('{0} PA={1:.0f}'.format(fileRoot, hdr['PA'])) fig.gca().set_xlabel('{0}'.format(psfName)) print 'Plotting: ', psfName py.ylabel('Press "p" for new star name.') fig.canvas.mpl_connect('key_press_event', key_press) starFound = False while not starFound: psfName = fig.gca().get_xlabel() print 'In while: ', psfName # Get the user selected PSF stars if firstFramePos == None or manual == True: pts = py.ginput(1, timeout=0) xinit = int(round(pts[0][0])) yinit = int(round(pts[0][1])) else: xinit = firstFramePos[0] yinit = firstFramePos[1] boxSize = 50 # Get an initial sub-image imgSub, xLo, yLo = get_sub_image(img, boxSize, xinit, yinit) # Find the maximum pixel value within this box... # assume this is the star and re-center up on it maxIdx = np.where(imgSub == imgSub.max()) xinit = xLo + maxIdx[1][0] yinit = yLo + maxIdx[0][0] # Get an sub-image centered on brightest pixel imgSub, xLo, yLo = get_sub_image(img, boxSize, xinit, yinit) yc, xc = scipy.ndimage.center_of_mass(imgSub) xc += xLo yc += yLo print '%s Centroid: x=%.2f y=%.2f' % (fileRoot, xc, yc) py.figure(2) py.clf() py.imshow(imgRescale, aspect='equal', cmap=py.cm.gray) py.plot([xc], [yc], 'kx', ms=10) py.xlim(xc - 30, xc + 30) py.ylim(yc - 30, yc + 30) py.figure(1) gaussInfo = psf.moments(imgSub, SubSize=5) g_height = gaussInfo[0] g_muX = gaussInfo[1] g_muY = gaussInfo[2] g_FWHMX = gaussInfo[3] g_FWHMY = gaussInfo[4] g_FWHM = gaussInfo[5] g_Ellip = gaussInfo[6] g_angle = gaussInfo[7] hdrout = '{0:5s} {1:5s} {2:5s} {3:5s} {4:5s} ' hdrout += '{5:5s} {6:4s} {7}\n' strout = '{0:5.2f} {1:5.2f} {2:5.2f} {3:5.2f} {4:5.2f} ' strout += '{5:5.2f} {6:4.2f} {7:.1f}\n' _gauss = open(fileDir + fileRoot + '.metrics', 'w') _gauss.write( hdrout.format('muX', 'muY', 'FWHMX', 'FWHMY', 'FWHM', 'Ellip', 'Angle', 'Height')) _gauss.write( strout.format(g_muX, g_muY, g_FWHMX, g_FWHMY, g_FWHM, g_Ellip, g_angle, g_height)) _gauss.close() # Make a max file _coo = open(fileDir + fileRoot + '.coo', 'w') _coo.write('{0:.2f} {1:.2f} {2}\n'.format(xc, yc, psfName)) _coo.close() if firstFramePos == None: firstFramePos = [xc, yc] starFound = True return