IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Aug 1, 2008, 1:58:37 PM (18 years ago)
Author:
eugene
Message:

splitting off pmShutterCorrectionGeneratePending for threaded coding

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psModules/src/detrend/pmShutterCorrection.c

    r17995 r18860  
    957957}
    958958
     959bool pmShutterCorrectionGeneratePrepare(pmReadout *shutter, pmReadout *pattern, const psArray *inputs, psMaskType maskVal)
     960{
     961    PS_ASSERT_PTR_NON_NULL(shutter, false);
     962    PS_ASSERT_PTR_NON_NULL(pattern, false);
     963    PS_ASSERT_ARRAY_NON_NULL(inputs, false);
     964
     965    // determine the output image size based on the input images
     966    int row0, col0, numCols, numRows;
     967    if (!pmReadoutStackSetOutputSize(&col0, &row0, &numCols, &numRows, inputs)) {
     968        psError(PS_ERR_UNKNOWN, false, "problem setting output readout size.");
     969        return false;
     970    }
     971
     972    // generate the required output image based on the specified sizes
     973    pmReadoutStackDefineOutput(shutter, col0, row0, numCols, numRows, false, false, maskVal);
     974    if (pattern) {
     975        pmReadoutStackDefineOutput(pattern, col0, row0, numCols, numRows, false, false, maskVal);
     976    }
     977
     978    psImage *nums = pmReadoutSetAnalysisImage(shutter, PM_READOUT_STACK_ANALYSIS_COUNT, numCols, numRows, PS_TYPE_U16, 0); // Image with number fitted per pixel
     979    if (!nums) {
     980        return false;
     981    }
     982    psImage *sigma = pmReadoutSetAnalysisImage(shutter, PM_READOUT_STACK_ANALYSIS_SIGMA, numCols, numRows, PS_TYPE_F32, NAN); // Image with stdev per pixel
     983    if (!sigma) {
     984        return false;
     985    }
     986
     987    // Update the "concepts"
     988    psList *inputCells = psListAlloc(NULL); // List of cells
     989    for (long i = 0; i < inputs->n; i++) {
     990        pmReadout *readout = inputs->data[i]; // Readout of interest
     991        psListAdd(inputCells, PS_LIST_TAIL, readout->parent);
     992    }
     993    bool success = pmConceptsAverageCells(shutter->parent, inputCells, NULL, NULL, true);
     994    psFree(inputCells);
     995
     996    // Correct the exposure times --- they don't make sense any more.
     997    psMetadataItem *item = psMetadataLookup(shutter->parent->concepts, "CELL.EXPOSURE");
     998    item->data.F32 = NAN;
     999    item = psMetadataLookup(shutter->parent->concepts, "CELL.DARKTIME");
     1000    item->data.F32 = NAN;
     1001
     1002    shutter->data_exists = true;
     1003    shutter->parent->data_exists = true;
     1004    shutter->parent->parent->data_exists = true;
     1005
     1006    pattern->data_exists = true;
     1007    if (pattern->parent) {
     1008        pattern->parent->data_exists = true;
     1009        if (pattern->parent->parent) {
     1010            pattern->parent->parent->data_exists = true;
     1011        }
     1012    }
     1013
     1014    return success;
     1015}
     1016
    9591017bool pmShutterCorrectionGenerate(pmReadout *shutter, pmReadout *pattern, const psArray *inputs,
    9601018                                 float reference, const pmShutterCorrectionData *data,
     
    9621020{
    9631021    PS_ASSERT_PTR_NON_NULL(shutter, false);
     1022    PS_ASSERT_PTR_NON_NULL(pattern, false);
    9641023    PS_ASSERT_ARRAY_NON_NULL(inputs, false);
    9651024    PS_ASSERT_INT_EQUAL(data->num, inputs->n, false);
     
    9751034    }
    9761035
    977     pmReadoutUpdateSize(shutter, minInputCols, minInputRows, xSize, ySize, false, false, maskVal);
    978     if (pattern) {
    979         pmReadoutUpdateSize(pattern, minInputCols, minInputRows, xSize, ySize, false, false, maskVal);
    980     }
    981 
    982     psImage *nums = pmReadoutAnalysisImage(shutter, PM_READOUT_STACK_ANALYSIS_COUNT, xSize, ySize,
    983                                            PS_TYPE_U16, 0); // Image with number fitted per pixel
     1036    psImage *nums = pmReadoutGetAnalysisImage(shutter, PM_READOUT_STACK_ANALYSIS_COUNT);
    9841037    if (!nums) {
    9851038        return false;
    9861039    }
    987     psImage *sigma = pmReadoutAnalysisImage(shutter, PM_READOUT_STACK_ANALYSIS_SIGMA, xSize, ySize,
    988                                             PS_TYPE_F32, NAN); // Image with stdev per pixel
     1040    psImage *sigma = pmReadoutGetAnalysisImage(shutter, PM_READOUT_STACK_ANALYSIS_SIGMA);
    9891041    if (!sigma) {
    990         psFree(nums);
    9911042        return false;
    9921043    }
    9931044
    9941045    psImage *shutterImage = shutter->image; // Shutter correction image
    995     psImage *patternImage; // Illumination pattern
    996     if (pattern) {
    997         patternImage = psMemIncrRefCounter(pattern->image);
    998     } else {
    999         patternImage = psImageAlloc(xSize, ySize, PS_TYPE_F32);
    1000     }
     1046    psImage *patternImage = pattern->image; // Illumination pattern
    10011047
    10021048    int num = data->num;                // Number of images
     
    10241070                    errors->data.F32[r] = sqrtf(readout->weight->data.F32[yIn][xIn]) * ref;
    10251071                } else {
    1026                     errors->data.F32[r] = sqrtf(image->data.F32[yIn][xIn]) * ref;
     1072                    // XXX guess that the input data is Poisson distributed; if we go negative, force high
     1073                    errors->data.F32[r] = sqrtf(fabs(image->data.F32[yIn][xIn])) * ref;
    10271074                }
    10281075            }
     
    10491096    psFree(errors);
    10501097    psFree(counts);
    1051     psFree(nums);
    1052     psFree(sigma);
    1053 
    1054     // Update the "concepts"
    1055     psList *inputCells = psListAlloc(NULL); // List of cells
    1056     for (long i = 0; i < inputs->n; i++) {
    1057         pmReadout *readout = inputs->data[i]; // Readout of interest
    1058         psListAdd(inputCells, PS_LIST_TAIL, readout->parent);
    1059     }
    1060     bool success = pmConceptsAverageCells(shutter->parent, inputCells, NULL, NULL, true);
    1061     psFree(inputCells);
    1062 
    1063     // Correct the exposure times --- they don't make sense any more.
    1064     psMetadataItem *item = psMetadataLookup(shutter->parent->concepts, "CELL.EXPOSURE");
    1065     item->data.F32 = NAN;
    1066     item = psMetadataLookup(shutter->parent->concepts, "CELL.DARKTIME");
    1067     item->data.F32 = NAN;
    1068 
    1069     shutter->data_exists = true;
    1070     shutter->parent->data_exists = true;
    1071     shutter->parent->parent->data_exists = true;
    1072 
    1073     if (pattern) {
    1074         pattern->data_exists = true;
    1075         pattern->parent->data_exists = true;
    1076         pattern->parent->parent->data_exists = true;
    1077     }
    1078 
    1079     return success;
    1080 }
     1098
     1099    return true;
     1100}
Note: See TracChangeset for help on using the changeset viewer.