Changeset 23287 for trunk/psphot/src
- Timestamp:
- Mar 11, 2009, 5:22:15 PM (17 years ago)
- Location:
- trunk/psphot/src
- Files:
-
- 3 edited
-
psphotMagnitudes.c (modified) (8 diffs)
-
psphotModelBackground.c (modified) (5 diffs)
-
psphotSubtractBackground.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psphot/src/psphotMagnitudes.c
r21519 r23287 15 15 int nThreads = psMetadataLookupS32(&status, config->arguments, "NTHREADS"); // Number of threads 16 16 if (!status) { 17 nThreads = 0;17 nThreads = 0; 18 18 } 19 19 … … 36 36 37 37 // 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"); 39 39 40 40 bool IGNORE_GROWTH = psMetadataLookupBool (&status, recipe, "IGNORE_GROWTH"); … … 53 53 for (int i = 0; i < cellGroups->n; i++) { 54 54 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 job60 psThreadJob *job = psThreadJobAlloc ("PSPHOT_MAGNITUDES");61 62 psArrayAdd(job->args, 1, cells->data[j]); // sources63 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 nAp71 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); 78 78 79 79 # 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; 86 86 # endif 87 }88 89 // wait for the threads to finish and manage results90 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 here96 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 } 106 106 } 107 107 … … 130 130 if (status && isfinite(source->apMag)) Nap ++; 131 131 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 } 151 151 } 152 152 … … 169 169 if (status && isfinite(source->apMag)) Nap ++; 170 170 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 } 190 190 } 191 191 … … 210 210 int nThreads = psMetadataLookupS32(&status, config->arguments, "NTHREADS"); // Number of threads 211 211 if (!status) { 212 nThreads = 0;212 nThreads = 0; 213 213 } 214 214 nThreads = 0; // XXX until testing is complete, do not thread this function … … 233 233 for (int i = 0; i < cellGroups->n; i++) { 234 234 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 job240 psThreadJob *job = psThreadJobAlloc ("PSPHOT_PSF_WEIGHTS");241 242 psArrayAdd(job->args, 1, cells->data[j]); // sources243 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 results255 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 here261 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 } 268 268 } 269 269 … … 285 285 pmSource *source = (pmSource *) sources->data[i]; 286 286 287 // we must have a valid model288 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 } 294 294 295 295 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 31 31 static bool backgroundModel(psImage *model, // Model image 32 32 psImage *modelStdev, // Model stdev image 33 ps Image *image, // Image for which to generate a background model34 p sImage *mask, // Mask for image33 psMetadata *analysis, // Analysis metadata for outputs 34 pmReadout *readout, // Readout for which to generate a background model 35 35 psImageBinning *binning, // Binning parameters 36 36 const pmConfig *config // Configuration … … 40 40 41 41 bool status = true; 42 43 psImage *image = readout->image, *mask = readout->mask; // Image and mask for readout 42 44 43 45 // select the appropriate recipe information … … 135 137 136 138 // 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); 140 141 141 142 psF32 **modelData = model->data.F32; … … 338 339 psImage *modelStdev = psImageAlloc(binning->nXruff, binning->nYruff, PS_TYPE_F32); // Standard deviation 339 340 340 if (!backgroundModel(model, modelStdev, ro-> image, ro->mask, binning, config)) {341 if (!backgroundModel(model, modelStdev, ro->analysis, ro, binning, config)) { 341 342 psFree(model); 342 343 psFree(modelStdev); … … 360 361 pmFPAfile *file = psMetadataLookupPtr (&status, config->files, filename); 361 362 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 367 366 pmReadout *model = pmFPAGenerateReadout(config, view, "PSPHOT.BACKMDL", inFPA, binning); 368 367 pmReadout *modelStdev = pmFPAGenerateReadout(config, view, "PSPHOT.BACKMDL.STDEV", inFPA, binning); 369 368 370 if (!backgroundModel(model->image, modelStdev->image, image, mask, binning, config)) {369 if (!backgroundModel(model->image, modelStdev->image, model->analysis, readout, binning, config)) { 371 370 psError(PS_ERR_UNKNOWN, false, "Unable to generate background model"); 372 371 return false; -
trunk/psphot/src/psphotSubtractBackground.c
r21183 r23287 4 4 // generate the median in NxN boxes, clipping heavily 5 5 // linear interpolation to generate full-scale model 6 bool psphotSubtractBackground (pmConfig *config, const pmFPAview *view, const char *filename) 6 bool psphotSubtractBackground (pmConfig *config, const pmFPAview *view, const char *filename) 7 7 { 8 8 bool status = true; … … 31 31 assert (maskVal); 32 32 33 psImageBinning *binning = psMetadataLookupPtr(&status, recipe, "PSPHOT.BACKGROUND.BINNING");33 psImageBinning *binning = psMetadataLookupPtr(&status, model->analysis, "PSPHOT.BACKGROUND.BINNING"); 34 34 assert (binning); 35 35
Note:
See TracChangeset
for help on using the changeset viewer.
