IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
May 16, 2012, 4:23:42 PM (14 years ago)
Author:
bills
Message:

Add pmSourceSmoothOp which adds or subtracts a smoothed version of a source's
model.
Remove instrumentation from psphotKronIterate.c

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psphot/src/psphotKronIterate.c

    r33877 r33879  
    11# include "psphotInternal.h"
    2 
    3 #define NO_USE_SE_KR   1
    4 #define NO_SAVE_IMAGES 1
    52
    63bool psphotKronWindowSetSource(pmSource *source, psImage *kronWindow, bool useKronRadius, bool insert, bool oldWindow);
     
    5754bool psphotVisualRangeImage (int kapaFD, psImage *inImage, const char *name, int channel, float min, float max);
    5855
    59 bool pass1 = true;
    60 // This is defined in pmSource.c
    61 extern psString psphot_outroot;
    62 
    63 #ifdef USE_SE_KR
    64 static int   nKR = 0;
    65 // input list indexed by list file's source->id
    66 static float kr_sextractor[10000];
    67 static int used[10000];
    68 
    69 int numMatched = 0;
    70 
    71 #define SE_KR_USED 0x800
    72 
    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 file
    101     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 file
    113 
    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_sextractor
    134     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 in
    139             // order of SN this makes it more likely to get the right match
    140             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_KR
    155 
    15656bool psphotKronIterateReadout(pmConfig *config, psMetadata *recipe, const pmFPAview *view, const char * filerule, pmReadout *readout, psArray *sources, pmPSF *psf, int index) {
    15757
     
    16565    psTimerStart ("psphot.kron");
    16666
    167 #ifdef USE_SE_KR
    168     if (!pass1) {
    169         build_kr_list(sources);
    170     }
    171 #endif
    17267
    17368    // determine the number of allowed threads
     
    237132
    238133    // start with the currently known moments (Mxx, Myy, Mxy) and generate a window image
    239 #ifdef USE_SE_KR
    240     int previous = numMatched;
    241 #endif
    242134    for (int i = 0; i < sources->n; i++) {
    243135
     
    247139        // (this skips really bad sources (no peak, no moments, DEFECT)
    248140        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    }
    260142
    261143    // We measure the Kron Radius on a smoothed copy of the readout image
     
    291173
    292174    }
    293 
    294 #ifdef SAVE_IMAGES
    295     psphot_outroot = psMetadataLookupStr(&status, config->arguments, "OUTPUT");
    296     {
    297         // Save the background subtracted image
    298         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 #endif
    315175
    316176    // threaded measurement of the source magnitudes
     
    377237    psFree (kronWindow);
    378238    psFree (smoothedImage);
    379     if (pass1) {
    380         pass1 = false;
    381     }
    382239
    383240    psLogMsg ("psphot.kron", PS_LOG_WARN, "measure masked kron magnitudes : %f sec for %ld objects\n", psTimerMark ("psphot.kron"), sources->n);
     
    465322            if (psphotKronWindowSetSource (source, kronWindow, (j > 0), false, KRON_APPLY_WINDOW)) {
    466323
    467 #ifdef SAVE_IMAGES
    468 #ifdef SAVE_SOURCE_IMAGES
    469                 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 #endif
    479 #endif
    480 
    481324                // this function populates moments->Mrf,KronFlux,KronFluxErr
    482325                psphotKronWindowMag (source, kronWindow, windowRadius, MIN_KRON_RADIUS, maskVal, KRON_APPLY_WEIGHT, smoothedPixels);
     
    606449            psF32 rs = 0.5 * (fDiff1 + fDiff2);
    607450
    608 #ifdef BE_SIMPLE_MINDED
    609             rf = vPix[row][col] * sqrt(r2);
    610             rs = vPix[row][col];
    611 #endif
    612 
    613451            RF  += rf;
    614452            RS  += rs;
     
    621459        Mrf = MIN (radius, Mrf);
    622460    }
    623 #ifdef USE_SE_KR
    624     if (source->tmpFlags & SE_KR_USED) {
    625         // we are using the sextratcor KR for this source set it back
    626         Mrf = source->moments->Mrf;
    627     }
    628 #endif
    629461
    630462    // Calculate the Kron magnitude (make this block optional?)
Note: See TracChangeset for help on using the changeset viewer.