Changeset 20864
- Timestamp:
- Dec 1, 2008, 2:38:47 PM (17 years ago)
- File:
-
- 1 edited
-
trunk/psphot/src/psphotApResid.c (modified) (13 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psphot/src/psphotApResid.c
r20581 r20864 22 22 bool measureAptrend = psMetadataLookupBool (&status, recipe, "MEASURE.APTREND"); 23 23 if (!measureAptrend) { 24 // save nan values since these were not calculated25 psMetadataAdd (recipe, PS_LIST_TAIL, "SKYBIAS", PS_DATA_F32 | PS_META_REPLACE, "aperture sky bias", NAN);26 psMetadataAdd (recipe, PS_LIST_TAIL, "SKYSAT", PS_DATA_F32 | PS_META_REPLACE, "aperture-determined saturation", NAN);27 psMetadataAdd (recipe, PS_LIST_TAIL, "APMIFIT", PS_DATA_F32 | PS_META_REPLACE, "aperture residual", NAN);28 psMetadataAdd (recipe, PS_LIST_TAIL, "DAPMIFIT", PS_DATA_F32 | PS_META_REPLACE, "ap residual scatter", NAN);29 psMetadataAdd (recipe, PS_LIST_TAIL, "APLOSS", PS_DATA_F32 | PS_META_REPLACE, "aperture loss (mag)", NAN);30 psMetadataAdd (recipe, PS_LIST_TAIL, "NAPMIFIT", PS_DATA_S32 | PS_META_REPLACE, "number of apresid stars", 0);31 return true;24 // save nan values since these were not calculated 25 psMetadataAdd (recipe, PS_LIST_TAIL, "SKYBIAS", PS_DATA_F32 | PS_META_REPLACE, "aperture sky bias", NAN); 26 psMetadataAdd (recipe, PS_LIST_TAIL, "SKYSAT", PS_DATA_F32 | PS_META_REPLACE, "aperture-determined saturation", NAN); 27 psMetadataAdd (recipe, PS_LIST_TAIL, "APMIFIT", PS_DATA_F32 | PS_META_REPLACE, "aperture residual", NAN); 28 psMetadataAdd (recipe, PS_LIST_TAIL, "DAPMIFIT", PS_DATA_F32 | PS_META_REPLACE, "ap residual scatter", NAN); 29 psMetadataAdd (recipe, PS_LIST_TAIL, "APLOSS", PS_DATA_F32 | PS_META_REPLACE, "aperture loss (mag)", NAN); 30 psMetadataAdd (recipe, PS_LIST_TAIL, "NAPMIFIT", PS_DATA_S32 | PS_META_REPLACE, "number of apresid stars", 0); 31 return true; 32 32 } 33 33 … … 93 93 if (!pmSourceMagnitudes (source, psf, photMode, maskVal)) { 94 94 Nskip ++; 95 psTrace ("psphot", 3, "skip : bad source mag");95 psTrace ("psphot", 3, "skip : bad source mag"); 96 96 continue; 97 97 } … … 99 99 if (!isfinite(source->apMag) || !isfinite(source->psfMag)) { 100 100 Nfail ++; 101 psTrace ("psphot", 3, "fail : nan mags : %f %f", source->apMag, source->psfMag);101 psTrace ("psphot", 3, "fail : nan mags : %f %f", source->apMag, source->psfMag); 102 102 continue; 103 103 } 104 104 105 // aperture residual for this source106 float dap = source->apMag - source->psfMag;105 // aperture residual for this source 106 float dap = source->apMag - source->psfMag; 107 107 108 108 // sanity clipping : if the model is very discrepant, put your expectation in the recipe 109 109 if ((MAX_AP_OFFSET > 0) && (fabs(dap) > MAX_AP_OFFSET)) { 110 110 Nfail ++; 111 psTrace ("psphot", 3, "fail : bad dap %f %f", dap, MAX_AP_OFFSET);111 psTrace ("psphot", 3, "fail : bad dap %f %f", dap, MAX_AP_OFFSET); 112 112 continue; 113 113 } 114 114 115 mag->data.F32[Npsf] = source->psfMag;115 mag->data.F32[Npsf] = source->psfMag; 116 116 apResid->data.F32[Npsf] = dap; 117 117 xPos->data.F32[Npsf] = model->params->data.F32[PM_PAR_XPOS]; … … 130 130 Npsf ++; 131 131 } 132 132 133 133 psLogMsg ("psphot.apresid", PS_LOG_DETAIL, "measure aperture residuals for %d objects (%d skipped, %d failed, %ld invalid)\n", 134 134 Npsf, Nskip, Nfail, sources->n - Npsf - Nskip - Nfail); … … 137 137 if (Npsf < APTREND_NSTAR_MIN) { 138 138 psWarning("Only %d valid aperture residual sources (need %d), giving up", Npsf, APTREND_NSTAR_MIN); 139 // save nan values since these were not calculated140 psMetadataAdd (recipe, PS_LIST_TAIL, "SKYBIAS", PS_DATA_F32 | PS_META_REPLACE, "aperture sky bias", NAN);141 psMetadataAdd (recipe, PS_LIST_TAIL, "SKYSAT", PS_DATA_F32 | PS_META_REPLACE, "aperture-determined saturation", NAN);142 psMetadataAdd (recipe, PS_LIST_TAIL, "APMIFIT", PS_DATA_F32 | PS_META_REPLACE, "aperture residual", NAN);143 psMetadataAdd (recipe, PS_LIST_TAIL, "DAPMIFIT", PS_DATA_F32 | PS_META_REPLACE, "ap residual scatter", NAN);144 psMetadataAdd (recipe, PS_LIST_TAIL, "APLOSS", PS_DATA_F32 | PS_META_REPLACE, "aperture loss (mag)", NAN);145 psMetadataAdd (recipe, PS_LIST_TAIL, "NAPMIFIT", PS_DATA_S32 | PS_META_REPLACE, "number of apresid stars", 0);146 147 psFree (mag);148 psFree (mask);149 psFree (xPos);150 psFree (yPos);151 psFree (apResid);152 psFree (dMag);139 // save nan values since these were not calculated 140 psMetadataAdd (recipe, PS_LIST_TAIL, "SKYBIAS", PS_DATA_F32 | PS_META_REPLACE, "aperture sky bias", NAN); 141 psMetadataAdd (recipe, PS_LIST_TAIL, "SKYSAT", PS_DATA_F32 | PS_META_REPLACE, "aperture-determined saturation", NAN); 142 psMetadataAdd (recipe, PS_LIST_TAIL, "APMIFIT", PS_DATA_F32 | PS_META_REPLACE, "aperture residual", NAN); 143 psMetadataAdd (recipe, PS_LIST_TAIL, "DAPMIFIT", PS_DATA_F32 | PS_META_REPLACE, "ap residual scatter", NAN); 144 psMetadataAdd (recipe, PS_LIST_TAIL, "APLOSS", PS_DATA_F32 | PS_META_REPLACE, "aperture loss (mag)", NAN); 145 psMetadataAdd (recipe, PS_LIST_TAIL, "NAPMIFIT", PS_DATA_S32 | PS_META_REPLACE, "number of apresid stars", 0); 146 147 psFree (mag); 148 psFree (mask); 149 psFree (xPos); 150 psFree (yPos); 151 psFree (apResid); 152 psFree (dMag); 153 153 return false; 154 154 } … … 168 168 for (int i = 1; i <= APTREND_ORDER_MAX; i++) { 169 169 170 if (!psphotApResidTrend (readout, psf, Npsf, i, &errorScale, &errorFloor, mask, xPos, yPos, apResid, dMag)) {171 break;172 }173 174 // store the resulting errorFloor values and the scales, redo the best175 if (errorFloor < errorFloorMin) {176 errorFloorMin = errorFloor;177 entryMin = i;178 }170 if (!psphotApResidTrend (readout, psf, Npsf, i, &errorScale, &errorFloor, mask, xPos, yPos, apResid, dMag)) { 171 break; 172 } 173 174 // store the resulting errorFloor values and the scales, redo the best 175 if (errorFloor < errorFloorMin) { 176 errorFloorMin = errorFloor; 177 entryMin = i; 178 } 179 179 } 180 180 if (entryMin == -1) { 181 psAbort ("failed on ApResid Trend");182 } 183 184 // XXX catch error condition 181 psAbort ("failed on ApResid Trend"); 182 } 183 184 // XXX catch error condition 185 185 psphotApResidTrend (readout, psf, Npsf, entryMin, &errorScale, &errorFloor, mask, xPos, yPos, apResid, dMag); 186 186 … … 191 191 192 192 if (psTraceGetLevel("psphot") >= 2) { 193 FILE *dumpFile = fopen ("apresid.dat", "w");194 for (int i = 0; i < xPos->n; i++) {195 fprintf (dumpFile, "%f %f %f %f %f %f %f %x\n", 196 xPos->data.F32[i], yPos->data.F32[i], 197 mag->data.F32[i], dMag->data.F32[i], dMagSys->data.F32[i],198 apResid->data.F32[i], apResidRes->data.F32[i],199 mask->data.U8[i]);200 }201 fclose (dumpFile);193 FILE *dumpFile = fopen ("apresid.dat", "w"); 194 for (int i = 0; i < xPos->n; i++) { 195 fprintf (dumpFile, "%f %f %f %f %f %f %f %x\n", 196 xPos->data.F32[i], yPos->data.F32[i], 197 mag->data.F32[i], dMag->data.F32[i], dMagSys->data.F32[i], 198 apResid->data.F32[i], apResidRes->data.F32[i], 199 mask->data.U8[i]); 200 } 201 fclose (dumpFile); 202 202 } 203 203 … … 252 252 int nBin = PS_MAX (dMag->n / nGroup, 1); 253 253 254 // output vectors for ApResid trend 254 // output vectors for ApResid trend 255 255 psVector *dSo = psVectorAlloc (nBin, PS_TYPE_F32); 256 256 psVector *dMo = psVectorAlloc (nBin, PS_TYPE_F32); … … 267 267 int n = 0; 268 268 for (int i = 0; i < dMo->n; i++) { 269 int j;270 for (j = 0; (j < nGroup) && (n < dMag->n); j++, n++) {271 int N = index->data.U32[n];272 dMSubset->data.F32[j] = dMag->data.F32[N];273 dASubset->data.F32[j] = dap->data.F32[N];274 mkSubset->data.U8[j] = mask->data.U8[N];275 }276 dMSubset->n = j;277 dASubset->n = j;278 mkSubset->n = j;279 280 psStatsInit (statsS);281 psStatsInit (statsM);282 283 if (j > 2) {284 bool status = true;285 status &= psVectorStats (statsS, dASubset, NULL, mkSubset, 0xff);286 status &= psVectorStats (statsM, dMSubset, NULL, mkSubset, 0xff);287 if (!status) { psErrorClear (); }288 dSo->data.F32[i] = statsS->robustStdev;289 dMo->data.F32[i] = statsM->sampleMean;290 dRo->data.F32[i] = statsS->robustStdev / statsM->sampleMean;291 fprintf (stderr, "%d (%d) : sys: %f, phot: %f, rat: %f\n", i, j, dSo->data.F32[i], dMo->data.F32[i], dRo->data.F32[i]);292 } else {293 dSo->data.F32[i] = NAN;294 dMo->data.F32[i] = NAN;295 dRo->data.F32[i] = NAN;296 }269 int j; 270 for (j = 0; (j < nGroup) && (n < dMag->n); j++, n++) { 271 int N = index->data.U32[n]; 272 dMSubset->data.F32[j] = dMag->data.F32[N]; 273 dASubset->data.F32[j] = dap->data.F32[N]; 274 mkSubset->data.U8[j] = mask->data.U8[N]; 275 } 276 dMSubset->n = j; 277 dASubset->n = j; 278 mkSubset->n = j; 279 280 psStatsInit (statsS); 281 psStatsInit (statsM); 282 283 if (j > 2) { 284 bool status = true; 285 status &= psVectorStats (statsS, dASubset, NULL, mkSubset, 0xff); 286 status &= psVectorStats (statsM, dMSubset, NULL, mkSubset, 0xff); 287 if (!status) { psErrorClear (); } 288 dSo->data.F32[i] = statsS->robustStdev; 289 dMo->data.F32[i] = statsM->sampleMean; 290 dRo->data.F32[i] = statsS->robustStdev / statsM->sampleMean; 291 // fprintf (stderr, "%d (%d) : sys: %f, phot: %f, rat: %f\n", i, j, dSo->data.F32[i], dMo->data.F32[i], dRo->data.F32[i]); 292 } else { 293 dSo->data.F32[i] = NAN; 294 dMo->data.F32[i] = NAN; 295 dRo->data.F32[i] = NAN; 296 } 297 297 } 298 298 psFree (dMSubset); 299 299 psFree (dASubset); 300 300 psFree (mkSubset); 301 301 302 302 psStats *stats = psStatsAlloc (PS_STAT_SAMPLE_MEDIAN); 303 303 if (!psVectorStats (stats, dRo, NULL, NULL, 0)) { 304 // XXX better testing of raised error305 psErrorClear();304 // XXX better testing of raised error 305 psErrorClear(); 306 306 } 307 307 308 308 *errorScale = stats->sampleMedian; 309 309 for (int i = 0; i < dSo->n; i++) { 310 *errorFloor = dSo->data.F32[i];311 if (isfinite(*errorFloor)) break;310 *errorFloor = dSo->data.F32[i]; 311 if (isfinite(*errorFloor)) break; 312 312 } 313 313 … … 318 318 psFree (dMo); 319 319 psFree (dSo); 320 320 321 321 psFree (statsS); 322 322 psFree (statsM); … … 328 328 329 329 int Nx, Ny; 330 330 331 331 if (readout->image->numCols > readout->image->numRows) { 332 332 Nx = scale; 333 float AR = readout->image->numRows / (float) readout->image->numCols;334 Ny = (int) (Nx * AR + 0.5);333 float AR = readout->image->numRows / (float) readout->image->numCols; 334 Ny = (int) (Nx * AR + 0.5); 335 335 Ny = PS_MAX (1, Ny); 336 336 } else { 337 Ny = scale;338 float AR = readout->image->numRows / (float) readout->image->numCols;339 Nx = (int) (Ny * AR + 0.5);340 Nx = PS_MAX (1, Nx);341 } 342 337 Ny = scale; 338 float AR = readout->image->numRows / (float) readout->image->numCols; 339 Nx = (int) (Ny * AR + 0.5); 340 Nx = PS_MAX (1, Nx); 341 } 342 343 343 // require at least 10 stars per spatial bin 344 344 if (Npsf < 10*Nx*Ny) { 345 return false;345 return false; 346 346 } 347 347 … … 361 361 psVector *dMagSoft = psVectorAlloc (dMag->n, PS_TYPE_F32); 362 362 for (int i = 0; i < dMag->n; i++) { 363 dMagSoft->data.F32[i] = hypot(dMag->data.F32[i], 0.01);363 dMagSoft->data.F32[i] = hypot(dMag->data.F32[i], 0.01); 364 364 } 365 365 366 366 // XXX test for errors here 367 367 pmTrend2DFit (psf->ApTrend, mask, 0xff, xPos, yPos, apResid, dMagSoft); 368 368 369 369 // construct the fitted values and the residuals 370 370 psVector *apResidFit = pmTrend2DEvalVector (psf->ApTrend, xPos, yPos); … … 387 387 return true; 388 388 } 389 389
Note:
See TracChangeset
for help on using the changeset viewer.
