IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Feb 5, 2009, 4:31:25 PM (17 years ago)
Author:
Paul Price
Message:

Merging pap_branch_20090128. Resolved a small number of conflicts. Compiles, but not tested in detail.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psModules/src/imcombine/pmReadoutCombine.c

    r21183 r21363  
    3737    params->iter = 1;
    3838    params->rej = INFINITY;
    39     params->weights = false;
     39    params->variances = false;
    4040
    4141    return params;
     
    7575    psStringAppend(&comment, "Combining using statistic: %x", params->combine);
    7676    if (!hdu->header) {
    77         hdu->header = psMetadataAlloc();
     77        hdu->header = psMetadataAlloc();
    7878    }
    7979    psMetadataAddStr(hdu->header, PS_LIST_TAIL, "HISTORY", PS_META_DUPLICATE_OK, comment, "");
     
    8282    // note the clipping parameters, if used
    8383    if (params->combine == PS_STAT_CLIPPED_MEAN) {
    84         psString comment = NULL;    // Comment to add to header
    85         psStringAppend(&comment, "Combination clipping: %d iterations, rejection at %f sigma", params->iter, params->rej);
    86         psMetadataAddStr(hdu->header, PS_LIST_TAIL, "HISTORY", PS_META_DUPLICATE_OK, comment, "");
    87         psFree(comment);
    88     }
    89 
    90     // note the use of weights
    91     if (params->weights) {
     84        psString comment = NULL;    // Comment to add to header
     85        psStringAppend(&comment, "Combination clipping: %d iterations, rejection at %f sigma", params->iter, params->rej);
     86        psMetadataAddStr(hdu->header, PS_LIST_TAIL, "HISTORY", PS_META_DUPLICATE_OK, comment, "");
     87        psFree(comment);
     88    }
     89
     90    // note the use of variances
     91    if (params->variances) {
    9292        psMetadataAddStr(hdu->header, PS_LIST_TAIL, "HISTORY", PS_META_DUPLICATE_OK,
    93                          "Using input weights to combine images", "");
     93                         "Using input variances to combine images", "");
    9494    }
    9595
     
    121121
    122122    // generate the required output images based on the specified sizes
    123     pmReadoutStackDefineOutput(output, col0, row0, numCols, numRows, true, params->weights, params->blank);
     123    pmReadoutStackDefineOutput(output, col0, row0, numCols, numRows, true, params->variances, params->blank);
    124124    psTrace("psModules.imcombine", 7, "Output minimum: %d,%d\n", output->col0, output->row0);
    125125
     
    177177            return false;
    178178        }
    179         if (params->weights && !readout->weight) {
     179        if (params->variances && !readout->variance) {
    180180            psError(PS_ERR_UNEXPECTED_NULL, true,
    181                     "Rejection based on weights requested, but no weights supplied for image %d.\n", i);
     181                    "Rejection based on variances requested, but no variances supplied for image %d.\n", i);
    182182            return false;
    183183        }
     
    190190    }
    191191
    192     // pthread_t id = pthread_self();
    193     // char name[64];
    194     // sprintf (name, "%x", (unsigned int) id);
    195     // psTimerStart (name);
    196 
    197     psStatsOptions combineStdev = 0; // Statistics option for weights
     192#if 0
     193    pthread_t id = pthread_self();
     194    char name[64];
     195    sprintf(name, "%x", (unsigned int)id);
     196    psTimerStart(name);
     197#endif
     198
     199    psStatsOptions combineStdev = 0; // Statistics option for variances
    198200    switch (params->combine) {
    199201      case PS_STAT_SAMPLE_MEAN:
     
    250252    psVectorMaskType *maskData = mask->data.PS_TYPE_VECTOR_MASK_DATA;     // Dereference mask
    251253
    252     psVector *weights = NULL;           // Stack of weights
    253     psVector *errors = NULL;            // Stack of errors (sqrt of variance/weights), for psVectorStats
    254     psF32 *weightsData = NULL;          // Dereference weights
    255     if (params->weights) {
    256         weights = psVectorAlloc(inputs->n, PS_TYPE_F32); // Stack of weights
    257         weightsData = weights->data.F32;
     254    psVector *variances = NULL;           // Stack of variances
     255    psVector *errors = NULL;            // Stack of errors (sqrt of variance), for psVectorStats
     256    psF32 *variancesData = NULL;          // Dereference variances
     257    if (params->variances) {
     258        variances = psVectorAlloc(inputs->n, PS_TYPE_F32); // Stack of variances
     259        variancesData = variances->data.F32;
    258260    }
    259261    psVector *index = NULL;             // The indices to sort the pixels
     
    279281    psF32 **outputImage  = output->image->data.F32; // Output image
    280282    psImageMaskType **outputMask   = output->mask->data.PS_TYPE_IMAGE_MASK_DATA; // Output mask
    281     psF32 **outputWeight = NULL; // Output weight map
    282     if (output->weight) {
    283         outputWeight = output->weight->data.F32;
     283    psF32 **outputVariance = NULL; // Output variance map
     284    if (output->variance) {
     285        outputVariance = output->variance->data.F32;
    284286    }
    285287
     
    323325                }
    324326
    325                 if (params->weights) {
    326                     weightsData[r] = readout->weight->data.F32[yIn][xIn];
     327                if (params->variances) {
     328                    variancesData[r] = readout->variance->data.F32[yIn][xIn];
    327329                }
    328330
     
    332334                if (scale) {
    333335                    pixelsData[r] *= invScale->data.F32[r];
    334                     if (params->weights) {
    335                         weightsData[r] *= invScale->data.F32[r] * invScale->data.F32[r];
     336                    if (params->variances) {
     337                        variancesData[r] *= invScale->data.F32[r] * invScale->data.F32[r];
    336338                    }
    337339                }
     
    376378
    377379            // XXXXX this step probably is very expensive : convert errors to variance everywhere?
    378             if (params->weights) {
    379                 errors = (psVector*)psUnaryOp(errors, weights, "sqrt");
     380            if (params->variances) {
     381                errors = (psVector*)psUnaryOp(errors, variances, "sqrt");
    380382            }
    381383
     
    386388                outputImage[yOut][xOut] = NAN;
    387389                outputMask[yOut][xOut] = params->blank;
    388                 if (params->weights) {
    389                     outputWeight[yOut][xOut] = NAN;
     390                if (params->variances) {
     391                    outputVariance[yOut][xOut] = NAN;
    390392                }
    391393                sigma->data.F32[yOut][xOut] = NAN;
     
    393395                outputImage[yOut][xOut] = psStatsGetValue(stats, params->combine);
    394396                outputMask[yOut][xOut] = isfinite(outputImage[yOut][xOut]) ? 0 : params->blank;
    395                 if (params->weights) {
     397                if (params->variances) {
    396398                    float stdev = psStatsGetValue(stats, combineStdev);
    397                     outputWeight[yOut][xOut] = PS_SQR(stdev); // Variance
     399                    outputVariance[yOut][xOut] = PS_SQR(stdev); // Variance
    398400                    // XXXX this is not the correct formal error.
    399401                    // also, the weighted mean is not obviously the correct thing here
     
    412414    psFree(pixels);
    413415    psFree(mask);
    414     psFree(weights);
     416    psFree(variances);
    415417    psFree(errors);
    416418    psFree(stats);
Note: See TracChangeset for help on using the changeset viewer.