VCA

class turbustat.statistics.VCA(cube, header=None, distance=None, beam=None, channel_width=None, downsample_kwargs={})[source]

Bases: BaseStatisticMixIn, StatisticBase_PSpec2D

The VCA technique (Lazarian & Pogosyan, 2004).

Parameters:
cubenumpy.ndarray or astropy.io.fits.PrimaryHDU or astropy.io.fits.ImageHDU or SpectralCube

Data cube.

headerFITS header, optional

Corresponding FITS header.

distanceQuantity, optional

Physical distance to the region in the data.

beamradio_beam.Beam, optional

Beam object for correcting for the effect of a finite beam.

channel_widthQuantity or int, optional

Set the width of channels to compute the VCA with. The channel width in the data is used by default. Given widths will be used to spectrally down-sample the data before calculating the VCA. Given an integer value, the spectral axis will be downsampled by the given number of spectral channels. Up-sampling to smaller channel sizes than the original is not supported.

downsample_kwargsdict, optional

Passed to spectral_regrid_cube.

Attributes Summary

brk

Fitted break point.

brk_err

1-sigma on the break point.

data

distance

ellip2D

Fitted ellipticity of the 2D power spectrum.

ellip2D_err

Ellipticity standard error of the 2D power spectrum.

freqs

Corresponding spatial frequencies of the 1D power spectrum.

header

need_header_flag

no_data_flag

ps1D

One-dimensional power spectrum.

ps1D_stddev

1-sigma standard deviation of the 1D power spectrum.

ps2D

Two-dimensional power spectrum.

slope

Power spectrum slope(s).

slope2D

Fitted slope of the 2D power spectrum.

slope2D_err

Slope standard error of the 2D power spectrum.

slope_err

1-sigma error on the power spectrum slope(s).

theta2D

Fitted position angle of the 2D power spectrum.

theta2D_err

Position angle standard error of the 2D power spectrum.

wavenumbers

Methods Summary

apodizing_kernel([kernel_type, alpha, beta])

Return an apodizing kernel to be applied to the image before taking Fourier transform

compute_beam_pspec()

Compute the power spectrum of the beam element.

compute_pspec([beam_correct, ...])

Compute the 2D power spectrum.

compute_radial_pspec([logspacing, max_bin])

Computes the radially averaged power spectrum.

fit_2Dpspec([fit_method, p0, low_cut, ...])

Model the 2D power-spectrum surface with an elliptical power-law model.

fit_pspec([brk, log_break, low_cut, ...])

Fit the 1D Power spectrum using a segmented linear model.

input_data_header(data, header[, need_copy])

Check if the header is given separately from the data type.

load_beam([beam])

Try loading the beam from the header or a given object.

load_results(pickle_file)

Load in a saved pickle file.

plot_fit([show_2D, show_residual, color, ...])

Plot the fitted model.

run([verbose, beam_correct, apodize_kernel, ...])

Full computation of VCA.

save_results(output_name[, keep_data])

Save the results of the SCF to avoid re-computing.

Attributes Documentation

brk

Fitted break point.

brk_err

1-sigma on the break point.

data
distance
ellip2D

Fitted ellipticity of the 2D power spectrum.

ellip2D_err

Ellipticity standard error of the 2D power spectrum.

freqs

Corresponding spatial frequencies of the 1D power spectrum.

header
need_header_flag = True
no_data_flag = False
ps1D

One-dimensional power spectrum.

ps1D_stddev

1-sigma standard deviation of the 1D power spectrum.

ps2D

Two-dimensional power spectrum.

slope

Power spectrum slope(s).

slope2D

Fitted slope of the 2D power spectrum.

slope2D_err

Slope standard error of the 2D power spectrum.

slope_err

1-sigma error on the power spectrum slope(s).

theta2D

Fitted position angle of the 2D power spectrum.

theta2D_err

Position angle standard error of the 2D power spectrum.

wavenumbers

Methods Documentation

apodizing_kernel(kernel_type='tukey', alpha=0.1, beta=0.0)

Return an apodizing kernel to be applied to the image before taking Fourier transform

Returns:
windowndarray

Apodizing kernel

compute_beam_pspec()

Compute the power spectrum of the beam element.

