Changeset 32612
- Timestamp:
- Nov 3, 2011, 7:41:16 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/ipp-20110906/psphot/src/psphotRadialProfileWings.c
r32606 r32612 4 4 // reach sky + X sigma 5 5 6 bool psphotRadialProfileWingsSource (pmSource *source, pmReadout *readout, float minRadius, float maxRadius,psImageMaskType maskVal);6 bool psphotRadialProfileWingsSource (pmSource *source, pmReadout *readout, psImageMaskType maskVal); 7 7 bool psphotRadialProfileFluxAtRadius (psVector *flux, psVector *fluxVar, pmSource *source, pmReadout *readout, float Radius, float dRadius, psImageMaskType maskVal); 8 8 … … 51 51 } 52 52 53 // these are set before we fork off to threads and used by all threads as constant values 54 static float MAX_RADIUS = NAN; 55 static float MIN_RADIUS = NAN; 56 static float SKY_STDEV = NAN; 57 // static FILE *file = NULL; 58 53 59 bool psphotRadialProfileWingsReadout(pmConfig *config, psMetadata *recipe, const pmFPAview *view, pmReadout *readout, psArray *sources) { 54 60 … … 69 75 70 76 // XXX is this a good recipe value to use for MAX RADIUS?? 71 floatMAX_RADIUS = psMetadataLookupF32 (&status, recipe, "EXT_FIT_MAX_RADIUS");77 MAX_RADIUS = psMetadataLookupF32 (&status, recipe, "EXT_FIT_MAX_RADIUS"); 72 78 if (!status) { 73 79 MAX_RADIUS = 50.0; 74 80 } 75 81 76 floatMIN_RADIUS = 0.25*psMetadataLookupF32 (&status, readout->analysis, "PSF_MOMENTS_RADIUS");82 MIN_RADIUS = 0.25*psMetadataLookupF32 (&status, readout->analysis, "PSF_MOMENTS_RADIUS"); 77 83 if (!status) { 78 84 MIN_RADIUS = 0.25*psMetadataLookupF32 (&status, recipe, "PSF_MOMENTS_RADIUS"); 85 } 86 87 // SKY_STDEV is the sigma of the sky model (ie, smoothed on large scales) 88 SKY_STDEV = psMetadataLookupF32 (&status, readout->analysis, "MSKY_SIG"); 89 if (!status) { 90 SKY_STDEV = 1.0; // a crude default value (why would this not exist?) 79 91 } 80 92 … … 97 109 } 98 110 111 // file = fopen ("radii.dat", "w"); 112 99 113 // threaded measurement of the source magnitudes 100 114 // choose Cx, Cy (see psphotThreadTools.c for overview of the concepts) … … 116 130 psArrayAdd(job->args, 1, cells->data[j]); // sources 117 131 PS_ARRAY_ADD_SCALAR(job->args, maskVal, PS_TYPE_IMAGE_MASK); 118 PS_ARRAY_ADD_SCALAR(job->args, MIN_RADIUS, PS_TYPE_F32);119 PS_ARRAY_ADD_SCALAR(job->args, MAX_RADIUS, PS_TYPE_F32);120 132 121 133 // set this to 0 to run without threading … … 151 163 psFree (cellGroups); 152 164 165 // fclose (file); 166 153 167 psLogMsg ("psphot.wings", PS_LOG_WARN, "measure radial profile wings : %f sec for %ld objects\n", psTimerMark ("psphot.wings"), sources->n); 154 168 return true; … … 160 174 psArray *sources = job->args->data[1]; 161 175 psImageMaskType maskVal = PS_SCALAR_VALUE(job->args->data[2],PS_TYPE_IMAGE_MASK_DATA); 162 float MIN_RADIUS = PS_SCALAR_VALUE(job->args->data[3],F32);163 float MAX_RADIUS = PS_SCALAR_VALUE(job->args->data[4],F32);164 176 165 177 for (int i = 0; i < sources->n; i++) { … … 184 196 185 197 // this function populates moments->Mrf,KronFlux,KronFluxErr 186 psphotRadialProfileWingsSource (source, readout, MIN_RADIUS, MAX_RADIUS,maskVal);198 psphotRadialProfileWingsSource (source, readout, maskVal); 187 199 188 200 // if we subtracted it above, re-subtract the object, leave local sky … … 194 206 } 195 207 208 # define TEST_X 3158 209 # define TEST_Y 3096 210 196 211 // XXX use integer radius values? the rings assume integer values, right? or do they? 197 bool psphotRadialProfileWingsSource (pmSource *source, pmReadout *readout, float minRadius, float maxRadius,psImageMaskType maskVal) {212 bool psphotRadialProfileWingsSource (pmSource *source, pmReadout *readout, psImageMaskType maskVal) { 198 213 199 214 PS_ASSERT_PTR_NON_NULL(source, false); 200 215 PS_ASSERT_PTR_NON_NULL(source->peak, false); 201 216 PS_ASSERT_PTR_NON_NULL(source->pixels, false); 202 PS_ASSERT_FLOAT_LARGER_THAN(minRadius, 0.0, false);203 PS_ASSERT_FLOAT_LARGER_THAN(maxRadius, 0.0, false);204 217 205 218 // psImageMaskType **vMsk = (source->maskObj == NULL) ? NULL : source->maskObj->data.PS_TYPE_IMAGE_MASK_DATA; 206 219 207 // radii will be minRadius to maxRadiusin NN log steps:220 // radii will be MIN_RADIUS to MAX_RADIUS in NN log steps: 208 221 float NSTEP = 10.0; 209 222 float MIN_DR = 2; 210 223 float NSIGMA = 1.0; 211 float SKY = 0.0;212 float alpha = pow (( maxRadius / minRadius), 1.0/NSTEP) - 1.0;213 float dRmax = maxRadius* alpha / (1.0 + alpha); // approximate size of last annulus, to get a rough size for vector allocation224 float THRESHOLD = 2.0*SKY_STDEV; 225 float alpha = pow ((MAX_RADIUS / MIN_RADIUS), 1.0/NSTEP) - 1.0; 226 float dRmax = MAX_RADIUS * alpha / (1.0 + alpha); // approximate size of last annulus, to get a rough size for vector allocation 214 227 215 228 int iter = 0; 216 229 217 psVector *flux = psVectorAllocEmpty(7* maxRadius*dRmax, PS_TYPE_F32);218 psVector *fluxVar = psVectorAllocEmpty(7* maxRadius*dRmax, PS_TYPE_F32);230 psVector *flux = psVectorAllocEmpty(7*MAX_RADIUS*dRmax, PS_TYPE_F32); 231 psVector *fluxVar = psVectorAllocEmpty(7*MAX_RADIUS*dRmax, PS_TYPE_F32); 219 232 220 233 // should I just use sample median here? … … 222 235 psStats *varStats = psStatsAlloc(PS_STAT_SAMPLE_MEAN); 223 236 224 for (float radius = minRadius; radius < maxRadius; iter ++) { 237 float lastFlux = NAN; 238 float lastRadius = NAN; 239 float lastSlope = NAN; 240 bool limit = false; 241 float limitRadius = NAN; 242 float limitFlux = NAN; 243 float limitSlope = NAN; 244 245 // note: radius is the inner radius of the annulus; outer radius = inner radius + dR 246 for (float radius = MIN_RADIUS; !limit && (radius < MAX_RADIUS); iter ++) { 225 247 226 248 float dR = (int)(radius * alpha); 227 249 if (dR < MIN_DR) dR = MIN_DR; 250 float outerRadius = radius + dR; 251 float meanRadius = (2.0/3.0) * (outerRadius*outerRadius*outerRadius - radius*radius*radius) / (PS_SQR(outerRadius) - PS_SQR(radius)); 228 252 229 253 // extract a vector of the pixel values (signal, variance) at this radius + dR … … 243 267 // \mean(variance) * Npts and cancelling the Npts term inside and out of the sqrt() 244 268 245 fprintf (stderr, "%f %f : %f : %f %f\n", source->peak->xf, source->peak->yf, radius, meanFlux, meanFluxError); 246 247 if (meanFlux - NSIGMA * meanFluxError < SKY) { 248 fprintf (stderr, "hit the sky at %f\n", radius); 249 } 250 269 float slope = NAN; 270 if (isfinite(lastFlux)) { 271 slope = (meanFlux - lastFlux) / (meanRadius - lastRadius); 272 } 273 274 // fprintf (stderr, "%f %f : %f : %f %f : %f\n", source->peak->xf, source->peak->yf, radius, meanFlux, meanFluxError, slope); 275 276 if (!limit) { 277 limit |= (meanFlux - NSIGMA * meanFluxError < THRESHOLD); // dropped to sky level 278 limit |= isfinite(slope) && (fabs(slope) < 3.0); // SB no longer changing. 279 limitRadius = meanRadius; 280 limitFlux = meanFlux; 281 limitSlope = slope; 282 } 283 251 284 // completion criteria: 252 285 // 1) flux - NSIGMA * dflux <= sky … … 254 287 // 3) flux flat? 255 288 289 lastFlux = meanFlux; 290 lastRadius = meanRadius; 291 lastSlope = slope; 292 256 293 // reset the flux & fluxVar vector length to zero for re-use above: 257 294 flux->n = 0; … … 260 297 } 261 298 299 if (!limit) { 300 limitRadius = lastRadius; 301 limitFlux = lastFlux; 302 limitSlope = lastSlope; 303 } 304 // fprintf (file, "%f %f : %f %f : %f\n", source->peak->xf, source->peak->yf, limitRadius, limitFlux, limitSlope); 305 262 306 psFree (flux); 263 307 psFree (fluxVar); 264 308 psFree (fluxStats); 265 309 psFree (varStats); 310 311 source->skyRadius = limitRadius; 312 source->skyFlux = limitFlux; 313 source->skySlope = limitSlope; 266 314 267 315 // save the max radius (and anything else?)
Note:
See TracChangeset
for help on using the changeset viewer.
