fef = pyfits.open('big_mosaic_feii.fits') fe = fef[0].data if os.path.exists('big_mosaic_feii_unsharp.fits'): feunsharp = pyfits.getdata('big_mosaic_feii_unsharp.fits') fenormed = pyfits.getdata('big_mosaic_feii_normed.fits') else: #kernel = astropy.nddata.convolution.make_kernel.make_kernel([151,151],kernelwidth=50) #fesmooth = astropy.nddata.convolve(fe,kernel) mimg = mask_image(fe, downsample=4) fesmooth = agpy.smooth(mimg, 250, fft_pad=False, interpolate_nan=True, psf_pad=False, ignore_edge_zeros=True, normalize_kernel=True, use_numpy_fft=True, nthreads=1, use_rfft=True, complextype=np.float32, silent=False, boundary='fill') feunsharp = fe for ii in xrange(4): for jj in xrange(4): shape = feunsharp[ii::4, jj::4].shape feunsharp[ii::4, jj::4] -= fesmooth[:shape[0], :shape[1]] fef[0].data = feunsharp fef.writeto("big_mosaic_feii_unsharp.fits", clobber=True) fenormed = fe for ii in xrange(4):
#FeII_NS_mosaic.fits H2_NS_mosaic.fits H2_mosaic.fits KS_mosaic.fits Ks_NS_mosaic.fits fef = pyfits.open('Fe_NS_mosaic_bgm.fits') fe = fef[0].data if os.path.exists('Fe_NS_mosaic_bgm_unsharp.fits'): feunsharp = pyfits.getdata('Fe_NS_mosaic_bgm_unsharp.fits') fenormed = pyfits.getdata('Fe_NS_mosaic_bgm_normed.fits') else: #kernel = astropy.nddata.convolution.make_kernel.make_kernel([151,151],kernelwidth=50) #fesmooth = astropy.nddata.convolve(fe,kernel) fesmooth = agpy.smooth(fe[::4, ::4], 250, fft_pad=False, interpolate_nan=True, psf_pad=False, ignore_edge_zeros=True, normalize_kernel=True, use_numpy_fft=True, nthreads=1, use_rfft=True, complextype=np.float32, silent=False, boundary='wrap') feunsharp = fe for ii in xrange(4): for jj in xrange(4): feunsharp[ii::4, jj::4] -= fesmooth fef[0].data = feunsharp fef.writeto("Fe_NS_mosaic_bgm_unsharp.fits", clobber=True) fenormed = fe for ii in xrange(4): for jj in xrange(4):
if not 'fe' in locals(): import pyfits #FeII_NS_mosaic.fits H2_NS_mosaic.fits H2_mosaic.fits KS_mosaic.fits Ks_NS_mosaic.fits # fe_montage_georgs_southeast.fits # h2_montage_georgs_southeast.fits # ks_montage_georgs_southeast.fits fef = pyfits.open('fe_montage_georgs_southeast.fits') fe = fef[0].data if os.path.exists('fe_montage_georgs_southeast_unsharp.fits'): feunsharp = pyfits.getdata('fe_montage_georgs_southeast_unsharp.fits') fenormed = pyfits.getdata('fe_montage_georgs_southeast_normed.fits') else: #kernel = astropy.nddata.convolution.make_kernel.make_kernel([151,151],kernelwidth=50) #fesmooth = astropy.nddata.convolve(fe,kernel) fesmooth = agpy.smooth(fe[::4,::4],250, fft_pad=False, interpolate_nan=True, psf_pad=False, ignore_edge_zeros=True, normalize_kernel=True, use_numpy_fft=True, nthreads=1, use_rfft=True, complextype=np.float32, silent=False, boundary='wrap') feunsharp = fe for ii in xrange(4): for jj in xrange(4): feunsharp[ii::4,jj::4] -= fesmooth fef[0].data = feunsharp fef.writeto("fe_montage_georgs_southeast_unsharp.fits",clobber=True) fenormed = fe for ii in xrange(4): for jj in xrange(4): fenormed[ii::4,jj::4] /= fesmooth fef[0].data = fenormed fef.writeto("fe_montage_georgs_southeast_normed.fits",clobber=True) # too big fesmooth = astropy.smooth(fe,100,ignore_nan=True) #b2 = pyfits.open('GEMS_B2_Trapezium_mosaic_bgmatch.fits')
ylabel('Power (Jy$^2$)') axis([0.00015, 0.15, 5e2, 1e10]) savefig('deconv_sim_wavenum_PSDSs.png') if 1: for ii, rad in enumerate([ 100, 210, 240, 270, 300, 330, 360, 400, 500, 600, 700, 800, 900, 1000 ]): if (ii % nprocs != myrank): continue #brfs[rad] = exp(-(rr*7.2)**2/(2.0*(rad/2.35)**2)) / exp(-(rr*7.2)**2/(2.0*(rad/2.35)**2)).sum() #kernel = numpy.sinc(2*numpy.pi*rr/rad) #kernel /= kernel.sum() #brsms[rad] = convolve(imgf,kernel) brickwalled = smooth(imgf, rad / 7.2, 'brickwall') gaussianed = smooth(imgf, rad / 2.35 / 7.2, 'gaussian') tophatted = smooth(imgf, rad / 7.2, 'tophat') figure(ii) clf() spectral() subplot(221) imshow(img, vmin=-1, vmax=10) title("Input Image") colorbar() subplot(222) imshow((img - pipeimg) - tophatted[:1155, :1151], vmin=-1, vmax=1) title('Filtered with %i" radius tophat' % rad) colorbar() subplot(223) imshow((img - pipeimg) - gaussianed[:1155, :1151], vmin=-1, vmax=1)
sourceimg/=sourceimg.sum() print "Filling Factor: ",(beamimg*sourceimg).sum() pl.figure(11) pl.clf() pl.subplot(1,3,1) pl.imshow(beamimg) pl.colorbar() pl.subplot(1,3,2) pl.imshow(sourceimg) pl.colorbar() pl.subplot(1,3,3) pl.imshow(beamimg*sourceimg) pl.colorbar() sourcepars = [0, 1, xc-30/15., yc+30/15., width_x_as.value, width_y_as.value, rota] sourceimgshift = gaussfitter.twodgaussian(sourcepars, shape=shape) sourceimgshift/=sourceimgshift.sum() print "Filling Factor (offset by 30,30): ",(beamimg*sourceimgshift).sum() sourcepars = [0, 1, xc-90/15., yc+90/15., width_x_as.value, width_y_as.value, rota] sourceimgshift = gaussfitter.twodgaussian(sourcepars, shape=shape) sourceimgshift/=sourceimgshift.sum() print "Filling Factor (offset by 90,90): ",(beamimg*sourceimgshift).sum() print "The filling factor appears to not be the correction factor for the elliptical gaussian." from agpy import smooth # to simulate what is done to the 2 cm image... si = sourceimg.copy() si /= si.max() print "The correction factor is ",smooth(si,4).max()
import pyfits #fe_NS_mosaic.fits H2_NS_mosaic.fits H2_mosaic.fits KS_mosaic.fits Ks_NS_mosaic.fits # fe_montage_georgs_southeast.fits # altair_big_h2.fits # fe_montage_georgs_southeast.fits fef = pyfits.open('altair_big_fe.fits') fe = fef[0].data if os.path.exists('altair_big_fe_unsharp.fits'): feunsharp = pyfits.getdata('altair_big_fe_unsharp.fits') fenormed = pyfits.getdata('altair_big_fe_normed.fits') else: #kernel = astropy.nddata.convolution.make_kernel.make_kernel([151,151],kernelwidth=50) #fesmooth = astropy.nddata.convolve(fe,kernel) fesmooth = agpy.smooth(mask_image(fe,downsample=4),250, fft_pad=False, interpolate_nan=True, psf_pad=False, ignore_edge_zeros=True, normalize_kernel=True, use_numpy_fft=True, nthreads=1, use_rfft=True, complextype=np.float32, silent=False, boundary='fill') feunsharp = fe for ii in xrange(4): for jj in xrange(4): shape = feunsharp[ii::4,jj::4].shape feunsharp[ii::4,jj::4] -= fesmooth[:shape[0],:shape[1]] fef[0].data = feunsharp fef.writeto("altair_big_fe_unsharp.fits",clobber=True) fenormed = fe for ii in xrange(4): for jj in xrange(4): shape = fenormed[ii::4,jj::4].shape fenormed[ii::4,jj::4] /= fesmooth[:shape[0],:shape[1]] fef[0].data = fenormed
cont_offset = (2.73*u.K).to(u.Jy,u.brightness_temperature(beam,14.488*u.GHz)) extra_cont_offset = 0.05 contlev = cont_offset.value + extra_cont_offset + noisefloor #spec2 = f2[0].data[0,350:600,:,:] + 0.03 spec2 = f2[0].data[190:293,:,:] + contlev + cont2 # try to "subtract out" the negative continuum... #spec2[:,cont2<0] -= cont2[cont2<0] dosmooth = False if dosmooth: spec2s = cube_regrid.spatial_smooth_cube(spec2,kernelwidth=1.5) cont2s = agpy.smooth(cont2+contlev,kernelwidth=1.5) else: spec2s = spec2 cont2s = cont2 spec2s[:,cont2s<0] -= cont2s[cont2s<0] #cont2s[cont2s<contlev]=contlev #cont2 += contlev #cont2[cont2<contlev+noisefloor]=contlev+noisefloor # "noise floor" (not really) #spec2[spec2<0.01] = 0.01 #tau2 = -np.log((spec2/cont2)) tau2 = -np.log((spec2s/cont2s)) tau2[np.isnan(tau2)] = 5
cube22.units = "K" cube44 = pyspeckit.Cube('hotclump_44.cube_r0.5_contsub.image.fits', maskmap=mask) cube44.cube *= (13.6 * (300.0 / (pyspeckit.spectrum.models.ammonia.freq_dict['fourfour']/1e9))**2 * 1./cube44.header.get('BMAJ')/3600. * 1./cube44.header.get('BMIN')/3600. ) cube44.units = "K" # Compute an error map. We use the 1-1 errors for all 3 because they're # essentially the same, but you could use a different error map for each # frequency errmap11 = (pyfits.getdata('hotclump_11.cube_r0.5_rerun.image.moment_linefree.fits').squeeze() * 13.6 * (300.0 / (pyspeckit.spectrum.models.ammonia.freq_dict['oneone']/1e9))**2 * 1./cube11.header.get('BMAJ')/3600. * 1./cube11.header.get('BMIN')/3600. ) errmap11[errmap11 != errmap11] = agpy.smooth(errmap11, interp_nan=True)[errmap11 != errmap11] # Stack the cubes into one big cube. The X-axis is no longer linear: there # will be jumps from 1-1 to 2-2 to 4-4. cubes = pyspeckit.CubeStack([cube11,cube22,cube44], maskmap=mask) cubes.units = "K" # Make a "moment map" to contain the initial guesses # If you've already fit the cube, just re-load the saved version # otherwise, re-fit it if os.path.exists('hot_momentcube.fits'): momentcubefile = pyfits.open('hot_momentcube.fits') momentcube = momentcubefile[0].data else: cube11.mapplot() # compute the moment at each pixel
from agpy import convolve, smooth from pylab import * test_image = zeros([512, 512]) # point test_image[204, 204] = 1 # box test_image[280:297, 280:297] = 1 / 256. shiftest_image = zeros([300, 320]) shiftest_image[100:120, 180:220] = 1.0 print "Testing for a shift" figure(11) clf() smoothed, kernel = smooth(shiftest_image, return_kernel=True) subplot(221) title("shiftest_image") imshow(shiftest_image) subplot(222) title("smoothed") imshow(smoothed) subplot(223) title("shiftest_image-smoothed") imshow(shiftest_image - smoothed) subplot(224) title("kernel") imshow(kernel) """ figure(0) clf()
from agpy import convolve, smooth from pylab import * test_image = zeros([512, 512]) # point test_image[204, 204] = 1 # box test_image[280:297, 280:297] = 1 / 256.0 shiftest_image = zeros([300, 320]) shiftest_image[100:120, 180:220] = 1.0 print "Testing for a shift" figure(11) clf() smoothed, kernel = smooth(shiftest_image, return_kernel=True) subplot(221) title("shiftest_image") imshow(shiftest_image) subplot(222) title("smoothed") imshow(smoothed) subplot(223) title("shiftest_image-smoothed") imshow(shiftest_image - smoothed) subplot(224) title("kernel") imshow(kernel) """
#tau2 = -np.log((spec2/cont2)) tau2 = -np.log((spec2s/cont2s)) tau2[np.isnan(tau2)] = 5 f2[0].header['CRPIX3'] -= 190 f2[0].data = tau2 f2.writeto('H2CO_22_Ku_BD_small_taucube_sm.fits',clobber=True) spec2s += contlev+0.05 #tau2 = -np.log((spec2/cont2)) tau2 = -np.log((spec2s/cont2s)) tau2[np.isnan(tau2)] = 5 f2[0].header['CRPIX3'] -= 190 f2[0].data = tau2 f2.writeto('H2CO_22_Ku_BD_small_taucube_sm.fits',clobber=True) get_ipython().magic(u'run -i ~/repos/w51evlareductionscripts/make_taucube_vla_ku_bd_22.py') cont2s = agpy.smooth(cont2+contlev,kernelwidth=2) tau2 = -np.log((spec2s/cont2s)) tau2[np.isnan(tau2)] = 5 f2[0].header['CRPIX3'] -= 190 f2[0].data = tau2 f2.writeto('H2CO_22_Ku_BD_small_taucube_sm.fits',clobber=True) get_ipython().magic(u'run -i ~/repos/w51evlareductionscripts/make_taucube_vla_ku_bd_22.py') get_ipython().magic(u'paste') yy,xx = np.indices(tau2.shape[1:]) rr = ((xx-255.)**2+(yy-255.)**2)**0.5 mask = rr < 200 nanmask = np.zeros_like(mask,dtype='float') nanmask[True-mask] = np.nan integ1 = tau2[11:48,:,:].sum(axis=0) f2[0].data = integ1 + nanmask