galfitools.galin package

Submodules

galfitools.galin.MakeMask module

galfitools.galin.MakeMask.CatArSort(SexCat, scale, SexArSort, NCol, NRow)[source]

Sorts the SExtractor catalog by area, from largest to smallest.

Parameters:
  • SexCat (str, name of the SExtractor catalog)

  • scale (float,)

  • SexArSort (new output SExtractor catalog)

  • NCol (number of columns of the image)

  • NRow (number of rows of the image)

Return type:

number of objects

galfitools.galin.MakeMask.CheckFlag(val, check, maxx=128)[source]

Check if SExtractor flag contains the check flag

This function is useful to check if a object sextractor flag contains saturated region

Parameters:
  • val (SExtractor flag of the object)

  • check (SExtractor flag value to check)

  • maxx (maximum value of the flag. Default = 128)

Returns:

  • bool, returns True if found

  • # repeated

galfitools.galin.MakeMask.CheckSatReg(x, y, filein, R, theta, ell)[source]

Check if object is inside of saturated region.

Parameters:
  • (x (int, int, center's coordinates in pixels)

  • y) (int, int, center's coordinates in pixels)

  • filein (str, file containing the saturated regions)

  • R (float, major axis)

  • theta (float, angular position of the ellipse)

  • ell (float, ellipticity of the object)

Returns:

bool

Return type:

it returns True if at least one pixel is inside

galfitools.galin.MakeMask.GetSizev1(x, y, R, theta, ell, ncol, nrow)[source]

This function retrieves the minimum and maximum pixel coordinates that enclose the ellipse.

Parameters:
  • x (int, int, position of the ellipse's center)

  • y (int, int, position of the ellipse's center)

  • R (float, ellipse major axis)

  • theta (float, angular position of the ellipse measured from X-axis)

  • ell (float, ellipticity of the ellipse)

  • ncol (number of columns of the image)

  • nrow (number of rows of the image)

Returns:

xmin, xmax, ymin, ymax – box delimitation of the ellipse

Return type:

int, int, int, int

galfitools.galin.MakeMask.MakeKron(imagemat, idn, x, y, R, theta, ell, xmin, xmax, ymin, ymax)[source]

This creates a ellipse in an image

This function creates an ellipse and fills the pixels inside it with the value specified by idn. The ellipse is created within a box delimited by xmin, xmax, ymin, and ymax.

Parameters:
  • imagemat (ndarray, the image matrix)

  • idn (int the value to fill the ellipse)

  • x (position of the ellipse's center)

  • y (position of the ellipse's center)

  • R (ellipse major axis)

  • theta (angular position of the ellipse measured from X-axis)

  • ell (ellipticity of the ellipse)

  • xmin (int, int, int, int) – box delimitation of the ellipse

  • xmax (int, int, int, int) – box delimitation of the ellipse

  • ymin (int, int, int, int) – box delimitation of the ellipse

  • ymax (int, int, int, int) – box delimitation of the ellipse

Returns:

imagemat

Return type:

the image with the new ellipse

galfitools.galin.MakeMask.MakeMask(maskimage, catfile, scale, offset, regfile)[source]

Creates ellipse masks for every object of the SExtractor catalog

Parameters:
  • maskimage (str) – name of the mask file. This file should already exists

  • catfile (str,) – SExtractor catalog

  • scale (float,) – Scale factor by which the ellipse will be enlarged or diminished.

  • offset (float) – constant to be added to the ellipse size

  • regfile (str) – DS9 region file containing the saturated region.

Return type:

None

galfitools.galin.MakeMask.MakeSatBox(maskimage, region, val, ncol, nrow)[source]

Creates saturated regions in the mask

Parameters:
  • maskimage (str, name of the mask file)

  • region (str, DS9 box region)

  • val (int, value to be filled inside the saturated region)

  • ncol (int, number of columns of the image)

  • nrow (int, number of rows of the image)

Return type:

bool

galfitools.galin.MakeMask.ds9satbox(satfileout, sexcat, satscale, satoffset)[source]
Creates a DS9 file which contains regions with bad

saturated regions

Parameters:
  • satfileout (str, DS9 region output file)

  • sexcat (str, SExtractor catalog)

  • satscale (float,) – Scale factor by which the saturation region will be enlarged or diminished.

  • satoffset (float,) – constant to be added to the size of saturated region

Return type:

None

galfitools.galin.MakeMask.makeMask(sexfile: str, image: str, maskfile: str, scale: float, satfileout: str) None[source]

Creates a mask file from a catalog of SExtractor

It creates a mask file for GALFIT using information from a SExtractor catalog. It includes masking of saturated regions.

Parameters:
  • sexfile (str) – name of the Sextractor catalog

  • image (str,) – name of the image file

  • maskfile (str,) – name of the mask file

  • scale (float,) – Scale factor by which the ellipse will be enlarged or diminished.

  • satfileout (str) – DS9 region file where the saturation regions will be indicated

Return type:

None

galfitools.galin.MakePSF module

galfitools.galin.MakePSF.makeDS9ellip(out, X, Y, rad, AxRat, theta)[source]

makes DS9 region

It creates an ellipse DS9 region

Parameters:
  • out (str) – name of the DS9 output file

  • X (float, float) – X, Y position of the center of PSF

  • Y (float, float) – X, Y position of the center of PSF

  • rad (float) – radius of the axis major of ellipse

  • AxRat (float) – Axis ratio

  • theta (float) – angular position of the ellipse

Return type:

0

galfitools.galin.MakePSF.makePSF(image: str, regfile: str, center: bool, psfout: str, sigma: str, imsize: int, sky: float, twist: bool, numgauss: int, fracrad=0.95) None[source]

makes PSF model

It creates a PSF model image model for GALFIT. It model a star from an image using the MGE method

Parameters:
  • image (str) – name of the FITS image

  • regfile (str) – DS9 ellipse region file containing the star.

  • center (bool) – If True, the geometrical center of the DS9 ellipse region will be used. Otherwise, the center with the maximum count level of the DS9 ellipse region will be used.

  • psfout (str) – name of the PSF output file

  • sigma (str) – If available, the sigma image, otherwise set to None

  • imsize (int) – size of the PSF image

  • sky (float) – value of sky background

  • twist (bool) – If true use the twist option for the MGE method

  • numgauss (int) – maximum number of gaussians to be used.

Return type:

None

galfitools.galin.MaskDs9 module

galfitools.galin.MaskDs9.MakeBox(Image, fill, xpos, ypos, rx, ry, angle, pixval, ncol, nrow, skymean=None, skystd=None, invert=False)[source]

Make a box in an image

Parameters:
  • Image (ndarray) – the image matrix array

  • fill (float) – value to be filled inside the DS9 region

  • xpos (float, float) – coordinates of the center

  • ypos (float, float) – coordinates of the center

  • rx (float) – x-longitude of the box

  • ry (float) – y-longitude of the box

  • angle (float) – angular position of the box

  • pixval (int) – mask only the pixels with this value

  • ncol (int, int) – size of the image

  • nrow (int, int) – size of the image

  • skymean (float) – mean of the sky background

  • skystd (float) – standard deviation of sky

  • invert (bool) – inverts the region of DS9

Returns:

Image – the image with the box region

Return type:

ndarray

galfitools.galin.MaskDs9.MakeEllip(Image, fill, xpos, ypos, rx, ry, angle, pixval, ncol, nrow, skymean=None, skystd=None, invert=False)[source]

Draw an ellipse in an image

Parameters:
  • Image (ndarray) – the image matrix array

  • fill (float) – value to be filled inside the DS9 region

  • xpos (float, float) – coordinates of the center

  • ypos (float, float) – coordinates of the center

  • rx (float) – major axis or minor axis of the ellipse

  • ry (float) – minor axis or major axis of the ellipse

  • angle (float) – angular position of the ellipse

  • pixval (int) – mask only the pixels with this value

ncol, nrowint, int

size of the image

skymeanfloat

mean of the sky background

skystdfloat

standard deviation of sky

invert: bool

inverts the mask region

Returns:

Image – the image with the ellipse

Return type:

ndarray

galfitools.galin.MaskDs9.MakeKronv2(imagemat, idn, x, y, R, theta, ell, xmin, xmax, ymin, ymax, pixval, ncol, nrow, skymean=None, skystd=None, invert=False)[source]

This creates a ellipse in an image

This function creates an ellipse and fills the pixels inside it with the value specified by idn. The ellipse is created within a box delimited by xmin, xmax, ymin, and ymax.

Parameters:
  • imagemat (ndarray, the image matrix)

  • idn (int the value to fill the ellipse)

  • x (position of the ellipse's center)

  • y (position of the ellipse's center)

  • R (ellipse major axis)

  • theta (angular position of the ellipse measured from X-axis)

  • ell (ellipticity of the ellipse)

  • xmin (int, int, int, int) – box delimitation of the ellipse

  • xmax (int, int, int, int) – box delimitation of the ellipse

  • ymin (int, int, int, int) – box delimitation of the ellipse

  • ymax (int, int, int, int) – box delimitation of the ellipse

Returns:

  • imagemat (the image with the new ellipse)

  • # repeated

galfitools.galin.MaskDs9.MakePolygon(Image, fill, tupVerts, pixval, ncol, nrow, skymean=None, skystd=None, invert=False)[source]

Make a polygon in an image

Parameters:
  • Image (ndarray) – the image matrix array

  • fill (float) – value to be filled inside the DS9 region

  • tupVerts (tuple) – vertices of the polygon

  • pixval (int) – mask only the pixels with this value

  • ncol (int, int) – size of the image

  • nrow (int, int) – size of the image

  • skymean (float) – mean of the sky background

  • skystd (float) – standard deviation of sky

  • invert (bool) – Changes the pixels outside of the DS9 region

Returns:

Image – the new image with the polygon

Return type:

ndarray

galfitools.galin.MaskDs9.maskDs9(MaskFile: str, RegFile: str, fill: float, image=None, bor_flag=False, borValue=0, pixval=None, skymean=None, skystd=None, invert=False) None[source]

Creates masks from DS9 regions

given DS9 regions such as box, ellipse or polygon it creates those regions as masks in a mask image for GALFIT. If the mask image does not exists, it creates one.

It also removes unwanted regions in the original image such as saturated regions by providing mean and standard deviation of sky.

Parameters:
  • MaskFile (str) – name of the mask image file

  • RegFile (str) – name of the file containing the DS9 regions

  • fill (float) – value to fill withing DS9 regions

  • image (str) – new of the image file to take the size of the matrix to create a new mask file if it does not exists.

  • bor_flag (False, optional) – if True, it will mask the border of the image. This is for those region where the image matrix is larger than the data matrix, e.g. Hubble images

  • borValue (int) – value of the border

  • pixval (int) – mask only the pixels with this value

  • skymean (None, optional) – mean of the sky value to be substituted inside of the DS9 region

  • skystd (None, optional) – standard deviation of the sky value to be substituted inside of the DS9 region

  • invert (bool, optional) – if True it changes the pixels outside of the DS9 Region

Return type:

None

galfitools.galin.MaskSky module

galfitools.galin.MaskSky.maskSky(imageFile, mean, sig, nsig, output='mask.fits', bor_flag=False, borValue=0)[source]

Creates a mask image for GALFIT by subtracting the sky background.

Parameters:
  • imageFile (str) – FITS image where the data will be taken

  • mean (float) – mean of the sky background

  • sig (float) – standard deviation of sky

  • nsig (float) – number of sky standard deviations to be removed from image

  • output (str) – output name of the new mask image

  • bor_flag (False, optional) – if True, it will mask the border of the image. This is for those region where the image matrix is larger than the data matrix, e.g. Hubble images

  • borValue (float) – value of the border in the image

Return type:

None

galfitools.galin.checkGalFile module

class galfitools.galin.checkGalFile.HeadInfo[source]

Bases: object

Data class to store information of the GALFIT Header

This Data class verifies that the variables in the GALFIT header contain valid values. It uses boolean flags to indicate whether the file exists and whether the sizes of the convolution box or fitting region are appropriate.

P = 0
constraints = 'none'
constraintsflag = False
convx = 1
convxflag = False
convy = 1
convyflag = False
display = 'regular'
inputimage = 'none.fits'
inputimageflag = False
maskimage = 'none'
maskimageflag = False
mgzpt = 25
outimage = 'none-out.fits'
outimageflag = False
psfimage = 'none'
psfimageflag = False
psfsamp = 1
scale = 1
scaley = 1
sigimage = 'none'
sigimageflag = False
xmax = 1
xmin = 0
xsizeflag = False
ymax = 1
ymin = 0
ysizeflag = False
galfitools.galin.checkGalFile.checkFile(galfitFile: str, dis: int) float[source]

checks that GALFIT file contains valid parameters

Parameters:
  • galfitFile (str) – name of the GALFIT file

  • dis (int) – maximum distance among components

Returns:

  • headinfo (HeadInfo data class defined above)

  • galax (number of components per galaxy model)

  • mag (total magnitude)

  • freepar (total number of free parameters for the fitting)

galfitools.galin.checkGalFile.copy2info(head, head2)[source]

copy header information

copy header variables from head to head2

Parameters:
  • head (GalHead data class defined in galfit.py)

  • head2 (Galhead data class where the variables will be copied)

Returns:

head2

Return type:

GalHead data class

galfitools.galin.exp2edge module

galfitools.galin.exp2edge.Exp2Edge(galfitFile: str, fileout: str, numexp: int) GalComps[source]

Convert a Exponential function to EdgeDisk function.

It converts a exponential function (or Sersic with n = 1) to a edgedisk function

Parameters:
  • galfitFile (str) – name of the GALFIT file

  • fileout (str) – name of the GALFIT output file

  • numexp (int) – component number (position in input file) of the exponential function

Returns:

galcomps – data class defined in galfitools.galin.galfit

Return type:

GalComps

See also

conver2Sersic

converts gaussian, exponential de Vaucoulers to Sersic models

conver2Ferrer

convert gaussian bar to a Ferrer bar

galfitools.galin.galfit module

class galfitools.galin.galfit.DataImg[source]

Bases: object

Data class to store the galaxy, model and residual images of the output file of GALFIT

imchi = array([[1, 1],        [1, 1]])
img = array([[1, 1],        [1, 1]])
impsf = array([[1, 1],        [1, 1]])
imres = array([[1, 1],        [1, 1]])
imsnr = array([[1, 1],        [1, 1]])
mask = array([[1, 1],        [1, 1]])
model = array([[1, 1],        [1, 1]])
sigma = array([[1, 1],        [1, 1]])
class galfitools.galin.galfit.GalComps(N: array = <factory>, skip: array = <factory>, PosXFree: array = <factory>, PosYFree: array = <factory>, MagFree: array = <factory>, RadFree: array = <factory>, ExpFree: array = <factory>, Exp2Free: array = <factory>, Exp3Free: array = <factory>, AxRatFree: array = <factory>, PosAngFree: array = <factory>)[source]

Bases: object

Data class to store the galfit components of the galfit file

AbsMag = array([], dtype=float64)
Active = array([], dtype=float64)
AxRat = array([], dtype=float64)
AxRatFree: array
Exp = array([], dtype=float64)
Exp2 = array([], dtype=float64)
Exp2Free: array
Exp3 = array([], dtype=float64)
Exp3Free: array
ExpFree: array
Flux = array([], dtype=float64)
KronRad = array([], dtype=float64)
Lum = array([], dtype=float64)
Mag = array([], dtype=float64)
MagFree: array
N: array
NameComp = array([], dtype=float64)
PerLight = array([], dtype=float64)
PetRad = array([], dtype=float64)
PosAng = array([], dtype=float64)
PosAngFree: array
PosX = array([], dtype=float64)
PosXFree: array
PosY = array([], dtype=float64)
PosYFree: array
Rad = array([], dtype=float64)
Rad50 = array([], dtype=float64)
Rad50kpc = array([], dtype=float64)
Rad50sec = array([], dtype=float64)
Rad90 = array([], dtype=float64)
RadFree: array
SerInd = array([], dtype=float64)
kser = array([], dtype=float64)
me = array([], dtype=float64)
mme = array([], dtype=float64)
skip: array
class galfitools.galin.galfit.GalHead[source]

Bases: object

Data class to store the header info of the galfit file

P = 0
constraints = 'none'
convx = 1
convy = 1
display = 'regular'
exptime = 1
flagidx = False
flagnum = False
imgidx = 'sci'
inputimage = 'none.fits'
maskimage = 'none'
mgzpt = 25.0
num = 1
outimage = 'none-out.fits'
psfimage = 'none'
psfsamp = 1
scale = 1.0
scaley = 1.0
sigimage = 'none'
stampmask = 'stampmask.fits'
xmax = 1
xmin = 0
ymax = 1
ymin = 0
class galfitools.galin.galfit.GalSky[source]

Bases: object

Data class to store the sky component of the GALFIT file

dskyx = 0
dskyxfree = 0
dskyy = 0
dskyyfree = 0
skip = 0
sky = 0
skyfree = 1
class galfitools.galin.galfit.Galfit(File: str)[source]

Bases: object

Class to read GALFIT parameters file

File

name of the GALFIT file

Type:

str

ReadHead : GalHead

reads the header of the GALFIT file

ReadComps : GalComps

reads the galfit components of the GALFIT file

ReadSky : GalSky

reads the galfit sky components of the GALFIT file

ReadComps() GalComps[source]
ReadHead() GalHead[source]
ReadSky() GalSky[source]
galfitools.galin.galfit.GetRadAng(R: float, q: list, pa: list, theta: float) float[source]

Obtains the radius along the specified angular direction.

Given the angular position and axis ratio of the ellipse it gives the radius of the ellipse in the theta direction.

If theta is in the major axis direction it returns the major axis. On the other hand, if theta is in the direction of the minor axis it returns the minor axis.

Parameters:
  • R (float) – Radius along the major axis

  • q (list) – Axis ratio of ellipse

  • pa (list) – Angular position of ellipse measured from Y-axis (same as GALFIT)

  • theta (float) – angle that defines the direction

Returns:

aell – radius along the angle specified by theta

Return type:

float

galfitools.galin.galfit.SelectComp(galcomps: GalComps, n_comp: int) GalComps[source]

Selects only a component for galcomps.

From the data class GalComps, it changes the flag Active to True for one components indicated in n_comp.

useful for selecting for one component

Parameters:
  • galcomps (GalComps data class defined above)

  • n_comp (int) – the component to select to be active

Returns:

galcomps – one component selected by n_comp.

Return type:

GalComps data class with flag Active = True for

galfitools.galin.galfit.SelectGal(galcomps: GalComps, distmax: float, n_comp: int) GalComps[source]

Selects which components belong to the galaxy.

From the data class GalComps, it changes the flag Active to True for those components where distance is less than distmax from component n_comp.

This is useful when there are simultaneous fitting of galaxies in a single GALFIT file.

Parameters:
  • galcomps (GalComps data class defined above)

  • distmax (float) – maximum distance among components

  • n_comp (int) – The center of the galaxy will be determined from this component (n_comp). The distances of the remaining components will be calculated relative to this center.

Returns:

galcomps – those components which belong to the galaxy selected by n_comp.

Return type:

GalComps data class with flag Active = True for

Notes

If a galaxy is made up of three components, it does not matter which of the three you select as a center. As long these belong to the same galaxy (and center).

galfitools.galin.galfit.conver2Edge(galcomps: GalComps, scale, N) GalComps[source]

Converts the expdisk to edgedisk

Using the format of GALFIT with the GalComps data class, it converts the parameters of the functions Sersic n = 1 , to parameters of edgedisk function.

Parameters:
  • galcomps (GalComps data class defined above)

  • scale (Plate Scale ''/pixel)

  • N (number of component to be converted)

Returns:

galcomps – parameters

Return type:

GalComps data class with the functions converted to Ferrer

galfitools.galin.galfit.conver2Ferrer(galcomps: GalComps, scale, N) GalComps[source]

Converts the Sersic to Ferrer

Using the format of GALFIT with the GalComps data class, it converts the parameters of the functions Sersic n = 0.5, to parameters of Ferrer function.

Parameters:
  • galcomps (GalComps data class defined above)

  • scale (Plate Scale ''/pixel)

  • N (number of component to be converted)

Returns:

galcomps – parameters

Return type:

GalComps data class with the functions converted to Ferrer

galfitools.galin.galfit.conver2Sersic(galcomps: GalComps) GalComps[source]

Converts the exponential, gaussian or De Vaucouleurs to Sersic

Using the format of GALFIT with the GalComps data class, it converts the parameters of the functions exponential, gaussian or De Vaucouleurs to parameters of Sersic function.

Parameters:

galcomps (GalComps data class defined above)

Returns:

galcomps – parameters

Return type:

GalComps data class with the functions converted to Sersic

galfitools.galin.galfit.expdisk_to_edgedisk(mag_total: float, rs_pix: float, axis_ratio: float, pa_deg: float, pixscale: float) Dict[str, float][source]

Convert approximate GALFIT expdisk parameters into initial edgedisk parameters.

This conversion is based on two assumptions:

  1. The radial scale length is preserved: rs_edge = rs_exp

  2. The vertical scale height is approximated from the exponential disk axis ratio: hs ~= q * rs

The central surface brightness of the edge-on disk is then estimated by conserving the total flux:

mu0 = mag_total + 2.5 * log10(2 * pi * rs * hs * pixscale^2)

where: - rs and hs are in pixels - pixscale is in arcsec/pixel - mu0 is returned in mag/arcsec^2

Parameters:
  • mag_total (float) – Total magnitude of the expdisk model.

  • rs_pix (float) – Exponential scale length in pixels.

  • axis_ratio (float) – Axis ratio b/a of the expdisk model.

  • pa_deg (float) – Position angle in degrees.

  • pixscale (float) – Pixel scale in arcsec/pixel.

Returns:

Dictionary with approximate edgedisk parameters: - mu0_mag_arcsec2 : central surface brightness [mag/arcsec^2] - hs_pix : disk scale height [pixels] - rs_pix : disk scale length [pixels] - pa_deg : position angle [degrees]

Return type:

Dict[str, float]

Raises:

ValueError – If any input value is not physically valid.

Notes

This is an approximation for initial guesses only. It is most useful when the galaxy is close to edge-on. For moderately inclined systems, the relation hs ~= q * rs is only a rough estimate.

galfitools.galin.galfit.galPrintComp(hdl: str, ncomp: int, idx: int, galcomps: GalComps) bool[source]

prints GALFIT component parameters to a file

Given a file handler, prints the GALFIT component parameters of one model the surface brightness models to a GALFIT file

Parameters:
  • hdl (str) – file handler where the component parameter information will be print

  • ncomp (int) – prints the number of component in the GALFIT file

  • idx (int) – index to indicate which component of the galcomps data class will be print

  • galcomps (GalComps data class defined above)

Return type:

bool

galfitools.galin.galfit.galPrintHeader(hdl: str, galhead: GalHead) bool[source]

prints GALFIT header to a file

Given a file handler, prints the GALFIT header parameters of to a file

Parameters:
  • hdl (str) – file handler where the header information will be print

  • galhead (GalHead data class defined above)

Return type:

bool

galfitools.galin.galfit.galPrintSky(hdl: str, ncomp: int, galsky: GalSky) bool[source]

prints GALFIT sky component parameters to a file

Given a file handler, prints the GALFIT sky component parameters to a GALFIT file

Parameters:
  • hdl (str) – file handler where the sky component parameter information will be print

  • ncomp (int) – prints the number of component in the GALFIT file

  • galsky (GalSky data class defined above)

Return type:

bool

galfitools.galin.galfit.galfitLastFit(directory: str) str[source]

determine the last fit completed by GALFIT

Every time GALFIT produces a successful fit it produces a file called galfit.XX, where the XX represent a number that increases every time where GALFIT finds a solution

Parameters:

directory (str) – directory containing the galfit files

Returns:

max_file – last fitting model file produced by GALFIT

Return type:

str

galfitools.galin.galfit.numComps(galcomps: GalComps, name: str) int[source]

gets the number of components for a galaxy.

Given the number of components of a GALFIT file, it discerns which components belong to the galaxy. This is useful when simultaneous fitting was used.

Parameters:
  • galcomps (GalComps data class defined above)

  • name (str) – indicates which model components to count: all, sersic, expdisk, gaussian, devauc

Returns:

N

Return type:

Number of components of the galaxy

galfitools.galin.galfit.numParFree(galcomps: GalComps) int[source]

Obtains the number of free parameters

Count the number of free parameters of the surface brightness model of the GALFIT file.

Parameters:

galcomps (GalComps Data Class defined above)

Returns:

pt – Number of free parameters

Return type:

int

See also

numParSkyFree

Obtains the number of free parameters of the sky component

Notes

It only counts the components with galcomps.Active == True This prevents to count components of other galaxies that were simultanously fitted.

Sky component is ignored.

galfitools.galin.galfit.numParSkyFree(galsky: GalSky) int[source]

Obtains the number of free parameters of the sky component

Count the number of free parameters of the sky component of the GALFIT file.

Parameters:

galsky (GalSky data Class defined above)

Returns:

pt – Number of free parameters

Return type:

int

See also

numParFree

Obtains the number of free parameters

galfitools.galin.galfit.readDataImg(galhead, sigma=None)[source]

reads galfit output cube data image

galfitools.galin.getBoxSizeDs9 module

galfitools.galin.getBoxSizeDs9.getBoxSizeDs9(RegFile: str) int[source]

obtains the corner coordinates of a DS9 region box

Using the DS9 region box file, this method obtains the X-minimum, X-maximum, Y-minimum, and Y-maximum values for the H) option in the GALFIT header file.

Parameters:

RegFile (str) – file containing the DS9 box region

Returns:

  • xmin (int)

  • xmax (int)

  • ymin (int)

  • ymax (int)

galfitools.galin.getSersic module

galfitools.galin.getSersic.getSersic(image: float, regfile: str, center: bool, maskfile: str, zeropoint: float, sky: float, noprint: float, bulgetot: float, bards9: str, plate: float, out: str, galfit_out=None, freeser=False) GalComps[source]

Obtains the initial parameters for GALFIT

given an DS9 ellipse region, it prints the initial parameters of the surface brightness model in GALFIT format.

Parameters:
  • image (float) – FITS image of the galaxy

  • regfile (str) – DS9 ellipse region file

  • center (bool) – If True, it uses the geometrical center of the DS9 ellipse. Otherwise it will use the peak pixel as a center of the galaxy.

  • maskfile (str) – mask file

  • zeropoint (float) – magnitude zero point

  • sky (float) – Sky/background value

  • noprint (float) – if False, avoids to print to STDOUT

  • bulgetot (float) – Estimates the bulge-to-total ratio of the galaxy to determine the initial parameters for the bulge/disk model. If set to None, it computes the initial parameters for a single Sersic model.

  • bards9 (str) – If a DS9 ellipse region is provided (different from the regfile defined above), it will be used to estimate the initial parameters of the bar. In this case, the initial parameters of the bulge, bar, and disk will be printed. The bulgetot parameter must be specified for this to function.

  • plate (float) – plate scale

  • out (str) – output GALFIT file. This is a file where the surface brightness model is formated as a GALFIT file without the header.

  • galfit_out (str) – Name of the output GALFIT cube fits. This is the name of the cube image after the fit.

  • freeser (bool) – keeps the Sersic index of the seccond component as free

Returns:

galcomps – the initial parameters

Return type:

GalComps data class defined in galfit.py containing

galfitools.galin.getStar module

galfitools.galin.getStar.GetFits(Image: str, Imageout: str, sky: float, xlo: int, xhi: int, ylo: int, yhi: int) None[source]

Get a piece from the image

Given an image, and X-minimum, X-maximum, Y-minimum, Y-maximum, it extracts a cutout image. the X-Y-minimum, X-Y-maximum determines the coordinates of the extracted neww image.

Parameters:
  • Image (str) – name of the image file

  • Imageout (str) – name of the output image file

  • sky (float) – value of the background sky

  • xlo (int) – Pixel with the minimum X value.

  • xhi (int) – Pixel with the maximum X value.

  • ylo (int) – Pixel with the minimum Y value.

  • yhi (int) – Pixel with the maximum Y value.

Returns:

  • None

  • # repeated

galfitools.galin.getStar.getStar(image: str, regfile: str, imsize: int, center: bool, sky: float, imout: str, sigma: str, sigout: str) None[source]

extracts a piece of the image file

Given a DS9 ellipse region file and a specified size, it extracts a cutout image that includes the region enclosed by the ellipse.

Parameters:
  • image (str) – name of the image file

  • regfile (str) – DS9 ellipse region file

  • imsize (int) – size of the new cutout image in pixels

  • center (bool) – If True, it takes the geometrical center of the DS9 ellipse region. Otherwise, it will take the peak’s pixels as the coordinate

  • sky (float) – value of the background sky

  • imout (str) – name of the output image file

  • sigma (str) – name of the sigma image file if it exists otherwise None

  • sigout (str) – name of the output sigma image file

Return type:

None

galfitools.galin.imarith module

galfitools.galin.imarith.imarith(ImageFile: str, output: str, image2: str, add: float | None = None, mul: float | None = None, div: float | None = None, sub: float | None = None) None[source]

Makes arithmetic operations on the image

Parameters:
  • ImageFile (str) – name of the image file

  • output (str) – name of the output file

  • image2 (str) – name of a second image, optional

  • add (float) – If a value is provided, it will be added to the image. Otherwise, if image2 is provided, the result will be the sum of image and image2.

  • mul (float) – If a value is provided, it will be multiplied to the image. Otherwise, if image2 is provided, the result will be the multiplication of image and image2.

  • div (float) – If a value is provided, it will be divided to the image. Otherwise, if image2 is provided, the result will be the division of image and image2.

  • sub (float) – If a value is provided, it will be substracted to the image. Otherwise, if image2 is provided, the result will be the substraction of image and image2.

Return type:

None

galfitools.galin.initgal module

class galfitools.galin.initgal.InitGal(GalfitFile: str, number: int, param3: float, param4: float, param5: float, param6: float, param7: float, param8: float, param9: float, param10: float, numcomp: int)[source]

Bases: object

Creates GALFIT’s input files with different initial parameters

Creates a bunch of GALFIT files with different initial parameters. It will create a bash file to run galfit on those files.

GalfitFile

will be taken.

Type:

str, galfit file where the header information

number
Type:

int, the number of files created

param3

parameter, specified in the format [min, max].

Type:

float float, Range of values to assign to the 3) model’s

param4

parameter, specified in the format [min, max].

Type:

float float, Range of values to assign to the 4) model’s

param5

parameter, specified in the format [min, max].

Type:

float float, Range of values to assign to the 5) model’s

param6

parameter, specified in the format [min, max].

Type:

float float, Range of values to assign to the 6) model’s

param7

parameter, specified in the format [min, max].

Type:

float float, Range of values to assign to the 7) model’s

param8

parameter, specified in the format [min, max].

Type:

float float, Range of values to assign to the 8) model’s

param9

parameter, specified in the format [min, max].

Type:

float float, Range of values to assign to the 9) model’s

