analysis.galfun module

Multipurpose module that contains important functions ranging from managing parameters of generated galaxies to extracing information from relevant files.

class analysis.galfun.GParameters(project=None, id_params=None, omit={})[source]

Bases: object

Class that manages galaxies parameters obtained from galaxies.csv

This class reads a galaxies.csv file located in the specified project directory and extracts the parameters of each galaxy contained in it.

Args:
project(str): String point to the directory specified by the user. id_params(dict): See Attributes for details. Makes it possible to create a GParameters object without galaxies.csv file.
Attributes:
omit_fit(dict): Dictionary defined in containing
the parameters that should not be included in the analysis for a particular galaxy model but could be ecessary for drawing the galaxy.
id_params(dict): Dictionary whose keys are the ids of each of the
galaxies specified in galaxies.csv, and that map to another dictionary that can be taken in by getGalaxyModel()
params(dict): Dictionary that encodes the same information as
id_params but in a different form. Combines each of the dictionaries contained in id_params into a single dictionary that contains all parameters but in the form param_#.
fit_params(dict): Dictionary similar to the params attribute but
without the parameters specified in omit_fit.
nfit_params(dict): Dictionary that contains all the parameters not
contained in fit_params. Usually used for kwargs in conjunction with fit_params to draw Galaxies.
ordered_fit_names(list): A list containing the keys of fit_params
in a desirable order.

num_galaxies(int): Number of galaxies specified.

static convertId_Params(id_params, omit_fit={})[source]

Converts id_params to the format of params.

Parameters:
  • id_params (dict) – Same as id_params
  • omit_fit (dict) – Dictionary that has the same purpose as omit_fit
Returns:

A dictionary of params (dict).

static convertParams_Id(params)[source]

Convert a dictionary params in the format of params to a dictionary in the format id_params

getNFitParams()[source]

Extract nfit_params from params by noticing which parameters are in fit_params.

sortModelParamsNames()[source]

Return the keys of params in an ordered specified by the class parameters. And when having more than one galaxy, all the parameters from one of the galaxies are ordered together.

class analysis.galfun.ImageRenderer(pixel_scale=None, nx=None, ny=None, stamp=None, project=None, bounds=None, mask=None)[source]

Bases: object

Object used to produce the image of a galaxy.

Parameters:
  • pixel_scale (float) – Pixel_scale to use in the image (ratio of pixels to arcsecs)
  • nx (float) – Width of the image in pixels.
  • ny (float) – height of the image in pixels.
  • stamp (int) – optional, galsim.Image of appropiate dimensions to draw the image. does not actually use whatever was originally in the stamp.
  • bounds (tuple) – When drawn, the image will be clipped to these bounds.
  • mask (np.array) – the pixels selected in this mask will be set to 0.
One of the the following must be specified:
*stamp *nx,ny,pixel_scale

This object is made so it can be passsed in to a class analysis.fisher.Fisher object.

getImage(galaxy)[source]
analysis.galfun.addNoise(image, snr, noise_seed=0)[source]

Set gaussian noise to the given galsim.Image.

Parameters:
  • image (galsim.Image) – Galaxy image that noise is going to be added to.
  • snr (float) – Signal to noise ratio.
  • noise_seed (int) – Seed to set to galsim.BaseDeviate which will create the galsim.noise instance.
Returns:

A galsim.Image, variance_noise tuple. The image is the noisy version of the original image and variance_noise is the noise variance on each pixel due to the added noise.

analysis.galfun.getGalaxiesModels(fit_params=None, id_params=None, g_parameters=None, **kwargs)[source]

Return the model of a set of galaxies.

One of the the following must be specified:
fit_params (and nfit_params as **kwargs. Used specially in runfits.py). id_params g_parameters (from which id_params is extracted.)

This function generates each of the galaxies specified in id_params and then sums them together to get a final galaxy.

Parameters:
  • fit_params (dict) – Partial form of id_params that only includes the parameters to be used for the fit. For details, GParameters
  • id_params (dict) – Dictionary containing each of the galaxies parameters. For details, GParameters
  • g_parameters (GParameters) – An object containing different forms of the galaxy parameters.
  • image (bool) – If :bool:True returns an galsim.Image otherwise it
  • a np.array (returns) –
Returns:

A galsim.GSObject

analysis.galfun.getGalaxyModel(params)[source]

Return the image of a single galaxy optionally drawn with a psf.

Look at analysis.models to figure out which galaxy models and psf models are supported as well as their corresponding implemented parameters. You can even add your own galaxies if desired.

Parameters:
  • params (dict) – Dictionary containing the information of a single
  • where the keys is the name (galaxy) –
  • are the values of the parametes. (values) –
Returns:

A galsim.GSObject

analysis.galfun.getOmitFit(id_params, omit)[source]
analysis.galfun.read_results(project, g_parameters, fish, limit=None)[source]