IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 33879


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

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/psModules/src/objects/pmSource.c

    r33690 r33879  
    3939#include "pmSourceExtendedPars.h"
    4040#include "pmSourceDiffStats.h"
     41#include "pmSourcePhotometry.h"
    4142#include "pmSource.h"
    4243
     
    159160    source->radialAper = NULL;
    160161    source->parent = NULL;
     162    source->tmpPtr = NULL;
    161163    source->imageID = -1;
    162164    source->nFrames = 0;
     
    11571159    PAR[PM_PAR_SYY] = oldshape.sy;
    11581160    PAR[PM_PAR_SXY] = oldshape.sxy;
     1161
     1162    return true;
     1163}
     1164
     1165bool pmSourceSmoothOp (pmSource *source, pmModelOpMode mode, psImage *target, float sigma, bool add, psImageMaskType maskVal, int dx, int dy)
     1166{
     1167//    assert (mode & PM_MODEL_OP_NOISE);
     1168    PS_ASSERT_PTR_NON_NULL(source, false);
     1169    PS_ASSERT_PTR_NON_NULL(source->peak, false);
     1170    PS_ASSERT_PTR_NON_NULL(target, false);
     1171
     1172    if (add) {
     1173        psTrace ("psphot", 3, "adding smoothed object at %f,%f\n", source->peak->xf, source->peak->yf);
     1174    } else {
     1175        psTrace ("psphot", 3, "removing smooted object at %f,%f\n", source->peak->xf, source->peak->yf);
     1176    }
     1177
     1178    pmModel *model = pmSourceGetModel(NULL, source);
     1179    if (!model) {
     1180        return false;
     1181    }
     1182    pmSourceSmoothOpModel (model, source, mode, target, sigma, add, maskVal, dx, dy);
     1183
     1184    return true;
     1185}
     1186
     1187bool pmSourceSmoothOpModel (pmModel *model, pmSource *source, pmModelOpMode mode, psImage *target, float sigma, bool add, psImageMaskType maskVal, int dx, int dy)
     1188{
     1189    bool status;
     1190    psEllipseShape oldshape;
     1191    psEllipseShape newshape;
     1192    psEllipseAxes axes;
     1193
     1194    if (add) {
     1195        psTrace ("psphot", 4, "adding smoothed object at %f,%f\n", model->params->data.F32[PM_PAR_XPOS], model->params->data.F32[PM_PAR_YPOS]);
     1196    } else {
     1197        psTrace ("psphot", 4, "removing smoothed object at %f,%f\n", model->params->data.F32[PM_PAR_XPOS], model->params->data.F32[PM_PAR_YPOS]);
     1198    }
     1199
     1200    psF32 *PAR = model->params->data.F32;
     1201
     1202    // Isn't this hanging around somewhere?
     1203    float oldFlux = NAN;
     1204    if (!pmSourcePhotometryModel (NULL, &oldFlux, model)) return false;
     1205
     1206    // save original values
     1207    float oldI0  = PAR[PM_PAR_I0];
     1208    float oldsxx = PAR[PM_PAR_SXX];
     1209    float oldsyy = PAR[PM_PAR_SYY];
     1210    float oldsxy = PAR[PM_PAR_SXY];
     1211
     1212    // Since we are going to scale the flux correctly we need to get our
     1213    // factors of sqrt(2) right
     1214    oldshape.sx  = oldsxx / M_SQRT2;
     1215    oldshape.sy  = oldsyy / M_SQRT2;
     1216    oldshape.sxy = oldsxy;
     1217
     1218    // XXX can this be done more intelligently?
     1219    if (oldI0 == 0.0) return false;
     1220    if (!isfinite(oldI0)) return false;
     1221
     1222    // increase size and height of source
     1223    axes = psEllipseShapeToAxes (oldshape, 20.0);
     1224    axes.major = sqrt(PS_SQR(axes.major) + PS_SQR(sigma));
     1225    axes.minor = sqrt(PS_SQR(axes.minor) + PS_SQR(sigma));
     1226    newshape = psEllipseAxesToShape (axes);
     1227    PAR[PM_PAR_SXX] = newshape.sx * M_SQRT2;
     1228    PAR[PM_PAR_SYY] = newshape.sy * M_SQRT2;
     1229    PAR[PM_PAR_SXY] = newshape.sxy;
     1230
     1231    PAR[PM_PAR_I0]  = 1.0;
     1232
     1233    float newFlux;
     1234    if (!pmSourcePhotometryModel (NULL, &newFlux, model)) return false;
     1235
     1236    PAR[PM_PAR_I0]  = oldFlux / newFlux;
     1237
     1238    if (add) {
     1239        status = pmModelAddWithOffset (target, source->maskObj, model, mode, maskVal, dx, dy);
     1240    } else {
     1241        status = pmModelSubWithOffset (target, source->maskObj, model, mode, maskVal, dx, dy);
     1242    }
     1243
     1244    // restore original values
     1245    PAR[PM_PAR_I0]  = oldI0;
     1246    PAR[PM_PAR_SXX] = oldsxx;
     1247    PAR[PM_PAR_SYY] = oldsyy;
     1248    PAR[PM_PAR_SXY] = oldsxy;
    11591249
    11601250    return true;
  • trunk/psModules/src/objects/pmSource.h

    r33690 r33879  
    117117    psArray *radialAper;                ///< radial flux in circular apertures
    118118    pmSource *parent;                   ///< reference to the master source from which this is derived
     119    psPtr *tmpPtr;                      ///< pointer that may be used to store data in a particular module. e.g. psphotKronIterate.
    119120    int imageID;
    120121    psU16 nFrames;
     
    302303bool pmSourceNoiseOp (pmSource *source, pmModelOpMode mode, float FACTOR, float SIZE, bool add, psImageMaskType maskVal, int dx, int dy);
    303304
     305bool pmSourceSmoothOp (pmSource *source, pmModelOpMode mode, psImage *target, float sigma, bool add, psImageMaskType maskVal, int dx, int dy);
     306bool pmSourceSmoothOpModel (pmModel *model, pmSource *source, pmModelOpMode mode, psImage *target, float sigma, bool add, psImageMaskType maskVal, int dx, int dy);
     307
    304308bool pmSourceOp (pmSource *source, pmModelOpMode mode, bool add, psImageMaskType maskVal, int dx, int dy);
    305309bool pmSourceCacheModel (pmSource *source, psImageMaskType maskVal);
  • 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.