pysersic.results ================ .. py:module:: pysersic.results Attributes ---------- .. autoapisummary:: pysersic.results.ArrayLike pysersic.results.ListLike Classes ------- .. autoapisummary:: pysersic.results.PySersicResults Functions --------- .. autoapisummary:: pysersic.results.parse_multi_results pysersic.results.get_bounds pysersic.results.plot_image pysersic.results.plot_residual Module Contents --------------- .. py:data:: ArrayLike .. py:data:: ListLike .. py:class:: PySersicResults(data: ArrayLike, rms: ArrayLike, psf: ArrayLike, loss_func: Callable, renderer: pysersic.rendering.BaseRenderer, mask: Optional[ArrayLike] = None) .. py:attribute:: data .. py:attribute:: rms .. py:attribute:: psf .. py:attribute:: mask :value: None .. py:attribute:: loss_func .. py:attribute:: renderer .. py:method:: __repr__() -> str .. py:method:: add_method_used(method) .. py:method:: add_prior(prior) add the prior object to the result object once created :param prior: created prior object :type prior: pysersic.priors.BasePrior .. py:method:: injest_data(sampler: Optional[numpyro.infer.mcmc.MCMC] = None, svi_res_dict: Optional[dict] = None, purge_extra: Optional[bool] = True, num_sample: Optional[int] = 1000, rkey: Optional[jax.random.PRNGKey] = 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. :param sampler: numpyro sampler containing results :type sampler: Optional[numpyro.infer.mcmc.MCMC], optional :param svi_res_dict: Dictionary containing 'guide', 'model' and 'svi_result' specifying a trained SVI model :type svi_res_dict: Optional[dict], optional :param purge_extra: Whether to purge variables containing 'auto', 'base' or 'unwrapped' often used in reparamaterization, by default True :type purge_extra: Optional[bool], optional :param num_sample: Number of samples to draw from trained SVI posterior, no effect if sampling was used. :type num_sample: Optional[int] :param rkey: PRNG key to use, by default jax.random.PRNGKey(5) :type rkey: Optional[jax.random.PRNGKey], optional :returns: ArviZ Summary of results :rtype: pandas.DataFrame :raises AssertionError: Must supply one of sampler or svi_dict .. py:method:: _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). :param data: _description_ :type data: arviz.InferenceData :param purge_extra: whether to purge extra params not part of the fitting, by default True :type purge_extra: bool, optional :param save_model: Whether to set self.models with model images from posterior :type save_model: bool :returns: the cleaned up object :rtype: arviz.InferenceData .. py:method:: summary() -> pandas.DataFrame Convenience function for returning the summary dataframe using the arviz summary. :returns: data frame containing the arviz summary of the fit. :rtype: pandas.DataFrame .. py:method:: get_median_model() .. py:method:: corner(quantiles=[0.16, 0.5, 0.84], **kwargs) Return a corner plot of the parameter estimation :param quantiles: which quantiles to mark on the corner plot, can pass None, by default [0.16,0.5,0.84] :type quantiles: ListLike, optional :param \*\*kwargs: any additional arguments to pass to corner (for the single plot case). :returns: fig object containing the corner plots :rtype: matplotlib.figure .. py:method:: retrieve_param_quantiles(quantiles: ListLike = [0.16, 0.5, 0.84], return_dataframe: bool = False) -> Union[pandas.DataFrame, dict] retrieve quantiles on the parameter estimation :param quantiles: array of quantiles to pull, must be between 0 and 1, by default [0.16,0.5,0.84] :type quantiles: ListLike, optional :param return_dataframe: whether to return dataframe instead of simple dict, by default False :type return_dataframe: bool, optional :returns: dict or dataframe with index/keys as parameters and columns/values as the chosen quantiles. :rtype: Union[pd.DataFrame,dict] .. py:method:: retrieve_med_std(return_dataframe: bool = False) -> Union[pandas.DataFrame, dict] .. py:method:: latex_table(quantiles: ListLike = [0.16, 0.5, 0.84]) Generate a simple AASTex deluxetable with the fit parameters. Prints the result. :param quantiles: 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] :type quantiles: ListLike, optional :raises AssertionError: if the quantile list does not have three values .. py:method:: get_chains() -> xarray.Dataset Wrapper for az.extract, producing the chains/draws for the run :returns: chain object :rtype: xarray.Dataset .. py:method:: 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 :param parameter: a legal parameter from the fit. Use e.g. `results.svi_summary()` to see them. :type parameter: str :param func: any function which reads in array-like data and computes something :type func: Callable :returns: the computed statistic(s) :rtype: ArrayLike .. py:method:: 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. :param fname: filename to save to. :type fname: str .. py:method:: sample_posterior(num_sample: int, purge_extra: Optional[bool] = True, rkey: Optional[jax.random.PRNGKey] = random.PRNGKey(7)) -> arviz.InferenceData Generate extra samples from an trained SVI posterior :param num_sample: number of samples to draw :type num_sample: int :param purge_extra: Whether to purge variables containing 'auto', 'base' or 'unwrapped' often used in reparamaterization, by default True :type purge_extra: Optional[bool], optional :param rkey: PRNG key to use, by default jax.random.PRNGKey(7) :type rkey: Optional[jax.random.PRNGKey], optional :returns: arviz InferenceData object containing posterior :rtype: az.InferenceData .. py:function:: 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` :param results: Results class from a FitMulti instance :type results: PySersicResults :param source_num: Source number to isolate or if equal to -1 will reset to the joint posterior of all sources :type source_num: int :returns: Results class with all the meta-data the same but the specified source isolated. The original posterior is saved under `.idata_all` :rtype: PySersicResults .. py:function:: get_bounds(im: numpy.array, scale: float) -> Tuple[float, float] Generate bounds based on image mean and standard deviation :param im: images :type im: np.array :param scale: Number of +/- sigmas for bounds :type scale: float :returns: Bounds to use :rtype: Tuple[float,float] .. py:function:: 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 :param image: Image to plot :type image: np.array :param mask: Mask :type mask: np.array :param sig: sigma or noise map :type sig: np.array :param psf: Point spread function :type psf: np.array :param cmap: Color map to use, by default 'gray_r' :type cmap: str, optional :param scale: Number of +/- std's of image to make the bounds, by default 2.0 :type scale: float, optional :param size: Size of figure, will be size*3 x size, by default 8. :type size: float, optional :returns: Figure and axes objects :rtype: Tuple[plt.Figure,plt.Axes] .. py:function:: 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 :param image: Original image :type image: np.array :param model: Best fit model image :type model: np.array :param mask: Pixel by Pixel mask, by default None :type mask: np.array, optional :param scale: Number of +/- std's to make the bounds of the image, by default 2.0 :type scale: float, optional :param cmap: color map to use, by default 'gray_r' :type cmap: str, optional :param colorbar: Whether or not to show a color bar, by default True :type colorbar: bool, optional :returns: Figure and axes objects :rtype: Tuple[plt.Figure,plt.Axes]