Example #1
0
from turbustat.statistics.psds import make_radial_freq_arrays

import astropy.io.fits as fits
import matplotlib.pyplot as plt
from mpl_toolkits.axes_grid1 import make_axes_locatable
import astropy.units as u

plt.rcParams['axes.unicode_minus'] = False

size = 512
slope = 3

test_img = fits.PrimaryHDU(
    make_extended(size,
                  powerlaw=slope,
                  ellip=0.4,
                  theta=(60 * u.deg).to(u.rad),
                  randomseed=345987))

# The power-law behaviour continues up to ~1/4 of the size
pspec = PowerSpectrum(test_img)
pspec.run(fit_2D=True,
          radial_pspec_kwargs={'binsize': 2.0},
          fit_kwargs={'weighted_fit': False},
          low_cut=1 / (15 * u.pix),
          verbose=False)

print("{0}+/-{1}".format(pspec.slope, pspec.slope_err))
print("{0}+/-{1}".format(pspec.slope2D, pspec.slope2D_err))
print("{0}+/-{1}".format(pspec.ellip2D, pspec.ellip2D_err))
print("{0}+/-{1}".format(pspec.theta2D, pspec.theta2D_err))
Example #2
0
col_pal = sb.color_palette()

plt.rcParams['axes.unicode_minus'] = False

size = 256

markers = ['D', 'o']

# Make a single figure example to save space in the paper.

fig = plt.figure(figsize=figsize)

slope = 3.0

test_img = fits.PrimaryHDU(make_extended(size, powerlaw=slope))
# The power-law behaviour continues up to ~1/4 of the size
delvar = DeltaVariance(test_img).run(xlow=3 * u.pix,
                                     xhigh=0.25 * size * u.pix,
                                     boundary='wrap')

plt.xscale("log")
plt.yscale("log")
plt.errorbar(delvar.lags.value,
             delvar.delta_var,
             yerr=delvar.delta_var_error,
             fmt=markers[0],
             label='TurbuStat')

# Now plot the IDL output
tab = Table.read("deltavar_{}.txt".format(slope), format='ascii')
image_sizes = [32, 64, 128, 256, 512, 1024, 2048]
samp_time = [1e-4, 1e-3, 1e-2, 1e-2, 1e-2, 1e-1, 1e-1]

twod_results = {}
for Stat in twod_stats:
    twod_results[Stat.__name__ + "_memory"] = []
    twod_results[Stat.__name__ + "_time"] = []

threed_results = {}
for Stat in threed_stats:
    threed_results[Stat.__name__ + "_memory"] = []
    threed_results[Stat.__name__ + "_time"] = []

for size, del_t in zip(image_sizes, samp_time):

    img = np.abs(make_extended(size))
    img_hdr = create_image_header(pixel_scale, beamfwhm, (size, size),
                                  restfreq, bunit)

    img_hdu = fits.PrimaryHDU(img, img_hdr)

    # Run 2D stats
    for Stat in twod_stats:

        kwargs = {}
        run_kwargs = {}

        # MVC has different inputs than the rest
        if Stat == MVC:
            inputs = [img_hdu] * 3
        elif Stat == Wavelet:
from turbustat.statistics import PowerSpectrum
from turbustat.simulator import make_extended
from turbustat.statistics.psds import make_radial_freq_arrays

import astropy.io.fits as fits
import matplotlib.pyplot as plt
from mpl_toolkits.axes_grid1 import make_axes_locatable
import astropy.units as u

plt.rcParams['axes.unicode_minus'] = False

size = 512
slope = 3

test_img = fits.PrimaryHDU(make_extended(size, powerlaw=slope,
                                         ellip=0.4,
                                         theta=(60 * u.deg).to(u.rad),
                                         randomseed=345987))

# The power-law behaviour continues up to ~1/4 of the size
pspec = PowerSpectrum(test_img)
pspec.run(fit_2D=True, radial_pspec_kwargs={'binsize': 2.0},
          fit_kwargs={'weighted_fit': False},
          low_cut=1 / (15 * u.pix),
          verbose=False)