param10

parameter, specified in the format [min, max].

Type:

float float, Range of values to assign to the 10) model’s

numcomp
Type:

int, the component number where the parameters will be changed

MakeParams : self

makes GALFIT files with different initial parameters

MakeBash : self

makes a bash file to run GALFIT on every file created by MakeParams method

ReadFile : self

read a file and returns the lines of the file as a list

MakeBash()[source]
MakeParams()[source]
ReadFile(inputf)[source]

galfitools.galin.sersic2ferrer module

galfitools.galin.sersic2ferrer.Sersic2Ferrer(galfitFile: str, alpha: bool, beta: bool, fileout: str) GalComps[source]

Convert a Sersic function to Ferrer funciton.

It converts a galfit (prefered fitted) file which contains of a Bulge (Sersic), Bar (gaussian/sersic n = 0.5) and disk (exponential/sersic n =1) surface brightness model (in that order) into a file containing Bulge (Sersic no changes), Bar (Ferrer alpha = 1, beta = 0) and disk (exponential/sersic n =1 no changes).

Parameters:
  • galfitFile (str) – name of the GALFIT file

  • alpha (bool) – If True, it leaves the Ferrer alpha parameter as free

  • beta (bool) – If True, it leaves the Ferrer beta parameter as free

  • fileout (str) – name of the GALFIT output file

