Changeset 25309
- Timestamp:
- Sep 9, 2009, 2:30:43 PM (17 years ago)
- File:
-
- 1 edited
-
branches/pap/psphot/src/psphotFake.c (modified) (12 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/pap/psphot/src/psphotFake.c
r25302 r25309 3 3 #define MODEL_MASK (PM_MODEL_STATUS_NONCONVERGE | PM_MODEL_STATUS_OFFIMAGE | \ 4 4 PM_MODEL_STATUS_BADARGS | PM_MODEL_STATUS_LIMITS) // Mask to apply to models 5 6 #define TESTING 5 7 6 8 … … 180 182 181 183 float smoothSigma = 0.5*(fwhmMajor + fwhmMinor) / (2.0*sqrtf(2.0*log(2.0))); // Gaussian smoothing sigma 184 int numCols = readout->image->numCols, numRows = readout->image->numRows; // Size of image 182 185 183 186 psImageMaskType maskVal = psMetadataLookupImageMask(NULL, recipe, "MASK.PSPHOT"); // Value to mask … … 186 189 psphotRemoveAllSources(realSources, recipe); 187 190 // psphotAddNoise(readout, realSources, recipe); 191 192 193 194 { 195 psRandom *rng = psRandomAlloc(PS_RANDOM_TAUS); 196 for (int y = 0; y < numRows; y++) { 197 for (int x = 0; x < numCols; x++) { 198 readout->image->data.F32[y][x] = psRandomGaussian(rng); 199 readout->variance->data.F32[y][x] = 1.0; 200 readout->mask->data.PS_TYPE_IMAGE_MASK_DATA[y][x] = 0; 201 } 202 } 203 psFree(readout->covariance); 204 readout->covariance = NULL; 205 psFree(rng); 206 } 207 208 209 188 210 189 211 float magLim; // Guess at limiting magnitude … … 193 215 return false; 194 216 } 217 218 #ifdef TESTING 219 psphotSaveImage(NULL, readout->image, "orig_image.fits"); 220 psphotSaveImage(NULL, readout->variance, "orig_variance.fits"); 221 psphotSaveImage(NULL, readout->mask, "orig_mask.fits"); 222 #endif 195 223 196 224 psImage *xFake = NULL, *yFake = NULL; // Coordinates of sources, each bin in a row … … 201 229 return false; 202 230 } 231 232 #ifdef TESTING 233 psphotSaveImage(NULL, readout->image, "fake_image.fits"); 234 psphotSaveImage(NULL, readout->variance, "fake_variance.fits"); 235 psphotSaveImage(NULL, readout->mask, "fake_mask.fits"); 236 #endif 203 237 204 238 // XXX Could speed this up significantly by only convolving the central pixels of each fake source … … 211 245 } 212 246 247 #ifdef TESTING 248 psphotSaveImage(NULL, readout->mask, "fake_sig.fits"); 249 #endif 250 213 251 thresh *= thresh; // Significance image is actually significance-squared 214 252 215 253 int numBins = magOffsets->n; // Number of bins 216 int numCols = readout->image->numCols, numRows = readout->image->numRows; // Size of image217 254 psVector *count = psVectorAlloc(numBins, PS_TYPE_S32); // Number of sources found in each bin 218 255 psArray *fakeSources = psArrayAllocEmpty(numSources * numBins); // Fake sources … … 221 258 for (int i = 0; i < numBins; i++) { 222 259 int num = 0; // Number found 260 223 261 for (int j = 0; j < numSources; j++) { 224 262 // Coordinates of interest … … 269 307 psVector *magErrMean = psVectorAlloc(numBins, PS_TYPE_F32); // Mean error in magnitude for each bin 270 308 psVector *magErrStdev = psVectorAlloc(numBins, PS_TYPE_F32); // Stdev of error in magnitude for each bin 309 psVector *magErrErrMean = psVectorAlloc(numBins, PS_TYPE_F32); // Mean error in magnitude for each bin 271 310 psVector *magErr = psVectorAlloc(numSources, PS_TYPE_F32); // Magnitude errors 311 psVector *magErrErr = psVectorAlloc(numSources, PS_TYPE_F32); // Error in magnitude error 272 312 psVector *magMask = psVectorAlloc(numSources, PS_TYPE_VECTOR_MASK); // Mask for magnitude errors 273 psStats *magStats = psStatsAlloc(PS_STAT_SAMPLE_MEAN | PS_STAT_SAMPLE_STDEV); // Statistics 313 psStats *magStats = psStatsAlloc(PS_STAT_SAMPLE_MEAN | PS_STAT_SAMPLE_STDEV | PS_STAT_ROBUST_MEDIAN | PS_STAT_ROBUST_STDEV); // Statistics 314 psVector *robustMedian = psVectorAlloc(numBins, PS_TYPE_F32); 315 psVector *robustStdev = psVectorAlloc(numBins, PS_TYPE_F32); 274 316 for (int i = 0, index = 0; i < numBins; i++) { 275 317 psStatsInit(magStats); 276 318 psVectorInit(magMask, 0); 277 319 320 psString name = NULL; 321 psStringAppend(&name, "fake_%d.dat", i); 322 FILE *file = fopen(name, "w"); 323 278 324 float magRef = magLim + magOffsets->data.F32[i]; // Reference magnitude 279 for (int j = 0; index < fakeEnd->data.S32[i]; j++, index++) { 325 int j; // Index 326 for (j = 0; index < fakeEnd->data.S32[i]; j++, index++) { 280 327 pmSource *source = fakeSources->data[index]; // Source of interest 281 328 if (!source || !isfinite(source->psfMag)) { … … 283 330 continue; 284 331 } 332 333 fprintf(file, "%f %f %f %f %f\n", source->peak->xf, source->peak->yf, 334 magRef, source->psfMag, source->errMag); 285 335 magErr->data.F32[j] = source->psfMag - magRef; 286 } 336 magErrErr->data.F32[j] = source->errMag; 337 } 338 magErr->n = j; 339 magMask->n = j; 287 340 if (!psVectorStats(magStats, magErr, NULL, magMask, 0xFF)) { 288 341 // Probably because we don't have enough sources … … 291 344 magErrMean->data.F32[i] = magStats->sampleMean; 292 345 magErrStdev->data.F32[i] = magStats->sampleStdev; 293 } 346 robustMedian->data.F32[i] = magStats->robustMedian; 347 robustStdev->data.F32[i] = magStats->robustStdev; 348 if (!psVectorStats(magStats, magErrErr, NULL, magMask, 0xFF)) { 349 // Probably because we don't have enough sources 350 psErrorClear(); 351 } 352 magErrErrMean->data.F32[i] = magStats->sampleMean; 353 fclose(file); 354 } 355 356 294 357 psFree(magStats); 295 358 psFree(magMask); … … 313 376 psMetadataAddVector(stats, PS_LIST_TAIL, "FAKE.RMS", PS_META_REPLACE, 314 377 "Stdev in magnitude differences", magErrStdev); 378 psMetadataAddVector(stats, PS_LIST_TAIL, "FAKE.RM", PS_META_REPLACE, 379 "Robust median magnitude differences", robustMedian); 380 psMetadataAddVector(stats, PS_LIST_TAIL, "FAKE.RS", PS_META_REPLACE, 381 "Robust stdev in magnitude differences", robustStdev); 382 psMetadataAddVector(stats, PS_LIST_TAIL, "FAKE.MEANERR", PS_META_REPLACE, 383 "Mean error in magnitude differences", magErrErrMean); 315 384 psMetadataConfigWrite(stats, "fake.stats"); 316 385 psFree(stats); … … 320 389 psFree(magErrStdev); 321 390 391 psFree(robustMedian); 392 psFree(robustStdev); 393 322 394 return true; 323 395 }
Note:
See TracChangeset
for help on using the changeset viewer.
