- Timestamp:
- Aug 3, 2011, 6:29:49 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/ipp-20110710/psphot/src/psphotExtendedSourceAnalysis.c
r31154 r32023 2 2 3 3 // measure the elliptical radial profile and use this to measure the petrosian parameters for the sources 4 // XXX this function needs to be threaded5 4 6 5 // for now, let's store the detections on the readout->analysis for each readout … … 59 58 } 60 59 61 // user-defined masks to test for good/bad pixels (build from recipe list if not yet set) 62 psImageMaskType maskVal = psMetadataLookupImageMask(&status, recipe, "MASK.PSPHOT"); // Mask value for bad pixels 63 assert (maskVal); 60 // determine the number of allowed threads 61 int nThreads = psMetadataLookupS32(&status, config->arguments, "NTHREADS"); // Number of threads 62 if (!status) { 63 nThreads = 0; 64 } 64 65 65 66 // get the sky noise from the background analysis; if this is missing, get the user-supplied value … … 70 71 } 71 72 73 // source analysis is done in S/N order (brightest first) 74 sources = psArraySort (sources, pmSourceSortByFlux); 75 76 // option to limit analysis to a specific region 77 char *region = psMetadataLookupStr (&status, recipe, "ANALYSIS_REGION"); 78 psRegion *AnalysisRegion = psRegionAlloc(0,0,0,0); 79 *AnalysisRegion = psRegionForImage (readout->image, psRegionFromString (region)); 80 if (psRegionIsNaN (*AnalysisRegion)) psAbort("analysis region mis-defined"); 81 82 // choose Cx, Cy (see psphotThreadTools.c for overview of the concepts) 83 int Cx = 1, Cy = 1; 84 psphotChooseCellSizes (&Cx, &Cy, readout, nThreads); 85 86 psArray *cellGroups = psphotAssignSources (Cx, Cy, sources); 87 88 for (int i = 0; i < cellGroups->n; i++) { 89 90 psArray *cells = cellGroups->data[i]; 91 92 for (int j = 0; j < cells->n; j++) { 93 94 // allocate a job -- if threads are not defined, this just runs the job 95 psThreadJob *job = psThreadJobAlloc ("PSPHOT_EXTENDED_ANALYSIS"); 96 97 psArrayAdd(job->args, 1, readout); 98 psArrayAdd(job->args, 1, cells->data[j]); // sources 99 psArrayAdd(job->args, 1, AnalysisRegion); 100 psArrayAdd(job->args, 1, recipe); 101 102 PS_ARRAY_ADD_SCALAR(job->args, skynoise, PS_TYPE_F32); 103 104 PS_ARRAY_ADD_SCALAR(job->args, 0, PS_TYPE_S32); // this is used as a return value for Next 105 PS_ARRAY_ADD_SCALAR(job->args, 0, PS_TYPE_S32); // this is used as a return value for Npetro 106 PS_ARRAY_ADD_SCALAR(job->args, 0, PS_TYPE_S32); // this is used as a return value for Nannuli 107 108 // set this to 0 to run without threading 109 # if (1) 110 if (!psThreadJobAddPending(job)) { 111 psError(PS_ERR_UNKNOWN, false, "Unable to guess model."); 112 psFree(AnalysisRegion); 113 return false; 114 } 115 # else 116 if (!psphotExtendedSourceAnalysis_Threaded(job)) { 117 psError(PS_ERR_UNKNOWN, false, "Unable to guess model."); 118 psFree(AnalysisRegion); 119 return false; 120 } 121 psScalar *scalar = NULL; 122 scalar = job->args->data[5]; 123 Next += scalar->data.S32; 124 scalar = job->args->data[6]; 125 Npetro += scalar->data.S32; 126 scalar = job->args->data[7]; 127 Nannuli += scalar->data.S32; 128 psFree(job); 129 # endif 130 } 131 132 // wait for the threads to finish and manage results 133 if (!psThreadPoolWait (false)) { 134 psError(PS_ERR_UNKNOWN, false, "Unable to guess model."); 135 psFree(AnalysisRegion); 136 return false; 137 } 138 139 // we have only supplied one type of job, so we can assume the types here 140 psThreadJob *job = NULL; 141 while ((job = psThreadJobGetDone()) != NULL) { 142 if (job->args->n < 1) { 143 fprintf (stderr, "error with job\n"); 144 } else { 145 psScalar *scalar = NULL; 146 scalar = job->args->data[5]; 147 Next += scalar->data.S32; 148 scalar = job->args->data[6]; 149 Npetro += scalar->data.S32; 150 scalar = job->args->data[7]; 151 Nannuli += scalar->data.S32; 152 } 153 psFree(job); 154 } 155 } 156 psFree (cellGroups); 157 psFree(AnalysisRegion); 158 159 psLogMsg ("psphot", PS_LOG_INFO, "extended source analysis: %f sec for %d objects\n", psTimerMark ("psphot.extended"), Next); 160 psLogMsg ("psphot", PS_LOG_INFO, " %d petrosian\n", Npetro); 161 psLogMsg ("psphot", PS_LOG_INFO, " %d annuli\n", Nannuli); 162 163 psphotVisualShowResidualImage (readout, false); 164 165 bool doPetrosian = psMetadataLookupBool (&status, recipe, "EXTENDED_SOURCE_PETROSIAN"); 166 if (doPetrosian) { 167 psphotVisualShowPetrosians (sources); 168 } 169 170 return true; 171 } 172 173 bool psphotExtendedSourceAnalysis_Threaded (psThreadJob *job) { 174 175 bool status; 176 177 int Next = 0; 178 int Npetro = 0; 179 int Nannuli = 0; 180 181 // arguments: readout, sources, models, region, psfSize, maskVal, markVal 182 pmReadout *readout = job->args->data[0]; 183 psArray *sources = job->args->data[1]; 184 psRegion *region = job->args->data[2]; 185 psMetadata *recipe = job->args->data[3]; 186 187 float skynoise = PS_SCALAR_VALUE(job->args->data[4],F32); 188 72 189 // S/N limit to perform full non-linear fits 73 190 float SN_LIM = psMetadataLookupF32 (&status, recipe, "EXTENDED_SOURCE_SN_LIM"); … … 78 195 bool doPetroStars = psMetadataLookupBool (&status, recipe, "PETROSIAN_FOR_STARS"); 79 196 80 // source analysis is done in S/N order (brightest first) 81 sources = psArraySort (sources, pmSourceSortByFlux); 82 83 // option to limit analysis to a specific region 84 char *region = psMetadataLookupStr (&status, recipe, "ANALYSIS_REGION"); 85 psRegion AnalysisRegion = psRegionForImage (readout->image, psRegionFromString (region)); 86 if (psRegionIsNaN (AnalysisRegion)) psAbort("analysis region mis-defined"); 197 // user-defined masks to test for good/bad pixels (build from recipe list if not yet set) 198 psImageMaskType maskVal = psMetadataLookupImageMask(&status, recipe, "MASK.PSPHOT"); // Mask value for bad pixels 199 assert (maskVal); 87 200 88 201 // choose the sources of interest … … 108 221 109 222 // limit selection by analysis region 110 if (source->peak->x < AnalysisRegion.x0) continue;111 if (source->peak->y < AnalysisRegion.y0) continue;112 if (source->peak->x > AnalysisRegion.x1) continue;113 if (source->peak->y > AnalysisRegion.y1) continue;223 if (source->peak->x < region->x0) continue; 224 if (source->peak->y < region->y0) continue; 225 if (source->peak->x > region->x1) continue; 226 if (source->peak->y > region->y1) continue; 114 227 115 228 // replace object in image … … 159 272 } 160 273 161 ps LogMsg ("psphot", PS_LOG_INFO, "extended source analysis: %f sec for %d objects\n", psTimerMark ("psphot.extended"), Next);162 psLogMsg ("psphot", PS_LOG_INFO, " %d petrosian\n", Npetro); 163 psLogMsg ("psphot", PS_LOG_INFO, " %d annuli\n", Nannuli);164 165 psphotVisualShowResidualImage (readout, false);166 167 if (doPetrosian) {168 psphotVisualShowPetrosians (sources);169 } 170 171 // fprintf (stderr, "xsrc : tried %ld objects\n", sources->n);274 psScalar *scalar = NULL; 275 276 // change the value of a scalar on the array (wrap this and put it in psArray.h) 277 scalar = job->args->data[5]; 278 scalar->data.S32 = Next; 279 280 scalar = job->args->data[6]; 281 scalar->data.S32 = Npetro; 282 283 scalar = job->args->data[7]; 284 scalar->data.S32 = Nannuli; 172 285 173 286 return true;
Note:
See TracChangeset
for help on using the changeset viewer.
