VIRCAM Pipeline  1.3.4
create_table_3.c
1 /* $Id: create_table_3.c,v 1.14 2013-10-15 16:19:40 jim Exp $
2  *
3  * This file is part of the VIRCAM Pipeline
4  * Copyright (C) 2005 Cambridge Astronomy Survey Unit
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  */
20 
21 /*
22  * $Author: jim $
23  * $Date: 2013-10-15 16:19:40 $
24  * $Revision: 1.14 $
25  * $Name: not supported by cvs2svn $
26  */
27 
28 #include <stdio.h>
29 #include <math.h>
30 #include "imcore.h"
31 #include "util.h"
32 #include "floatmath.h"
33 
34 /* Column numbers for each item to be stored */
35 
36 #define COL_NUMBER 1
37 #define COL_X 2
38 #define COL_Y 3
39 #define COL_FLUXISO 4
40 #define COL_PEAKHEIGHT 5
41 #define COL_ELLIPT 6
42 #define COL_SIGMA 7
43 #define COL_PA 8
44 #define COL_AREAL1 9
45 #define COL_AREAL2 10
46 #define COL_AREAL3 11
47 #define COL_AREAL4 12
48 #define COL_AREAL5 13
49 #define COL_AREAL6 14
50 #define COL_AREAL7 15
51 #define COL_AREAL8 16
52 
53 /* Number of columns in the table */
54 
55 #define NCOLS 32
56 
57 /* Column definitions */
58 
59 static const char *ttype[NCOLS]={"No.","X_coordinate","Y_coordinate",
60  "Isophotal_flux","Peak_height","Ellipticity",
61  "Gaussian_sigma","Position_angle",
62  "Areal_1_profile","Areal_2_profile","Areal_3_profile",
63  "Areal_4_profile","Areal_5_profile","Areal_6_profile",
64  "Areal_7_profile","Areal_8_profile",
65  "Blank17","Blank18","Blank19","Blank20",
66  "Blank21","Blank22","Blank23","Blank24",
67  "Blank25","Blank26","Blank27","Blank28",
68  "Blank29","Blank30","Blank31","Blank32"};
69 static const char *tunit[NCOLS]={" ","Pixels","Pixels","Counts","Counts"," ",
70  "Pixels","Degrees","Pixels","Pixels","Pixels",
71  "Pixels","Pixels","Pixels","Pixels","Pixels",
72  "Blank","Blank","Blank","Blank","Blank","Blank",
73  "Blank","Blank","Blank","Blank","Blank","Blank",
74  "Blank","Blank","Blank","Blank"};
75 
76 static cpl_type tform[NCOLS]={CPL_TYPE_INT,CPL_TYPE_FLOAT,CPL_TYPE_FLOAT,
77  CPL_TYPE_FLOAT,CPL_TYPE_FLOAT,CPL_TYPE_FLOAT,
78  CPL_TYPE_FLOAT,CPL_TYPE_FLOAT,CPL_TYPE_FLOAT,
79  CPL_TYPE_FLOAT,CPL_TYPE_FLOAT,CPL_TYPE_FLOAT,
80  CPL_TYPE_FLOAT,CPL_TYPE_FLOAT,CPL_TYPE_FLOAT,
81  CPL_TYPE_FLOAT,CPL_TYPE_FLOAT,CPL_TYPE_FLOAT,
82  CPL_TYPE_FLOAT,CPL_TYPE_FLOAT,CPL_TYPE_FLOAT,
83  CPL_TYPE_FLOAT,CPL_TYPE_FLOAT,CPL_TYPE_FLOAT,
84  CPL_TYPE_FLOAT,CPL_TYPE_FLOAT,CPL_TYPE_FLOAT,
85  CPL_TYPE_FLOAT,CPL_TYPE_FLOAT,CPL_TYPE_FLOAT,
86  CPL_TYPE_FLOAT,CPL_TYPE_FLOAT};
87 
88 static int areal_cols[NAREAL] = {COL_AREAL1,COL_AREAL2,COL_AREAL3,COL_AREAL4,
89  COL_AREAL5,COL_AREAL6,COL_AREAL7,COL_AREAL8};
92 /*---------------------------------------------------------------------------*/
114 /*---------------------------------------------------------------------------*/
115 
116 extern void tabinit_3(void) {
117 
118  /* Call the generic routine to open a new output table */
119 
120  tabinit_gen(NCOLS,ttype,tunit,tform);
121 
122  /* RA and DEC columns are undefined */
123 
124  imcore_xcol = COL_X;
125  imcore_ycol = COL_Y;
126 }
127 
128 /*---------------------------------------------------------------------------*/
153 /*---------------------------------------------------------------------------*/
154 
155 extern int do_seeing_3(ap_t *ap) {
156  int retval,i;
157  char *areal_colnames[NAREAL];
158 
159  /* Sort out the areal profile column names */
160 
161  for (i = 0; i < NAREAL; i++)
162  areal_colnames[i] = (char *)ttype[areal_cols[i]-1];
163 
164  /* Just call the generic seeing routine */
165 
166  retval = do_seeing_gen(ap,ttype[COL_ELLIPT-1],ttype[COL_PEAKHEIGHT-1],
167  areal_colnames);
168 
169  /* Get out of here */
170 
171  return(retval);
172 }
173 
174 
175 /*---------------------------------------------------------------------------*/
202 /*---------------------------------------------------------------------------*/
203 
204 extern int process_results_3(ap_t *ap) {
205  float momresults[8],parmall[NPAR];
206  float sxx,syy,srr,sxy,ecc,temp,xx,theta,radeg,ell;
207  float yy,sigma,peak,areal1,iso_flux;
208  float areal2,areal3,areal4,areal5,areal6,areal7,areal8;
209  int iareal[NAREAL],i,nr;
210  long nrows;
211 
212  /* Do a basic moments analysis and work out the areal profiles*/
213 
214  moments(ap,momresults);
215  if (momresults[0] < 0)
216  return(VIR_FATAL);
217  areals(ap,iareal);
218 
219  /* See if this object makes the cut in terms of its size. If not, then
220  just return with good status */
221 
222  if (iareal[0] < ap->ipnop || momresults[3] < ap->xintmin)
223  return(VIR_OK);
224 
225  /* Try and deblend the images if it is requested and justified */
226 
227  parmall[0] = momresults[3];
228  parmall[1] = momresults[1];
229  parmall[2] = momresults[2];
230  parmall[3] = ap->thresh;
231  for (i = 4; i < 8; i++)
232  parmall[i] = momresults[i];
233  for (i = 0; i < NAREAL; i++)
234  parmall[i+8] = (float)iareal[i];
235 
236  /* Massage the results and write them to the fits table */
237 
238  radeg = 180.0/CPL_MATH_PI;
239  sxx = parmall[4];
240  sxy = parmall[5];
241  syy = parmall[6];
242  if(sxy > 0.0)
243  sxy = MAX(1.0e-4,MIN(sxy,sqrtf(sxx*syy)));
244  else
245  sxy = MIN(-1.0e-4,MAX(sxy,-sqrtf(sxx*syy)));
246 
247  srr = MAX(0.5,sxx+syy);
248  ecc = sqrtf((syy-sxx)*(syy-sxx)+4.0*sxy*sxy)/srr;
249  temp = MAX((1.0-ecc)/(1.0+ecc),0.0);
250  ell = 1.0 - sqrtf(temp);
251  ell = MIN(0.99,MAX(0.0,ell));
252  xx = 0.5*(1.0+ecc)*srr-sxx;
253  if(xx == 0.0)
254  theta = 0.0;
255  else
256  theta = 90.0-radeg*atanf(sxy/xx);
257 
258  /* Create a list of values */
259 
260  nrows = cpl_table_get_nrow(tab);
261  nobjects++;
262  if (nobjects > nrows)
263  (void)cpl_table_set_size(tab,nrows+INITROWS);
264  nr = nobjects - 1;
265  iso_flux = parmall[0];
266  xx = parmall[1];
267  yy = parmall[2];
268  sigma = sqrt(srr);
269  peak = parmall[7];
270  areal1 = parmall[8];
271  areal2 = parmall[9];
272  areal3 = parmall[10];
273  areal4 = parmall[11];
274  areal5 = parmall[12];
275  areal6 = parmall[13];
276  areal7 = parmall[14];
277  areal8 = parmall[15];
278 
279  /* Store away the results for this object */
280 
281  cpl_table_set_int(tab,ttype[COL_NUMBER-1],nr,nr);
282  cpl_table_set_float(tab,ttype[COL_X-1],nr,xx);
283  cpl_table_set_float(tab,ttype[COL_Y-1],nr,yy);
284  cpl_table_set_float(tab,ttype[COL_FLUXISO-1],nr,iso_flux);
285  cpl_table_set_float(tab,ttype[COL_PEAKHEIGHT-1],nr,peak);
286  cpl_table_set_float(tab,ttype[COL_ELLIPT-1],nr,ell);
287  cpl_table_set_float(tab,ttype[COL_SIGMA-1],nr,sigma);
288  cpl_table_set_float(tab,ttype[COL_PA-1],nr,theta);
289  cpl_table_set_float(tab,ttype[COL_AREAL1-1],nr,areal1);
290  cpl_table_set_float(tab,ttype[COL_AREAL2-1],nr,areal2);
291  cpl_table_set_float(tab,ttype[COL_AREAL3-1],nr,areal3);
292  cpl_table_set_float(tab,ttype[COL_AREAL4-1],nr,areal4);
293  cpl_table_set_float(tab,ttype[COL_AREAL5-1],nr,areal5);
294  cpl_table_set_float(tab,ttype[COL_AREAL6-1],nr,areal6);
295  cpl_table_set_float(tab,ttype[COL_AREAL7-1],nr,areal7);
296  cpl_table_set_float(tab,ttype[COL_AREAL8-1],nr,areal8);
297 
298  /* Get outta here */
299 
300  return(VIR_OK);
301 }
302 
305 /*
306 
307 $Log: not supported by cvs2svn $
308 Revision 1.13 2010/09/09 12:09:57 jim
309 Added docs
310 
311 Revision 1.12 2009/09/09 09:40:12 jim
312 Using CPL macros for various constants
313 
314 Revision 1.11 2009/02/20 10:49:58 jim
315 Removed superfluous declarations
316 
317 Revision 1.10 2009/01/23 12:24:33 jim
318 Fixed bugs in pixel flagging
319 
320 Revision 1.9 2008/10/13 08:09:31 jim
321 Removed redundant code and fixed pixel flagging scheme
322 
323 Revision 1.8 2007/05/03 11:15:34 jim
324 Fixed little problem with table wcs
325 
326 Revision 1.7 2007/05/02 09:11:35 jim
327 Modified to allow for inclusion of table WCS keywords into FITS header
328 
329 Revision 1.6 2007/03/01 12:38:26 jim
330 Small modifications after a bit of code checking
331 
332 Revision 1.5 2006/05/30 12:14:08 jim
333 Fixed indexing bug in table that was causing a memory overwrite
334 
335 Revision 1.4 2005/11/25 09:56:15 jim
336 Tidied up some more documentation
337 
338 Revision 1.3 2005/09/22 08:40:42 jim
339 Fixed some bugs in imcore and added classification Removed some unnecessary
340 files
341 
342 Revision 1.2 2005/09/20 15:07:47 jim
343 Fixed a few bugs and added a few things
344 
345 Revision 1.1 2005/09/13 13:25:28 jim
346 Initial entry after modifications to make cpl compliant
347 
348 
349 */
int do_seeing_gen(ap_t *ap, const char *col_ellipt, const char *col_pkht, char *col_areals[NAREAL])
Do seeing estimate (generic)
Definition: create_table.c:334
void areals(ap_t *ap, int iareal[NAREAL])
Work out the areal profiles for an object.
Definition: areals.c:67
void moments(ap_t *ap, float results[])
Do moments analysis on an object.
Definition: moments.c:65
void tabinit_gen(int ncols, const char *ttype[], const char *tunit[], cpl_type tform[])
Initialise tables (generic)
Definition: create_table.c:281
int process_results_3(ap_t *ap)
Process results for type 3 catalogue.
int do_seeing_3(ap_t *ap)
Do seeing estimate for type 3 catalogue.
void tabinit_3(void)
Initialise type 1 catalogue.