CR2RE Pipeline Reference Manual 1.6.8
hdrl_cat_moments.c
1/*
2 * This file is part of the HDRL
3 * Copyright (C) 2017 European Southern Observatory
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19
20#include "hdrl_cat_moments.h"
21
22
23/*---------------------------------------------------------------------------*/
31/*----------------------------------------------------------------------------*/
32
35/* ---------------------------------------------------------------------------*/
46/* ---------------------------------------------------------------------------*/
47void hdrl_moments(ap_t *ap, double results[]) {
48
49 /* Initialise a few things */
50 double xintmin = ap->xintmin;
51 plstruct *plarray = ap->plarray;
52 cpl_size np = ap->npl_pix;
53
54 double xoff = (double)(plarray[0].x);
55 double yoff = (double)(plarray[0].y);
56
57 double tmax = plarray[0].z;
58
59 double xsum = 0.;
60 double ysum = 0.;
61 double tsum = 0.;
62 double xsum_w = 0.;
63 double ysum_w = 0.;
64 double wsum = 0.;
65 double xsumsq = 0.;
66 double ysumsq = 0.;
67 double xysum = 0.;
68
69 /* Do a moments analysis on an object */
70 for (cpl_size i = 0; i < np; i++) {
71
72 double t = plarray[i].z;
73 if (t >= 0.) {
74
75 double w = plarray[i].zsm;
76
77 double x = (double)(plarray[i].x) - xoff;
78 double y = (double)(plarray[i].y) - yoff;
79
80 xsum += t * x;
81 ysum += t * y;
82 tsum += t;
83
84 xsum_w += w * t * x;
85 ysum_w += w * t * y;
86 wsum += w * t;
87
88 xsumsq += x * x * t;
89 ysumsq += y * y * t;
90 xysum += x * y * t;
91
92 tmax = CPL_MAX(tmax, plarray[i].z);
93 }
94 }
95
96 /* Check that the total intensity is enough and if it is, then do the final results */
97 if (tsum >= xintmin) {
98
99 double xbar = xsum / tsum;
100 double ybar = ysum / tsum;
101
102 double sxx = CPL_MAX(0., (xsumsq / tsum - xbar * xbar));
103 double syy = CPL_MAX(0., (ysumsq / tsum - ybar * ybar));
104 double sxy = xysum / tsum - xbar * ybar;
105
106 xbar = CPL_MAX(1., CPL_MIN(ap->lsiz, xoff + xsum_w / wsum));
107 ybar = CPL_MAX(1., CPL_MIN(ap->csiz, yoff + ysum_w / wsum));
108
109 results[0] = 1.;
110 results[1] = xbar;
111 results[2] = ybar;
112 results[3] = tsum;
113 results[4] = sxx;
114 results[5] = sxy;
115 results[6] = syy;
116 results[7] = tmax;
117
118 } else {
119
120 results[0] = -1.;
121 }
122}
123
void hdrl_moments(ap_t *ap, double results[])
Do moments analysis on an object in a Plessey array.