00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #include <stdio.h>
00029 #include <math.h>
00030 #include "imcore.h"
00031 #include "util.h"
00032 #include "floatmath.h"
00033
00034
00035
00036 #define COL_NUMBER 1
00037 #define COL_FLUXISO 2
00038 #define COL_FLUXTOTAL 3
00039 #define COL_APFLUX1 4
00040 #define COL_X 5
00041 #define COL_Y 6
00042 #define COL_SIGMA 7
00043 #define COL_ELLIPT 8
00044 #define COL_PA 9
00045 #define COL_PEAKHEIGHT 10
00046 #define COL_AREAL1 11
00047 #define COL_AREAL2 12
00048 #define COL_AREAL3 13
00049 #define COL_AREAL4 14
00050 #define COL_AREAL5 15
00051 #define COL_AREAL6 16
00052 #define COL_AREAL7 17
00053 #define COL_AREAL8 18
00054 #define COL_APFLUX2 19
00055 #define COL_APFLUX3 20
00056 #define COL_APFLUX4 21
00057 #define COL_APFLUX5 22
00058 #define COL_RA 23
00059 #define COL_DEC 24
00060 #define COL_CLASS 25
00061 #define COL_STAT 26
00062 #define COL_APFLUX6 27
00063 #define COL_SKYLEV 28
00064 #define COL_SKYRMS 29
00065
00066
00067
00068 #define NCOLS 32
00069
00070
00071
00072 #define NRADS 6
00073 static float rmults[] = {0.5,1.0,CPL_MATH_SQRT2,2.0,2.0*CPL_MATH_SQRT2,4.0};
00074 static int nrcore = 1;
00075 static float apertures[NRADS];
00076
00077
00078
00079 static const char *ttype[NCOLS]={"No.","Isophotal_flux","Total_flux","Core_flux",
00080 "X_coordinate","Y_coordinate","Gaussian_sigma",
00081 "Ellipticity","Position_angle","Peak_height",
00082 "Areal_1_profile","Areal_2_profile","Areal_3_profile",
00083 "Areal_4_profile","Areal_5_profile","Areal_6_profile",
00084 "Areal_7_profile","Areal_8_profile","Core1_flux",
00085 "Core2_flux","Core3_flux","Core4_flux",
00086 "RA","DEC","Classification","Statistic",
00087 "Core5_flux","Skylev",
00088 "Skyrms","Blank_30","Blank_31","Blank_32"};
00089 static const char *tunit[NCOLS]={" ","Counts","Counts","Counts","Pixels","Pixels",
00090 "Pixels"," ","Degrees","Counts","Pixels","Pixels",
00091 "Pixels","Pixels","Pixels","Pixels","Pixels","Pixels",
00092 "Counts","Counts","Counts","Counts",
00093 "Degrees","Degrees","Flag","N-sigma",
00094 "Counts","Counts","Counts","Blank_30",
00095 "Blank_31","Blank_32"};
00096 static cpl_type tform[NCOLS]={CPL_TYPE_INT,CPL_TYPE_FLOAT,CPL_TYPE_FLOAT,
00097 CPL_TYPE_FLOAT,CPL_TYPE_FLOAT,CPL_TYPE_FLOAT,
00098 CPL_TYPE_FLOAT,CPL_TYPE_FLOAT,CPL_TYPE_FLOAT,
00099 CPL_TYPE_FLOAT,CPL_TYPE_FLOAT,CPL_TYPE_FLOAT,
00100 CPL_TYPE_FLOAT,CPL_TYPE_FLOAT,CPL_TYPE_FLOAT,
00101 CPL_TYPE_FLOAT,CPL_TYPE_FLOAT,CPL_TYPE_FLOAT,
00102 CPL_TYPE_FLOAT,CPL_TYPE_FLOAT,CPL_TYPE_FLOAT,
00103 CPL_TYPE_FLOAT,CPL_TYPE_FLOAT,CPL_TYPE_FLOAT,
00104 CPL_TYPE_FLOAT,CPL_TYPE_FLOAT,CPL_TYPE_FLOAT,
00105 CPL_TYPE_FLOAT,CPL_TYPE_FLOAT,CPL_TYPE_FLOAT,
00106 CPL_TYPE_FLOAT,CPL_TYPE_FLOAT};
00107
00108 static int areal_cols[NAREAL] = {COL_AREAL1,COL_AREAL2,COL_AREAL3,COL_AREAL4,
00109 COL_AREAL5,COL_AREAL6,COL_AREAL7,COL_AREAL8};
00112
00134
00135
00136 extern void tabinit_1(void) {
00137
00138
00139
00140 tabinit_gen(NCOLS,ttype,tunit,tform);
00141
00142
00143
00144 imcore_xcol = COL_X;
00145 imcore_ycol = COL_Y;
00146 }
00147
00148
00173
00174
00175 extern int do_seeing_1(ap_t *ap) {
00176 int retval,i;
00177 char *areal_colnames[NAREAL];
00178
00179
00180
00181 for (i = 0; i < NAREAL; i++)
00182 areal_colnames[i] = (char *)ttype[areal_cols[i]-1];
00183
00184
00185
00186 retval = do_seeing_gen(ap,ttype[COL_ELLIPT-1],ttype[COL_PEAKHEIGHT-1],
00187 areal_colnames);
00188
00189
00190
00191 return(retval);
00192 }
00193
00194
00221
00222
00223 extern int process_results_1(ap_t *ap) {
00224 float momresults[8],ttotal,parmall[IMNUM][NPAR],ratio,cflux[NRADS*IMNUM];
00225 float sxx,syy,srr,sxy,ecc,temp,xx,theta,radeg,ell,iso_flux,total_flux;
00226 float apflux1,apflux2,apflux3,apflux4,apflux5,yy,sigma,peak,areal1,apflux6;
00227 float areal2,areal3,areal4,areal5,areal6,areal7,areal8;
00228 float skylev,skyrms,badpix[IMNUM];
00229 int iareal[NAREAL],nbit,i,k,nr,mbit,j;
00230 long nrows;
00231
00232
00233
00234 moments(ap,momresults);
00235 if (momresults[0] < 0)
00236 return(VIR_FATAL);
00237 areals(ap,iareal);
00238
00239
00240
00241
00242 if (iareal[0] < ap->ipnop || momresults[3] < ap->xintmin)
00243 return(VIR_OK);
00244
00245
00246
00247 extend(ap,momresults[3],momresults[1],momresults[2],
00248 momresults[4],momresults[5],momresults[6],
00249 (float)iareal[0],momresults[7],&ttotal);
00250 ratio = MAX(ttotal,momresults[3])/momresults[3];
00251
00252
00253
00254 if (iareal[0] >= ap->mulpix && ap->icrowd)
00255 overlp(ap,parmall,&nbit,momresults[1],momresults[2],
00256 momresults[3],iareal[0],momresults[7]);
00257 else
00258 nbit = 1;
00259 if (nbit == 1) {
00260 parmall[0][0] = momresults[3];
00261 parmall[0][1] = momresults[1];
00262 parmall[0][2] = momresults[2];
00263 parmall[0][3] = ap->thresh;
00264 for (i = 4; i < 8; i++)
00265 parmall[0][i] = momresults[i];
00266 for (i = 0; i < NAREAL; i++)
00267 parmall[0][i+8] = (float)iareal[i];
00268 } else {
00269 mbit = 0;
00270 for (i = 0; i < nbit; i++) {
00271 if (parmall[i][1] > 1.0 && parmall[i][1] < ap->lsiz &&
00272 parmall[i][2] > 1.0 && parmall[i][2] < ap->csiz) {
00273 for (j = 0; j < NPAR; j++)
00274 parmall[mbit][j] = parmall[i][j];
00275 mbit++;
00276 }
00277 }
00278 nbit = mbit;
00279 }
00280
00281
00282
00283 for (i = 0; i < NRADS; i++)
00284 apertures[i] = rmults[i]*(ap->rcore);
00285
00286
00287
00288 for (i = 0; i < nbit; i++)
00289 badpix[i] = 0.0;
00290
00291
00292
00293 phopt(ap,parmall,nbit,NRADS,apertures,cflux,badpix,nrcore);
00294
00295
00296
00297 radeg = 180.0/CPL_MATH_PI;
00298 for (k = 0; k < nbit; k++) {
00299 sxx = parmall[k][4];
00300 sxy = parmall[k][5];
00301 syy = parmall[k][6];
00302 if(sxy > 0.0)
00303 sxy = MAX(1.0e-4,MIN(sxy,sqrtf(sxx*syy)));
00304 else
00305 sxy = MIN(-1.0e-4,MAX(sxy,-sqrtf(sxx*syy)));
00306
00307 srr = MAX(0.5,sxx+syy);
00308 ecc = sqrtf((syy-sxx)*(syy-sxx)+4.0*sxy*sxy)/srr;
00309 temp = MAX((1.0-ecc)/(1.0+ecc),0.0);
00310 ell = 1.0 - sqrtf(temp);
00311 ell = MIN(0.99,MAX(0.0,ell));
00312 xx = 0.5*(1.0+ecc)*srr-sxx;
00313 if(xx == 0.0)
00314 theta = 0.0;
00315 else
00316 theta = 90.0-radeg*atanf(sxy/xx);
00317
00318
00319
00320 nrows = cpl_table_get_nrow(tab);
00321 nobjects++;
00322 if (nobjects > nrows)
00323 (void)cpl_table_set_size(tab,nrows+INITROWS);
00324 nr = nobjects - 1;
00325 iso_flux = parmall[k][0];
00326 total_flux = ratio*parmall[k][0];
00327 apflux1 = cflux[k*NRADS + 0];
00328 apflux2 = cflux[k*NRADS + 1];
00329 apflux3 = cflux[k*NRADS + 2];
00330 apflux4 = cflux[k*NRADS + 3];
00331 apflux5 = cflux[k*NRADS + 4];
00332 apflux6 = cflux[k*NRADS + 5];
00333 xx = parmall[k][1];
00334 yy = parmall[k][2];
00335 sigma = sqrt(srr);
00336 peak = parmall[k][7];
00337 areal1 = parmall[k][8];
00338 areal2 = parmall[k][9];
00339 areal3 = parmall[k][10];
00340 areal4 = parmall[k][11];
00341 areal5 = parmall[k][12];
00342 areal6 = parmall[k][13];
00343 areal7 = parmall[k][14];
00344 if (nbit > 1 && k == 0)
00345 areal8 = 0.0;
00346 else
00347 areal8 = parmall[k][15];
00348 imcore_backest(ap,xx,yy,&skylev,&skyrms);
00349
00350
00351
00352 cpl_table_set_int(tab,ttype[COL_NUMBER-1],nr,nobjects);
00353 cpl_table_set_float(tab,ttype[COL_FLUXISO-1],nr,iso_flux);
00354 cpl_table_set_float(tab,ttype[COL_FLUXTOTAL-1],nr,total_flux);
00355 cpl_table_set_float(tab,ttype[COL_APFLUX1-1],nr,apflux2);
00356 cpl_table_set_float(tab,ttype[COL_X-1],nr,xx);
00357 cpl_table_set_float(tab,ttype[COL_Y-1],nr,yy);
00358 cpl_table_set_float(tab,ttype[COL_SIGMA-1],nr,sigma);
00359 cpl_table_set_float(tab,ttype[COL_ELLIPT-1],nr,ell);
00360 cpl_table_set_float(tab,ttype[COL_PA-1],nr,theta);
00361 cpl_table_set_float(tab,ttype[COL_PEAKHEIGHT-1],nr,peak);
00362 cpl_table_set_float(tab,ttype[COL_AREAL1-1],nr,areal1);
00363 cpl_table_set_float(tab,ttype[COL_AREAL2-1],nr,areal2);
00364 cpl_table_set_float(tab,ttype[COL_AREAL3-1],nr,areal3);
00365 cpl_table_set_float(tab,ttype[COL_AREAL4-1],nr,areal4);
00366 cpl_table_set_float(tab,ttype[COL_AREAL5-1],nr,areal5);
00367 cpl_table_set_float(tab,ttype[COL_AREAL6-1],nr,areal6);
00368 cpl_table_set_float(tab,ttype[COL_AREAL7-1],nr,areal7);
00369 cpl_table_set_float(tab,ttype[COL_AREAL8-1],nr,areal8);
00370 cpl_table_set_float(tab,ttype[COL_APFLUX2-1],nr,apflux1);
00371 cpl_table_set_float(tab,ttype[COL_APFLUX3-1],nr,apflux3);
00372 cpl_table_set_float(tab,ttype[COL_APFLUX4-1],nr,apflux4);
00373 cpl_table_set_float(tab,ttype[COL_APFLUX5-1],nr,apflux5);
00374 cpl_table_set_float(tab,ttype[COL_APFLUX6-1],nr,apflux6);
00375 cpl_table_set_float(tab,ttype[COL_SKYLEV-1],nr,skylev);
00376 cpl_table_set_float(tab,ttype[COL_SKYRMS-1],nr,skyrms);
00377 }
00378
00379
00380
00381 return(VIR_OK);
00382 }
00383
00386
00387
00388
00389
00390
00391
00392
00393
00394
00395
00396
00397
00398
00399
00400
00401
00402
00403
00404
00405
00406
00407
00408
00409
00410
00411
00412
00413
00414
00415
00416
00417
00418
00419
00420
00421
00422
00423
00424
00425
00426
00427
00428
00429
00430
00431
00432
00433
00434
00435
00436
00437