def test_pspec(plotname="pspec_rnoise_beamsmooth_apodizetukey.pdf", size=256, powerlaw=3., run_kwargs={ 'verbose': False, 'apodize_kernel': 'tukey' }, plot_kwargs={'fit_color': 'black'}, beam_smooth=True, pixel_scale=2 * u.arcsec, bmin=8.09 * u.arcsec, bmaj=10.01 * u.arcsec, bpa=-12.9 * u.deg, restfreq=1.4 * u.GHz, bunit=u.K): from spectral_cube import Projection from radio_beam import Beam rnoise_img = make_extended(size, powerlaw) # Create a FITS HDU rnoise_hdu = create_fits_hdu(rnoise_img, 2 * u.arcsec, 2 * u.arcsec, rnoise_img.shape, 1.4 * u.GHz, u.K) pspec = PowerSpectrum(rnoise_hdu) if beam_smooth: pencil_beam = Beam(0 * u.deg) rnoise_proj = Projection.from_hdu(rnoise_hdu).with_beam(pencil_beam) new_beam = Beam(bmaj, bmin, bpa) rnoise_conv = rnoise_proj.convolve_to(new_beam) # hdr = fits.Header(header) # rnoise_hdu = fits.PrimaryHDU(rnoise_img, header=hdr) pspec = PowerSpectrum(rnoise_conv) pspec.run(**run_kwargs) pspec.plot_fit(save_name=plotname, **plot_kwargs) return pspec
apodize_kernel='splitcosinebell', alpha=0.3, beta=0.8) pspec5 = PowerSpectrum(plaw_hdu) pspec5.run(verbose=False, radial_pspec_kwargs={'binsize': 1.0}, fit_kwargs={'weighted_fit': False}, fit_2D=False, low_cut=1. / (60 * u.pix), apodize_kernel='tukey', alpha=0.3) # Overplot all of the to demonstrate affect on large-scales. pspec.plot_fit(color=col_pal[0], label='Original') pspec2.plot_fit(color=col_pal[1], label='Hanning') pspec3.plot_fit(color=col_pal[2], label='CosineBell') pspec4.plot_fit(color=col_pal[3], label='SplitCosineBell') pspec5.plot_fit(color=col_pal[4], label='Tukey') plt.legend(frameon=True, loc='lower left') plt.ylim([-2, 7.5]) plt.tight_layout() plt.savefig(osjoin(fig_path, "rednoise_pspec_slope3_apod_comparisons.png")) plt.close() print("Original: {0:.2f} \nHanning: {1:.2f} \nCosineBell: {2:.2f} \n" "SplitCosineBell: {3:.2f} \nTukey: {4:.2f}".format( pspec.slope, pspec2.slope, pspec3.slope, pspec4.slope, pspec5.slope))
distance=fitinfo_dict[gal]['distance']) pspec.compute_pspec(use_pyfftw=True, threads=ncores, apodize_kernel=fitinfo_dict[gal]['apod_kern']) # Divide out the normalized mask pspec # pspec._ps2D /= pspec_mask.ps2D pspec.compute_radial_pspec() # pspec.fit_pspec() # high_cut=0.1 / u.pix,) # pspec.run(verbose=False, beam_correct=False, fit_2D=False, # high_cut=0.1 / u.pix, # use_pyfftw=True, threads=ncores, # apodize_kernel=fitinfo_dict[gal]['apod_kern']) if make_interactive: print(pspec.slope) pspec.plot_fit(show_residual=False, show_2D=True) plt.draw() input(gal) plt.close() full_save_name = osjoin(data_path, gal, save_name) pspec.save_results(full_save_name, keep_data=False) if do_fitpspec: nsamp = 6000 row_names = [] fit_results = { 'logA': [],
pspec4 = PowerSpectrum(plaw_hdu) pspec4.run(verbose=False, radial_pspec_kwargs={'binsize': 1.0}, fit_kwargs={'weighted_fit': False}, fit_2D=False, low_cut=1. / (60 * u.pix), apodize_kernel='splitcosinebell', alpha=0.3, beta=0.8) pspec5 = PowerSpectrum(plaw_hdu) pspec5.run(verbose=False, radial_pspec_kwargs={'binsize': 1.0}, fit_kwargs={'weighted_fit': False}, fit_2D=False, low_cut=1. / (60 * u.pix), apodize_kernel='tukey', alpha=0.3) # Overplot all of the to demonstrate affect on large-scales. pspec.plot_fit(color=col_pal[0], label='Original') pspec2.plot_fit(color=col_pal[1], label='Hanning') pspec3.plot_fit(color=col_pal[2], label='CosineBell') pspec4.plot_fit(color=col_pal[3], label='SplitCosineBell') pspec5.plot_fit(color=col_pal[4], label='Tukey') plt.legend(frameon=True, loc='lower left') plt.ylim([-2, 7.5]) plt.tight_layout() plt.savefig(osjoin(fig_path, "rednoise_pspec_slope3_apod_comparisons.png")) plt.close() print("Original: {0:.2f} \nHanning: {1:.2f} \nCosineBell: {2:.2f} \n" "SplitCosineBell: {3:.2f} \nTukey: {4:.2f}" .format(pspec.slope, pspec2.slope, pspec3.slope, pspec4.slope, pspec5.slope))