create_table_3.c

00001 /* $Id: create_table_3.c,v 1.13 2010/09/09 12:09:57 jim Exp $
00002  *
00003  * This file is part of the VIRCAM Pipeline
00004  * Copyright (C) 2005 Cambridge Astronomy Survey Unit
00005  *
00006  * This program is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation; either version 2 of the License, or
00009  * (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software
00018  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019  */
00020 
00021 /*
00022  * $Author: jim $
00023  * $Date: 2010/09/09 12:09:57 $
00024  * $Revision: 1.13 $
00025  * $Name: v1-1-0 $
00026  */
00027 
00028 #include <stdio.h>
00029 #include <math.h>
00030 #include "imcore.h"
00031 #include "util.h"
00032 #include "floatmath.h"
00033 
00034 /* Column numbers for each item to be stored */
00035 
00036 #define COL_NUMBER      1
00037 #define COL_X           2
00038 #define COL_Y           3
00039 #define COL_FLUXISO     4
00040 #define COL_PEAKHEIGHT  5
00041 #define COL_ELLIPT      6
00042 #define COL_SIGMA       7
00043 #define COL_PA          8
00044 #define COL_AREAL1      9
00045 #define COL_AREAL2     10
00046 #define COL_AREAL3     11
00047 #define COL_AREAL4     12
00048 #define COL_AREAL5     13
00049 #define COL_AREAL6     14
00050 #define COL_AREAL7     15
00051 #define COL_AREAL8     16
00052 
00053 /* Number of columns in the table */
00054 
00055 #define NCOLS 32
00056 
00057 /* Column definitions */
00058 
00059 static const char *ttype[NCOLS]={"No.","X_coordinate","Y_coordinate",
00060                                  "Isophotal_flux","Peak_height","Ellipticity",
00061                                  "Gaussian_sigma","Position_angle",
00062                                  "Areal_1_profile","Areal_2_profile","Areal_3_profile",
00063                                  "Areal_4_profile","Areal_5_profile","Areal_6_profile",
00064                                  "Areal_7_profile","Areal_8_profile",
00065                                  "Blank","Blank","Blank","Blank","Blank","Blank",
00066                                  "Blank","Blank","Blank","Blank","Blank","Blank",
00067                                  "Blank","Blank","Blank","Blank"};
00068 static const char *tunit[NCOLS]={" ","Pixels","Pixels","Counts","Counts"," ",
00069                                  "Pixels","Degrees","Pixels","Pixels","Pixels",
00070                                  "Pixels","Pixels","Pixels","Pixels","Pixels",
00071                                  "Blank","Blank","Blank","Blank","Blank","Blank",
00072                                  "Blank","Blank","Blank","Blank","Blank","Blank",
00073                                  "Blank","Blank","Blank","Blank"};
00074 
00075 static cpl_type tform[NCOLS]={CPL_TYPE_INT,CPL_TYPE_FLOAT,CPL_TYPE_FLOAT,
00076                               CPL_TYPE_FLOAT,CPL_TYPE_FLOAT,CPL_TYPE_FLOAT,
00077                               CPL_TYPE_FLOAT,CPL_TYPE_FLOAT,CPL_TYPE_FLOAT,
00078                               CPL_TYPE_FLOAT,CPL_TYPE_FLOAT,CPL_TYPE_FLOAT,
00079                               CPL_TYPE_FLOAT,CPL_TYPE_FLOAT,CPL_TYPE_FLOAT,
00080                               CPL_TYPE_FLOAT,CPL_TYPE_FLOAT,CPL_TYPE_FLOAT,
00081                               CPL_TYPE_FLOAT,CPL_TYPE_FLOAT,CPL_TYPE_FLOAT,
00082                               CPL_TYPE_FLOAT,CPL_TYPE_FLOAT,CPL_TYPE_FLOAT,
00083                               CPL_TYPE_FLOAT,CPL_TYPE_FLOAT,CPL_TYPE_FLOAT,
00084                               CPL_TYPE_FLOAT,CPL_TYPE_FLOAT,CPL_TYPE_FLOAT,
00085                               CPL_TYPE_FLOAT,CPL_TYPE_FLOAT};
00086 
00087 static int areal_cols[NAREAL] = {COL_AREAL1,COL_AREAL2,COL_AREAL3,COL_AREAL4,
00088                                  COL_AREAL5,COL_AREAL6,COL_AREAL7,COL_AREAL8};
00091 /*---------------------------------------------------------------------------*/
00113 /*---------------------------------------------------------------------------*/
00114 
00115 extern void tabinit_3(void) {
00116 
00117     /* Call the generic routine to open a new output table */
00118 
00119     tabinit_gen(NCOLS,ttype,tunit,tform);
00120 
00121     /* RA and DEC columns are undefined */
00122 
00123     imcore_xcol = COL_X;
00124     imcore_ycol = COL_Y;
00125 }
00126 
00127 /*---------------------------------------------------------------------------*/
00152 /*---------------------------------------------------------------------------*/
00153 
00154 extern int do_seeing_3(ap_t *ap) {
00155     int retval,i;
00156     char *areal_colnames[NAREAL];
00157 
00158     /* Sort out the areal profile column names */
00159 
00160     for (i = 0; i < NAREAL; i++) 
00161         areal_colnames[i] = (char *)ttype[areal_cols[i]-1];
00162  
00163     /* Just call the generic seeing routine */
00164  
00165     retval = do_seeing_gen(ap,ttype[COL_ELLIPT-1],ttype[COL_PEAKHEIGHT-1],
00166                            areal_colnames);
00167 
00168     /* Get out of here */
00169  
00170     return(retval);
00171 }
00172         
00173         
00174 /*---------------------------------------------------------------------------*/
00201 /*---------------------------------------------------------------------------*/
00202 
00203 extern int process_results_3(ap_t *ap) {
00204     float momresults[8],parmall[NPAR];
00205     float sxx,syy,srr,sxy,ecc,temp,xx,theta,radeg,ell;
00206     float yy,sigma,peak,areal1,iso_flux;
00207     float areal2,areal3,areal4,areal5,areal6,areal7,areal8;
00208     int iareal[NAREAL],i,nr;
00209     long nrows;
00210 
00211     /* Do a basic moments analysis and work out the areal profiles*/
00212 
00213     moments(ap,momresults);
00214     if (momresults[0] < 0)
00215         return(VIR_FATAL);
00216     areals(ap,iareal);
00217 
00218     /* See if this object makes the cut in terms of its size.  If not, then
00219        just return with good status */
00220 
00221     if (iareal[0] < ap->ipnop || momresults[3] < ap->xintmin)
00222         return(VIR_OK);
00223 
00224     /* Try and deblend the images if it is requested and justified */
00225 
00226     parmall[0] = momresults[3];
00227     parmall[1] = momresults[1];
00228     parmall[2] = momresults[2];
00229     parmall[3] = ap->thresh;
00230     for (i = 4; i < 8; i++) 
00231         parmall[i] = momresults[i];
00232     for (i = 0; i < NAREAL; i++)
00233         parmall[i+8] = (float)iareal[i];
00234 
00235     /* Massage the results and write them to the fits table */
00236 
00237     radeg = 180.0/CPL_MATH_PI;
00238     sxx = parmall[4];
00239     sxy = parmall[5];
00240     syy = parmall[6];    
00241     if(sxy > 0.0)
00242       sxy = MAX(1.0e-4,MIN(sxy,sqrtf(sxx*syy)));
00243     else
00244       sxy = MIN(-1.0e-4,MAX(sxy,-sqrtf(sxx*syy)));
00245 
00246     srr = MAX(0.5,sxx+syy);
00247     ecc = sqrtf((syy-sxx)*(syy-sxx)+4.0*sxy*sxy)/srr;
00248     temp = MAX((1.0-ecc)/(1.0+ecc),0.0);
00249     ell = 1.0 - sqrtf(temp);
00250     ell = MIN(0.99,MAX(0.0,ell));
00251     xx = 0.5*(1.0+ecc)*srr-sxx;
00252     if(xx == 0.0)
00253         theta = 0.0;
00254     else
00255         theta = 90.0-radeg*atanf(sxy/xx);
00256 
00257     /* Create a list of values */
00258 
00259     nrows = cpl_table_get_nrow(tab);
00260     nobjects++;
00261     if (nobjects > nrows) 
00262         (void)cpl_table_set_size(tab,nrows+INITROWS);
00263     nr = nobjects - 1;
00264     iso_flux = parmall[0];
00265     xx = parmall[1];
00266     yy = parmall[2];
00267     sigma = sqrt(srr);
00268     peak = parmall[7];
00269     areal1 = parmall[8];
00270     areal2 = parmall[9];
00271     areal3 = parmall[10];
00272     areal4 = parmall[11];
00273     areal5 = parmall[12];
00274     areal6 = parmall[13];
00275     areal7 = parmall[14];
00276     areal8 = parmall[15];
00277 
00278     /* Store away the results for this object */
00279 
00280     cpl_table_set_int(tab,ttype[COL_NUMBER-1],nr,nr);
00281     cpl_table_set_float(tab,ttype[COL_X-1],nr,xx);
00282     cpl_table_set_float(tab,ttype[COL_Y-1],nr,yy);
00283     cpl_table_set_float(tab,ttype[COL_FLUXISO-1],nr,iso_flux);
00284     cpl_table_set_float(tab,ttype[COL_PEAKHEIGHT-1],nr,peak);
00285     cpl_table_set_float(tab,ttype[COL_ELLIPT-1],nr,ell);
00286     cpl_table_set_float(tab,ttype[COL_SIGMA-1],nr,sigma);
00287     cpl_table_set_float(tab,ttype[COL_PA-1],nr,theta);
00288     cpl_table_set_float(tab,ttype[COL_AREAL1-1],nr,areal1);
00289     cpl_table_set_float(tab,ttype[COL_AREAL2-1],nr,areal2);
00290     cpl_table_set_float(tab,ttype[COL_AREAL3-1],nr,areal3);
00291     cpl_table_set_float(tab,ttype[COL_AREAL4-1],nr,areal4);
00292     cpl_table_set_float(tab,ttype[COL_AREAL5-1],nr,areal5);
00293     cpl_table_set_float(tab,ttype[COL_AREAL6-1],nr,areal6);
00294     cpl_table_set_float(tab,ttype[COL_AREAL7-1],nr,areal7);
00295     cpl_table_set_float(tab,ttype[COL_AREAL8-1],nr,areal8);
00296 
00297     /* Get outta here */
00298 
00299     return(VIR_OK);
00300 }
00301 
00304 /*
00305 
00306 $Log: create_table_3.c,v $
00307 Revision 1.13  2010/09/09 12:09:57  jim
00308 Added docs
00309 
00310 Revision 1.12  2009/09/09 09:40:12  jim
00311 Using CPL macros for various constants
00312 
00313 Revision 1.11  2009/02/20 10:49:58  jim
00314 Removed superfluous declarations
00315 
00316 Revision 1.10  2009/01/23 12:24:33  jim
00317 Fixed bugs in pixel flagging
00318 
00319 Revision 1.9  2008/10/13 08:09:31  jim
00320 Removed redundant code and fixed pixel flagging scheme
00321 
00322 Revision 1.8  2007/05/03 11:15:34  jim
00323 Fixed little problem with table wcs
00324 
00325 Revision 1.7  2007/05/02 09:11:35  jim
00326 Modified to allow for inclusion of table WCS keywords into FITS header
00327 
00328 Revision 1.6  2007/03/01 12:38:26  jim
00329 Small modifications after a bit of code checking
00330 
00331 Revision 1.5  2006/05/30 12:14:08  jim
00332 Fixed indexing bug in table that was causing a memory overwrite
00333 
00334 Revision 1.4  2005/11/25 09:56:15  jim
00335 Tidied up some more documentation
00336 
00337 Revision 1.3  2005/09/22 08:40:42  jim
00338 Fixed some bugs in imcore and added classification Removed some unnecessary
00339 files
00340 
00341 Revision 1.2  2005/09/20 15:07:47  jim
00342 Fixed a few bugs and added a few things
00343 
00344 Revision 1.1  2005/09/13 13:25:28  jim
00345 Initial entry after modifications to make cpl compliant
00346 
00347 
00348 */

Generated on 7 Feb 2011 for VIRCAM Pipeline by  doxygen 1.6.1