GALFIT is a galaxy/point source fitting algorithm that fits 2-D parameterized, axisymmetric, functions directly to images http://adsabs.harvard.edu/abs/2002AJ....124..266P(Peng, Ho, Impey, & Rix 2002, AJ, 124: 266). The program has been developed by Chien Peng who maintains a http://www.ociw.edu/ peng/work/galfit/galfit.htmlGalfit homepage.
The main classes in the Galfit object model for Astro-WISE (i.e. those classes that are stored in the database, and must be queried on to get results) are these:
The input which Galfit needs to run are an image of the object to be fitted, information on the 2-D profile to be fitted and various parameters which configure how to perform the fitting. The galaxy images to be fitted by Galfit are defined via a SourceList ID (SLID) and the source IDs (SID) of sources in it. For each source a cut-out of the image is made, centered on the source position which is then fed to Galfit.
The 2-D parameterized functions (e.g., a sersic profile) that can be fitted to this cut-out image are called ``components'' in Astro-WISE. The components that currently can be fitted in Astro-WISE are listed in Table . The definition of the components can be found in the http://users.ociw.edu/peng/work/galfit/README.ps.gzGalfit manual.
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
For example to fit a sersic profile plus a sky background to 4 sources from the sourcelist with SLID=57424 which have SID=7,3,9,33 using the cpu on your own machine, enter at the awe-prompt:
# Import the class GalFitTask: from astro.recipes.GalFit import GalFitTask task = GalFitTask(instrument='WFI', slid=57424, sids=[7,3,9,33], models=[{'name:'sersic'}, {'name':'sky'}], commit=1) task.execute()the same input as above but using the cpus of the parallel cluster of computers:
# Import Processor class: needed to run processes on parallel cluster: from astro.recipes.mods.dpu import Processor # Import Environment class: needed to run processes on parallel cluster: from common.config.Environment import Env # Instantiate an object of class dpu: needed to run processes on parallel cluster: dpu = Processor(Env['dpu_name']) # Run GalFit (see previous example for explanation of parameters): dpu.run('GalFit', i='WFI', slid=57424, sids=[1,3,9,33], m=[{'name':'sersic'},\ {'name':'sky'}], C=1)
The GalFitList class is intended as a simple way to group GalFitModels (and GalFitComponents). The way to use this class is to first create and commit one, and then specify its GalFitList identifier GFLID when running the GalFit task on the DPU or locally:
# Create the GalFitList object l = GalFitList() l.name = 'test-run-1' l.make() l.commit() # [schmidt] 16:27:12 - Set GalFitList identifier GFLID to 100231 # Refer to the GalFitList object by specifying its GFLID, as reported # after committing the GalFitList (see above). dpu.run('GalFit', i='WFI', slid=75637, sids=range(10,20), gflid=100231, C=1)Now it is easy to query on the group of GalFitModels you called "test-run-1" and inspect their residual images:
query = GalFitModel.GFLID == 100211 for model in query: model.get_residual()This will create all residual images, which can then be inspected with a FITS viewer.
To print the results from the fit made above for source with SID=7 enter at the awe-prompt:
# Import the class GalFitComponent which is defined in GalFitModel: from astro.main.GalFitModel import GalFitComponent # Query the database for the GalFitComponents which contain the results # for source with SID=3 in SourceList with SLID=57424 which # were fitted with a sersic profile: query = (GalFitComponent.name == 'sersic') & (GalFitComponent.SLID==57424) & (GalFitComponent.SID==3) # Loop over the results in the query: for c in query: # Print x position and the effective radius: print(c.SID, c.GFID, c.x, c.reff, c.N, c.iN, c.iratio, c.ishape)To print the results from the fit made above enter at the awe-prompt in a script:
# Import the class GalFitComponent which is defined in GalFitModel: from astro.main.GalFitModel import GalFitComponent # Query the database for the GalFitComponents which contain the results # for those sources in SourceList with SLID=57424 which # were fitted with a sersic profile: query = (GalFitComponent.name == 'sersic') & (GalFitComponent.SLID==57424) # Loop over the results in the query: for c in query: # Print x position and the effective radius: print(c.SID, c.GFID, c.x, c.reff, c.N, c.iN, c.iratio, c.ishape)If you have run Galfit with different parameters various times on the same set of sources. Print the results for the last run.
# Define three sources by tuples of SLID, SID, here sources 31, 52, 73 from # SourceList with SLID=57424 mysources = [(57424, 31), (57424, 52), (57424, 73)] models = [] for slid, sid in mysources: q = (GalFitModel.SLID == slid) & (GalFitModel.SID == sid) model = q.max('GFID') models.append(model) for m in models: m.show_model_parameters()To get a listing of all parameters of a Sersic profile:
# Import all classes defined in GalFitModel (GalFitSersic being one of them): from astro.main.GalFitModel import * # Prints a listing of all parameters of a Sersic profile: GalFitSersic.get_persistent_properties()
While it is possible to configure GalFitModel manually, a configuration is determined automatically when no configuration is specified. The following steps can be distinguished in this process:
Galfit's configuration file can be considered as consisting of two separate parts. One part is a number of general configuration parameters, such as the input and output files, pixelscales etc. The other part is an arbitrarily large collection of initial values of functions (e.g. Sersic, Nuker, King) that are fit to the galaxy and potentially other sources in its neighbourhood.
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
To get a listing of all general parameters of Galfit (which are contained in the class GalFitModel, see also table ) type the following lines in the AWE prompt:
# Import the class Pars. from astro.util.Pars import Pars # Make an object which contains the general process parameters for GalFit. p = Pars(GalFitModel) p.show()This uses the general method to show process parameters as discussed in the process parameters howto (see /portal/howtos/man_howto_configure/man_howto_configure.shtmlhere) . This how-to also explains how to use this method to set parameters for Galfit. Here is nevertheless one example. To set the cut-out region around the source which will be modeled by Galfit, one should specify a dictionary:
p = {'GalFitModel.process_params.region_xmin': 1, {'GalFitModel.process_params.region_xmax': 10, {'GalFitModel.process_params.region_ymin': 1, {'GalFitModel.process_params.region_ymax': 10}To get the necessary coordinates, these values have to be offset by the source position. From the source parameters retrieve the Xpos and Ypos of the source:
sl = (SourceList.SLID == 57424)[0] xpos = sl.sources[10]['Xpos'] ypos = sl.sources[10]['Ypos']then determine the region you want around this source and fill in as above. The dictionary specified above can be given to the DPU to change the process parameters:
dpu.run('GalFit', i='WFI', slid=57424, sids=[1,3,9,33], m=[{'name':'sersic'}, {'name':'sky'}], p=p, C=1)or to the Task:
task = GalFitTask(instrument='WFI', slid=57424, sids=[1,3,9,33], models=[{'name':'sersic'}, {'name':'sky'}], pars=p, commit=1) task.execute()
The following commands clarify the correspondence between the names of parameters in the original C code of Galfit and the names given in the Astro-WISE implementation. The class of a specific profile (e.g., GalFitSersic) contains the mapping of parameters specifically for that profile. The class GalFitParameters contains the mapping of general parameters.
# Import all classes defined in GalFitModel: from astro.main.GalFitModel import * GalFitParameters.CONFIG_FILE_MAP GalFitSersic.CONFIG_FILE_MAPA dictionary is returned which has as key the parameters name in the original C code and as value the name in the Astro-WISE implementation.
To set the initial fit parameters and/or fix parameters, their names and values must be specified in the list of dictionaries given in the ``models'' (task level) or ``m'' (dpu level) argument:
# Task level: task = GalFitTask(instrument='WFI', slid=57424, sids=[1,3,9,33], models=[{'name':'sersic', 'iN':1.5, 'free_N':0}, {'name':'sky'}], commit=1) task.execute() # DPU level: dpu.run('GalFit', i='WFI', slid=57424, sids=[1,3,9,33], m=[{'name':'sersic', 'iN':1.5, 'free_N':0}, {'name':'sky'}], C=1)
Fit parameters can be constrained in 4 different ways by Galfit. These different constraints are represented by 4 Python classes:
A list of constraints can be specified in the task as follows:
# Task level: task = GalFitTask(instrument='WFI', slid=57424, sids=[1,3,9,33], constraints=[{'name':'abs', 'comp':1, 'param': 'x', 'min':13, 'max':13}], commit=1) # DPU level: dpu.run('GalFit', i='WFI', slid=57424, sids=[1,3,9,33], cs=[{'name':'abs', 'comp':1, 'param': 'x', 'min':13, 'max':13}], C=1) task.execute()In other words, a constraint can be defined in a dictionary, which maps the properties of the constraint object. A list of such dictionaries represents a list of constraints.
In the configuration file of Galfit a PSF image filename can be specified. Galfit uses this image to convolve the model before comparing it to the data. PSF image files are represented by the PSFImage class.
There are two ways to create PSFImages:
p = PSFImage(pathname='my_psf_image.fits') p.make() p.store() p.commit()This will update the filename of the PSF image to be unique.
Now using the stored PSFImage is done by specifying its filename in the appropriate process parameter. The presence of the filename in the process parameters object triggers a query to find the specified file in the database:
task = GalFitTask(instrument='ACS', slid=110521, sids=[50], pars={'GalFitModel.process_params.psf': 'Cal-EHELMICH----- --------TinyTim---PSF-54227.5867871-83e1bd5c6e15be667a 3cc511ccca13a6ee043514.fits'}, commit=1) task.execute()
Creates the model image and returns it as a BaseFrame object.
Creates the residual image and returns it as a BaseFrame object.
Extracts and downloads the region in the science image for which the model was derived, and returns it as a BaseFrame object.
Extracts and downloads the region in the weight image for which the model was derived and returns it as a BaseFrame object.
Display a list of all ellipse parameters.
Returns a list of dictionaries of all components. I.e. each item of the list is a dictionary which contains the description of one GalFitComponent.
ReducedScienceFrames which are not calibrated with Astro-WISE ingested, but ingested into the system as a ReducedScienceFrame by users can contain weight image formats which differ from the standard. The ACS ReducedScienceFrames are an example. Users can obtain correct sigma images in such cases by adapting GalFitModel.py.