Changeset 29004 for trunk/psModules/src/objects/pmSource.c
- Timestamp:
- Aug 20, 2010, 1:14:11 PM (16 years ago)
- Location:
- trunk/psModules
- Files:
-
- 2 edited
-
. (modified) (1 prop)
-
src/objects/pmSource.c (modified) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psModules
- Property svn:mergeinfo deleted
-
trunk/psModules/src/objects/pmSource.c
r28013 r29004 23 23 #include "pmFPA.h" 24 24 #include "pmFPAMaskWeight.h" 25 26 #include "pmTrend2D.h" 27 #include "pmResiduals.h" 28 #include "pmGrowthCurve.h" 25 29 #include "pmSpan.h" 30 #include "pmFootprintSpans.h" 26 31 #include "pmFootprint.h" 27 32 #include "pmPeaks.h" 28 33 #include "pmMoments.h" 29 #include "pmResiduals.h" 30 #include "pmGrowthCurve.h" 31 #include "pmTrend2D.h" 32 #include "pmPSF.h" 34 #include "pmModelFuncs.h" 33 35 #include "pmModel.h" 36 #include "pmModelUtils.h" 37 #include "pmModelClass.h" 38 #include "pmSourceMasks.h" 39 #include "pmSourceExtendedPars.h" 40 #include "pmSourceDiffStats.h" 34 41 #include "pmSource.h" 35 42 … … 98 105 static int id = 1; 99 106 pmSource *source = (pmSource *) psAlloc(sizeof(pmSource)); 100 *(int *)&source->id = id++; 107 P_PM_SOURCE_SET_ID(source, id++); 108 101 109 source->seq = -1; 102 110 source->peak = NULL; … … 114 122 source->type = PM_SOURCE_TYPE_UNKNOWN; 115 123 source->mode = PM_SOURCE_MODE_DEFAULT; 124 source->mode2 = PM_SOURCE_MODE_DEFAULT; 116 125 source->tmpFlags = 0; 117 126 source->extpars = NULL; … … 131 140 source->sky = NAN; 132 141 source->skyErr = NAN; 133 source->pixWeight = NAN; 142 source->pixWeightNotBad = NAN; 143 source->pixWeightNotPoor = NAN; 134 144 135 145 source->psfChisq = NAN; … … 142 152 143 153 /****************************************************************************** 144 pmSourceCopy(): copy the pmSource structure and contents 145 XXX : are we OK with incrementing the ID? 154 pmSourceCopy(): copy the pmSource, yielding a copy of the source that can be used without 155 affecting the original. This Copy can be used to allow multiple fit attempts on the same 156 object. The pixels, variance, and mask arrays all point to the same original subarrays. The 157 peak and moments point at the original values. 146 158 *****************************************************************************/ 147 159 pmSource *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 /****************************************************************************** 202 pmSourceCopyData(): this creates a new, duplicate source with the same parameters as the 203 original (but is actually a new source at the same location) 204 *****************************************************************************/ 205 pmSource *pmSourceCopyData(pmSource *in) 148 206 { 149 207 if (in == NULL) { … … 482 540 } 483 541 psfClump.X = stats->clippedMean; 484 psfClump.dX = stats->clippedStdev;542 psfClump.dX = hypot(stats->clippedStdev, PSF_CLUMP_GRID_SCALE); 485 543 486 544 if (!psVectorStats (stats, tmpSy, NULL, NULL, 0)) { … … 489 547 } 490 548 psfClump.Y = stats->clippedMean; 491 psfClump.dY = stats->clippedStdev;549 psfClump.dY = hypot(stats->clippedStdev, PSF_CLUMP_GRID_SCALE); 492 550 493 551 psTrace ("psModules.objects", 2, "clump X, Y: %f, %f\n", psfClump.X, psfClump.Y); … … 910 968 bool addNoise = mode & PM_MODEL_OP_NOISE; 911 969 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) { 913 972 // add in the pixels from the modelFlux image 914 973 int dX = source->modelFlux->col0 - source->pixels->col0; … … 931 990 932 991 psF32 **target = source->pixels->data.F32; 933 if (addNoise) {934 // when adding noise, we assume the shape and Io have been modified935 target = source->variance->data.F32;936 }937 992 938 993 for (int iy = 0; iy < source->modelFlux->numRows; iy++) { … … 949 1004 } 950 1005 } 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; 957 1010 } 958 1011 return true; … … 973 1026 } 974 1027 } 1028 1029 return true; 1030 } 1031 1032 // should we call pmSourceCacheModel if it does not exist? 1033 bool 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 1054 bool 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; 975 1102 976 1103 return true;
Note:
See TracChangeset
for help on using the changeset viewer.