Returns:

galcomps – data class defined in galfitools.galin.galfit

Return type:

GalComps

See also

conver2Sersic

converts gaussian, exponential de Vaucoulers to Sersic models

Notes

To make the convertion from Sersic (n=0.5) to Ferrer it takes the first two terms of an Taylor expantion of the Sersic to make the approximation to Ferrer.

galfitools.galin.std module

galfitools.galin.std.Ds9ell2Kronell(xpos, ypos, rx, ry, angle)[source]

Converts DS9 ellipse parameters to geometrical parameters

Parameters:
  • obj (str) – object name

  • xpos (float, x-center)

  • ypos (float, y-center)

  • rx (float, major or minor axis)

  • ry (float, minor or major axis)

  • angle (float, angular position)

Returns:

  • xx (float, x center position)

  • yy (float, y center positon)

  • Rkron (float, major axis)

  • theta (float, angular position measured from X-axis)

  • e (float, ellipticity)

galfitools.galin.std.Ds9ell2Kronellv2(xpos, ypos, rx, ry, angle)[source]

Converts DS9 ellipse parameters to geometrical parameters

Parameters:
  • obj (str) – object name

  • xpos (float, x-center)

  • ypos (float, y-center)

  • rx (float, major or minor axis)

  • ry (float, minor or major axis)

  • angle (float, angular position)

