32 #include "imcore_radii.h"
33 #include "floatmath.h"
37 static float fraction (
float x,
float y,
float r_out);
77 float peak,
int naper) {
86 for (i = 0; i < naper; i++) {
87 if (cflux[i] > halflight) {
98 delr = (cflux[i] - halflight)/MAX(1.0,cflux[i]-peak);
99 halfrad = rcores[0]*(1.0 - delr) + delr*sqrt(1.0/M_PI);
101 delr = (cflux[i] - halflight)/MAX(1.0,(cflux[i] - cflux[i-1]));
102 halfrad = rcores[i-1]*delr + rcores[i]*(1.0-delr);
143 float rcores[],
int naper) {
148 pk = MAX(1.5*thresh,peak);
149 r_t = sqrtf(areal0/CPL_MATH_PI);
150 rad = 5.0*r_t/logf(pk/thresh);
151 rad = MAX(r_t,MIN(5.0*r_t,MIN(rad,rcores[naper-1])));
191 float r_t,rad,wt,sum;
195 r_t = sqrtf(areal0/CPL_MATH_PI);
196 rad = 0.5*rcores[0]*cflux[0];
199 for (i = 1; i < imax; i++) {
200 wt = MAX(0.0,cflux[i]-cflux[i-1]);
201 rad += 0.5*(rcores[i] + rcores[i-1])*wt;
205 rad = MAX(r_t,MIN(5.0*r_t,MIN(2.0*rad,rcores[naper-1])));
245 float eta,r_t,etaold,r1,r2,r3,r4,r5,r_petr;
249 r_t = sqrtf(areal0/CPL_MATH_PI);
253 while (eta > 0.2 && j < naper) {
255 r1 = rcores[j]*rcores[j]/(rcores[j-1]*rcores[j-1]) - 1.0;
256 r2 = cflux[j]/cflux[j-1] - 1.0;
261 r_petr = rcores[naper-1];
263 r1 = rcores[j]*rcores[j];
264 r2 = rcores[j-1]*rcores[j-1];
265 r3 = rcores[j-2]*rcores[j-2];
266 r4 = (etaold - 0.2)/(etaold - eta);
267 r5 = (0.2 - eta)/(etaold - eta);
268 r_petr = r4*sqrt(0.5*(r1 + r2)) + r5*sqrt(0.5*(r2 + r3));
270 r_petr = MAX(r_t,MIN(5.0*r_t,MIN(2.0*r_petr,rcores[naper-1])));
316 void imcore_flux(ap_t *ap,
float parm[IMNUM][NPAR],
int nbit,
float apers[],
317 float fluxes[],
int nr,
float rcores[],
float rfluxes[]) {
318 float *map,t,xj,yj,sumiso,sumcf,delr;
319 unsigned char *mflag,mf;
321 int xmin,xmax,ymin,ymax,ix1,ix2,iy1,iy2,i,j,kk,n;
336 xmin = parm[0][1] - apers[0] - 0.5;
337 xmax = parm[0][1] + apers[0] + 0.5;
338 ymin = parm[0][2] - apers[0] - 0.5;
339 ymax = parm[0][2] + apers[0] + 0.5;
340 ix1 = MAX(0,(
int)xmin-1);
341 ix2 = MIN(nx-1,(
int)xmax);
342 iy1 = MAX(0,(
int)ymin-1);
343 iy2 = MIN(ny-1,(
int)ymax);
349 for(j = iy1; j <= iy2; j++) {
351 for(i = ix1; i <= ix2; i++) {
353 if (mf == MF_CLEANPIX || mf == MF_OBJPIX ||
354 mf == MF_SATURATED) {
356 xj = (float)i - parm[0][1] + 1.0;
357 yj = (float)j - parm[0][2] + 1.0;
358 fluxes[0] += fraction(xj,yj,apers[0])*t;
363 fluxes[0] = parm[0][0];
373 for (j = 0; j < nbit; j++) {
374 sumiso += parm[j][0];
376 while (rcores[n] < apers[j] && n < nr-1)
378 delr = (rcores[n] - apers[j])/(rcores[n] - rcores[n-1]);
379 fluxes[j] = rfluxes[j*nr+n]*(1.0 - delr) + rfluxes[j*nr+n-1]*delr;
386 for (j = 0; j < nbit; j++) {
387 fluxes[j] = sumcf*parm[j][0]/MAX(1.0,sumiso);
389 fluxes[j] = parm[j][0];
400 static float fraction (
float x,
float y,
float r_out) {
401 float r,t,x_a,x_b,frac,tanao2,cosa,tanp2a,sqrt2o2;
403 r = sqrtf(x*x + y*y);
404 sqrt2o2 = 0.5*CPL_MATH_SQRT2;
408 if(r > r_out+sqrt2o2)
413 if(r < r_out-sqrt2o2)
429 if (x > 0.0 && y > 0.0) {
432 cosa = x/sqrt(x*x + y*y);
441 x_a = x - tanao2 + (r_out - r)/cosa;
446 x_b = x + tanao2 + (r_out - r)/cosa;
451 frac = 0.5*MAX(0.0,x_b-(x-0.5))*MAX(0.0,x_b-(x-0.5))*tanp2a;
454 frac = 1.0 - 0.5*(x+0.5-x_a)*(x+0.5-x_a)*tanp2a;
456 frac = 0.5-(x-x_a)+0.5*(x_b-x_a);
void imcore_flux(ap_t *ap, float parm[IMNUM][NPAR], int nbit, float apers[], float fluxes[], int nr, float rcores[], float rfluxes[])
Work out the fluxes for special radii.
float imcore_halflight(float rcores[], float cflux[], float halflight, float peak, int naper)
Work out the half-light radius for an object.
float imcore_petrad(float areal0, float rcores[], float cflux[], int naper)
Work out the Petrosian.
float imcore_exprad(float thresh, float peak, float areal0, float rcores[], int naper)
Work out the exponential radius for an object.
float imcore_kronrad(float areal0, float rcores[], float cflux[], int naper)
Work out the Kron radius for an object.