compute_pspec(beam_correct=False, apodize_kernel=None, alpha=0.3, beta=0.0, use_pyfftw=False, threads=1, **pyfftw_kwargs)[source]

Compute the 2D power spectrum.

Parameters:
beam_correctbool, optional

If a beam object was given, divide the 2D FFT by the beam response.

apodize_kernelNone or ‘splitcosinebell’, ‘hanning’, ‘tukey’, ‘cosinebell’, ‘tophat’

If None, no apodization kernel is applied. Otherwise, the type of apodizing kernel is given.

alphafloat, optional

alpha shape parameter of the apodization kernel. See apodizing_kernel for more information.

betafloat, optional

beta shape parameter of the apodization kernel. See apodizing_kernel for more information.

use_pyfftwbool, optional

Enable to use pyfftw, if it is installed.

threadsint, optional

Number of threads to use in FFT when using pyfftw.

pyfftw_kwargsPassed to

rfft_to_fft. See here for a list of accepted kwargs.

compute_radial_pspec(logspacing=False, max_bin=None, **kwargs)

Computes the radially averaged power spectrum.

Parameters:
logspacingbool, optional

Return logarithmically spaced bins for the lags.

max_binfloat, optional

Maximum spatial frequency to bin values at.

kwargspassed to pspec.
fit_2Dpspec(fit_method='LevMarq', p0=(), low_cut=None, high_cut=None, bootstrap=True, niters=100, use_azimmask=False, radial_weighting=False, fix_ellip_params=False)

Model the 2D power-spectrum surface with an elliptical power-law model.

Parameters:
fit_methodstr, optional

The algorithm fitting to use. Only ‘LevMarq’ is currently available.

p0tuple, optional

Initial parameters for fitting. If no values are given, the initial parameters start from the 1D fit parameters.

low_cutQuantity, optional

Lowest frequency to consider in the fit.

high_cutQuantity, optional

Highest frequency to consider in the fit.

bootstrapbool, optional

Bootstrap using the model residuals to estimate the parameter standard errors. This tends to give more realistic intervals than the covariance matrix.

nitersint, optional

Number of bootstrap iterations.

use_azimmaskbool, optional

Use the azimuthal mask defined for the 1D spectrum, when azimuthal limit have been given.

radial_weightingbool, optional

To account for the increasing number of samples at greater radii, the fit can be weighted by \(1/\mathrm{radius}\) to emphasize the points at small radii. DO NOT enabled weighting when the field is elliptical! This will bias the fit parameters! Default is False.

fix_ellip_paramsbool, optional

If the field is expected to be isotropic, the ellipticity and theta parameters can be fixed in the fit. This will help the fit since the isotropic case sits at the edge of the ellipticity parameter space and can be difficult to correctly converge to.

fit_pspec(brk=None, log_break=False, low_cut=None, high_cut=None, min_fits_pts=10, weighted_fit=False, bootstrap=False, bootstrap_kwargs={}, verbose=False)

Fit the 1D Power spectrum using a segmented linear model. Note that the current implementation allows for only 1 break point in the model. If the break point is estimated via a spline, the breaks are tested, starting from the largest, until the model finds a good fit.

Parameters:
brkfloat or None, optional

Guesses for the break points. If given as a list, the length of the list sets the number of break points to be fit. If a choice is outside of the allowed range from the data, Lm_Seg will raise an error. If None, a spline is used to estimate the breaks.

log_breakbool, optional

Sets whether the provided break estimates are log-ed (base 10) values. This is disabled by default. When enabled, the brk must be a unitless Quantity (u.dimensionless_unscaled).

low_cutQuantity, optional

Lowest frequency to consider in the fit.

high_cutQuantity, optional

Highest frequency to consider in the fit.

min_fits_ptsint, optional

Sets the minimum number of points needed to fit. If not met, the break found is rejected.

weighted_fitbool, optional

Fit using weighted least-squares. The weights are the inverse-squared standard deviations in each radial bin.

bootstrapbool, optional

Bootstrap using the model residuals to estimate the parameter standard errors. This tends to give more realistic intervals than the covariance matrix.

bootstrap_kwargsdict, optional