Returns:

  • xx (float, x center position)

  • yy (float, y center positon)

  • Rkron (float, major axis)

  • theta (float, angular position measured from Y-axis)

  • e (float, ellipticity)

galfitools.galin.std.GetAxis(Image)[source]

Get number of rows and columns from the image

galfitools.galin.std.GetExpTime(Image)[source]

Get exposition time from the image header

galfitools.galin.std.GetInfoEllip(regfile: str)[source]

gets ellipse information from DS9 region files

Parameters:

regfile (str) – DS9 region file

Returns:

  • obj (str) – object name

  • xpos (float, x-center)

  • ypos (float, y-center)

  • rx (float, major or minor axis)

  • ry (float, minor or major axis)

  • angle (float, angular position)

returns 0, 0, 0, 0, 0, 0 if ellipse region was not found in file

galfitools.galin.std.GetPmax(image, mask, xmin, xmax, ymin, ymax)[source]

gets the peak coordinates

Given an image, and optionally a mask, it identifies the (x, y) pixels where the maximum value is located.

Parameters:
  • image (2D-array of the image)

  • mask (2D-array of the mask)

  • xmin (int, int, int, int) – coordinates of the image section where the maximum will be obtained

  • xmax (int, int, int, int) – coordinates of the image section where the maximum will be obtained

  • ymin (int, int, int, int) – coordinates of the image section where the maximum will be obtained

  • ymax (int, int, int, int) – coordinates of the image section where the maximum will be obtained

