Changeset 28426
- Timestamp:
- Jun 22, 2010, 3:00:02 PM (16 years ago)
- Location:
- trunk
- Files:
-
- 4 edited
-
psModules/src/objects/pmSourcePhotometry.c (modified) (14 diffs)
-
psModules/src/objects/pmSourcePhotometry.h (modified) (2 diffs)
-
psphot/src/psphotFitSourcesLinear.c (modified) (4 diffs)
-
psphot/src/psphotFitSourcesLinearStack.c (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psModules/src/objects/pmSourcePhotometry.c
r27531 r28426 107 107 // the source peak pixel is guaranteed to be on the image, and only minimally different from the source center 108 108 double fluxScale = pmTrend2DEval (psf->FluxScale, (float)source->peak->x, (float)source->peak->y); 109 psAssert (isfinite(fluxScale), "how can the flux scale be invalid? source at %d, %d\n", source->peak->x, source->peak->y);110 psAssert (fluxScale > 0.0, "how can the flux scale be negative? source at %d, %d\n", source->peak->x, source->peak->y);111 source->psfFlux = fluxScale * source->modelPSF->params->data.F32[PM_PAR_I0];112 source->psfFluxErr = fluxScale * source->modelPSF->dparams->data.F32[PM_PAR_I0];113 source->psfMag = -2.5*log10(source->psfFlux);109 psAssert (isfinite(fluxScale), "how can the flux scale be invalid? source at %d, %d\n", source->peak->x, source->peak->y); 110 psAssert (fluxScale > 0.0, "how can the flux scale be negative? source at %d, %d\n", source->peak->x, source->peak->y); 111 source->psfFlux = fluxScale * source->modelPSF->params->data.F32[PM_PAR_I0]; 112 source->psfFluxErr = fluxScale * source->modelPSF->dparams->data.F32[PM_PAR_I0]; 113 source->psfMag = -2.5*log10(source->psfFlux); 114 114 } else { 115 115 status = pmSourcePhotometryModel (&source->psfMag, &source->psfFlux, source->modelPSF); 116 source->psfFluxErr = source->psfFlux * (source->modelPSF->dparams->data.F32[PM_PAR_I0] / source->modelPSF->params->data.F32[PM_PAR_I0]);116 source->psfFluxErr = source->psfFlux * (source->modelPSF->dparams->data.F32[PM_PAR_I0] / source->modelPSF->params->data.F32[PM_PAR_I0]); 117 117 } 118 118 … … 120 120 if (source->modelFits) { 121 121 bool foundEXT = false; 122 for (int i = 0; i < source->modelFits->n; i++) {123 pmModel *model = source->modelFits->data[i];124 status = pmSourcePhotometryModel (&model->mag, NULL, model);125 if (model == source->modelEXT) foundEXT = true;126 }127 if (foundEXT) {128 source->extMag = source->modelEXT->mag;129 } else {130 status = pmSourcePhotometryModel (&source->extMag, NULL, source->modelEXT);131 }122 for (int i = 0; i < source->modelFits->n; i++) { 123 pmModel *model = source->modelFits->data[i]; 124 status = pmSourcePhotometryModel (&model->mag, NULL, model); 125 if (model == source->modelEXT) foundEXT = true; 126 } 127 if (foundEXT) { 128 source->extMag = source->modelEXT->mag; 129 } else { 130 status = pmSourcePhotometryModel (&source->extMag, NULL, source->modelEXT); 131 } 132 132 } else { 133 if (source->modelEXT) {134 status = pmSourcePhotometryModel (&source->extMag, NULL, source->modelEXT);135 }133 if (source->modelEXT) { 134 status = pmSourcePhotometryModel (&source->extMag, NULL, source->modelEXT); 135 } 136 136 } 137 137 … … 204 204 } 205 205 if (mode & PM_SOURCE_PHOT_APCORR) { 206 // XXX this should be removed -- we no longer fit for the 'sky bias'206 // XXX this should be removed -- we no longer fit for the 'sky bias' 207 207 rflux = pow (10.0, 0.4*source->psfMag); 208 208 source->apMag -= PS_SQR(source->apRadius)*rflux * psf->skyBias + psf->skySat / rflux; … … 236 236 flux = model->modelFlux (model->params); 237 237 if (flux > 0) { 238 mag = -2.5*log10(flux);238 mag = -2.5*log10(flux); 239 239 } 240 240 if (fitMag) { 241 *fitMag = mag;241 *fitMag = mag; 242 242 } 243 243 if (fitFlux) { 244 *fitFlux = flux;244 *fitFlux = flux; 245 245 } 246 246 … … 380 380 381 381 if (source->diffStats == NULL) { 382 source->diffStats = pmSourceDiffStatsAlloc();382 source->diffStats = pmSourceDiffStatsAlloc(); 383 383 } 384 384 … … 388 388 int nMask = 0; 389 389 int nBad = 0; 390 390 391 391 psImage *flux = source->pixels; 392 392 psImage *variance = source->variance; … … 394 394 395 395 for (int iy = 0; iy < flux->numRows; iy++) { 396 for (int ix = 0; ix < flux->numCols; ix++) {396 for (int ix = 0; ix < flux->numCols; ix++) { 397 397 if (mask->data.PS_TYPE_IMAGE_MASK_DATA[iy][ix] & maskVal) { 398 nMask ++;399 continue; 400 }401 402 float SN = flux->data.F32[iy][ix] / sqrt(variance->data.F32[iy][ix]);403 404 if (SN > +FLUX_LIMIT) { 405 nGood ++;406 fGood += fabs(flux->data.F32[iy][ix]);407 }408 409 if (SN < -FLUX_LIMIT) { 410 nBad ++;411 fBad += fabs(flux->data.F32[iy][ix]);412 }413 }398 nMask ++; 399 continue; 400 } 401 402 float SN = flux->data.F32[iy][ix] / sqrt(variance->data.F32[iy][ix]); 403 404 if (SN > +FLUX_LIMIT) { 405 nGood ++; 406 fGood += fabs(flux->data.F32[iy][ix]); 407 } 408 409 if (SN < -FLUX_LIMIT) { 410 nBad ++; 411 fBad += fabs(flux->data.F32[iy][ix]); 412 } 413 } 414 414 } 415 415 416 416 source->diffStats->nGood = nGood; 417 source->diffStats->fRatio = (fGood + fBad == 0.0) ? NAN : fGood / (fGood + fBad); 418 source->diffStats->nRatioBad = (nGood + nBad == 0) ? NAN : nGood / (float) (nGood + nBad); 419 source->diffStats->nRatioMask = (nGood + nMask == 0) ? NAN : nGood / (float) (nGood + nMask); 417 source->diffStats->fRatio = (fGood + fBad == 0.0) ? NAN : fGood / (fGood + fBad); 418 source->diffStats->nRatioBad = (nGood + nBad == 0) ? NAN : nGood / (float) (nGood + nBad); 419 source->diffStats->nRatioMask = (nGood + nMask == 0) ? NAN : nGood / (float) (nGood + nMask); 420 420 source->diffStats->nRatioAll = (nGood + nMask + nBad == 0) ? NAN : nGood / (float) (nGood + nMask + nBad); 421 421 … … 628 628 } 629 629 } 630 model->nPix = Npix; 630 model->nPix = Npix; 631 631 model->nDOF = Npix - 1; 632 632 model->chisq = dC; … … 636 636 637 637 638 double pmSourceModelWeight(const pmSource *Mi, int term, const bool unweighted_sum, const float covarFactor )638 double pmSourceModelWeight(const pmSource *Mi, int term, const bool unweighted_sum, const float covarFactor, psImageMaskType maskVal) 639 639 { 640 640 PS_ASSERT_PTR_NON_NULL(Mi, NAN); … … 652 652 for (int yi = 0; yi < Pi->numRows; yi++) { 653 653 for (int xi = 0; xi < Pi->numCols; xi++) { 654 if (Ti->data.PS_TYPE_IMAGE_MASK_DATA[yi][xi] )654 if (Ti->data.PS_TYPE_IMAGE_MASK_DATA[yi][xi] & maskVal) 655 655 continue; 656 656 if (!unweighted_sum) { … … 684 684 } 685 685 686 double pmSourceModelDotModel (const pmSource *Mi, const pmSource *Mj, const bool unweighted_sum, const float covarFactor )686 double pmSourceModelDotModel (const pmSource *Mi, const pmSource *Mj, const bool unweighted_sum, const float covarFactor, psImageMaskType maskVal) 687 687 { 688 688 PS_ASSERT_PTR_NON_NULL(Mi, NAN); … … 727 727 for (yi = yIs, yj = yJs; yi < yIe; yi++, yj++) { 728 728 for (xi = xIs, xj = xJs; xi < xIe; xi++, xj++) { 729 if (Ti->data.PS_TYPE_IMAGE_MASK_DATA[yi][xi] )730 continue; 731 if (Tj->data.PS_TYPE_IMAGE_MASK_DATA[yj][xj] )729 if (Ti->data.PS_TYPE_IMAGE_MASK_DATA[yi][xi] & maskVal) 730 continue; 731 if (Tj->data.PS_TYPE_IMAGE_MASK_DATA[yj][xj] & maskVal) 732 732 continue; 733 733 … … 746 746 } 747 747 748 double pmSourceDataDotModel (const pmSource *Mi, const pmSource *Mj, const bool unweighted_sum, const float covarFactor )748 double pmSourceDataDotModel (const pmSource *Mi, const pmSource *Mj, const bool unweighted_sum, const float covarFactor, psImageMaskType maskVal) 749 749 { 750 750 PS_ASSERT_PTR_NON_NULL(Mi, NAN); … … 789 789 for (yi = yIs, yj = yJs; yi < yIe; yi++, yj++) { 790 790 for (xi = xIs, xj = xJs; xi < xIe; xi++, xj++) { 791 if (Ti->data.PS_TYPE_IMAGE_MASK_DATA[yi][xi] )792 continue; 793 if (Tj->data.PS_TYPE_IMAGE_MASK_DATA[yj][xj] )791 if (Ti->data.PS_TYPE_IMAGE_MASK_DATA[yi][xi] & maskVal) 792 continue; 793 if (Tj->data.PS_TYPE_IMAGE_MASK_DATA[yj][xj] & maskVal) 794 794 continue; 795 795 -
trunk/psModules/src/objects/pmSourcePhotometry.h
r27531 r28426 48 48 psImage *image, ///< image pixels to be used 49 49 psImage *mask, ///< mask of pixels to ignore 50 psImageMaskType maskVal ///< Value to mask50 psImageMaskType maskVal ///< Value to mask 51 51 ); 52 52 … … 58 58 bool pmSourceMeasureDiffStats (pmSource *source, psImageMaskType maskVal); 59 59 60 double pmSourceDataDotModel (const pmSource *Mi, const pmSource *Mj, const bool unweighted_sum, const float covarFactor );61 double pmSourceModelDotModel (const pmSource *Mi, const pmSource *Mj, const bool unweighted_sum, const float covarFactor );62 double pmSourceModelWeight(const pmSource *Mi, int term, const bool unweighted_sum, const float covarFactor );60 double pmSourceDataDotModel (const pmSource *Mi, const pmSource *Mj, const bool unweighted_sum, const float covarFactor, psImageMaskType maskVal); 61 double pmSourceModelDotModel (const pmSource *Mi, const pmSource *Mj, const bool unweighted_sum, const float covarFactor, psImageMaskType maskVal); 62 double pmSourceModelWeight(const pmSource *Mi, int term, const bool unweighted_sum, const float covarFactor, psImageMaskType maskVal); 63 63 64 64 // retire these: -
trunk/psphot/src/psphotFitSourcesLinear.c
r28399 r28426 171 171 172 172 // diagonal elements of the sparse matrix (auto-cross-product) 173 f = pmSourceModelDotModel (SRCi, SRCi, CONSTANT_PHOTOMETRIC_WEIGHTS, covarFactor );173 f = pmSourceModelDotModel (SRCi, SRCi, CONSTANT_PHOTOMETRIC_WEIGHTS, covarFactor, maskVal); 174 174 psSparseMatrixElement (sparse, i, i, f); 175 175 176 176 // the formal error depends on the weighting scheme 177 177 if (CONSTANT_PHOTOMETRIC_WEIGHTS) { 178 float var = pmSourceModelDotModel (SRCi, SRCi, false, covarFactor );178 float var = pmSourceModelDotModel (SRCi, SRCi, false, covarFactor, maskVal); 179 179 errors->data.F32[i] = 1.0 / sqrt(var); 180 180 } else { … … 184 184 185 185 // find the image x model value 186 f = pmSourceDataDotModel (SRCi, SRCi, CONSTANT_PHOTOMETRIC_WEIGHTS, covarFactor );186 f = pmSourceDataDotModel (SRCi, SRCi, CONSTANT_PHOTOMETRIC_WEIGHTS, covarFactor, maskVal); 187 187 psSparseVectorElement (sparse, i, f); 188 188 … … 190 190 switch (SKY_FIT_ORDER) { 191 191 case 1: 192 f = pmSourceModelWeight (SRCi, 1, CONSTANT_PHOTOMETRIC_WEIGHTS, covarFactor );192 f = pmSourceModelWeight (SRCi, 1, CONSTANT_PHOTOMETRIC_WEIGHTS, covarFactor, maskVal); 193 193 psSparseBorderElementB (border, i, 1, f); 194 f = pmSourceModelWeight (SRCi, 2, CONSTANT_PHOTOMETRIC_WEIGHTS, covarFactor );194 f = pmSourceModelWeight (SRCi, 2, CONSTANT_PHOTOMETRIC_WEIGHTS, covarFactor, maskVal); 195 195 psSparseBorderElementB (border, i, 2, f); 196 196 197 197 case 0: 198 f = pmSourceModelWeight (SRCi, 0, CONSTANT_PHOTOMETRIC_WEIGHTS, covarFactor );198 f = pmSourceModelWeight (SRCi, 0, CONSTANT_PHOTOMETRIC_WEIGHTS, covarFactor, maskVal); 199 199 psSparseBorderElementB (border, i, 0, f); 200 200 break; … … 216 216 217 217 // got an overlap; calculate cross-product and add to output array 218 f = pmSourceModelDotModel (SRCi, SRCj, CONSTANT_PHOTOMETRIC_WEIGHTS, covarFactor );218 f = pmSourceModelDotModel (SRCi, SRCj, CONSTANT_PHOTOMETRIC_WEIGHTS, covarFactor, maskVal); 219 219 psSparseMatrixElement (sparse, j, i, f); 220 220 } -
trunk/psphot/src/psphotFitSourcesLinearStack.c
r28013 r28426 43 43 for (int i = 0; i < objects->n; i++) { 44 44 pmPhotObj *object = objects->data[i]; 45 if (!object) continue;46 if (!object->sources) continue;45 if (!object) continue; 46 if (!object->sources) continue; 47 47 48 // XXX check an element of the group to see if we should use it49 // if (!object->flags & PM_PHOT_OBJ_BAD) continue;48 // XXX check an element of the group to see if we should use it 49 // if (!object->flags & PM_PHOT_OBJ_BAD) continue; 50 50 51 for (int j = 0; j < object->sources->n; j++) {52 pmSource *source = object->sources->data[j];53 if (!source) continue;51 for (int j = 0; j < object->sources->n; j++) { 52 pmSource *source = object->sources->data[j]; 53 if (!source) continue; 54 54 55 // turn this bit off and turn it on again if we keep this source56 source->mode &= ~PM_SOURCE_MODE_LINEAR_FIT;55 // turn this bit off and turn it on again if we keep this source 56 source->mode &= ~PM_SOURCE_MODE_LINEAR_FIT; 57 57 58 // generate model for sources without, or skip if we can't59 if (!source->modelFlux) {58 // generate model for sources without, or skip if we can't 59 if (!source->modelFlux) { 60 60 if (!pmSourceCacheModel (source, maskVal)) continue; 61 }61 } 62 62 63 source->mode |= PM_SOURCE_MODE_LINEAR_FIT;64 psArrayAdd (fitSources, 100, source);65 }63 source->mode |= PM_SOURCE_MODE_LINEAR_FIT; 64 psArrayAdd (fitSources, 100, source); 65 } 66 66 } 67 67 psLogMsg ("psphot.ensemble", PS_LOG_MINUTIA, "built fitSources: %f sec (%ld objects)\n", psTimerMark ("psphot.linear"), objects->n); … … 85 85 86 86 // diagonal elements of the sparse matrix (auto-cross-product) 87 f = pmSourceModelDotModel (SRCi, SRCi, CONSTANT_PHOTOMETRIC_WEIGHTS, COVAR_FACTOR );87 f = pmSourceModelDotModel (SRCi, SRCi, CONSTANT_PHOTOMETRIC_WEIGHTS, COVAR_FACTOR, maskVal); 88 88 psSparseMatrixElement (sparse, i, i, f); 89 89 90 90 // the formal error depends on the weighting scheme 91 91 if (CONSTANT_PHOTOMETRIC_WEIGHTS) { 92 float var = pmSourceModelDotModel (SRCi, SRCi, false, COVAR_FACTOR );92 float var = pmSourceModelDotModel (SRCi, SRCi, false, COVAR_FACTOR, maskVal); 93 93 errors->data.F32[i] = 1.0 / sqrt(var); 94 94 } else { … … 97 97 98 98 // find the image x model value 99 f = pmSourceDataDotModel (SRCi, SRCi, CONSTANT_PHOTOMETRIC_WEIGHTS, COVAR_FACTOR );99 f = pmSourceDataDotModel (SRCi, SRCi, CONSTANT_PHOTOMETRIC_WEIGHTS, COVAR_FACTOR, maskVal); 100 100 psSparseVectorElement (sparse, i, f); 101 101 … … 104 104 pmSource *SRCj = fitSources->data[j]; 105 105 106 // we only need to generate dot terms for source on the same image107 if (SRCj->imageID != SRCi->imageID) { continue; }106 // we only need to generate dot terms for source on the same image 107 if (SRCj->imageID != SRCi->imageID) { continue; } 108 108 109 109 // skip over disjoint source images, break after last possible overlap … … 114 114 115 115 // got an overlap; calculate cross-product and add to output array 116 f = pmSourceModelDotModel (SRCi, SRCj, CONSTANT_PHOTOMETRIC_WEIGHTS, COVAR_FACTOR );116 f = pmSourceModelDotModel (SRCi, SRCj, CONSTANT_PHOTOMETRIC_WEIGHTS, COVAR_FACTOR, maskVal); 117 117 psSparseMatrixElement (sparse, j, i, f); 118 118 }
Note:
See TracChangeset
for help on using the changeset viewer.
