IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Apr 3, 2021, 11:37:46 AM (5 years ago)
Author:
eugene
Message:

add alternative configuration for reference image so we can run diff with two different cameras (recipes from first image camera are used); remove commented out test lines and move test function to end of ppSubLoop.c; move bit of code to remove extra detection block into ppSubReadoutInverse to clean up the ppSubLoop flow

File:
1 edited

Legend:

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

    r40742 r41528  
    2121#include "ppSub.h"
    2222
     23// Test functions defined below, if needed
     24bool dumpout(pmConfig *config, char *name);
     25bool check_psphot_input (pmConfig *config, char *name);
     26
     27bool ppSubLoop(ppSubData *data)
     28{
     29    bool mdok = false;
     30    bool success = true;
     31
     32    psAssert(data, "Require processing data");
     33    pmConfig *config = data->config;    // Configuration
     34    psAssert(config, "Require configuration.");
     35
     36    psMetadata *recipe = psMetadataLookupMetadata(NULL, config->recipes, PPSUB_RECIPE); // Recipe for ppSim
     37    psAssert(recipe, "We checked this earlier, so it should be here.");
     38    bool noConvolve = psMetadataLookupBool(&mdok, recipe, "NOCONVOLVE"); // Do not use convolved images.
     39
     40    pmConfigCamerasCull(config, NULL);
     41    pmConfigRecipesCull(config, "PPSUB,PPSTATS,PSPHOT,PSASTRO,MASKS,JPEG");
     42
     43    pmFPAfile *input = psMetadataLookupPtr(NULL, config->files, "PPSUB.INPUT");
     44    pmFPAfile *reference = psMetadataLookupPtr(NULL, config->files, "PPSUB.REF");
     45    pmFPAfile *output = psMetadataLookupPtr(NULL, config->files, "PPSUB.OUTPUT");
     46    psAssert(input && reference && output, "Require files");
     47
     48    if (!ppSubFilesIterateDown(config, PPSUB_FILES_INPUT | PPSUB_FILES_CONV)) {
     49        psError(PPSUB_ERR_IO, false, "Unable to load files.");
     50        return false;
     51    }
     52
     53    psTimerStart("PPSUB_MATCH");
     54
     55    if (!ppSubSetMasks(config)) {
     56        psError(psErrorCodeLast(), false, "Unable to set masks.");
     57        return false;
     58    }
     59
     60    if (data->forcedPhot1) {
     61        bool foundDetections = false;
     62        if (!ppSubInputDetections(&foundDetections, "PPSUB.POS1.SOURCES", "PPSUB.INPUT", data)) {
     63            psError(psErrorCodeLast(), false, "Unable to measure positive detections (1)");
     64            success = false;
     65            goto ESCAPE;
     66        }
     67        // if nothing was found, don't bother doing the forced photometry below
     68        if (!foundDetections) {
     69            psWarning ("no sources found in positive image 1, skipping forced photometry");
     70            data->forcedPhot1 = false;
     71        }
     72    }
     73    if (data->forcedPhot2) {
     74        // Change the recipe to use a higher nsigma limit and quit after pass1
     75        psMetadata *psphotRecipe = psMetadataLookupPtr (NULL, config->recipes, PSPHOT_RECIPE);
     76
     77        psF32 nsigma_peak_save = psMetadataLookupF32 (NULL, psphotRecipe, "PEAKS_NSIGMA_LIMIT");
     78        char *breakPt_save =  psMetadataLookupStr (NULL, psphotRecipe, "BREAK_POINT");
     79
     80        psF32 pos2_nsigma_peak = psMetadataLookupF32 (&mdok, psphotRecipe, "PEAKS_POS2_NSIGMA_LIMIT");
     81        if (!mdok) {
     82            psWarning("PEAKS_POS2_NSIGMA_LIMIT not found in psphotRecipe. Will use 25.\n");
     83            pos2_nsigma_peak = 25.;
     84        }
     85        psMetadataAddF32(psphotRecipe, PS_LIST_TAIL, "PEAKS_NSIGMA_LIMIT", PS_META_REPLACE, "", pos2_nsigma_peak);
     86        psMetadataAddStr(psphotRecipe, PS_LIST_TAIL, "BREAK_POINT", PS_META_REPLACE, "", "PASS1");
     87
     88        bool foundDetections = false;
     89        if (!ppSubInputDetections(&foundDetections, "PPSUB.POS2.SOURCES", "PPSUB.REF", data)) {
     90            psError(psErrorCodeLast(), false, "Unable to measure positive detections (2)");
     91            psMetadataAddF32(psphotRecipe, PS_LIST_TAIL, "PEAKS_NSIGMA_LIMIT", PS_META_REPLACE, "", nsigma_peak_save);
     92            psMetadataAddStr(psphotRecipe, PS_LIST_TAIL, "BREAK_POINT", PS_META_REPLACE, "", breakPt_save);
     93            success = false;
     94            goto ESCAPE;
     95        }
     96        psMetadataAddF32(psphotRecipe, PS_LIST_TAIL, "PEAKS_NSIGMA_LIMIT", PS_META_REPLACE, "", nsigma_peak_save);
     97        psMetadataAddStr(psphotRecipe, PS_LIST_TAIL, "BREAK_POINT", PS_META_REPLACE, "", breakPt_save);
     98        // if nothing was found, don't bother doing the forced photometry below
     99        if (!foundDetections) {
     100            psWarning ("no sources found in positive image 2, skipping forced photometry");
     101            data->forcedPhot2 = false;
     102        }
     103    }
     104
     105    // XXX if it exists, use the POS1, POS2 successs for the FWHMs
     106    if (!ppSubMatchPSFs(data)) {
     107        psError(psErrorCodeLast(), false, "Unable to match PSFs.");
     108        success = false;
     109        goto ESCAPE;
     110    }
     111
     112    if (data->quality) {
     113        // Can't do anything at all
     114        success = false;
     115        goto ESCAPE;
     116    }
     117    // generate the residual stamp grid for visualization
     118    if (!ppSubResidualSampleJpeg(config)) {
     119        psError(psErrorCodeLast(), false, "Unable to update.");
     120        success = false;
     121        goto ESCAPE;
     122    }
     123
     124    // XXX add in a positive image detection step here (if needed)
     125   
     126
     127    psMetadataAddF32(data->stats, PS_LIST_TAIL, "TIME_MATCH", 0, "Time to match PSFs", psTimerClear("PPSUB_MATCH"));
     128
     129    // Close input files (freeing up space) : for the noConvolve case, we cannot close the
     130    // inputs since we will use them for subtraction below.  wait until later to do the work
     131    if (!noConvolve) {
     132        if (!ppSubFilesIterateUp(config, PPSUB_FILES_INPUT)) {
     133            psError(PPSUB_ERR_IO, false, "Unable to close input files.");
     134            success = false;
     135            goto ESCAPE;
     136        }
     137    }
     138    if (!ppSubLowThreshold(data)) {
     139        psError(psErrorCodeLast(), false, "Unable to threshold images.");
     140        success = false;
     141        goto ESCAPE;
     142    }
     143
     144    // Set up subtraction files
     145    if (!ppSubFilesIterateDown(config, PPSUB_FILES_SUB)) {
     146        psError(PPSUB_ERR_IO, false, "Unable to set up subtraction files.");
     147        success = false;
     148        goto ESCAPE;
     149    }
     150
     151    if (!ppSubDefineOutput("PPSUB.OUTPUT", config)) {
     152        psError(psErrorCodeLast(), false, "Unable to define output.");
     153        success = false;
     154        goto ESCAPE;
     155    }
     156
     157    if (!data->quality && !ppSubMakePSF(data)) {
     158        psError(psErrorCodeLast(), false, "Unable to generate PSF.");
     159        success = false;
     160        goto ESCAPE;
     161    }
     162
     163    // Now we've got a PSF, blow away detections in case they're confused with real output detections
     164    {
     165        pmFPAview *view = ppSubViewReadout(); // View to readout
     166        pmReadout *out = pmFPAfileThisReadout(config->files, view, "PPSUB.OUTPUT");
     167        if (psMetadataLookup(out->analysis, "PSPHOT.DETECTIONS")) {
     168            psMetadataRemoveKey(out->analysis, "PSPHOT.DETECTIONS");
     169        }
     170        psFree(view);
     171    }
     172
     173    if (!ppSubReadoutSubtract(config)) {
     174        psError(psErrorCodeLast(), false, "Unable to subtract images.");
     175        success = false;
     176        goto ESCAPE;
     177    }
     178
     179    // Close convolved files
     180    if (!ppSubFilesIterateUp(config, PPSUB_FILES_PSF | PPSUB_FILES_CONV)) {
     181        psError(PPSUB_ERR_IO, false, "Unable to close input files.");
     182        success = false;
     183        goto ESCAPE;
     184    }
     185    if (noConvolve) {
     186        if (!ppSubFilesIterateUp(config, PPSUB_FILES_INPUT)) {
     187            psError(PPSUB_ERR_IO, false, "Unable to close input files.");
     188            success = false;
     189            goto ESCAPE;
     190        }
     191    }
     192   
     193    // Higher order background subtraction using psphot
     194    if (!ppSubBackground(config)) {
     195        psError(psErrorCodeLast(), false, "Unable to subtract background.");
     196        success = false;
     197        goto ESCAPE;
     198    }
     199
     200    // Perform Variance correction (rescale within a modest range)
     201    if (!ppSubVarianceRescale(config, data)) {
     202        psError(psErrorCodeLast(), false, "Unable to rescale variance.");
     203        success = false;
     204        goto ESCAPE;
     205    }
     206
     207    if (data->quality) {
     208        // Done all we can do up to this point
     209        success = false;
     210        goto ESCAPE;
     211    }
     212
     213    if (!ppSubFilesIterateDown(config, PPSUB_FILES_PHOT_SUB)) {
     214        psError(PPSUB_ERR_IO, false, "Unable to set up photometry files.");
     215        success = false;
     216        goto ESCAPE;
     217    }
     218
     219    if (!data->quality && !ppSubReadoutPhotometry("PPSUB.OUTPUT", data)) {
     220        psError(psErrorCodeLast(), false, "Unable to perform photometry.");
     221        success = false;
     222        goto ESCAPE;
     223    }
     224
     225    // forced photometry for positive image 1
     226    if (data->forcedPhot1 && !data->quality) {
     227        if (!ppSubReadoutForcedPhot("PPSUB.FORCED1.SOURCES", "PPSUB.OUTPUT", "PPSUB.POS1.SOURCES", data)) {
     228            psError(psErrorCodeLast(), false, "Unable to perform photometry.");
     229            success = false;
     230            goto ESCAPE;
     231        }
     232    }
     233
     234    // forced photometry for positive image 2
     235    if (data->forcedPhot2 && !data->quality) {
     236        if (!ppSubReadoutForcedPhot("PPSUB.FORCED2.SOURCES", "PPSUB.OUTPUT", "PPSUB.POS2.SOURCES", data)) {
     237            psError(psErrorCodeLast(), false, "Unable to perform photometry.");
     238            success = false;
     239            goto ESCAPE;
     240        }
     241    }
     242
     243    if (!ppSubFilesIterateUp(config, PPSUB_FILES_PHOT_SUB)) {
     244        psError(PPSUB_ERR_IO, false, "Unable to set up photometry files.");
     245        success = false;
     246        goto ESCAPE;
     247    }
     248
     249    // Perform statistics on the cell
     250    if (!ppSubReadoutStats(data)) {
     251        psError(psErrorCodeLast(), false, "Unable to collect statistics");
     252        success = false;
     253        goto ESCAPE;
     254    }
     255
     256    // Do Mask Stats
     257    {
     258        pmFPAview *view = ppSubViewReadout(); // View to readout
     259        if (!ppSubMaskStats(config, view,data->stats)) {
     260            psError(psErrorCodeLast(), false, "Unable to generate mask statistics");
     261            success = false;
     262            psFree(view);
     263            goto ESCAPE;
     264        }
     265        psFree(view);
     266    }
     267   
     268    // generate the binned image used to write the jpeg
     269    if (!ppSubReadoutJpeg(config)) {
     270        psError(psErrorCodeLast(), false, "Unable to update.");
     271        success = false;
     272        goto ESCAPE;
     273    }
     274
     275    if (data->inverse) {
     276        // Set up inverse subtraction files
     277        if (!ppSubFilesIterateDown(config, PPSUB_FILES_INV)) {
     278            psError(PPSUB_ERR_IO, false, "Unable to set up inverse files.");
     279            success = false;
     280            goto ESCAPE;
     281        }
     282
     283        if (data->inverse && !ppSubDefineOutput("PPSUB.INVERSE", config)) {
     284            psError(psErrorCodeLast(), false, "Unable to define inverse.");
     285            success = false;
     286            goto ESCAPE;
     287        }
     288
     289        if (!ppSubReadoutInverse(config)) {
     290            psError(psErrorCodeLast(), false, "Unable to invert images.");
     291            success = false;
     292            goto ESCAPE;
     293        }
     294
     295        // Close subtraction files and open inverse photometry files
     296        if (!ppSubFilesIterateUp(config, PPSUB_FILES_SUB)) {
     297            psError(PPSUB_ERR_IO, false, "Unable to close subtraction files.");
     298            success = false;
     299            goto ESCAPE;
     300        }
     301
     302        if (!ppSubFilesIterateDown(config, PPSUB_FILES_PHOT_INV)) {
     303            psError(PPSUB_ERR_IO, false, "Unable to set up inverse files.");
     304            success = false;
     305            goto ESCAPE;
     306        }
     307
     308        if (!data->quality && !ppSubReadoutPhotometry("PPSUB.INVERSE", data)) {
     309            psError(psErrorCodeLast(), false, "Unable to perform photometry.");
     310            success = false;
     311            goto ESCAPE;
     312        }
     313
     314        // Close inverse subtraction files
     315        if (!ppSubFilesIterateUp(config, PPSUB_FILES_INV | PPSUB_FILES_PHOT_INV)) {
     316            psError(PPSUB_ERR_IO, false, "Unable to close subtraction files.");
     317            success = false;
     318            goto ESCAPE;
     319        }
     320
     321    } else {
     322        // Close subtraction files
     323        if (!ppSubFilesIterateUp(config, PPSUB_FILES_SUB)) {
     324            psError(PPSUB_ERR_IO, false, "Unable to close subtraction files.");
     325            success = false;
     326            goto ESCAPE;
     327        }
     328    }
     329
     330 ESCAPE:
     331    pmFPAfileDropInternal(config->files, "PSPHOT.BACKGND");
     332    pmFPAfileDropInternal(config->files, "PSPHOT.BACKMDL");
     333    pmFPAfileDropInternal(config->files, "PSPHOT.BACKMDL.STDEV");
     334
     335    return success;
     336}
     337
     338bool check_psphot_input (pmConfig *config, char *name) {
     339
     340  return true;
     341
     342  bool mdok = true;
     343    pmFPAfile *photFile = psMetadataLookupPtr(&mdok, config->files, "PSPHOT.INPUT"); // Photometry file
     344
     345    pmFPA *fpa = photFile ? photFile->fpa : NULL;
     346    pmChip *chip = fpa && fpa->chips->n ? fpa->chips->data[0] : NULL;
     347
     348    psPlaneTransform *toFPA = chip ? chip->toFPA : NULL;
     349    int nCount = toFPA ? psMemGetRefCounter (toFPA) : 0;
     350
     351    fprintf (stderr, "PSPHOT.INPUT %s chip %p toFPA %p Count %d\n", name, chip, toFPA, nCount);
     352    return true;
     353}
     354
    23355bool dumpout(pmConfig *config, char *name)
    24356{
     
    31363
    32364
    33 bool ppSubLoop(ppSubData *data)
    34 {
    35     bool mdok = false;
    36     bool success = true;
    37 
    38     psAssert(data, "Require processing data");
    39     pmConfig *config = data->config;    // Configuration
    40     psAssert(config, "Require configuration.");
    41 
    42     psMetadata *recipe = psMetadataLookupMetadata(NULL, config->recipes, PPSUB_RECIPE); // Recipe for ppSim
    43     psAssert(recipe, "We checked this earlier, so it should be here.");
    44     bool noConvolve = psMetadataLookupBool(&mdok, recipe, "NOCONVOLVE"); // Do not use convolved images.
    45 
    46     pmConfigCamerasCull(config, NULL);
    47     pmConfigRecipesCull(config, "PPSUB,PPSTATS,PSPHOT,PSASTRO,MASKS,JPEG");
    48 
    49     pmFPAfile *input = psMetadataLookupPtr(NULL, config->files, "PPSUB.INPUT");
    50     pmFPAfile *reference = psMetadataLookupPtr(NULL, config->files, "PPSUB.REF");
    51     pmFPAfile *output = psMetadataLookupPtr(NULL, config->files, "PPSUB.OUTPUT");
    52     psAssert(input && reference && output, "Require files");
    53 
    54     if (!ppSubFilesIterateDown(config, PPSUB_FILES_INPUT | PPSUB_FILES_CONV)) {
    55         psError(PPSUB_ERR_IO, false, "Unable to load files.");
    56         return false;
    57     }
    58 
    59     psTimerStart("PPSUB_MATCH");
    60 
    61     if (!ppSubSetMasks(config)) {
    62         psError(psErrorCodeLast(), false, "Unable to set masks.");
    63         return false;
    64     }
    65 
    66     if (data->forcedPhot1) {
    67         bool foundDetections = false;
    68         if (!ppSubInputDetections(&foundDetections, "PPSUB.POS1.SOURCES", "PPSUB.INPUT", data)) {
    69             psError(psErrorCodeLast(), false, "Unable to measure positive detections (1)");
    70             success = false;
    71             goto ESCAPE;
    72         }
    73         // if nothing was found, don't bother doing the forced photometry below
    74         if (!foundDetections) {
    75             psWarning ("no sources found in positive image 1, skipping forced photometry");
    76             data->forcedPhot1 = false;
    77         }
    78     }
    79     if (data->forcedPhot2) {
    80         // Change the recipe to use a higher nsigma limit and quit after pass1
    81         psMetadata *psphotRecipe = psMetadataLookupPtr (NULL, config->recipes, PSPHOT_RECIPE);
    82 
    83         psF32 nsigma_peak_save = psMetadataLookupF32 (NULL, psphotRecipe, "PEAKS_NSIGMA_LIMIT");
    84         char *breakPt_save =  psMetadataLookupStr (NULL, psphotRecipe, "BREAK_POINT");
    85 
    86         psF32 pos2_nsigma_peak = psMetadataLookupF32 (&mdok, psphotRecipe, "PEAKS_POS2_NSIGMA_LIMIT");
    87         if (!mdok) {
    88             psWarning("PEAKS_POS2_NSIGMA_LIMIT not found in psphotRecipe. Will use 25.\n");
    89             pos2_nsigma_peak = 25.;
    90         }
    91         psMetadataAddF32(psphotRecipe, PS_LIST_TAIL, "PEAKS_NSIGMA_LIMIT", PS_META_REPLACE, "", pos2_nsigma_peak);
    92         psMetadataAddStr(psphotRecipe, PS_LIST_TAIL, "BREAK_POINT", PS_META_REPLACE, "", "PASS1");
    93 
    94         bool foundDetections = false;
    95         if (!ppSubInputDetections(&foundDetections, "PPSUB.POS2.SOURCES", "PPSUB.REF", data)) {
    96             psError(psErrorCodeLast(), false, "Unable to measure positive detections (2)");
    97             psMetadataAddF32(psphotRecipe, PS_LIST_TAIL, "PEAKS_NSIGMA_LIMIT", PS_META_REPLACE, "", nsigma_peak_save);
    98             psMetadataAddStr(psphotRecipe, PS_LIST_TAIL, "BREAK_POINT", PS_META_REPLACE, "", breakPt_save);
    99             success = false;
    100             goto ESCAPE;
    101         }
    102         psMetadataAddF32(psphotRecipe, PS_LIST_TAIL, "PEAKS_NSIGMA_LIMIT", PS_META_REPLACE, "", nsigma_peak_save);
    103         psMetadataAddStr(psphotRecipe, PS_LIST_TAIL, "BREAK_POINT", PS_META_REPLACE, "", breakPt_save);
    104         // if nothing was found, don't bother doing the forced photometry below
    105         if (!foundDetections) {
    106             psWarning ("no sources found in positive image 2, skipping forced photometry");
    107             data->forcedPhot2 = false;
    108         }
    109     }
    110 
    111     // XXX if it exists, use the POS1, POS2 successs for the FWHMs
    112     if (!ppSubMatchPSFs(data)) {
    113         psError(psErrorCodeLast(), false, "Unable to match PSFs.");
    114         success = false;
    115         goto ESCAPE;
    116     }
    117 
    118     if (data->quality) {
    119         // Can't do anything at all
    120         success = false;
    121         goto ESCAPE;
    122     }
    123     // generate the residual stamp grid for visualization
    124     if (!ppSubResidualSampleJpeg(config)) {
    125         psError(psErrorCodeLast(), false, "Unable to update.");
    126         success = false;
    127         goto ESCAPE;
    128     }
    129 
    130     // XXX add in a positive image detection step here (if needed)
    131    
    132 
    133     psMetadataAddF32(data->stats, PS_LIST_TAIL, "TIME_MATCH", 0, "Time to match PSFs",
    134                      psTimerClear("PPSUB_MATCH"));
    135 
    136     // Close input files (freeing up space) : for the noConvolve case, we cannot close the
    137     // inputs since we will use them for subtraction below.  wait until later to do the work
    138     if (!noConvolve) {
    139         if (!ppSubFilesIterateUp(config, PPSUB_FILES_INPUT)) {
    140             psError(PPSUB_ERR_IO, false, "Unable to close input files.");
    141             success = false;
    142             goto ESCAPE;
    143         }
    144     }
    145     if (!ppSubLowThreshold(data)) {
    146         psError(psErrorCodeLast(), false, "Unable to threshold images.");
    147         success = false;
    148         goto ESCAPE;
    149     }
    150 
    151     // Set up subtraction files
    152     if (!ppSubFilesIterateDown(config, PPSUB_FILES_SUB)) {
    153         psError(PPSUB_ERR_IO, false, "Unable to set up subtraction files.");
    154         success = false;
    155         goto ESCAPE;
    156     }
    157 
    158     if (!ppSubDefineOutput("PPSUB.OUTPUT", config)) {
    159         psError(psErrorCodeLast(), false, "Unable to define output.");
    160         success = false;
    161         goto ESCAPE;
    162     }
    163 
    164     if (!data->quality && !ppSubMakePSF(data)) {
    165         psError(psErrorCodeLast(), false, "Unable to generate PSF.");
    166         success = false;
    167         goto ESCAPE;
    168     }
    169 
    170     // Now we've got a PSF, blow away detections in case they're confused with real output detections
    171     {
    172         pmFPAview *view = ppSubViewReadout(); // View to readout
    173         pmReadout *out = pmFPAfileThisReadout(config->files, view, "PPSUB.OUTPUT");
    174         if (psMetadataLookup(out->analysis, "PSPHOT.DETECTIONS")) {
    175             psMetadataRemoveKey(out->analysis, "PSPHOT.DETECTIONS");
    176         }
    177         psFree(view);
    178     }
    179 
    180     if (!ppSubReadoutSubtract(config)) {
    181         psError(psErrorCodeLast(), false, "Unable to subtract images.");
    182         success = false;
    183         goto ESCAPE;
    184     }
    185     // dumpout(config, "diff.1.fits");
    186 
    187     // Close convolved files
    188     if (!ppSubFilesIterateUp(config, PPSUB_FILES_PSF | PPSUB_FILES_CONV)) {
    189         psError(PPSUB_ERR_IO, false, "Unable to close input files.");
    190         success = false;
    191         goto ESCAPE;
    192     }
    193     // dumpout(config, "diff.2a.fits");
    194     if (noConvolve) {
    195         if (!ppSubFilesIterateUp(config, PPSUB_FILES_INPUT)) {
    196             psError(PPSUB_ERR_IO, false, "Unable to close input files.");
    197             success = false;
    198             goto ESCAPE;
    199         }
    200     }
    201    
    202     // Higher order background subtraction using psphot
    203     if (!ppSubBackground(config)) {
    204         psError(psErrorCodeLast(), false, "Unable to subtract background.");
    205         success = false;
    206         goto ESCAPE;
    207     }
    208     // dumpout(config, "diff.2b.fits");
    209 
    210     // Perform Variance correction (rescale within a modest range)
    211     if (!ppSubVarianceRescale(config, data)) {
    212         psError(psErrorCodeLast(), false, "Unable to rescale variance.");
    213         success = false;
    214         goto ESCAPE;
    215     }
    216     // dumpout(config, "diff.2c.fits");
    217 
    218     if (data->quality) {
    219         // Done all we can do up to this point
    220         success = false;
    221         goto ESCAPE;
    222     }
    223 
    224     if (!ppSubFilesIterateDown(config, PPSUB_FILES_PHOT_SUB)) {
    225         psError(PPSUB_ERR_IO, false, "Unable to set up photometry files.");
    226         success = false;
    227         goto ESCAPE;
    228     }
    229 
    230     if (!data->quality && !ppSubReadoutPhotometry("PPSUB.OUTPUT", data)) {
    231         psError(psErrorCodeLast(), false, "Unable to perform photometry.");
    232         success = false;
    233         goto ESCAPE;
    234     }
    235     // dumpout(config, "diff.3.fits");
    236 
    237     // forced photometry for positive image 1
    238     if (data->forcedPhot1 && !data->quality) {
    239         if (!ppSubReadoutForcedPhot("PPSUB.FORCED1.SOURCES", "PPSUB.OUTPUT", "PPSUB.POS1.SOURCES", data)) {
    240             psError(psErrorCodeLast(), false, "Unable to perform photometry.");
    241             success = false;
    242             goto ESCAPE;
    243         }
    244     }
    245 
    246     // forced photometry for positive image 2
    247     if (data->forcedPhot2 && !data->quality) {
    248         if (!ppSubReadoutForcedPhot("PPSUB.FORCED2.SOURCES", "PPSUB.OUTPUT", "PPSUB.POS2.SOURCES", data)) {
    249             psError(psErrorCodeLast(), false, "Unable to perform photometry.");
    250             success = false;
    251             goto ESCAPE;
    252         }
    253     }
    254 
    255     if (!ppSubFilesIterateUp(config, PPSUB_FILES_PHOT_SUB)) {
    256         psError(PPSUB_ERR_IO, false, "Unable to set up photometry files.");
    257         success = false;
    258         goto ESCAPE;
    259     }
    260 
    261     // Perform statistics on the cell
    262     if (!ppSubReadoutStats(data)) {
    263         psError(psErrorCodeLast(), false, "Unable to collect statistics");
    264         success = false;
    265         goto ESCAPE;
    266     }
    267     // Do Mask Stats
    268     {
    269         pmFPAview *view = ppSubViewReadout(); // View to readout
    270         if (!ppSubMaskStats(config, view,data->stats)) {
    271             psError(psErrorCodeLast(), false, "Unable to generate mask statistics");
    272             success = false;
    273             psFree(view);
    274             goto ESCAPE;
    275         }
    276         psFree(view);
    277     }
    278     // dumpout(config, "diff.4.fits");
    279    
    280     // generate the binned image used to write the jpeg
    281     if (!ppSubReadoutJpeg(config)) {
    282         psError(psErrorCodeLast(), false, "Unable to update.");
    283         success = false;
    284         goto ESCAPE;
    285     }
    286 
    287     if (data->inverse) {
    288         // Set up inverse subtraction files
    289         if (!ppSubFilesIterateDown(config, PPSUB_FILES_INV)) {
    290             psError(PPSUB_ERR_IO, false, "Unable to set up inverse files.");
    291             success = false;
    292             goto ESCAPE;
    293         }
    294 
    295         if (data->inverse && !ppSubDefineOutput("PPSUB.INVERSE", config)) {
    296             psError(psErrorCodeLast(), false, "Unable to define inverse.");
    297             success = false;
    298             goto ESCAPE;
    299         }
    300 
    301         if (!ppSubReadoutInverse(config)) {
    302             psError(psErrorCodeLast(), false, "Unable to invert images.");
    303             success = false;
    304             goto ESCAPE;
    305         }
    306 
    307         //MEH -- need to also clear out detections or inv.cmf corrupted on update
    308         pmFPAview *viewinv = ppSubViewReadout(); // View to readout
    309         pmReadout *inv = pmFPAfileThisReadout(config->files, viewinv, "PPSUB.INVERSE");
    310         if (psMetadataLookup(inv->analysis, "PSPHOT.DETECTIONS")) {
    311             psMetadataRemoveKey(inv->analysis, "PSPHOT.DETECTIONS");
    312         }
    313         psFree(viewinv);
    314 
    315         // Close subtraction files and open inverse photometry files
    316         if (!ppSubFilesIterateUp(config, PPSUB_FILES_SUB)) {
    317             psError(PPSUB_ERR_IO, false, "Unable to close subtraction files.");
    318             success = false;
    319             goto ESCAPE;
    320         }
    321 
    322         if (!ppSubFilesIterateDown(config, PPSUB_FILES_PHOT_INV)) {
    323             psError(PPSUB_ERR_IO, false, "Unable to set up inverse files.");
    324             success = false;
    325             goto ESCAPE;
    326         }
    327 
    328         if (!data->quality && !ppSubReadoutPhotometry("PPSUB.INVERSE", data)) {
    329             psError(psErrorCodeLast(), false, "Unable to perform photometry.");
    330             success = false;
    331             goto ESCAPE;
    332         }
    333 
    334         // Close inverse subtraction files
    335         if (!ppSubFilesIterateUp(config, PPSUB_FILES_INV | PPSUB_FILES_PHOT_INV)) {
    336             psError(PPSUB_ERR_IO, false, "Unable to close subtraction files.");
    337             success = false;
    338             goto ESCAPE;
    339         }
    340     } else {
    341         // Close subtraction files
    342         // dumpout(config, "diff.5.fits");
    343         if (!ppSubFilesIterateUp(config, PPSUB_FILES_SUB)) {
    344             psError(PPSUB_ERR_IO, false, "Unable to close subtraction files.");
    345             success = false;
    346             goto ESCAPE;
    347         }
    348     }
    349 
    350  ESCAPE:
    351     pmFPAfileDropInternal(config->files, "PSPHOT.BACKGND");
    352     pmFPAfileDropInternal(config->files, "PSPHOT.BACKMDL");
    353     pmFPAfileDropInternal(config->files, "PSPHOT.BACKMDL.STDEV");
    354 
    355     return success;
    356 }
Note: See TracChangeset for help on using the changeset viewer.