IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Sep 15, 2009, 4:02:42 PM (17 years ago)
Author:
eugene
Message:

updates from trunk

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/20090715/pstamp/src/ppstampMakeStamp.c

    r21403 r25406  
    1717
    1818static void skyToChip(pmAstromObj *pt, pmFPA *fpa, pmChip *chip);
     19static bool setMaskedToNAN(pmConfig *config, psImage *image, psImage *mask, psImage *variance);
    1920
    2021// convert the input chip's transforms to the output
     
    173174static psImage *extractStamp(psImage *image, psRegion region, double value)
    174175{
    175     int width  = region.x1 - region.x0;
    176     int height = region.y1 - region.y0;
     176    int width  = region.x1 - region.x0 + 0.5;
     177    int height = region.y1 - region.y0 + 0.5;
    177178
    178179    if (width < 0) {
     
    251252// Build the postage stamp output file
    252253
    253 static bool makeStamp(pmConfig *config, ppstampOptions *options, pmFPAfile *input,
     254static int makeStamp(pmConfig *config, ppstampOptions *options, pmFPAfile *input,
    254255                pmChip *inChip, pmFPAview *view)
    255256{
     
    259260    if (!output) {
    260261        psError(PS_ERR_UNKNOWN, false, "Can't find output data\n");
    261         return false;
     262        return PS_EXIT_DATA_ERROR;
    262263    }
    263264    char *fpaName = psMetadataLookupStr(NULL, input->fpa->concepts, "FPA.OBS"); // Name of FPA
     
    283284        pmFPAfile *mosaic = ppstampBuildMosaic(config, input, view);
    284285        if (mosaic == NULL) {
    285             return false;
     286            return PS_EXIT_UNKNOWN_ERROR;
    286287        }
    287288        srcFile = mosaic;
     
    325326            break;
    326327        }
     328        if (readout->variance) {
     329            outReadout->variance = extractStamp(readout->variance, extractRegion,  0);
     330            if (!outReadout->variance) {
     331                psError(PS_ERR_UNKNOWN, false, "failed to create postage stamp weight image\n");
     332                status = false;
     333                break;
     334            }
     335        }
    327336        if (readout->mask) {
    328337            outReadout->mask = extractStamp(readout->mask, extractRegion,  0);
     
    332341                break;
    333342            }
    334         }
    335         if (readout->variance) {
    336             outReadout->variance = extractStamp(readout->variance, extractRegion,  0);
    337             if (!outReadout->variance) {
    338                 psError(PS_ERR_UNKNOWN, false, "failed to create postage stamp weight image\n");
    339                 status = false;
    340                 break;
     343
     344            if (!setMaskedToNAN(config, outReadout->image, outReadout->mask, outReadout->variance)) {
     345                 psError(PS_ERR_UNKNOWN, false, "failed to create postage stamp mask image\n");
     346                 status = false;
     347                 break;
    341348            }
    342349        }
     
    355362        status = copyMetadata(output, input, inChip, options);
    356363    }
    357     return status;
     364    return status ? PS_EXIT_SUCCESS : PS_EXIT_UNKNOWN_ERROR;
    358365}
    359366
     
    567574}
    568575
    569 bool ppstampMakeStamp (pmConfig *config, ppstampOptions *options)
     576int ppstampMakeStamp (pmConfig *config, ppstampOptions *options)
    570577{
    571578    bool        status = false;
    572     bool        returnval = false;;
     579    int        returnval = PS_EXIT_SUCCESS;;
    573580    bool        foundOverlap = false;
    574581
     
    576583    if (!status) {
    577584        psError(PS_ERR_UNKNOWN, true, "Can't find input file!\n");
    578         return false;
     585        return PS_EXIT_DATA_ERROR;
    579586    }
    580587
     
    584591    } else if (astrom->camera != input->camera) {
    585592        psError(PS_ERR_UNKNOWN, true, "Input camera and astrometry camera do not match");
    586         return false;
     593        return PS_EXIT_CONFIG_ERROR;
    587594    }
    588595
     
    593600        psError(PS_ERR_UNKNOWN, false, "Failed to load input.");
    594601        psFree (view);
    595         return false;
     602        return PS_EXIT_DATA_ERROR;
    596603    }
    597604    bool bilevelAstrometry  = false;
     
    607614            psError(PS_ERR_UNKNOWN, false, "Unable to read bilevel mosaic astrometry for input FPA.");
    608615            psFree(view);
    609             return false;
     616            return PS_EXIT_DATA_ERROR;
    610617        }
    611618    }
     
    640647            break;
    641648        case PSTAMP_ERROR:
    642             returnval = false;
     649            returnval = PS_EXIT_UNKNOWN_ERROR;
    643650            allDone = true;
    644651            break;
     
    660667    psFree(view);
    661668
    662     if (!foundOverlap) {
     669    if (!foundOverlap && (returnval == PS_EXIT_SUCCESS)) {
    663670        fprintf(stderr, "ROI not found in input\n");
     671        returnval = PSTAMP_NO_OVERLAP;
    664672    }
    665673
     
    668676
    669677
     678static bool setMaskedToNAN(pmConfig *config, psImage *image, psImage *mask, psImage *variance)
     679{
     680    bool status;
     681    psMetadata *masks = psMetadataLookupMetadata(&status, config->recipes, "MASKS");
     682    if (!status) {
     683        psError(PM_ERR_CONFIG, false, "failed to lookup MASKS in recipes\n");
     684        return false;
     685    }
     686    // we set anything masked to NAN except if CONV.POOR is the only bit set
     687    // First check the old value
     688    psU32 convPoor = psMetadataLookupU32(&status, masks, "POOR.WARP");
     689    if (!status) {
     690        convPoor = psMetadataLookupU32(&status, masks, "CONV.POOR");
     691        if (!status) {
     692            psError(PM_ERR_CONFIG, false, "failed to lookup mask value for CONV.POOR in recipes\n");
     693            return false;
     694        }
     695    }
     696    psU32 maskMask = ~convPoor;
     697
     698    double exciseValue;
     699    if (image->type.type == PS_TYPE_U16) {
     700        exciseValue = 0xffff;
     701    } else if (image->type.type == PS_TYPE_F32) {
     702        exciseValue = NAN;
     703    } else {
     704         psError(PS_ERR_PROGRAMMING, true, "unexpected image type: %d\n", image->type.type);
     705        return false;
     706    }
     707    long numExcised = 0;
     708    for (int y=0; y<image->numRows; y++) {
     709        for (int x=0; x<image->numCols; x++) {
     710            psU16 maskVal = psImageGet(mask, x, y);
     711            if (maskVal & maskMask) {
     712                numExcised++;
     713                psImageSet(image, x, y, exciseValue);
     714                if (variance) {
     715                    psImageSet(variance, x, y, exciseValue);
     716                }
     717            }
     718        }
     719    }
     720    fprintf(stderr, "excised %ld masked pixels\n", numExcised);
     721
     722    return true;
     723}
Note: See TracChangeset for help on using the changeset viewer.