Changeset 33879
- Timestamp:
- May 16, 2012, 4:23:42 PM (14 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
-
psModules/src/objects/pmSource.c (modified) (3 diffs)
-
psModules/src/objects/pmSource.h (modified) (2 diffs)
-
psphot/src/psphotKronIterate.c (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psModules/src/objects/pmSource.c
r33690 r33879 39 39 #include "pmSourceExtendedPars.h" 40 40 #include "pmSourceDiffStats.h" 41 #include "pmSourcePhotometry.h" 41 42 #include "pmSource.h" 42 43 … … 159 160 source->radialAper = NULL; 160 161 source->parent = NULL; 162 source->tmpPtr = NULL; 161 163 source->imageID = -1; 162 164 source->nFrames = 0; … … 1157 1159 PAR[PM_PAR_SYY] = oldshape.sy; 1158 1160 PAR[PM_PAR_SXY] = oldshape.sxy; 1161 1162 return true; 1163 } 1164 1165 bool 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 1187 bool 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; 1159 1249 1160 1250 return true; -
trunk/psModules/src/objects/pmSource.h
r33690 r33879 117 117 psArray *radialAper; ///< radial flux in circular apertures 118 118 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. 119 120 int imageID; 120 121 psU16 nFrames; … … 302 303 bool pmSourceNoiseOp (pmSource *source, pmModelOpMode mode, float FACTOR, float SIZE, bool add, psImageMaskType maskVal, int dx, int dy); 303 304 305 bool pmSourceSmoothOp (pmSource *source, pmModelOpMode mode, psImage *target, float sigma, bool add, psImageMaskType maskVal, int dx, int dy); 306 bool pmSourceSmoothOpModel (pmModel *model, pmSource *source, pmModelOpMode mode, psImage *target, float sigma, bool add, psImageMaskType maskVal, int dx, int dy); 307 304 308 bool pmSourceOp (pmSource *source, pmModelOpMode mode, bool add, psImageMaskType maskVal, int dx, int dy); 305 309 bool pmSourceCacheModel (pmSource *source, psImageMaskType maskVal); -
trunk/psphot/src/psphotKronIterate.c
r33877 r33879 1 1 # include "psphotInternal.h" 2 3 #define NO_USE_SE_KR 14 #define NO_SAVE_IMAGES 15 2 6 3 bool psphotKronWindowSetSource(pmSource *source, psImage *kronWindow, bool useKronRadius, bool insert, bool oldWindow); … … 57 54 bool psphotVisualRangeImage (int kapaFD, psImage *inImage, const char *name, int channel, float min, float max); 58 55 59 bool pass1 = true;60 // This is defined in pmSource.c61 extern psString psphot_outroot;62 63 #ifdef USE_SE_KR64 static int nKR = 0;65 // input list indexed by list file's source->id66 static float kr_sextractor[10000];67 static int used[10000];68 69 int numMatched = 0;70 71 #define SE_KR_USED 0x80072 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 file101 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 file113 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_sextractor134 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 in139 // order of SN this makes it more likely to get the right match140 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_KR155 156 56 bool psphotKronIterateReadout(pmConfig *config, psMetadata *recipe, const pmFPAview *view, const char * filerule, pmReadout *readout, psArray *sources, pmPSF *psf, int index) { 157 57 … … 165 65 psTimerStart ("psphot.kron"); 166 66 167 #ifdef USE_SE_KR168 if (!pass1) {169 build_kr_list(sources);170 }171 #endif172 67 173 68 // determine the number of allowed threads … … 237 132 238 133 // start with the currently known moments (Mxx, Myy, Mxy) and generate a window image 239 #ifdef USE_SE_KR240 int previous = numMatched;241 #endif242 134 for (int i = 0; i < sources->n; i++) { 243 135 … … 247 139 // (this skips really bad sources (no peak, no moments, DEFECT) 248 140 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 } 260 142 261 143 // We measure the Kron Radius on a smoothed copy of the readout image … … 291 173 292 174 } 293 294 #ifdef SAVE_IMAGES295 psphot_outroot = psMetadataLookupStr(&status, config->arguments, "OUTPUT");296 {297 // Save the background subtracted image298 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 #endif315 175 316 176 // threaded measurement of the source magnitudes … … 377 237 psFree (kronWindow); 378 238 psFree (smoothedImage); 379 if (pass1) {380 pass1 = false;381 }382 239 383 240 psLogMsg ("psphot.kron", PS_LOG_WARN, "measure masked kron magnitudes : %f sec for %ld objects\n", psTimerMark ("psphot.kron"), sources->n); … … 465 322 if (psphotKronWindowSetSource (source, kronWindow, (j > 0), false, KRON_APPLY_WINDOW)) { 466 323 467 #ifdef SAVE_IMAGES468 #ifdef SAVE_SOURCE_IMAGES469 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 #endif479 #endif480 481 324 // this function populates moments->Mrf,KronFlux,KronFluxErr 482 325 psphotKronWindowMag (source, kronWindow, windowRadius, MIN_KRON_RADIUS, maskVal, KRON_APPLY_WEIGHT, smoothedPixels); … … 606 449 psF32 rs = 0.5 * (fDiff1 + fDiff2); 607 450 608 #ifdef BE_SIMPLE_MINDED609 rf = vPix[row][col] * sqrt(r2);610 rs = vPix[row][col];611 #endif612 613 451 RF += rf; 614 452 RS += rs; … … 621 459 Mrf = MIN (radius, Mrf); 622 460 } 623 #ifdef USE_SE_KR624 if (source->tmpFlags & SE_KR_USED) {625 // we are using the sextratcor KR for this source set it back626 Mrf = source->moments->Mrf;627 }628 #endif629 461 630 462 // Calculate the Kron magnitude (make this block optional?)
Note:
See TracChangeset
for help on using the changeset viewer.
