IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Aug 7, 2009, 4:08:25 PM (17 years ago)
Author:
Paul Price
Message:

Merging trunk (r25026) to get up-to-date on old branch.

Location:
branches/pap
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/pap

  • branches/pap/ppSub

    • Property svn:mergeinfo deleted
  • branches/pap/ppSub/src/ppSubMatchPSFs.c

    r23758 r25027  
    1818#include <pslib.h>
    1919#include <psmodules.h>
    20 #include <psphot.h>
    2120
    2221#include "ppSub.h"
     22
     23// Normalise a region on an image
     24static void normaliseRegion(psImage *image, // Image to normalise
     25                            const psRegion *region, // Region of image to normalise
     26                            float norm  // Normalisation
     27                            )
     28{
     29    if (!image) {
     30        return;
     31    }
     32    psAssert(region, "Expect region");
     33    psImage *subImage = psImageSubset(image, *region); // Sub-image
     34    psBinaryOp(subImage, subImage, "*", psScalarAlloc(norm, PS_TYPE_F32));
     35    psFree(subImage);
     36    return;
     37}
     38
    2339
    2440bool ppSubMatchPSFs(ppSubData *data)
     
    6076    pmReadout *inSourceRO = pmFPAfileThisReadout(config->files, view, "PPSUB.INPUT.SOURCES");
    6177    pmReadout *refSourceRO = pmFPAfileThisReadout(config->files, view, "PPSUB.REF.SOURCES");
    62     psArray *inSources = psMetadataLookupPtr(&mdok, inSourceRO->analysis, "PSPHOT.SOURCES"); // Source list
    63     psArray *refSources = psMetadataLookupPtr(&mdok, refSourceRO->analysis, "PSPHOT.SOURCES"); // Source list
     78    psArray *inSources = inSourceRO ? psMetadataLookupPtr(&mdok, inSourceRO->analysis, "PSPHOT.SOURCES") :
     79        NULL; // Source list from input image
     80    psArray *refSources = refSourceRO ? psMetadataLookupPtr(&mdok, refSourceRO->analysis, "PSPHOT.SOURCES") :
     81        NULL ; // Source list from reference image
    6482
    6583    psArray *sources = NULL;            // Merged list of sources
     
    92110    float spacing = psMetadataLookupF32(NULL, recipe, "STAMP.SPACING"); // Typical stamp spacing
    93111    float threshold = psMetadataLookupF32(NULL, recipe, "STAMP.THRESHOLD"); // Threshold for stmps
    94     const char *stampsName = psMetadataLookupStr(&mdok, config->arguments, "STAMPS"); // Filename for stamps
    95112
    96113    const char *typeStr = psMetadataLookupStr(NULL, recipe, "KERNEL.TYPE"); // Kernel type
     
    135152
    136153    bool dual = psMetadataLookupBool(&mdok, recipe, "DUAL"); // Dual convolution?
    137     pmSubtractionMode subMode = dual ? PM_SUBTRACTION_MODE_DUAL : PM_SUBTRACTION_MODE_UNSURE; // Subtracn mode
     154    pmSubtractionMode subMode;          // Subtraction mode
     155    if (dual) {
     156        subMode = PM_SUBTRACTION_MODE_DUAL;
     157    } else {
     158        int convolve = psMetadataLookupS32(NULL, config->arguments, "-convolve"); // Image number to convolve
     159        switch (convolve) {
     160          case 0:
     161            subMode = PM_SUBTRACTION_MODE_UNSURE;
     162            break;
     163          case 1:
     164            subMode = PM_SUBTRACTION_MODE_1;
     165            break;
     166          case 2:
     167            subMode = PM_SUBTRACTION_MODE_2;
     168            break;
     169          default:
     170            psErrorStackPrint(stderr, "Invalid value for -convolve");
     171            return false;
     172        }
     173    }
    138174
    139175    int threads = psMetadataLookupS32(NULL, config->arguments, "-threads"); // Number of threads
     
    149185    } else {
    150186        success = pmSubtractionMatch(inConv, refConv, inRO, refRO, footprint, stride, regionSize,
    151                                      spacing, threshold, sources, stampsName, type, size, order,
     187                                     spacing, threshold, sources, data->stamps, type, size, order,
    152188                                     widths, orders, inner, ringsOrder, binning, penalty, optimum,
    153189                                     optWidths, optOrder, optThresh, iter, rej, sys, maskVal,
     
    165201            ppSubDataQuality(data, error, PPSUB_FILES_ALL);
    166202            return true;
     203        } else if (error == PM_ERR_SMALL_AREA) {
     204            psErrorStackPrint(stderr, "Insufficient area for PSF matching");
     205            psWarning("Insufficient area for PSF matching --- suspect bad data quality.");
     206            ppSubDataQuality(data, error, PPSUB_FILES_ALL);
     207            return true;
    167208        } else {
    168209            psError(PS_ERR_UNKNOWN, false, "Unable to match images.");
     
    171212    }
    172213
     214    // Need to be careful with the normalisation
     215    // We will normalise everything to the normalisation of the *input* image
     216    {
     217        // Since the entries are MULTI, we have to retrieve them differently
     218        psMetadataIterator *regIter = psMetadataIteratorAlloc(inConv->analysis, PS_LIST_HEAD,
     219                                                              "^" PM_SUBTRACTION_ANALYSIS_REGION "$");
     220        psMetadataIterator *modeIter = psMetadataIteratorAlloc(inConv->analysis, PS_LIST_HEAD,
     221                                                              "^" PM_SUBTRACTION_ANALYSIS_MODE "$");
     222        psMetadataIterator *normIter = psMetadataIteratorAlloc(inConv->analysis, PS_LIST_HEAD,
     223                                                              "^" PM_SUBTRACTION_ANALYSIS_NORM "$");
     224        psMetadataItem *regItem;        // Item with region
     225        while ((regItem = psMetadataGetAndIncrement(regIter))) {
     226            psAssert(regItem->type == PS_DATA_REGION && regItem->data.V, "Expect region type");
     227            psRegion *region = regItem->data.V; // Region of interest
     228            psMetadataItem *modeItem = psMetadataGetAndIncrement(modeIter); // Item with mode
     229            psAssert(modeItem && modeItem->type == PS_TYPE_S32, "Expect subtraction mode");
     230            pmSubtractionMode mode = modeItem->data.S32; // Subtraction mode
     231            psMetadataItem *normItem = psMetadataGetAndIncrement(normIter); // Item with normalisation
     232            psAssert(normItem && normItem->type == PS_TYPE_F32 && isfinite(normItem->data.F32),
     233                     "Expect normalisation");
     234            float norm = normItem->data.F32; // Normalisation
     235
     236            switch (mode) {
     237              case PM_SUBTRACTION_MODE_1: // Convolved the input to match template
     238              case PM_SUBTRACTION_MODE_DUAL: // Convolved both; template should have flux conserved
     239                psLogMsg("ppSub", PS_LOG_INFO, "Correcting image for normalisation of %f\n", norm);
     240                normaliseRegion(inConv->image, region, 1.0 / norm);
     241                normaliseRegion(refConv->image, region, 1.0 / norm);
     242                normaliseRegion(inConv->variance, region, 1.0 / PS_SQR(norm));
     243                normaliseRegion(refConv->variance, region, 1.0 / PS_SQR(norm));
     244                break;
     245              case PM_SUBTRACTION_MODE_2:       // Convolved the template to match input
     246                // We're already happy!
     247                psLogMsg("ppSub", PS_LOG_INFO, "Image normalisation is correct\n");
     248                break;
     249              default:
     250                psAbort("Invalid subtraction mode: %x", mode);
     251            }
     252        }
     253        psFree(regIter);
     254        psFree(modeIter);
     255        psFree(normIter);
     256    }
     257
     258
    173259    pmConceptsCopyFPA(inConv->parent->parent->parent, inRO->parent->parent->parent, true, true);
    174260    pmConceptsCopyFPA(refConv->parent->parent->parent, refRO->parent->parent->parent, true, true);
Note: See TracChangeset for help on using the changeset viewer.