IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Aug 26, 2010, 9:18:39 AM (16 years ago)
Author:
Serge CHASTEL
Message:

Merging trunk in branch

Location:
branches/sc_branches/trunkTest
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/sc_branches/trunkTest

  • branches/sc_branches/trunkTest/psModules

    • Property svn:mergeinfo deleted
  • branches/sc_branches/trunkTest/psModules/src/objects/pmSource.c

    r28013 r29060  
    2323#include "pmFPA.h"
    2424#include "pmFPAMaskWeight.h"
     25
     26#include "pmTrend2D.h"
     27#include "pmResiduals.h"
     28#include "pmGrowthCurve.h"
    2529#include "pmSpan.h"
     30#include "pmFootprintSpans.h"
    2631#include "pmFootprint.h"
    2732#include "pmPeaks.h"
    2833#include "pmMoments.h"
    29 #include "pmResiduals.h"
    30 #include "pmGrowthCurve.h"
    31 #include "pmTrend2D.h"
    32 #include "pmPSF.h"
     34#include "pmModelFuncs.h"
    3335#include "pmModel.h"
     36#include "pmModelUtils.h"
     37#include "pmModelClass.h"
     38#include "pmSourceMasks.h"
     39#include "pmSourceExtendedPars.h"
     40#include "pmSourceDiffStats.h"
    3441#include "pmSource.h"
    3542
     
    98105    static int id = 1;
    99106    pmSource *source = (pmSource *) psAlloc(sizeof(pmSource));
    100     *(int *)&source->id = id++;
     107    P_PM_SOURCE_SET_ID(source, id++);
     108
    101109    source->seq = -1;
    102110    source->peak = NULL;
     
    114122    source->type = PM_SOURCE_TYPE_UNKNOWN;
    115123    source->mode = PM_SOURCE_MODE_DEFAULT;
     124    source->mode2 = PM_SOURCE_MODE_DEFAULT;
    116125    source->tmpFlags = 0;
    117126    source->extpars = NULL;
     
    131140    source->sky    = NAN;
    132141    source->skyErr = NAN;
    133     source->pixWeight = NAN;
     142    source->pixWeightNotBad = NAN;
     143    source->pixWeightNotPoor = NAN;
    134144
    135145    source->psfChisq = NAN;
     
    142152
    143153/******************************************************************************
    144 pmSourceCopy(): copy the pmSource structure and contents
    145 XXX : are we OK with incrementing the ID?
     154pmSourceCopy(): copy the pmSource, yielding a copy of the source that can be used without
     155affecting the original.  This Copy can be used to allow multiple fit attempts on the same
     156object.  The pixels, variance, and mask arrays all point to the same original subarrays.  The
     157peak and moments point at the original values.
    146158*****************************************************************************/
    147159pmSource *pmSourceCopy(pmSource *in)
     160{
     161    if (in == NULL) {
     162        return(NULL);
     163    }
     164    pmSource *source = pmSourceAlloc ();
     165
     166    // keep the original ID so we can find map back to the original
     167    P_PM_SOURCE_SET_ID(source, in->id);
     168
     169    // peak has the same values as the original
     170    if (in->peak != NULL) {
     171        source->peak = pmPeakAlloc (in->peak->x, in->peak->y, in->peak->value, in->peak->type);
     172        source->peak->xf = in->peak->xf;
     173        source->peak->yf = in->peak->yf;
     174        source->peak->flux = in->peak->flux;
     175        source->peak->SN = in->peak->SN;
     176    }
     177
     178    // copy the values in the moments structure
     179    if (in->moments != NULL) {
     180        source->moments  =  pmMomentsAlloc();
     181        *source->moments = *in->moments;
     182    }
     183
     184    // These images are all views to the parent.  We want a new view, but pointing at the same
     185    // pixels.  Modifying these pixels (ie, subtracting the model) will affect the pixels seen
     186    // by all copies.
     187    source->pixels   = psImageCopyView(NULL, in->pixels);
     188    source->variance   = psImageCopyView(NULL, in->variance);
     189    source->maskView = in->maskView ? psImageCopyView(NULL, in->maskView) : NULL;
     190
     191    // the maskObj is a unique mask array; create a new mask image
     192    source->maskObj = in->maskObj ? psImageCopy (NULL, in->maskObj, PS_TYPE_IMAGE_MASK) : NULL;
     193
     194    source->type = in->type;
     195    source->mode = in->mode;
     196    source->imageID = in->imageID;
     197
     198    return(source);
     199}
     200
     201/******************************************************************************
     202pmSourceCopyData(): this creates a new, duplicate source with the same parameters as the
     203original (but is actually a new source at the same location)
     204*****************************************************************************/
     205pmSource *pmSourceCopyData(pmSource *in)
    148206{
    149207    if (in == NULL) {
     
    482540        }
    483541        psfClump.X  = stats->clippedMean;
    484         psfClump.dX = stats->clippedStdev;
     542        psfClump.dX = hypot(stats->clippedStdev, PSF_CLUMP_GRID_SCALE);
    485543
    486544        if (!psVectorStats (stats, tmpSy, NULL, NULL, 0)) {
     
    489547        }
    490548        psfClump.Y  = stats->clippedMean;
    491         psfClump.dY = stats->clippedStdev;
     549        psfClump.dY = hypot(stats->clippedStdev, PSF_CLUMP_GRID_SCALE);
    492550
    493551        psTrace ("psModules.objects", 2, "clump  X,  Y: %f, %f\n", psfClump.X, psfClump.Y);
     
    910968    bool addNoise = mode & PM_MODEL_OP_NOISE;
    911969
    912     if (source->modelFlux) {
     970    // require the use of pmModelAddWithOffset if we are adding noise (because the model size and norm are rescaled)
     971    if (!addNoise && source->modelFlux) {
    913972        // add in the pixels from the modelFlux image
    914973        int dX = source->modelFlux->col0 - source->pixels->col0;
     
    931990
    932991        psF32 **target = source->pixels->data.F32;
    933         if (addNoise) {
    934             // when adding noise, we assume the shape and Io have been modified
    935             target = source->variance->data.F32;
    936         }
    937992
    938993        for (int iy = 0; iy < source->modelFlux->numRows; iy++) {
     
    9491004            }
    9501005        }
    951         if (!addNoise) {
    952             if (add) {
    953                 source->tmpFlags &= ~PM_SOURCE_TMPF_SUBTRACTED;
    954             } else {
    955                 source->tmpFlags |= PM_SOURCE_TMPF_SUBTRACTED;
    956             }
     1006        if (add) {
     1007            source->tmpFlags &= ~PM_SOURCE_TMPF_SUBTRACTED;
     1008        } else {
     1009            source->tmpFlags |= PM_SOURCE_TMPF_SUBTRACTED;
    9571010        }
    9581011        return true;
     
    9731026        }
    9741027    }
     1028
     1029    return true;
     1030}
     1031
     1032// should we call pmSourceCacheModel if it does not exist?
     1033bool pmSourceNoiseOp (pmSource *source, pmModelOpMode mode, float FACTOR, float SIZE, bool add, psImageMaskType maskVal, int dx, int dy)
     1034{
     1035    assert (mode & PM_MODEL_OP_NOISE);
     1036    PS_ASSERT_PTR_NON_NULL(source, false);
     1037    PS_ASSERT_PTR_NON_NULL(source->peak, false);
     1038
     1039    if (add) {
     1040        psTrace ("psphot", 3, "adding noise to object at %f,%f\n", source->peak->xf, source->peak->yf);
     1041    } else {
     1042        psTrace ("psphot", 3, "removing noise from object at %f,%f\n", source->peak->xf, source->peak->yf);
     1043    }
     1044
     1045    pmSourceNoiseOpModel (source->modelPSF, source, mode, FACTOR, SIZE, add, maskVal, dx, dy);
     1046
     1047    if (source->modelEXT) {
     1048        pmSourceNoiseOpModel (source->modelEXT, source, mode, FACTOR, SIZE, add, maskVal, dx, dy);
     1049    }
     1050
     1051    return true;
     1052}
     1053
     1054bool pmSourceNoiseOpModel (pmModel *model, pmSource *source, pmModelOpMode mode, float FACTOR, float SIZE, bool add, psImageMaskType maskVal, int dx, int dy)
     1055{
     1056    bool status;
     1057    psEllipseShape oldshape;
     1058    psEllipseShape newshape;
     1059    psEllipseAxes axes;
     1060
     1061    if (add) {
     1062        psTrace ("psphot", 4, "adding noise for object at %f,%f\n", model->params->data.F32[PM_PAR_XPOS], model->params->data.F32[PM_PAR_YPOS]);
     1063    } else {
     1064        psTrace ("psphot", 4, "remove noise for object at %f,%f\n", model->params->data.F32[PM_PAR_XPOS], model->params->data.F32[PM_PAR_YPOS]);
     1065    }
     1066
     1067    psF32 *PAR = model->params->data.F32;
     1068
     1069    // save original values
     1070    float oldI0  = PAR[PM_PAR_I0];
     1071    oldshape.sx  = PAR[PM_PAR_SXX];
     1072    oldshape.sy  = PAR[PM_PAR_SYY];
     1073    oldshape.sxy = PAR[PM_PAR_SXY];
     1074
     1075    // XXX can this be done more intelligently?
     1076    if (oldI0 == 0.0) return false;
     1077    if (!isfinite(oldI0)) return false;
     1078
     1079    // increase size and height of source
     1080    axes = psEllipseShapeToAxes (oldshape, 20.0);
     1081    axes.major *= SIZE;
     1082    axes.minor *= SIZE;
     1083    newshape = psEllipseAxesToShape (axes);
     1084    PAR[PM_PAR_I0]  = FACTOR*oldI0;
     1085    PAR[PM_PAR_SXX] = newshape.sx;
     1086    PAR[PM_PAR_SYY] = newshape.sy;
     1087    PAR[PM_PAR_SXY] = newshape.sxy;
     1088
     1089    psImage *target = source->variance;
     1090
     1091    if (add) {
     1092        status = pmModelAddWithOffset (target, source->maskObj, model, mode, maskVal, dx, dy);
     1093    } else {
     1094        status = pmModelSubWithOffset (target, source->maskObj, model, mode, maskVal, dx, dy);
     1095    }
     1096
     1097    // restore original values
     1098    PAR[PM_PAR_I0]  = oldI0;
     1099    PAR[PM_PAR_SXX] = oldshape.sx;
     1100    PAR[PM_PAR_SYY] = oldshape.sy;
     1101    PAR[PM_PAR_SXY] = oldshape.sxy;
    9751102
    9761103    return true;
Note: See TracChangeset for help on using the changeset viewer.