Changeset 21359 for trunk/psphot/src/psphotGuessModels.c
- Timestamp:
- Feb 5, 2009, 3:12:59 PM (17 years ago)
- File:
-
- 1 edited
-
trunk/psphot/src/psphotGuessModels.c (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psphot/src/psphotGuessModels.c
r21183 r21359 22 22 } 23 23 24 bool psphotGuessModel_Unthreaded (pmReadout *readout, psArray *sources, pmPSF *psf, psImageMaskType maskVal, psImageMaskType markVal); 25 24 26 // construct an initial PSF model for each object 25 27 bool psphotGuessModels (pmConfig *config, pmReadout *readout, psArray *sources, pmPSF *psf) { … … 38 40 nThreads = 0; 39 41 } 40 // nThreads = 0; // XXX until testing is complete, do not thread this function41 42 42 43 // bit-masks to test for good/bad pixels … … 66 67 for (int j = 0; j < cells->n; j++) { 67 68 68 // allocate a job -- if threads are not defined, this just runs the job 69 psThreadJob *job = psThreadJobAlloc ("PSPHOT_GUESS_MODEL"); 70 psArrayAdd(job->args, 1, readout); 71 psArrayAdd(job->args, 1, cells->data[j]); // sources 72 psArrayAdd(job->args, 1, psf); 73 74 // XXX change these to use abstract mask type info 75 PS_ARRAY_ADD_SCALAR(job->args, maskVal, PS_TYPE_IMAGE_MASK); 76 PS_ARRAY_ADD_SCALAR(job->args, markVal, PS_TYPE_IMAGE_MASK); 77 78 if (!psThreadJobAddPending(job)) { 69 if (nThreads) { 70 // allocate a job -- if threads are not defined, this just runs the job 71 psThreadJob *job = psThreadJobAlloc ("PSPHOT_GUESS_MODEL"); 72 psArrayAdd(job->args, 1, readout); 73 psArrayAdd(job->args, 1, cells->data[j]); // sources 74 psArrayAdd(job->args, 1, psf); 75 76 // XXX change these to use abstract mask type info 77 PS_ARRAY_ADD_SCALAR(job->args, maskVal, PS_TYPE_IMAGE_MASK); 78 PS_ARRAY_ADD_SCALAR(job->args, markVal, PS_TYPE_IMAGE_MASK); 79 80 if (!psThreadJobAddPending(job)) { 81 psError(PS_ERR_UNKNOWN, false, "Unable to guess model."); 82 psFree (job); 83 return false; 84 } 85 psFree(job); 86 } else { 87 if (!psphotGuessModel_Unthreaded (readout, cells->data[j], psf, maskVal, markVal)) { 88 psError(PS_ERR_UNKNOWN, false, "Unable to guess model."); 89 return false; 90 } 91 } 92 } 93 94 if (nThreads) { 95 // wait for the threads to finish and manage results 96 // wait here for the threaded jobs to finish 97 // fprintf (stderr, "wait for threads (%d, %d)\n", jx, jy); 98 if (!psThreadPoolWait (false)) { 79 99 psError(PS_ERR_UNKNOWN, false, "Unable to guess model."); 80 psFree (job);81 100 return false; 82 101 } 83 psFree(job); 84 } 85 86 // wait for the threads to finish and manage results 87 // wait here for the threaded jobs to finish 88 // fprintf (stderr, "wait for threads (%d, %d)\n", jx, jy); 89 if (!psThreadPoolWait (false)) { 90 psError(PS_ERR_UNKNOWN, false, "Unable to guess model."); 91 return false; 92 } 93 94 // we have only supplied one type of job, so we can assume the types here 95 psThreadJob *job = NULL; 96 while ((job = psThreadJobGetDone()) != NULL) { 97 // we have no returned data from this operation 98 if (job->args->n < 1) { 99 fprintf (stderr, "error with job\n"); 100 } 101 psFree(job); 102 103 // we have only supplied one type of job, so we can assume the types here 104 psThreadJob *job = NULL; 105 while ((job = psThreadJobGetDone()) != NULL) { 106 // we have no returned data from this operation 107 if (job->args->n < 1) { 108 fprintf (stderr, "error with job\n"); 109 } 110 psFree(job); 111 } 102 112 } 103 113 } … … 211 221 } 212 222 223 // construct models only for sources in the specified region 224 bool psphotGuessModel_Unthreaded (pmReadout *readout, psArray *sources, pmPSF *psf, psImageMaskType maskVal, psImageMaskType markVal) { 225 226 int nSrc = 0; 227 228 for (int i = 0; i < sources->n; i++) { 229 pmSource *source = sources->data[i]; 230 231 // XXXX this is just for a test: use this to mark sources for which the model is measured 232 // check later that all are used. 233 source->mode |= PM_SOURCE_MODE_EXT_LIMIT; 234 235 // skip non-astronomical objects (very likely defects) 236 if (source->type == PM_SOURCE_TYPE_DEFECT) continue; 237 if (source->type == PM_SOURCE_TYPE_SATURATED) continue; 238 if (!source->peak) continue; 239 240 nSrc ++; 241 242 // XXX if a source is faint, it will not have moments measured. 243 // it must be modelled as a PSF. In this case, we need to use 244 // the peak centroid to get the coordinates and get the peak flux 245 // from the image? 246 pmModel *modelEXT; 247 if (!source->moments) { 248 modelEXT = wildGuess(source, psf); 249 } else { 250 // use the source moments, etc to guess basic model parameters 251 modelEXT = pmSourceModelGuess (source, psf->type); // ALLOC 252 if (!modelEXT) { 253 modelEXT = wildGuess(source, psf); 254 } 255 // these valuse are set in pmSourceModelGuess, should this rule be in there as well? 256 if (source->mode & PM_SOURCE_MODE_SATSTAR) { 257 modelEXT->params->data.F32[PM_PAR_XPOS] = source->moments->Mx; 258 modelEXT->params->data.F32[PM_PAR_YPOS] = source->moments->My; 259 } else { 260 modelEXT->params->data.F32[PM_PAR_XPOS] = source->peak->xf; 261 modelEXT->params->data.F32[PM_PAR_YPOS] = source->peak->yf; 262 } 263 } 264 265 // set PSF parameters for this model (apply 2D shape model) 266 pmModel *modelPSF = pmModelFromPSF (modelEXT, psf); // ALLOC 267 if (modelPSF == NULL) { 268 psError(PSPHOT_ERR_PSF, false, 269 "Failed to determine PSF model at r,c = (%d,%d); trying centre of image", 270 source->peak->y, source->peak->x); 271 // 272 // Try the centre of the image 273 // 274 modelEXT->params->data.F32[PM_PAR_XPOS] = 0.5*readout->image->numCols; 275 modelEXT->params->data.F32[PM_PAR_YPOS] = 0.5*readout->image->numRows; 276 modelPSF = pmModelFromPSF (modelEXT, psf); 277 if (modelPSF == NULL) { 278 psError(PSPHOT_ERR_PSF, false, 279 "Failed to determine PSF model at centre of image"); 280 psFree(modelEXT); 281 return false; 282 } 283 284 source->mode |= PM_SOURCE_MODE_BADPSF; 285 } 286 psFree (modelEXT); 287 288 // XXX need to define the guess flux? 289 // set the fit radius based on the object flux limit and the model 290 // this function affects the mask pixels 291 psphotCheckRadiusPSF (readout, source, modelPSF, markVal); 292 293 // set the source PSF model 294 source->modelPSF = modelPSF; 295 source->modelPSF->residuals = psf->residuals; 296 297 pmSourceCacheModel (source, maskVal); 298 299 } 300 301 return true; 302 }
Note:
See TracChangeset
for help on using the changeset viewer.
