Changeset 21359 for trunk/psphot/src/psphotMagnitudes.c
- Timestamp:
- Feb 5, 2009, 3:12:59 PM (17 years ago)
- File:
-
- 1 edited
-
trunk/psphot/src/psphotMagnitudes.c (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psphot/src/psphotMagnitudes.c
r21252 r21359 1 1 # include "psphotInternal.h" 2 3 bool psphotMagnitudes_Unthreaded (int *nap, psArray *sources, pmPSF *psf, psImageBinning *binning, pmReadout *backModel, pmReadout *backStdev, pmSourcePhotometryMode photMode, psImageMaskType maskVal); 2 4 3 5 bool psphotMagnitudes(pmConfig *config, pmReadout *readout, const pmFPAview *view, psArray *sources, pmPSF *psf) { … … 17 19 nThreads = 0; 18 20 } 19 // nThreads = 0; // XXX until testing is complete, do not thread this function20 21 21 22 // if backModel or backStdev are missing, the values of sky and/or skyErr will be set to NAN … … 58 59 for (int j = 0; j < cells->n; j++) { 59 60 60 // allocate a job -- if threads are not defined, this just runs the job 61 psThreadJob *job = psThreadJobAlloc ("PSPHOT_MAGNITUDES"); 62 63 psArrayAdd(job->args, 1, cells->data[j]); // sources 64 psArrayAdd(job->args, 1, psf); 65 psArrayAdd(job->args, 1, binning); 66 psArrayAdd(job->args, 1, backModel); 67 psArrayAdd(job->args, 1, backStdev); 68 69 PS_ARRAY_ADD_SCALAR(job->args, photMode, PS_TYPE_S32); 70 PS_ARRAY_ADD_SCALAR(job->args, maskVal, PS_TYPE_U8); // XXX change this to use abstract mask type info 71 PS_ARRAY_ADD_SCALAR(job->args, 0, PS_TYPE_S32); // this is used as a return value for nAp 72 73 if (!psThreadJobAddPending(job)) { 61 if (nThreads) { 62 // allocate a job -- if threads are not defined, this just runs the job 63 psThreadJob *job = psThreadJobAlloc ("PSPHOT_MAGNITUDES"); 64 65 psArrayAdd(job->args, 1, cells->data[j]); // sources 66 psArrayAdd(job->args, 1, psf); 67 psArrayAdd(job->args, 1, binning); 68 psArrayAdd(job->args, 1, backModel); 69 psArrayAdd(job->args, 1, backStdev); 70 71 PS_ARRAY_ADD_SCALAR(job->args, photMode, PS_TYPE_S32); 72 PS_ARRAY_ADD_SCALAR(job->args, maskVal, PS_TYPE_IMAGE_MASK); 73 PS_ARRAY_ADD_SCALAR(job->args, 0, PS_TYPE_S32); // this is used as a return value for nAp 74 75 if (!psThreadJobAddPending(job)) { 76 psError(PS_ERR_UNKNOWN, false, "Unable to guess model."); 77 psFree (job); 78 return false; 79 } 80 psFree(job); 81 } else { 82 int nap = 0; 83 if (!psphotMagnitudes_Unthreaded (&nap, cells->data[j], psf, binning, backModel, backStdev, photMode, maskVal)) { 84 psError(PS_ERR_UNKNOWN, false, "Unable to guess model."); 85 return false; 86 } 87 Nap += nap; 88 } 89 } 90 91 if (nThreads) { 92 // wait for the threads to finish and manage results 93 if (!psThreadPoolWait (false)) { 74 94 psError(PS_ERR_UNKNOWN, false, "Unable to guess model."); 75 psFree (job);76 95 return false; 77 96 } 78 psFree(job); 79 80 } 81 82 // wait for the threads to finish and manage results 83 if (!psThreadPoolWait (false)) { 84 psError(PS_ERR_UNKNOWN, false, "Unable to guess model."); 85 return false; 86 } 87 88 // we have only supplied one type of job, so we can assume the types here 89 psThreadJob *job = NULL; 90 while ((job = psThreadJobGetDone()) != NULL) { 91 if (job->args->n < 1) { 92 fprintf (stderr, "error with job\n"); 93 } else { 94 psScalar *scalar = job->args->data[7]; 95 Nap += scalar->data.S32; 96 } 97 psFree(job); 97 98 // we have only supplied one type of job, so we can assume the types here 99 psThreadJob *job = NULL; 100 while ((job = psThreadJobGetDone()) != NULL) { 101 if (job->args->n < 1) { 102 fprintf (stderr, "error with job\n"); 103 } else { 104 psScalar *scalar = job->args->data[7]; 105 Nap += scalar->data.S32; 106 } 107 psFree(job); 108 } 98 109 } 99 110 } … … 116 127 pmReadout *backStdev = job->args->data[4]; 117 128 pmSourcePhotometryMode photMode = PS_SCALAR_VALUE(job->args->data[5],S32); 118 ps MaskType maskVal = PS_SCALAR_VALUE(job->args->data[6],U8);129 psImageMaskType maskVal = PS_SCALAR_VALUE(job->args->data[6],PS_TYPE_IMAGE_MASK_DATA); 119 130 120 131 for (int i = 0; i < sources->n; i++) { … … 150 161 return true; 151 162 } 163 164 bool psphotMagnitudes_Unthreaded (int *nap, psArray *sources, pmPSF *psf, psImageBinning *binning, pmReadout *backModel, pmReadout *backStdev, pmSourcePhotometryMode photMode, psImageMaskType maskVal) { 165 166 bool status; 167 int Nap = 0; 168 169 for (int i = 0; i < sources->n; i++) { 170 pmSource *source = (pmSource *) sources->data[i]; 171 status = pmSourceMagnitudes (source, psf, photMode, maskVal); 172 if (status && isfinite(source->apMag)) Nap ++; 173 174 if (backModel) { 175 psAssert (binning, "if backModel is defined, so should binning be"); 176 source->sky = psImageUnbinPixel(source->peak->x, source->peak->y, backModel->image, binning); 177 if (isnan(source->sky) && false) { 178 psLogMsg ("psphot.magnitudes", PS_LOG_DETAIL, "error setting pmSource.sky"); 179 } 180 } else { 181 source->sky = NAN; 182 } 183 184 if (backStdev) { 185 psAssert (binning, "if backStdev is defined, so should binning be"); 186 source->skyErr = psImageUnbinPixel(source->peak->x, source->peak->y, backStdev->image, binning); 187 if (isnan(source->skyErr) && false) { 188 psLogMsg ("psphot.magnitudes", PS_LOG_DETAIL, "error setting pmSource.skyErr"); 189 } 190 } else { 191 source->skyErr = NAN; 192 } 193 } 194 195 // change the value of a scalar on the array (wrap this and put it in psArray.h) 196 *nap = Nap; 197 198 return true; 199 } 200 201 # if (0) 202 bool psphotPSFWeights(pmConfig *config, pmReadout *readout, const pmFPAview *view, psArray *sources, pmPSF *psf) { 203 204 bool status = false; 205 int Nap = 0; 206 207 psTimerStart ("psphot.mags"); 208 209 // select the appropriate recipe information 210 psMetadata *recipe = psMetadataLookupPtr (&status, config->recipes, PSPHOT_RECIPE); 211 assert (recipe); 212 213 // determine the number of allowed threads 214 int nThreads = psMetadataLookupS32(&status, config->arguments, "NTHREADS"); // Number of threads 215 if (!status) { 216 nThreads = 0; 217 } 218 nThreads = 0; // XXX until testing is complete, do not thread this function 219 220 // bit-masks to test for good/bad pixels 221 psImageMaskType maskVal = psMetadataLookupImageMask(&status, recipe, "MASK.PSPHOT"); 222 assert (maskVal); 223 224 // bit-mask to mark pixels not used in analysis 225 psImageMaskType markVal = psMetadataLookupImageMask(&status, recipe, "MARK.PSPHOT"); 226 assert (markVal); 227 228 // maskVal is used to test for rejected pixels, and must include markVal 229 maskVal |= markVal; 230 231 pmSourcePhotometryMode photMode = PM_SOURCE_PHOT_APCORR | PM_SOURCE_PHOT_WEIGHT; 232 if (!IGNORE_GROWTH) photMode |= PM_SOURCE_PHOT_GROWTH; 233 if (INTERPOLATE_AP) photMode |= PM_SOURCE_PHOT_INTERP; 234 235 // choose Cx, Cy (see psphotThreadTools.c for overview of the concepts) 236 int Cx = 1, Cy = 1; 237 psphotChooseCellSizes (&Cx, &Cy, readout, nThreads); 238 239 psArray *cellGroups = psphotAssignSources (Cx, Cy, sources); 240 241 for (int i = 0; i < cellGroups->n; i++) { 242 243 psArray *cells = cellGroups->data[i]; 244 245 for (int j = 0; j < cells->n; j++) { 246 247 // allocate a job -- if threads are not defined, this just runs the job 248 psThreadJob *job = psThreadJobAlloc ("PSPHOT_PSF_WEIGHTS"); 249 250 psArrayAdd(job->args, 1, cells->data[j]); // sources 251 psArrayAdd(job->args, 1, psf); 252 PS_ARRAY_ADD_SCALAR(job->args, maskVal, PS_TYPE_IMAGE_MASK); 253 254 if (!psThreadJobAddPending(job)) { 255 psError(PS_ERR_UNKNOWN, false, "Unable to guess model."); 256 psFree (job); 257 return false; 258 } 259 psFree(job); 260 261 } 262 263 // wait for the threads to finish and manage results 264 if (!psThreadPoolWait (false)) { 265 psError(PS_ERR_UNKNOWN, false, "Unable to guess model."); 266 return false; 267 } 268 269 // we have only supplied one type of job, so we can assume the types here 270 psThreadJob *job = NULL; 271 while ((job = psThreadJobGetDone()) != NULL) { 272 if (job->args->n < 1) { 273 fprintf (stderr, "error with job\n"); 274 } 275 psFree(job); 276 } 277 } 278 279 psFree (cellGroups); 280 281 psLogMsg ("psphot", PS_LOG_DETAIL, "measure psf weights : %f sec for %ld objects\n", psTimerMark ("psphot.mags"), sources->n); 282 return true; 283 } 284 285 bool psphotPSFWeights_Threaded (psThreadJob *job) { 286 287 bool status; 288 bool isPSF; 289 290 psArray *sources = job->args->data[0]; 291 pmPSF *psf = job->args->data[1]; 292 psImageMaskType maskVal = PS_SCALAR_VALUE(job->args->data[2],PS_TYPE_IMAGE_MASK_DATA); 293 294 for (int i = 0; i < sources->n; i++) { 295 pmSource *source = (pmSource *) sources->data[i]; 296 297 // we must have a valid model 298 pmModel *model = pmSourceGetModel (&isPSF, source); 299 if (model == NULL) { 300 psTrace ("psphot", 3, "fail mag : no valid model"); 301 source->pixWeight = NAN; 302 continue; 303 } 304 305 status = pmSourcePixelWeight (&source->pixWeight, model, source->pixels, source->maskObj, maskVal); 306 if (!status) { 307 psTrace ("psphot", 3, "fail to measure pixel weight"); 308 source->pixWeight = NAN; 309 continue; 310 } 311 312 } 313 314 return true; 315 } 316 317 # endif 318
Note:
See TracChangeset
for help on using the changeset viewer.
