Changeset 5958 for branches/eam_rel9_p0/psModules/src/objects/pmPSFtry.c
- Timestamp:
- Jan 9, 2006, 6:46:03 PM (21 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_rel9_p0/psModules/src/objects/pmPSFtry.c
r5765 r5958 5 5 * @author EAM, IfA 6 6 * 7 * @version $Revision: 1.3 $ $Name: not supported by cvs2svn $8 * @date $Date: 200 5-12-12 21:14:38$7 * @version $Revision: 1.3.4.1 $ $Name: not supported by cvs2svn $ 8 * @date $Date: 2006-01-10 04:46:03 $ 9 9 * 10 10 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 119 119 psTrace ("psphot.psftry", 3, "keeping %d of %d PSF candidates (FLT)\n", Nflt, sources->n); 120 120 121 // make this optional?122 // DumpModelFits (psfTry->modelFLT, "modelsFLT.dat");123 124 121 // stage 2: construct a psf (pmPSF) from this collection of model fits 125 122 pmPSFFromModels (psfTry->psf, psfTry->modelFLT, psfTry->mask); … … 169 166 170 167 } 168 psfTry->psf->nPSFstars = Npsf; 169 171 170 psLogMsg ("psphot.psftry", 4, "fit psf: %f sec for %d sources\n", psTimerMark ("fit"), sources->n); 172 171 psTrace ("psphot.psftry", 3, "keeping %d of %d PSF candidates (PSF)\n", Npsf, sources->n); … … 177 176 // XXX this function wants aperture radius for pmSourcePhotometry 178 177 pmPSFtryMetric (psfTry, RADIUS); 179 psLogMsg ("psphot.pspsf", 3, "try model %s, ap-fit: %f +/- %f, sky bias: %f\n", 180 modelName, 181 psfTry->psf->ApResid, 182 psfTry->psf->dApResid, 183 psfTry->psf->skyBias); 184 178 psLogMsg ("psphot.pspsf", 3, "try model %s, ap-fit: %f +/- %f : sky bias: %f\n", 179 modelName, psfTry->psf->ApResid, psfTry->psf->dApResid, psfTry->psf->skyBias); 185 180 return (psfTry); 186 181 } 187 182 188 189 183 bool pmPSFtryMetric (pmPSFtry *psfTry, float RADIUS) 190 184 { 191 192 float dBin;193 int nKeep, nSkip;194 195 185 // the measured (aperture - fit) magnitudes (dA == psfTry->metric) 196 186 // depend on both the true ap-fit (dAo) and the bias in the sky measurement: … … 210 200 } 211 201 212 // find min and max of (1/flux): 213 psStats *stats = psStatsAlloc (PS_STAT_MIN | PS_STAT_MAX); 214 psVectorStats (stats, rflux, NULL, psfTry->mask, PSFTRY_MASK_ALL); 215 216 // build binned versions of rflux, metric 217 dBin = (stats->max - stats->min) / 10.0; 218 psVector *rfBin = psVectorCreate(NULL, stats->min, stats->max, dBin, PS_TYPE_F64); 219 psVector *daBin = psVectorAlloc (rfBin->n, PS_TYPE_F64); 220 psVector *maskB = psVectorAlloc (rfBin->n, PS_TYPE_U8); 221 psFree (stats); 222 223 psTrace ("psphot.metricmodel", 3, "rflux max: %g, min: %g, delta: %g\n", stats->max, stats->min, dBin); 224 225 // group data in daBin bins, measure lower 50% mean 226 for (int i = 0; i < daBin->n; i++) { 227 228 psVector *tmp = psVectorAlloc (psfTry->sources->n, PS_TYPE_F64); 229 tmp->n = 0; 230 231 // accumulate data within bin range 232 for (int j = 0; j < psfTry->sources->n; j++) { 233 // masked for: bad model fit, outlier in parameters 234 if (psfTry->mask->data.U8[j] & PSFTRY_MASK_ALL) 235 continue; 236 237 // skip points with extreme dA values 238 if (fabs(psfTry->metric->data.F64[j]) > 0.5) 239 continue; 240 241 // skip points outside of this bin 242 if (rflux->data.F64[j] < rfBin->data.F64[i] - 0.5*dBin) 243 continue; 244 if (rflux->data.F64[j] > rfBin->data.F64[i] + 0.5*dBin) 245 continue; 246 247 tmp->data.F64[tmp->n] = psfTry->metric->data.F64[j]; 248 tmp->n ++; 249 } 250 251 // is this a valid point? 252 maskB->data.U8[i] = 0; 253 if (tmp->n < 2) { 254 maskB->data.U8[i] = 1; 255 psFree (tmp); 256 continue; 257 } 258 259 // dA values are contaminated with low outliers 260 // measure statistics only on upper 50% of points 261 // this would be easier if we could sort in reverse: 262 // 263 // psVectorSort (tmp, tmp); 264 // tmp->n = 0.5*tmp->n; 265 // stats = psStatsAlloc (PS_STAT_SAMPLE_MEDIAN); 266 // psVectorStats (stats, tmp, NULL, NULL, 0); 267 // psTrace ("psphot.metricmodel", 4, "rfBin %d (%g): %d pts, %g\n", i, rfBin->data.F64[i], tmp->n, stats->sampleMedian); 268 269 psVectorSort (tmp, tmp); 270 nKeep = 0.5*tmp->n; 271 nSkip = tmp->n - nKeep; 272 273 psVector *tmp2 = psVectorAlloc (nKeep, PS_TYPE_F64); 274 for (int j = 0; j < tmp2->n; j++) { 275 tmp2->data.F64[j] = tmp->data.F64[j + nSkip]; 276 } 277 278 stats = psStatsAlloc (PS_STAT_SAMPLE_MEDIAN); 279 psVectorStats (stats, tmp2, NULL, NULL, 0); 280 psTrace ("psphot.metricmodel", 4, "rfBin %d (%g): %d pts, %g\n", i, rfBin->data.F64[i], tmp->n, stats->sampleMedian); 281 282 daBin->data.F64[i] = stats->sampleMedian; 283 284 psFree (stats); 285 psFree (tmp); 286 psFree (tmp2); 287 } 288 289 // linear fit to rfBin, daBin 290 psPolynomial1D *poly = psPolynomial1DAlloc(PS_POLYNOMIAL_ORD, 1); 291 292 // XXX EAM : this is the intended API (cycle 7? cycle 8?) 293 poly = psVectorFitPolynomial1D(poly, maskB, 1, daBin, NULL, rfBin); 294 295 // XXX EAM : replace this when the above version is implemented 296 // poly = psVectorFitPolynomial1DOrd(poly, maskB, rfBin, daBin, NULL); 297 298 psVector *daBinFit = psPolynomial1DEvalVector (poly, rfBin); 299 psVector *daResid = (psVector *) psBinaryOp (NULL, (void *) daBin, "-", (void *) daBinFit); 300 301 stats = psStatsAlloc (PS_STAT_CLIPPED_STDEV); 302 stats = psVectorStats (stats, daResid, NULL, maskB, 1); 303 304 psfTry->psf->ApResid = poly->coeff[0]; 305 psfTry->psf->dApResid = stats->clippedStdev; 306 psfTry->psf->skyBias = poly->coeff[1] / (M_PI * PS_SQR(RADIUS)); 202 // use 3hi/1lo sigma clipping on the rflux vs metric fit 203 psStats *stats = psStatsAlloc (PS_STAT_SAMPLE_MEDIAN | PS_STAT_SAMPLE_STDEV); 204 stats->min = 1.0; 205 stats->max = 3.0; 206 stats->clipIter = 3; 207 208 // fit ApResid only to rflux, ignore x,y variations for now 209 // linear clipped fit of ApResid to rflux 210 psPolynomial1D *poly = psPolynomial1DAlloc (1, PS_POLYNOMIAL_ORD); 211 poly = psVectorClipFitPolynomial1D (poly, stats, psfTry->mask, PSFTRY_MASK_ALL, psfTry->metric, NULL, rflux); 212 psLogMsg ("pmPSFtryMetric", 4, "fit stats: %f +/- %f\n", stats->sampleMedian, stats->sampleStdev); 213 214 psfTry->psf->ApTrend->coeff[0][0][0] = poly->coeff[0]; 215 psfTry->psf->ApTrend->coeff[0][0][1] = 0; 216 217 psfTry->psf->skyBias = poly->coeff[1] / (M_PI * PS_SQR(RADIUS)); 218 psfTry->psf->ApResid = poly->coeff[0]; 219 psfTry->psf->dApResid = stats->sampleStdev; 307 220 308 221 psFree (rflux); 309 psFree (rfBin);310 psFree (daBin);311 psFree (maskB);312 psFree (daBinFit);313 psFree (daResid);314 222 psFree (poly); 315 223 psFree (stats); … … 317 225 return true; 318 226 } 227 228 /* 229 (aprMag' - fitMag) = rflux*skyBias + ApTrend(x,y) 230 (aprMag - rflux*skyBias) - fitMag = ApTrend(x,y) 231 (aprMag - rflux*skyBias) = fitMag + ApTrend(x,y) 232 */ 233
Note:
See TracChangeset
for help on using the changeset viewer.