Pass keyword arguments to residual_bootstrap.

verbosebool, optional

Enables verbose mode in Lm_Seg.

input_data_header(data, header, need_copy=False)

Check if the header is given separately from the data type.

load_beam(beam=None)

Try loading the beam from the header or a given object.

Parameters:
beamBeam, optional

The beam.

static load_results(pickle_file)

Load in a saved pickle file.

Parameters:
pickle_filestr

Name of filename to load in.

Returns:
selfSave statistic class

Statistic instance with saved results.

Examples

Load saved results. >>> stat = Statistic.load_results(“stat_saved.pkl”) # doctest: +SKIP

plot_fit(show_2D=False, show_residual=True, color='r', fit_color='k', label=None, fillin_errs=True, symbol='o', xunit=Unit('1 / pix'), save_name=None, use_wavenumber=False)

Plot the fitted model.

Parameters:
show_2Dbool, optional

Plot the 2D power spectrum with contours for the masked regions and 2D fit contours (if the 2D power spectrum was fit).

show_residualbool, optional

Plot the residuals for the 1D power-spectrum fit.

colorstr, optional

Color to use in the plotted points.

fit_colorstr, optional

Color to show the fitted relation in. Defaults to color when no color is given.

labelstr, optional

Apply a label to the 1D plot. Useful for overplotting multiple power-spectra.

fillin_errsbool, optional

Show the range of the standard deviation with as a transparent filled in region. When disabled, the standard deviations are shown as error bars.

symbolstr, optional

Plot symbols for the 1D power spectrum.

xunitastropy.units.Unit, optional

Units for the x-axis. If a header is given, xunit can be given in inverse angular units. And if a distance is given, an inverse physical unit can also be passed.

save_namestr, optional

File name for the plot to be saved. Enables saving when a string is given.

use_wavenumberbool, optional

Convert spatial frequencies to a wavenumber.

run(verbose=False, beam_correct=False, apodize_kernel=None, alpha=0.2, beta=0.0, use_pyfftw=False, threads=1, pyfftw_kwargs={}, radial_pspec_kwargs={}, low_cut=None, high_cut=None, fit_2D=True, fit_kwargs={}, fit_2D_kwargs={}, save_name=None, xunit=Unit('1 / pix'), use_wavenumber=False)[source]

Full computation of VCA.

Parameters:
verbosebool, optional

Enables plotting.

beam_correctbool, optional

If a beam object was given, divide the 2D FFT by the beam response.

apodize_kernelNone or ‘splitcosinebell’, ‘hanning’, ‘tukey’, ‘cosinebell’, ‘tophat’

If None, no apodization kernel is applied. Otherwise, the type of apodizing kernel is given.

alphafloat, optional

alpha shape parameter of the apodization kernel. See apodizing_kernel for more information.

betafloat, optional

beta shape parameter of the apodization kernel. See apodizing_kernel for more information.

use_pyfftwbool, optional

Enable to use pyfftw, if it is installed.

threadsint, optional

Number of threads to use in FFT when using pyfftw.

pyfft_kwargsPassed to

rfft_to_fft. See here for a list of accepted kwargs.

radial_pspec_kwargsdict, optional

Passed to compute_radial_pspec.

low_cutQuantity, optional

Low frequency cut off in frequencies used in the fitting.

high_cutQuantity, optional

High frequency cut off in frequencies used in the fitting.

fit_2Dbool, optional

Fit an elliptical power-law model to the 2D power spectrum.

fit_kwargsdict, optional

Passed to fit_pspec.

fit_2D_kwargsdict, optional

Keyword arguments for fit_2Dpspec. Use the low_cut and high_cut keywords to provide fit limits.

save_namestr,optional

Save the figure when a file name is given.

xunitu.Unit, optional

Choose the unit to convert the x-axis in the plot to.

use_wavenumberbool, optional

Plot the x-axis as the wavenumber rather than spatial frequency.

fit_kwargsPassed to fit_pspec.
save_results(output_name, keep_data=False)

Save the results of the SCF to avoid re-computing. The pickled file will not include the data cube by default.

Parameters:
output_namestr

Name of the outputted pickle file.

keep_databool, optional

Save the data cube in the pickle file when enabled.