{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Galaxy surface brightness analysis" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Selecting your source" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "context.set_project('TUTORIAL')\n", "context.set_privileges(1)\n", "print(context.get_current_project())" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Identify a source in a SourceList which we want to analyse. Actually you will probably be thinking of an image rather than a SourceList. So lets start with that. Retrieve the image with the following filename: ``Sci-EHELMICH-WFI-------#842---Coadd---Sci-54552.5317447-4d2189f46deed79e536cdbfb0af72ae24187ffd8.fits``." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "c = (CoaddedRegriddedFrame.filename == 'Sci-EHELMICH-WFI-------#842---Coadd---Sci-54552.5317447-4d2189f46deed79e536cdbfb0af72ae24187ffd8.fits')[0]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Lets have a look at this image, and select a galaxy from it." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "c.retrieve()\n", "c.display()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "A SourceList exists for this image:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "sl = (SourceList.SLID == 423431)[0]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Make a skycat catalog for the image and find the SID of an interesting source." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "sl.make_skycat_on_sources()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Now overplot the catalog in skycat. Open the file and select *Data-Servers -> Local Catalogs -> Load from file*.... As filter fill in \\*.scat. You may need to increase the number of sources to get all of them to display. If you click on a symbol the corresponding entry in the catalog is highlighted. Here you can determine the SID of the source.\n", "Take the source with SID 16246 in the SourceList with SLID 423431." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## GalPhot: Isophotal analysis: GalPhot\n", "\n", "It is instructive to first read the [Galphot HOW-TO](http://doc.astro-wise.org/man_howto_galphot.html), in particular to get an idea of the names of classes and methods defined for Galphot.\n", "\n", "Isophotes can be fit to sources using the Galphot package. The main classes used to store the information of the fit are `GalPhotModel` and `GalPhotEllipse`. Lets follow an example here.\n", "\n", "Use the GalPhotTask task to do the isophotal fits." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "task = GalPhotTask(slid=423431, sids=[16246], commit=True)\n", "task.execute()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "or" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "```\n", "dpu.run('GalPhot', slid=423431, sids=[16246], C=1)\n", "```" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Inspect the model. We must start by finding the model we made in the previous step in the database. This can be done by selecting the most recent GalPhotModel created by yourself." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "m = (GalPhotModel.SLID == 423431).user_only().max('GPID')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The methods ``get_model()``, ``get_residual()``, ``get_science()`` can be used on a GalPhotModel to visually inspect its quality." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "s = m.get_science()\n", "s.inspect()\n", "r = m.get_residual()\n", "r.inspect()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The fitted ellipses are stored in the model, and they can also be obtained:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "m.ellipses[0].r" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "For a description of the ellipse parameters see the help page of one of the ellipses:" ] }, { "cell_type": "markdown", "metadata": { "collapsed": true }, "source": [ "help(m.ellipses[0])" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "```\n", "Help on GalPhotEllipse in module astro.main.GalPhotModel object:\n", "\n", "class GalPhotEllipse(common.database.DBMain.DBObject, astro.main.SourceLink.SourceLink, astro.main.ProcessTarget.ProcessTarget)\n", " | This describes one ellipse as calculated by GalPhot. A GalPhotModel\n", " | consists of a number of GalPhotEllipses\n", " | \n", " | Method resolution order:\n", " | GalPhotEllipse\n", " | common.database.DBMain.DBObject\n", " | astro.main.SourceLink.SourceLink\n", " | astro.main.ProcessTarget.ProcessTarget\n", " | common.database.DBMeta.DBMixin\n", " | common.main.ProcessTarget.ProcessTarget\n", " | astro.main.OnTheFly.OnTheFly\n", " | common.main.OnTheFly.OnTheFly\n", " | builtins.object\n", " | \n", " | Methods defined here:\n", " | \n", " | get_ellipse_parameters(self)\n", " | \n", " | show_ellipse_parameters(self)\n", " | \n", " | ----------------------------------------------------------------------\n", " | Data descriptors defined here:\n", " | \n", " | GPID\n", " | Galphot ID [None]\n", " | \n", " | GPLID\n", " | Galphot List identifier [None]\n", " | \n", " | SID\n", " | Source identifier [None]\n", " | \n", " | SLID\n", " | SourceList identifier [None]\n", " | \n", " | c1\n", " | The cos(n*theta) term of the residuals along the ellipse [None]\n", " | \n", " | c2\n", " | The cos(n*theta) term of the residuals along the ellipse [None]\n", " | \n", " | c3\n", " | The cos(n*theta) term of the residuals along the ellipse [None]\n", " etc.\n", " ```" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "You can obtain/visualize the ellipse parameters:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "ellipses = m.get_model_parameters()\n", "rad = [e['r'] for e in ellipses]\n", "pos = [e['pos'] for e in ellipses]\n", "pylab.scatter(rad, pos)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "For more information see the [Galphot HOW-TO](http://doc.astro-wise.org/man_howto_galphot.html)." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## GalFit: 2D Parametric fits to a galaxy surface brightness distribution\n", "\n", "The main classes used to store Galfit models are GalFitModel and a number of classes named e.g. GalFitSeric, each of which is a function that can be fit to the data. See the first section of the Galfit HOW-TO for an overview of the important classes defined for using Galfit in Astro-WISE.\n", "\n", "Here too, **we first need to identify a source on which we want to run Galfit**. We can take the same source as in the previous example, the source from the SourceList with SLID 423431 and SID 16246.\n", "\n", "**Create a Sersic model for the galaxy where the index of the Sersic model is fixed at 3.** The model components are specified as a list of dictionaries. Each dictionary describes one component. (Physical) component parameters come in 3 variants e.g.: **ix**, **x**, **dx**, respectively the initial, final and error values. Additionally the parameter is set to be fixed or free with the **free_x** parameter." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "task = GalFitTask(slid=423431, sids=[16246], models=[{'name': 'sersic', 'iN': 3, 'free_N': 0}],\n", " commit=True)\n", "task.execute()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "or" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "```\n", "dpu.run('GalFit', i='WFI', slid=423431, sids=[16246], m=[{'name': 'sersic', 'iN': 3, 'free_N': 0}], C=1)\n", "```" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Again we need to find the result in the database:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "m = (GalFitModel.SLID == 423431).user_only().max('GFID')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Now we can inspect the model: retrieve the residual image of the science and the model." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "sci = m.get_science()\n", "res = m.get_residual()\n", "mod = m.get_model()\n", "sci.inspect()\n", "res.inspect()\n", "mod.inspect()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "etc.\n", "Have a look at the parameters of the model:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "m.show_model_parameters()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "or" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "m.info()\n", "m.components[0].info()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "For more information see the [Galfit HOW-TO](http://doc.astro-wise.org/man_howto_galfit.html)." ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.5.1" } }, "nbformat": 4, "nbformat_minor": 1 }