Changeset 10032
- Timestamp:
- Nov 16, 2006, 4:45:46 PM (20 years ago)
- File:
-
- 1 edited
-
trunk/psphot/src/psphotEnsemblePSF.c (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psphot/src/psphotEnsemblePSF.c
r9834 r10032 1 1 # include "psphot.h" 2 bool pmSourceChisq (pmModel *model, psImage *image, psImage *mask, psImage *weight); 3 4 // 2006.02.07 : no leaks! 2 5 3 // fit all reasonable sources with the linear PSF model 6 4 bool psphotEnsemblePSF (pmReadout *readout, psArray *sources, psMetadata *recipe, pmPSF *psf, bool final) { … … 29 27 psArray *models = psArrayAllocEmpty (sources->n); 30 28 psVector *index = psVectorAllocEmpty (sources->n, PS_TYPE_U32); 31 // DROP models->n = index->n = 0;32 29 33 30 // option to limit analysis to a specific region … … 66 63 // really saturated stars should be re-measured for a better centroid 67 64 // XXX EAM : move this to a 'clear satstar function' 65 // XXX : place this in pmSourceMoments or wherever it is called? 68 66 if (inSource->mode & PM_SOURCE_MODE_SATSTAR) { 69 67 status = pmSourceMoments (inSource, INNER_RADIUS); … … 109 107 110 108 // make temporary copies of the image pixels and mask 109 // we need to have a copy which will not be modified by changes to its neighbor 111 110 otSource->mask = psImageCopy (NULL, inSource->mask, PS_TYPE_U8); 112 111 otSource->pixels = psImageCopy (NULL, inSource->pixels, PS_TYPE_F32); … … 142 141 psVector *weight = psVectorAlloc (models->n, PS_TYPE_F32); 143 142 psVector *errors = psVectorAlloc (models->n, PS_TYPE_F32); 143 144 // create the border matrix (includes the sparse matrix) 145 // for just sky: 1 row; for x,y terms: 3 rows 146 psSparseBorder *border = psSparseBorderAlloc (sparse, 1); 144 147 145 148 for (int i = 0; i < models->n; i++) { … … 166 169 psSparseVectorElement (sparse, i, f / r); 167 170 171 // add the per-source weights (border region) 172 p = pmSourceWeight (Mi, CONST, CONSTANT_PHOTOMETRIC_WEIGHTS); 173 // px = pmSourceWeight (Mi, XTERM, CONSTANT_PHOTOMETRIC_WEIGHTS); 174 // py = pmSourceWeight (Mi, YTERM, CONSTANT_PHOTOMETRIC_WEIGHTS); 175 psSparseBorderElementB (border, i, 0, p); 176 // psSparseBorderElementB (border, i, 1, px); 177 // psSparseBorderElementB (border, i, 2, py); 178 168 179 // loop over all other stars following this one 169 180 for (int j = i + 1; j < models->n; j++) { … … 183 194 psLogMsg ("psphot.emsemble", 4, "built matrix: %f (%d elements)\n", psTimerMark ("psphot"), sparse->Nelem); 184 195 196 // generate the image-wide weight terms 197 // first, mask all object pixels 198 for (int i = 0; i < models->n; i++) { 199 int N = index->data.U32[i]; 200 pmSource *Fi = sources->data[N]; 201 pmSource *Mi = models->data[i]; 202 203 // XXX need to select the correct mode (check this against the selections below 204 // - which model is appropriate for the given source? 205 // - which radius is appropriate for the given source? 206 // - where do x,y come from? 207 psImageKeepCircle (Mi->mask, x, y, model->radiusFit, "OR", PM_MASK_MARK); 208 } 209 210 // accumulate the image statistics from the masked regions 211 for (int j = 0; j < numRows; j++) { 212 for (int i = 0; i < numCols; i++) { 213 w += image->data.F32[j][i]/weight->data.F32[j][i]; 214 x += i*image->data.F32[j][i]/weight->data.F32[j][i]; 215 y += j*image->data.F32[j][i]/weight->data.F32[j][i]; 216 x2 += i*i*image->data.F32[j][i]/weight->data.F32[j][i]; 217 xy += i*j*image->data.F32[j][i]/weight->data.F32[j][i]; 218 y2 += j*j*image->data.F32[j][i]/weight->data.F32[j][i]; 219 } 220 } 221 psSparseBorderElementT (border, 0, 0, w); 222 if (0) { 223 psSparseBorderElementT (border, 1, 0, x); 224 psSparseBorderElementT (border, 2, 0, y); 225 psSparseBorderElementT (border, 0, 1, x); 226 psSparseBorderElementT (border, 1, 1, x2); 227 psSparseBorderElementT (border, 2, 1, xy); 228 psSparseBorderElementT (border, 0, 2, y); 229 psSparseBorderElementT (border, 1, 2, xy); 230 psSparseBorderElementT (border, 2, 2, y2); 231 } 232 185 233 psSparseConstraint constraint; 186 234 constraint.paramMin = 0.0; … … 190 238 // solve for normalization terms (need include local sky?) 191 239 psSparseResort (sparse); 192 psVector *norm = psSparseSolve (NULL, constraint, sparse, 3); 240 psSparseBorderSolve (&xFit, &yFit, constraint, border, 3); 241 242 // psVector *norm = psSparseSolve (NULL, constraint, sparse, 3); 193 243 194 244 // adjust models, set sources and subtract … … 244 294 return true; 245 295 } 246 247 bool pmSourceChisq (pmModel *model, psImage *image, psImage *mask, psImage *weight) {248 249 double dC = 0.0;250 int Npix = 0;251 for (int j = 0; j < image->numRows; j++) {252 for (int i = 0; i < image->numCols; i++) {253 if (mask->data.U8[j][i]) continue;254 if (weight->data.F32[j][i] <= 0) continue;255 dC += PS_SQR (image->data.F32[j][i]) / weight->data.F32[j][i];256 Npix ++;257 }258 }259 model->nDOF = Npix - 1;260 model->chisq = dC;261 262 return (true);263 }
Note:
See TracChangeset
for help on using the changeset viewer.
