IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 30619 for trunk/ppSub


Ignore:
Timestamp:
Feb 13, 2011, 11:43:27 AM (15 years ago)
Author:
eugene
Message:

plug leaks in ppSub; adjust kernel auto-scaling to take place after we have measured the source sizes; new option to allow positive output (A+B) instead of diff output (A-B); do NOT weight covariances when averaging

Location:
trunk/ppSub/src
Files:
14 edited

Legend:

Unmodified
Added
Removed
  • trunk/ppSub/src/ppSub.c

    r29551 r30619  
    112112        psLibFinalize();
    113113
     114        fprintf (stderr, "found %d leaks at %s\n", psMemCheckLeaks (0, NULL, stdout, false), "ppSub");
    114115        exitValue = ppSubExitCode(exitValue);
    115116        exit(exitValue);
  • trunk/ppSub/src/ppSubFiles.c

    r27094 r30619  
    125125    // FPA
    126126    if (!pmFPAfileIOChecks(config, view, PM_FPA_BEFORE)) {
     127        psFree (view);
    127128        return false;
    128129    }
     
    131132    view->chip = 0;
    132133    if (!pmFPAfileIOChecks(config, view, PM_FPA_BEFORE)) {
     134        psFree (view);
    133135        return false;
    134136    }
     
    137139    view->cell = 0;
    138140    if (!pmFPAfileIOChecks(config, view, PM_FPA_BEFORE)) {
     141        psFree (view);
    139142        return false;
    140143    }
     
    143146    view->readout = 0;
    144147    if (!pmFPAfileIOChecks(config, view, PM_FPA_BEFORE)) {
    145         return false;
    146     }
    147 
    148     ppSubFilesActivate(config, PPSUB_FILES_ALL, false);
    149 
     148        psFree (view);
     149        return false;
     150    }
     151
     152    ppSubFilesActivate(config, PPSUB_FILES_ALL, false);
     153
     154    psFree (view);
    150155    return true;
    151156}
     
    162167    // Readout
    163168    if (!pmFPAfileIOChecks(config, view, PM_FPA_AFTER)) {
     169        psFree (view);
    164170        return false;
    165171    }
     
    168174    view->readout = -1;
    169175    if (!pmFPAfileIOChecks(config, view, PM_FPA_AFTER)) {
     176        psFree (view);
    170177        return false;
    171178    }
     
    174181    view->cell = -1;
    175182    if (!pmFPAfileIOChecks(config, view, PM_FPA_AFTER)) {
     183        psFree (view);
    176184        return false;
    177185    }
     
    180188    view->chip = -1;
    181189    if (!pmFPAfileIOChecks(config, view, PM_FPA_AFTER)) {
     190        psFree (view);
    182191        return false;
    183192    }
     
    222231    ppSubFilesActivate(config, PPSUB_FILES_ALL, false);
    223232
     233    psFree (view);
    224234    return true;
    225235}
  • trunk/ppSub/src/ppSubInputDetections.c

    r29937 r30619  
    118118        if (!psMetadataCopy(sourcesHDU->header, imageHDU->header)) {
    119119            psError(PPSUB_ERR_PROG, false, "Unable to copy header");
     120            psFree(view);
    120121            return false;
    121122        }
     
    130131    if (!psphotCopyResults (foundDetections, sourcesFile, photFile, view)) {
    131132        psError(PPSUB_ERR_PROG, false, "Unable to copy psphot outputs");
     133        psFree(view);
    132134        return false;
    133135    }
    134136    // if no sources were found here, we report that back and let them handle it
    135137
     138    psFree(view);
    136139    return true;
    137140}
  • trunk/ppSub/src/ppSubLoop.c

    r30066 r30619  
    2626  pmReadout *out = pmFPAfileThisReadout(config->files, view, "PPSUB.OUTPUT");
    2727  psphotSaveImage (NULL, out->image, name);
     28  psFree(view);
    2829  return true;
    2930}
     
    111112        goto ESCAPE;
    112113    }
     114
    113115    if (data->quality) {
    114116        // Can't do anything at all
     
    257259        psError(psErrorCodeLast(), false, "Unable to generate mask statistics");
    258260        success = false;
     261        psFree(view);
    259262        goto ESCAPE;
    260263      }
     264      psFree(view);
    261265    }
    262266    // dumpout(config, "diff.4.fits");
  • trunk/ppSub/src/ppSubMakePSF.c

    r29937 r30619  
    7979    if (!detections || !detections->allSources) {
    8080        psError(PPSUB_ERR_CONFIG, true, "No sources from which to determine PSF.");
     81        psFree(view);
    8182        return false;
    8283    }
     
    8687    // use flags to toss totally bogus entries?
    8788    psArray *goodSources = ppSubSelectPSFSources (sources);
     89
    8890    if (!psphotReadoutFindPSF(config, view, "PSPHOT.INPUT", goodSources)) {
    8991        // This is likely a data quality issue
     
    126128        outputRO = pmReadoutAlloc(outputCell);
    127129        outputRO->image = psMemIncrRefCounter(inputRO->image);
     130        psFree(outputRO); // I have a copy on the outputCell
    128131    }
    129132
  • trunk/ppSub/src/ppSubMatchPSFs.c

    r29937 r30619  
    7878        return true;
    7979    }
    80 
    8180    psFree(view);
    8281
     
    127126    if (!inSourceRO || !refSourceRO) {
    128127        psError(PPSUB_ERR_DATA, false, "Unable to scale kernel, since no sources were provided.");
     128        psFree(view);
    129129        return false;
    130130    }
     
    164164
    165165    // is auto-scaling needed?
    166     if (!psMetadataLookupBool(NULL, recipe, "SCALE")) {
    167         // No scaling requested
    168         psFree(view);
    169         return true;
    170     }
    171 
     166    bool scale = psMetadataLookupBool(NULL, recipe, "SCALE");
    172167    float scaleRef = psMetadataLookupF32(NULL, recipe, "SCALE.REF"); // Reference for scaling
    173168    float scaleMin = psMetadataLookupF32(NULL, recipe, "SCALE.MIN"); // Minimum for scaling
    174169    float scaleMax = psMetadataLookupF32(NULL, recipe, "SCALE.MAX"); // Maximum for scaling
    175     if (!isfinite(scaleRef) || !isfinite(scaleMin) || !isfinite(scaleMax)) {
     170
     171    if (scale && (!isfinite(scaleRef) || !isfinite(scaleMin) || !isfinite(scaleMax))) {
    176172        psError(PPSUB_ERR_ARGUMENTS, false,
    177                 "Scale parameters (SCALE.REF=%f, SCALE.MIN=%f, SCALE.MAX=%f) not set in recipe.",
     173                "auto-scale selected but scale parameters (SCALE.REF=%f, SCALE.MIN=%f, SCALE.MAX=%f) not set in recipe.",
    178174                scaleRef, scaleMin, scaleMax);
    179175        return false;
    180176    }
    181177
    182     if (!pmSubtractionParamsScale(kernelSize, stampSize, kernelWidths, scaleRef, scaleMin, scaleMax)) {
    183         psError(PPSUB_ERR_DATA, false, "Unable to scale parameters.");
    184         return false;
    185     }
     178    pmSubtractionParamScaleOptions(scale, scaleRef, scaleMin, scaleMax);
     179
     180    // if (!pmSubtractionParamsScale(kernelSize, stampSize, kernelWidths)) {
     181    //     psError(PPSUB_ERR_DATA, false, "Unable to scale parameters.");
     182    //     return false;
     183    // }
    186184
    187185    return true;
     
    221219        pmCell *cell = pmFPAfileThisCell(config->files, view, "PPSUB.INPUT.CONV"); // Cell for convolved input
    222220        inConv = pmReadoutAlloc(cell);
     221        psFree(inConv);
    223222    }
    224223    pmReadout *refConv = pmFPAfileThisReadout(config->files, view, "PPSUB.REF.CONV"); // Reference convolved
     
    226225        pmCell *cell = pmFPAfileThisCell(config->files, view, "PPSUB.REF.CONV"); // Cell for convolved ref.
    227226        refConv = pmReadoutAlloc(cell);
     227        psFree(refConv);
    228228    }
    229229
     
    380380
    381381    if (inRO->covariance) {
    382         psImageCovarianceTruncate(inRO->covariance, COVAR_FRAC);
     382        psKernel *truncated = psImageCovarianceTruncate(inRO->covariance, COVAR_FRAC);
     383        psFree(inRO->covariance);
     384        inRO->covariance = truncated;
    383385    }
    384386    if (refRO->covariance) {
    385         psImageCovarianceTruncate(refRO->covariance, COVAR_FRAC);
     387        psKernel *truncated = psImageCovarianceTruncate(refRO->covariance, COVAR_FRAC);
     388        psFree(refRO->covariance);
     389        refRO->covariance = truncated;
    386390    }
    387391
     
    494498
    495499    if (inConv->covariance) {
    496         psImageCovarianceTruncate(inConv->covariance, COVAR_FRAC);
     500        psKernel *truncated = psImageCovarianceTruncate(inConv->covariance, COVAR_FRAC);
     501        psFree(inConv->covariance);
     502        inConv->covariance = truncated;
    497503    }
    498504    if (refConv->covariance) {
    499         psImageCovarianceTruncate(refConv->covariance, COVAR_FRAC);
     505        psKernel *truncated = psImageCovarianceTruncate(refConv->covariance, COVAR_FRAC);
     506        psFree(refConv->covariance);
     507        refConv->covariance = truncated;
    500508    }
    501509
  • trunk/ppSub/src/ppSubReadoutForcedPhot.c

    r29937 r30619  
    6161        // XXX remove the pixels from photFile?
    6262        // XXX other cleanup operations?
     63        psFree(view);
    6364        return true;
    6465    }
     
    8990    if (!psphotCopyResults (&foundDetections, outputFile, photFile, view)) {
    9091        psError(PPSUB_ERR_PROG, false, "Unable to copy psphot outputs");
     92        psFree(view);
    9193        return false;
    9294    }
     
    9799    psMetadataAddF32(data->stats, PS_LIST_TAIL, "TIME_PHOT", PS_META_REPLACE, "Time to do photometry", elapsed);
    98100
     101    psFree(view);
    99102    return true;
    100103}
  • trunk/ppSub/src/ppSubReadoutInverse.c

    r27789 r30619  
    3636    if (!pmAstromWriteWCS(invHDU->header, outFPA, outChip, WCS_TOLERANCE)) {
    3737        psError(psErrorCodeLast(), false, "Unable to write WCS astrometry to PPSUB.INVERSE.");
     38        psFree(view);
    3839        return false;
    3940    }
     
    4142    if (!pmAstromReadWCS(invFPA, invChip, invHDU->header, 1.0)) {
    4243        psError(psErrorCodeLast(), false, "Unable to read WCS astrometry.");
     44        psFree(view);
    4345        return false;
    4446    }
    4547
     48    psFree(view);
    4649    return true;
    4750}
  • trunk/ppSub/src/ppSubReadoutJpeg.c

    r26982 r30619  
    139139    }
    140140
     141    psFree(view);
    141142    return true;
    142143}
  • trunk/ppSub/src/ppSubReadoutPhotometry.c

    r29937 r30619  
    109109        if (!psMetadataCopySingle(inRO->analysis, photRO->analysis, "PSPHOT.DETECTIONS")) {
    110110            psError(PPSUB_ERR_PROG, false, "Unable to copy PSPHOT.DETECTIONS");
     111            psFree(view);
    111112            return false;
    112113        }
    113114        if (!psMetadataCopySingle(inRO->analysis, photRO->analysis, "PSPHOT.HEADER")) {
    114115            psError(PPSUB_ERR_PROG, false, "Unable to copy PSPHOT.HEADER");
     116            psFree(view);
    115117            return false;
    116118        }
    117119        if (!psMetadataCopySingle(inRO->analysis, photRO->analysis, PM_DETEFF_ANALYSIS)) {
    118120            psError(PPSUB_ERR_PROG, false, "Unable to copy Detection Efficiency");
     121            psFree(view);
    119122            return false;
    120123        }
     
    128131    }
    129132
     133    psFree(view);
    130134    return true;
    131135}
    132136
    133137#ifdef TESTING
    134     // Record data about sources: not everything gets into the output CMF files
     138// Record data about sources: not everything gets into the output CMF files
    135139    {
    136140        pmReadout *photRO = pmFPAviewThisReadout(view, photFile->fpa); // Readout with the sources
  • trunk/ppSub/src/ppSubReadoutSubtract.c

    r29003 r30619  
    3131
    3232    bool reverse = psMetadataLookupBool(&mdok, config->arguments, "REVERSE"); // Reverse sense of subtraction?
     33    bool addPair = psMetadataLookupBool(&mdok, recipe, "ADD.NOT.SUBTRACT"); // add instead of subtracting
    3334
    3435    pmFPAview *view = ppSubViewReadout(); // View to readout
     
    4748    // Do the actual subtraction
    4849    pmReadout *outRO = pmFPAfileThisReadout(config->files, view, "PPSUB.OUTPUT");
    49     outRO->image = (psImage*)psBinaryOp(outRO->image, minuend->image, "-", subtrahend->image);
     50
     51    if (addPair) {
     52        outRO->image = (psImage*)psBinaryOp(outRO->image, minuend->image, "+", subtrahend->image);
     53    } else {
     54        outRO->image = (psImage*)psBinaryOp(outRO->image, minuend->image, "-", subtrahend->image);
     55    }
    5056    outRO->mask = (psImage*)psBinaryOp(outRO->mask, minuend->mask, "|", subtrahend->mask);
    5157    outRO->variance = (psImage*)psBinaryOp(outRO->variance, minuend->variance, "+", subtrahend->variance);
     
    7076    psFree(rng);
    7177
     78    // XXX EAM : I suspect that the weighted averaging is giving the wrong answer for
     79    // single-direction PSF matching (and maybe DUAL as well).  I am testing the difference by
     80    // generating A+B images instead of A-B images and then checking the significance of the
     81    // sources in the image
     82
    7283    // Combine the covariances
    7384    // These are weighted by the appropriate mean variance.  This is probably not perfectly correct, but it
     
    7990    covarWeights->data.F32[0] = minuendVar;
    8091    covarWeights->data.F32[1] = subtrahendVar;
     92# if (0)   
    8193    outRO->covariance = psImageCovarianceAverageWeighted(covars, covarWeights);
     94# else
     95    outRO->covariance = psImageCovarianceAverage(covars);
     96# endif
    8297    psFree(covars);
    8398    psFree(covarWeights);
     
    109124    pmChip *outChip = pmFPAfileThisChip(config->files, view, "PPSUB.OUTPUT"); // Output chip
    110125    psFree(view);
     126
    111127    if (!outHDU || !inHDU) {
    112128        psError(PPSUB_ERR_PROG, true, "Unable to find HDU at FPA level to copy astrometry.");
  • trunk/ppSub/src/ppSubSetMasks.c

    r29551 r30619  
    8080    if (!pmReadoutMaskInvalid(inRO, maskValue, satValue)) {
    8181        psError(PPSUB_ERR_DATA, false, "Unable to mask non-finite pixels in input.");
     82        psFree(view);
    8283        return false;
    8384    }
    8485    if (!pmReadoutMaskInvalid(refRO, maskValue, satValue)) {
    8586        psError(PPSUB_ERR_DATA, false, "Unable to mask non-finite pixels in reference.");
     87        psFree(view);
    8688        return false;
    8789    }
     
    9496    if (interpMode == PS_INTERPOLATE_NONE) {
    9597        psError(PPSUB_ERR_CONFIG, false, "Unknown interpolation mode: %s", interpModeStr);
     98        psFree(view);
    9699        return false;
    97100    }
     
    104107    if (!pmReadoutInterpolateBadPixels(inRO, maskVal, interpMode, poorFrac, maskPoor, maskBad)) {
    105108        psError(PPSUB_ERR_DATA, false, "Unable to interpolate bad pixels for input image.");
     109        psFree(view);
    106110        return false;
    107111    }
    108112    if (!pmReadoutInterpolateBadPixels(refRO, maskVal, interpMode, poorFrac, maskPoor, maskBad)) {
    109113        psError(PPSUB_ERR_DATA, false, "Unable to interpolate bad pixels for reference image.");
     114        psFree(view);
    110115        return false;
    111116    }
     
    113118#endif
    114119
     120    psFree(view);
    115121    return true;
    116122}
  • trunk/ppSub/src/ppSubThreshold.c

    r26982 r30619  
    9898    if (!in) {
    9999        psError(PPSUB_ERR_UNKNOWN, false, "Unable to find readout.");
     100        psFree(view);
    100101        return false;
    101102    }
     
    104105    if (!ref) {
    105106        psError(PPSUB_ERR_UNKNOWN, false, "Unable to find readout.");
     107        psFree(view);
    106108        return false;
    107109    }
     
    115117        if (!lowThreshold(in, thresh, maskVal, maskThresh, region, "input convolved image")) {
    116118            psError(psErrorCodeLast(), false, "Unable to threshold input image.");
     119            psFree(view);
    117120            return false;
    118121        }
    119122        if (!lowThreshold(ref, thresh, maskVal, maskThresh, region, "reference convolved image")) {
    120123            psError(psErrorCodeLast(), false, "Unable to threshold input image.");
     124            psFree(view);
    121125            return false;
    122126        }
  • trunk/ppSub/src/ppSubVarianceRescale.c

    r28121 r30619  
    5757        // Nothing to renormalise
    5858        psWarning("Renormalisation of the variance requested, but no variance provided.");
     59        psFree(view);
    5960        return true;
    6061    }
     
    6970    }
    7071
     72    psFree(view);
    7173    return true;
    7274}
Note: See TracChangeset for help on using the changeset viewer.