- Timestamp:
- Mar 29, 2010, 3:55:49 PM (16 years ago)
- Location:
- branches/eam_branches/20100225
- Files:
-
- 2 edited
-
. (modified) (1 prop)
-
ppStack/src/ppStackSources.c (modified) (13 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/20100225
- Property svn:mergeinfo changed
-
branches/eam_branches/20100225/ppStack/src/ppStackSources.c
r27004 r27517 8 8 9 9 //#define TESTING // Enable debugging output 10 11 //#define ASTROMETRY // Correct astrometry? 10 12 11 13 #ifdef TESTING … … 62 64 63 65 if (!options->matchZPs && !options->photometry) { 64 int num = psMetadataLookupS32(NULL, config->arguments, "INPUTS.NUM"); // Number of inputs 65 options->norm = psVectorAlloc(num, PS_TYPE_F32); 66 psVectorInit (options->norm, 0.0); 67 68 // XXX do I need to set this? 69 // options->sumExposure = sumExpTime; 70 66 options->norm = psVectorAlloc(options->num, PS_TYPE_F32); 67 psVectorInit(options->norm, 0.0); 71 68 return true; 72 69 } … … 90 87 } 91 88 source->psfMag += 1.0; 89 #ifdef ASTROMETRY 90 if (source->modelPSF) { 91 source->modelPSF->params->data.F32[PM_PAR_XPOS] += 1.0; 92 source->modelPSF->params->data.F32[PM_PAR_YPOS] += 1.0; 93 } 94 if (source->peak) { 95 source->peak->xf += 1.0; 96 source->peak->yf += 1.0; 97 } 98 #endif 92 99 } 93 100 } … … 119 126 return false; 120 127 } 121 122 int num = psMetadataLookupS32(NULL, config->arguments, "INPUTS.NUM"); // Number of inputs 128 psMetadata *zpTargetMenu = psMetadataLookupMetadata(NULL, recipe, "ZP.TARGET"); // Target zero point terms 129 if (!zpTargetMenu) { 130 psError(PPSTACK_ERR_CONFIG, false, "Unable to find ZP.TARGET in recipe."); 131 return false; 132 } 133 134 int num = options->num; // Number of inputs 123 135 psAssert(num == sourceLists->n, "Wrong number of source lists: %ld\n", sourceLists->n); 124 136 125 psVector *zp = psVectorAlloc(num, PS_TYPE_F32); // Zero points for each image 137 psVector *zp = psVectorAlloc(num, PS_TYPE_F32); // Relative zero points for each image 138 psVector *zpExp = psVectorAlloc(num, PS_TYPE_F32); // Measured zero points for each image (maybe) 139 int zpExpNum = 0; // Number of measured zero points 126 140 const char *filter = NULL; // Filter name 127 141 float airmassTerm = NAN; // Airmass term 128 float sumExpTime = 0.0; // Sum of the exposure time 142 float zpTarget = NAN; // Target zero point 143 int numGoodImages = 0; // Number of good images 129 144 for (int i = 0; i < num; i++) { 145 psArray *sources = sourceLists->data[i]; // Source list 146 if (!sources || sources->n == 0) { 147 psLogMsg("ppStack", PS_LOG_WARN, "Image %d has no sources for transparency measurement.", i); 148 options->inputMask->data.PS_TYPE_VECTOR_MASK_DATA[i] |= PPSTACK_MASK_CAL; 149 zp->data.F32[i] = NAN; 150 continue; 151 } 152 numGoodImages++; 153 130 154 pmFPAfile *file = pmFPAfileSelectSingle(config->files, "PPSTACK.INPUT", i); // File of interest 131 pmCell *cell = pmFPAviewThisCell(view, file->fpa); // Cell of interest132 155 133 156 #if defined(TESTING) && 0 … … 146 169 #endif 147 170 148 149 float exptime = psMetadataLookupF32(NULL, cell->concepts, "CELL.EXPOSURE"); // Exposure time 171 float exptime = options->exposures->data.F32[i]; // Exposure time 150 172 float airmass = psMetadataLookupF32(NULL, file->fpa->concepts, "FPA.AIRMASS"); // Airmass 151 173 const char *expFilter = psMetadataLookupStr(NULL, file->fpa->concepts, "FPA.FILTER"); // Filter name 174 zpExp->data.F32[i] = psMetadataLookupF32(NULL, file->fpa->concepts, "FPA.ZP"); // Exposure zero point 175 psLogMsg("ppStack", PS_LOG_INFO, 176 "Image %d: %.2f sec exposure in %s at airmass %.2f with zero point %.2f", 177 i, exptime, expFilter, airmass, zpExp->data.F32[i]); 152 178 if (!isfinite(exptime) || exptime == 0 || !isfinite(airmass) || airmass == 0 || 153 179 !expFilter || strlen(expFilter) == 0) { … … 158 184 return false; 159 185 } 186 if (isfinite(zpExp->data.F32[i])) { 187 zpExp->data.F32[i] += 2.5 * log10(exptime); 188 zpExpNum++; 189 } 160 190 161 191 if (!filter) { 162 192 filter = expFilter; 163 airmassTerm = psMetadataLookupF32(NULL, airmassZP, filter); 164 if (!isfinite(airmassTerm)) { 193 bool mdok; 194 airmassTerm = psMetadataLookupF32(&mdok, airmassZP, filter); 195 if (!mdok || !isfinite(airmassTerm)) { 165 196 psError(PPSTACK_ERR_CONFIG, false, 166 197 "Unable to find airmass term (ZP.AIRMASS) for filter %s", filter); … … 168 199 return false; 169 200 } 201 zpTarget = psMetadataLookupF32(&mdok, zpTargetMenu, filter); 202 if (!mdok || !isfinite(zpTarget)) { 203 psError(PPSTACK_ERR_CONFIG, false, 204 "Unable to find target zero point (ZP.TARGET) for filter %s", filter); 205 psFree(zp); 206 return false; 207 } 170 208 } else if (strcmp(filter, expFilter) != 0) { 171 209 psError(PPSTACK_ERR_CONFIG, false, "Filters don't match: %s vs %s", filter, expFilter); … … 174 212 } 175 213 176 zp->data.F32[i] = airmassTerm * airmass - 2.5 * log10(exptime); 177 sumExpTime += exptime; 178 } 179 180 options->sumExposure = sumExpTime; 214 zp->data.F32[i] = airmassTerm * airmass + 2.5 * log10(exptime); 215 } 216 217 if (numGoodImages == 0) { 218 psLogMsg("ppStack", PS_LOG_WARN, "No images with sources to measure transparency."); 219 options->quality = PPSTACK_ERR_REJECTED; 220 psFree(zp); 221 psFree(zpExp); 222 return true; 223 } 224 if (numGoodImages == 1) { 225 psArray *sources = NULL; // Sources 226 for (int i = 0; i < num && !sources; i++) { 227 if (options->inputMask->data.PS_TYPE_VECTOR_MASK_DATA[i]) { 228 continue; 229 } 230 sources = sourceLists->data[i]; 231 } 232 options->sources = psMemIncrRefCounter(sources); 233 psLogMsg("ppStack", PS_LOG_WARN, "Single image with sources --- no need to match transparency."); 234 psFree(zp); 235 psFree(zpExp); 236 return true; 237 } 238 239 if (zpExpNum == numGoodImages) { 240 for (int i = 0; i < num; i++) { 241 zp->data.F32[i] = zpExp->data.F32[i]; 242 } 243 } 181 244 182 245 psArray *matches = pmSourceMatchSources(sourceLists, radius, true); // List of matches … … 212 275 options->norm = psVectorAlloc(num, PS_TYPE_F32); 213 276 for (int i = 0; i < num; i++) { 214 if ( !isfinite(trans->data.F32[i])) {277 if (inputMask->data.U8[i] || !isfinite(trans->data.F32[i])) { 215 278 continue; 216 279 } 217 280 psArray *sources = sourceLists->data[i]; // Sources of interest 218 float magCorr = airmassTerm - 2.5*log10(sumExpTime) - zp->data.F32[i] - trans->data.F32[i]; 219 options->norm->data.F32[i] = magCorr; 220 psLogMsg("ppStack", PS_LOG_INFO, "Applying magnitude correction to image %d: %f\n", 221 i, magCorr); 281 float magCorr = zp->data.F32[i] + trans->data.F32[i] - 2.5*log10(options->sumExposure); 282 if (zpExpNum == numGoodImages) { 283 // Using measured zero points, so attempt to set target zero point 284 magCorr -= zpTarget; 285 } 286 options->norm->data.F32[i] = -magCorr; 287 psLogMsg("ppStack", PS_LOG_INFO, 288 "Applying scale correction to image %d: %f mag (%f)\n", 289 i, magCorr, trans->data.F32[i]); 222 290 223 291 for (int j = 0; j < sources->n; j++) { … … 226 294 continue; 227 295 } 228 source->psfMag += magCorr; 229 } 230 } 231 } 296 source->psfMag -= magCorr; 297 } 298 } 299 } 300 301 if (zpExpNum == numGoodImages) { 302 // Producing image with target zero point 303 options->zp = zpTarget; 304 } else { 305 options->zp = NAN; 306 } 307 232 308 233 309 #ifdef TESTING … … 239 315 // Double check: all transparencies should be zero 240 316 { 241 psArray *matches = pmSourceMatchSources(sourceLists, radius ); // List of matches317 psArray *matches = pmSourceMatchSources(sourceLists, radius, true); // List of matches 242 318 if (!matches) { 243 319 psError(PPSTACK_ERR_DATA, false, "Unable to match sources"); … … 245 321 return false; 246 322 } 247 psVector *trans = pmSourceMatchRelphot(matches, zp, iter, tol, starLimit, transIter, transRej, 248 transThresh, starRej, starSys); 323 psVector *trans = pmSourceMatchRelphot(matches, zp, tol, iter1, starRej1, starSys1, 324 iter2, starRej2, starSys2, starLimit, 325 transIter, transRej, transThresh); // Transparencies 249 326 for (int i = 0; i < num; i++) { 250 327 fprintf(stderr, "Transparency of image %d: %f\n", i, trans->data.F32[i]); 251 328 } 252 329 psFree(trans); 253 } 254 #endif 255 } 256 257 258 #if 0 330 psFree(matches); 331 } 332 #endif 333 } 334 335 psFree(zp); 336 psFree(zpExp); 337 338 #ifdef ASTROMETRY 259 339 // Position offsets 260 340 { … … 266 346 } 267 347 for (int i = 0; i < num; i++) { 268 psVector *offset = offsets->data[i]; 269 fprintf(stderr, "Offset %d: %f,%f\n", i, offset->data.F32[0], offset->data.F32[1]); 348 if (options->inputMask->data.U8[i]) { 349 continue; 350 } 351 psArray *sources = sourceLists->data[i]; // Sources of interest 352 psVector *offset = offsets->data[i]; // Offsets for image 353 float dx = offset->data.F32[0], dy = offset->data.F32[1]; // Offsets to apply 354 if (!isfinite(dx) || !isfinite(dy)) { 355 continue; 356 } 357 psLogMsg("ppStack", PS_LOG_INFO, "Applying astrometric correction to image %d: %f,%f\n", 358 i, dx, dy); 359 for (int j = 0; j < sources->n; j++) { 360 pmSource *source = sources->data[j]; // Source of interest 361 if (!source) { 362 continue; 363 } 364 if (source->modelPSF) { 365 source->modelPSF->params->data.F32[PM_PAR_XPOS] -= dx; 366 source->modelPSF->params->data.F32[PM_PAR_YPOS] -= dy; 367 } 368 if (source->peak) { 369 source->peak->xf -= dx; 370 source->peak->yf -= dy; 371 } 372 } 270 373 } 271 374 psFree(offsets); 272 375 } 273 376 #endif 377 378 #if (defined TESTING && defined ASTROMETRY) 379 // Double check: all offsets should be zero 380 { 381 psArray *matches = pmSourceMatchSources(sourceLists, radius, true); // List of matches 382 if (!matches) { 383 psError(PPSTACK_ERR_DATA, false, "Unable to match sources"); 384 psFree(zp); 385 return false; 386 } 387 psArray *offsets = pmSourceMatchRelastro(matches, num, tol, iter1, starRej1, 388 iter2, starRej2, starLimit); // Shifts for each image 389 for (int i = 0; i < num; i++) { 390 psVector *offset = offsets->data[i]; // Offsets for image 391 fprintf(stderr, "Offset of image %d: %f,%f\n", i, offset->data.F32[0], offset->data.F32[1]); 392 } 393 psFree(offsets); 394 psFree(matches); 395 } 396 #endif 397 274 398 275 399 if (options->photometry) {
Note:
See TracChangeset
for help on using the changeset viewer.
