Changeset 31452
- Timestamp:
- May 5, 2011, 11:09:38 AM (15 years ago)
- Location:
- trunk/psphot
- Files:
-
- 29 edited
- 1 copied
-
. (modified) (1 prop)
-
src/Makefile.am (modified) (1 diff)
-
src/psphot.h (modified) (2 diffs)
-
src/psphotApResid.c (modified) (6 diffs)
-
src/psphotBlendFit.c (modified) (3 diffs)
-
src/psphotChoosePSF.c (modified) (1 diff)
-
src/psphotEfficiency.c (modified) (2 diffs)
-
src/psphotExtendedSourceFits.c (modified) (2 diffs)
-
src/psphotFitSourcesLinear.c (modified) (3 diffs)
-
src/psphotFitSourcesLinearStack.c (modified) (1 diff)
-
src/psphotGuessModels.c (modified) (4 diffs)
-
src/psphotKronMasked.c (copied) (copied from branches/eam_branches/ipp-20110404/psphot/src/psphotKronMasked.c )
-
src/psphotLoadSRCTEXT.c (modified) (2 diffs)
-
src/psphotMagnitudes.c (modified) (4 diffs)
-
src/psphotMakeGrowthCurve.c (modified) (2 diffs)
-
src/psphotMergeSources.c (modified) (1 diff)
-
src/psphotModelTest.c (modified) (1 diff)
-
src/psphotOutput.c (modified) (2 diffs)
-
src/psphotPetrosianStats.c (modified) (3 diffs)
-
src/psphotRadialApertures.c (modified) (2 diffs)
-
src/psphotRadiusChecks.c (modified) (2 diffs)
-
src/psphotReadout.c (modified) (3 diffs)
-
src/psphotReplaceUnfit.c (modified) (1 diff)
-
src/psphotRoughClass.c (modified) (1 diff)
-
src/psphotSetThreads.c (modified) (1 diff)
-
src/psphotSourceFits.c (modified) (7 diffs)
-
src/psphotSourceSize.c (modified) (2 diffs)
-
src/psphotSourceStats.c (modified) (16 diffs)
-
src/psphotVisual.c (modified) (2 diffs)
-
test/tap_psphot_stackphot.pro (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psphot
- Property svn:mergeinfo changed
/branches/eam_branches/ipp-20110404/psphot (added) merged: 31313-31314,31328,31337,31362,31364,31381,31384,31437,31444
- Property svn:mergeinfo changed
-
trunk/psphot/src/Makefile.am
r31154 r31452 167 167 psphotSourcePlots.c \ 168 168 psphotRadialPlot.c \ 169 psphotKronMasked.c \ 169 170 psphotDeblendSatstars.c \ 170 171 psphotMosaicSubimage.c \ -
trunk/psphot/src/psphot.h
r31154 r31452 149 149 bool psphotPSFstats (pmReadout *readout, pmPSF *psf); 150 150 bool psphotMomentsStats (pmReadout *readout, psArray *sources); 151 152 bool psphotKronMasked (pmConfig *config, const pmFPAview *view, const char *filerule); 153 bool psphotKronMaskedReadout(pmConfig *config, psMetadata *recipe, const pmFPAview *view, pmReadout *readout, psArray *sources, pmPSF *psf); 151 154 152 155 // in psphotGuessModel.c … … 310 313 311 314 bool psphotMakeFluxScale (psImage *image, psMetadata *recipe, pmPSF *psf); 312 bool psphotMakeGrowthCurve (pmReadout *readout, psMetadata *recipe, pmPSF *psf );315 bool psphotMakeGrowthCurve (pmReadout *readout, psMetadata *recipe, pmPSF *psf, psArray *sources); 313 316 bool psphotDumpPSFStars (pmReadout *readout, pmPSFtry *try, float radius, psImageMaskType maskVal, psImageMaskType markVal); 314 317 -
trunk/psphot/src/psphotApResid.c
r31154 r31452 1 1 # include "psphotInternal.h" 2 //# define DEBUG2 # define DEBUG 3 3 4 4 # define SKIPSTAR(MSG) { psTrace ("psphot", 3, "invalid : %s", MSG); continue; } … … 206 206 207 207 // XXX make this user-configurable? 208 if (source-> errMag> 0.01) continue;208 if (source->psfMagErr > 0.01) continue; 209 209 210 210 // aperture residual for this source … … 222 222 source->peak->xf, source->peak->yf, 223 223 source->modelPSF->params->data.F32[PM_PAR_XPOS], source->modelPSF->params->data.F32[PM_PAR_YPOS], 224 source->psfMag, source->apMag, source-> errMag,224 source->psfMag, source->apMag, source->psfMagErr, 225 225 source->modelPSF->params->data.F32[PM_PAR_I0], 226 226 source->modelPSF->params->data.F32[PM_PAR_SXX], source->modelPSF->params->data.F32[PM_PAR_SXY], source->modelPSF->params->data.F32[PM_PAR_SYY], … … 228 228 # endif 229 229 if (!isfinite(source->psfMag)) psAbort ("nan in psfMag"); 230 if (!isfinite(source-> errMag)) psAbort ("nan in errMag");230 if (!isfinite(source->psfMagErr)) psAbort ("nan in psfMagErr"); 231 231 if (!isfinite(source->apMag)) psAbort ("nan in apMag"); 232 232 if (!isfinite(model->params->data.F32[PM_PAR_XPOS])) psAbort ("nan in xPos"); … … 234 234 235 235 psVectorAppend (mag, source->psfMag); 236 psVectorAppend (dMag,source-> errMag);236 psVectorAppend (dMag,source->psfMagErr); 237 237 psVectorAppend (apResid, dap); 238 238 psVectorAppend (xPos, model->params->data.F32[PM_PAR_XPOS]); … … 328 328 psMetadataAddF32 (readout->analysis, PS_LIST_TAIL, "DAPMIFIT", PS_META_REPLACE, "ap residual scatter", psf->dApResid); 329 329 psMetadataAddS32 (readout->analysis, PS_LIST_TAIL, "NAPMIFIT", PS_META_REPLACE, "number of apresid stars", psf->nApResid); 330 psMetadataAddF32 (readout->analysis, PS_LIST_TAIL, "APLOSS", PS_META_REPLACE, "aperture loss (mag)", psf->growth ? psf->growth->apLoss : NAN); 330 331 // curve-of-growth offset 332 if (psf->growth) { 333 float gaussSigma = psMetadataLookupF32(&status, readout->analysis, "MOMENTS_GAUSS_SIGMA"); 334 if (!status) { 335 gaussSigma = psMetadataLookupF32(&status, recipe, "MOMENTS_GAUSS_SIGMA"); 336 } 337 float apScale = psMetadataLookupF32(&status, recipe, "PSF_APERTURE_SCALE"); 338 float PSF_APERTURE = (int)(apScale*gaussSigma); 339 340 float offset = pmGrowthCurveCorrect (psf->growth, PSF_APERTURE); 341 psMetadataAddF32 (readout->analysis, PS_LIST_TAIL, "APLOSS", PS_META_REPLACE, "aperture loss (mag)", psf->growth->apLoss); 342 psMetadataAddF32 (readout->analysis, PS_LIST_TAIL, "APREFOFF", PS_META_REPLACE, "offset to ref aperture", offset); 343 } else { 344 psMetadataAddF32 (readout->analysis, PS_LIST_TAIL, "APLOSS", PS_META_REPLACE, "aperture loss (mag)", NAN); 345 psMetadataAddF32 (readout->analysis, PS_LIST_TAIL, "APREFOFF", PS_META_REPLACE, "offset to ref aperture", NAN); 346 } 331 347 332 348 psLogMsg ("psphot.apresid", PS_LOG_DETAIL, "aperture residual: %f +/- %f\n", psf->ApResid, psf->dApResid); -
trunk/psphot/src/psphotBlendFit.c
r31154 r31452 242 242 if (source->mode & PM_SOURCE_MODE_PAIR) continue; 243 243 244 // do not include MOMENTS_FAILURES in the fit 245 if (source->mode & PM_SOURCE_MODE_MOMENTS_FAILURE) continue; 246 244 247 // limit selection to some SN limit 245 248 if (sqrt(source->peak->detValue) < FIT_SN_LIM) continue; … … 280 283 if (source->mode & PM_SOURCE_MODE_EXT_LIMIT) { 281 284 if (psphotFitBlob (readout, source, newSources, psf, fitOptions, maskVal, markVal)) { 282 source->type = PM_SOURCE_TYPE_EXTENDED;283 285 psTrace ("psphot", 5, "source at %7.1f, %7.1f is ext", source->peak->xf, source->peak->yf); 284 286 Next ++; 285 source->mode |= PM_SOURCE_MODE_NONLINEAR_FIT;286 287 continue; 287 288 } … … 291 292 psTrace ("psphot", 5, "source at %7.1f, %7.1f is psf", source->peak->xf, source->peak->yf); 292 293 Npsf ++; 293 source->mode |= PM_SOURCE_MODE_NONLINEAR_FIT;294 294 continue; 295 295 } -
trunk/psphot/src/psphotChoosePSF.c
r31154 r31452 350 350 351 351 // build curve-of-growth vector for this psf 352 if (!psphotMakeGrowthCurve (readout, recipe, try->psf )) {352 if (!psphotMakeGrowthCurve (readout, recipe, try->psf, try->sources)) { 353 353 psError(PSPHOT_ERR_PSF, false, "Unable to construct flux scale for PSF"); 354 354 psFree (models); -
trunk/psphot/src/psphotEfficiency.c
r30560 r31452 400 400 source->type = PM_SOURCE_TYPE_STAR; 401 401 402 source->modelPSF->fitRadius = sourceRadius; 403 source->apRadius = sourceRadius; 404 402 405 numFound++; 403 406 psArrayAdd(sources, sources->n, source); … … 468 471 source->modelPSF->params->data.F32[PM_PAR_XPOS], 469 472 source->modelPSF->params->data.F32[PM_PAR_YPOS], 470 magRef, source->psfMag, source-> errMag);473 magRef, source->psfMag, source->psfMagErr); 471 474 #endif 472 475 magDiff->data.F32[j] = source->psfMag - magRef; 473 magErr->data.F32[j] = source-> errMag;476 magErr->data.F32[j] = source->psfMagErr; 474 477 } 475 478 magDiff->n = sources->n; -
trunk/psphot/src/psphotExtendedSourceFits.c
r31154 r31452 333 333 // this uses the footprint to judge both radius and aperture? 334 334 // XXX save the psf-based moments for output 335 if (!pmSourceMoments (source, radius, 0.0, 0.0, maskVal)) {335 if (!pmSourceMoments (source, radius, 0.0, 0.0, 0.0, maskVal)) { 336 336 fprintf (stderr, "skipping (2) %f, %f\n", source->peak->xf, source->peak->yf); 337 337 // subtract the best fit from the object, leave local sky … … 379 379 assert (status); 380 380 381 // fprintf (stderr, "xfit: %f, %f : %f\n", source->peak->xf, source->peak->yf, source->peak->SN);382 383 381 // limit selection to some SN limit 384 assert (source->peak); // how can a source not have a peak?382 // assert (source->peak); // how can a source not have a peak? 385 383 if (sqrt(source->peak->detValue) < SNlim) { 386 384 Nfaint ++; -
trunk/psphot/src/psphotFitSourcesLinear.c
r31154 r31452 137 137 if (source->mode & PM_SOURCE_MODE_CR_LIMIT) continue; 138 138 139 // do not include MOMENTS_FAILURES in the fit 140 if (source->mode & PM_SOURCE_MODE_MOMENTS_FAILURE) continue; 141 139 142 // XXX count saturated stars 140 143 if (source->mode & PM_SOURCE_MODE_SATSTAR) { … … 164 167 165 168 // check the integral of the model : is it large enough? 169 // apply mask? 166 170 float modelSum = 0.0; 171 float maskedSum = 0.0; 167 172 for (int iy = 0; iy < source->modelFlux->numRows; iy++) { 168 173 for (int ix = 0; ix < source->modelFlux->numCols; ix++) { 169 174 modelSum += source->modelFlux->data.F32[iy][ix]; 175 if (source->maskObj->data.PS_TYPE_IMAGE_MASK_DATA[iy][ix] & maskVal) continue; 176 maskedSum += source->modelFlux->data.F32[iy][ix]; 170 177 } 171 178 } 172 179 if (modelSum < 0.5) continue; // skip sources with no model constraint (somewhat arbitrary limit) 173 // if (modelSum < 0.01) continue; // skip sources with no model constraint (somewhat arbitrary limit)174 180 if (modelSum < 0.8) { 175 fprintf (stderr, "low-sig model @ %f, %f (%f sum, %f peak)\n",176 source->peak->xf, source->peak->yf, m odelSum, source->peak->rawFlux);181 fprintf (stderr, "low-sig model @ %f, %f (%f masked sum, %f sum, %f peak)\n", 182 source->peak->xf, source->peak->yf, maskedSum, modelSum, source->peak->rawFlux); 177 183 } 178 179 pmModel *model = pmSourceGetModel (NULL, source); 184 if (maskedSum < 0.5) { 185 fprintf (stderr, "worrying model @ %f, %f (%f masked sum, %f sum, %f peak)\n", 186 source->peak->xf, source->peak->yf, maskedSum, modelSum, source->peak->rawFlux); 187 } 188 189 bool isPSF = false; 190 pmModel *model = pmSourceGetModel (&isPSF, source); 180 191 181 192 psImageMaskPixels (source->maskObj, "AND", PS_NOT_IMAGE_MASK(markVal)); 182 193 psImageKeepCircle (source->maskObj, source->peak->x, source->peak->y, model->fitRadius, "OR", markVal); 183 194 184 source->mode |= PM_SOURCE_MODE_LINEAR_FIT; 195 // we call this function multiple times. for the first time, we have only PSF models for all objects 196 // the second time has extended sources. If we ever fit the PSF model, we should raise this bit 197 source->mode |= PM_SOURCE_MODE_LINEAR_FIT; 198 if (isPSF) { 199 source->mode |= PM_SOURCE_MODE_PSFMODEL; 200 } 201 185 202 psArrayAdd (fitSources, 100, source); 186 203 } … … 260 277 } 261 278 } 279 280 # if (0) 281 static int npass = 0; 282 char name[128]; 283 FILE *f1 = NULL; 284 int fd = -1; 285 286 snprintf (name, 128, "sparse.Aij.%02d.dat", npass); 287 f1 = fopen (name, "w"); 288 psAssert (f1, "failed to open file\n"); 289 fd = fileno (f1); 290 p_psVectorPrint (fd, sparse->Aij, "Aij"); 291 fclose (f1); 292 293 snprintf (name, 128, "sparse.Bfj.%02d.dat", npass); 294 f1 = fopen (name, "w"); 295 psAssert (f1, "failed to open file\n"); 296 fd = fileno (f1); 297 p_psVectorPrint (fd, sparse->Bfj, "Bfj"); 298 fclose (f1); 299 300 snprintf (name, 128, "sparse.Qii.%02d.dat", npass); 301 f1 = fopen (name, "w"); 302 psAssert (f1, "failed to open file\n"); 303 fd = fileno (f1); 304 p_psVectorPrint (fd, sparse->Qii, "Qii"); 305 fclose (f1); 306 npass ++; 307 # endif 262 308 263 309 psSparseResort (sparse); -
trunk/psphot/src/psphotFitSourcesLinearStack.c
r31154 r31452 69 69 if (!pmSourceCacheModel (source, maskVal)) continue; 70 70 } 71 72 // check the integral of the model : is it large enough? 73 float modelSum = 0.0; 74 for (int iy = 0; iy < source->modelFlux->numRows; iy++) { 75 for (int ix = 0; ix < source->modelFlux->numCols; ix++) { 76 modelSum += source->modelFlux->data.F32[iy][ix]; 77 } 78 } 79 if (modelSum < 0.5) continue; // skip sources with no model constraint (somewhat arbitrary limit) 80 if (modelSum < 0.8) { 81 fprintf (stderr, "low-sig model @ %f, %f (%f sum, %f peak)\n", 82 source->peak->xf, source->peak->yf, modelSum, source->peak->rawFlux); 83 } 71 84 72 85 source->mode |= PM_SOURCE_MODE_LINEAR_FIT; -
trunk/psphot/src/psphotGuessModels.c
r31154 r31452 160 160 pmSource *source = sources->data[i]; 161 161 162 if (source->mode & PM_SOURCE_MODE_MOMENTS_FAILURE) {163 fprintf (stderr, "moment failure\n");164 }165 166 162 // this is used to mark sources for which the model is measured. We check later that 167 163 // all are used. … … 169 165 170 166 // skip non-astronomical objects (very likely defects) 167 if (source->mode & PM_SOURCE_MODE_MOMENTS_FAILURE) continue; 171 168 if (source->type == PM_SOURCE_TYPE_DEFECT) continue; 172 169 if (source->type == PM_SOURCE_TYPE_SATURATED) continue; … … 196 193 } 197 194 195 # if (0) 198 196 if (source->mode & PM_SOURCE_MODE_SATSTAR) { 199 197 fprintf (stderr, "satstar: %f,%f vs %f,%f : %c\n", … … 202 200 (useMoments ? 'T' : 'F')); 203 201 } 202 # endif 204 203 205 204 // set PSF parameters for this model (apply 2D shape model to coordinates Xo, Yo) -
trunk/psphot/src/psphotLoadSRCTEXT.c
r31154 r31452 52 52 53 53 // NOTE: most of these values are irrelevant for loaded source positions 54 source->seq = 0;54 source->seq = source->id; 55 55 PAR[PM_PAR_XPOS] = X; 56 56 PAR[PM_PAR_YPOS] = Y; … … 67 67 68 68 source->psfMag = 0.0; 69 source-> errMag= 0.0;69 source->psfMagErr = 0.0; 70 70 source->apMag = 0.0; 71 71 -
trunk/psphot/src/psphotMagnitudes.c
r31154 r31452 167 167 pmSource *source = (pmSource *) sources->data[i]; 168 168 169 bool saveTest = false; 170 psImage *testImage = NULL; 171 # if (0) 172 if ((fabs(source->peak->xf-3518) < 5) && (fabs(source->peak->yf-3178) < 5)) { 173 saveTest = true; 174 psRegion subregion = psRegionSet (source->peak->xf - 200, source->peak->xf + 200, source->peak->yf - 200, source->peak->yf + 200); 175 testImage = psImageSubset ((psImage *) source->pixels->parent, subregion); 176 } 177 # endif 178 179 if (saveTest) { 180 psphotSaveImage(NULL, testImage, "test.image.1.fits"); 181 } 182 169 183 // replace object in image 170 184 if (source->tmpFlags & PM_SOURCE_TMPF_SUBTRACTED) { … … 172 186 } 173 187 188 if (saveTest) { 189 psphotSaveImage(NULL, testImage, "test.image.2.fits"); 190 } 191 192 float xPos = source->peak->xf; 193 float yPos = source->peak->yf; 194 195 pmModel *model = source->modelPSF; 196 if (model) { 197 xPos = model->params->data.F32[PM_PAR_XPOS]; 198 yPos = model->params->data.F32[PM_PAR_YPOS]; 199 } else { 200 bool useMoments = pmSourcePositionUseMoments(source); 201 if (useMoments) { 202 xPos = source->moments->Mx; 203 yPos = source->moments->My; 204 } 205 } 206 174 207 // clear the mask bit and set the circular mask pixels 175 208 psImageMaskPixels (source->maskObj, "AND", PS_NOT_IMAGE_MASK(markVal)); 176 psImageKeepCircle (source->maskObj, source->peak->x, source->peak->y, source->apRadius, "OR", markVal);209 psImageKeepCircle (source->maskObj, xPos, yPos, source->apRadius, "OR", markVal); 177 210 178 211 status = pmSourceMagnitudes (source, psf, photMode, maskVal, markVal, source->apRadius); 179 if (status && isfinite(source->apMag)) Nap ++; 212 if (status && isfinite(source->apFlux)) { 213 Nap ++; 214 } else { 215 fprintf (stderr, "failed to measure mag for source @ %f,%f\n", source->peak->xf, source->peak->yf); 216 } 180 217 181 218 // clear the mask bit … … 185 222 pmSourceSub (source, PM_MODEL_OP_FULL, maskVal); 186 223 224 if (saveTest) { 225 psphotSaveImage(NULL, testImage, "test.image.3.fits"); 226 } 227 187 228 if (backModel) { 188 229 psAssert (binning, "if backModel is defined, so should binning be"); 189 source->sky = psImageUnbinPixel( source->peak->x, source->peak->y, backModel->image, binning);230 source->sky = psImageUnbinPixel(xPos, yPos, backModel->image, binning); 190 231 if (isnan(source->sky) && false) { 191 232 psLogMsg ("psphot.magnitudes", PS_LOG_DETAIL, "error setting pmSource.sky"); … … 197 238 if (backStdev) { 198 239 psAssert (binning, "if backStdev is defined, so should binning be"); 199 source->skyErr = psImageUnbinPixel( source->peak->x, source->peak->y, backStdev->image, binning);240 source->skyErr = psImageUnbinPixel(xPos, yPos, backStdev->image, binning); 200 241 if (isnan(source->skyErr) && false) { 201 242 psLogMsg ("psphot.magnitudes", PS_LOG_DETAIL, "error setting pmSource.skyErr"); -
trunk/psphot/src/psphotMakeGrowthCurve.c
r31154 r31452 1 1 # include "psphotInternal.h" 2 2 3 bool psphotMakeGrowthCurve (pmReadout *readout, psMetadata *recipe, pmPSF *psf ) {3 bool psphotMakeGrowthCurve (pmReadout *readout, psMetadata *recipe, pmPSF *psf, psArray *sources) { 4 4 5 5 bool status; … … 22 22 23 23 // measure the aperture loss as a function of radius for PSF 24 bool IGNORE_GROWTH = psMetadataLookupBool (&status, recipe, "IGNORE_GROWTH");25 24 float REF_RADIUS = psMetadataLookupF32 (&status, recipe, "PSF_REF_RADIUS"); 26 25 float PSF_FIT_PAD = psMetadataLookupF32 (&status, recipe, "PSF_FIT_PADDING"); 26 27 float gaussSigma = psMetadataLookupF32(&status, readout->analysis, "MOMENTS_GAUSS_SIGMA"); 28 if (!status) { 29 gaussSigma = psMetadataLookupF32(&status, recipe, "MOMENTS_GAUSS_SIGMA"); 30 } 31 float apScale = psMetadataLookupF32(&status, recipe, "PSF_APERTURE_SCALE"); 32 float PSF_APERTURE = (int)(apScale*gaussSigma); 27 33 28 34 psf->growth = pmGrowthCurveAlloc (PSF_FIT_PAD, 100.0, REF_RADIUS); 29 35 30 if (!pmGrowthCurveGenerate (readout, psf, IGNORE_GROWTH, maskVal, markVal)) { 31 psError(PSPHOT_ERR_APERTURE, false, "Fitting aperture corrections"); 32 psFree(psf->growth); psf->growth = NULL; 33 return false; 36 bool GROWTH_FROM_SOURCES = psMetadataLookupBool (&status, recipe, "GROWTH_FROM_SOURCES"); 37 if (!status) GROWTH_FROM_SOURCES = false; 38 39 if (GROWTH_FROM_SOURCES) { 40 bool INTERPOLATE_AP = psMetadataLookupBool (&status, recipe, "INTERPOLATE_AP"); 41 if (!pmGrowthCurveGenerateFromSources (readout, psf, sources, INTERPOLATE_AP, maskVal, markVal)) { 42 psError(PSPHOT_ERR_APERTURE, false, "Fitting aperture corrections"); 43 psFree(psf->growth); psf->growth = NULL; 44 return false; 45 } 46 47 } else { 48 bool IGNORE_GROWTH = psMetadataLookupBool (&status, recipe, "IGNORE_GROWTH"); 49 if (!pmGrowthCurveGenerate (readout, psf, IGNORE_GROWTH, maskVal, markVal)) { 50 psError(PSPHOT_ERR_APERTURE, false, "Fitting aperture corrections"); 51 psFree(psf->growth); psf->growth = NULL; 52 return false; 53 } 34 54 } 35 55 36 56 psLogMsg ("psphot", PS_LOG_MINUTIA, "built growth curve: %f sec\n", psTimerMark ("psphot.growth")); 37 57 58 float offset = pmGrowthCurveCorrect (psf->growth, PSF_APERTURE); 59 psLogMsg ("psphot", PS_LOG_DETAIL, "correction from %f to %f: %f mags\n", PSF_APERTURE, REF_RADIUS, offset); 60 38 61 return true; 39 62 } -
trunk/psphot/src/psphotMergeSources.c
r31154 r31452 137 137 pmSource *source = extSourcesTXT->data[i]; 138 138 source->mode |= PM_SOURCE_MODE_EXTERNAL; 139 140 // the supplied peak flux needs to be re-normalized 141 source->peak->rawFlux = 1.0; 142 source->peak->smoothFlux = 1.0; 143 source->peak->detValue = 1.0; 139 144 140 145 // drop the loaded source modelPSF -
trunk/psphot/src/psphotModelTest.c
r29548 r31452 226 226 // measure the source mags 227 227 pmSourcePhotometryModel (&fitMag, model); 228 pmSourcePhotometryAper ( &obsMag, NULL, NULL, model, source->pixels, source->variance, source->maskObj, maskVal);228 pmSourcePhotometryAper (NULL, &obsMag, NULL, NULL, model, source->pixels, source->variance, source->maskObj, maskVal); 229 229 fprintf (stderr, "ap: %f, fit: %f, apmifit: %f, nIter: %d\n", obsMag, fitMag, obsMag - fitMag, model->nIter); 230 230 -
trunk/psphot/src/psphotOutput.c
r31154 r31452 75 75 source->peak->xf, source->peak->yf, 76 76 model->params->data.F32[PM_PAR_XPOS], model->params->data.F32[PM_PAR_YPOS], 77 source->psfMag, source->apMag, source-> errMag,77 source->psfMag, source->apMag, source->psfMagErr, 78 78 model->params->data.F32[PM_PAR_I0], 79 79 model->params->data.F32[PM_PAR_SXX], model->params->data.F32[PM_PAR_SXY], model->params->data.F32[PM_PAR_SYY], … … 251 251 psMetadataItemSupplement (&status, header, analysis, "NPSFSTAR"); 252 252 psMetadataItemSupplement (&status, header, analysis, "APLOSS"); 253 psMetadataItemSupplement (&status, header, analysis, "APREFOFF"); 253 254 254 255 psMetadataItemSupplement (&status, header, analysis, "FWHM_MAJ"); -
trunk/psphot/src/psphotPetrosianStats.c
r31154 r31452 163 163 if (refRadius->data.F32[i] > apRadius) { 164 164 if (i == 0) { 165 psWarning ("does this case make any sense? (refRadius[0] > apRadius)");165 psWarning ("does this case make any sense? (refRadius[0] %f > apRadius %f)", refRadius->data.F32[i], apRadius); 166 166 continue; 167 167 } else { … … 188 188 if (!found50 && (fluxSum->data.F32[i] > flux50)) { 189 189 if (i == 0) { 190 psWarning ("does this case make any sense? (fluxSum[0] > flux50)");190 psWarning ("does this case make any sense? (fluxSum[0] %f > flux50 %f)", fluxSum->data.F32[i], flux50); 191 191 continue; 192 192 } else { … … 198 198 if (!found90 && (fluxSum->data.F32[i] > flux90)) { 199 199 if (i == 0) { 200 psWarning ("does this case make any sense? (fluxSum[0] > flux90)");200 psWarning ("does this case make any sense? (fluxSum[0] %f > flux90 %f)", fluxSum->data.F32[i], flux90); 201 201 continue; 202 202 } else { -
trunk/psphot/src/psphotRadialApertures.c
r31154 r31452 95 95 if (source->type == PM_SOURCE_TYPE_SATURATED) continue; 96 96 if (source->mode & PM_SOURCE_MODE_DEFECT) continue; 97 if (source->mode & PM_SOURCE_MODE_SATSTAR) continue; 97 98 // XXX measure radial apertures even for saturated stars 99 // if (source->mode & PM_SOURCE_MODE_SATSTAR) continue; 98 100 99 101 // limit selection to some SN limit … … 257 259 float SBstdv = sqrt((fluxStd->data.F32[i] / nPix) - PS_SQR(SBmean)); 258 260 261 // XXX report the total flux or the mask-corrected flux? 259 262 // flux->data.F32[i] = SBmean * Area; 263 // fluxErr->data.F32[i] = sqrt(fluxErr->data.F32[i]) * Area / nPix; 264 265 fluxErr->data.F32[i] = sqrt(fluxErr->data.F32[i]); 260 266 fluxStd->data.F32[i] = SBstdv * Area; 261 fluxErr->data.F32[i] = sqrt(fluxErr->data.F32[i]) * Area / nPix; 262 263 // fill->data.F32[i] /= Area; 267 fill->data.F32[i] /= Area; 268 264 269 psTrace ("psphot", 5, "radial bins: %3d %5.1f : %8.1f +/- %7.2f : %8.1f +/- %8.1f : %4.2f %6.1f\n", 265 270 i, aperRadii->data.F32[i], flux->data.F32[i], fluxErr->data.F32[i], SBmean, SBstdv, fill->data.F32[i], Area); -
trunk/psphot/src/psphotRadiusChecks.c
r29936 r31452 184 184 bool psphotSetRadiusModel (pmModel *model, pmReadout *readout, pmSource *source, psImageMaskType markVal, bool deep) { 185 185 186 psF32 *PAR = model->params->data.F32; 187 188 pmMoments *moments = source->moments; 189 if (moments == NULL) return false; 186 pmPeak *peak = source->peak; 190 187 191 188 // set the fit radius based on the object flux limit and the model … … 199 196 200 197 // redefine the pixels if needed 201 pmSourceRedefinePixels (source, readout, PAR[PM_PAR_XPOS], PAR[PM_PAR_YPOS], model->fitRadius);202 203 // set the mask to flag the excluded pixels 204 psImageKeepCircle (source->maskObj, PAR[PM_PAR_XPOS], PAR[PM_PAR_YPOS], model->fitRadius, "OR", markVal);205 return true; 206 } 198 pmSourceRedefinePixels (source, readout, peak->xf, peak->yf, model->fitRadius); 199 200 // set the mask to flag the excluded pixels 201 psImageKeepCircle (source->maskObj, peak->xf, peak->yf, model->fitRadius, "OR", markVal); 202 return true; 203 } -
trunk/psphot/src/psphotReadout.c
r31154 r31452 200 200 psphotDumpChisqs (config, view, filerule); 201 201 202 // XXX re-measure the kron mags with models subtracted 203 psphotKronMasked(config, view, filerule); 204 202 205 // identify CRs and extended sources (only unmeasured sources are measured) 203 206 psphotSourceSize (config, view, filerule, true); // pass 1 (detections->allSources) … … 309 312 pass1finish: 310 313 314 // XXX re-measure the kron mags with models subtracted 315 psphotKronMasked(config, view, filerule); 316 311 317 // measure source size for the remaining sources 312 318 // NOTE: applies only to NEW (unmeasured) sources … … 345 351 psErrorStackPrint(stderr, "Unable to replace sky"); 346 352 psErrorClear(); 347 348 /* psLogMsg("psphot", 3, "failed on psphotSkyReplace"); */ 349 /* return(psphotReadoutCleanup(config, view, filerule)); */ 350 } 353 } 354 351 355 // drop the references to the image pixels held by each source 352 356 if (!psphotSourceFreePixels (config, view, filerule)) { // pass 1 353 357 psErrorStackPrint(stderr, "Unable to free source pixels"); 354 358 psErrorClear(); 355 356 /* psLogMsg ("psphot", 3, "failed on psphotSourceFreePixels"); */ 357 /* return(psphotReadoutCleanup(config, view, filerule)); */ 358 } 359 } 360 359 361 // create the exported-metadata and free local data 360 362 return psphotReadoutCleanup(config, view, filerule); -
trunk/psphot/src/psphotReplaceUnfit.c
r31154 r31452 67 67 psAssert (maskVal, "missing mask value?"); 68 68 69 // bit-mask to mark pixels not used in analysis 70 psImageMaskType markVal = psMetadataLookupImageMask(&status, recipe, "MARK.PSPHOT"); 71 assert (markVal); 72 73 // maskVal is used to test for rejected pixels, and must include markVal 74 maskVal |= markVal; 75 69 76 for (int i = 0; i < sources->n; i++) { 70 77 source = sources->data[i]; -
trunk/psphot/src/psphotRoughClass.c
r31154 r31452 207 207 return false; 208 208 } 209 psLogMsg ("psphot", 3, "psf clump X, Y: %f, %f : DX, DY: %f, %f : nStars %d of %d\n", psfClump.X, psfClump.Y, psfClump.dX, psfClump.dY, psfClump.nStars, psfClump.nTotal); 209 if (!havePSF) { 210 psLogMsg ("psphot", 3, "psf clump X, Y: %f, %f : DX, DY: %f, %f : nStars %d of %d\n", psfClump.X, psfClump.Y, psfClump.dX, psfClump.dY, psfClump.nStars, psfClump.nTotal); 211 } else { 212 psLogMsg ("psphot", 3, "psf clump X, Y: %f, %f : DX, DY: %f, %f : loaded from metadata\n", psfClump.X, psfClump.Y, psfClump.dX, psfClump.dY); 213 } 210 214 211 215 // get basic parameters, or set defaults -
trunk/psphot/src/psphotSetThreads.c
r31154 r31452 25 25 psFree(task); 26 26 27 task = psThreadTaskAlloc("PSPHOT_SOURCE_STATS", 1 0);27 task = psThreadTaskAlloc("PSPHOT_SOURCE_STATS", 11); 28 28 task->function = &psphotSourceStats_Threaded; 29 29 psThreadTaskAdd(task); -
trunk/psphot/src/psphotSourceFits.c
r31154 r31452 146 146 pmSourceSub (source, PM_MODEL_OP_FULL, maskVal); 147 147 source->mode |= PM_SOURCE_MODE_BLEND_FIT; 148 source->mode |= PM_SOURCE_MODE_NONLINEAR_FIT; 148 149 return true; 149 150 } … … 186 187 187 188 // build cached model and subtract 189 source->mode |= PM_SOURCE_MODE_NONLINEAR_FIT; 188 190 pmSourceCacheModel (source, maskVal); 189 191 pmSourceSub (source, PM_MODEL_OP_FULL, maskVal); … … 233 235 // XXX save the psf-based moments for output 234 236 psfMoments = *source->moments; 235 if (!pmSourceMoments (source, radius, 0.0, 0.5, maskVal)) {237 if (!pmSourceMoments (source, radius, 0.0, 0.5, 0.0, maskVal)) { 236 238 *source->moments = psfMoments; 237 239 return false; … … 319 321 source->type = PM_SOURCE_TYPE_EXTENDED; 320 322 source->mode |= PM_SOURCE_MODE_EXTMODEL; 323 source->mode |= PM_SOURCE_MODE_NONLINEAR_FIT; 321 324 322 325 // build cached model and subtract … … 346 349 source->modelPSF = psMemIncrRefCounter (DBL->data[0]); 347 350 source->mode |= PM_SOURCE_MODE_PAIR; 351 source->mode |= PM_SOURCE_MODE_NONLINEAR_FIT; 348 352 349 353 // copy most data from the primary source (modelEXT, blends stay NULL) … … 489 493 // psTraceSetLevel("psLib.math.psMinimizeLMChi2", 5); 490 494 pmSourceFitModel (source, model, &options, maskVal); 491 // fprintf (stderr, "chisq: %f, nIter: %d, radius: %f, npix: %d\n \n", model->chisqNorm, model->nIter, model->fitRadius, model->nPix);495 // fprintf (stderr, "chisq: %f, nIter: %d, radius: %f, npix: %d\n", model->chisqNorm, model->nIter, model->fitRadius, model->nPix); 492 496 493 497 // psTraceSetLevel("psLib.math.psMinimizeLMChi2", 0); … … 554 558 // psTraceSetLevel("psLib.math.psMinimizeLMChi2", 5); 555 559 pmSourceFitPCM (pcm, source, &options, maskVal, markVal, psfSize); 556 // fprintf (stderr, "chisq: %f, nIter: %d, radius: %f, npix: %d\n \n", model->chisqNorm, model->nIter, model->fitRadius, model->nPix);560 // fprintf (stderr, "chisq: %f, nIter: %d, radius: %f, npix: %d\n", model->chisqNorm, model->nIter, model->fitRadius, model->nPix); 557 561 558 562 // psTraceSetLevel("psLib.math.psMinimizeLMChi2", 0); -
trunk/psphot/src/psphotSourceSize.c
r31154 r31452 213 213 214 214 psVectorAppend (ApOff, dMag); 215 psVectorAppend (ApErr, source-> errMag);215 psVectorAppend (ApErr, source->psfMagErr); 216 216 } 217 217 if (num == 0) { … … 520 520 // set nSigmaMAG to include both systematic and poisson error terms. we include a hard 521 521 // floor on the Ap Sys Err (to be a bit generous). XXX put the floor in the recipe... 522 float nSigmaMAG = (dMag - options->ApResid) / hypot(source-> errMag, hypot(options->ApSysErr, 0.02));522 float nSigmaMAG = (dMag - options->ApResid) / hypot(source->psfMagErr, hypot(options->ApSysErr, 0.02)); 523 523 source->extNsigma = nSigmaMAG; 524 524 -
trunk/psphot/src/psphotSourceStats.c
r31154 r31452 98 98 99 99 // generate the array of sources, define the associated pixel 100 bool firstPass = false; 100 101 if (!detections->newSources) { 101 102 detections->newSources = psArrayAllocEmpty (peaks->n); 103 firstPass = true; 102 104 } 103 105 sources = detections->newSources; … … 125 127 if (source->mode & PM_SOURCE_MODE_MOMENTS_FAILURE) { 126 128 fprintf (stderr, "moment failure\n"); 129 } 130 131 if (firstPass) { 132 source->mode2 |= PM_SOURCE_MODE2_PASS1_SRC; 127 133 } 128 134 … … 159 165 RADIUS = psMetadataLookupF32 (&status, recipe, "PSF_MOMENTS_RADIUS"); 160 166 } 167 float MIN_KRON_RADIUS = psMetadataLookupF32 (&status, readout->analysis, "MOMENTS_MIN_KRON"); 168 if (!status) { 169 MIN_KRON_RADIUS = 0.75*SIGMA; 170 } 161 171 162 172 // threaded measurement of the source magnitudes … … 186 196 PS_ARRAY_ADD_SCALAR(job->args, RADIUS, PS_TYPE_F32); 187 197 PS_ARRAY_ADD_SCALAR(job->args, SIGMA, PS_TYPE_F32); 198 PS_ARRAY_ADD_SCALAR(job->args, MIN_KRON_RADIUS, PS_TYPE_F32); 188 199 189 200 PS_ARRAY_ADD_SCALAR(job->args, maskVal, PS_TYPE_IMAGE_MASK); … … 215 226 } else { 216 227 psScalar *scalar = NULL; 217 scalar = job->args->data[ 7];228 scalar = job->args->data[8]; 218 229 Nmoments += scalar->data.S32; 219 scalar = job->args->data[ 8];230 scalar = job->args->data[9]; 220 231 Nfail += scalar->data.S32; 221 scalar = job->args->data[ 9];232 scalar = job->args->data[10]; 222 233 Nfaint += scalar->data.S32; 223 234 } … … 231 242 232 243 psphotVisualShowMoments (sources); 244 245 // clear the mark bits 246 // psImageMaskPixels (readout->mask, "AND", PS_NOT_IMAGE_MASK(markVal)); 233 247 234 248 if (detections->allSources) { … … 373 387 float RADIUS = PS_SCALAR_VALUE(job->args->data[3],F32); 374 388 float SIGMA = PS_SCALAR_VALUE(job->args->data[4],F32); 375 376 psImageMaskType maskVal = PS_SCALAR_VALUE(job->args->data[5],PS_TYPE_IMAGE_MASK_DATA); 377 psImageMaskType markVal = PS_SCALAR_VALUE(job->args->data[6],PS_TYPE_IMAGE_MASK_DATA); 389 float MIN_KRON_RADIUS = PS_SCALAR_VALUE(job->args->data[5],F32); 390 391 psImageMaskType maskVal = PS_SCALAR_VALUE(job->args->data[6],PS_TYPE_IMAGE_MASK_DATA); 392 psImageMaskType markVal = PS_SCALAR_VALUE(job->args->data[7],PS_TYPE_IMAGE_MASK_DATA); 378 393 379 394 // if no valid pixels, massive swing or very large Mrf, likely saturated source, … … 431 446 if (!(source->peak->type == PM_PEAK_SUSPECT_SATURATION)) { 432 447 // measure basic source moments (no S/N clipping on input pixels) 433 status = pmSourceMoments (source, RADIUS, SIGMA, 0.0, maskVal);448 status = pmSourceMoments (source, RADIUS, SIGMA, 0.0, MIN_KRON_RADIUS, maskVal); 434 449 } else { 435 450 // For saturated stars, choose a much larger box NOTE this is slightly sleazy, but … … 447 462 448 463 psTrace ("psphot", 4, "retrying moments for %d, %d\n", source->peak->x, source->peak->y); 449 status = pmSourceMoments (source, BIG_RADIUS, BIG_SIGMA, 0.0, maskVal);464 status = pmSourceMoments (source, BIG_RADIUS, BIG_SIGMA, 0.0, MIN_KRON_RADIUS, maskVal); 450 465 source->mode |= PM_SOURCE_MODE_BIG_RADIUS; 451 466 } … … 456 471 continue; 457 472 } 473 474 // XXX test of masking neighbors when measureing moments (does this fail?) 475 // psEllipseMoments moments = {source->moments->Mxx, source->moments->Myy, source->moments->Mxy}; 476 // psEllipseAxes axes = psEllipseMomentsToAxes(moments, 20.0); 477 // psImageMaskCircle (source->maskView, source->peak->x, source->peak->y, 3.0*axes.major, "OR", markVal); 478 458 479 Nmoments ++; 459 480 … … 492 513 float sigma[NSIGMA] = {1.0, 2.0, 3.0, 4.5, 6.0, 9.0, 12.0, 18.0}; 493 514 float Sout[NSIGMA]; 515 float Rmin[NSIGMA]; 494 516 int Nout[NSIGMA]; // number of stars found in clump : use this to control the number of regions measured by psphotRoughClass 495 517 … … 513 535 514 536 // measure basic source moments (no S/N clipping on input pixels) 515 status = pmSourceMoments (source, 4*sigma[i], sigma[i], 0.0, maskVal);537 status = pmSourceMoments (source, 4*sigma[i], sigma[i], 0.0, 0.0, maskVal); 516 538 } 517 539 … … 524 546 pmPSFClump psfClump = pmSourcePSFClump (NULL, NULL, sources, PSF_SN_LIM, PSF_CLUMP_GRID_SCALE, MOMENTS_SX_MAX, MOMENTS_SY_MAX, MOMENTS_AR_MAX); 525 547 psLogMsg ("psphot", 3, "radius %.1f, nStars: %d of %d in clump, nSigma: %5.2f, X, Y: %f, %f (%f, %f)\n", sigma[i], psfClump.nStars, psfClump.nTotal, psfClump.nSigma, psfClump.X, psfClump.Y, sqrt(psfClump.X) / sigma[i], sqrt(psfClump.Y) / sigma[i]); 548 549 Rmin[i] = pmSourceMinKronRadius(sources, PSF_SN_LIM); 526 550 527 551 #if 0 … … 549 573 // we are looking for sigma for which Sout = 0.65 (or some other value) 550 574 int Nstars = 0; 575 float minKronRadius = NAN; 551 576 float Sigma = NAN; 552 577 float minS = Sout[0]; … … 565 590 Sigma = sigma[i] + (0.65 - Sout[i])*(sigma[i+1] - sigma[i])/(Sout[i+1] - Sout[i]); 566 591 Nstars = 0.5*(Nout[i] + Nout[i+1]); 592 minKronRadius = Rmin[i] + (0.65 - Sout[i])*(Rmin[i+1] - Rmin[i])/(Sout[i+1] - Sout[i]); 567 593 } 568 594 psAssert (isfinite(Sigma), "did we miss a case?"); … … 575 601 psMetadataAddF32(analysis, PS_LIST_TAIL, "PSF_MOMENTS_RADIUS", PS_META_REPLACE, "moments limit", 4.0*Sigma); 576 602 psMetadataAddF32(analysis, PS_LIST_TAIL, "PSF_CLUMP_NSTARS", PS_META_REPLACE, "number of stars in clump", Nstars); 577 578 psLogMsg ("psphot", 3, "using window function with sigma = %f\n", Sigma); 603 psMetadataAddF32(analysis, PS_LIST_TAIL, "MOMENTS_MIN_KRON", PS_META_REPLACE, "minimum Kron Radius", minKronRadius); 604 605 psLogMsg ("psphot", 3, "using window function with sigma = %f (Min Kron Radius = %f, Nstars = %d)\n", Sigma, minKronRadius, Nstars); 579 606 return true; 580 607 } -
trunk/psphot/src/psphotVisual.c
r31154 r31452 1867 1867 continue; 1868 1868 } 1869 if (source-> errMag> 0.1) {1869 if (source->psfMagErr > 0.1) { 1870 1870 xLOW->data.F32[nLOW] = source->moments->Mxx; 1871 1871 yLOW->data.F32[nLOW] = source->moments->Myy; … … 2591 2591 x->data.F32[n] = source->psfMag; 2592 2592 y->data.F32[n] = dMag; 2593 dy->data.F32[n] = source-> errMag;2593 dy->data.F32[n] = source->psfMagErr; 2594 2594 graphdata.xmin = PS_MIN(graphdata.xmin, x->data.F32[n]); 2595 2595 graphdata.xmax = PS_MAX(graphdata.xmax, x->data.F32[n]); -
trunk/psphot/test/tap_psphot_stackphot.pro
r31154 r31452 1 1 #!/usr/bin/env mana 2 2 # -*-sh-*- 3 4 $KAPA = kapa -noX 3 5 4 6 # config for ppImage to generate chip, mask, weight
Note:
See TracChangeset
for help on using the changeset viewer.
