Changeset 10171
- Timestamp:
- Nov 22, 2006, 7:28:54 PM (19 years ago)
- File:
-
- 1 edited
-
trunk/psphot/src/psphotEnsemblePSF.c (modified) (14 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psphot/src/psphotEnsemblePSF.c
r10104 r10171 10 10 // the analysis is performed wrt the simulated pixel values 11 11 12 static bool SetBorderT (psSparseBorder *border, pmReadout *readout, psArray *refSources, psArray *fitSources, psVector *index, bool fitSlope, bool constant_weights);12 static bool SetBorderT (psSparseBorder *border, pmReadout *readout, psArray *refSources, psArray *fitSources, psVector *index, bool constant_weights, int SKY_FIT_ORDER); 13 13 14 14 bool psphotEnsemblePSF (pmReadout *readout, psArray *refSources, psMetadata *recipe, pmPSF *psf, bool final) { … … 19 19 float y; 20 20 float f; 21 float r;21 // float r; 22 22 23 23 psTimerStart ("psphot"); … … 36 36 if (psRegionIsNaN (AnalysisRegion)) psAbort ("psphot", "analysis region mis-defined"); 37 37 38 constbool CONSTANT_PHOTOMETRIC_WEIGHTS =38 bool CONSTANT_PHOTOMETRIC_WEIGHTS = 39 39 psMetadataLookupBool(&status, recipe, "CONSTANT_PHOTOMETRIC_WEIGHTS"); 40 40 if (!status) { 41 41 psAbort(PS_FILE_LINE, "You must provide a value for the BOOL recipe CONSTANT_PHOTOMETRIC_WEIGHTS"); 42 } 43 int SKY_FIT_ORDER = psMetadataLookupS32(&status, recipe, "SKY_FIT_ORDER"); 44 if (!status) { 45 SKY_FIT_ORDER = 0; 46 } 47 bool SKY_FIT_LINEAR = psMetadataLookupBool(&status, recipe, "SKY_FIT_LINEAR"); 48 if (!status) { 49 SKY_FIT_LINEAR = false; 42 50 } 43 51 … … 100 108 101 109 // vectors to store stats for each object 102 psVector *weight = psVectorAlloc (fitSources->n, PS_TYPE_F32);110 // psVector *weight = psVectorAlloc (fitSources->n, PS_TYPE_F32); 103 111 psVector *errors = psVectorAlloc (fitSources->n, PS_TYPE_F32); 104 112 … … 106 114 // for just sky: 1 row; for x,y terms: 3 rows 107 115 psSparse *sparse = psSparseAlloc (fitSources->n, 100); 108 psSparseBorder *border = psSparseBorderAlloc (sparse, 1); 116 int nBorder = (SKY_FIT_ORDER == 0) ? 1 : 3; 117 psSparseBorder *border = psSparseBorderAlloc (sparse, nBorder); 109 118 110 119 // fill out the sparse matrix elements and border elements (B) … … 116 125 pmSource *Fi = fitSources->data[i]; 117 126 118 // scale by diagonal element (auto-cross-product) 119 r = pmSourceCrossProduct (Fi, Fi, CONSTANT_PHOTOMETRIC_WEIGHTS); 120 weight->data.F32[i] = r; 127 // diagonal elements of the sparse matrix (auto-cross-product) 128 f = pmSourceCrossProduct (Fi, Fi, CONSTANT_PHOTOMETRIC_WEIGHTS); 129 psSparseMatrixElement (sparse, i, i, f); 130 131 // XXX being used? weight->data.F32[i] = r; 121 132 122 133 // the formal error depends on the weighting scheme … … 125 136 errors->data.F32[i] = 1.0 / sqrt(var); 126 137 } else { 127 errors->data.F32[i] = 1.0 / sqrt( r);138 errors->data.F32[i] = 1.0 / sqrt(f); 128 139 } 129 140 130 psSparseMatrixElement (sparse, i, i, 1.0);131 141 132 142 // find the image x model value 133 143 f = pmSourceCrossProduct (Ri, Fi, CONSTANT_PHOTOMETRIC_WEIGHTS); 134 psSparseVectorElement (sparse, i, f / r);144 psSparseVectorElement (sparse, i, f); 135 145 136 146 // add the per-source weights (border region) 137 float p = pmSourceWeight (Fi, 0, CONSTANT_PHOTOMETRIC_WEIGHTS); 138 // float px = pmSourceWeight (Fi, 1, CONSTANT_PHOTOMETRIC_WEIGHTS); 139 // float py = pmSourceWeight (Fi, 2, CONSTANT_PHOTOMETRIC_WEIGHTS); 140 psSparseBorderElementB (border, i, 0, p); 141 // psSparseBorderElementB (border, i, 1, px); 142 // psSparseBorderElementB (border, i, 2, py); 147 switch (SKY_FIT_ORDER) { 148 case 1: 149 f = pmSourceWeight (Fi, 1, CONSTANT_PHOTOMETRIC_WEIGHTS); 150 psSparseBorderElementB (border, i, 1, f); 151 f = pmSourceWeight (Fi, 2, CONSTANT_PHOTOMETRIC_WEIGHTS); 152 psSparseBorderElementB (border, i, 2, f); 153 154 case 0: 155 f = pmSourceWeight (Fi, 0, CONSTANT_PHOTOMETRIC_WEIGHTS); 156 psSparseBorderElementB (border, i, 0, f); 157 break; 158 159 default: 160 psAbort(PS_FILE_LINE, "Invalid SKY_FIT_ORDER %d\n", SKY_FIT_ORDER); 161 break; 162 } 143 163 144 164 // loop over all other stars following this one … … 154 174 // got an overlap; calculate cross-product and add to output array 155 175 f = pmSourceCrossProduct (Fi, Fj, CONSTANT_PHOTOMETRIC_WEIGHTS); 156 psSparseMatrixElement (sparse, j, i, f / r);176 psSparseMatrixElement (sparse, j, i, f); 157 177 } 158 178 } … … 161 181 162 182 // set the sky, sky_x, sky_y components of border matrix 163 // XXX ignore sky slope terms for now 164 SetBorderT (border, readout, refSources, fitSources, index, false, CONSTANT_PHOTOMETRIC_WEIGHTS); 183 SetBorderT (border, readout, refSources, fitSources, index, CONSTANT_PHOTOMETRIC_WEIGHTS, SKY_FIT_ORDER); 165 184 166 185 psSparseConstraint constraint; … … 170 189 171 190 // solve for normalization terms (need include local sky?) 172 # if (1)173 191 psVector *norm = NULL; 174 192 psVector *skyfit = NULL; 175 psSparseBorderSolve (&norm, &skyfit, constraint, border, 3); 176 fprintf (stderr, "skyfit: %f\n", skyfit->data.F32[0]); 177 # else 178 psVector *norm = psSparseSolve (NULL, constraint, sparse, 3); 179 psVector *skyfit = NULL; 180 # endif 193 if (SKY_FIT_LINEAR) { 194 psSparseBorderSolve (&norm, &skyfit, constraint, border, 5); 195 fprintf (stderr, "skyfit: %f\n", skyfit->data.F32[0]); 196 } else { 197 norm = psSparseSolve (NULL, constraint, sparse, 5); 198 skyfit = NULL; 199 } 181 200 182 201 // adjust fitSources, set refSources and subtract … … 220 239 psFree (norm); 221 240 psFree (skyfit); 222 psFree (weight);223 241 psFree (errors); 224 242 psFree (border); … … 229 247 230 248 // calculate the weight terms for the sky fit component of the matrix 231 static bool SetBorderT (psSparseBorder *border, pmReadout *readout, psArray *refSources, psArray *fitSources, psVector *index, bool fitSlope, bool constant_weights) {249 static bool SetBorderT (psSparseBorder *border, pmReadout *readout, psArray *refSources, psArray *fitSources, psVector *index, bool constant_weights, int SKY_FIT_ORDER) { 232 250 233 251 // generate the image-wide weight terms … … 271 289 w += 1/wt; 272 290 fo += f/wt; 273 274 if (!fitSlope) continue; 291 if (SKY_FIT_ORDER == 0) continue; 292 275 293 xc = i + col0; 276 294 yc = j + row0; … … 291 309 psSparseBorderElementG (border, 0, fo); 292 310 psSparseBorderElementT (border, 0, 0, w); 293 if ( fitSlope) {311 if (SKY_FIT_ORDER > 0) { 294 312 psSparseBorderElementG (border, 0, fx); 295 313 psSparseBorderElementG (border, 0, fy);
Note:
See TracChangeset
for help on using the changeset viewer.
