IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jun 8, 2011, 2:41:13 PM (15 years ago)
Author:
watersc1
Message:

compilable version of updated stack code (doesn't correctly reject) and asinh scaling (completely untested).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/czw_branch/20110406/psModules/src/imcombine/pmStack.c

    r31607 r31618  
    2222#include <pslib.h>
    2323
     24#include <gsl/gsl_cdf.h>
     25
    2426#include "pmHDU.h"
    2527#include "pmFPA.h"
     
    3537
    3638
    37 # if (0)
     39# if (1)
    3840#define TESTING                         // Enable test output
    39 #define TEST_X 3145                       // x coordinate to examine
    40 #define TEST_Y 2334                       // y coordinate to examine
     41#define TEST_X 5745                       // x coordinate to examine
     42#define TEST_Y 5331                       // y coordinate to examine
    4143#define TEST_RADIUS 0.5                 // Radius to examine
    4244# endif
     
    332334    memset (nGoodBits, 0, 16*sizeof(int));
    333335
    334     // Extract the pixel and mask data
     336
     337    // Extract the pixel and mask data   
    335338    int numGood = 0;                    // Number of good pixels
    336339    for (int i = 0, j = 0; i < inputs->n; i++) {
     
    364367            continue;
    365368        }
    366 
     369       
    367370        int xIn = x - data->readout->col0, yIn = y - data->readout->row0; // Coordinates on input readout
    368371        psImage *mask = data->readout->mask; // Mask of interest
     
    984987
    985988static void KMMcalculate(const psVector *values,
    986                          float *Punimodal,
     989                         float *Punimodal,int *iter,
    987990                         float *pi1, float *m1, float *s1,
    988991                         float *pi2, float *m2, float *s2) {
     
    10121015  float dL = 0;
    10131016  float oldL = -999;
    1014   int k = 0;
     1017  *iter = 0;
    10151018  logL_bimodal = logL_unimodal;
    10161019  *m1 = mU - 3 * sU;
     
    10241027  float w1,w2;
    10251028
    1026   while (((dL > KMM_TOLERANCE)||(k < 3))&&(k < KMM_MAX_ITERATIONS)) {
    1027     k++;
     1029  float KMM_TOLERANCE = 1e-6;
     1030  int KMM_MAX_ITERATIONS = 500;
     1031  float KMM_SMALL_NUMBER = 1e-5;
     1032  while (((dL > KMM_TOLERANCE)||(*iter < 3))&&(*iter < KMM_MAX_ITERATIONS)) {
     1033    *iter += 1;
    10281034    dL = fabs(logL_bimodal - oldL);
    10291035    oldL = logL_bimodal;
     
    10551061      *m2 += values->data.F32[i] * P2->data.F32[i];
    10561062
    1057       w1 += P1[i];
    1058       w2 += P2[i];
     1063      w1 += P1->data.F32[i];
     1064      w2 += P2->data.F32[i];
    10591065    }
    10601066    *m1 /= w1;
     
    10951101}
    10961102
    1097 static void KMMrejectUnpopular(const psVector *values, psArray *reject) {
     1103static void KMMRejectUnpopular(const psArray *inputs, int x, int y) {
     1104  float KMM_MINIMUM_PVALUE = 0.05;
    10981105  float Punimodal,pi1,m1,s1,pi2,m2,s2;
    1099   KMMcalculate(values,&Punimodal,
     1106  int iter;
     1107  int j;
     1108
     1109  psVector *values = psVectorAlloc(inputs->n, PS_TYPE_F32);
     1110  for (j = 0; j < inputs->n; j++) {
     1111    pmStackData *data = inputs->data[j]; // Stack data of interest
     1112    psImage *image = data->readout->image; // Image of interest
     1113    int xIn = x - data->readout->col0, yIn = y - data->readout->row0; // Coordinates on input readout
     1114    values->data.F32[j] = image->data.F32[yIn][xIn];
     1115  }
     1116 
     1117  KMMcalculate(values,&Punimodal,&iter,
    11001118               &pi1,&m1,&s1,
    11011119               &pi2,&m2,&s2);
     1120  //  fprintf(stderr,
     1121  psTrace("psModules.imcombine",3,
     1122          "KMM Unpopular Test: %d,%d: Puni: %f in %d",x,y,Punimodal,iter);
     1123  //  CHECKPIX(x, y, "
     1124 
    11021125  if (Punimodal < KMM_MINIMUM_PVALUE) {
    11031126    int i;
    1104     float g1,g2;
     1127    float g1,g2,norm;
    11051128    float P1,P2;
    11061129
     
    11121135      P2 = (pi2 * g2) / norm;
    11131136
     1137      CHECKPIX(x, y, "KMM Unpopular Rejection: %d,%d: %d %f %f:(%f %f %f ) %f:(%f %f %f) rejection? %d %d\n",
     1138               x, y, i, values->data.F32[i],
     1139               P1,m1,s1,pi1,
     1140               P2,m2,s2,pi2,
     1141               (pi1 > pi2)&&(P1 < P2),
     1142               (pi1 < pi2)&&(P1 > P2));
    11141143      if ((pi1 > pi2)&&(P1 < P2)) { // mode 1 is more popular, but this element belongs to mode 2
    1115         reject_input(reject,i);
     1144        combineMarkReject(inputs,x,y,i);
    11161145      }
    11171146      if ((pi1 < pi2)&&(P1 > P2)) { // mode 2 is more popular, but this element belongs to mode 1
    1118         reject_input(reject,i);
     1147        combineMarkReject(inputs,x,y,i);
    11191148      }
    11201149    }
    11211150  }
     1151  psFree(values);
    11221152  // else do nothing.
    11231153}
    11241154
    1125 static void KMMrejectBright(const psVector *values, psArray *reject) {
    1126   KMMcalculate(values,&Punimodal,
     1155static void KMMRejectBright(const psArray *inputs, int x, int y) {
     1156  float KMM_MINIMUM_PVALUE = 0.05;
     1157  float Punimodal,pi1,m1,s1,pi2,m2,s2;
     1158  int iter;
     1159  int j;
     1160
     1161  psVector *values = psVectorAlloc(inputs->n, PS_TYPE_F32);
     1162  for (j = 0; j < inputs->n; j++) {
     1163    pmStackData *data = inputs->data[j]; // Stack data of interest
     1164    psImage *image = data->readout->image; // Image of interest
     1165    int xIn = x - data->readout->col0, yIn = y - data->readout->row0; // Coordinates on input readout
     1166    values->data.F32[j] = image->data.F32[yIn][xIn];
     1167  }
     1168 
     1169  KMMcalculate(values,&Punimodal,&iter,
    11271170               &pi1,&m1,&s1,
    11281171               &pi2,&m2,&s2);
    11291172  if (Punimodal < KMM_MINIMUM_PVALUE) {
    11301173    int i;
    1131     float g1,g2;
     1174    float g1,g2,norm;
    11321175    float P1,P2;
    11331176
     
    11401183
    11411184      if ((m1 > m2)&&(P1 > P2)) { // m1 is larger, and this element belongs to mode 1
    1142         reject_input(reject,i);
     1185        combineMarkReject(inputs,x,y,i);
    11431186      }
    11441187      if ((m1 < m2)&&(P1 < P2)) { // m2 is larger, and this element belongs to mode 2
    1145         reject_input(reject,i);
     1188        combineMarkReject(inputs,x,y,i);
    11461189      }
    11471190    }
     
    13101353    }
    13111354
     1355    // Pre-reject inputs using KMM bimodality test.
     1356    if (1)  {
     1357/*       KMMRejectUnpopular(input,x,y); */
     1358      rejection = true;
     1359    }
     1360   
    13121361    // Set up rejection list
    13131362    psArray *pixelMap = NULL;           // Map of pixels to source
     
    13191368    for (int y = minInputRows; y < maxInputRows; y++) {
    13201369        for (int x = minInputCols; x < maxInputCols; x++) {
     1370
    13211371            CHECKPIX(x, y, "Combining pixel %d,%d: %x %x %f %f %f %f %d %d %d\n", x, y, badMaskBits, blankMaskBits, iter, rej, sys, olympic, useVariance, safe, rejection);
     1372
     1373            // Pre-reject inputs using KMM bimodality test.
     1374          if (1)  {
     1375            KMMRejectUnpopular(input,x,y);
     1376/*          rejection = true; */
     1377          }
     1378          else {
     1379            KMMRejectBright(input,x,y);
     1380          }
    13221381
    13231382#ifdef TESTING
Note: See TracChangeset for help on using the changeset viewer.