create_table_3.c

00001 /*
00002 
00003 $Id: create_table_3.c,v 1.8 2007/05/03 11:15:34 jim Exp $
00004 
00005 */
00006 
00007 #include <stdio.h>
00008 #include <math.h>
00009 #include "imcore.h"
00010 #include "util.h"
00011 #include "floatmath.h"
00012 
00013 /* Column numbers for each item to be stored */
00014 
00015 #define COL_NUMBER      1
00016 #define COL_X           2
00017 #define COL_Y           3
00018 #define COL_FLUXISO     4
00019 #define COL_PEAKHEIGHT  5
00020 #define COL_ELLIPT      6
00021 #define COL_SIGMA       7
00022 #define COL_PA          8
00023 #define COL_AREAL1      9
00024 #define COL_AREAL2     10
00025 #define COL_AREAL3     11
00026 #define COL_AREAL4     12
00027 #define COL_AREAL5     13
00028 #define COL_AREAL6     14
00029 #define COL_AREAL7     15
00030 #define COL_AREAL8     16
00031 
00032 /* Number of columns in the table */
00033 
00034 #define NCOLS 32
00035 
00036 /* Column definitions */
00037 
00038 static const char *ttype[NCOLS]={"No.","X_coordinate","Y_coordinate",
00039                                  "Isophotal_flux","Peak_height","Ellipticity",
00040                                  "Gaussian_sigma","Position_angle",
00041                                  "Areal_1_profile","Areal_2_profile","Areal_3_profile",
00042                                  "Areal_4_profile","Areal_5_profile","Areal_6_profile",
00043                                  "Areal_7_profile","Areal_8_profile",
00044                                  "Blank","Blank","Blank","Blank","Blank","Blank",
00045                                  "Blank","Blank","Blank","Blank","Blank","Blank",
00046                                  "Blank","Blank","Blank","Blank"};
00047 static const char *tunit[NCOLS]={" ","Pixels","Pixels","Counts","Counts"," ",
00048                                  "Pixels","Degrees","Pixels","Pixels","Pixels",
00049                                  "Pixels","Pixels","Pixels","Pixels","Pixels",
00050                                  "Blank","Blank","Blank","Blank","Blank","Blank",
00051                                  "Blank","Blank","Blank","Blank","Blank","Blank",
00052                                  "Blank","Blank","Blank","Blank"};
00053 
00054 static cpl_type tform[NCOLS]={CPL_TYPE_INT,CPL_TYPE_FLOAT,CPL_TYPE_FLOAT,
00055                               CPL_TYPE_FLOAT,CPL_TYPE_FLOAT,CPL_TYPE_FLOAT,
00056                               CPL_TYPE_FLOAT,CPL_TYPE_FLOAT,CPL_TYPE_FLOAT,
00057                               CPL_TYPE_FLOAT,CPL_TYPE_FLOAT,CPL_TYPE_FLOAT,
00058                               CPL_TYPE_FLOAT,CPL_TYPE_FLOAT,CPL_TYPE_FLOAT,
00059                               CPL_TYPE_FLOAT,CPL_TYPE_FLOAT,CPL_TYPE_FLOAT,
00060                               CPL_TYPE_FLOAT,CPL_TYPE_FLOAT,CPL_TYPE_FLOAT,
00061                               CPL_TYPE_FLOAT,CPL_TYPE_FLOAT,CPL_TYPE_FLOAT,
00062                               CPL_TYPE_FLOAT,CPL_TYPE_FLOAT,CPL_TYPE_FLOAT,
00063                               CPL_TYPE_FLOAT,CPL_TYPE_FLOAT,CPL_TYPE_FLOAT,
00064                               CPL_TYPE_FLOAT,CPL_TYPE_FLOAT};
00065 
00066 static int areal_cols[NAREAL] = {COL_AREAL1,COL_AREAL2,COL_AREAL3,COL_AREAL4,
00067                                  COL_AREAL5,COL_AREAL6,COL_AREAL7,COL_AREAL8};
00068 
00069 extern void tabinit_3(void) {
00070 
00071     /* Call the generic routine to open a new output table */
00072 
00073     tabinit_gen(NCOLS,ttype,tunit,tform);
00074 
00075     /* RA and DEC columns are undefined */
00076 
00077     imcore_xcol = COL_X;
00078     imcore_ycol = COL_Y;
00079 }
00080 
00081 extern int do_seeing_3(ap_t *ap) {
00082     int retval,i;
00083     char *areal_colnames[NAREAL];
00084 
00085     /* Sort out the areal profile column names */
00086 
00087     for (i = 0; i < NAREAL; i++) 
00088         areal_colnames[i] = (char *)ttype[areal_cols[i]-1];
00089  
00090     /* Just call the generic seeing routine */
00091  
00092     retval = do_seeing_gen(ap,ttype[COL_ELLIPT-1],ttype[COL_PEAKHEIGHT-1],
00093                            areal_colnames);
00094 
00095     /* Get out of here */
00096  
00097     return(retval);
00098 }
00099         
00100 
00101 extern int process_results_3(ap_t *ap) {
00102     float momresults[8],parmall[NPAR];
00103     float sxx,syy,srr,sxy,ecc,temp,xx,theta,radeg,ell;
00104     float yy,sigma,peak,areal1,iso_flux;
00105     float areal2,areal3,areal4,areal5,areal6,areal7,areal8,aa,bb;
00106     int iareal[NAREAL],i,k,nn,nr;
00107     long nrows;
00108     plstruct *pl;
00109     unsigned char *mflag;
00110 
00111     /* Do a basic moments analysis and work out the areal profiles*/
00112 
00113     moments(ap,momresults);
00114     if (momresults[0] < 0)
00115         return(VIR_FATAL);
00116     areals(ap,iareal);
00117 
00118     /* See if this object makes the cut in terms of its size.  If not, then
00119        just return with good status */
00120 
00121     if (iareal[0] < ap->ipnop || momresults[3] < ap->xintmin)
00122         return(VIR_OK);
00123 
00124     /* Try and deblend the images if it is requested and justified */
00125 
00126     parmall[0] = momresults[3];
00127     parmall[1] = momresults[1];
00128     parmall[2] = momresults[2];
00129     parmall[3] = ap->thresh;
00130     for (i = 4; i < 8; i++) 
00131         parmall[i] = momresults[i];
00132     for (i = 0; i < NAREAL; i++)
00133         parmall[i+8] = (float)iareal[i];
00134 
00135     /* Massage the results and write them to the fits table */
00136 
00137     radeg = 180.0/M_PI;
00138     sxx = parmall[4];
00139     sxy = parmall[5];
00140     syy = parmall[6];    
00141     if(sxy > 0.0)
00142       sxy = MAX(1.0e-4,MIN(sxy,sqrtf(sxx*syy)));
00143     else
00144       sxy = MIN(-1.0e-4,MAX(sxy,-sqrtf(sxx*syy)));
00145 
00146     srr = MAX(0.5,sxx+syy);
00147     ecc = sqrtf((syy-sxx)*(syy-sxx)+4.0*sxy*sxy)/srr;
00148     temp = MAX((1.0-ecc)/(1.0+ecc),0.0);
00149     ell = 1.0 - sqrtf(temp);
00150     ell = MIN(0.99,MAX(0.0,ell));
00151     xx = 0.5*(1.0+ecc)*srr-sxx;
00152     if(xx == 0.0)
00153         theta = 0.0;
00154     else
00155         theta = 90.0-radeg*atanf(sxy/xx);
00156 
00157     /* Create a list of values */
00158 
00159     nrows = cpl_table_get_nrow(tab);
00160     nobjects++;
00161     if (nobjects > nrows) 
00162         (void)cpl_table_set_size(tab,nrows+INITROWS);
00163     nr = nobjects - 1;
00164     iso_flux = parmall[0];
00165     xx = parmall[1];
00166     yy = parmall[2];
00167     sigma = sqrt(srr);
00168     peak = parmall[7];
00169     areal1 = parmall[8];
00170     areal2 = parmall[9];
00171     areal3 = parmall[10];
00172     areal4 = parmall[11];
00173     areal5 = parmall[12];
00174     areal6 = parmall[13];
00175     areal7 = parmall[14];
00176     areal8 = parmall[15];
00177 
00178     /* Store away the results for this object */
00179 
00180     cpl_table_set_int(tab,ttype[COL_NUMBER-1],nr,nr);
00181     cpl_table_set_float(tab,ttype[COL_X-1],nr,xx);
00182     cpl_table_set_float(tab,ttype[COL_Y-1],nr,yy);
00183     cpl_table_set_float(tab,ttype[COL_FLUXISO-1],nr,iso_flux);
00184     cpl_table_set_float(tab,ttype[COL_PEAKHEIGHT-1],nr,peak);
00185     cpl_table_set_float(tab,ttype[COL_ELLIPT-1],nr,ell);
00186     cpl_table_set_float(tab,ttype[COL_SIGMA-1],nr,sigma);
00187     cpl_table_set_float(tab,ttype[COL_PA-1],nr,theta);
00188     cpl_table_set_float(tab,ttype[COL_AREAL1-1],nr,areal1);
00189     cpl_table_set_float(tab,ttype[COL_AREAL2-1],nr,areal2);
00190     cpl_table_set_float(tab,ttype[COL_AREAL3-1],nr,areal3);
00191     cpl_table_set_float(tab,ttype[COL_AREAL4-1],nr,areal4);
00192     cpl_table_set_float(tab,ttype[COL_AREAL5-1],nr,areal5);
00193     cpl_table_set_float(tab,ttype[COL_AREAL6-1],nr,areal6);
00194     cpl_table_set_float(tab,ttype[COL_AREAL7-1],nr,areal7);
00195     cpl_table_set_float(tab,ttype[COL_AREAL8-1],nr,areal8);
00196 
00197     /* Write out the .ell file info... */
00198 
00199     if (ellfp != NULL) {
00200         aa = sqrtf(areal1/(M_PI*(1.0 - ell)));
00201         bb = aa*(1.0 - ell);
00202         fprintf(ellfp,"image; ellipse %9.3f %9.3f %7.2f %7.2f %6.1f\n",
00203                 xx,yy,aa,bb,theta);
00204     }
00205 
00206     /* Flag all pixels as object pixels */
00207 
00208     pl = ap->plarray;
00209     mflag = ap->mflag;
00210     for (k = 0; k < ap->npl_pix; k++) {
00211         nn = ap->lsiz*(pl[k].y - 1) + pl[k].x - 1;
00212         mflag[nn] = MF_POBJPIX;
00213     }
00214 
00215     /* Get outta here */
00216 
00217     return(VIR_OK);
00218 }
00219 
00220 
00221 /*
00222 
00223 $Log: create_table_3.c,v $
00224 Revision 1.8  2007/05/03 11:15:34  jim
00225 Fixed little problem with table wcs
00226 
00227 Revision 1.7  2007/05/02 09:11:35  jim
00228 Modified to allow for inclusion of table WCS keywords into FITS header
00229 
00230 Revision 1.6  2007/03/01 12:38:26  jim
00231 Small modifications after a bit of code checking
00232 
00233 Revision 1.5  2006/05/30 12:14:08  jim
00234 Fixed indexing bug in table that was causing a memory overwrite
00235 
00236 Revision 1.4  2005/11/25 09:56:15  jim
00237 Tidied up some more documentation
00238 
00239 Revision 1.3  2005/09/22 08:40:42  jim
00240 Fixed some bugs in imcore and added classification Removed some unnecessary
00241 files
00242 
00243 Revision 1.2  2005/09/20 15:07:47  jim
00244 Fixed a few bugs and added a few things
00245 
00246 Revision 1.1  2005/09/13 13:25:28  jim
00247 Initial entry after modifications to make cpl compliant
00248 
00249 
00250 */

Generated on Wed Apr 10 04:01:54 2013 for VIRCAM Pipeline by  doxygen 1.5.1