- Timestamp:
- Feb 19, 2011, 10:40:50 AM (15 years ago)
- Location:
- branches/eam_branches/ipp-20110213/psphot
- Files:
-
- 2 edited
-
. (modified) (1 prop)
-
src/psphotPetrosianStats.c (modified) (15 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/ipp-20110213/psphot
- Property svn:mergeinfo changed (with no actual effect on merging)
-
branches/eam_branches/ipp-20110213/psphot/src/psphotPetrosianStats.c
r28013 r30707 6 6 // generate the Petrosian radius and flux from the mean surface brightness (r_i) 7 7 8 float InterpolateValues (float X0, float Y0, float X1, float Y1, float X); 8 float InterpolateValues (float X0, float Y0, float X1, float Y1, float X); 9 float InterpolateValuesErrX (float X0, float Y0, float X1, float Y1, float X, float dX0, float dX1); 10 float InterpolateValuesErrY (float X0, float Y0, float X1, float Y1, float X, float dY0, float dY1); 9 11 10 12 bool psphotPetrosianStats (pmSource *source) { … … 25 27 psVector *binRad = profile->radialBins; 26 28 psVector *area = profile->area; 29 psVector *binFill = profile->binFill; 27 30 28 31 psVector *fluxSum = psVectorAllocEmpty(binSB->n, PS_TYPE_F32); … … 33 36 psVector *meanSB = psVectorAllocEmpty(binSB->n, PS_TYPE_F32); 34 37 psVector *areaSum = psVectorAllocEmpty(binSB->n, PS_TYPE_F32); 38 psVector *apixSum = psVectorAllocEmpty(binSB->n, PS_TYPE_F32); 35 39 36 40 float petRadius = NAN; 41 float petRadiusErr = NAN; 37 42 float petFlux = NAN; 43 float petFluxErr = NAN; 44 float petArea = NAN; 45 float petApix = NAN; 38 46 39 47 bool anyPetro = false; … … 41 49 bool above = true; 42 50 float Asum = 0.0; 51 float Psum = 0.0; 43 52 float Fsum = 0.0; 44 53 float dFsum2 = 0.0; … … 56 65 57 66 float Area = area->data.F32[i]; 58 Asum += Area; 67 Asum += Area; // Asum is the cumulative area interior to this bin 59 68 Fsum += binSB->data.F32[i] * Area; 60 69 dFsum2 += PS_SQR(binSBstdev->data.F32[i] * Area); 70 Psum += Area*binFill->data.F32[i]; // Psum is the cumulative number of pixels interior to this bin 61 71 62 72 float areaInner = 0.5 * Area; … … 87 97 88 98 psVectorAppend(areaSum, Asum); 99 psVectorAppend(apixSum, Psum); 89 100 psVectorAppend(fluxSum, Fsum); 90 101 psVectorAppend(fluxSumErr2, dFsum2); 91 102 psVectorAppend(refRadius, binRad->data.F32[i]); 92 103 93 psTrace ("psphot", 4, "%3d : %5.2f : %5.3f %5.3f : %5.3f %5.3f : %5.3f %5.3f : %5.3f %5.3f : %5.1f %5.1f \n",104 psTrace ("psphot", 4, "%3d : %5.2f : %5.3f %5.3f : %5.3f %5.3f : %5.3f %5.3f : %5.3f %5.3f : %5.1f %5.1f %5.1f\n", 94 105 i, refRadius->data.F32[nOut], 95 106 binSB->data.F32[i], binSBstdev->data.F32[i], 96 107 meanSB->data.F32[nOut], meanSBerr, 97 108 petRatio->data.F32[nOut], petRatioErr->data.F32[nOut], 98 fluxSum->data.F32[nOut], sqrt(fluxSumErr2->data.F32[nOut]), areaSum->data.F32[nOut], a reaInner);109 fluxSum->data.F32[nOut], sqrt(fluxSumErr2->data.F32[nOut]), areaSum->data.F32[nOut], apixSum->data.F32[nOut], areaInner); 99 110 100 111 // anytime we transition below the PETROSIAN_RATIO, calculate the radius and flux … … 104 115 if (i == 0) { 105 116 // assume Fmax @ R = 0.0 106 petRadius = InterpolateValues (1.0, 0.0, petRatio->data.F32[nOut], refRadius->data.F32[nOut], PETROSIAN_RATIO); 107 } else { 108 petRadius = InterpolateValues (petRatio->data.F32[nOut-1], refRadius->data.F32[nOut-1], petRatio->data.F32[nOut], refRadius->data.F32[nOut], PETROSIAN_RATIO); 117 petRadius = InterpolateValues (1.0, 0.0, petRatio->data.F32[nOut], refRadius->data.F32[nOut], PETROSIAN_RATIO); 118 petRadiusErr = InterpolateValuesErrX (1.0, 0.0, petRatio->data.F32[nOut], refRadius->data.F32[nOut], PETROSIAN_RATIO, 0.0, petRatioErr->data.F32[nOut]); 119 } else { 120 petRadius = InterpolateValues (petRatio->data.F32[nOut-1], refRadius->data.F32[nOut-1], petRatio->data.F32[nOut], refRadius->data.F32[nOut], PETROSIAN_RATIO); 121 petRadiusErr = InterpolateValuesErrX (petRatio->data.F32[nOut-1], refRadius->data.F32[nOut-1], petRatio->data.F32[nOut], refRadius->data.F32[nOut], PETROSIAN_RATIO, petRatioErr->data.F32[nOut-1], petRatioErr->data.F32[nOut]); 109 122 } 110 123 above = false; … … 128 141 } 129 142 143 // if we failed to reach the PETROSIAN_RATIO, use the lowest significant ratio instead (flag this!) 130 144 if (!anyPetro) { 131 145 // interpolate Rvec between i-1 and i to PETROSIAN_RATIO to get flux (Fvec) and radius (rvec) 132 146 if (lowestSignificantRadius == 0) { 133 147 // assume Fmax @ R = 0.0 134 petRadius = InterpolateValues (1.0, 0.0, petRatio->data.F32[lowestSignificantRadius], refRadius->data.F32[lowestSignificantRadius], PETROSIAN_RATIO); 148 petRadius = InterpolateValues (1.0, 0.0, petRatio->data.F32[lowestSignificantRadius], refRadius->data.F32[lowestSignificantRadius], PETROSIAN_RATIO); 149 petRadiusErr = InterpolateValuesErrX (1.0, 0.0, petRatio->data.F32[lowestSignificantRadius], refRadius->data.F32[lowestSignificantRadius], PETROSIAN_RATIO, 0.0, petRatioErr->data.F32[lowestSignificantRadius]); 150 135 151 } else { 136 petRadius = InterpolateValues (petRatio->data.F32[lowestSignificantRadius-1], refRadius->data.F32[lowestSignificantRadius-1], petRatio->data.F32[lowestSignificantRadius], refRadius->data.F32[lowestSignificantRadius], PETROSIAN_RATIO); 152 int n0 = lowestSignificantRadius-1; 153 int n1 = lowestSignificantRadius; 154 petRadius = InterpolateValues (petRatio->data.F32[n0], refRadius->data.F32[n0], petRatio->data.F32[n1], refRadius->data.F32[n1], PETROSIAN_RATIO); 155 petRadiusErr = InterpolateValuesErrX (petRatio->data.F32[n0], refRadius->data.F32[n0], petRatio->data.F32[n1], refRadius->data.F32[n1], PETROSIAN_RATIO, petRatioErr->data.F32[n0], petRatioErr->data.F32[n1]); 137 156 } 138 157 } … … 147 166 continue; 148 167 } else { 149 petFlux = InterpolateValues (refRadius->data.F32[i-1], fluxSum->data.F32[i-1], refRadius->data.F32[i], fluxSum->data.F32[i], apRadius); 168 petFlux = InterpolateValues (refRadius->data.F32[i-1], fluxSum->data.F32[i-1], refRadius->data.F32[i], fluxSum->data.F32[i], apRadius); 169 petFluxErr = InterpolateValuesErrY (refRadius->data.F32[i-1], fluxSum->data.F32[i-1], refRadius->data.F32[i], fluxSum->data.F32[i], apRadius, sqrt(fluxSumErr2->data.F32[i-1]), sqrt(fluxSumErr2->data.F32[i])); 170 petArea = InterpolateValues (refRadius->data.F32[i-1], areaSum->data.F32[i-1], refRadius->data.F32[i], areaSum->data.F32[i], apRadius); 171 petApix = InterpolateValues (refRadius->data.F32[i-1], apixSum->data.F32[i-1], refRadius->data.F32[i], apixSum->data.F32[i], apRadius); 150 172 break; 151 173 } … … 158 180 float R50 = NAN; 159 181 float R90 = NAN; 182 float R50err = NAN; 183 float R90err = NAN; 160 184 bool found50 = false; 161 185 bool found90 = false; … … 167 191 continue; 168 192 } else { 169 R50 = InterpolateValues (fluxSum->data.F32[i-1], refRadius->data.F32[i-1], fluxSum->data.F32[i], refRadius->data.F32[i], flux50); 193 R50 = InterpolateValues (fluxSum->data.F32[i-1], refRadius->data.F32[i-1], fluxSum->data.F32[i], refRadius->data.F32[i], flux50); 194 R50err = InterpolateValuesErrX (fluxSum->data.F32[i-1], refRadius->data.F32[i-1], fluxSum->data.F32[i], refRadius->data.F32[i], flux50, sqrt(fluxSumErr2->data.F32[i-1]), sqrt(fluxSumErr2->data.F32[i])); 170 195 found50 = true; 171 196 } … … 176 201 continue; 177 202 } else { 178 R90 = InterpolateValues (fluxSum->data.F32[i-1], refRadius->data.F32[i-1], fluxSum->data.F32[i], refRadius->data.F32[i], flux90); 203 R90 = InterpolateValues (fluxSum->data.F32[i-1], refRadius->data.F32[i-1], fluxSum->data.F32[i], refRadius->data.F32[i], flux90); 204 R90err = InterpolateValuesErrX (fluxSum->data.F32[i-1], refRadius->data.F32[i-1], fluxSum->data.F32[i], refRadius->data.F32[i], flux90, sqrt(fluxSumErr2->data.F32[i-1]), sqrt(fluxSumErr2->data.F32[i])); 179 205 found90 = true; 180 206 } … … 188 214 source->extpars->petrosianR50 = R50; 189 215 source->extpars->petrosianR90 = R90; 216 source->extpars->petrosianFill = petApix / petArea; 190 217 191 218 // XXX add the errors 192 source->extpars->petrosianRadiusErr = NAN;193 source->extpars->petrosianFluxErr = NAN;194 source->extpars->petrosianR50Err = NAN;195 source->extpars->petrosianR90Err = NAN;219 source->extpars->petrosianRadiusErr = petRadiusErr; 220 source->extpars->petrosianFluxErr = petFluxErr; 221 source->extpars->petrosianR50Err = R50err; 222 source->extpars->petrosianR90Err = R90err; 196 223 197 224 // fprintf (stderr, "source @ %f,%f\n", source->peak->xf, source->peak->yf); … … 205 232 psFree(meanSB); 206 233 psFree(areaSum); 234 psFree(apixSum); 207 235 208 236 return true; … … 210 238 211 239 float InterpolateValues (float X0, float Y0, float X1, float Y1, float X) { 212 float Y = Y0 + (Y1 - Y0) * (X - X0) / (X1 - X0); 240 float dydx = (Y1 - Y0) / (X1 - X0); 241 float Y = Y0 + dydx * (X - X0); 213 242 return Y; 214 243 } 215 244 245 float InterpolateValuesErrX (float X0, float Y0, float X1, float Y1, float X, float dX0, float dX1) { 246 247 float dydx = (Y1 - Y0) / (X1 - X0); 248 float dxdx = (X - X0) / (X1 - X0); 249 250 float dY = sqrt(PS_SQR(dX1*dydx*dxdx) + PS_SQR(dX0*dydx*(dxdx - 1.0))); 251 return dY; 252 } 253 254 float InterpolateValuesErrY (float X0, float Y0, float X1, float Y1, float X, float dY0, float dY1) { 255 256 float dxdx = (X - X0) / (X1 - X0); 257 258 float dY = sqrt(PS_SQR(dY1*dxdx) + PS_SQR(dY0*(1.0 - dxdx))); 259 return dY; 260 } 261
Note:
See TracChangeset
for help on using the changeset viewer.
