IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 34315


Ignore:
Timestamp:
Aug 15, 2012, 9:12:28 AM (14 years ago)
Author:
bills
Message:

add function to estimate the memory consumed by a pmSource

Location:
trunk/psModules/src/objects
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/psModules/src/objects/pmSource.c

    r34085 r34315  
    261261    PS_ASSERT_INT_POSITIVE(Radius, false);
    262262
    263     psRegion srcRegion;
     263    psRegion sourceRegion;
    264264
    265265    // Grab a subimage of the original image of size (2 * outerRadius).
    266     srcRegion = psRegionForSquare (x, y, Radius);
    267     srcRegion = psRegionForImage (readout->image, srcRegion);
     266    sourceRegion = psRegionForSquare (x, y, Radius);
     267    sourceRegion = psRegionForImage (readout->image, sourceRegion);
    268268
    269269    // these images are subset images of the equivalent parents
    270     mySource->pixels = psImageSubset(readout->image, srcRegion);
     270    mySource->pixels = psImageSubset(readout->image, sourceRegion);
    271271    if (readout->variance) {
    272         mySource->variance = psImageSubset(readout->variance, srcRegion);
     272        mySource->variance = psImageSubset(readout->variance, sourceRegion);
    273273    }
    274274    if (readout->mask) {
    275         mySource->maskView = psImageSubset(readout->mask,  srcRegion);
     275        mySource->maskView = psImageSubset(readout->mask,  sourceRegion);
    276276        // the object mask is a copy, and used to define the source pixels
    277277        mySource->maskObj = psImageCopy(NULL, mySource->maskView, PS_TYPE_IMAGE_MASK);
    278278    }
    279     mySource->region   = srcRegion;
     279    mySource->region   = sourceRegion;
    280280    mySource->windowRadius = Radius;
    281281
     
    415415        int nValid = 0;                 // Number of valid sources
    416416        for (int i = 0; i < sources->n; i++) {
    417             pmSource *src = sources->data[i]; // Source of interest
    418             if (!src || !src->moments) {
     417            pmSource *source = sources->data[i]; // Source of interest
     418            if (!source || !source->moments) {
    419419                continue;
    420420            }
    421421
    422422            if (region) {
    423                 int x = src->peak->x, y = src->peak->y; // Coordinates of peak
     423                int x = source->peak->x, y = source->peak->y; // Coordinates of peak
    424424                if (x < region->x0 || x > region->x1 || y < region->y0 || y > region->y1) {
    425425                    continue;
     
    427427            }
    428428
    429             if (src->mode & PM_SOURCE_MODE_BLEND) {
    430                 continue;
    431             }
    432 
    433             if (!src->moments->nPixels) continue;
    434 
    435             if (src->moments->SN < PSF_SN_LIM) {
     429            if (source->mode & PM_SOURCE_MODE_BLEND) {
     430                continue;
     431            }
     432
     433            if (!source->moments->nPixels) continue;
     434
     435            if (source->moments->SN < PSF_SN_LIM) {
    436436                psTrace("psModules.objects", 10, "Rejecting source from clump because of low S/N (%f)\n",
    437                         src->moments->SN);
    438                 continue;
    439             }
    440 
    441             float Mxx = src->moments->Mxx, Myy = src->moments->Myy; // Second moments
     437                        source->moments->SN);
     438                continue;
     439            }
     440
     441            float Mxx = source->moments->Mxx, Myy = source->moments->Myy; // Second moments
    442442            float ar = Mxx / Myy;       // Radius
    443443
     
    14961496  return NULL;
    14971497}
     1498
     1499// Function to estimate the memory consumed by a source.
     1500// Not yet complete but it counts the biggest stuff.
     1501// XXX: handle child images. For big ones the array of data pointers is significant
     1502#define IMAGE_BYTES(_im, _pix_size) (_im ? (sizeof(psImage) + (_im->numRows * _im->numCols * _pix_size)) : 0)
     1503#define VECTOR_BYTES(_v, _elem_size) (_v ? (sizeof(psVector) + (_v->n * _elem_size)) : 0)
     1504
     1505// estimate the memory consumed by this source
     1506psU64 pmSourceMemoryUse (pmSource *source) {
     1507    psU64 bytes = sizeof(pmSource) + sizeof(pmPeak) + sizeof(pmMoments);
     1508
     1509    bytes += IMAGE_BYTES(source->modelVar, 4);
     1510    bytes += IMAGE_BYTES(source->maskObj, 2);
     1511    bytes += IMAGE_BYTES(source->modelFlux, 4);
     1512    bytes += IMAGE_BYTES(source->psfImage, 4);
     1513
     1514    if (source->modelFits) {
     1515        for (int i = 0; i < source->modelFits->n; i++) {
     1516            pmModel *model = source->modelFits->data[i];
     1517            if (!model) continue;
     1518            bytes += sizeof(pmModel);
     1519            bytes += IMAGE_BYTES(model->covar, 4);
     1520            bytes += VECTOR_BYTES(model->params, 4);
     1521            bytes += VECTOR_BYTES(model->dparams, 4);
     1522            if (model->residuals) {
     1523                bytes += sizeof(pmResiduals);
     1524                bytes += IMAGE_BYTES(model->residuals->Ro, 4);
     1525                bytes += IMAGE_BYTES(model->residuals->Rx, 4);
     1526                bytes += IMAGE_BYTES(model->residuals->Ry, 4);
     1527                bytes += IMAGE_BYTES(model->residuals->variance, 4);
     1528                bytes += IMAGE_BYTES(model->residuals->mask, 2);
     1529            }
     1530        }
     1531    }
     1532    if (source->radialAper) {
     1533        for (int i = 0; i < source->radialAper->n; i++) {
     1534            pmSourceRadialApertures *radialAper = source->radialAper->data[i];
     1535            if (radialAper) {
     1536                bytes += sizeof(pmSourceRadialApertures);
     1537                bytes += VECTOR_BYTES(radialAper->flux, 4);
     1538                bytes += VECTOR_BYTES(radialAper->fluxStdev, 4);
     1539                bytes += VECTOR_BYTES(radialAper->fluxErr, 4);
     1540                bytes += VECTOR_BYTES(radialAper->fill, 4);
     1541            }
     1542        }
     1543    }
     1544
     1545    return bytes;
     1546}
  • trunk/psModules/src/objects/pmSource.h

    r34085 r34315  
    323323char *pmSourceModeToString (const pmSourceMode mode);
    324324
     325psU64 pmSourceMemoryUse(pmSource *source);
     326
    325327/// @}
    326328# endif /* PM_SOURCE_H */
Note: See TracChangeset for help on using the changeset viewer.