Changeset 35455 for trunk/psModules/src/imcombine/pmSubtraction.c
- Timestamp:
- Apr 30, 2013, 6:10:41 PM (13 years ago)
- File:
-
- 1 edited
-
trunk/psModules/src/imcombine/pmSubtraction.c (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psModules/src/imcombine/pmSubtraction.c
r33425 r35455 37 37 #define USE_KERNEL_ERR // Use kernel error image? 38 38 #define NUM_COVAR_POS 5 // Number of positions for covariance calculation 39 #define USE_LOGFIT_REJECT 39 40 40 41 // XXX we need to pass these fwhm values elsewhere. These should go on one of the structure, but … … 966 967 psPolynomial1D *model = psPolynomial1DAlloc (PS_POLYNOMIAL_ORD, 2); 967 968 969 #ifdef USE_LOGFIT_REJECT 970 // CZW: Since flux and chisq can range over many orders of magnitude, use a log-log fit to calculate the 971 // RMS scatter. This should be more robust against outliers that can impact the fit quality. 972 psVector *logchisq = psVectorAlloc(match->chisq->n,PS_TYPE_F32); 973 psVector *logflux = psVectorAlloc(match->fluxes->n,PS_TYPE_F32); 974 for (int qq = 0; qq < match->chisq->n; qq++) { 975 if ((match->chisq->data.F32[qq] > 0)&& 976 (match->fluxes->data.F32[qq] > 0)) { 977 logchisq->data.F32[qq] = log10(match->chisq->data.F32[qq]); 978 logflux->data.F32[qq] = log10(match->fluxes->data.F32[qq]); 979 } 980 else { 981 // Ignore negative values. Maybe we could do an offset or something, but not today. 982 match->stampMask->data.PS_TYPE_VECTOR_MASK_DATA[qq] |= PM_SUBTRACTION_STAMP_REJECTED; 983 } 984 // if (!(match->stampMask->data.PS_TYPE_VECTOR_MASK_DATA[qq] & 0xff)) { 985 // psLogMsg("psModules.imcombine", PS_LOG_INFO, "RRRRRR: %d %g %g %g %g\n", 986 // qq,match->chisq->data.F32[qq],match->fluxes->data.F32[qq], 987 // 0.0,0.0); 988 // } 989 990 } 991 bool result = psVectorClipFitPolynomial1D(model, stats, match->stampMask, 0xff, logchisq, NULL, logflux); 992 if (!result) { 993 psError(PM_ERR_DATA, false, "Unable to measure statistics for deviations."); 994 psFree(model); 995 psFree(stats); 996 return -1; 997 } 998 999 // However, since we've done a log-log fit, we can't rely on the statistics in the stats object 1000 // To accurately represent the distribution. I've tried to massage them (as dlog10(X) = abs(1/(X log(10))) dX), 1001 // but ended up deciding to just manually calculate the residual, and then pass that to a robust stats object. 1002 psStats *residStats = psStatsAlloc(PS_STAT_ROBUST_MEDIAN | PS_STAT_ROBUST_STDEV); 1003 psVector *residData = psVectorAlloc(match->chisq->n,PS_TYPE_F32); 1004 int counter = 0; 1005 for (int qq = 0; qq < match->chisq->n; qq++) { 1006 if (!(match->stampMask->data.PS_TYPE_VECTOR_MASK_DATA[qq] & 0xff)) { 1007 double vv = pow(10, 1008 model->coeff[0] + 1009 model->coeff[1] * log10(match->fluxes->data.F32[qq]) + 1010 model->coeff[2] * pow(log10(match->fluxes->data.F32[qq]),2)); 1011 residData->data.F32[qq] = match->chisq->data.F32[qq] - vv; 1012 counter++; 1013 // psLogMsg("psModules.imcombine", PS_LOG_INFO, "SSSSS: %d %g %g %g %g\n", 1014 // qq,match->chisq->data.F32[qq],match->fluxes->data.F32[qq], 1015 // vv,residData->data.F32[qq]); 1016 } 1017 } 1018 psVectorStats(residStats,residData,NULL,match->stampMask,0xff); 1019 if (isnan(residStats->robustMedian)) { 1020 psError(PM_ERR_DATA, false, "Unable to measure statistics for deviations."); 1021 psFree(model); 1022 psFree(stats); 1023 psFree(logchisq); 1024 psFree(logflux); 1025 psFree(residStats); 1026 psFree(residData); 1027 1028 return -1; 1029 } 1030 1031 kernels->mean = residStats->robustMedian; 1032 kernels->rms = residStats->robustStdev; 1033 kernels->numStamps = counter; 1034 1035 psLogMsg ("pmPSFtry", 4, "chisq vs flux resid: %f +/- %f\n", residStats->robustMedian,residStats->robustStdev); 1036 psFree(logchisq); 1037 psFree(logflux); 1038 psFree(residStats); 1039 psFree(residData); 1040 1041 #else 1042 // CZW: Otherwise, use the original linear fit code. 968 1043 bool result = psVectorClipFitPolynomial1D(model, stats, match->stampMask, 0xff, match->chisq, NULL, match->fluxes); 969 1044 if (!result) { … … 979 1054 return -1; 980 1055 } 981 982 1056 kernels->mean = stats->sampleMean; 983 kernels->rms = stats->sampleStdev;1057 kernels->rms = stats->sampleStdev; 984 1058 kernels->numStamps = stats->clippedNvalues; 1059 psLogMsg ("pmPSFtry", 4, "chisq vs flux resid: %f +/- %f\n", stats->sampleMean, stats->sampleStdev); 1060 #endif 985 1061 986 1062 psLogMsg ("pmPSFtry", 4, "chisq vs flux model: %e + %e flux + %e flux^2\n", model->coeff[0], model->coeff[1], model->coeff[2]); 987 psLogMsg ("pmPSFtry", 4, "chisq vs flux resid: %f +/- %f\n", stats->sampleMean, stats->sampleStdev);988 1063 psLogMsg("psModules.imcombine", PS_LOG_INFO, "Mean deviation from %d stamps: %lf +/- %lf", kernels->numStamps, kernels->mean, kernels->rms); 989 1064
Note:
See TracChangeset
for help on using the changeset viewer.
