PDF¶
- class turbustat.statistics.PDF(img, min_val=-inf, bins=None, weights=None, normalization_type=None)[source]¶
Bases:
BaseStatisticMixIn
Create the PDF of a given array.
- Parameters:
- imgnumpy.ndarray or astropy.io.fits.PrimaryHDU or astropy.io.fits.ImageHDU or spectral_cube.Projection or spectral_cube.Slice or SpectralCube
A 1-3D array.
- min_valfloat, optional
Minimum value to keep in the given image.
- binslist or numpy.ndarray or int, optional
Bins to compute the PDF from.
- weightsnumpy.ndarray or astropy.io.fits.PrimaryHDU or astropy.io.fits.ImageHDU or spectral_cube.Projection or spectral_cube.Slice or SpectralCube, optional
Weights to apply to the image. Must have the same shape as the image.
- normalization_type{“standardize”, “center”, “normalize”, “normalize_by_mean”}, optional
See
data_normalization
.
Examples
>>> from turbustat.statistics import PDF >>> from astropy.io import fits >>> moment0 = fits.open("Design4_21_0_0_flatrho_0021_13co.moment0.fits")[0] >>> pdf_mom0 = PDF(moment0).run(verbose=True)
Attributes Summary
Bin centers.
ECDF values in
bins
.Parameters of the fitted model.
Standard errors of the fitted model.
PDF values in
bins
.Methods Summary
corner_plot
(**kwargs)Create a corner plot from the MCMC.
find_at_percentile
(percentiles)Return the values at the given percentiles.
find_percentile
(values)Return the percentiles of given values from the data distribution.
fit_pdf
([model, verbose, fit_type, floc, ...])Fit a model to the PDF.
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.
Create the ECDF.
make_pdf
([bins])Create the PDF.
plot_distrib
([save_name, color, fit_color, ...])Plot the PDF distribution and (if fitted) the best fit model.
run
([verbose, save_name, bins, do_fit, ...])Compute the PDF and ECDF.
save_results
(output_name[, keep_data])Save the results of the SCF to avoid re-computing.
trace_plot
(**kwargs)Create a trace plot from the MCMC.
Attributes Documentation
- bins¶
Bin centers.
- data¶
- distance¶
- header¶
- model_params¶
Parameters of the fitted model.
- model_stderrs¶
Standard errors of the fitted model. If using an MCMC, the 15th and 85th percentiles are returned.
- need_header_flag = True¶
- no_data_flag = False¶
- normalization_type¶
Methods Documentation
- corner_plot(**kwargs)[source]¶
Create a corner plot from the MCMC. Requires the ‘corner’ package.
- Parameters:
- kwargsPassed to
corner
.
- kwargsPassed to
- find_at_percentile(percentiles)[source]¶
Return the values at the given percentiles.
- Parameters:
- percentilesfloat or np.ndarray
Percentile or array of percentiles. Must be between 0 and 100.
- find_percentile(values)[source]¶
Return the percentiles of given values from the data distribution.
- Parameters:
- valuesfloat or np.ndarray
Value or array of values.
- fit_pdf(model=<scipy.stats._continuous_distns.lognorm_gen object>, verbose=False, fit_type='mle', floc=True, loc=0.0, fscale=False, scale=1.0, **kwargs)[source]¶
Fit a model to the PDF. Use statsmodel’s generalized likelihood setup to get uncertainty estimates and such.
- Parameters:
- modelscipy.stats distribution, optional
Pass any scipy distribution. NOTE: All fits assume
loc
can be fixed to 0. This is reasonable for all realistic PDF forms in the ISM.- verbosebool, optional
Enable printing of the fit results.
- fit_type{‘mle’, ‘mcmc’}, optional
- Type of fitting to use. By default Maximum Likelihood Estimation
(‘mle’) is used. An MCMC approach (‘mcmc’) may also be used. This requires the optional
emcee
to be installed. kwargs can be passed to adjust various properties of the MCMC chain.
- flocbool, optional
Fix the
loc
parameter when fitting.- locfloat, optional
Value to set
loc
to when fixed.- fscalebool, optional
Fix the
scale
parameter when fitting.- scalefloat, optional
Value to set
scale
to when fixed.- kwargsPassed to
EnsembleSampler
.
- 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:
- beam
Beam
, optional The beam.
- 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
- make_pdf(bins=None)[source]¶
Create the PDF.
- Parameters:
- binslist or numpy.ndarray or int, optional
Bins to compute the PDF from. Overrides initial bin input.
- plot_distrib(save_name=None, color='r', fit_color='k', show_ecdf=True)[source]¶
Plot the PDF distribution and (if fitted) the best fit model. Optionally show the ECDF and fit ECDF, too.
- Parameters:
- save_namestr,optional
Save the figure when a file name is given.
- color{str, RGB tuple}, optional
Color to show the Genus curves in.
- fit_color{str, RGB tuple}, optional
Color of the fitted line. Defaults to
color
when no input is given.- show_ecdfbool, optional
Plot the ECDF when enabled.
- run(verbose=False, save_name=None, bins=None, do_fit=True, model=<scipy.stats._continuous_distns.lognorm_gen object>, color=None, **kwargs)[source]¶
Compute the PDF and ECDF. Enabling verbose provides a summary plot.
- Parameters:
- verbosebool, optional
Enables plotting of the results.
- save_namestr,optional
Save the figure when a file name is given.
- binslist or numpy.ndarray or int, optional
Bins to compute the PDF from. Overrides initial bin input.
- do_fitbool, optional
Enables (by default) fitting a given model.
- modelscipy.stats distribution, optional
Pass any scipy distribution. See
fit_pdf
.- color{str, RGB tuple}, optional
Color to show the Genus curves in when
verbose=True
.- kwargsPassed to
fit_pdf
.
- 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.