IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 35512


Ignore:
Timestamp:
May 5, 2013, 2:20:46 PM (13 years ago)
Author:
eugene
Message:

stats is basically working now

Location:
branches/eam_branches/ipp-20130419/pswarp
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-20130419/pswarp/doc/notes.20130406.txt

    r35449 r35512  
    104104    this with the filerules.
    105105
     106** trouble running warp -> chip using astrometry from skycell (ok using astrom from warp)
  • branches/eam_branches/ipp-20130419/pswarp/src/Makefile.am

    r35424 r35512  
    5050        pswarpTransformSources.c        \
    5151        pswarpTransformTile.c           \
     52        pswarpUpdateStatistics.c \
    5253        pswarpVersion.c                 \
    5354        pswarpFiles.c
  • branches/eam_branches/ipp-20130419/pswarp/src/pswarp.c

    r35434 r35512  
    4545        pswarpCleanup(config, statsFile);
    4646    }
    47 
    48 # if (0)
    49     pswarpDumpOutput (config);
    50     exit (0);
    51 # endif
    52 
    5347    // load and warp
    5448    if (!pswarpLoop(config, statsFile->md)) {
    5549        pswarpCleanup(config, statsFile);
    5650    }
    57     pswarpDumpOutput (config);
    58     exit (0);
    5951
    6052# else
     
    7870    }
    7971# endif
     72
    8073    psLogMsg("pswarp", PS_LOG_INFO, "complete pswarp run: %f sec\n", psTimerMark("pswarp"));
    8174    pswarpCleanup(config, statsFile);
     
    8376
    8477// NOTE: pswarpCleanup calls exit
     78
     79// pswarpDumpOutput (config);
     80// exit (0);
  • branches/eam_branches/ipp-20130419/pswarp/src/pswarp.h

    r35449 r35512  
    189189} pswarpBounds;
    190190
    191 bool pswarpFindOverlap (pmFPA *fpa, pswarpBounds *src, pswarpBounds *tgt);
     191bool pswarpFindOverlap (pmFPA *input, pmFPA *output, pswarpBounds *src, pswarpBounds *tgt);
    192192psProjection *pswarpLocalFrame (pmFPA *fpa);
    193193pswarpBounds *pswarpMakeBounds (pmFPA *fpa, psProjection *frame);
     
    199199bool pswarpTransformToTarget (pmFPA *output, pmReadout *input, pmConfig *config);
    200200bool pswarpMakePSF (pmFPA *output);
    201 bool pswarpUpdateStatistics (pmFPA *output, pmFPA *input, pmConfig *config);
     201bool pswarpUpdateStatistics (pmFPA *output, psMetadata *stats, pmFPA *input, pmFPA *astrom, pmConfig *config);
  • branches/eam_branches/ipp-20130419/pswarp/src/pswarpCleanup.c

    r35421 r35512  
    1818
    1919    // Ensure everything is written out, at every level
    20     pswarpFileActivation(config, detectorFiles, true);
     20    pswarpFileActivation(config, detectorFiles, false);
     21    pswarpFileActivation(config, photFiles, false);
     22    pswarpFileActivation(config, independentFiles, false);
    2123    pswarpFileActivation(config, skycellFiles, true);
    22     pswarpFileActivation(config, photFiles, true);
    23     pswarpFileActivation(config, independentFiles, true);
    2424
    25     if (!pswarpIOChecksAfter(config)) {
     25    pmFPAfile *output = psMetadataLookupPtr(NULL, config->files, "PSWARP.OUTPUT");
     26    if (!output) {
     27        psError(PSWARP_ERR_CONFIG, false, "Can't find output data!\n");
     28        pmFPAfileFreeSetStrict(false);
     29        goto DONE;
     30    }
     31
     32    pmFPAview *view = pmFPAviewAlloc(0);
     33    if (!pmFPAfileIOChecks(config, view, PM_FPA_BEFORE)) {
     34        psError(psErrorCodeLast(), false, "Unable to read files.");
     35        pmFPAfileFreeSetStrict(false);
     36        goto DONE;
     37    }
     38    pmChip *chip;
     39    while ((chip = pmFPAviewNextChip (view, output->fpa, 1)) != NULL) {
     40        psTrace ("pswarp", 4, "Chip %d: %x %x\n", view->chip, chip->file_exists, chip->process);
     41        if (!chip->process || !chip->file_exists) { continue; }
     42        if (!pmFPAfileIOChecks(config, view, PM_FPA_BEFORE)) {
     43            psError(psErrorCodeLast(), false, "Unable to read files.");
     44            pmFPAfileFreeSetStrict(false);
     45            goto DONE;
     46        }
     47        pmCell *cell;
     48        while ((cell = pmFPAviewNextCell (view, output->fpa, 1)) != NULL) {
     49            psTrace ("pswarp", 4, "Cell %d: %x %x\n", view->cell, cell->file_exists, cell->process);
     50            if (!cell->process || !cell->file_exists) { continue; }
     51            if (!pmFPAfileIOChecks (config, view, PM_FPA_BEFORE) ||
     52                !pmFPAfileIOChecks (config, view, PM_FPA_AFTER)) {
     53                psError(psErrorCodeLast(), false, "Unable to read files.");
     54                pmFPAfileFreeSetStrict(false);
     55                goto DONE;
     56            }
     57        }
     58        if (!pmFPAfileIOChecks (config, view, PM_FPA_AFTER)) {
     59            psError(psErrorCodeLast(), false, "Unable to write files.");
     60            pmFPAfileFreeSetStrict(false);
     61            goto DONE;
     62        }
     63    }
     64    if (!pmFPAfileIOChecks (config, view, PM_FPA_AFTER)) {
    2665        psError(psErrorCodeLast(), false, "Unable to write files.");
    27         exitValue = pswarpExitCode(exitValue);
    2866        pmFPAfileFreeSetStrict(false);
     67        goto DONE;
    2968    }
     69    psFree(view);
    3070
    3171    if (!pswarpStatsFileSave (config, statsFile)) {
     
    5696    psLibFinalize();
    5797
     98DONE:
    5899    exitValue = pswarpExitCode(exitValue);
    59100    exit (exitValue);
  • branches/eam_branches/ipp-20130419/pswarp/src/pswarpDefineLayout.c

    r35434 r35512  
    5353
    5454    // generate Lmin,max, Mmin,max for both datasets
    55     fprintf (stderr, "srcBounds:\n");
    56     // pswarpBounds *srcBounds = pswarpMakeBounds (astrom->fpa, frame);
    5755    pswarpBounds *srcBounds = pswarpMakeBounds (input->fpa, frame);
    58 
    59     fprintf (stderr, "srcBounds:\n");
    6056    pswarpBounds *tgtBounds = pswarpMakeBounds (skycell->fpa, frame);
    6157
    62     pswarpFindOverlap (output->fpa, srcBounds, tgtBounds);
     58    // find the output (tgt) chips which overlap the input (src) chips
     59    pswarpFindOverlap (input->fpa, output->fpa, srcBounds, tgtBounds);
    6360
    64     // XXX the loop below generates the output pixels. should this be deferred until
    65     // we actually need them?
     61    // The loop below generates the output pixels. XXX Should this be deferred until we
     62    // actually need them? 
     63
    6664    // Generate the output chips (pixels on output->fpa, concepts from skycell->fpa)
    6765    pmFPAview *view = pmFPAviewAlloc(0);
     66
     67    // generate the output hdu and contents bits
     68    pmFPAAddSourceFromFormat(output->fpa, output->format);
    6869
    6970    pmChip *chip;
     
    115116            cell->file_exists = true;
    116117
    117 # if (0)
    118             // ******* this chunk comes from pswarpLoop, but should be done when the output chip is generated
     118            // copy the basic headers across from astrom ref to output
    119119            pmHDU *outHDU = pmHDUFromCell (cell);           ///< HDU for the output warped image
    120120            outHDU->header = psMetadataCopy(outHDU->header, hdu->header);
    121121            pswarpVersionHeader(outHDU->header);
    122 # endif
    123122        }
    124123    }
    125 
    126     // XXX not sure what this does...
    127     pmFPAviewReset (view);
    128     pmFPAAddSourceFromView(output->fpa, view, output->format);
    129 
    130124    psFree (view);
    131125    return true;
  • branches/eam_branches/ipp-20130419/pswarp/src/pswarpLoop.c

    r35434 r35512  
    3636    if (!pswarpSetMaskBits(config)) {
    3737        psError(psErrorCodeLast(), false, "failed to set mask bits");
    38         return NULL;
     38        return false;
    3939    }
    4040
     
    8383    // XXX pmFPAfileActivate(config->files, true, "PSWARP.OUTPUT.SOURCES");
    8484
    85     // Done with the detector side of things
     85    // the loops below load the input data
    8686    pswarpFileActivation(config, detectorFiles, true);
    87     pswarpFileActivation(config, independentFiles, true);
     87
     88    // pswarpFileActivation(config, independentFiles, true);
    8889
    8990    pmFPAview *view = pmFPAviewAlloc(0);
     
    9596    if (!pmFPAfileIOChecks (config, view, PM_FPA_BEFORE)) {
    9697        psError(psErrorCodeLast(), false, "Unable to read files.");
    97         goto DONE;
     98        goto FAIL;
    9899    }
    99100
     
    107108        if (!pmFPAfileIOChecks (config, view, PM_FPA_BEFORE)) {
    108109            psError(psErrorCodeLast(), false, "Unable to read files.");
    109             goto DONE;
     110            goto FAIL;
    110111        }
    111112
     
    116117            if (!pmFPAfileIOChecks (config, view, PM_FPA_BEFORE)) {
    117118                psError(psErrorCodeLast(), false, "Unable to read files.");
    118                 goto DONE;
     119                goto FAIL;
    119120            }
    120121
     
    124125                if (!pmFPAfileIOChecks(config, view, PM_FPA_BEFORE)) {
    125126                    psError(psErrorCodeLast(), false, "Unable to read files.");
    126                     goto DONE;
     127                    goto FAIL;
    127128                }
    128129                if (!readout->data_exists) {
     
    145146                if (!pmFPAfileIOChecks(config, view, PM_FPA_AFTER)) {
    146147                    psError(psErrorCodeLast(), false, "Unable to write files.");
    147                     goto DONE;
     148                    goto FAIL;
    148149                }
    149150            }
    150151            if (!pmFPAfileIOChecks(config, view, PM_FPA_AFTER)) {
    151152                psError(psErrorCodeLast(), false, "Unable to write files.");
    152                 goto DONE;
     153                goto FAIL;
    153154            }
    154155        }
    155156        if (!pmFPAfileIOChecks(config, view, PM_FPA_AFTER)) {
    156157            psError(psErrorCodeLast(), false, "Unable to write files.");
    157             goto DONE;
     158            goto FAIL;
    158159        }
    159160    }
    160161    if (!pmFPAfileIOChecks(config, view, PM_FPA_AFTER)) {
    161162        psError(psErrorCodeLast(), false, "Unable to write files.");
    162         goto DONE;
     163        goto FAIL;
    163164    }
    164165
     
    167168    pswarpFileActivation(config, independentFiles, false);
    168169
    169     // XXXX turn these on later .. pswarpUpdateStatistics (output);
     170    if (!pswarpUpdateStatistics (output->fpa, stats, input->fpa, astrom->fpa, config)) {
     171      psError(psErrorCodeLast(), false, "problem generating statistics.");
     172      goto FAIL;
     173    }
     174
    170175    // XXXX turn these on later .. pswarpMakePSF (output);
    171 
    172176    // XXX have not yet written the output to disk
    173 
    174177    psFree(view);
    175 
    176  DONE:
    177178    return true;
     179
     180 FAIL:
     181    psFree (view);
     182    return false;
    178183}
    179184
    180 # if (0)
    181185// once the output fpa elements have been built, loop over the fpa and generate stats
    182186// for each readout
    183 bool pswarpUpdateStatistics (pmFPA *output, pmFPA *input, pmConfig *config)  {
    184 
    185     // output mask bits
    186     psImageMaskType maskValue = psMetadataLookupImageMask(&status, recipe, "MASK.OUTPUT");
    187     psAssert (status, "MASK.OUTPUT was not defined");
     187bool pswarpTransformToTarget (pmFPA *output, pmReadout *input, pmConfig *config)  {
    188188
    189189    pmFPAview *view = pmFPAviewAlloc(0);
     
    195195
    196196        pmCell *cell;
    197         while ((cell = pmFPAviewNextCell (view, output->fpa, 1)) != NULL) {
    198             psTrace ("pswarp", 4, "Cell %d: %x %x\n", view->cell, cell->file_exists, cell->process);
    199             if (!cell->process || !cell->file_exists) { continue; }
    200 
    201             // process each of the readouts
    202             pmReadout *readout;
    203             while ((readout = pmFPAviewNextReadout(view, output->fpa, 1)) != NULL) {
    204                 if (!readout->data_exists) {
    205                     psWarning("No overlap between input and skycell.");
    206                     if (stats) {
    207                         psMetadataAddS32(stats, PS_LIST_TAIL, "QUALITY", PS_META_REPLACE,
    208                                          "No overlap between input and skycell", PSWARP_ERR_NO_OVERLAP);
    209                     }
    210                     psphotFilesActivate(config, false);
    211                     psFree(cells);
    212                     psFree(view);
    213                     goto DONE;
    214                 }
    215    
    216                 if (!pswarpPixelsLit(readout, stats, config)) {
    217                     psError(psErrorCodeLast(), false, "Unable to calculate pixel regions.");
    218                     psFree(view);
    219                     goto DONE;
    220                 }
    221                 bool doStats = psMetadataLookupBool(&mdok,recipe,"MASK.STATS");
    222                 if (doStats) {
    223                     if (!pswarpMaskStats(readout, stats, config)) {
    224                         psError(psErrorCodeLast(), false, "Unable to calculate mask stats.");
    225                         psFree(cells);
    226                         psFree(view);
    227                         goto DONE;
    228                     }
    229                 }
    230 
    231                 // Set covariance matrix for output
    232                 {
    233                     psList *covariances = psMetadataLookupPtr(&mdok, output->analysis,
    234                                                               PSWARP_ANALYSIS_COVARIANCES); // Covariance matrices
    235                     psAssert(covariances, "Should be there");
    236                     psArray *covars = psListToArray(covariances); // Array of covariance matrices
    237                     psKernel *covar = psImageCovarianceAverage(covars);
    238                     psFree(covars);
    239                     psMetadataRemoveKey(output->analysis, PSWARP_ANALYSIS_COVARIANCES);
    240 
    241                     // Correct covariance matrix scale for the mean (square root of the) Jacobian
    242                     double jacobian = psMetadataLookupF64(NULL, output->analysis, PSWARP_ANALYSIS_JACOBIAN); // Jacobian
    243                     int goodPixels = psMetadataLookupS32(NULL, output->analysis, PSWARP_ANALYSIS_GOODPIX);   // Good pixels
    244                     jacobian /= goodPixels;
    245                     output->covariance = psImageCovarianceScale(covar, jacobian);
    246                     psFree(covar);
    247 
    248                     if (output->variance) {
    249                         psImageCovarianceTransfer(output->variance, output->covariance);
    250                     }
    251                 }
    252             }
    253 
    254             // XXX need to get the input Cells for this output cell (save on the analysis somewhere
    255             // XXX skip this for now
    256 # if (0)
    257             psArray *inputCells = psMetadataLookupPtr (NULL, cell->analysis, "something");
    258             if (!pmConceptsAverageCells(cell, inputCells, NULL, NULL, false)) {
    259                 psError(psErrorCodeLast(), false, "Unable to average cell concepts.");
    260                 psFree(view);
    261                 goto DONE;
    262             }
    263 # endif
    264             // XXX Is this too ad-hoc?
    265             psRegion *trimsec = psMetadataLookupPtr(NULL, cell->concepts, "CELL.TRIMSEC"); ///< Trim section
    266             trimsec->x0 = trimsec->x1 = trimsec->y0 = trimsec->y1 = 0; ///< All pixels
    267 
    268         }
    269 
    270         // Perform statistics on the output image
    271         if (stats) {
    272             // XXX this should be done at each level...
    273             if (!ppStatsFPA(stats, output->parent->parent->parent, view, maskValue, config)) {
    274                 psWarning("Unable to perform statistics on warped image.");
    275             }
    276         }
    277     }
    278     if (!psMetadataCopy(output->concepts, input->concepts)) {
    279         psError(psErrorCodeLast(), false, "Unable to copy FPA concepts from input to output.");
    280         psFree(view);
    281         goto DONE;
    282     }
    283 
    284     // Update ZP from the astrometry
    285     {
    286         psMetadataItem *item = psMetadataLookup(outFPA->concepts, "FPA.ZP");
    287         item->data.F32 = psMetadataLookupF32(NULL, astrom->fpa->concepts, "FPA.ZP");
    288     }
    289 
    290     // need to update the chip and fpa level astrometry appropriate, see
    291     // code in psastro
    292    
    293 # if (0)
    294     // Add MD5 information for readout
    295     const char *chipName = psMetadataLookupStr(NULL, output->parent->parent->concepts, "CHIP.NAME");
    296     const char *cellName = psMetadataLookupStr(NULL, output->parent->concepts, "CELL.NAME");
    297     psString headerName = NULL; ///< Header name for MD5
    298     psStringAppend(&headerName, "MD5_%s_%s_%d", chipName, cellName, view->readout);
    299     psVector *md5 = psImageMD5(output->image); ///< md5 hash
    300     psString md5string = psMD5toString(md5); ///< String
    301     psFree(md5);
    302     psMetadataAddStr(hdu->header, PS_LIST_TAIL, headerName, PS_META_REPLACE,
    303                      "Image MD5", md5string);
    304     psFree(md5string);
    305     psFree(headerName);
    306 # endif
    307 
    308 # if (0)
    309     if (!pmAstromWriteWCS(hdu->header, outFPA, outChip, WCS_NONLIN_TOL)) {
    310         psError(psErrorCodeLast(), false, "Unable to generate WCS header.");
    311         goto DONE;
    312     }
    313 # endif
    314     return true;
    315 }
    316 # endif
    317 
    318 # if (0)
    319 // We need a new PSF model for the warped frame.  It would be good to generate this analytically, but
    320 // that's going to be tricky.  We have a list of sources, so we use those to redetermine the PSF model.
    321 bool pswarpMakePSF (pmConfig *config) {
    322 
    323     // load the recipe
    324     psMetadata *recipe = psMetadataLookupPtr (&status, config->recipes, PSWARP_RECIPE);
    325     if (!recipe) {
    326         psError(PSWARP_ERR_CONFIG, false, "missing recipe %s", PSWARP_RECIPE);
    327         return false;
    328     }
    329 
    330     if (psMetadataLookupBool(&mdok, recipe, "PSF")) {
    331         pswarpFileActivation(config, photFiles, true);
    332         if (!pswarpIOChecksBefore(config)) {
    333             psError(psErrorCodeLast(), false, "Unable to read files.");
    334             goto DONE;
    335         }
    336 
    337         // supply the readout and fpa of interest to psphot
    338         pmFPAfile *photFile = psMetadataLookupPtr(NULL, config->files, "PSPHOT.INPUT");
    339         pmFPACopy(photFile->fpa, outFPA);
    340 
    341         pmFPAview *view = pmFPAviewAlloc(0); ///< View into skycell
    342         view->chip = view->cell = view->readout = 0;
    343 
    344         // grab the sources of interest from the storage location (pmFPAfile PSPHOT.INPUT.CMF)
    345         psArray *sources = psphotLoadPSFSources (config, view);
    346         if (!sources) {
    347             psError(psErrorCodeLast(), false, "No sources supplied to measure PSF");
    348             goto DONE;
    349         }
    350 
    351         pmModelClassSetLimits(PM_MODEL_LIMITS_STRICT);
    352 
    353         // measure the PSF using these sources
    354         if (!psphotReadoutFindPSF(config, view, "PSPHOT.INPUT", sources)) {
    355             // This is likely a data quality issue
    356             // XXX Split into multiple cases using error codes?
    357             psErrorStackPrint(stderr, "Unable to determine PSF");
    358             psWarning("Unable to determine PSF --- suspect bad data quality.");
    359             if (stats && psMetadataLookupS32(NULL, stats, "QUALITY") == 0) {
    360                 psMetadataAddS32(stats, PS_LIST_TAIL, "QUALITY", PS_META_REPLACE,
    361                                  "Unable to determine PSF", psErrorCodeLast());
    362             }
    363             psErrorClear();
    364             psphotFilesActivate(config, false);
    365         }
    366 
    367         // Ensure seeing is carried over
    368         pmChip *photChip = pmFPAviewThisChip(view, photFile->fpa);                 // Chip with seeing
    369         psMetadataItem *item = psMetadataLookup(outChip->concepts, "CHIP.SEEING"); // Concept with seeing
    370         item->data.F32 = psMetadataLookupF32(NULL, photChip->concepts, "CHIP.SEEING");
    371 
    372 // XXX EAM : put this in a visualization function
    373 #if (TESTING)
    374         {
    375             #define PSF_SIZE 20         ///< Half-size of PSF
    376             #define PSF_FLUX 10000      ///< Central flux for PSF
    377             pmChip *photChip = pmFPAviewThisChip(view, photFile->fpa);
    378             pmPSF *psf = psMetadataLookupPtr(NULL, photChip->analysis, "PSPHOT.PSF");
    379             psImage *image = psImageAlloc(2 * PSF_SIZE + 1, 2 * PSF_SIZE + 1, PS_TYPE_F32);
    380             psImageInit(image, 0);
    381             pmModel *model = pmModelFromPSFforXY(psf, PSF_SIZE, PSF_SIZE, PSF_FLUX);
    382             pmModelAdd(image, NULL, model, PM_MODEL_OP_FULL, 0);
    383             psFree(model);
    384             psFits *fits = psFitsOpen("psf.fits", "w");
    385             psFitsWriteImage(fits, NULL, image, 0, NULL);
    386             psFitsClose(fits);
    387             psFree(image);
    388         }
    389 #endif
    390 
    391         psFree(view);
    392     }
    393     return true;
    394 }
    395 # endif
    396 
    397 // once the output fpa elements have been built, loop over the fpa and generate stats
    398 // for each readout
    399 bool pswarpTransformToTarget (pmFPA *output, pmReadout *input, pmConfig *config)  {
    400 
    401     pmFPAview *view = pmFPAviewAlloc(0);
    402    
    403     pmChip *chip;
    404     while ((chip = pmFPAviewNextChip (view, output, 1)) != NULL) {
    405         psTrace ("pswarp", 4, "Chip %d: %x %x\n", view->chip, chip->file_exists, chip->process);
    406         if (!chip->process || !chip->file_exists) { continue; }
    407 
    408         pmCell *cell;
    409197        while ((cell = pmFPAviewNextCell (view, output, 1)) != NULL) {
    410198            psTrace ("pswarp", 4, "Cell %d: %x %x\n", view->cell, cell->file_exists, cell->process);
  • branches/eam_branches/ipp-20130419/pswarp/src/pswarpMaskStats.c

    r28130 r35512  
    3131                              dynamicMaskVal,advisoryMaskVal)) {
    3232    psError(PS_ERR_UNKNOWN, false, "Unable to calculate masks for readout.");
    33     return(false);
     33    return false;
    3434  }
    3535  psMetadataAddS32(stats, PS_LIST_TAIL,"MASKFRAC_NPIX", 0,
     
    4343  psMetadataAddF32(stats,PS_LIST_TAIL, "MASKFRAC_ADVISORY", 0,
    4444                   "Fraction of pixels masked as an advisory", (float) Npix_advisory / Npix_valid);
    45   return(true);
     45  return true;
    4646}
  • branches/eam_branches/ipp-20130419/pswarp/src/pswarpOverlaps.c

    r35434 r35512  
    4545        if (!chip->process || !chip->file_exists) {
    4646            // this ensures one entry per chip (regardless of existence)
    47             // XXX maybe not? pswarpBoundsAppend (bounds, NAN, NAN, NAN, NAN);
     47            pswarpBoundsAppend (bounds, NAN, NAN, NAN, NAN);
    4848            continue;
    4949        }
     
    8383            }
    8484        }
    85         fprintf (stderr, "bounds %d : %f - %f, %f - %f\n", view->chip, Pmin, Pmax, Qmin, Qmax);
     85        // fprintf (stderr, "bounds %d : %f - %f, %f - %f\n", view->chip, Pmin, Pmax, Qmin, Qmax);
    8686        pswarpBoundsAppend (bounds, Pmin, Pmax, Qmin, Qmax);
    8787    }
     
    164164}
    165165
    166 bool pswarpFindOverlap (pmFPA *fpa, pswarpBounds *src, pswarpBounds *tgt) {
     166bool pswarpFindOverlap (pmFPA *input, pmFPA *output, pswarpBounds *src, pswarpBounds *tgt) {
    167167
    168168    // we have the source and target bounds.  loop over all output elements and check if any of the source
    169169    // elements overlap it.
    170170
    171     assert (fpa->chips->n == tgt->Pmin->n);
    172 
    173     for (int j = 0; j < fpa->chips->n; j++) {
    174         pmChip *chip = fpa->chips->data[j];
     171    // also add the list if input (src) cells which land on each output (tgt) chip we do this
     172    // by only identifying the input and output chips and adding all input chip cells to each
     173    // output cell
     174
     175    assert (output->chips->n == tgt->Pmin->n);
     176    assert (input->chips->n == src->Pmin->n);
     177
     178    for (int j = 0; j < output->chips->n; j++) {
     179        pmChip *chip = output->chips->data[j];
    175180
    176181        // we have src bounds
     
    180185        float Qmax = tgt->Qmax->data.F32[j];
    181186
    182         bool valid = false;
    183         for (int i = 0; !valid && (i < src->Pmin->n); i++) {
     187        psArray *inputChips = psArrayAllocEmpty(8);
     188
     189        bool hasOverlap = false;
     190        for (int i = 0; i < src->Pmin->n; i++) {
    184191            // overlaps in P?
    185             bool Pvalid = (Pmin < src->Pmax->data.F32[i]) && (Pmax > src->Pmin->data.F32[i]);
    186             bool Qvalid = (Qmin < src->Qmax->data.F32[i]) && (Qmax > src->Qmin->data.F32[i]);
    187             valid = Pvalid && Qvalid;
    188         }
    189         // if (valid) {
    190         //     fprintf (stderr, "chip %d is valid\n", j);
    191         // } else {
    192         //     fprintf (stderr, "chip %d is NOT valid\n", j);
    193         // }
    194         chip->process = valid;
     192            if (!isfinite(src->Pmin->data.F32[i])) continue;
     193            if (!isfinite(src->Pmax->data.F32[i])) continue;
     194            if (!isfinite(src->Qmin->data.F32[i])) continue;
     195            if (!isfinite(src->Qmax->data.F32[i])) continue;
     196
     197            if (Pmin > src->Pmax->data.F32[i]) continue;
     198            if (Pmax < src->Pmin->data.F32[i]) continue;
     199
     200            if (Qmin > src->Qmax->data.F32[i]) continue;
     201            if (Qmax < src->Qmin->data.F32[i]) continue;
     202
     203            hasOverlap = true;
     204            psArrayAdd (inputChips, 1, input->chips->data[i]);
     205        }
     206        chip->process = hasOverlap;
     207        if (hasOverlap) {
     208            // get the complete list of input cells for this set of input chips
     209            // pmConceptsAverageCells needs a psList (not a psArray)
     210            psList *inputCells = psListAlloc(NULL);
     211            for (int nChip = 0; nChip < inputChips->n; nChip++) {
     212                pmChip *inputChip = inputChips->data[nChip];
     213                for (int nCell = 0; nCell < inputChip->cells->n; nCell++) {
     214                    fprintf (stderr, "input %d, %d : output %d\n", nChip, nCell, j);
     215                    psListAdd (inputCells, PS_LIST_TAIL, inputChip->cells->data[nCell]);
     216                }
     217            }
     218           
     219            // place the inputCells on each of the output cells
     220            for (int nCell = 0; nCell < chip->cells->n; nCell++) {
     221                pmCell *outputCell = chip->cells->data[nCell];
     222                psMetadataAddPtr(outputCell->analysis, PS_LIST_TAIL, "INPUT.CELLS", PS_DATA_LIST , "input cells touching this output cell", inputCells);
     223            }
     224            psFree (inputCells);
     225        }
     226        psFree (inputChips);
    195227    }
    196228    return true;
  • branches/eam_branches/ipp-20130419/pswarp/src/pswarpPixelsLit.c

    r23688 r35512  
    6464    for (int y = 0; y < numRows; y++) {
    6565        for (int x = 0; x < numCols; x++) {
    66             if (!(mask->data.PS_TYPE_IMAGE_MASK_DATA[y][x] & maskValue)) {
    67                 if (y > yMax) {
    68                     yMax = y;
    69                 }
    70                 if (y < yMin) {
    71                     yMin = y;
    72                 }
    73                 if (x > xMax) {
    74                     xMax = x;
    75                 }
    76                 if (x < xMin) {
    77                     xMin = x;
    78                 }
    79             }
     66            if (mask->data.PS_TYPE_IMAGE_MASK_DATA[y][x] & maskValue) { continue; }
     67            xMin = PS_MIN (xMin, x);
     68            xMax = PS_MAX (xMax, x);
     69            yMin = PS_MIN (yMin, y);
     70            yMax = PS_MAX (yMax, y);
    8071        }
    8172    }
    8273
     74    // XXX need to add these in a container appropriate to the element
    8375    if (stats) {
    8476        psMetadataAddS32(stats, PS_LIST_TAIL, "RANGE.XMIN", 0, "Minimum valid x value", xMin);
  • branches/eam_branches/ipp-20130419/pswarp/src/pswarpStatsFile.c

    r35421 r35512  
    3737
    3838    pswarpStatsFile *statsFile = pswarpStatsFileAlloc ();
    39     statsFile->name = name;
     39    statsFile->name = psMemIncrRefCounter(name);
    4040
    4141    if (!mdok) return statsFile; // XXX this is probably a config error, but treat as ok for now
Note: See TracChangeset for help on using the changeset viewer.