- 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/psphotRadialApertures.c
r31452 r32023 63 63 } 64 64 65 // determine the number of allowed threads 66 int nThreads = psMetadataLookupS32(&status, config->arguments, "NTHREADS"); // Number of threads 67 if (!status) { 68 nThreads = 0; 69 } 70 71 // source analysis is done in S/N order (brightest first) 72 // XXX are we getting the objects out of order? does it matter? 73 sources = psArraySort (sources, pmSourceSortByFlux); 74 75 // option to limit analysis to a specific region 76 char *region = psMetadataLookupStr (&status, recipe, "ANALYSIS_REGION"); 77 psRegion *AnalysisRegion = psRegionAlloc(0,0,0,0); 78 *AnalysisRegion = psRegionForImage (readout->image, psRegionFromString (region)); 79 if (psRegionIsNaN (*AnalysisRegion)) psAbort("analysis region mis-defined"); 80 81 // choose Cx, Cy (see psphotThreadTools.c for overview of the concepts) 82 int Cx = 1, Cy = 1; 83 psphotChooseCellSizes (&Cx, &Cy, readout, nThreads); 84 85 psArray *cellGroups = psphotAssignSources (Cx, Cy, sources); 86 87 for (int i = 0; i < cellGroups->n; i++) { 88 89 psArray *cells = cellGroups->data[i]; 90 91 for (int j = 0; j < cells->n; j++) { 92 93 // allocate a job -- if threads are not defined, this just runs the job 94 psThreadJob *job = psThreadJobAlloc ("PSPHOT_RADIAL_APERTURES"); 95 96 psArrayAdd(job->args, 1, readout); 97 psArrayAdd(job->args, 1, cells->data[j]); // sources 98 psArrayAdd(job->args, 1, AnalysisRegion); 99 psArrayAdd(job->args, 1, recipe); 100 101 PS_ARRAY_ADD_SCALAR(job->args, 0, PS_TYPE_S32); // this is used as a return value for Nradial 102 103 // set this to 0 to run without threading 104 # if (1) 105 if (!psThreadJobAddPending(job)) { 106 psError(PS_ERR_UNKNOWN, false, "Unable to guess model."); 107 psFree(AnalysisRegion); 108 return false; 109 } 110 # else 111 if (!psphotRadialApertures_Threaded(job)) { 112 psError(PS_ERR_UNKNOWN, false, "Unable to guess model."); 113 psFree(AnalysisRegion); 114 return false; 115 } 116 psScalar *scalar = NULL; 117 scalar = job->args->data[4]; 118 Nradial += scalar->data.S32; 119 psFree(job); 120 # endif 121 } 122 123 // wait for the threads to finish and manage results 124 if (!psThreadPoolWait (false)) { 125 psError(PS_ERR_UNKNOWN, false, "Unable to guess model."); 126 psFree(AnalysisRegion); 127 return false; 128 } 129 130 // we have only supplied one type of job, so we can assume the types here 131 psThreadJob *job = NULL; 132 while ((job = psThreadJobGetDone()) != NULL) { 133 if (job->args->n < 1) { 134 fprintf (stderr, "error with job\n"); 135 } else { 136 psScalar *scalar = NULL; 137 scalar = job->args->data[4]; 138 Nradial += scalar->data.S32; 139 } 140 psFree(job); 141 } 142 } 143 psFree (cellGroups); 144 psFree(AnalysisRegion); 145 146 psLogMsg ("psphot", PS_LOG_INFO, "radial source apertures: %f sec for %d objects\n", psTimerMark ("psphot.radial"), Nradial); 147 return true; 148 } 149 150 bool psphotRadialApertures_Threaded (psThreadJob *job) { 151 152 bool status; 153 int Nradial = 0; 154 155 // arguments: readout, sources, models, region, psfSize, maskVal, markVal 156 pmReadout *readout = job->args->data[0]; 157 psArray *sources = job->args->data[1]; 158 psRegion *region = job->args->data[2]; 159 psMetadata *recipe = job->args->data[3]; 160 65 161 // radMax stores the upper bounds of the annuli 66 162 // XXX keep the same name here as for the petrosian / elliptical apertures? … … 68 164 psAssert (radMax, "annular bins (RADIAL.ANNULAR.BINS.UPPER) are not defined in the recipe"); 69 165 psAssert (radMax->n, "no valid annular bins (RADIAL.ANNULAR.BINS.UPPER) are define"); 70 float outerRadius = radMax->data.F32[radMax->n - 1];71 166 72 167 // user-defined masks to test for good/bad pixels (build from recipe list if not yet set) … … 77 172 float SN_LIM = psMetadataLookupF32 (&status, recipe, "RADIAL_APERTURES_SN_LIM"); 78 173 79 // source analysis is done in S/N order (brightest first) 80 // XXX are we getting the objects out of order? does it matter? 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"); 174 float outerRadius = radMax->data.F32[radMax->n - 1]; 87 175 88 176 // choose the sources of interest … … 104 192 105 193 // limit selection by analysis region 106 if (source->peak->x < AnalysisRegion.x0) continue;107 if (source->peak->y < AnalysisRegion.y0) continue;108 if (source->peak->x > AnalysisRegion.x1) continue;109 if (source->peak->y > AnalysisRegion.y1) continue;194 if (source->peak->x < region->x0) continue; 195 if (source->peak->y < region->y0) continue; 196 if (source->peak->x > region->x1) continue; 197 if (source->peak->y > region->y1) continue; 110 198 111 199 // allocate pmSourceExtendedParameters, if not already defined … … 145 233 pmSourceSub (source, PM_MODEL_OP_FULL, maskVal); 146 234 } 147 148 psLogMsg ("psphot", PS_LOG_INFO, "radial source apertures: %f sec for %d objects\n", psTimerMark ("psphot.radial"), Nradial); 235 psScalar *scalar = job->args->data[4]; 236 scalar->data.S32 = Nradial; 237 149 238 return true; 150 239 }
Note:
See TracChangeset
for help on using the changeset viewer.
