IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 23287 for trunk/psphot


Ignore:
Timestamp:
Mar 11, 2009, 5:22:15 PM (17 years ago)
Author:
Paul Price
Message:

Putting the psImageBinning onto the recipe was causing the dump for the PSPHOT recipe to fail --- it was empty. Instead, we put it on an appropriate readout's analysis metadata.

Location:
trunk/psphot/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/psphot/src/psphotMagnitudes.c

    r21519 r23287  
    1515    int nThreads = psMetadataLookupS32(&status, config->arguments, "NTHREADS"); // Number of threads
    1616    if (!status) {
    17         nThreads = 0;
     17        nThreads = 0;
    1818    }
    1919
     
    3636
    3737    // the binning details are saved on the analysis metadata
    38     psImageBinning *binning = psMetadataLookupPtr(&status, recipe, "PSPHOT.BACKGROUND.BINNING");
     38    psImageBinning *binning = psMetadataLookupPtr(&status, backModel->analysis, "PSPHOT.BACKGROUND.BINNING");
    3939
    4040    bool IGNORE_GROWTH = psMetadataLookupBool (&status, recipe, "IGNORE_GROWTH");
     
    5353    for (int i = 0; i < cellGroups->n; i++) {
    5454
    55         psArray *cells = cellGroups->data[i];
    56 
    57         for (int j = 0; j < cells->n; j++) {
    58 
    59             // allocate a job -- if threads are not defined, this just runs the job
    60             psThreadJob *job = psThreadJobAlloc ("PSPHOT_MAGNITUDES");
    61 
    62             psArrayAdd(job->args, 1, cells->data[j]); // sources
    63             psArrayAdd(job->args, 1, psf);
    64             psArrayAdd(job->args, 1, binning);
    65             psArrayAdd(job->args, 1, backModel);
    66             psArrayAdd(job->args, 1, backStdev);
    67 
    68             PS_ARRAY_ADD_SCALAR(job->args, photMode, PS_TYPE_S32);
    69             PS_ARRAY_ADD_SCALAR(job->args, maskVal,  PS_TYPE_IMAGE_MASK);
    70             PS_ARRAY_ADD_SCALAR(job->args, 0,        PS_TYPE_S32); // this is used as a return value for nAp
    71 
    72             if (!psThreadJobAddPending(job)) {
    73                 psError(PS_ERR_UNKNOWN, false, "Unable to guess model.");
    74                 psFree (job);
    75                 return false;
    76             }
    77             psFree(job);
     55        psArray *cells = cellGroups->data[i];
     56
     57        for (int j = 0; j < cells->n; j++) {
     58
     59            // allocate a job -- if threads are not defined, this just runs the job
     60            psThreadJob *job = psThreadJobAlloc ("PSPHOT_MAGNITUDES");
     61
     62            psArrayAdd(job->args, 1, cells->data[j]); // sources
     63            psArrayAdd(job->args, 1, psf);
     64            psArrayAdd(job->args, 1, binning);
     65            psArrayAdd(job->args, 1, backModel);
     66            psArrayAdd(job->args, 1, backStdev);
     67
     68            PS_ARRAY_ADD_SCALAR(job->args, photMode, PS_TYPE_S32);
     69            PS_ARRAY_ADD_SCALAR(job->args, maskVal,  PS_TYPE_IMAGE_MASK);
     70            PS_ARRAY_ADD_SCALAR(job->args, 0,        PS_TYPE_S32); // this is used as a return value for nAp
     71
     72            if (!psThreadJobAddPending(job)) {
     73                psError(PS_ERR_UNKNOWN, false, "Unable to guess model.");
     74                psFree (job);
     75                return false;
     76            }
     77            psFree(job);
    7878
    7979# if (0)
    80                 int nap = 0;
    81                 if (!psphotMagnitudes_Unthreaded (&nap, cells->data[j], psf, binning, backModel, backStdev, photMode, maskVal)) {
    82                     psError(PS_ERR_UNKNOWN, false, "Unable to guess model.");
    83                     return false;
    84                 }
    85                 Nap += nap;
     80                int nap = 0;
     81                if (!psphotMagnitudes_Unthreaded (&nap, cells->data[j], psf, binning, backModel, backStdev, photMode, maskVal)) {
     82                    psError(PS_ERR_UNKNOWN, false, "Unable to guess model.");
     83                    return false;
     84                }
     85                Nap += nap;
    8686# endif
    87         }
    88 
    89         // wait for the threads to finish and manage results
    90         if (!psThreadPoolWait (false)) {
    91             psError(PS_ERR_UNKNOWN, false, "Unable to guess model.");
    92             return false;
    93         }
    94 
    95         // we have only supplied one type of job, so we can assume the types here
    96         psThreadJob *job = NULL;
    97         while ((job = psThreadJobGetDone()) != NULL) {
    98             if (job->args->n < 1) {
    99                 fprintf (stderr, "error with job\n");
    100             } else {
    101                 psScalar *scalar = job->args->data[7];
    102                 Nap += scalar->data.S32;
    103             }
    104             psFree(job);
    105         }
     87        }
     88
     89        // wait for the threads to finish and manage results
     90        if (!psThreadPoolWait (false)) {
     91            psError(PS_ERR_UNKNOWN, false, "Unable to guess model.");
     92            return false;
     93        }
     94
     95        // we have only supplied one type of job, so we can assume the types here
     96        psThreadJob *job = NULL;
     97        while ((job = psThreadJobGetDone()) != NULL) {
     98            if (job->args->n < 1) {
     99                fprintf (stderr, "error with job\n");
     100            } else {
     101                psScalar *scalar = job->args->data[7];
     102                Nap += scalar->data.S32;
     103            }
     104            psFree(job);
     105        }
    106106    }
    107107
     
    130130        if (status && isfinite(source->apMag)) Nap ++;
    131131
    132         if (backModel) {
    133             psAssert (binning, "if backModel is defined, so should binning be");
    134             source->sky = psImageUnbinPixel(source->peak->x, source->peak->y, backModel->image, binning);
    135             if (isnan(source->sky) && false) {
    136                 psLogMsg ("psphot.magnitudes", PS_LOG_DETAIL, "error setting pmSource.sky");
    137             }
    138         } else {
    139             source->sky = NAN;
    140         }
    141 
    142         if (backStdev) {
    143             psAssert (binning, "if backStdev is defined, so should binning be");
    144             source->skyErr = psImageUnbinPixel(source->peak->x, source->peak->y, backStdev->image, binning);
    145             if (isnan(source->skyErr) && false) {
    146                 psLogMsg ("psphot.magnitudes", PS_LOG_DETAIL, "error setting pmSource.skyErr");
    147             }
    148         } else {
    149             source->skyErr = NAN;
    150         }
     132        if (backModel) {
     133            psAssert (binning, "if backModel is defined, so should binning be");
     134            source->sky = psImageUnbinPixel(source->peak->x, source->peak->y, backModel->image, binning);
     135            if (isnan(source->sky) && false) {
     136                psLogMsg ("psphot.magnitudes", PS_LOG_DETAIL, "error setting pmSource.sky");
     137            }
     138        } else {
     139            source->sky = NAN;
     140        }
     141
     142        if (backStdev) {
     143            psAssert (binning, "if backStdev is defined, so should binning be");
     144            source->skyErr = psImageUnbinPixel(source->peak->x, source->peak->y, backStdev->image, binning);
     145            if (isnan(source->skyErr) && false) {
     146                psLogMsg ("psphot.magnitudes", PS_LOG_DETAIL, "error setting pmSource.skyErr");
     147            }
     148        } else {
     149            source->skyErr = NAN;
     150        }
    151151    }
    152152
     
    169169        if (status && isfinite(source->apMag)) Nap ++;
    170170
    171         if (backModel) {
    172             psAssert (binning, "if backModel is defined, so should binning be");
    173             source->sky = psImageUnbinPixel(source->peak->x, source->peak->y, backModel->image, binning);
    174             if (isnan(source->sky) && false) {
    175                 psLogMsg ("psphot.magnitudes", PS_LOG_DETAIL, "error setting pmSource.sky");
    176             }
    177         } else {
    178             source->sky = NAN;
    179         }
    180 
    181         if (backStdev) {
    182             psAssert (binning, "if backStdev is defined, so should binning be");
    183             source->skyErr = psImageUnbinPixel(source->peak->x, source->peak->y, backStdev->image, binning);
    184             if (isnan(source->skyErr) && false) {
    185                 psLogMsg ("psphot.magnitudes", PS_LOG_DETAIL, "error setting pmSource.skyErr");
    186             }
    187         } else {
    188             source->skyErr = NAN;
    189         }
     171        if (backModel) {
     172            psAssert (binning, "if backModel is defined, so should binning be");
     173            source->sky = psImageUnbinPixel(source->peak->x, source->peak->y, backModel->image, binning);
     174            if (isnan(source->sky) && false) {
     175                psLogMsg ("psphot.magnitudes", PS_LOG_DETAIL, "error setting pmSource.sky");
     176            }
     177        } else {
     178            source->sky = NAN;
     179        }
     180
     181        if (backStdev) {
     182            psAssert (binning, "if backStdev is defined, so should binning be");
     183            source->skyErr = psImageUnbinPixel(source->peak->x, source->peak->y, backStdev->image, binning);
     184            if (isnan(source->skyErr) && false) {
     185                psLogMsg ("psphot.magnitudes", PS_LOG_DETAIL, "error setting pmSource.skyErr");
     186            }
     187        } else {
     188            source->skyErr = NAN;
     189        }
    190190    }
    191191
     
    210210    int nThreads = psMetadataLookupS32(&status, config->arguments, "NTHREADS"); // Number of threads
    211211    if (!status) {
    212         nThreads = 0;
     212        nThreads = 0;
    213213    }
    214214    nThreads = 0; // XXX until testing is complete, do not thread this function
     
    233233    for (int i = 0; i < cellGroups->n; i++) {
    234234
    235         psArray *cells = cellGroups->data[i];
    236 
    237         for (int j = 0; j < cells->n; j++) {
    238 
    239             // allocate a job -- if threads are not defined, this just runs the job
    240             psThreadJob *job = psThreadJobAlloc ("PSPHOT_PSF_WEIGHTS");
    241 
    242             psArrayAdd(job->args, 1, cells->data[j]); // sources
    243             PS_ARRAY_ADD_SCALAR(job->args, maskVal,  PS_TYPE_IMAGE_MASK);
    244 
    245             if (!psThreadJobAddPending(job)) {
    246                 psError(PS_ERR_UNKNOWN, false, "Unable to guess model.");
    247                 psFree (job);
    248                 return false;
    249             }
    250             psFree(job);
    251 
    252         }
    253 
    254         // wait for the threads to finish and manage results
    255         if (!psThreadPoolWait (false)) {
    256             psError(PS_ERR_UNKNOWN, false, "Unable to guess model.");
    257             return false;
    258         }
    259 
    260         // we have only supplied one type of job, so we can assume the types here
    261         psThreadJob *job = NULL;
    262         while ((job = psThreadJobGetDone()) != NULL) {
    263             if (job->args->n < 1) {
    264                 fprintf (stderr, "error with job\n");
    265             }
    266             psFree(job);
    267         }
     235        psArray *cells = cellGroups->data[i];
     236
     237        for (int j = 0; j < cells->n; j++) {
     238
     239            // allocate a job -- if threads are not defined, this just runs the job
     240            psThreadJob *job = psThreadJobAlloc ("PSPHOT_PSF_WEIGHTS");
     241
     242            psArrayAdd(job->args, 1, cells->data[j]); // sources
     243            PS_ARRAY_ADD_SCALAR(job->args, maskVal,  PS_TYPE_IMAGE_MASK);
     244
     245            if (!psThreadJobAddPending(job)) {
     246                psError(PS_ERR_UNKNOWN, false, "Unable to guess model.");
     247                psFree (job);
     248                return false;
     249            }
     250            psFree(job);
     251
     252        }
     253
     254        // wait for the threads to finish and manage results
     255        if (!psThreadPoolWait (false)) {
     256            psError(PS_ERR_UNKNOWN, false, "Unable to guess model.");
     257            return false;
     258        }
     259
     260        // we have only supplied one type of job, so we can assume the types here
     261        psThreadJob *job = NULL;
     262        while ((job = psThreadJobGetDone()) != NULL) {
     263            if (job->args->n < 1) {
     264                fprintf (stderr, "error with job\n");
     265            }
     266            psFree(job);
     267        }
    268268    }
    269269
     
    285285        pmSource *source = (pmSource *) sources->data[i];
    286286
    287         // we must have a valid model
    288         pmModel *model = pmSourceGetModel (&isPSF, source);
    289         if (model == NULL) {
    290           psTrace ("psphot", 3, "fail mag : no valid model");
    291           source->pixWeight = NAN;
    292           continue;
    293         }
     287        // we must have a valid model
     288        pmModel *model = pmSourceGetModel (&isPSF, source);
     289        if (model == NULL) {
     290          psTrace ("psphot", 3, "fail mag : no valid model");
     291          source->pixWeight = NAN;
     292          continue;
     293        }
    294294
    295295        status = pmSourcePixelWeight (&source->pixWeight, model, source->maskObj, maskVal);
    296         if (!status) {
    297           psTrace ("psphot", 3, "fail to measure pixel weight");
    298           source->pixWeight = NAN;
    299           continue;
    300         }
    301 
    302     }
    303 
    304     return true;
    305 }
     296        if (!status) {
     297          psTrace ("psphot", 3, "fail to measure pixel weight");
     298          source->pixWeight = NAN;
     299          continue;
     300        }
     301
     302    }
     303
     304    return true;
     305}
  • trunk/psphot/src/psphotModelBackground.c

    r23259 r23287  
    3131static bool backgroundModel(psImage *model,  // Model image
    3232                            psImage *modelStdev, // Model stdev image
    33                             psImage *image, // Image for which to generate a background model
    34                             psImage *mask, // Mask for image
     33                            psMetadata *analysis, // Analysis metadata for outputs
     34                            pmReadout *readout, // Readout for which to generate a background model
    3535                            psImageBinning *binning, // Binning parameters
    3636                            const pmConfig *config // Configuration
     
    4040
    4141    bool status = true;
     42
     43    psImage *image = readout->image, *mask = readout->mask; // Image and mask for readout
    4244
    4345    // select the appropriate recipe information
     
    135137
    136138    // we save the binning structure for use in psphotMagnitudes
    137     status = psMetadataAddPtr(recipe, PS_LIST_TAIL, "PSPHOT.BACKGROUND.BINNING", PS_DATA_UNKNOWN | PS_META_REPLACE, "Background binning", binning);
    138     PS_ASSERT (status, false);
    139 
     139    psMetadataAddPtr(analysis, PS_LIST_TAIL, "PSPHOT.BACKGROUND.BINNING",
     140                     PS_DATA_UNKNOWN | PS_META_REPLACE, "Background binning", binning);
    140141
    141142    psF32 **modelData = model->data.F32;
     
    338339    psImage *modelStdev = psImageAlloc(binning->nXruff, binning->nYruff, PS_TYPE_F32); // Standard deviation
    339340
    340     if (!backgroundModel(model, modelStdev, ro->image, ro->mask, binning, config)) {
     341    if (!backgroundModel(model, modelStdev, ro->analysis, ro, binning, config)) {
    341342        psFree(model);
    342343        psFree(modelStdev);
     
    360361    pmFPAfile *file = psMetadataLookupPtr (&status, config->files, filename);
    361362    pmFPA *inFPA = file->fpa;
    362     pmReadout *readout = pmFPAviewThisReadout (view, inFPA);
    363     psImage *image = readout->image;
    364     psImage *mask  = readout->mask;
    365 
    366     psImageBinning *binning = backgroundBinning(image, config); // Image binning parameters
     363    pmReadout *readout = pmFPAviewThisReadout(view, inFPA);
     364
     365    psImageBinning *binning = backgroundBinning(readout->image, config); // Image binning parameters
    367366    pmReadout *model = pmFPAGenerateReadout(config, view, "PSPHOT.BACKMDL", inFPA, binning);
    368367    pmReadout *modelStdev = pmFPAGenerateReadout(config, view, "PSPHOT.BACKMDL.STDEV", inFPA, binning);
    369368
    370     if (!backgroundModel(model->image, modelStdev->image, image, mask, binning, config)) {
     369    if (!backgroundModel(model->image, modelStdev->image, model->analysis, readout, binning, config)) {
    371370        psError(PS_ERR_UNKNOWN, false, "Unable to generate background model");
    372371        return false;
  • trunk/psphot/src/psphotSubtractBackground.c

    r21183 r23287  
    44// generate the median in NxN boxes, clipping heavily
    55// linear interpolation to generate full-scale model
    6 bool psphotSubtractBackground (pmConfig *config, const pmFPAview *view, const char *filename) 
     6bool psphotSubtractBackground (pmConfig *config, const pmFPAview *view, const char *filename)
    77{
    88    bool status = true;
     
    3131    assert (maskVal);
    3232
    33     psImageBinning *binning = psMetadataLookupPtr(&status, recipe, "PSPHOT.BACKGROUND.BINNING");
     33    psImageBinning *binning = psMetadataLookupPtr(&status, model->analysis, "PSPHOT.BACKGROUND.BINNING");
    3434    assert (binning);
    3535
Note: See TracChangeset for help on using the changeset viewer.