IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 34800 for trunk/psModules


Ignore:
Timestamp:
Dec 11, 2012, 2:04:31 PM (13 years ago)
Author:
watersc1
Message:

Merge from my branch including background restoration and stack stage projection cell binned images.

Location:
trunk
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/psModules

  • trunk/psModules/src/camera/pmFPABin.c

    r24906 r34800  
    4343    }
    4444
     45    int Nbits = (int) (ceil(log(maskVal)/log(2)) + 1);
     46    int *bitcounter = malloc(sizeof(int) * Nbits);
     47    int pxlcount;
     48
    4549    int xLast = numColsIn - 1, yLast = numRowsIn - 1; // Last index
    4650    int yStart = psImageBinningGetFineY(binning, 0); // Starting input y for binning
     
    5559            float sum = 0.0;            // Sum of pixels
    5660            int numPix = 0;             // Number of pixels
     61
     62            for (int j = 0; j < Nbits; j++) { // Reset bit counter
     63              bitcounter[j] = 0;
     64            }
     65            pxlcount = 0;
     66           
    5767            for (int y = yStart; y < yStop; y++) {
    5868                for (int x = xStart; x < xStop; x++) {
     69                  if (inMask && (inMask->data.PS_TYPE_IMAGE_MASK_DATA[y][x] != 0)) {
     70                      for (int j = 0; j < Nbits; j++) {
     71                        psImageMaskType M = (psImageMaskType) pow(2,j);
     72                        if (inMask->data.PS_TYPE_IMAGE_MASK_DATA[y][x] & M) {
     73                          bitcounter[j]++;
     74                        }
     75                      }
     76                    }
     77                 
    5978                    if (inMask && (inMask->data.PS_TYPE_IMAGE_MASK_DATA[y][x] & maskVal)) {
    6079                        continue;
     
    6584                    sum += inImage->data.F32[y][x];
    6685                    numPix++;
     86
     87
    6788                }
    6889            }
    69 
     90           
     91           
    7092            // Values to set
    7193            float imageValue;
     
    79101            }
    80102            outImage->data.F32[yOut][xOut] = imageValue;
    81             outMask->data.PS_TYPE_IMAGE_MASK_DATA[yOut][xOut] = maskValue;
     103            //            outMask->data.PS_TYPE_IMAGE_MASK_DATA[yOut][xOut] = maskValue;
     104            outMask->data.PS_TYPE_IMAGE_MASK_DATA[yOut][xOut] = 0;
     105            for (int j = 0; j < Nbits; j++) {
     106              if (bitcounter[j] > 0.5 * pxlcount) {
     107                outMask->data.PS_TYPE_IMAGE_MASK_DATA[yOut][xOut] |= (int) pow(2,j);
     108              }
     109            }
    82110            xStart = xStop;
    83111        }
  • trunk/psModules/src/camera/pmFPAfileIO.c

    r34403 r34800  
    7676    while ((item = psMetadataGetAndIncrement (iter)) != NULL) {
    7777        pmFPAfile *file = item->data.V;
    78 
    7978        switch (place) {
    8079          case PM_FPA_BEFORE:
  • trunk/psModules/src/detrend/pmDark.c

    r33089 r34800  
    353353
    354354    // retrieve the required parameter vectors
    355     psArray *values  = psMetadataLookupPtr(&mdok, output->analysis, "DARK.VALUES");
    356     psAssert(values, "values not supplied");
     355    psArray *in_values  = psMetadataLookupPtr(&mdok, output->analysis, "DARK.VALUES");
     356    psAssert(in_values, "values not supplied");
    357357    psVector *roMask = psMetadataLookupPtr(&mdok, output->analysis, "DARK.RO.MASK");
    358358    psAssert(roMask, "roMask not supplied");
    359     psVector *orders = psMetadataLookupPtr(&mdok, output->analysis, "DARK.ORDERS");
    360     psAssert(orders, "orders not supplied");
    361 
    362     psPolynomialMD *poly = psPolynomialMDAlloc(orders); // Polynomial for fitting
     359    psVector *max_orders = psMetadataLookupPtr(&mdok, output->analysis, "DARK.ORDERS");
     360    psAssert(max_orders, "orders not supplied");
     361
     362    psArray *values_set = psArrayAlloc(max_orders->n);
     363    psArray *poly_set = psArrayAlloc(max_orders->n);
     364    psVector *logL = psVectorAlloc(max_orders->n,PS_TYPE_F64);
     365
     366    for (int i = 0; i < max_orders->n; i++) {
     367      psVector *orders = psVectorAlloc(i+1,PS_TYPE_U8);
     368      for (int j = 0; j < orders->n; j++) {
     369        orders->data.U8[j] = max_orders->data.U8[j];
     370      }
     371      poly_set->data[i] =  psPolynomialMDAlloc(orders); // Polynomial for fitting
     372     
     373      psArray *values = psArrayAlloc(in_values->n);
     374     
     375      for (int j = 0; j < values->n; j++) {
     376        psVector *these_values = psVectorAlloc(i+1,PS_TYPE_F32);
     377        psVector *input_values = in_values->data[j];
     378
     379        for (int k = 0; k < orders->n; k++) {
     380          these_values->data.F32[k] = input_values->data.F32[k];
     381        }
     382        values->data[j] = these_values;
     383      }
     384      values_set->data[i] = values;
     385    }
    363386
    364387    // retrieve the norm vector, if supplied
     
    383406    }
    384407
    385     pmDarkVisualInit(values);
     408    pmDarkVisualInit(values_set->data[max_orders->n - 1]);
    386409
    387410    pmReadout *outReadout = output->readouts->data[0];
     
    423446            }
    424447
    425             if (!psPolynomialMDClipFit(poly, pixels, NULL, mask, 0xff, values, iter, rej)) {
     448            int k_best = 0;
     449            for (int k = 0; k < max_orders->n; k++) {
     450              psPolynomialMD *poly = poly_set->data[k];
     451              psArray *values = values_set->data[k];
     452             
     453              if (!psPolynomialMDClipFit(poly, pixels, NULL, mask, 0xff, values, iter, rej)) {
    426454                psErrorClear();         // Nothing we can do about it
    427455                psVectorInit(poly->coeff, NAN);
    428             }
    429 
    430             pmDarkVisualPixelFit(pixels, mask);
    431             pmDarkVisualPixelModel(poly, values);
    432 
    433             for (int k = 0; k < poly->coeff->n; k++) {
     456              }
     457
     458              pmDarkVisualPixelFit(pixels, mask);
     459              pmDarkVisualPixelModel(poly, values);
     460
     461              // Insert math here to choose optimum model.
     462              logL->data.F64[k] = 0.0;
     463              psPolynomialMD *polySig = poly_set->data[0];
     464              for (int m = 0; m < poly->deviations->n; m++) {
     465                logL->data.F64[k] += pow(poly->deviations->data.F32[m] / polySig->stdevFit,2);
     466/*              if ((xOut == 20) && (yOut == 256)) { */
     467/*                psTrace("psModules.detrend",3,"pmDarkCombine DEV: %d %d: input %d models: Norders: %d logL: %g value: %g\n", */
     468/*                        xOut,yOut,m,k,logL->data.F64[k],poly->deviations->data.F32[m]); */
     469/*              } */
     470              }
     471              if (k > 0) {
     472                if ( ( logL->data.F64[k - 1] - logL->data.F64[k] ) > 1) { // Hard coded criterion for a ~5% limit with one degree of freedom
     473                  k_best = k;
     474                }
     475              }
     476              if ((xOut <= 600) && (yOut <= 600)) {
     477                psTrace("psModules.detrend",3,"pmDarkCombine: %d %d: models: Norders: %d logL: %g BestOrders: %d\n",
     478                        xOut,yOut,k,logL->data.F64[k],k_best);
     479              }
     480            }
     481            if (k_best > 1) {
     482              k_best = 1;
     483            }
     484/*          k_best = 1; */
     485            // Select the polynomial that seems best.
     486            psPolynomialMD *poly = poly_set->data[k_best];
     487             
     488            //            for (int k = 0; k < poly->coeff->n; k++) {
     489            for (int k = 0; k < max_orders->n + 1; k++) { // There is one more coefficient than is stored here.
    434490                pmReadout *ro = output->readouts->data[k]; // Readout of interest
    435                 ro->image->data.F32[yOut][xOut] = poly->coeff->data.F64[k];
     491                if (k < poly->coeff->n) {
     492                  ro->image->data.F32[yOut][xOut] = poly->coeff->data.F64[k];
     493                }
     494                else {
     495                  ro->image->data.F32[yOut][xOut] = 0.0;
     496                }
    436497            }
    437498            counts->data.U16[yOut][xOut] = poly->numFit;
  • trunk/psModules/src/imcombine/pmStack.c

    r34150 r34800  
    13581358}
    13591359
     1360bool pmStackSimpleMedianCombine(
     1361                                pmReadout *combined,
     1362                                psArray *input) {
     1363  int num = input->n;
     1364  //  int numCols, numRows;
     1365  int minInputCols, maxInputCols, minInputRows, maxInputRows; // Smallest and largest values to combine
     1366  int xSize, ySize;                   // Size of the output image
     1367
     1368  psArray *stack = psArrayAlloc(num); // Stack of readouts 
     1369  for (int i = 0; i < num; i++) {
     1370    //    pmStackData *data = input->data[i]; // Stack data for this input
     1371    pmReadout *ro = input->data[i]; // data->readout;  // Readout of interest
     1372    if (!ro) {
     1373      continue;
     1374    }
     1375    stack->data[i] = psMemIncrRefCounter(ro);
     1376  }   
     1377
     1378  if (!pmReadoutStackValidate(&minInputCols, &maxInputCols, &minInputRows, &maxInputRows, &xSize, &ySize,
     1379                              stack)) {
     1380    psError(psErrorCodeLast(), false, "Input stack is not valid.");
     1381    psFree(stack);
     1382    return false;
     1383  }
     1384
     1385  psVector *pixelData = psVectorAlloc(input->n,PS_TYPE_F32);
     1386  psStats  *stats     = psStatsAlloc(PS_STAT_ROBUST_MEDIAN);
     1387
     1388  for (int y = minInputRows; y < maxInputRows; y++) {
     1389    for (int x = minInputCols; x < maxInputCols; x++) {
     1390      for (int i = 0; i < input->n; i++) {
     1391        pmReadout *ro  = stack->data[i];
     1392        psImage *image = ro->image;
     1393        pixelData->data.F32[i] = image->data.F32[y][x];
     1394      }
     1395      if (!psVectorStats(stats,pixelData,NULL,NULL,0)) {
     1396        psError(PS_ERR_UNKNOWN, false, "Unable to calculate median");
     1397        psFree(stats);
     1398        psFree(pixelData);
     1399        psFree(stack);
     1400        return(false);
     1401      }
     1402      combined->image->data.F32[y][x] = stats->robustMedian;
     1403      combined->mask->data.PS_TYPE_IMAGE_MASK_DATA[y][x] = 0;
     1404    }
     1405  }
     1406 
     1407  psFree(stats);
     1408  psFree(pixelData);
     1409  psFree(stack);
     1410  return (true);
     1411}
     1412
    13601413/// Stack input images
    13611414bool pmStackCombine(
  • trunk/psModules/src/imcombine/pmStack.h

    r27427 r34800  
    4141                              float addVariance ///< Additional variance when rejecting
    4242    );
     43/// Stack input images simply
     44bool pmStackSimpleMedianCombine(pmReadout *combined, ///< Combined readout (output)
     45                                psArray *input       ///< Input array of pmStackData
     46                                );
    4347
    4448/// Stack input images
  • trunk/psModules/src/objects/Makefile.am

    r34403 r34800  
    111111        pmSourceOutputs.h \
    112112        pmSourceIO.h \
     113        pmSourceSatstar.h \
    113114        pmSourcePlots.h \
    114115        pmSourceVisual.h \
  • trunk/psModules/src/objects/pmFootprintCullPeaks.c

    r34198 r34800  
    9191
    9292        // max flux is above threshold for brightest peak
    93         pmPeak *maxPeak = fp->peaks->data[0];
     93      pmPeak *maxPeak = NULL;
     94      for (int i = 0; i < fp->peaks->n; i++) {
     95        pmPeak *testPeak = fp->peaks->data[i];
     96        float this_peak = useSmoothedImage ? testPeak->smoothFlux : testPeak->rawFlux;
     97       
     98        if (isfinite(this_peak)) {
     99          maxPeak = fp->peaks->data[i];
     100          break;
     101        }
     102      }
     103      psAssert(maxPeak,"maxPeak was not set in these peaks");
     104      //      = fp->peaks->data[0];
    94105        float maxFlux = useSmoothedImage ? maxPeak->smoothFlux : maxPeak->rawFlux;
    95106
Note: See TracChangeset for help on using the changeset viewer.