pysersic.galfit

Classes

FitMulti

Class used to fit multiple sources within a single image

FitSingle

Class used to fit a single source

Functions

gaussian_loss(→ float)

Basic Gaussian loss function using given uncertainties

search_start(→ list)

Search a list of strings and match those which start with to_match

load_fits_from_galfit_line(→ jax.numpy.array)

Load fits file from galfit config line

match_line_and_load_galfit(→ jax.numpy.array)

Combine the above two functions to search and load fits files from a galfit config

generate_fitter_from_galfit_config(...)

Function to generate a Fitter instance from a galfit config file. This function is only meant to be a starting place to easily try PySersic on the many galfit config files we know you all have lying around. As such this does not follow all of the rules and constraints the galfit takes into account. For more fine grained control we recommend initializing a pysersic Fitter instance yourself, please see the examples/ folder or the documentation for some help with this.

Module Contents

class pysersic.galfit.FitMulti(data: jax.typing.ArrayLike, rms: jax.typing.ArrayLike, psf: jax.typing.ArrayLike, prior: pysersic.priors.PySersicMultiPrior, mask: jax.typing.ArrayLike | None = None, loss_func: Callable | None = gaussian_loss, renderer: pysersic.rendering.BaseRenderer | None = HybridRenderer, renderer_kwargs: dict | None = {})

Bases: BaseFitter

Class used to fit multiple sources within a single image

build_model(return_model: bool = True) Callable

Generate Numpyro model for the specified image, profile and priors

Returns:

model – Function specifying the current model in Numpyro, can be passed to inference algorithms

Return type:

Callable

find_MAP(return_model: bool | None = True, rkey: jax.random.PRNGKey | None = jax.random.PRNGKey(3), purge_extra: bool | None = True)

Find the “best-fit” parameters as the maximum a-posteriori and return a dictionary with values for the parameters.

Parameters:
  • return_model (Optional[bool], optional) – whether to return the model image, adds a small time and memory overhead, by default True

  • rkey (Optional[jax.random.PRNGKey], optional) – rng key, by default jax.random.PRNGKey(3)

Returns:

dictionary with fit parameters and their values.

Return type:

dict

class pysersic.galfit.FitSingle(data: jax.typing.ArrayLike, rms: jax.typing.ArrayLike, psf: jax.typing.ArrayLike, prior: pysersic.priors.PySersicSourcePrior, mask: jax.typing.ArrayLike | None = None, loss_func: Callable | None = gaussian_loss, renderer: pysersic.rendering.BaseRenderer | None = HybridRenderer, renderer_kwargs: dict | None = {})

Bases: BaseFitter

Class used to fit a single source

build_model(return_model: bool = True) Callable

Generate Numpyro model for the specified image, profile and priors

Returns:

model – Function specifying the current model in Numpyro, can be passed to inference algorithms

Return type:

Callable

pysersic.galfit.gaussian_loss(mod: jax.numpy.array, data: jax.numpy.array, rms: jax.numpy.array, mask: jax.numpy.array, suffix: str = '') float

Basic Gaussian loss function using given uncertainties

Parameters:
  • mod (jnp.array) – Model image

  • data (jnp.array) – data to be fit

  • rms (jnp.array) – per pixel 1-sigma uncertainties

Returns:

Sampled loss function

Return type:

float

pysersic.galfit.search_start(list_of_strings: Iterable, to_match: str) list

Search a list of strings and match those which start with to_match

Parameters:
  • list_of_strings (Iterable)

  • to_match (str) – pattern to match

Returns:

List of results contianing the index and full string

Return type:

list

pysersic.galfit.load_fits_from_galfit_line(line: str) jax.numpy.array

Load fits file from galfit config line

Parameters:

line (str)

Returns:

Image in first HDU

Return type:

jnp.array

pysersic.galfit.match_line_and_load_galfit(list_of_strings: Iterable, to_match: str, assert_message: str = '') jax.numpy.array

Combine the above two functions to search and load fits files from a galfit config

Parameters:
  • list_of_strings (Iterable)

  • to_match (str)

  • assert_message (str, optional) – Message to raise if line file is not present

Returns:

_description_

Return type:

jnp.array

Raises:

UserWarning – _description_

pysersic.galfit.generate_fitter_from_galfit_config(config_loc: str, loss: callable = gaussian_loss) pysersic.FitSingle | pysersic.FitMulti

Function to generate a Fitter instance from a galfit config file. This function is only meant to be a starting place to easily try PySersic on the many galfit config files we know you all have lying around. As such this does not follow all of the rules and constraints the galfit takes into account. For more fine grained control we recommend initializing a pysersic Fitter instance yourself, please see the examples/ folder or the documentation for some help with this.

Parameters:
  • config_loc (str) – Config file locations

  • loss (callable, optional) – Loss function to use, see loss.py for more details, by default gaussian_loss

Returns:

Fitter based on config file. If there is only one source then returns a FitSingle object, otherwise returns a fit_multi

Return type:

Union[FitSingle,FitMulti]