Changeset 27838 for branches/tap_branches/psphot/src/psphotEfficiency.c
- Timestamp:
- May 3, 2010, 8:41:49 AM (16 years ago)
- Location:
- branches/tap_branches
- Files:
-
- 4 edited
-
. (modified) (1 prop)
-
psphot (modified) (1 prop)
-
psphot/src (modified) (1 prop)
-
psphot/src/psphotEfficiency.c (modified) (15 diffs, 1 prop)
Legend:
- Unmodified
- Added
- Removed
-
branches/tap_branches
- Property svn:mergeinfo changed
-
branches/tap_branches/psphot
-
Property svn:mergeinfo
set to (toggle deleted branches)
/trunk/psphot merged eligible /branches/eam_branches/stackphot.20100406/psphot 27622-27655 /branches/pap_delete/psphot 27530-27595
-
Property svn:mergeinfo
set to (toggle deleted branches)
-
branches/tap_branches/psphot/src
- Property svn:ignore
-
old new 19 19 psphotMomentsStudy 20 20 psphotPetrosianStudy 21 psphotForced 22 psphotMakePSF 23 psphotStack
-
- Property svn:ignore
-
branches/tap_branches/psphot/src/psphotEfficiency.c
- Property svn:mergeinfo deleted
r25890 r27838 4 4 PM_MODEL_STATUS_BADARGS | PM_MODEL_STATUS_LIMITS) // Mask to apply to models 5 5 6 //#define TESTING 7 6 # define TESTING 0 8 7 9 8 // Calculate the limiting magnitude for an image … … 17 16 float *covarFactor,// Covariance factor 18 17 const pmReadout *ro, // Readout of interest 19 const pmPSF *psf,// Point-spread function18 pmPSF *psf, // Point-spread function 20 19 float thresh, // Threshold for source identification 21 20 float smoothSigma, // Gaussian smoothing sigma … … 33 32 34 33 psKernel *kernel = psImageSmoothKernel(smoothSigma, smoothNsigma); // Kernel used for smoothing 35 psKernel *newCovar = psImageCovarianceCalculate(kernel, ro->covariance); // Covariance matrix34 *covarFactor = psImageCovarianceCalculateFactor(kernel, ro->covariance); 36 35 psFree(kernel); 37 *covarFactor = psImageCovarianceFactor(newCovar); // Variance factor38 psFree(newCovar);39 36 40 37 psStats *stats = psStatsAlloc(PS_STAT_ROBUST_MEDIAN); // Statistics for variance … … 128 125 psFree(rng); 129 126 127 bool oldThreads = pmReadoutFakeThreads(true); // Old threading status 128 130 129 pmReadout *fakeRO = pmReadoutAlloc(NULL); // Fake readout 131 130 if (!pmReadoutFakeFromVectors(fakeRO, numCols, numRows, xAll, yAll, magAll, … … 142 141 psFree(yAll); 143 142 143 pmReadoutFakeThreads(oldThreads); 144 144 145 psBinaryOp(ro->image, ro->image, "+", fakeRO->image); 145 146 psFree(fakeRO); … … 148 149 } 149 150 151 bool psphotEfficiency (pmConfig *config, const pmFPAview *view) 152 { 153 bool status = true; 154 155 // select the appropriate recipe information 156 psMetadata *recipe = psMetadataLookupPtr (&status, config->recipes, PSPHOT_RECIPE); 157 psAssert (recipe, "missing recipe?"); 158 159 int num = psMetadataLookupS32 (&status, config->arguments, "PSPHOT.INPUT.NUM"); 160 psAssert (status, "programming error: must define PSPHOT.INPUT.NUM"); 161 162 // skip the chisq image (optionally?) 163 int chisqNum = psMetadataLookupS32 (&status, config->arguments, "PSPHOT.CHISQ.NUM"); 164 if (!status) chisqNum = -1; 165 166 // loop over the available readouts 167 for (int i = 0; i < num; i++) { 168 if (i == chisqNum) continue; // skip chisq image 169 if (!psphotEfficiencyReadout (config, view, "PSPHOT.INPUT", i, recipe)) { 170 psError (PSPHOT_ERR_CONFIG, false, "failed to measure detection efficiency for PSPHOT.INPUT entry %d", i); 171 return false; 172 } 173 } 174 return true; 175 } 150 176 151 177 // Determine detection efficiency 152 bool psphotEfficiency(pmConfig *config, pmReadout *readout, const pmFPAview *view, const pmPSF *psf, 153 psMetadata *recipe, const psArray *realSources) 178 bool psphotEfficiencyReadout(pmConfig *config, const pmFPAview *view, const char *filename, int index, psMetadata *recipe) 154 179 { 180 bool status = true; 181 182 psTimerStart("psphot.fake"); 183 184 // find the currently selected readout 185 pmFPAfile *file = pmFPAfileSelectSingle(config->files, filename, index); // File of interest 186 psAssert (file, "missing file?"); 187 188 pmReadout *readout = pmFPAviewThisReadout(view, file->fpa); 189 psAssert (readout, "missing readout?"); 190 191 pmDetections *detections = psMetadataLookupPtr (&status, readout->analysis, "PSPHOT.DETECTIONS"); 192 psAssert (detections, "missing detections?"); 193 194 psArray *realSources = detections->allSources; 195 psAssert (realSources, "missing sources?"); 196 197 // XXX do we need to skip this step if we do not have a psf? 198 pmPSF *psf = psMetadataLookupPtr (&status, readout->analysis, "PSPHOT.PSF"); 199 psAssert (psf, "missing psf?"); 200 155 201 PM_ASSERT_READOUT_NON_NULL(readout, false); 156 202 PM_ASSERT_READOUT_IMAGE(readout, false); 157 203 PS_ASSERT_PTR_NON_NULL(psf, false); 158 204 PS_ASSERT_METADATA_NON_NULL(recipe, false); 159 PS_ASSERT_ARRAY_NON_NULL(realSources, false);160 161 psTimerStart("psphot.fake");162 205 163 206 // Collect recipe information 164 float fwhmMajor = psMetadataLookupF32(NULL, recipe, "FWHM_MAJ"); // PSF size in x 165 float fwhmMinor = psMetadataLookupF32(NULL, recipe, "FWHM_MIN"); // PSF size in y 207 float smoothNsigma = psMetadataLookupF32(&status, recipe, "PEAKS_SMOOTH_NSIGMA"); // Smoothing limit 208 psAssert (status && isfinite(smoothNsigma), "Unable to find PEAKS_SMOOTH_NSIGMA in recipe (or invalid value)"); 209 210 float thresh = psMetadataLookupF32(&status, recipe, "PEAKS_NSIGMA_LIMIT_2"); 211 psAssert (status && isfinite(thresh), "Unable to find PEAKS_NSIGMA_LIMIT_2 in recipe (or invalid value)"); 212 213 psVector *magOffsets = psMetadataLookupVector(&status, recipe, "EFF.MAG"); // Magnitude offsets 214 psAssert (status, "Unable to find EFF.MAG F32 vector in recipe"); 215 psAssert (magOffsets->type.type == PS_TYPE_F32, "Unable to find EFF.MAG F32 vector in recipe"); 216 217 int numSources = psMetadataLookupS32(&status, recipe, "EFF.NUM"); // Number of sources for each bin 218 psAssert (status && (numSources > 0), "Unable to find EFF.NUM in recipe (or invalid value)"); 219 220 float minGauss = psMetadataLookupF32(&status, recipe, "PEAKS_MIN_GAUSS"); // Minimum valid fraction of kernel 221 psAssert (status && isfinite(minGauss), "PEAKS_MIN_GAUSS is not set in recipe (or invalid)"); 222 223 // find the PSF size information (why is this not part of the psf structure?) 224 float fwhmMajor = psMetadataLookupF32(NULL, readout->analysis, "FWHM_MAJ"); // PSF size in x 225 float fwhmMinor = psMetadataLookupF32(NULL, readout->analysis, "FWHM_MIN"); // PSF size in y 166 226 if (!isfinite(fwhmMajor) || !isfinite(fwhmMinor) || fwhmMajor == 0.0 || fwhmMinor == 0.0) { 167 psError(PSPHOT_ERR_CONFIG, false, "Unable to find FWHM_MAJ and FWHM_MIN in recipe"); 168 return false; 169 } 170 float smoothNsigma = psMetadataLookupF32(NULL, recipe, "PEAKS_SMOOTH_NSIGMA"); // Smoothing limit 171 if (!isfinite(smoothNsigma)) { 172 psError(PSPHOT_ERR_CONFIG, false, "Unable to find PEAKS_SMOOTH_NSIGMA in recipe"); 173 return false; 174 } 175 float thresh = psMetadataLookupF32(NULL, recipe, "PEAKS_NSIGMA_LIMIT_2"); 176 if (!isfinite(thresh)) { 177 psError(PSPHOT_ERR_CONFIG, false, "Unable to find PEAKS_NSIGMA_LIMIT_2 in recipe"); 178 return false; 179 } 180 psVector *magOffsets = psMetadataLookupVector(NULL, recipe, "EFF.MAG"); // Magnitude offsets 181 if (!magOffsets || magOffsets->type.type != PS_TYPE_F32) { 182 psError(PSPHOT_ERR_CONFIG, false, "Unable to find EFF.MAG F32 vector in recipe"); 183 return NULL; 184 } 185 int numSources = psMetadataLookupS32(NULL, recipe, "EFF.NUM"); // Number of sources for each bin 186 if (numSources == 0) { 187 psError(PSPHOT_ERR_CONFIG, false, "Unable to find EFF.NUM in recipe"); 188 return NULL; 189 } 190 float minGauss = psMetadataLookupF32(NULL, recipe, "PEAKS_MIN_GAUSS"); // Minimum valid fraction of kernel 191 if (!isfinite(minGauss)) { 192 psWarning("PEAKS_MIN_GAUSS is not set in recipe; using default value"); 193 minGauss = 0.5; 227 psError(PSPHOT_ERR_CONFIG, false, "Unable to find FWHM_MAJ and FWHM_MIN in readout->analysis"); 228 return false; 194 229 } 195 230 … … 202 237 // remove all sources, adding noise for subtracted sources 203 238 psphotRemoveAllSources(realSources, recipe); 204 // psphotAddNoise(readout, realSources, recipe); 205 206 207 #if defined(TESTING) && 0 239 240 #if TESTING 208 241 { 209 242 psRandom *rng = psRandomAlloc(PS_RANDOM_TAUS); … … 234 267 } 235 268 236 #if defTESTING269 #if TESTING 237 270 psphotSaveImage(NULL, readout->image, "orig_image.fits"); 238 271 psphotSaveImage(NULL, readout->variance, "orig_variance.fits"); … … 249 282 } 250 283 251 #if defTESTING284 #if TESTING 252 285 psphotSaveImage(NULL, readout->image, "fake_image.fits"); 253 286 psphotSaveImage(NULL, readout->variance, "fake_variance.fits"); … … 364 397 psFree(significance); 365 398 366 if (!psphotFitSourcesLinear (readout, fakeSourcesAll, recipe, psf, true)) {399 if (!psphotFitSourcesLinearReadout(recipe, readout, fakeSourcesAll, psf, true)) { 367 400 psError(PS_ERR_UNKNOWN, false, "Unable to perform linear fit on fake sources."); 368 401 psFree(fakeSources); … … 371 404 } 372 405 373 // Disable aperture corrections ; casting away const!406 // Disable aperture corrections (save current value) 374 407 pmTrend2D *apTrend = psf->ApTrend; // Aperture trend 375 ((pmPSF*)psf)->ApTrend = NULL;376 377 if (!psphotMagnitudes (config, readout, view, fakeSourcesAll, psf)) {408 psf->ApTrend = NULL; 409 410 if (!psphotMagnitudesReadout(config, recipe, view, readout, fakeSourcesAll, psf)) { 378 411 psError(PS_ERR_UNKNOWN, false, "Unable to measure magnitudes of fake sources."); 379 412 psFree(fakeSources); 380 413 psFree(count); 381 ((pmPSF*)psf)->ApTrend = apTrend; // Casting away const!414 psf->ApTrend = apTrend; // Casting away const! 382 415 return false; 383 416 } 384 417 psFree(fakeSourcesAll); 385 418 386 // Re -enable aperture corrections; casting away const!387 ((pmPSF*)psf)->ApTrend = apTrend;419 // Replace aperture corrections 420 psf->ApTrend = apTrend; 388 421 389 422 psVector *magDiffMean = psVectorAlloc(numBins, PS_TYPE_F32); // Mean difference in magnitude for each bin … … 399 432 psVectorInit(magMask, 0); 400 433 401 #if defTESTING434 #if TESTING 402 435 psString name = NULL; 403 436 psStringAppend(&name, "fake_%d.dat", i); … … 415 448 } 416 449 417 #if defTESTING450 #if TESTING 418 451 fprintf(file, "%f %f %f %f %f %f %f\n", source->peak->xf, source->peak->yf, 419 452 source->modelPSF->params->data.F32[PM_PAR_XPOS], … … 451 484 } 452 485 453 #if defTESTING486 #if TESTING 454 487 fclose(file); 455 488 #endif … … 476 509 psLogMsg("psphot", PS_LOG_INFO, "Detection efficiency: %lf sec\n", psTimerClear("psphot.fake")); 477 510 478 479 511 return true; 480 512 }
Note:
See TracChangeset
for help on using the changeset viewer.
