Changeset 25988
- Timestamp:
- Nov 1, 2009, 4:02:18 PM (17 years ago)
- File:
-
- 1 edited
-
trunk/psphot/src/psphotSourceStats.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psphot/src/psphotSourceStats.c
r25958 r25988 141 141 } 142 142 143 bool psphotSourceStatsUpdate (psArray *sources, pmConfig *config, pmReadout *readout) { 144 145 bool status = false; 146 147 psTimerStart ("psphot.stats"); 148 149 // select the appropriate recipe information 150 psMetadata *recipe = psMetadataLookupPtr (&status, config->recipes, PSPHOT_RECIPE); 151 assert (recipe); 152 153 // determine the number of allowed threads 154 int nThreads = psMetadataLookupS32(&status, config->arguments, "NTHREADS"); // Number of threads 155 if (!status) { 156 nThreads = 0; 157 } 158 159 // determine properties (sky, moments) of initial sources 160 float OUTER = psMetadataLookupF32 (&status, recipe, "SKY_OUTER_RADIUS"); 161 if (!status) return NULL; 162 163 OUTER = PS_MAX(OUTER, 20.0); // XXX Guarantee that we can encompass the max moments radius 164 165 char *breakPt = psMetadataLookupStr (&status, recipe, "BREAK_POINT"); 166 if (!status) return NULL; 167 168 for (int i = 0; i < sources->n; i++) { 169 170 pmSource *source = sources->data[i]; 171 if (!source->peak) continue; // XXX how can we have a peak-less source? 172 173 // allocate space for moments 174 if (!source->moments) { 175 source->moments = pmMomentsAlloc(); 176 } 177 178 // allocate image, weight, mask arrays for each peak (square of radius OUTER) 179 pmSourceDefinePixels (source, readout, source->peak->x, source->peak->y, OUTER); 180 source->peak->assigned = true; 181 } 182 183 if (!strcasecmp (breakPt, "PEAKS")) { 184 psLogMsg ("psphot", PS_LOG_INFO, "%ld sources : %f sec\n", sources->n, psTimerMark ("psphot.stats")); 185 psLogMsg ("psphot", PS_LOG_INFO, "break point PEAKS, skipping MOMENTS\n"); 186 psphotVisualShowMoments (sources); 187 return sources; 188 } 189 190 // XXX how else could we get the window size in? 191 if (!psphotSetMomentsWindow(recipe, readout->analysis, sources)) { 192 psError(PS_ERR_UNEXPECTED_NULL, false, "Failed to determine Moments Window!"); 193 return NULL; 194 } 195 196 // threaded measurement of the source magnitudes 197 int Nfail = 0; 198 int Nmoments = 0; 199 int Nfaint = 0; 200 201 // choose Cx, Cy (see psphotThreadTools.c for overview of the concepts) 202 int Cx = 1, Cy = 1; 203 psphotChooseCellSizes (&Cx, &Cy, readout, nThreads); 204 205 psArray *cellGroups = psphotAssignSources (Cx, Cy, sources); 206 207 for (int i = 0; i < cellGroups->n; i++) { 208 209 psArray *cells = cellGroups->data[i]; 210 211 for (int j = 0; j < cells->n; j++) { 212 213 // allocate a job -- if threads are not defined, this just runs the job 214 psThreadJob *job = psThreadJobAlloc ("PSPHOT_SOURCE_STATS"); 215 216 psArrayAdd(job->args, 1, cells->data[j]); // sources 217 psArrayAdd(job->args, 1, recipe); 218 PS_ARRAY_ADD_SCALAR(job->args, 0, PS_TYPE_S32); // this is used as a return value for Nmoments 219 PS_ARRAY_ADD_SCALAR(job->args, 0, PS_TYPE_S32); // this is used as a return value for Nfail 220 PS_ARRAY_ADD_SCALAR(job->args, 0, PS_TYPE_S32); // this is used as a return value for Nfaint 221 222 if (!psThreadJobAddPending(job)) { 223 psError(PS_ERR_UNKNOWN, false, "Unable to launch thread job PSPHOT_SOURCE_STATS"); 224 psFree (job); 225 return NULL; 226 } 227 psFree(job); 228 } 229 230 // wait for the threads to finish and manage results 231 if (!psThreadPoolWait (false)) { 232 psError(PS_ERR_UNKNOWN, false, "Failure in thread job PSPHOT_SOURCE_STATS"); 233 return NULL; 234 } 235 236 // we have only supplied one type of job, so we can assume the types here 237 psThreadJob *job = NULL; 238 while ((job = psThreadJobGetDone()) != NULL) { 239 if (job->args->n < 1) { 240 fprintf (stderr, "error with job\n"); 241 } else { 242 psScalar *scalar = NULL; 243 scalar = job->args->data[2]; 244 Nmoments += scalar->data.S32; 245 scalar = job->args->data[3]; 246 Nfail += scalar->data.S32; 247 scalar = job->args->data[4]; 248 Nfaint += scalar->data.S32; 249 } 250 psFree(job); 251 } 252 } 253 254 psFree (cellGroups); 255 256 psLogMsg ("psphot", PS_LOG_INFO, "%ld sources, %d moments, %d faint, %d failed: %f sec\n", sources->n, Nmoments, Nfaint, Nfail, psTimerMark ("psphot.stats")); 257 258 psphotVisualShowMoments (sources); 259 260 return (sources); 261 } 262 143 263 bool psphotSourceStats_Threaded (psThreadJob *job) { 144 264
Note:
See TracChangeset
for help on using the changeset viewer.
