pysersic.results
Attributes
Classes
Functions
|
Function written to parse results from a FitMulti instance to isolate a single source. A new PySersicResults class is created with only the posteriors of the specified source. The original chains saved under .idata_all |
|
Generate bounds based on image mean and standard deviation |
|
Plot a summary figure with the image, sigma map and psf side by side |
|
Generate a summary plot comparing the data to the best fit model |
Module Contents
- pysersic.results.ArrayLike
- pysersic.results.ListLike
- class pysersic.results.PySersicResults(data: ArrayLike, rms: ArrayLike, psf: ArrayLike, loss_func: Callable, renderer: pysersic.rendering.BaseRenderer, mask: ArrayLike | None = None)
- data
- rms
- psf
- mask = None
- loss_func
- renderer
- __repr__() str
- add_method_used(method)
- add_prior(prior)
add the prior object to the result object once created
- Parameters:
prior (pysersic.priors.BasePrior) – created prior object
- injest_data(sampler: numpyro.infer.mcmc.MCMC | None = None, svi_res_dict: dict | None = None, purge_extra: bool | None = True, num_sample: int | None = 1000, rkey: jax.random.PRNGKey | None = random.PRNGKey(5)) pandas.DataFrame
Method to injest data from optimized SVI model or results of sampling. When sampling data is input, sets the class attribute sampling_results, while for an SVI run, saves svi_results. A PysersicResults object can have at most data for one SVI and one sampling run. Both class atttributes are instances of arviz.InferenceData objects.
- Parameters:
sampler (Optional[numpyro.infer.mcmc.MCMC], optional) – numpyro sampler containing results
svi_res_dict (Optional[dict], optional) – Dictionary containing ‘guide’, ‘model’ and ‘svi_result’ specifying a trained SVI model
purge_extra (Optional[bool], optional) – Whether to purge variables containing ‘auto’, ‘base’ or ‘unwrapped’ often used in reparamaterization, by default True
num_sample (Optional[int]) – Number of samples to draw from trained SVI posterior, no effect if sampling was used.
rkey (Optional[jax.random.PRNGKey], optional) – PRNG key to use, by default jax.random.PRNGKey(5)
- Returns:
ArviZ Summary of results
- Return type:
pandas.DataFrame
- Raises:
AssertionError – Must supply one of sampler or svi_dict
- _parse_injested_data(data: arviz.InferenceData, purge_extra: bool = True, save_model: bool = True) arviz.InferenceData
Helper function to postprocess the poterior object (internal use).
- Parameters:
data (arviz.InferenceData) – _description_
purge_extra (bool, optional) – whether to purge extra params not part of the fitting, by default True
save_model (bool) – Whether to set self.models with model images from posterior
- Returns:
the cleaned up object
- Return type:
arviz.InferenceData
- summary() pandas.DataFrame
Convenience function for returning the summary dataframe using the arviz summary.
- Returns:
data frame containing the arviz summary of the fit.
- Return type:
pandas.DataFrame
- get_median_model()
- corner(quantiles=[0.16, 0.5, 0.84], **kwargs)
Return a corner plot of the parameter estimation
- Parameters:
quantiles (ListLike, optional) – which quantiles to mark on the corner plot, can pass None, by default [0.16,0.5,0.84]
**kwargs – any additional arguments to pass to corner (for the single plot case).
- Returns:
fig object containing the corner plots
- Return type:
matplotlib.figure
- retrieve_param_quantiles(quantiles: ListLike = [0.16, 0.5, 0.84], return_dataframe: bool = False) pandas.DataFrame | dict
retrieve quantiles on the parameter estimation
- Parameters:
quantiles (ListLike, optional) – array of quantiles to pull, must be between 0 and 1, by default [0.16,0.5,0.84]
return_dataframe (bool, optional) – whether to return dataframe instead of simple dict, by default False
- Returns:
dict or dataframe with index/keys as parameters and columns/values as the chosen quantiles.
- Return type:
Union[pd.DataFrame,dict]
- retrieve_med_std(return_dataframe: bool = False) pandas.DataFrame | dict
- latex_table(quantiles: ListLike = [0.16, 0.5, 0.84])
Generate a simple AASTex deluxetable with the fit parameters. Prints the result.
- Parameters:
quantiles (ListLike, optional) – quantiles to use must be len 3 as we do upper-median and median-lower to get +/- values, by default [0.16,0.5,0.84]
- Raises:
AssertionError – if the quantile list does not have three values
- get_chains() xarray.Dataset
Wrapper for az.extract, producing the chains/draws for the run
- Returns:
chain object
- Return type:
xarray.Dataset
- compute_statistic(parameter: str, func: Callable) ArrayLike
Compute an arbitrary array statistic on the chain for a given parameter. For example, the std of all ellipticity draws. or the mean of the sersic draws
- Parameters:
parameter (str) – a legal parameter from the fit. Use e.g. results.svi_summary() to see them.
func (Callable) – any function which reads in array-like data and computes something
- Returns:
the computed statistic(s)
- Return type:
ArrayLike
- save_result(fname: str)
Save summary of the fit, copies of the data, the chains, and some other info about priors and renderers into an asdf file for later retrieval.
- Parameters:
fname (str) – filename to save to.
- sample_posterior(num_sample: int, purge_extra: bool | None = True, rkey: jax.random.PRNGKey | None = random.PRNGKey(7)) arviz.InferenceData
Generate extra samples from an trained SVI posterior
- Parameters:
num_sample (int) – number of samples to draw
purge_extra (Optional[bool], optional) – Whether to purge variables containing ‘auto’, ‘base’ or ‘unwrapped’ often used in reparamaterization, by default True
rkey (Optional[jax.random.PRNGKey], optional) – PRNG key to use, by default jax.random.PRNGKey(7)
- Returns:
arviz InferenceData object containing posterior
- Return type:
az.InferenceData
- pysersic.results.parse_multi_results(results: PySersicResults, source_num: int) PySersicResults
Function written to parse results from a FitMulti instance to isolate a single source. A new PySersicResults class is created with only the posteriors of the specified source. The original chains saved under .idata_all
- Parameters:
results (PySersicResults) – Results class from a FitMulti instance
source_num (int) – Source number to isolate or if equal to -1 will reset to the joint posterior of all sources
- Returns:
Results class with all the meta-data the same but the specified source isolated. The original posterior is saved under .idata_all
- Return type:
- pysersic.results.get_bounds(im: numpy.array, scale: float) Tuple[float, float]
Generate bounds based on image mean and standard deviation
- Parameters:
im (np.array) – images
scale (float) – Number of +/- sigmas for bounds
- Returns:
Bounds to use
- Return type:
Tuple[float,float]
- pysersic.results.plot_image(image: numpy.array, mask: numpy.array, sig: numpy.array, psf: numpy.array, cmap: str = 'gray_r', scale: float = 2.0, size: float = 8.0) Tuple[matplotlib.pyplot.Figure, matplotlib.pyplot.Axes]
Plot a summary figure with the image, sigma map and psf side by side
- Parameters:
image (np.array) – Image to plot
mask (np.array) – Mask
sig (np.array) – sigma or noise map
psf (np.array) – Point spread function
cmap (str, optional) – Color map to use, by default ‘gray_r’
scale (float, optional) – Number of +/- std’s of image to make the bounds, by default 2.0
size (float, optional) – Size of figure, will be size*3 x size, by default 8.
- Returns:
Figure and axes objects
- Return type:
Tuple[plt.Figure,plt.Axes]
- pysersic.results.plot_residual(image: numpy.array, model: numpy.array, mask: numpy.array = None, scale: float = 2.0, cmap: str = 'gray_r', colorbar: bool = True, **resid_plot_kwargs) Tuple[matplotlib.pyplot.Figure, matplotlib.pyplot.Axes]
Generate a summary plot comparing the data to the best fit model
- Parameters:
image (np.array) – Original image
model (np.array) – Best fit model image
mask (np.array, optional) – Pixel by Pixel mask, by default None
scale (float, optional) – Number of +/- std’s to make the bounds of the image, by default 2.0
cmap (str, optional) – color map to use, by default ‘gray_r’
colorbar (bool, optional) – Whether or not to show a color bar, by default True
- Returns:
Figure and axes objects
- Return type:
Tuple[plt.Figure,plt.Axes]