Changeset 33879 for trunk/psphot/src/psphotKronIterate.c
- Timestamp:
- May 16, 2012, 4:23:42 PM (14 years ago)
- File:
-
- 1 edited
-
trunk/psphot/src/psphotKronIterate.c (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psphot/src/psphotKronIterate.c
r33877 r33879 1 1 # include "psphotInternal.h" 2 3 #define NO_USE_SE_KR 14 #define NO_SAVE_IMAGES 15 2 6 3 bool psphotKronWindowSetSource(pmSource *source, psImage *kronWindow, bool useKronRadius, bool insert, bool oldWindow); … … 57 54 bool psphotVisualRangeImage (int kapaFD, psImage *inImage, const char *name, int channel, float min, float max); 58 55 59 bool pass1 = true;60 // This is defined in pmSource.c61 extern psString psphot_outroot;62 63 #ifdef USE_SE_KR64 static int nKR = 0;65 // input list indexed by list file's source->id66 static float kr_sextractor[10000];67 static int used[10000];68 69 int numMatched = 0;70 71 #define SE_KR_USED 0x80072 73 static void find_se_kr(pmSource *source) {74 int sid = source->id;75 if (isfinite(kr_sextractor[sid])) {76 source->moments->Mrf = kr_sextractor[sid] / 2.5;77 source->tmpFlags |= SE_KR_USED;78 numMatched++;79 }80 }81 82 static void getxy(pmSource *source, float *pX, float *pY) {83 float x, y;84 if (source->modelPSF) {85 psF32 *PAR = source->modelPSF->params->data.F32;86 x = PAR[PM_PAR_XPOS];87 y = PAR[PM_PAR_YPOS];88 } else if (pmSourcePositionUseMoments(source)) {89 x = source->moments->Mx;90 y = source->moments->My;91 } else {92 x = source->peak->x;93 y = source->peak->y;94 }95 *pX = x;96 *pY = y;97 }98 99 static void build_kr_list(psArray *sources) {100 // write list of source->id X Y to a file101 pid_t pid = getpid();102 char filename[40];103 sprintf(filename, "sources.%d.list", pid);104 FILE *out = fopen(filename, "w");105 for (int i=0; i < sources->n; i++) {106 pmSource *source = sources->data[i];107 float x, y;108 getxy(source, &x, &y);109 fprintf(out, "%6.3f %6.3f %5d\n", x, y, source->id);110 }111 fclose(out);112 // run gcompare on that file113 114 char matchedfilename[20];115 sprintf(matchedfilename, "sources.%d.matched", pid);116 char command[80];117 sprintf(command, "rungcompare %s %s", filename, matchedfilename);118 int rc = system(command);119 if (rc) {120 fprintf(stderr, "failed to read matched list %d %d\n", rc, rc >> 8);121 return;122 }123 124 unlink(filename);125 126 for (int i = 0; i < 10000; i++) {127 used[i] = -1;128 kr_sextractor[i] = NAN;129 }130 int sid;131 int ipp_idet;132 float kr;133 // read the results to build the kr_sextractor134 FILE *in = fopen(matchedfilename, "r");135 while (fscanf(in, "%d %f %d", &sid, &kr, &ipp_idet) > 0) {136 // take first match for each sid ...137 if (!isfinite(kr_sextractor[sid])) {138 // .. and for each ipp_idet Since the lists are sorted in139 // order of SN this makes it more likely to get the right match140 if (used[ipp_idet] == -1) {141 kr_sextractor[sid] = kr;142 used[ipp_idet] = sid;143 nKR++;144 } else {145 fprintf(stderr, "match for %d %d is already used for %d\n",146 sid, ipp_idet, used[ipp_idet]);147 }148 }149 }150 fclose(in);151 unlink(matchedfilename);152 }153 154 #endif // USE_SE_KR155 156 56 bool psphotKronIterateReadout(pmConfig *config, psMetadata *recipe, const pmFPAview *view, const char * filerule, pmReadout *readout, psArray *sources, pmPSF *psf, int index) { 157 57 … … 165 65 psTimerStart ("psphot.kron"); 166 66 167 #ifdef USE_SE_KR168 if (!pass1) {169 build_kr_list(sources);170 }171 #endif172 67 173 68 // determine the number of allowed threads … … 237 132 238 133 // start with the currently known moments (Mxx, Myy, Mxy) and generate a window image 239 #ifdef USE_SE_KR240 int previous = numMatched;241 #endif242 134 for (int i = 0; i < sources->n; i++) { 243 135 … … 247 139 // (this skips really bad sources (no peak, no moments, DEFECT) 248 140 psphotKronWindowSetSource (source, kronWindow, false, true, KRON_APPLY_WINDOW); 249 #ifdef USE_SE_KR 250 if (!pass1) { 251 find_se_kr(source); 252 } 253 #endif 254 } 255 #ifdef USE_SE_KR 256 if (!pass1) { 257 fprintf(stdout, "Matched %d sources previous %d\n", numMatched, previous); 258 } 259 #endif 141 } 260 142 261 143 // We measure the Kron Radius on a smoothed copy of the readout image … … 291 173 292 174 } 293 294 #ifdef SAVE_IMAGES295 psphot_outroot = psMetadataLookupStr(&status, config->arguments, "OUTPUT");296 {297 // Save the background subtracted image298 psString fn = NULL;299 psStringAppend(&fn, "%s.p%d.src.sub.fits", psphot_outroot, pass1 ? 1 : 2);300 psphotSaveImage(0, readout->image, fn);301 psFree(fn);302 fn = NULL;303 if (KRON_SMOOTH) {304 psStringAppend(&fn, "%s.p%d.src.sub.sm.fits", psphot_outroot, pass1 ? 1 : 2);305 psphotSaveImage(0, smoothedImage, fn);306 psFree(fn);307 }308 if (KRON_APPLY_WINDOW) {309 psStringAppend(&fn, "%s.p%d.window.fits", psphot_outroot, pass1 ? 1 : 2);310 psphotSaveImage(0, kronWindow, fn);311 psFree(fn);312 }313 }314 #endif315 175 316 176 // threaded measurement of the source magnitudes … … 377 237 psFree (kronWindow); 378 238 psFree (smoothedImage); 379 if (pass1) {380 pass1 = false;381 }382 239 383 240 psLogMsg ("psphot.kron", PS_LOG_WARN, "measure masked kron magnitudes : %f sec for %ld objects\n", psTimerMark ("psphot.kron"), sources->n); … … 465 322 if (psphotKronWindowSetSource (source, kronWindow, (j > 0), false, KRON_APPLY_WINDOW)) { 466 323 467 #ifdef SAVE_IMAGES468 #ifdef SAVE_SOURCE_IMAGES469 if (j == 1 && !pass1) {470 char fn[80];471 if (smoothedPixels) {472 sprintf(fn, "%s.s.%d.p%d.sm.fits", psphot_outroot, source->id, pass1 ? 1 : 2);473 psphotSaveImage(0, smoothedPixels, fn);474 }475 sprintf(fn, "%s.s.%d.p%d.fits", psphot_outroot, source->id, pass1 ? 1 : 2);476 psphotSaveImage(0, source->pixels, fn);477 }478 #endif479 #endif480 481 324 // this function populates moments->Mrf,KronFlux,KronFluxErr 482 325 psphotKronWindowMag (source, kronWindow, windowRadius, MIN_KRON_RADIUS, maskVal, KRON_APPLY_WEIGHT, smoothedPixels); … … 606 449 psF32 rs = 0.5 * (fDiff1 + fDiff2); 607 450 608 #ifdef BE_SIMPLE_MINDED609 rf = vPix[row][col] * sqrt(r2);610 rs = vPix[row][col];611 #endif612 613 451 RF += rf; 614 452 RS += rs; … … 621 459 Mrf = MIN (radius, Mrf); 622 460 } 623 #ifdef USE_SE_KR624 if (source->tmpFlags & SE_KR_USED) {625 // we are using the sextratcor KR for this source set it back626 Mrf = source->moments->Mrf;627 }628 #endif629 461 630 462 // Calculate the Kron magnitude (make this block optional?)
Note:
See TracChangeset
for help on using the changeset viewer.
