Changeset 13900 for trunk/psphot/src/psphotFitSourcesLinear.c
- Timestamp:
- Jun 19, 2007, 4:40:44 PM (19 years ago)
- File:
-
- 1 edited
-
trunk/psphot/src/psphotFitSourcesLinear.c (modified) (13 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psphot/src/psphotFitSourcesLinear.c
r13375 r13900 5 5 // model with selected pixels, and the fit radius must be defined 6 6 7 // given the set of sources, each of which points to the pixels in the 8 // science image, we construct a set of simulated sources with their own pixels. 9 // these are used to determine the simultaneous linear fit of fluxes. 7 // given the set of sources, each of which points to the pixels in the 8 // science image, we construct a set of simulated sources with their own pixels. 9 // these are used to determine the simultaneous linear fit of fluxes. 10 10 // the analysis is performed wrt the simulated pixel values 11 11 12 12 static bool SetBorderMatrixElements (psSparseBorder *border, pmReadout *readout, psArray *sources, bool constant_weights, int SKY_FIT_ORDER); 13 13 14 bool psphotFitSourcesLinear (pmReadout *readout, psArray *sources, psMetadata *recipe, pmPSF *psf, bool final ) {14 bool psphotFitSourcesLinear (pmReadout *readout, psArray *sources, psMetadata *recipe, pmPSF *psf, bool final, psMaskType maskVal) { 15 15 16 16 bool status; … … 41 41 int SKY_FIT_ORDER = psMetadataLookupS32(&status, recipe, "SKY_FIT_ORDER"); 42 42 if (!status) { 43 SKY_FIT_ORDER = 0;43 SKY_FIT_ORDER = 0; 44 44 } 45 45 bool SKY_FIT_LINEAR = psMetadataLookupBool(&status, recipe, "SKY_FIT_LINEAR"); 46 46 if (!status) { 47 SKY_FIT_LINEAR = false;47 SKY_FIT_LINEAR = false; 48 48 } 49 49 … … 55 55 if (source->type == PM_SOURCE_TYPE_DEFECT) continue; 56 56 if (source->type == PM_SOURCE_TYPE_SATURATED) continue; 57 if (source->type == PM_SOURCE_TYPE_STAR &&57 if (source->type == PM_SOURCE_TYPE_STAR && 58 58 source->mode & PM_SOURCE_MODE_SATSTAR) continue; 59 59 if (final) { … … 67 67 y = source->peak->yf; 68 68 69 // is the source in the region of interest?69 // is the source in the region of interest? 70 70 if (x < AnalysisRegion.x0) continue; 71 71 if (y < AnalysisRegion.y0) continue; … … 97 97 psSparseMatrixElement (sparse, i, i, f); 98 98 99 // the formal error depends on the weighting scheme100 if (CONSTANT_PHOTOMETRIC_WEIGHTS) {101 float var = pmSourceModelDotModel (SRCi, SRCi, false);102 errors->data.F32[i] = 1.0 / sqrt(var);103 } else {104 errors->data.F32[i] = 1.0 / sqrt(f);105 }99 // the formal error depends on the weighting scheme 100 if (CONSTANT_PHOTOMETRIC_WEIGHTS) { 101 float var = pmSourceModelDotModel (SRCi, SRCi, false); 102 errors->data.F32[i] = 1.0 / sqrt(var); 103 } else { 104 errors->data.F32[i] = 1.0 / sqrt(f); 105 } 106 106 107 107 … … 110 110 psSparseVectorElement (sparse, i, f); 111 111 112 // add the per-source weights (border region)113 switch (SKY_FIT_ORDER) {114 case 1:115 f = pmSourceModelWeight (SRCi, 1, CONSTANT_PHOTOMETRIC_WEIGHTS);116 psSparseBorderElementB (border, i, 1, f);117 f = pmSourceModelWeight (SRCi, 2, CONSTANT_PHOTOMETRIC_WEIGHTS);118 psSparseBorderElementB (border, i, 2, f);119 120 case 0:121 f = pmSourceModelWeight (SRCi, 0, CONSTANT_PHOTOMETRIC_WEIGHTS);122 psSparseBorderElementB (border, i, 0, f);123 break;124 125 default:126 psAbort("Invalid SKY_FIT_ORDER %d\n", SKY_FIT_ORDER);127 break;128 }112 // add the per-source weights (border region) 113 switch (SKY_FIT_ORDER) { 114 case 1: 115 f = pmSourceModelWeight (SRCi, 1, CONSTANT_PHOTOMETRIC_WEIGHTS); 116 psSparseBorderElementB (border, i, 1, f); 117 f = pmSourceModelWeight (SRCi, 2, CONSTANT_PHOTOMETRIC_WEIGHTS); 118 psSparseBorderElementB (border, i, 2, f); 119 120 case 0: 121 f = pmSourceModelWeight (SRCi, 0, CONSTANT_PHOTOMETRIC_WEIGHTS); 122 psSparseBorderElementB (border, i, 0, f); 123 break; 124 125 default: 126 psAbort("Invalid SKY_FIT_ORDER %d\n", SKY_FIT_ORDER); 127 break; 128 } 129 129 130 130 // loop over all other stars following this one … … 159 159 psVector *skyfit = NULL; 160 160 if (SKY_FIT_LINEAR) { 161 psSparseBorderSolve (&norm, &skyfit, constraint, border, 5);162 fprintf (stderr, "skyfit: %f\n", skyfit->data.F32[0]);161 psSparseBorderSolve (&norm, &skyfit, constraint, border, 5); 162 fprintf (stderr, "skyfit: %f\n", skyfit->data.F32[0]); 163 163 } else { 164 norm = psSparseSolve (NULL, constraint, sparse, 5);165 skyfit = NULL;164 norm = psSparseSolve (NULL, constraint, sparse, 5); 165 skyfit = NULL; 166 166 } 167 167 … … 169 169 for (int i = 0; i < fitSources->n; i++) { 170 170 pmSource *source = fitSources->data[i]; 171 pmModel *model = pmSourceGetModel (NULL, source);171 pmModel *model = pmSourceGetModel (NULL, source); 172 172 173 173 // assign linearly-fitted normalization … … 177 177 model->params->data.F32[PM_PAR_I0] = norm->data.F32[i]; 178 178 model->dparams->data.F32[PM_PAR_I0] = errors->data.F32[i]; 179 // XXX is the value of 'errors' modified by the sky fit?179 // XXX is the value of 'errors' modified by the sky fit? 180 180 181 181 // subtract object 182 pmSourceSub (source, PM_MODEL_OP_FULL);182 pmSourceSub (source, PM_MODEL_OP_FULL, maskVal); 183 183 source->mode |= PM_SOURCE_MODE_SUBTRACTED; 184 184 if (!final) source->mode |= PM_SOURCE_MODE_TEMPSUB; 185 // XXX not sure about the use of TEMPSUB185 // XXX not sure about the use of TEMPSUB 186 186 } 187 187 … … 190 190 pmSource *source = fitSources->data[i]; 191 191 pmModel *model = pmSourceGetModel (NULL, source); 192 pmSourceChisq (model, source->pixels, source->maskObj, source->weight );192 pmSourceChisq (model, source->pixels, source->maskObj, source->weight, maskVal); 193 193 } 194 194 … … 219 219 for (int i = 0; i < sources->n; i++) { 220 220 pmSource *source = sources->data[i]; 221 pmModel *model = pmSourceGetModel (NULL, source);222 if (model == NULL) continue;221 pmModel *model = pmSourceGetModel (NULL, source); 222 if (model == NULL) continue; 223 223 float x = model->params->data.F32[PM_PAR_XPOS]; 224 224 float y = model->params->data.F32[PM_PAR_YPOS]; 225 psImageMaskCircle (source->maskView, x, y, model->radiusFit, "AND", PS_NOT_U8(PM_MASK_MARK));226 } 225 psImageMaskCircle (source->maskView, x, y, model->radiusFit, "AND", PS_NOT_U8(PM_MASK_MARK)); 226 } 227 227 228 228 // accumulate the image statistics from the masked regions … … 233 233 double w, x, y, x2, xy, y2, xc, yc, wt, f, fo, fx, fy; 234 234 w = x = y = x2 = xy = y2 = fo = fx = fy = 0; 235 235 236 236 int col0 = readout->image->col0; 237 237 int row0 = readout->image->row0; 238 238 239 239 for (int j = 0; j < readout->image->numRows; j++) { 240 for (int i = 0; i < readout->image->numCols; i++) {241 if (mask[j][i]) continue;242 if (constant_weights) {243 wt = 1.0;244 } else {245 wt = weight[j][i];246 }247 f = image[j][i];248 w += 1/wt;249 fo += f/wt;250 if (SKY_FIT_ORDER == 0) continue;251 252 xc = i + col0;253 yc = j + row0;254 x += xc/wt;255 y += yc/wt;256 x2 += xc*xc/wt;257 xy += xc*yc/wt;258 y2 += yc*yc/wt;259 fx += f*xc/wt;260 fy += f*yc/wt;261 }240 for (int i = 0; i < readout->image->numCols; i++) { 241 if (mask[j][i]) continue; 242 if (constant_weights) { 243 wt = 1.0; 244 } else { 245 wt = weight[j][i]; 246 } 247 f = image[j][i]; 248 w += 1/wt; 249 fo += f/wt; 250 if (SKY_FIT_ORDER == 0) continue; 251 252 xc = i + col0; 253 yc = j + row0; 254 x += xc/wt; 255 y += yc/wt; 256 x2 += xc*xc/wt; 257 xy += xc*yc/wt; 258 y2 += yc*yc/wt; 259 fx += f*xc/wt; 260 fy += f*yc/wt; 261 } 262 262 } 263 263 … … 269 269 psSparseBorderElementT (border, 0, 0, w); 270 270 if (SKY_FIT_ORDER > 0) { 271 psSparseBorderElementG (border, 0, fx);272 psSparseBorderElementG (border, 0, fy);273 psSparseBorderElementT (border, 1, 0, x);274 psSparseBorderElementT (border, 2, 0, y);275 psSparseBorderElementT (border, 0, 1, x);276 psSparseBorderElementT (border, 1, 1, x2);277 psSparseBorderElementT (border, 2, 1, xy);278 psSparseBorderElementT (border, 0, 2, y);279 psSparseBorderElementT (border, 1, 2, xy);280 psSparseBorderElementT (border, 2, 2, y2);281 } 271 psSparseBorderElementG (border, 0, fx); 272 psSparseBorderElementG (border, 0, fy); 273 psSparseBorderElementT (border, 1, 0, x); 274 psSparseBorderElementT (border, 2, 0, y); 275 psSparseBorderElementT (border, 0, 1, x); 276 psSparseBorderElementT (border, 1, 1, x2); 277 psSparseBorderElementT (border, 2, 1, xy); 278 psSparseBorderElementT (border, 0, 2, y); 279 psSparseBorderElementT (border, 1, 2, xy); 280 psSparseBorderElementT (border, 2, 2, y2); 281 } 282 282 return true; 283 283 }
Note:
See TracChangeset
for help on using the changeset viewer.
