Changeset 31154 for trunk/psphot/src/psphotRadialApertures.c
- Timestamp:
- Apr 4, 2011, 1:12:39 PM (15 years ago)
- Location:
- trunk/psphot
- Files:
-
- 2 edited
-
. (modified) (2 props)
-
src/psphotRadialApertures.c (modified) (12 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psphot
- Property svn:ignore
-
old new 19 19 psphot-config 20 20 Doxyfile 21 a.out.dSYM
-
- Property svn:mergeinfo changed
- Property svn:ignore
-
trunk/psphot/src/psphotRadialApertures.c
r30624 r31154 37 37 int Nradial = 0; 38 38 39 // perform full non-linear fits / extended source analysis? 40 if (!psMetadataLookupBool (&status, recipe, "RADIAL_APERTURES")) { 41 psLogMsg ("psphot", PS_LOG_INFO, "skipping radial apertures\n"); 42 return true; 43 } 44 39 45 psTimerStart ("psphot.radial"); 40 46 … … 62 68 psAssert (radMax, "annular bins (RADIAL.ANNULAR.BINS.UPPER) are not defined in the recipe"); 63 69 psAssert (radMax->n, "no valid annular bins (RADIAL.ANNULAR.BINS.UPPER) are define"); 70 float outerRadius = radMax->data.F32[radMax->n - 1]; 64 71 65 72 // user-defined masks to test for good/bad pixels (build from recipe list if not yet set) … … 67 74 assert (maskVal); 68 75 69 // XXX temporary user-supplied systematic sky noise measurement (derive from background model)70 float skynoise = psMetadataLookupF32 (&status, recipe, "SKY.NOISE");71 72 76 // S/N limit to perform full non-linear fits 73 77 float SN_LIM = psMetadataLookupF32 (&status, recipe, "RADIAL_APERTURES_SN_LIM"); … … 75 79 // source analysis is done in S/N order (brightest first) 76 80 // XXX are we getting the objects out of order? does it matter? 77 sources = psArraySort (sources, pmSourceSortBy SN);81 sources = psArraySort (sources, pmSourceSortByFlux); 78 82 79 83 // option to limit analysis to a specific region … … 95 99 // limit selection to some SN limit 96 100 assert (source->peak); // how can a source not have a peak? 97 if (s ource->peak->SN< SN_LIM) continue;101 if (sqrt(source->peak->detValue) < SN_LIM) continue; 98 102 99 103 // limit selection by analysis region … … 112 116 pmSourceAdd (source, PM_MODEL_OP_FULL, maskVal); 113 117 } 118 119 // we need to change the view for the radial aperture analysis, but we want to recover exactly 120 // the original view; the following elements get destroyed by pmSourceRedefinePixels so save them: 121 psImage *oldMaskObj = psMemIncrRefCounter(source->maskObj); 122 psImage *oldModelFlux = psMemIncrRefCounter(source->modelFlux); 123 psImage *oldPSFimage = psMemIncrRefCounter(source->psfImage); 124 psRegion oldRegion = source->region; 125 114 126 Nradial ++; 115 127 116 128 // force source image to be a bit larger... 117 float radius = source->peak->xf - source->pixels->col0; 118 radius = PS_MAX (radius, source->peak->yf - source->pixels->row0); 119 radius = PS_MAX (radius, source->pixels->numRows - source->peak->yf + source->pixels->row0); 120 radius = PS_MAX (radius, source->pixels->numCols - source->peak->xf + source->pixels->col0); 121 pmSourceRedefinePixels (source, readout, source->peak->xf, source->peak->yf, 1.5*radius); 122 123 if (!psphotRadialApertureSource (source, recipe, skynoise, maskVal, radMax, 0)) { 129 pmSourceRedefinePixels (source, readout, source->peak->xf, source->peak->yf, outerRadius + 2); 130 131 if (!psphotRadialApertureSource (source, recipe, maskVal, radMax, 0)) { 124 132 psTrace ("psphot", 5, "failed to extract radial profile for source at %7.1f, %7.1f", source->moments->Mx, source->moments->My); 125 133 } else { … … 127 135 } 128 136 137 pmSourceRedefinePixelsByRegion (source, readout, oldRegion); 138 psFree(source->maskObj); source->maskObj = oldMaskObj; 139 psFree(source->modelFlux); source->modelFlux = oldModelFlux; 140 psFree(source->psfImage); source->psfImage = oldPSFimage; 141 129 142 // re-subtract the object, leave local sky 130 143 pmSourceSub (source, PM_MODEL_OP_FULL, maskVal); … … 135 148 } 136 149 137 bool psphotRadialApertureSource (pmSource *source, psMetadata *recipe, float skynoise,psImageMaskType maskVal, const psVector *aperRadii, int entry) {150 bool psphotRadialApertureSource (pmSource *source, psMetadata *recipe, psImageMaskType maskVal, const psVector *aperRadii, int entry) { 138 151 139 152 // if we are a child source, save the results to the parent source radial aperture array … … 163 176 } 164 177 165 // center of the apertures 166 float xCM = source->moments->Mx - 0.5 - source->pixels->col0; // coord of peak in subimage 167 float yCM = source->moments->My - 0.5 - source->pixels->row0; // coord of peak in subimage 178 float xCM = NAN, yCM = NAN; 179 if (pmSourcePositionUseMoments(source)) { 180 xCM = source->moments->Mx - 0.5 - source->pixels->col0; // coord of peak in subimage 181 yCM = source->moments->My - 0.5 - source->pixels->row0; // coord of peak in subimage 182 } else { 183 xCM = source->peak->xf - 0.5 - source->pixels->col0; // coord of peak in subimage 184 yCM = source->peak->yf - 0.5 - source->pixels->row0; // coord of peak in subimage 185 } 168 186 169 187 // one pass through the pixels to select the valid pixels and calculate R^2 … … 203 221 psVector *flux = psVectorAlloc(aperRadii->n, PS_TYPE_F32); // surface brightness of radial bin 204 222 psVector *fluxErr = psVectorAlloc(aperRadii->n, PS_TYPE_F32); // surface brightness of radial bin 223 psVector *fluxStd = psVectorAlloc(aperRadii->n, PS_TYPE_F32); // surface brightness of radial bin 205 224 psVector *fill = psVectorAlloc(aperRadii->n, PS_TYPE_F32); // surface brightness of radial bin 206 225 207 226 psVectorInit (flux, 0.0); 227 psVectorInit (fluxStd, 0.0); 208 228 psVectorInit (fluxErr, 0.0); 209 229 psVectorInit (fill, 0.0); … … 212 232 for (int i = 0; i < pixRadius2->n; i++, rPix2++) { 213 233 234 int j = 0; 214 235 float *aRad2 = aperRadii2->data.F32; 215 for (int j = 0; (*rPix2 < *aRad2) && (j < aperRadii2->n); j++, aRad2++) { 236 for (; (*aRad2 < *rPix2) && (j < aperRadii2->n); j++, aRad2++); 237 for (; j < aperRadii2->n; j++, aRad2++) { 216 238 flux->data.F32[j] += pixFlux->data.F32[i]; 239 fluxStd->data.F32[j] += PS_SQR(pixFlux->data.F32[i]); 217 240 fluxErr->data.F32[j] += pixVar->data.F32[i]; 218 241 fill->data.F32[j] += 1.0; 219 242 } 220 243 } 244 245 /* for each radial bin, R(i), we measure: 246 1) the flux within that aperture: F(i) = \sum_{r_j<R_i}(F_j) 247 2) the fractional fill factor (count of valid pixels / effective area of the aperture 248 3) the error on the flux within that aperture 249 */ 221 250 222 251 for (int i = 0; i < flux->n; i++) { 223 252 // calculate the total flux for bin 'nOut' 224 253 float Area = M_PI*aperRadii2->data.F32[i]; 225 fluxErr->data.F32[i] = sqrt(fluxErr->data.F32[i]); 226 fill->data.F32[i] /= Area; 227 psTrace ("psphot", 5, "radial bins: %3d %5.1f : %8.1f +/- %7.2f : %4.2f %6.1f\n", 228 i, aperRadii->data.F32[i], flux->data.F32[i], fluxErr->data.F32[i], fill->data.F32[i], Area); 254 255 int nPix = fill->data.F32[i]; 256 float SBmean = flux->data.F32[i] / nPix; 257 float SBstdv = sqrt((fluxStd->data.F32[i] / nPix) - PS_SQR(SBmean)); 258 259 // flux->data.F32[i] = SBmean * Area; 260 fluxStd->data.F32[i] = SBstdv * Area; 261 fluxErr->data.F32[i] = sqrt(fluxErr->data.F32[i]) * Area / nPix; 262 263 // fill->data.F32[i] /= Area; 264 psTrace ("psphot", 5, "radial bins: %3d %5.1f : %8.1f +/- %7.2f : %8.1f +/- %8.1f : %4.2f %6.1f\n", 265 i, aperRadii->data.F32[i], flux->data.F32[i], fluxErr->data.F32[i], SBmean, SBstdv, fill->data.F32[i], Area); 229 266 } 230 267 231 268 radialAper->flux = flux; 269 radialAper->fluxStdev = fluxStd; 232 270 radialAper->fluxErr = fluxErr; 233 271 radialAper->fill = fill; … … 245 283 static int nPix = 0; 246 284 247 bool psphotRadialApertureSource_With_Sort (pmSource *source, psMetadata *recipe, float skynoise,psImageMaskType maskVal, const psVector *radMax, int entry) {285 bool psphotRadialApertureSource_With_Sort (pmSource *source, psMetadata *recipe, psImageMaskType maskVal, const psVector *radMax, int entry) { 248 286 249 287 psAssert(source->radialAper->data[entry] == NULL, "why is this already defined?");
Note:
See TracChangeset
for help on using the changeset viewer.
