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/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;
Note: See TracChangeset for help on using the changeset viewer.