IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jun 19, 2012, 5:24:19 PM (14 years ago)
Author:
mhuber
Message:

merging latest r34040 trunk changes to branch

Location:
branches/meh_branches/ppstack_test
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/meh_branches/ppstack_test

  • branches/meh_branches/ppstack_test/psModules

  • branches/meh_branches/ppstack_test/psModules/src/objects/pmSource.c

    r33415 r34041  
    3939#include "pmSourceExtendedPars.h"
    4040#include "pmSourceDiffStats.h"
     41#include "pmSourcePhotometry.h"
    4142#include "pmSource.h"
    4243
     
    5051    psFree(tmp->pixels);
    5152    psFree(tmp->variance);
     53# if (HAVE_MODEL_VAR)
     54    psFree(tmp->modelVar);
     55# endif
    5256    psFree(tmp->maskObj);
    5357    psFree(tmp->maskView);
     
    7680    psFree (source->pixels);
    7781    psFree (source->variance);
     82# if (HAVE_MODEL_VAR)
     83    psFree (source->modelVar);
     84# endif
    7885    psFree (source->maskObj);
    7986    psFree (source->maskView);
     
    8390    source->pixels = NULL;
    8491    source->variance = NULL;
     92# if (HAVE_MODEL_VAR)
     93    source->modelVar = NULL;
     94# endif
    8595    source->maskObj = NULL;
    8696    source->maskView = NULL;
     
    112122    source->pixels = NULL;
    113123    source->variance = NULL;
     124# if (HAVE_MODEL_VAR)
     125    source->modelVar = NULL;
     126# endif
    114127    source->maskObj = NULL;
    115128    source->maskView = NULL;
     
    159172    source->radialAper = NULL;
    160173    source->parent = NULL;
     174    source->tmpPtr = NULL;
    161175    source->imageID = -1;
     176    source->nFrames = 0;
    162177
    163178    psMemSetDeallocator(source, (psFreeFunc) sourceFree);
     
    197212    source->pixels   = in->pixels   ? psImageCopyView(NULL, in->pixels)   : NULL;
    198213    source->variance = in->variance ? psImageCopyView(NULL, in->variance) : NULL;
     214# if (HAVE_MODEL_VAR)
     215    source->modelVar = NULL;
     216# endif
    199217    source->maskView = in->maskView ? psImageCopyView(NULL, in->maskView) : NULL;
    200218
     
    10261044    bool addNoise = mode & PM_MODEL_OP_NOISE;
    10271045
     1046# if (HAVE_MODEL_VAR)
     1047    bool addModelVar = mode & PM_MODEL_OP_MODELVAR;
     1048    if (addModelVar) psAssert (source->modelVar, "programming error");
     1049# endif
     1050
    10281051    // require the use of pmModelAddWithOffset if we are adding noise (because the model size and norm are rescaled)
    10291052    if (!addNoise && source->modelFlux) {
     
    10471070        }
    10481071
     1072# if (HAVE_MODEL_VAR)
     1073        psF32 **target = addModelVar ? source->modelVar->data.F32 : source->pixels->data.F32;
     1074# else
    10491075        psF32 **target = source->pixels->data.F32;
     1076# endif
    10501077
    10511078        for (int iy = 0; iy < source->modelFlux->numRows; iy++) {
     
    10621089            }
    10631090        }
     1091# if (HAVE_MODEL_VAR)
     1092        if (!addModelVar) {
     1093            if (add) {
     1094                source->tmpFlags &= ~PM_SOURCE_TMPF_SUBTRACTED;
     1095            } else {
     1096                source->tmpFlags |= PM_SOURCE_TMPF_SUBTRACTED;
     1097            }
     1098        }
     1099# else
    10641100        if (add) {
    10651101            source->tmpFlags &= ~PM_SOURCE_TMPF_SUBTRACTED;
     
    10671103            source->tmpFlags |= PM_SOURCE_TMPF_SUBTRACTED;
    10681104        }
     1105# endif
    10691106        return true;
    10701107    }
     
    10741111        target = source->variance;
    10751112    }
     1113# if (HAVE_MODEL_VAR)
     1114    if (addModelVar) {
     1115        target = source->modelVar;
     1116    }
     1117# endif
    10761118
    10771119    if (add) {
    10781120        status = pmModelAddWithOffset (target, source->maskObj, model, PM_MODEL_OP_FULL, maskVal, dx, dy);
     1121# if (HAVE_MODEL_VAR)
     1122        if (!addNoise && !addModelVar) source->tmpFlags &= ~PM_SOURCE_TMPF_SUBTRACTED;
     1123# else
    10791124        source->tmpFlags &= ~PM_SOURCE_TMPF_SUBTRACTED;
     1125# endif
    10801126    } else {
    10811127        status = pmModelSubWithOffset (target, source->maskObj, model, PM_MODEL_OP_FULL, maskVal, dx, dy);
     1128# if (HAVE_MODEL_VAR)
     1129        if (!addNoise && !addModelVar) source->tmpFlags |= PM_SOURCE_TMPF_SUBTRACTED;
     1130# else
    10821131        source->tmpFlags |= PM_SOURCE_TMPF_SUBTRACTED;
     1132# endif
    10831133    }
    10841134
     
    11561206    PAR[PM_PAR_SYY] = oldshape.sy;
    11571207    PAR[PM_PAR_SXY] = oldshape.sxy;
     1208
     1209    return true;
     1210}
     1211
     1212bool pmSourceSmoothOp (pmSource *source, pmModelOpMode mode, psImage *target, float sigma, bool add, psImageMaskType maskVal, int dx, int dy)
     1213{
     1214//    assert (mode & PM_MODEL_OP_NOISE);
     1215    PS_ASSERT_PTR_NON_NULL(source, false);
     1216    PS_ASSERT_PTR_NON_NULL(source->peak, false);
     1217    PS_ASSERT_PTR_NON_NULL(target, false);
     1218
     1219    if (add) {
     1220        psTrace ("psphot", 3, "adding smoothed object at %f,%f\n", source->peak->xf, source->peak->yf);
     1221    } else {
     1222        psTrace ("psphot", 3, "removing smooted object at %f,%f\n", source->peak->xf, source->peak->yf);
     1223    }
     1224
     1225    pmModel *model = pmSourceGetModel(NULL, source);
     1226    if (!model) {
     1227        return false;
     1228    }
     1229    pmSourceSmoothOpModel (model, source, mode, target, sigma, add, maskVal, dx, dy);
     1230
     1231    return true;
     1232}
     1233
     1234bool pmSourceSmoothOpModel (pmModel *model, pmSource *source, pmModelOpMode mode, psImage *target, float sigma, bool add, psImageMaskType maskVal, int dx, int dy)
     1235{
     1236    bool status;
     1237    psEllipseShape oldshape;
     1238    psEllipseShape newshape;
     1239    psEllipseAxes axes;
     1240
     1241    if (add) {
     1242        psTrace ("psphot", 4, "adding smoothed object at %f,%f\n", model->params->data.F32[PM_PAR_XPOS], model->params->data.F32[PM_PAR_YPOS]);
     1243    } else {
     1244        psTrace ("psphot", 4, "removing smoothed object at %f,%f\n", model->params->data.F32[PM_PAR_XPOS], model->params->data.F32[PM_PAR_YPOS]);
     1245    }
     1246
     1247    psF32 *PAR = model->params->data.F32;
     1248
     1249    // Isn't this hanging around somewhere?
     1250    float oldFlux = NAN;
     1251    if (!pmSourcePhotometryModel (NULL, &oldFlux, model)) return false;
     1252
     1253    // save original values
     1254    float oldI0  = PAR[PM_PAR_I0];
     1255    float oldsxx = PAR[PM_PAR_SXX];
     1256    float oldsyy = PAR[PM_PAR_SYY];
     1257    float oldsxy = PAR[PM_PAR_SXY];
     1258
     1259    // Since we are going to scale the flux correctly we need to get our
     1260    // factors of sqrt(2) right
     1261    oldshape.sx  = oldsxx / M_SQRT2;
     1262    oldshape.sy  = oldsyy / M_SQRT2;
     1263    oldshape.sxy = oldsxy;
     1264
     1265    // XXX can this be done more intelligently?
     1266    if (oldI0 == 0.0) return false;
     1267    if (!isfinite(oldI0)) return false;
     1268
     1269    // increase size and height of source
     1270    axes = psEllipseShapeToAxes (oldshape, 20.0);
     1271    axes.major = sqrt(PS_SQR(axes.major) + PS_SQR(sigma));
     1272    axes.minor = sqrt(PS_SQR(axes.minor) + PS_SQR(sigma));
     1273    newshape = psEllipseAxesToShape (axes);
     1274    PAR[PM_PAR_SXX] = newshape.sx * M_SQRT2;
     1275    PAR[PM_PAR_SYY] = newshape.sy * M_SQRT2;
     1276    PAR[PM_PAR_SXY] = newshape.sxy;
     1277
     1278    PAR[PM_PAR_I0]  = 1.0;
     1279
     1280    float newFlux;
     1281    if (!pmSourcePhotometryModel (NULL, &newFlux, model)) return false;
     1282
     1283    PAR[PM_PAR_I0]  = oldFlux / newFlux;
     1284
     1285    if (add) {
     1286        status = pmModelAddWithOffset (target, source->maskObj, model, mode, maskVal, dx, dy);
     1287    } else {
     1288        status = pmModelSubWithOffset (target, source->maskObj, model, mode, maskVal, dx, dy);
     1289    }
     1290
     1291    // restore original values
     1292    PAR[PM_PAR_I0]  = oldI0;
     1293    PAR[PM_PAR_SXX] = oldsxx;
     1294    PAR[PM_PAR_SYY] = oldsyy;
     1295    PAR[PM_PAR_SXY] = oldsxy;
    11581296
    11591297    return true;
Note: See TracChangeset for help on using the changeset viewer.