Returns:

(xpos, ypos)

Return type:

(x, y) coordinates of the maximum

galfitools.galin.std.GetSize(x, y, R, theta, ell, ncol, nrow)[source]

Get the (x,y) coordinates that encompass the ellipse

Parameters:
  • x (float, x-center of ellipse)

  • y (float, y-center of ellipse)

  • R (float, major axis of ellipse)

  • theta (float, angular position of ellipse measured from X-axis)

  • ell (float, ellipticity)

  • ncol (number of columns of the image)

  • nrow (number of rows of the image)

Returns:

  • xmin, xmax, ymin, ymax (Minimum and maximum coordinates)

  • that encompass the ellipse.

galfitools.galin.std.MakeImage(newfits, sizex, sizey)[source]

create a new blank FITS Image

Parameters:
  • newfits (str) – name of the new image

  • sizex (int) – number of columns of the new image

  • sizey (int) – number of rows of the new image

Return type:

bool

galfitools.galin.std.parse_ds9_ellipse(tokens)[source]
Parse tokens like:

[‘ellipse(1442’, ‘1061’, ‘16’, ‘16’, ‘0)n’]

or:

[‘ellipse(1442’, ‘1061’, ‘16’, ‘16’, ‘0)’]

Returns: (shape, x, y, a, b, theta)

