Changeset 21166 for trunk/psphot/src/psphotSourceStats.c
- Timestamp:
- Jan 24, 2009, 10:54:29 AM (17 years ago)
- File:
-
- 1 edited
-
trunk/psphot/src/psphotSourceStats.c (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psphot/src/psphotSourceStats.c
r20453 r21166 1 1 # include "psphotInternal.h" 2 2 3 psArray *psphotSourceStats (pm Readout *readout, psMetadata *recipe, pmDetections *detections)4 { 5 bool status= false;3 psArray *psphotSourceStats (pmConfig *config, pmReadout *readout, pmDetections *detections) { 4 5 bool status = false; 6 6 psArray *sources = NULL; 7 float BIG_RADIUS;8 7 9 8 psTimerStart ("psphot.stats"); 10 9 11 // bit-masks to test for good/bad pixels12 psM askType maskVal = psMetadataLookupU8(&status, recipe, "MASK.PSPHOT");13 assert ( maskVal);14 15 // bit-mask to mark pixels not used in analysis16 psMaskType markVal = psMetadataLookupU8(&status, recipe, "MARK.PSPHOT");17 assert (markVal);18 19 // maskVal is used to test for rejected pixels, and must include markVal20 maskVal |= markVal;10 // select the appropriate recipe information 11 psMetadata *recipe = psMetadataLookupPtr (&status, config->recipes, PSPHOT_RECIPE); 12 assert (recipe); 13 14 // determine the number of allowed threads 15 int nThreads = psMetadataLookupS32(&status, config->arguments, "NTHREADS"); // Number of threads 16 if (!status) { 17 nThreads = 0; 18 } 19 // nThreads = 0; // XXX until testing is complete, do not thread this function 21 20 22 21 // determine properties (sky, moments) of initial sources 23 float INNER = psMetadataLookupF32 (&status, recipe, "SKY_INNER_RADIUS");24 if (!status) return NULL;25 22 float OUTER = psMetadataLookupF32 (&status, recipe, "SKY_OUTER_RADIUS"); 26 if (!status) return NULL;27 float RADIUS = psMetadataLookupF32 (&status, recipe, "PSF_MOMENTS_RADIUS");28 if (!status) return NULL;29 float MIN_SN = psMetadataLookupF32 (&status, recipe, "MOMENTS_SN_MIN");30 23 if (!status) return NULL; 31 24 char *breakPt = psMetadataLookupStr (&status, recipe, "BREAK_POINT"); … … 38 31 } 39 32 33 // generate the array of sources, define the associated pixel 40 34 sources = psArrayAllocEmpty (peaks->n); 41 35 36 for (int i = 0; i < peaks->n; i++) { 37 38 pmPeak *peak = peaks->data[i]; 39 if (peak->assigned) continue; 40 41 // create a new source 42 pmSource *source = pmSourceAlloc(); 43 44 // add the peak 45 source->peak = psMemIncrRefCounter(peak); 46 47 // allocate space for moments 48 source->moments = pmMomentsAlloc(); 49 50 // allocate image, weight, mask arrays for each peak (square of radius OUTER) 51 pmSourceDefinePixels (source, readout, source->peak->x, source->peak->y, OUTER); 52 53 peak->assigned = true; 54 psArrayAdd (sources, 100, source); 55 psFree (source); 56 } 57 58 if (!strcasecmp (breakPt, "PEAKS")) { 59 psLogMsg ("psphot", PS_LOG_INFO, "%ld sources : %f sec\n", sources->n, psTimerMark ("psphot.stats")); 60 psLogMsg ("psphot", PS_LOG_INFO, "break point PEAKS, skipping MOMENTS\n"); 61 psphotVisualShowMoments (sources); 62 return sources; 63 } 64 65 // threaded measurement of the source magnitudes 42 66 int Nfail = 0; 43 67 int Nmoments = 0; 44 for (int i = 0; i < peaks->n; i++) { 45 46 pmPeak *peak = peaks->data[i]; 47 if (peak->assigned) continue; 48 49 // create a new source, add peak 50 pmSource *source = pmSourceAlloc(); 51 source->peak = psMemIncrRefCounter(peak); 52 53 // allocate image, weight, mask arrays for each peak (square of radius OUTER) 54 pmSourceDefinePixels (source, readout, source->peak->x, source->peak->y, OUTER); 55 if (!strcasecmp (breakPt, "PEAKS")) { 56 peak->assigned = true; 57 psArrayAdd (sources, 100, source); 58 psFree (source); 59 continue; 60 } 68 69 // choose Cx, Cy (see psphotThreadTools.c for overview of the concepts) 70 int Cx = 1, Cy = 1; 71 psphotChooseCellSizes (&Cx, &Cy, readout, nThreads); 72 73 psArray *cellGroups = psphotAssignSources (Cx, Cy, sources); 74 75 for (int i = 0; i < cellGroups->n; i++) { 76 77 psArray *cells = cellGroups->data[i]; 78 79 for (int j = 0; j < cells->n; j++) { 80 81 // allocate a job -- if threads are not defined, this just runs the job 82 psThreadJob *job = psThreadJobAlloc ("PSPHOT_SOURCE_STATS"); 83 84 psArrayAdd(job->args, 1, cells->data[j]); // sources 85 psArrayAdd(job->args, 1, recipe); 86 PS_ARRAY_ADD_SCALAR(job->args, 0, PS_TYPE_S32); // this is used as a return value for Nmoments 87 PS_ARRAY_ADD_SCALAR(job->args, 0, PS_TYPE_S32); // this is used as a return value for Nfail 88 89 if (!psThreadJobAddPending(job)) { 90 psError(PS_ERR_UNKNOWN, false, "Unable to guess model."); 91 psFree (job); 92 return NULL; 93 } 94 psFree(job); 95 96 } 97 98 // wait for the threads to finish and manage results 99 if (!psThreadPoolWait (false)) { 100 psError(PS_ERR_UNKNOWN, false, "Unable to guess model."); 101 return NULL; 102 } 103 104 // we have only supplied one type of job, so we can assume the types here 105 psThreadJob *job = NULL; 106 while ((job = psThreadJobGetDone()) != NULL) { 107 if (job->args->n < 1) { 108 fprintf (stderr, "error with job\n"); 109 } else { 110 psScalar *scalar = NULL; 111 scalar = job->args->data[2]; 112 Nmoments += scalar->data.S32; 113 scalar = job->args->data[3]; 114 Nfail += scalar->data.S32; 115 } 116 psFree(job); 117 } 118 } 119 120 psFree (cellGroups); 121 122 psLogMsg ("psphot", PS_LOG_INFO, "%ld sources, %d moments, %d failed: %f sec\n", sources->n, Nmoments, Nfail, psTimerMark ("psphot.stats")); 123 124 psphotVisualShowMoments (sources); 125 126 return (sources); 127 } 128 129 bool psphotSourceStats_Threaded (psThreadJob *job) { 130 131 bool status = false; 132 float BIG_RADIUS; 133 psScalar *scalar = NULL; 134 135 psArray *sources = job->args->data[0]; 136 psMetadata *recipe = job->args->data[1]; 137 138 float INNER = psMetadataLookupF32 (&status, recipe, "SKY_INNER_RADIUS"); 139 if (!status) return false; 140 float MIN_SN = psMetadataLookupF32 (&status, recipe, "MOMENTS_SN_MIN"); 141 if (!status) return false; 142 float RADIUS = psMetadataLookupF32 (&status, recipe, "PSF_MOMENTS_RADIUS"); 143 if (!status) return false; 144 145 // bit-masks to test for good/bad pixels 146 psMaskType maskVal = psMetadataLookupU8(&status, recipe, "MASK.PSPHOT"); 147 assert (maskVal); 148 149 // bit-mask to mark pixels not used in analysis 150 psMaskType markVal = psMetadataLookupU8(&status, recipe, "MARK.PSPHOT"); 151 assert (markVal); 152 153 // maskVal is used to test for rejected pixels, and must include markVal 154 maskVal |= markVal; 155 156 // threaded measurement of the sources moments 157 int Nfail = 0; 158 int Nmoments = 0; 159 for (int i = 0; i < sources->n; i++) { 160 pmSource *source = sources->data[i]; 61 161 62 162 // skip faint sources for moments measurement 63 163 if (source->peak->SN < MIN_SN) { 64 peak->assigned = true;65 psArrayAdd (sources, 100, source);66 psFree (source);67 164 continue; 68 165 } … … 72 169 status = pmSourceLocalSky (source, PS_STAT_SAMPLE_MEDIAN, INNER, maskVal, markVal); 73 170 if (!status) { 74 psFree (source); 75 Nfail ++; 76 psErrorClear(); 77 continue; 171 psErrorClear(); // XXX re-consider the errors raised here 172 Nfail ++; 173 continue; 78 174 } 79 175 … … 82 178 status = pmSourceLocalSkyVariance (source, PS_STAT_SAMPLE_MEDIAN, INNER, maskVal, markVal); 83 179 if (!status) { 84 psFree (source); 85 Nfail ++; 86 psErrorClear(); 87 continue; 180 Nfail ++; 181 psErrorClear(); 182 continue; 88 183 } 89 184 … … 91 186 status = pmSourceMoments (source, RADIUS); 92 187 if (status) { 93 // add to the source array94 peak->assigned = true;95 psArrayAdd (sources, 100, source);96 psFree (source);97 188 Nmoments ++; 98 189 continue; … … 105 196 status = pmSourceMoments (source, BIG_RADIUS); 106 197 if (status) { 107 // add to the source array108 peak->assigned = true;109 psArrayAdd (sources, 100, source);110 psFree (source);111 198 Nmoments ++; 112 199 continue; 113 200 } 114 201 115 psFree (source);116 202 Nfail ++; 117 203 psErrorClear(); … … 119 205 } 120 206 121 psLogMsg ("psphot", PS_LOG_INFO, "%ld sources, %d moments, %d failed: %f sec\n", sources->n, Nmoments, Nfail, psTimerMark ("psphot.stats")); 122 123 psphotVisualShowMoments (sources); 124 125 return (sources); 207 // change the value of a scalar on the array (wrap this and put it in psArray.h) 208 scalar = job->args->data[2]; 209 scalar->data.S32 = Nmoments; 210 211 scalar = job->args->data[3]; 212 scalar->data.S32 = Nfail; 213 214 return true; 126 215 } 127 128 // XXX EAM : filter out bad peaks (eg, no valid pixels available for sky)
Note:
See TracChangeset
for help on using the changeset viewer.
