pysersic.priors =============== .. py:module:: pysersic.priors Attributes ---------- .. autoapisummary:: pysersic.priors.base_sky_types pysersic.priors.base_sky_params pysersic.priors.base_profile_types pysersic.priors.base_profile_params Classes ------- .. autoapisummary:: pysersic.priors.BaseSkyPrior pysersic.priors.NoSkyPrior pysersic.priors.FlatSkyPrior pysersic.priors.TiltedPlaneSkyPrior pysersic.priors.BasePrior pysersic.priors.PySersicSourcePrior pysersic.priors.PySersicMultiPrior pysersic.priors.SourceProperties Functions --------- .. autoapisummary:: pysersic.priors.render_tilted_plane_sky pysersic.priors.update_prior_suffix pysersic.priors.estimate_sky pysersic.priors.autoprior Module Contents --------------- .. py:data:: base_sky_types :value: ['none', 'flat', 'tilted-plane'] .. py:data:: base_sky_params .. py:function:: render_tilted_plane_sky(X, Y, back, x_sl, y_sl) .. py:data:: base_profile_types :value: ['sersic', 'doublesersic', 'sersic_exp', 'sersic_pointsource', 'pointsource', 'exp', 'dev', 'spergel'] .. py:data:: base_profile_params .. py:class:: BaseSkyPrior(sky_guess: float, sky_guess_err: float, suffix: str = '') Bases: :py:obj:`equinox.Module` .. py:attribute:: type :type: eqx.AbstractClassVar() .. py:attribute:: repr_dict :type: dict .. py:attribute:: suffix :type: str .. py:attribute:: dist_dict :type: dict .. py:attribute:: reparam_dict :type: dict .. py:method:: sample(X: jax.numpy.array, Y: jax.numpy.array) :abstractmethod: .. py:method:: update_prior(name: str, mu: float, sigma: float) Update prior for a given parameter, assumed to be Gaussian with mu and sigma :param name: Name of parameter :type name: str :param mu: Location for prior :type mu: float :param sigma: width of prior :type sigma: float .. py:method:: __repr__() .. py:class:: NoSkyPrior(sky_guess: float, sky_guess_err: float, suffix: str = '') Bases: :py:obj:`BaseSkyPrior` .. py:attribute:: type :type: str :value: 'None' .. py:method:: sample(X, Y) .. py:class:: FlatSkyPrior(sky_guess: float, sky_guess_err: float, suffix: str = '') Bases: :py:obj:`BaseSkyPrior` .. py:attribute:: type :type: str :value: 'flat' .. py:method:: sample(X, Y) .. py:class:: TiltedPlaneSkyPrior(sky_guess: float, sky_guess_err: float, suffix: str = '') Bases: :py:obj:`BaseSkyPrior` .. py:attribute:: type :type: str :value: 'TiltedPlane' .. py:method:: sample(X, Y) .. py:class:: BasePrior(sky_type='none', sky_guess=None, sky_guess_err=None, suffix='') Bases: :py:obj:`equinox.Module` .. py:attribute:: sky_type :type: str .. py:attribute:: repr_dict :type: dict .. py:attribute:: suffix :type: str .. py:attribute:: dist_dict :type: dict .. py:attribute:: reparam_dict :type: dict .. py:attribute:: sky_prior :type: equinox.Module Base class for priors with sky sampling included .. py:property:: param_names .. py:method:: sample_sky(X: jax.numpy.array, Y: jax.numpy.array) -> float Sample sky parameters and return sky model :param X: 2D mesh grid of pixel x pixel indices :type X: jax.numpy.array :param Y: 2D mesh grid of pixel y pixel indices :type Y: jax.numpy.array :returns: sampled and rendered sky model :rtype: float .. py:method:: _set_dist(var_name: str, dist: BasePrior._set_dist.dist) -> None Set prior for a given variable :param var_name: variable name :type var_name: str :param dist: Numpyro distribution object specifying prior :type dist: dist.Distribution .. py:method:: _get_dist(var_name: str) -> numpyro.distributions.Distribution Get prior for a given variable :param var_name: variable name :type var_name: str :returns: Numpyro distribution clas describing prior :rtype: dist.Distribution .. py:method:: set_gaussian_prior(var_name: str, loc: float, scale: float) -> PySersicSourcePrior Set a Gaussian prior for a variable :param var_name: variable name :type var_name: str :param loc: mean :type loc: float :param scale: standard deviation :type scale: float :returns: returns self to allow chaining :rtype: PySersicSourcePrior .. py:method:: set_uniform_prior(var_name: str, low: float, high: float) -> PySersicSourcePrior Set a uniform prior for a variable :param var_name: variable name :type var_name: str :param low: lower bound :type low: float :param high: upper bound :type high: float :returns: returns self to allow chaining :rtype: PySersicSourcePrior .. py:method:: set_truncated_gaussian_prior(var_name: str, loc: float, scale: float, low: Optional[float] = None, high: Optional[float] = None) -> PySersicSourcePrior Set a truncated Gaussian prior for a given variable :param var_name: variable name :type var_name: str :param loc: mean :type loc: float :param scale: standard deviation :type scale: float :param low: lower bound, by default None :type low: Optional[float], optional :param high: upper bound, by default None :type high: Optional[float], optional :returns: Returns self to allow chaining :rtype: PySersicSourcePrior .. py:method:: set_custom_prior(var_name: str, prior_dist: numpyro.distributions.Distribution, reparam: Optional[numpyro.infer.reparam.Reparam] = None) -> PySersicSourcePrior Set a custom distribution as the prior for a given variable :param var_name: variable name :type var_name: str :param prior_dist: Numpyro Distribution object describing prior :type prior_dist: dist.Distribution :param reparam: Optional reparamaterization to use for variable, by default None :type reparam: Optional[infer.reparam.Reparam], optional :returns: Returns self to allow chaining :rtype: PySersicSourcePrior .. py:method:: __call__() -> jax.numpy.array Sample variables from prior :returns: sampled variables :rtype: jax.numpy.array .. py:class:: PySersicSourcePrior(profile_type: str, sky_type: Optional[str] = 'none', sky_guess: Optional[float] = None, sky_guess_err: Optional[float] = None, suffix: Optional[str] = '') Bases: :py:obj:`BasePrior` Class used for priors for single source fitting in PySersic .. py:attribute:: profile_type :type: str .. py:method:: __repr__() -> str .. py:method:: check_vars(verbose=False) -> bool Function to check if all variable for the specified profile type are set with no extras :param verbose: Wheter to print out missing and extra variables, by default False :type verbose: bool, optional :returns: True if all variable for given type are present with no extra, False otherwise :rtype: bool .. py:class:: PySersicMultiPrior(catalog: Union[pandas.DataFrame, dict, numpy.recarray], sky_type: Optional[str] = 'none', sky_guess: Optional[float] = None, sky_guess_err: Optional[float] = None, suffix: Optional[str] = '') Bases: :py:obj:`BasePrior` Class used for priors for multi source fitting in PySersic .. py:attribute:: catalog :type: dict .. py:attribute:: N_sources :type: int .. py:attribute:: suffix :value: '' .. py:method:: __repr__() -> str .. py:function:: update_prior_suffix(prior: BasePrior, new_suffix: str) -> BasePrior Change the suffix of a pysersic prior :param prior: Either a Source or Multi Prior, :type prior: BasePrior :param new_suffix: new suffix for variables :type new_suffix: str :returns: Prior with updated suffix :rtype: BasePrior .. py:class:: SourceProperties(image: Union[numpy.array, jax.numpy.array], mask: Union[numpy.array, jax.numpy.array] = None) A Class used to estimate initial guesses for source properties. If no guesses are provided, then the class will estimate them using the `photutls` package and the `data_properties()` function. .. py:method:: measure_properties(**kwargs) -> SourceProperties Measure default properties of the source :returns: returns self :rtype: SourceProperties .. py:method:: set_sky_guess(sky_guess: Optional[float] = None, sky_guess_err: Optional[float] = None, n_pix_sample: int = 5, **kwargs) -> SourceProperties Measure or set guess for initial sky background level. If no estimate is provided, the median of the n_pix_sample number of pixels around each edge is used :param sky_guess: Initial guess for level of background, by default None :type sky_guess: Optional[float], optional :param sky_guess_err: Uncertainity on inital guess, by default None :type sky_guess_err: Optional[float], optional :param n_pix_sample: Number of pixels around each edge to use to estimate sky level if neccesary, by default 5 :type n_pix_sample: int, optional :returns: returns self :rtype: SourceProperties .. py:method:: set_flux_guess(flux_guess: Optional[float] = None, flux_guess_err: Optional[float] = None, **kwargs) -> SourceProperties Measure or set guess for initial flux. If no estimate is provided, the flux of the source in estimated as the total flux within the sgmentatated region for the source :param flux_guess: Initial guess for flux, by default None :type flux_guess: Optional[float], optional :param flux_guess_err: Uncertainty on initial guess, by default None :type flux_guess_err: Optional[float], optional :returns: returns self :rtype: SourceProperties .. py:method:: set_r_eff_guess(r_eff_guess: Optional[float] = None, r_eff_guess_err: Optional[float] = None, **kwargs) -> SourceProperties Measure or set guess for effective radius. If no estimate is provided, the r_eff of the source in estimated using photutils :param r_eff_guess: Initial guess for effective radius, by default None :type r_eff_guess: Optional[float], optional :param r_eff_guess_err: Uncertainty on initial guess, by default None :type r_eff_guess_err: Optional[float], optional :returns: returns self :rtype: SourceProperties .. py:method:: set_theta_guess(theta_guess: Optional[float] = None, **kwargs) -> SourceProperties Measure or set guess for initial position angle. If no estimate is provided, the position angle of the source in estimated using the data_properties() function from photutils :param theta_guess: Estimate of the position angle in radians, by default None :type theta_guess: Optional[float], optional :returns: returns self :rtype: SourceProperties .. py:method:: set_position_guess(position_guess: Optional[Iterable[float, float]] = None, **kwargs) -> SourceProperties Measure or set guess for initial position. If no estimate is provided, the position of the source in estimated using the data_properties() function from photutils :param position_guess: A 2 element list, tuple or array which contain the x,y pixel values of the inital guess for the centroid, by default None :type position_guess: Optional[Iterable[float,float]], optional :returns: returns self :rtype: SourceProperties .. py:method:: generate_prior(profile_type: str, sky_type: Optional[str] = 'none', suffix: Optional[str] = '') -> PySersicSourcePrior Function to generate default priors based on a given image and profile type :param profile_type: Type of profile :type profile_type: str :param sky_type: Type of sky model to use, must be one of: 'none', 'flat', 'tilted-plane' :type sky_type: str, default 'none' :param suffix: Add suffix onto all source related variables, generally only used to number sources in MultiPrior :type suffix: str, default '' :returns: Pysersic prior object to be used to initialize FitSingle :rtype: PySersicSourcePrior .. py:method:: visualize(figsize: Tuple[float, float] = (6.0, 6.0), cmap: str = 'gray', scale: float = 1.0) -> None Display a figure summarizing the current guess for the source properties :param figsize: figure, by default (6.,6.) :type figsize: Tuple[float,float], optional :param cmap: color map, by default 'gray' :type cmap: str, optional :param scale: number of +/- std's at which to clip image, by default 1 :type scale: float, optional .. py:function:: estimate_sky(image: numpy.array, mask: Optional[numpy.array] = None, n_pix_sample: int = 5) -> Tuple[float, float, int] Estimate the sky background using the edge of the cutout :param im: image, either an array or masked array :type im: np.array :param mask: mask to apply, if im is not a masked array already, by default None :type mask: Optional[np.array], optional :param n_pix_sample: number of pixels around the edge to use, by default 5 :type n_pix_sample: int, optional :returns: a tuple containing the median, standard deviation and number of pixels used :rtype: Tuple[float,float,int] .. py:function:: autoprior(image: numpy.array, profile_type: str, mask: numpy.array = None, sky_type: str = 'none') -> PySersicSourcePrior Simple wrapper function to generate a prior using the built-in defaults. This can be used as a starting place but may not work for all sources :param image: science image :type image: np.array :param profile_type: Type of profile to be fit :type profile_type: str :param mask: pixel by pixel mask, by default None :type mask: np.array, optional :param sky_type: Type of sky to fit, default 'none' :type sky_type: str :returns: Prior object that can be used in initializing FitSingle :rtype: PySersicSourcePrior