print("{0}+/-{1}".format(pspec.slope, pspec.slope_err))
print("{0}+/-{1}".format(pspec.slope2D, pspec.slope2D_err))
print("{0}+/-{1}".format(pspec.ellip2D, pspec.ellip2D_err))
print("{0}+/-{1}".format(pspec.theta2D, pspec.theta2D_err))

# pspec.plot_fit(show_2D=True)
               np.abs(np.fft.rfft(data4[shape[0] // 2]))**2,
               label='Tukey')
    plt.legend(frameon=True)
    plt.xlabel("Freq. (1 / pix)")
    plt.ylabel("Power")
    plt.savefig(osjoin(fig_path, '1d_apods_pspec.png'))
    plt.close()

    # Example of 2D Tukey power-spectrum
    plt.imshow(np.log10(np.fft.fftshift(np.abs(np.fft.fft2(data4))**2)))
    plt.savefig(osjoin(fig_path, '2d_tukey_pspec.png'))
    plt.close()

    # This is easier to show with a red noise image due to the limited
    # inertial range in the sim data.
    rnoise_img = make_extended(256, powerlaw=3.)

    pixel_scale = 3 * u.arcsec
    beamfwhm = 3 * u.arcsec
    imshape = rnoise_img.shape
    restfreq = 1.4 * u.GHz
    bunit = u.K

    plaw_hdu = create_fits_hdu(rnoise_img, pixel_scale, beamfwhm, imshape,
                               restfreq, bunit)

    plt.imshow(plaw_hdu.data, cmap='viridis')
    plt.savefig(osjoin(fig_path, "rednoise_slope3_img.png"))
    plt.close()

    pspec = PowerSpectrum(plaw_hdu)
Example #6
0
    plt.loglog(freqs, np.abs(np.fft.rfft(data3[shape[0] // 2]))**2, label='Split Cosine')
    plt.loglog(freqs, np.abs(np.fft.rfft(data4[shape[0] // 2]))**2, label='Tukey')
    plt.legend(frameon=True)
    plt.xlabel("Freq. (1 / pix)")
    plt.ylabel("Power")
    plt.savefig(osjoin(fig_path, '1d_apods_pspec.png'))
    plt.close()

    # Example of 2D Tukey power-spectrum
    plt.imshow(np.log10(np.fft.fftshift(np.abs(np.fft.fft2(data4))**2)))
    plt.savefig(osjoin(fig_path, '2d_tukey_pspec.png'))
    plt.close()

    # This is easier to show with a red noise image due to the limited
    # inertial range in the sim data.
    rnoise_img = make_extended(256, powerlaw=3.)

    pixel_scale = 3 * u.arcsec
    beamfwhm = 3 * u.arcsec
    imshape = rnoise_img.shape
    restfreq = 1.4 * u.GHz
    bunit = u.K

    plaw_hdu = create_fits_hdu(rnoise_img, pixel_scale, beamfwhm, imshape,
                               restfreq, bunit)

    plt.imshow(plaw_hdu.data, cmap='viridis')
    plt.savefig(osjoin(fig_path, "rednoise_slope3_img.png"))
    plt.close()

    pspec = PowerSpectrum(plaw_hdu)
col_pal = sb.color_palette()

plt.rcParams['axes.unicode_minus'] = False

size = 256

markers = ['D', 'o']

# Make a single figure example to save space in the paper.

fig = plt.figure(figsize=figsize)

slope = 3.0

test_img = fits.PrimaryHDU(make_extended(size, powerlaw=slope))
# The power-law behaviour continues up to ~1/4 of the size
delvar = DeltaVariance(test_img).run(xlow=3 * u.pix,
                                     xhigh=0.25 * size * u.pix,
                                     boundary='wrap')

plt.xscale("log")
plt.yscale("log")
plt.errorbar(delvar.lags.value, delvar.delta_var,
             yerr=delvar.delta_var_error,
             fmt=markers[0], label='TurbuStat')

# Now plot the IDL output
tab = Table.read("deltavar_{}.txt".format(slope), format='ascii')
# First is pixel scale, second is delvar, then delvar error, and finally
# the fit values