galfitools.galin.supermask module

galfitools.galin.supermask.get_ds9_ellipse_center_from_file(region_file)[source]

Return the center of the first DS9 ellipse region in a file.

Parameters:

region_file (str or pathlib.Path) – Path to the DS9 region file.

Returns:

  • xcen (int) – X coordinate of the ellipse center.

  • ycen (int) – Y coordinate of the ellipse center.

Raises:

ValueError – If no valid DS9 ellipse region is found in the file.

galfitools.galin.supermask.mainsuperMask()[source]
galfitools.galin.supermask.superMask(segmentation_file: str, masksky_file: str, ds9ellipse_file: str, output='supermask.fits', rem_masksky=False)[source]

Combines SExtractor segmentation fits file, mask fits file (created with maskSky), and DS9 ellipse region file. It removes the central galaxy.

Parameters:
  • segmentation_file (str) – Path to the SExtractor segmentation FITS image.

  • masksky_file (str) – Path to the mask FITS image.

  • ds9ellipse_file (str) – Path to the DS9 ellipse region file.

  • rem_masksky (bool) – If True, removes central galaxy from masksky using DS9 ellipse maskbits region file recommended if central galaxy has not been removed from this mask.

  • output (str optional) – name of the output mask fits file. Default: megamask.fits

Return type:

