def GeoTran(): filters = ['J', '1113', '1184'] for filt in filters: s = 'mfm*' + filt + '*.fits' files = glob.glob(s) flist = 'flist' + str(filt) glist = 'glist' + str(filt) fout = open(flist, 'w') gout = open(glist, 'w') for file in files: ffile = str(file) #+'\n' gfile = 'g' + str(file) #+'\n' fout.write(ffile + '\n') gout.write(gfile + '\n') iraf.geotran(input=ffile, output=gfile, database='PiscesBok', transforms=filt, fluxconserve='no') iraf.rotate(input=gfile, output=gfile, rotation=90) gfilein = 'g' + str(file) + '[-*,*]' gfileout = 'g' + str(file) iraf.imcopy(gfilein, gfileout) infiles = '@' + str(flist) outfiles = '@' + str(glist) #infiles=str(flist) #outfiles=str(glist) fout.close() gout.close()
def deimos_preproc(image): '''Take a MEF DEIMOS image, extract the relevant extensions, trim the LVM slit masks appropriately, and rename.''' # Needing grating graname = get_head(image, "GRATENAM", extn=0) # "Blue" chip iraf.imcopy("%s[%i]" % (image, BEXT), "d%s_B.fits" % image[6:10]) iraf.ccdproc("d%s_B.fits" % image[6:10], overscan=yes, trim=yes, fixpix=yes, biassec=BBIASSEC, trimsec=BTRIMSEC, fixfile="%s_%i.fits" % (MASK, BEXT)) iraf.imcopy("d%s_B.fits%s" % (image[6:10], DGRATINGS[graname]["blvmreg"]), "td%s_B.fits" % image[6:10]) iraf.imtranspose("td%s_B.fits" % image[6:10], "rtd%s_B.fits" % image[6:10]) # "Red" chip iraf.imcopy("%s[%i]" % (image, REXT), "d%s_R.fits" % image[6:10]) iraf.ccdproc("d%s_R.fits" % image[6:10], overscan=yes, trim=yes, fixpix=yes, biassec=RBIASSEC, trimsec=RTRIMSEC, fixfile="%s_%i.fits" % (MASK, BEXT)) iraf.imcopy("d%s_R.fits%s" % (image[6:10], DGRATINGS[graname]["rlvmreg"]), "td%s_R.fits" % image[6:10]) iraf.imtranspose("td%s_R.fits" % image[6:10], "rtd%s_R.fits" % image[6:10]) iraf.rotate("rtd%s_R.fits" % image[6:10], "rtd%s_R.fits" % image[6:10], 180.0) return
def rotate_2005_lgsao(): # Need to rotate an image. ir.unlearn('rotate') ir.rotate.boundary = 'constant' ir.rotate.constant = 0 ir.rotate.interpolant = 'spline3' ir.rotate.ncols = 1040 ir.rotate.nlines = 1040 ir.rotate.xin = 528 ir.rotate.xout = 540 ir.rotate.yin = 645 ir.rotate.yout = 410 ir.rotate(workdir + 'mag05jullgs_kp.fits', workdir + 'mag05jullgs_kp_rot.fits', 190) ir.rotate.xin = 535 ir.rotate.xout = 540 ir.rotate.yin = 655 ir.rotate.yout = 410 ir.rotate(workdir + 'mag05jullgs_h.fits', workdir + 'mag05jullgs_h_rot.fits', 190) ir.rotate.xin = 572 ir.rotate.xout = 540 ir.rotate.yin = 694 ir.rotate.yout = 410 ir.rotate(workdir + 'mag05jullgs_lp.fits', workdir + 'mag05jullgs_lp_rot.fits', 190) ir.rotate.xin = 483 ir.rotate.xout = 483 ir.rotate.yin = 612 ir.rotate.yout = 612 ir.rotate(workdir + 'mag04jul.fits', workdir + 'mag04jul_rot.fits', 1)
def rotate24(): for i in range(len(images24)): #for i in range(1): iraf.imgets( image=images24[i], param='CROTA2') #[deg] Orientation of axis 2 (W of N, +=CW) print iraf.imgets.value rot24 = float(iraf.imgets.value) iraf.imgets( image=images[i], param='ORIENTAT') #position angle of image y axis (deg. e of n) print iraf.imgets.value rotacs = float(iraf.imgets.value) angle = -1 * rot24 - rotacs outimage = rimages24[i] iraf.rotate(input=images24[i], output=outimage, rotation=angle)
def rotate(imlist_name, rotation): """ rotate and shift a list of images Rotate input output rotation Angle of rotation of the image in degrees. Positive angles will rotate the image counter-clockwise from the x axis. In the case of SAO 1-m longslit data, 180 degree rotation is required for easy wavelength calibration. """ import glob import os, sys from pyraf import iraf iraf.images() iraf.imgeom() imlist = glob.glob(imlist_name) imlist.sort() for i in range(len(imlist)): inim = imlist[i] print('Rotate ' + inim + ' with angle of ' + str(round(rotation, 3))) iraf.rotate(input=inim, output='r' + inim, rotation=rotation) print('r' + inim + ' is created.')
def lgsAnimate(redoImages=False): dataRoot = "/u/ghezgroup/data/gc/" imgRoots = ["05jullgs", "06maylgs1", "06junlgs", "06jullgs", "07maylgs", "07auglgs", "08maylgs1"] workRoot = "/u/ghezgroup/public_html/gc/images/media/image_anim/" alignRoot = workRoot + "align/align" s = starset.StarSet(alignRoot) names = s.getArray("name") idx = names.index("SgrA") sgraxOrig = s.stars[idx].getArrayAllEpochs("xorig") sgrayOrig = s.stars[idx].getArrayAllEpochs("yorig") sgrax = s.stars[idx].getArrayAllEpochs("xpix") sgray = s.stars[idx].getArrayAllEpochs("ypix") print sgraxOrig print sgrax print sgrayOrig print sgray sgrax = array([602.831, 600.688, 600.9547, 601.239, 601.118, 601.5432, 600.7679]) sgray = array([689.024, 686.918, 687.0692, 686.7293, 686.971, 686.8857, 687.4686]) # Color Ranges for Images - Log Scale vmin = array([2.55, 2.52, 2.45, 2.48, 2.5, 2.55, 2.5]) vmax = array([3.4, 3.33, 3.38, 3.35, 3.4, 3.25, 3.25]) # Image plate scale scale = 0.00996 if len(imgRoots) != len(sgrax): print "Problem... images and align do not match. Compare to align.list" print imgRoots import gcutil, nirc2 if redoImages: # Need to rotate images from pyraf import iraf as ir ir.unlearn("rotate") ir.rotate.boundary = "constant" ir.rotate.constant = 0 ir.rotate.interpolant = "spline3" # Need to plot images pylab.clf() for i in range(len(imgRoots)): imgIn = dataRoot + imgRoots[i] + "/combo/mag" + imgRoots[i] + "_kp.fits" imgOut = "images/mag" + imgRoots[i] + "_rot.fits" trans = objects.Transform() trans.loadFromAbsolute(root=workRoot, align="align/align.trans", idx=i) trans.linearToSpherical(override=False) hdr = pyfits.getheader(imgIn) # phi = nirc2.getPA(hdr) phi = math.degrees(trans.angle) if phi != 0: phi *= -1 if redoImages: gcutil.rmall([imgOut]) ir.rotate.xin = sgraxOrig[i] ir.rotate.yin = sgrayOrig[i] ir.rotate.xout = sgrax[i] ir.rotate.yout = sgray[i] ir.rotate(imgIn, imgOut, phi) img = pyfits.getdata(imgOut) xax = arange(0, img.shape[0]) yax = arange(0, img.shape[1]) xax = (xax - sgrax[1]) * -scale yax = (yax - sgray[1]) * scale pylab.imshow(log10(img), extent=[xax[0], xax[-1], yax[0], yax[-1]], vmin=vmin[i], vmax=vmax[i]) pylab.plot([0], [0], "k+") # pylab.axis([0.5, -0.5, -0.5, 0.5]) pylab.axis([0.8, -0.8, -0.8, 0.8]) # pylab.axis([3, -3, -3, 3]) pylab.xlabel("RA Offset from Sgr A* (arcsec)") pylab.ylabel("RA Offset from Sgr A* (arcsec)") pylab.title(imgRoots[i]) pylab.savefig("frame%d.png" % i)
def ASYM(cutimage, maskimage, ini_xcntr, ini_ycntr, pa, one_minus_eg_sq, r50, background, extraction_radius, angle, flag_image, ABS_ZSUM): iraf.images(_doprint=0) iraf.images.imgeom(_doprint=0) iraf.images.imutil(_doprint=0) co = n.cos(pa * n.pi / 180.0) si = n.sin(pa * n.pi / 180.0) Aabs = n.zeros([9]) Aabs = Aabs.astype(n.float32) rot_sum = n.zeros([9]) rot_sum = rot_sum.astype(n.float32) abs_zsum = n.zeros([9]) abs_zsum = abs_zsum.astype(n.float32) sh_sum = n.zeros([9]) sh_sum = sh_sum.astype(n.float32) absres_sum = n.zeros([9]) absres_sum = absres_sum.astype(n.float32) f=pyfits.open(cutimage) z = f[0].data z = z - background f.close() z = n.swapaxes(z, 0, 1) iraf.rotate("".join(maskimage), output="MRotated.fits",\ rotation=180, xin = ini_xcntr + 1.0,\ yin = ini_ycntr + 1.0, \ xout = ini_xcntr + 1.0, yout = ini_ycntr + 1.0, \ ncols= "INDEF",\ nlines = "INDEF", interpo= "linear", \ boundar="nearest", verbose="no") # iraf.imarith("".join(maskimage), op="*", operand2="MRotated.fits", \ # result="AMask.fits") # f=pyfits.open("AMask.fits") # mask = f[0].data # f.close() f=pyfits.open("MRotated.fits") mask1 = f[0].data f.close() mask1 = n.swapaxes(mask1, 0, 1) f=pyfits.open(maskimage) mask2 = f[0].data f.close() mask2 = n.swapaxes(mask2, 0, 1) mask = mask1 + mask2 maskedgalaxy = ma.masked_array(z, mask) z = ma.filled(maskedgalaxy, value = background) hdu = pyfits.PrimaryHDU(n.swapaxes(z, 0, 1).astype(n.float32)) hdu.writeto('MaskedGalaxy.fits') NXPTS = z.shape[0] NYPTS = z.shape[1] #r50=c.r50 center_rad = 0.01 * r50 # print 'center_rad', center_rad # center_rad = 0.5#0.01*r50 The centering correction has to be done by calculating asymmetric parameters at different points 0.1% of r50 away around the center flag_center = 0 #flag_center=1 if the program finds the exact center else center=0 #extraction_radius=total_rad ie. 1.5 times the radius at eta=0.2 x = n.reshape(n.arange(NXPTS * NYPTS), (NXPTS, NYPTS)) / NYPTS x = x.astype(n.float32) y = n.reshape(n.arange(NXPTS * NYPTS), (NXPTS, NYPTS)) % NYPTS y = y.astype(n.float32) nn = 0 #This nn is given here and the following loop run either it finds the minimum asymmetry or n=20 while flag_center == 0: flag_out = 0 #x and y coordinates of different center points in 1-d array xcntr = n.reshape(n.array([[ini_xcntr] * 3, [ini_xcntr - center_rad] *\ 3, [ini_xcntr + center_rad] * 3]), (9, )) xcntr = xcntr.astype(n.float32) ycntr = n.array([ini_ycntr, ini_ycntr - center_rad, ini_ycntr + \ center_rad]*3) ycntr = ycntr.astype(n.float32) for iter in range(9):#The below is done in order to keep the extraction radius inside the image. If the extraction radius goes outside the image then flag_out=1 if(flag_image):#flag_image will tell whether the input is image (flag_image=1) or background (flag_image=0) if(xcntr[iter] - 2 - extraction_radius < 0): extraction_radius = xcntr[iter] - 2 flag_out = 1 if(ycntr[iter] - 2 - extraction_radius < 0): extraction_radius = ycntr[iter] - 2 flag_out = 1 if(xcntr[iter] + 2 + extraction_radius > NXPTS): extraction_radius = NXPTS - xcntr[iter] - 2 flag_out = 1 if(ycntr[iter] + 2 + extraction_radius > NYPTS): extraction_radius = NYPTS - ycntr[iter] - 2 flag_out = 1 tx = (x - xcntr[iter]) * co + (y - ycntr[iter]) * si ty = (xcntr[iter] - x) * si + (y - ycntr[iter]) * co R = n.sqrt(tx**2.0 + ty**2.0 / one_minus_eg_sq) iraf.rotate("".join("MaskedGalaxy.fits"), output="Rotated.fits",\ rotation = 180, xin = xcntr[iter] + 1.0, \ yin = ycntr[iter] + 1.0, \ xout = xcntr[iter] + 1.0, yout = ycntr[iter] + 1.0, \ ncols = "INDEF",\ nlines = "INDEF", interpo = "linear", \ boundar = "nearest", verbose = "no") f = pyfits.open("Rotated.fits") rz = f[0].data f.close() rz = n.swapaxes(rz, 0, 1) res = z - rz for myfile in ['Rotated.fits', 'Residual.fits', 'AResidual.fits']: if os.access(myfile, os.F_OK): os.remove(myfile) sh_sum[iter] = z[n.where(R <= extraction_radius)].sum() rot_sum[iter] = rz[n.where(R <= extraction_radius)].sum() abs_zsum[iter] = abs(z[n.where(R <= extraction_radius)]).sum() absres_sum[iter] = abs(res[n.where(R <= extraction_radius)]).sum() if(flag_image): Aabs[iter] = absres_sum[iter] / (abs_zsum[iter]) else: Aabs[iter] = absres_sum[iter] / (ABS_ZSUM) Aabso = Aabs.min() index = Aabs.argmin() if(nn > 20): xcntr[index] = ini_xcntr ycntr[index] = ini_ycntr if(xcntr[index] == ini_xcntr and ycntr[index] == ini_ycntr): iraf.rotate("".join("MaskedGalaxy.fits"), output = "Rotated.fits",\ rotation = 180, xin = xcntr[iter] + 1.0, \ yin = ycntr[iter] + 1.0, \ xout = xcntr[iter] + 1.0, yout = ycntr[iter] + 1.0, \ ncols = "INDEF",\ nlines = "INDEF", interpo = "linear", \ boundar = "nearest", verbose = "no") f = pyfits.open("Rotated.fits") rz = f[0].data f.close() rz = n.swapaxes(rz, 0, 1) res = z - rz hdu = pyfits.PrimaryHDU(n.swapaxes(res, 0, 1).astype(n.float32)) hdu.writeto('AResidual.fits') flag_center = 1 rot_sum = rot_sum[index] abs_zsum = abs_zsum[index] if(flag_image == 0): abs_zsum = ABS_ZSUM sh_sum = sh_sum[index] absres_sum = absres_sum[index] if(flag_image): error_asym = n.sqrt( Aabso**2*( ((sh_sum + rot_sum + 4 * \ background * \ R[n.where(R <= n.floor(extraction_radius))].size) \ / absres_sum**2.0) + ((sh_sum + 2.0 * background *\ R[n.where(R <= n.floor(extraction_radius))].size) \ / abs_zsum**2) ) ) else: error_asym = n.sqrt( Aabso**2 * (((sh_sum+rot_sum + 2 * \ background * \ R[n.where(R <= n.floor(extraction_radius))].size) \ / absres_sum**2.0) + ((sh_sum + 2.0 * background \ * R[n.where(R <= n.floor(extraction_radius))].size) \ / abs_zsum**2) ) ) else: ini_xcntr = xcntr[index] ini_ycntr = ycntr[index] nn += 1 for myfile in ['MaskedGalaxy.fits', 'MRotated.fits']: if os.access(myfile, os.F_OK): os.remove(myfile) return Aabso, error_asym, ini_xcntr, ini_ycntr, nn, flag_out,\ abs_zsum, sh_sum, extraction_radius
def psf_rotate(psf, psf_rot, angle): file_remove(psf_rot) iraf.rotate(psf + '[0]', psf_rot, -angle, interpolant='nearest') iraf.rotate.unlearn()
def rotate(params, params_gal, dark_perform): """This function rotates the image Args: key: (str) key value for galaxy. e.g. jcmc11ctq_flt.fits has key == rw: (str) name of FLT file x_filter: (str)filter name . e.g. F165LP params: (dict) Dictionary of 'basic' section of config file (common for all ULIRGs) params_gal: (dict) Dictionary of galaxy parameters from config file Returns: str : (xreg_out) shifted image with a reference image """ flt_files = params['flt_files'] tab = Table.read(flt_files, format='csv') rw = list(tab["filename"]) gal_name = params_gal['name'] dark = params_gal['dark_frames'] dark = (dark.split(',')) bad = params_gal['bad_frames'] bad = (bad.split(',')) primary_dir = params['data_dir'] + gal_name + '/' t = 0 for i in range(len(tab)): c = [] for letter in rw[i]: c.append(letter) gal_key = c[4] + c[5] + c[6] + c[7] + c[8] x_filter = tab["filtername"][i] if t == 0: ref_angle = float(tab["orientation"][i]) rotate_ang = float(tab["orientation"][i]) - ref_angle if gal_key not in bad \ and gal_key not in dark \ and tab["galaxy"][i] == gal_name \ and tab["detector"][i] == "SBC": t = t + 1 sky_dark_iraf, rotate_out, sky_dark_err, rotate_out_err, sky_dark_DQ, rotate_out_DQ = \ iraf_rotate_command("sky", rw[i], x_filter, primary_dir) iraf.rotate(sky_dark_iraf, rotate_out, rotate_ang, interpolant='nearest') iraf.rotate.unlearn() iraf.rotate(sky_dark_err, rotate_out_err, rotate_ang, interpolant='nearest') iraf.rotate.unlearn() iraf.rotate(sky_dark_DQ, rotate_out_DQ, rotate_ang, interpolant='nearest') iraf.rotate.unlearn() if gal_key in dark \ and tab["galaxy"][i] == gal_name \ and tab["detector"][i] == "SBC" and dark_perform: sky_dark_iraf, rotate_out, sky_dark_err, rotate_out_err, sky_dark_DQ, rotate_out_DQ = \ iraf_rotate_command("drk", rw[i], x_filter, primary_dir) iraf.rotate(sky_dark_iraf, rotate_out, rotate_ang, interpolant='nearest') iraf.rotate.unlearn() iraf.rotate(sky_dark_err, rotate_out_err, rotate_ang, interpolant='nearest') iraf.rotate.unlearn() iraf.rotate(sky_dark_DQ, rotate_out_DQ, rotate_ang, interpolant='nearest') iraf.rotate.unlearn() return tab, bad, dark, primary_dir
def lgsAnimate(redoImages=False): dataRoot = '/u/ghezgroup/data/gc/' imgRoots = [ '05jullgs', '06maylgs1', '06junlgs', '06jullgs', '07maylgs', '07auglgs', '08maylgs1' ] workRoot = '/u/ghezgroup/public_html/gc/images/media/image_anim/' alignRoot = workRoot + 'align/align' s = starset.StarSet(alignRoot) names = s.getArray('name') idx = names.index('SgrA') sgraxOrig = s.stars[idx].getArrayAllEpochs('xorig') sgrayOrig = s.stars[idx].getArrayAllEpochs('yorig') sgrax = s.stars[idx].getArrayAllEpochs('xpix') sgray = s.stars[idx].getArrayAllEpochs('ypix') print sgraxOrig print sgrax print sgrayOrig print sgray sgrax = array( [602.831, 600.688, 600.9547, 601.239, 601.118, 601.5432, 600.7679]) sgray = array( [689.024, 686.918, 687.0692, 686.7293, 686.971, 686.8857, 687.4686]) # Color Ranges for Images - Log Scale vmin = array([2.55, 2.52, 2.45, 2.48, 2.5, 2.55, 2.5]) vmax = array([3.4, 3.33, 3.38, 3.35, 3.4, 3.25, 3.25]) # Image plate scale scale = 0.00996 if (len(imgRoots) != len(sgrax)): print 'Problem... images and align do not match. Compare to align.list' print imgRoots import gcutil, nirc2 if (redoImages): # Need to rotate images from pyraf import iraf as ir ir.unlearn('rotate') ir.rotate.boundary = 'constant' ir.rotate.constant = 0 ir.rotate.interpolant = 'spline3' # Need to plot images pylab.clf() for i in range(len(imgRoots)): imgIn = dataRoot + imgRoots[i] + '/combo/mag' + imgRoots[i] + '_kp.fits' imgOut = 'images/mag' + imgRoots[i] + '_rot.fits' trans = objects.Transform() trans.loadFromAbsolute(root=workRoot, align='align/align.trans', idx=i) trans.linearToSpherical(override=False) hdr = pyfits.getheader(imgIn) #phi = nirc2.getPA(hdr) phi = math.degrees(trans.angle) if (phi != 0): phi *= -1 if (redoImages): gcutil.rmall([imgOut]) ir.rotate.xin = sgraxOrig[i] ir.rotate.yin = sgrayOrig[i] ir.rotate.xout = sgrax[i] ir.rotate.yout = sgray[i] ir.rotate(imgIn, imgOut, phi) img = pyfits.getdata(imgOut) xax = arange(0, img.shape[0]) yax = arange(0, img.shape[1]) xax = (xax - sgrax[1]) * -scale yax = (yax - sgray[1]) * scale pylab.imshow(log10(img), extent=[xax[0], xax[-1], yax[0], yax[-1]], vmin=vmin[i], vmax=vmax[i]) pylab.plot([0], [0], 'k+') #pylab.axis([0.5, -0.5, -0.5, 0.5]) pylab.axis([0.8, -0.8, -0.8, 0.8]) #pylab.axis([3, -3, -3, 3]) pylab.xlabel('RA Offset from Sgr A* (arcsec)') pylab.ylabel('RA Offset from Sgr A* (arcsec)') pylab.title(imgRoots[i]) pylab.savefig('frame%d.png' % i)
def psf_rotate(psf, psf_rot, angle): iraf.rotate(psf + '[0]', psf_rot, -angle, interpolant='nearest')
def lgsAnimate(redoAlign=False, redoImages=False): dataRoot = '/u/ghezgroup/data/gc/' imgRoots = ['05jullgs', '06maylgs1', '06junlgs', '06jullgs', '07maylgs', '07auglgs', '08maylgs1', '08jullgs', '09maylgs', '10maylgs', '10jullgs1', '10auglgs1', '11maylgs', '11auglgs'] refEpoch = '08maylgs' workRoot = '/u/ghezgroup/public_html/gc/images/media/image_anim/' alignRoot = workRoot + 'align/align' if (redoAlign): # Copy over the starlists for epoch in imgRoots: lisFile = 'mag' + epoch + '_kp_rms.lis' copyFrom = dataRoot + epoch + '/combo/starfinder/' + lisFile copyTo = workRoot + 'lis/' shutil.copy(copyFrom, copyTo) lisFile = 'mag' + epoch + '_kp_rms_named.lis' copyFrom = dataRoot + epoch + '/combo/starfinder/' + lisFile copyTo = workRoot + 'lis/' shutil.copy(copyFrom, copyTo) # Align os.chdir(workRoot + 'align/') alignList = open(alignRoot + '.list', 'w') for epoch in imgRoots: lisFile = 'mag' + epoch + '_kp_rms.lis' alignList.write('../lis/' + lisFile + ' 9') if (epoch == refEpoch): alignList.write(' ref') alignList.write('\n') alignList.close() alignCmd = 'java align -a 2 -p ' alignCmd += '-N /u/ghezgroup/data/gc/source_list/label.dat ' #alignCmd += '-N /u/ghezgroup/data/gc/source_list/label_new.dat ' alignCmd += '-o /u/ghezgroup/data/gc/source_list/orbits.dat ' alignCmd += 'align.list' os.system(alignCmd) absCmd = 'java align_absolute ' absCmd += '-abs /u/ghezgroup/data/gc/source_list/absolute_refs.dat ' absCmd += 'align align_abs' os.system(absCmd) os.chdir(workRoot) s = starset.StarSet(alignRoot+'_abs') names = s.getArray('name') idx = names.index('SgrA') sgraxOrig = s.stars[idx].getArrayAllEpochs('xorig') sgrayOrig = s.stars[idx].getArrayAllEpochs('yorig') sgrax = s.stars[idx].getArrayAllEpochs('xpix') sgray = s.stars[idx].getArrayAllEpochs('ypix') print 'sgraxOrig = ', sgraxOrig print 'sgrax = ', sgrax print 'sgrayOrig = ', sgrayOrig print 'sgray = ', sgray # Tweak 05jullgs Sgr A* position, since it was not detected print print 'Tweaking 05jullgs Sgr A* position, since it was not named in the starlist' sgraxOrig[0] = 525.9 sgrayOrig[0] = 643.9 sgrax[0] = 0.0 sgray[0] = 0.0 print 'Update code with positions of Sgr A*' foo = raw_input('Continue? ') if (foo == 'q' or foo == 'Q'): return # Tweaks to Sgr A*'s positions (in arcseconds) # more negative goes to the right dx = array([-0.017, -0.002, -0.003, -0.005, 0.001, 0.00, 0.002, 0.001, 0.002, 0.001, 0.00, 0.00, 0.001, 0.00]) dy = array([ 0.005, 0.00, 0.00, 0.00, 0.001, 0.00, 0.00, -0.003, 0.00, 0.00, 0.000, 0.00, 0.000, 0.00]) # Color Ranges for Images - Log Scale vmin = array([2.48, 2.51, 2.45, 2.48, 2.50, 2.55, 2.50, 2.50, 2.50, 2.55, 2.53, 2.53, 2.53, 2.45]) vmax = array([3.45, 3.32, 3.38, 3.35, 3.40, 3.25, 3.3, 3.35, 3.3, 3.30, 3.30, 3.30, 3.30, 3.45]) # Image plate scale scale = 0.00995 if (len(imgRoots) != len(sgrax)): print 'Problem... images and align do not match. Compare to align.list' print imgRoots from gcreduce import gcutil import nirc2 if (redoImages): # Need to rotate images from pyraf import iraf as ir ir.unlearn('rotate') ir.rotate.boundary = 'constant' ir.rotate.constant = 0 ir.rotate.interpolant = 'spline3' # Need to plot images pylab.clf() for i in range(len(imgRoots)): imgIn = dataRoot + imgRoots[i] + '/combo/mag' + imgRoots[i] + '_kp.fits' imgOut = 'images/mag' + imgRoots[i] + '_rot.fits' hdr = pyfits.getheader(imgIn) phi = nirc2.getPA(hdr) if (redoImages): gcutil.rmall([imgOut]) ir.rotate.xin = sgraxOrig[i]+1 ir.rotate.yin = sgrayOrig[i]+1 ir.rotate.xout = (sgrax[i]/scale)+512+1 ir.rotate.yout = (sgray[i]/scale)+512+1 ir.rotate(imgIn, imgOut, phi) img = pyfits.getdata(imgOut) xax = arange(0, img.shape[1]) yax = arange(0, img.shape[0]) xax = (xax - 512.) * -scale + dx[i] yax = (yax - 512.) * scale + dy[i] # With labels and borders pylab.figure(1) pylab.clf() pylab.figure(figsize=(7,7)) pylab.imshow(log10(img), extent=[xax[0], xax[-1], yax[0], yax[-1]], vmin=vmin[i], vmax=vmax[i],origin='lowerleft') pylab.plot([0], [0], 'k+') #pylab.axis([0.5, -0.5, -0.5, 0.5]) #pylab.axis([0.8, -0.8, -0.8, 0.8]) #pylab.axis([3, -3, -3, 3]) pylab.axis([1, -1, -1, 1]) pylab.xlabel('RA Offset from Sgr A* (arcsec)') pylab.ylabel('Dec Offset from Sgr A* (arcsec)') pylab.title(imgRoots[i]) pylab.savefig('frame%d.png' % i) pylab.close(1) # No labels and borders pylab.figure(2) pylab.clf() pylab.figure(figsize=(6,6)) pylab.subplots_adjust(left=0, right=1, bottom=0, top=1) pylab.imshow(log10(img), extent=[xax[0], xax[-1], yax[0], yax[-1]], vmin=vmin[i], vmax=vmax[i],origin='lowerleft') pylab.plot([0], [0], 'k+') pylab.axis([0.5, -0.5, -0.5, 0.5]) pylab.axis('off') pylab.title(imgRoots[i]) pylab.savefig('frame%d_noborder.png' % i) pylab.close(2)