Changeset 4115 for trunk/psphot/src/pspsf.c
- Timestamp:
- Jun 4, 2005, 5:22:13 PM (21 years ago)
- File:
-
- 1 edited
-
trunk/psphot/src/pspsf.c (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psphot/src/pspsf.c
r4114 r4115 36 36 test->metricStats = NULL; 37 37 test->metric = psVectorAlloc (sources->n, PS_TYPE_F64); 38 test->mask = psVectorAlloc (sources->n, PS_TYPE_U8); 38 39 39 40 for (int i = 0; i < test->modelFLT->n; i++) { 40 41 test->modelFLT->data[i] = NULL; 41 42 test->modelPSF->data[i] = NULL; 43 test->mask->data.U8[i] = 0; 42 44 } 43 45 return (test); … … 57 59 psModel *model = pmSourceModelGuess (source, test->modelType); 58 60 59 // fit model as FLT, not PSF (skip poor fits) 60 if (!pmSourceFitModel (source, model, false)) continue; 61 // fit model as FLT, not PSF (mask & skip poor fits) 62 if (!pmSourceFitModel (source, model, false)) { 63 test->mask->data.U8[i] = 1; 64 continue; 65 } 61 66 test->modelFLT->data[i] = model; 62 67 Nflt ++; … … 66 71 67 72 // stage 2: construct a psf (pmPSF) from this collection of model fits 68 pmPSFFromModels (test->psf, test->modelFLT );73 pmPSFFromModels (test->psf, test->modelFLT, test->mask); 69 74 70 75 // stage 3: refit with fixed shape parameters … … 73 78 psSource *source = test->sources->data[i]; 74 79 psModel *modelFLT = test->modelFLT->data[i]; 75 if (modelFLT == NULL) continue; 80 81 // masked for: bad model fit, outlier in parameters 82 if (test->mask->data.U8[i]) continue; 83 if (modelFLT == NULL) { 84 psLogMsg ("psphot.psftest", 2, "programming error: missing model not masked\n"); 85 continue; 86 } 76 87 psModel *modelPSF = psModelFromPSF (modelFLT, test->psf); // set shape for this model 77 88 78 89 // fit model as PSF, not FLT (skip poor fits) 79 if (!pmSourceFitModel (source, modelPSF, true)) continue; 90 if (!pmSourceFitModel (source, modelPSF, true)) { 91 test->mask->data.U8[i] = 1; 92 continue; 93 } 80 94 test->modelPSF->data[i] = modelPSF; 81 95 Npsf ++; … … 92 106 float fitSum = 0; 93 107 108 // is this metricMask redundant with test->mask ? 94 109 metricMask->data.U8[i] = 1; 95 110 test->metric->data.F64[i] = 0; 96 111 112 if (test->mask->data.U8[i]) continue; 113 97 114 psModel *model = test->modelPSF->data[i]; 98 if (model == NULL) continue; 115 if (model == NULL) { 116 psLogMsg ("psphot.psftest", 2, "programming error: missing model not masked\n"); 117 continue; 118 } 99 119 100 120 psImage *image = ((psSource *)test->sources->data[i])->pixels; 101 121 psImage *mask = ((psSource *)test->sources->data[i])->mask; 102 122 123 // this metric is Ap-Fit 103 124 float sky = model->params->data.F32[0]; 104 105 125 for (int ix = 0; ix < image->numCols; ix++) { 106 126 for (int iy = 0; iy < image->numRows; iy++) { … … 110 130 } 111 131 } 112 // this metric is Ap-Fit113 132 // fprintf (stderr, "%d %f %f %f\n", i, obsSum, fitSum, test->metric->data.F64[i]); 133 // keep the good metrics 114 134 if ((fitSum > 0) && (obsSum > 0)) { 115 135 metricMask->data.U8[i] = 0; 116 136 test->metric->data.F64[i] = -2.5*log10(obsSum/fitSum); 117 } 137 } else { 138 test->mask->data.U8[i] = 1; 139 } 118 140 } 119 141 … … 128 150 // input: an array of psModels, pre-allocated psf 129 151 // some of the array entries may be NULL, ignore them 130 bool pmPSFFromModels (pmPSF *psf, psArray *models ) {152 bool pmPSFFromModels (pmPSF *psf, psArray *models, psVector *mask) { 131 153 132 154 int n; 133 155 134 // construct the x and yvectors from the collection of objects135 // count the number of valid model measurements156 // construct the fit vectors from the collection of objects 157 // use the mask to ignore missing fits 136 158 psVector *x = psVectorAlloc (models->n, PS_TYPE_F64); 137 159 psVector *y = psVectorAlloc (models->n, PS_TYPE_F64); 138 n = 0; 160 psVector *z = psVectorAlloc (models->n, PS_TYPE_F64); 161 psVector *dz = psVectorAlloc (models->n, PS_TYPE_F64); 162 139 163 for (int i = 0; i < models->n; i++) { 140 164 psModel *model = models->data[i]; … … 142 166 143 167 // XXX EAM : this is fragile: x and y must be stored consistently at 2,3 144 x->data.F64[n] = model->params->data.F32[2]; 145 y->data.F64[n] = model->params->data.F32[3]; 146 n++; 147 } 148 x->n = y->n = n; 168 x->data.F64[i] = model->params->data.F32[2]; 169 y->data.F64[i] = model->params->data.F32[3]; 170 } 149 171 150 172 // we are doing a robust fit. after each pass, we drop points which are 151 // more deviant than three sigma. 152 psVector *z = psVectorAlloc (x->n, PS_TYPE_F64);153 psVector *dz = psVectorAlloc (x->n, PS_TYPE_F64); 173 // more deviant than three sigma. 174 // mask is currently updated for each pass. this is inconsistent 175 154 176 for (int i = 0; i < psf->params->n; i++) { 155 n = 0;156 177 for (int j = 0; j < models->n; j++) { 157 178 psModel *model = models->data[j]; 158 179 if (model == NULL) continue; 159 z->data.F64[n] = model->params->data.F32[i + 4]; 160 dz->data.F64[n] = 1; 161 n++; 180 z->data.F64[j] = model->params->data.F32[i + 4]; 181 dz->data.F64[j] = 1; 162 182 // XXX EAM : need to use actual errors? 163 183 // XXX EAM : this is fragile: psf(Nparams) = model(Nparams) - 4 164 184 } 165 if (n != x->n) psAbort ("pmPSFFromModels", "programming error: mismatched number of NULL models\n"); 166 z->n = n; 167 dz->n = n; 168 169 psf->params->data[i] = RobustFit2D (psf->params->data[i], x, y, z, dz); 185 // if (n != x->n) psAbort ("pmPSFFromModels", "programming error: mismatched number of NULL models\n"); 186 187 psf->params->data[i] = RobustFit2D (psf->params->data[i], mask, x, y, z, dz); 170 188 // psPolynomial2DDump (psf->params->data[i]); 171 189 }
Note:
See TracChangeset
for help on using the changeset viewer.