True

galfitools.galin.tosersic module

galfitools.galin.tosersic.toSersic(galfitFile: str, fileout: str, nfree: bool) GalComps[source]

Convert to Sersic components.

It converts a exponential, de Vaucouleurs, Gaussian functions to a Sersic function

Parameters:
  • galfitFile (str) – name of the GALFIT file

  • fileout (str) – name of the GALFIT output file

  • nfree (Boolean) – leaves sersic index as free to fit

Returns:

galcomps – data class defined in galfitools.galin.galfit

Return type:

GalComps

Note

the components to convert to Sersic must be derived from Sersic: Gaussian, de Vaucoulers, exponential. This does not apply to Ferrer, Nuker, King, etc.

See also

conver2Sersic

converts gaussian, exponential de Vaucoulers to Sersic models

conver2Ferrer

convert gaussian bar to a Ferrer bar

conver2Edge

convert to edgedisk

galfitools.galin.xy2fits module

class galfitools.galin.xy2fits.xy2fits[source]

Bases: object

converts a ASCII mask file with x y format pixels to a FITS image.

ImageFile

the name of the new FITS mask image file

Type:

str

AsciiFilestr

the ASCII file containing the pixels

Valuefloat

the value to be substituted as a count value in the FITS mask image

MakeFits : this is the main method this creates the

FITS image from the ASCII file

MakeImage : create a new blank Image
PutPix : assign the count value to the pixels of the new

image

MakeFits(ImageFile, AsciiFile, Value)[source]
MakeImage(newfits, sizex, sizey)[source]

create a new blank Image

PutPix(X, Y, Value, ImageFits)[source]

Module contents