VIRCAM Pipeline  2.3.10
create_table_3.c
1 /* $Id: create_table_3.c,v 1.3 2015/08/12 11:16:55 jim Exp $
2  *
3  * This file is part of the CASU Pipeline utilities
4  * Copyright (C) 2015 European Southern Observatory
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: 2015/08/12 11:16:55 $
24  * $Revision: 1.3 $
25  * $Name: $
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 imcore_tabinit_3(int *imcore_xcol, int *imcore_ycol,
117  cpl_table **tab) {
118 
119  /* Call the generic routine to open a new output table */
120 
121  imcore_tabinit_gen(NCOLS,ttype,tunit,tform,tab);
122 
123  /* RA and DEC columns are undefined */
124 
125  *imcore_xcol = COL_X;
126  *imcore_ycol = COL_Y;
127 }
128 
129 /*---------------------------------------------------------------------------*/
154 /*---------------------------------------------------------------------------*/
155 
156 extern int imcore_do_seeing_3(ap_t *ap, int nobjects, cpl_table *tab) {
157  int retval,i;
158  char *areal_colnames[NAREAL];
159 
160  /* Sort out the areal profile column names */
161 
162  for (i = 0; i < NAREAL; i++)
163  areal_colnames[i] = (char *)ttype[areal_cols[i]-1];
164 
165  /* Just call the generic seeing routine */
166 
167  retval = imcore_do_seeing_gen(ap,ttype[COL_ELLIPT-1],ttype[COL_PEAKHEIGHT-1],
168  areal_colnames,nobjects,tab);
169 
170  /* Get out of here */
171 
172  return(retval);
173 }
174 
175 
176 /*---------------------------------------------------------------------------*/
203 /*---------------------------------------------------------------------------*/
204 
205 extern int imcore_process_results_3(ap_t *ap, int *nobjects, cpl_table *tab) {
206  float momresults[8],parmall[NPAR];
207  float sxx,syy,srr,sxy,ecc,temp,xx,theta,radeg,ell;
208  float yy,sigma,peak,areal1,iso_flux;
209  float areal2,areal3,areal4,areal5,areal6,areal7,areal8;
210  int iareal[NAREAL],i,nr;
211  long nrows;
212 
213  /* Do a basic moments analysis and work out the areal profiles*/
214 
215  imcore_moments(ap,momresults);
216  if (momresults[0] < 0)
217  return(CASU_FATAL);
218  imcore_areals(ap,iareal);
219 
220  /* See if this object makes the cut in terms of its size. If not, then
221  just return with good status */
222 
223  if (iareal[0] < ap->ipnop || momresults[3] < ap->xintmin)
224  return(CASU_OK);
225 
226  /* Try and deblend the images if it is requested and justified */
227 
228  parmall[0] = momresults[3];
229  parmall[1] = momresults[1];
230  parmall[2] = momresults[2];
231  parmall[3] = ap->thresh;
232  for (i = 4; i < 8; i++)
233  parmall[i] = momresults[i];
234  for (i = 0; i < NAREAL; i++)
235  parmall[i+8] = (float)iareal[i];
236 
237  /* Massage the results and write them to the fits table */
238 
239  radeg = 180.0/CPL_MATH_PI;
240  sxx = parmall[4];
241  sxy = parmall[5];
242  syy = parmall[6];
243  if(sxy > 0.0)
244  sxy = MAX(1.0e-4,MIN(sxy,sqrtf(sxx*syy)));
245  else
246  sxy = MIN(-1.0e-4,MAX(sxy,-sqrtf(sxx*syy)));
247 
248  srr = MAX(0.5,sxx+syy);
249  ecc = sqrtf((syy-sxx)*(syy-sxx)+4.0*sxy*sxy)/srr;
250  temp = MAX((1.0-ecc)/(1.0+ecc),0.0);
251  ell = 1.0 - sqrtf(temp);
252  ell = MIN(0.99,MAX(0.0,ell));
253  xx = 0.5*(1.0+ecc)*srr-sxx;
254  if(xx == 0.0)
255  theta = 0.0;
256  else
257  theta = 90.0-radeg*atanf(sxy/xx);
258 
259  /* Create a list of values */
260 
261  nrows = cpl_table_get_nrow(tab);
262  (*nobjects)++;
263  if (*nobjects > nrows)
264  (void)cpl_table_set_size(tab,nrows+INITROWS);
265  nr = *nobjects - 1;
266  iso_flux = parmall[0];
267  xx = parmall[1];
268  yy = parmall[2];
269  sigma = sqrt(srr);
270  peak = parmall[7];
271  areal1 = parmall[8];
272  areal2 = parmall[9];
273  areal3 = parmall[10];
274  areal4 = parmall[11];
275  areal5 = parmall[12];
276  areal6 = parmall[13];
277  areal7 = parmall[14];
278  areal8 = parmall[15];
279 
280  /* Store away the results for this object */
281 
282  cpl_table_set_int(tab,ttype[COL_NUMBER-1],nr,nr);
283  cpl_table_set_float(tab,ttype[COL_X-1],nr,xx);
284  cpl_table_set_float(tab,ttype[COL_Y-1],nr,yy);
285  cpl_table_set_float(tab,ttype[COL_FLUXISO-1],nr,iso_flux);
286  cpl_table_set_float(tab,ttype[COL_PEAKHEIGHT-1],nr,peak);
287  cpl_table_set_float(tab,ttype[COL_ELLIPT-1],nr,ell);
288  cpl_table_set_float(tab,ttype[COL_SIGMA-1],nr,sigma);
289  cpl_table_set_float(tab,ttype[COL_PA-1],nr,theta);
290  cpl_table_set_float(tab,ttype[COL_AREAL1-1],nr,areal1);
291  cpl_table_set_float(tab,ttype[COL_AREAL2-1],nr,areal2);
292  cpl_table_set_float(tab,ttype[COL_AREAL3-1],nr,areal3);
293  cpl_table_set_float(tab,ttype[COL_AREAL4-1],nr,areal4);
294  cpl_table_set_float(tab,ttype[COL_AREAL5-1],nr,areal5);
295  cpl_table_set_float(tab,ttype[COL_AREAL6-1],nr,areal6);
296  cpl_table_set_float(tab,ttype[COL_AREAL7-1],nr,areal7);
297  cpl_table_set_float(tab,ttype[COL_AREAL8-1],nr,areal8);
298 
299  /* Get outta here */
300 
301  return(CASU_OK);
302 }
303 
306 /*
307 
308 $Log: create_table_3.c,v $
309 Revision 1.3 2015/08/12 11:16:55 jim
310 Modified procedure names to protect namespace
311 
312 Revision 1.2 2015/08/07 13:06:54 jim
313 Fixed copyright to ESO
314 
315 Revision 1.1.1.1 2015/06/12 10:44:32 jim
316 Initial import
317 
318 Revision 1.3 2015/01/09 11:42:36 jim
319 Fixed routines to remove globals
320 
321 Revision 1.2 2014/04/09 09:09:51 jim
322 Detabbed
323 
324 Revision 1.1.1.1 2013/08/27 12:07:48 jim
325 Imported
326 
327 
328 */
void imcore_areals(ap_t *ap, int iareal[NAREAL])
Work out the areal profiles for an object.
Definition: areals.c:67
int imcore_process_results_3(ap_t *ap, int *nobjects, cpl_table *tab)
Process results for type 3 catalogue.
void imcore_moments(ap_t *ap, float results[])
Do moments analysis on an object.
Definition: moments.c:65
int imcore_do_seeing_gen(ap_t *ap, const char *col_ellipt, const char *col_pkht, char *col_areals[NAREAL], int nobjects, cpl_table *tab)
Do seeing estimate (generic)
Definition: create_table.c:335
void imcore_tabinit_3(int *imcore_xcol, int *imcore_ycol, cpl_table **tab)
Initialise type 1 catalogue.
int imcore_do_seeing_3(ap_t *ap, int nobjects, cpl_table *tab)
Do seeing estimate for type 3 catalogue.
void imcore_tabinit_gen(int ncols, const char *ttype[], const char *tunit[], cpl_type tform[], cpl_table **tab)
Initialise tables (generic)
Definition: create_table.c:281