IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jun 25, 2009, 2:00:56 PM (17 years ago)
Author:
eugene
Message:

merging changes from head

Location:
branches/eam_branches/20090522
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/20090522

  • branches/eam_branches/20090522/ppSub

    • Property svn:mergeinfo changed (with no actual effect on merging)
  • branches/eam_branches/20090522/ppSub/src/ppSubCamera.c

    r23753 r24557  
    163163
    164164
     165    // Now that the camera has been determined, we can read the recipe
     166    psMetadata *recipe = psMetadataLookupMetadata(NULL, config->recipes, PPSUB_RECIPE); // Recipe for ppSim
     167    if (!recipe) {
     168        psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to find recipe %s", PPSUB_RECIPE);
     169        return false;
     170    }
     171    if (psMetadataLookupBool(NULL, config->arguments, "-photometry")) {
     172        psMetadataAddBool(recipe, PS_LIST_TAIL, "PHOTOMETRY", PS_META_REPLACE,
     173                          "Perform photometry?", true);
     174    }
     175    if (psMetadataLookupBool(NULL, config->arguments, "-inverse")) {
     176        psMetadataAddBool(recipe, PS_LIST_TAIL, "INVERSE", PS_META_REPLACE,
     177                          "Generate inverse subtractions?", true);
     178    }
     179
     180    data->inverse = psMetadataLookupBool(NULL, recipe, "INVERSE");
     181    data->photometry = psMetadataLookupBool(NULL, recipe, "PHOTOMETRY");
     182
     183    bool mdok;                          // Status of MD lookup
     184    bool saveConv = psMetadataLookupBool(&mdok, recipe, "SAVE.CONVOLVED"); // Save convolved images?
     185
    165186    // Convolved input image
    166187    pmFPAfile *inConvImage = defineOutputFile(config, input, true, "PPSUB.INPUT.CONV", PM_FPA_FILE_IMAGE);
     
    171192        return false;
    172193    }
     194    if (saveConv) {
     195        inConvImage->save = true;
     196        inConvMask->save = true;
     197    }
    173198    if (inVar) {
    174199        pmFPAfile *inConvVar = defineOutputFile(config, inConvImage, false, "PPSUB.INPUT.CONV.VARIANCE",
     
    177202            psError(PS_ERR_UNKNOWN, false, "Unable to define output files");
    178203            return false;
     204        }
     205        if (saveConv) {
     206            inConvVar->save = true;
    179207        }
    180208    }
     
    188216        return false;
    189217    }
     218    if (saveConv) {
     219        refConvImage->save = true;
     220        refConvMask->save = true;
     221    }
    190222    if (refVar) {
    191223        pmFPAfile *refConvVar = defineOutputFile(config, refConvImage, false, "PPSUB.REF.CONV.VARIANCE",
     
    195227            return false;
    196228        }
    197     }
    198 
    199 
    200     // Now that the camera has been determined, we can read the recipe
    201     psMetadata *recipe = psMetadataLookupMetadata(NULL, config->recipes, PPSUB_RECIPE); // Recipe for ppSim
    202     if (!recipe) {
    203         psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to find recipe %s", PPSUB_RECIPE);
    204         return false;
    205     }
    206     if (psMetadataLookupBool(NULL, config->arguments, "-photometry")) {
    207         psMetadataAddBool(recipe, PS_LIST_TAIL, "PHOTOMETRY", PS_META_REPLACE,
    208                           "Perform photometry?", true);
    209     }
    210     if (psMetadataLookupBool(NULL, config->arguments, "-inverse")) {
    211         psMetadataAddBool(recipe, PS_LIST_TAIL, "INVERSE", PS_META_REPLACE,
    212                           "Generate inverse subtractions?", true);
    213     }
    214 
    215     data->inverse = psMetadataLookupBool(NULL, recipe, "INVERSE");
    216     data->photometry = psMetadataLookupBool(NULL, recipe, "PHOTOMETRY");
    217 
     229        if (saveConv) {
     230            refConvVar->save = true;
     231        }
     232    }
    218233
    219234    // Output image
  • branches/eam_branches/20090522/ppSub/src/ppSubMatchPSFs.c

    r24181 r24557  
    2121
    2222#include "ppSub.h"
     23
     24// Normalise a region on an image
     25static void normaliseRegion(psImage *image, // Image to normalise
     26                            const psRegion *region, // Region of image to normalise
     27                            float norm  // Normalisation
     28                            )
     29{
     30    if (!image) {
     31        return;
     32    }
     33    psAssert(region, "Expect region");
     34    psImage *subImage = psImageSubset(image, *region); // Sub-image
     35    psBinaryOp(subImage, subImage, "*", psScalarAlloc(norm, PS_TYPE_F32));
     36    psFree(subImage);
     37    return;
     38}
     39
    2340
    2441bool ppSubMatchPSFs(ppSubData *data)
     
    166183            ppSubDataQuality(data, error, PPSUB_FILES_ALL);
    167184            return true;
     185        } else if (error == PM_ERR_SMALL_AREA) {
     186            psErrorStackPrint(stderr, "Insufficient area for PSF matching");
     187            psWarning("Insufficient area for PSF matching --- suspect bad data quality.");
     188            ppSubDataQuality(data, error, PPSUB_FILES_ALL);
     189            return true;
    168190        } else {
    169191            psError(PS_ERR_UNKNOWN, false, "Unable to match images.");
     
    172194    }
    173195
     196    // Need to be careful with the normalisation
     197    // We will normalise everything to the normalisation of the *input* image
     198    {
     199        // Since the entries are MULTI, we have to retrieve them differently
     200        psMetadataIterator *regIter = psMetadataIteratorAlloc(inConv->analysis, PS_LIST_HEAD,
     201                                                              "^" PM_SUBTRACTION_ANALYSIS_REGION "$");
     202        psMetadataIterator *modeIter = psMetadataIteratorAlloc(inConv->analysis, PS_LIST_HEAD,
     203                                                              "^" PM_SUBTRACTION_ANALYSIS_MODE "$");
     204        psMetadataIterator *normIter = psMetadataIteratorAlloc(inConv->analysis, PS_LIST_HEAD,
     205                                                              "^" PM_SUBTRACTION_ANALYSIS_NORM "$");
     206        psMetadataItem *regItem;        // Item with region
     207        while ((regItem = psMetadataGetAndIncrement(regIter))) {
     208            psAssert(regItem->type == PS_DATA_REGION && regItem->data.V, "Expect region type");
     209            psRegion *region = regItem->data.V; // Region of interest
     210            psMetadataItem *modeItem = psMetadataGetAndIncrement(modeIter); // Item with mode
     211            psAssert(modeItem && modeItem->type == PS_TYPE_S32, "Expect subtraction mode");
     212            pmSubtractionMode mode = modeItem->data.S32; // Subtraction mode
     213            psMetadataItem *normItem = psMetadataGetAndIncrement(normIter); // Item with normalisation
     214            psAssert(normItem && normItem->type == PS_TYPE_F32 && isfinite(normItem->data.F32),
     215                     "Expect normalisation");
     216            float norm = normItem->data.F32; // Normalisation
     217
     218            switch (mode) {
     219              case PM_SUBTRACTION_MODE_1: // Convolved the input to match template
     220              case PM_SUBTRACTION_MODE_DUAL: // Convolved both; template should have flux conserved
     221                psLogMsg("ppSub", PS_LOG_INFO, "Correcting image for normalisation of %f\n", norm);
     222                normaliseRegion(inConv->image, region, 1.0 / norm);
     223                normaliseRegion(refConv->image, region, 1.0 / norm);
     224                normaliseRegion(inConv->variance, region, 1.0 / PS_SQR(norm));
     225                normaliseRegion(refConv->variance, region, 1.0 / PS_SQR(norm));
     226                break;
     227              case PM_SUBTRACTION_MODE_2:       // Convolved the template to match input
     228                // We're already happy!
     229                psLogMsg("ppSub", PS_LOG_INFO, "Image normalisation is correct\n");
     230                break;
     231              default:
     232                psAbort("Invalid subtraction mode: %x", mode);
     233            }
     234        }
     235        psFree(regIter);
     236        psFree(modeIter);
     237        psFree(normIter);
     238    }
     239
     240
    174241    pmConceptsCopyFPA(inConv->parent->parent->parent, inRO->parent->parent->parent, true, true);
    175242    pmConceptsCopyFPA(refConv->parent->parent->parent, refRO->parent->parent->parent, true, true);
  • branches/eam_branches/20090522/ppSub/src/ppSubReadoutInverse.c

    r24155 r24557  
    2323    invRO->data_exists = invRO->parent->data_exists = invRO->parent->parent->data_exists = true;
    2424
     25    // Get concepts from reference
     26    pmFPAfile *refFile = psMetadataLookupPtr(NULL, config->files, "PPSUB.REF.CONV"); // File with concepts
     27    pmFPA *invFPA = invRO->parent->parent->parent; // Inverse FPA
     28    pmConceptsCopyFPA(invFPA, refFile->fpa, true, true);
     29
     30    // Get astrometry from (forward) subtraction
    2531    pmChip *outChip = outRO->parent->parent;       // Output chip
    2632    pmFPA *outFPA = outChip->parent;               // Output FPA
    27     pmFPA *invFPA = invRO->parent->parent->parent; // Inverse FPA
    28 
    29     pmConceptsCopyFPA(invFPA, outFPA, true, true);
    30 
    31 #if 0
    32     // Copy astrometry over
    33     pmHDU *outHDU = outFPA->hdu;          // Output HDU
    3433    pmChip *invChip = invRO->parent->parent; // Inverse chip
    35     psFree(view);
    36     if (!outHDU || !inHDU) {
    37         psError(PS_ERR_UNKNOWN, false, "Unable to find HDU at FPA level to copy astrometry.");
    38         return false;
    39     }
    40     if (!pmAstromReadWCS(invFPA, invChip, outHDU->header, 1.0)) {
    41         psError(PS_ERR_UNKNOWN, false, "Unable to read WCS astrometry from PPSUB.OUTPUT.");
    42         return false;
    43     }
    44 #endif
    4534    pmHDU *invHDU = invFPA->hdu;          // Inverse HDU
    4635    if (!pmAstromWriteWCS(invHDU->header, outFPA, outChip, WCS_TOLERANCE)) {
     
    4837        return false;
    4938    }
     39    // Read from newly written astrometry so that it exists in the "inverse" FPA (for sources)
     40    if (!pmAstromReadWCS(invFPA, invChip, invHDU->header, 1.0)) {
     41        psError(PS_ERR_UNKNOWN, false, "Unable to read WCS astrometry.");
     42        return false;
     43    }
    5044
    5145    return true;
  • branches/eam_branches/20090522/ppSub/src/ppSubReadoutPhotometry.c

    r23938 r24557  
    6565    // equivalent to the minuend image.
    6666    pmReadout *inRO = pmFPAfileThisReadout(config->files, view, name); // Readout with image and sources
     67    if (psMetadataLookup(inRO->analysis, "PSPHOT.SOURCES")) {
     68        psMetadataRemoveKey(inRO->analysis, "PSPHOT.SOURCES");
     69    }
    6770
    6871    pmFPAfile *photFile = psMetadataLookupPtr(&mdok, config->files, "PSPHOT.INPUT"); // Photometry file
Note: See TracChangeset for help on using the changeset viewer.