moments.c

00001 /* $Id: moments.c,v 1.3 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.3 $
00025  * $Name: vcam-1_3_0 $
00026  */
00027 
00028 #include <stdio.h>
00029 #include <stdlib.h>
00030 
00031 #include "imcore.h"
00032 #include "util.h"
00033 
00036 /*---------------------------------------------------------------------------*/
00063 /*---------------------------------------------------------------------------*/
00064 
00065 extern void moments(ap_t *ap, float results[]) {
00066     int i,np;
00067     float x,y,xoff,yoff,xsum,ysum,xsumsq,ysumsq,tsum,xysum,t,tmax,twelfth;
00068     float xbar,ybar,sxx,syy,sxy,xintmin,w,wsum,xsum_w,ysum_w;
00069     plstruct *plarray;
00070 
00071     /* Initialise a few things */
00072 
00073     xintmin = ap->xintmin;
00074     plarray = ap->plarray;
00075     np = ap->npl_pix;
00076     xoff = (float)plarray[0].x;
00077     yoff = (float)plarray[0].y;
00078     xsum = 0.0;
00079     ysum = 0.0;
00080     xsum_w = 0.0;
00081     ysum_w = 0.0;
00082     wsum = 0.0;
00083     xsumsq = 0.0;
00084     ysumsq = 0.0;
00085     tsum = 0.0;
00086     xysum = 0.0;
00087     tmax = plarray[0].z;
00088     twelfth = 1.0/12.0;
00089 
00090     /* Do a moments analysis on an object */
00091 
00092     for (i = 0; i < np; i++) {
00093         x = (float)plarray[i].x - xoff;
00094         y = (float)plarray[i].y - yoff;
00095         t = plarray[i].z;
00096         w = plarray[i].zsm; 
00097         if (t < 0.0)
00098             continue;
00099         xsum += t*x;
00100         ysum += t*y;
00101         tsum += t;
00102         xsum_w += w*t*x;
00103         ysum_w += w*t*y;
00104         wsum += w*t;
00105         tmax = MAX(tmax,plarray[i].z);
00106         xsumsq += (x*x + twelfth)*t;
00107         ysumsq += (y*y + twelfth)*t;
00108         xysum += x*y*t;
00109     }
00110 
00111     /* Check that the total intensity is enough and if it is, then do
00112        the final results */
00113 
00114     if (tsum >= xintmin) {
00115         xbar = xsum/tsum;
00116         ybar = ysum/tsum;
00117         sxx = MAX(0.0,(xsumsq/tsum-xbar*xbar));
00118         syy = MAX(0.0,(ysumsq/tsum-ybar*ybar));
00119         sxy = xysum/tsum - xbar*ybar;
00120         xbar = xsum_w/wsum;
00121         ybar = ysum_w/wsum;
00122         xbar += xoff;
00123         ybar += yoff;
00124         xbar = MAX(1.0,MIN(xbar,ap->lsiz));
00125         ybar = MAX(1.0,MIN(ybar,ap->csiz));
00126         results[0] = 1.0;
00127         results[1] = xbar;
00128         results[2] = ybar;
00129         results[3] = tsum;
00130         results[4] = sxx;
00131         results[5] = sxy;
00132         results[6] = syy;
00133         results[7] = tmax;
00134     } else {
00135         results[0] = -1.0;
00136     }
00137 }
00138 
00141 /*
00142 
00143 $Log: moments.c,v $
00144 Revision 1.3  2010/09/09 12:09:57  jim
00145 Added docs
00146 
00147 Revision 1.2  2006/08/21 09:07:29  jim
00148 Modified centring algorithm
00149 
00150 Revision 1.1  2005/09/13 13:25:30  jim
00151 Initial entry after modifications to make cpl compliant
00152 
00153 
00154 */

Generated on 15 Mar 2012 for VIRCAM Pipeline by  doxygen 1.6.1