Changeset 40490 for trunk/psastro/src/psastroLoadGhosts.c
- Timestamp:
- Jun 27, 2018, 4:11:05 PM (8 years ago)
- Location:
- trunk/psastro
- Files:
-
- 2 edited
-
. (modified) (1 prop)
-
src/psastroLoadGhosts.c (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psastro
-
Property svn:mergeinfo
set to
/branches/czw_branch/20160809/psastro merged eligible /branches/czw_branch/20170908/psastro merged eligible
-
Property svn:mergeinfo
set to
-
trunk/psastro/src/psastroLoadGhosts.c
r33859 r40490 40 40 * calculate ghost FPA and Chip positions for the stars loaded on the FPA 41 41 */ 42 43 44 42 45 bool psastroLoadGhosts (pmConfig *config) { 43 46 … … 58 61 psLogMsg ("psastro", PS_LOG_INFO, "determine ghost positions"); 59 62 63 // XXX this needs to be camera-dependent 64 if (0) { 65 psWarning("Doing the hard coded switch to HSC ghosts still."); 66 return (psastroLoadGhostsHSC(config)); 67 } 68 69 psWarning("hard coded switch to GPC ghosts."); 70 60 71 // select the current recipe 61 72 psMetadata *recipe = psMetadataLookupPtr (&status, config->recipes, PSASTRO_RECIPE); … … 68 79 if (!REFSTAR_MASK_GHOST) return true; 69 80 81 70 82 char *ghostFile = psMetadataLookupStr (&status, recipe, "GHOST_MODEL"); 71 83 if (!strcasecmp(ghostFile, "NONE")) return true; … … 256 268 return false; 257 269 } 270 271 272 273 bool psastroLoadGhostsHSC (pmConfig *config) { 274 bool status; 275 pmChip *chip = NULL; 276 pmCell *cell = NULL; 277 pmReadout *readout = NULL; 278 float zeropt, exptime, MAX_MAG; 279 psMetadata *ghostModel = NULL; 280 psVector *C_terms; 281 psVector *R_terms; 282 float glintPixelScale; 283 284 psLogMsg ("psastro", PS_LOG_INFO, "determine ghost positions"); 285 286 // select the current recipe 287 psMetadata *recipe = psMetadataLookupPtr (&status, config->recipes, PSASTRO_RECIPE); 288 if (!recipe) { 289 psError(PSASTRO_ERR_CONFIG, true, "Can't find PSASTRO recipe"); 290 return false; 291 } 292 293 bool REFSTAR_MASK_GHOST = psMetadataLookupBool (&status, recipe, "REFSTAR_MASK_GHOST"); 294 if (!REFSTAR_MASK_GHOST) return true; 295 296 // Load model from file 297 char *ghostFile = psMetadataLookupStr (&status, recipe, "GHOST_MODEL"); 298 if (!strcasecmp(ghostFile, "NONE")) return true; 299 psLogMsg("psastro", PS_LOG_INFO, "ghost file %s",ghostFile); 300 if (!pmConfigFileRead (&ghostModel, ghostFile, "GHOST MODEL")) { 301 psError(PSASTRO_ERR_CONFIG, true, "Trouble loading ghost model"); 302 return false; 303 } 304 305 // Allocate FPA and refstars 306 pmFPAview *view = pmFPAviewAlloc (0); 307 // select the input astrometry data (also carries the refstars) 308 pmFPAfile *astrom = psMetadataLookupPtr (NULL, config->files, "PSASTRO.INPUT"); 309 if (!astrom) { 310 psError(PSASTRO_ERR_CONFIG, true, "Can't find input data"); 311 goto escape; 312 } 313 pmFPA *fpa = astrom->fpa; 314 315 char *filter = psMetadataLookupStr (&status, fpa->concepts, "FPA.FILTERID"); 316 psMetadataItem *item = psMetadataLookup(ghostModel, "GHOST.MODEL.HSC"); 317 if (!item) { 318 psLogMsg ("psastro", PS_LOG_INFO, "GHOST.MODEL.HSC data missing"); 319 return false; 320 } 321 if (item->type != PS_DATA_METADATA_MULTI) { 322 psLogMsg ("psastro", PS_LOG_INFO, "GHOST.MODEL.HSC not multi"); 323 return false; 324 } 325 326 psListIterator *iter = psListIteratorAlloc(item->data.list,PS_LIST_HEAD, false); 327 psMetadataItem *refItem = NULL; 328 while ((refItem = psListGetAndIncrement(iter))) { 329 if (refItem->type != PS_DATA_METADATA) { 330 psLogMsg ("psastro", PS_LOG_INFO, "GHOST.MODEL.HSC entry not metadata"); 331 return false; 332 } 333 char *refFilter = psMetadataLookupStr (&status, refItem->data.md, "FILTER"); 334 if (!status) { 335 // psLogMsg ("psastro", PS_LOG_INFO, "a PHOTCODE.DATA recipe folder is missing FILTER"); 336 continue; 337 } 338 if (strcmp(refFilter, filter)) continue; 339 340 C_terms = psMetadataLookupPtr(&status, refItem->data.md, "C_TERMS"); 341 R_terms = psMetadataLookupPtr(&status, refItem->data.md, "R_TERMS"); 342 glintPixelScale = psMetadataLookupF32(&status, refItem->data.md, "SCALE"); 343 } 344 345 // really error-out here? or just skip? 346 if (!psastroZeroPointFromRecipe (&zeropt, &exptime, &MAX_MAG, fpa, recipe)) { 347 psLogMsg ("psastro", PS_LOG_INFO, "failed to load zeropt data from recipe"); 348 goto escape; 349 } 350 351 // recipe values are given in instrumental magnitudes 352 // use the zero point and exposure time to convert to apparent mags: M_ap = M_inst + C_0 + 2.5*log(exptime) 353 float MagOffset = zeropt + 2.5*log10(exptime); 354 MAX_MAG += MagOffset; 355 356 // this loop selects the matched stars for all chips 357 while ((chip = pmFPAviewNextChip (view, fpa, 1)) != NULL) { 358 psTrace ("psastro", 4, "Chip %d: %x %x\n", view->chip, chip->file_exists, chip->process); 359 if (!chip->process || !chip->file_exists) { continue; } 360 if (!chip->fromFPA) { continue; } 361 362 while ((cell = pmFPAviewNextCell (view, fpa, 1)) != NULL) { 363 psTrace ("psastro", 4, "Cell %d: %x %x\n", view->cell, cell->file_exists, cell->process); 364 if (!cell->process || !cell->file_exists) { continue; } 365 366 // process each of the readouts 367 while ((readout = pmFPAviewNextReadout (view, fpa, 1)) != NULL) { 368 if (! readout->data_exists) { continue; } 369 370 // select the raw objects for this readout (loaded in psastroChooseRefstars.c) 371 // XXX : note that we place limits on the refstar sample in psastroChooseRefstars.c: 372 // 1) on chip and 2) < PSASTRO.MAX.NREF. magnitude limits and clump exclusion are only 373 psArray *refstars = psMetadataLookupPtr (&status, readout->analysis, "PSASTRO.REFSTARS"); 374 if (refstars == NULL) { continue; } 375 376 // identify the bright stars of interest 377 for (int i = 0; i < refstars->n; i++) { 378 pmAstromObj *ref = refstars->data[i]; 379 if (ref->Mag > MAX_MAG) continue; 380 381 psastroGhost *ghost = psastroGhostAlloc (); 382 383 double R_TPA = sqrt(pow(ref->TP->y,2) + pow(ref->TP->x,2)); 384 double theta0 = atan2(ref->TP->y,ref->TP->x); 385 double star_radius_deg = R_TPA * glintPixelScale; 386 387 // psTrace("psastro.ghost",5, 388 psLogMsg("psastro",PS_LOG_INFO, 389 "Begin ghost %d/%ld: MAX_MAG: %g; ref_mag: %g @ (%.10g,%.10g) TPA: (%f %f) R: %f %f %f", 390 i,refstars->n,MAX_MAG,ref->Mag,ref->sky->r * 180 / M_PI,ref->sky->d * 180.0 / M_PI,ref->TP->x,ref->TP->y, 391 R_TPA,star_radius_deg,theta0); 392 393 if (star_radius_deg > 0.5) { continue; } 394 395 // Calculate expected position. 396 double C = C_terms->data.F32[0] + C_terms->data.F32[1] * star_radius_deg + C_terms->data.F32[2] * pow(star_radius_deg,2) + 397 C_terms->data.F32[3] * pow(star_radius_deg,3) + C_terms->data.F32[4] * pow(star_radius_deg,4) + 398 C_terms->data.F32[5] * pow(star_radius_deg,5) + C_terms->data.F32[6] * pow(star_radius_deg,6) + 399 C_terms->data.F32[7] * pow(star_radius_deg,7); 400 double R = R_terms->data.F32[0] + R_terms->data.F32[1] * star_radius_deg + R_terms->data.F32[2] * pow(star_radius_deg,2) + 401 R_terms->data.F32[3] * pow(star_radius_deg,3) + R_terms->data.F32[4] * pow(star_radius_deg,4) + 402 R_terms->data.F32[5] * pow(star_radius_deg,5) + R_terms->data.F32[6] * pow(star_radius_deg,6) + 403 R_terms->data.F32[7] * pow(star_radius_deg,7); 404 R = R / 0.015; 405 406 psPlane *fp = psPlaneAlloc(); 407 psPlane *tp = psPlaneAlloc(); 408 409 tp->x = 13.5 * (C * cos(theta0) / 0.015 + 12.78); 410 tp->y = 13.5 * (C * sin(theta0) / 0.015 + 57.74); 411 psPlaneTransformApply(fp,fpa->fromTPA, tp); 412 413 ghost->srcFP->x = ref->FP->x; 414 ghost->srcFP->y = ref->FP->y; 415 ghost->FP->x = fp->x; 416 ghost->FP->y = fp->y; 417 418 ghost->inner.major = 0.0; 419 ghost->inner.minor = 0.0; 420 ghost->outer.major = R; 421 ghost->outer.minor = R; 422 423 pmChip *ghostChip = psastroFindChip (&ghost->chip->x, &ghost->chip->y, fpa, ghost->FP->x, ghost->FP->y); 424 425 if (ghostChip) { 426 psLogMsg("psastro",PS_LOG_INFO, 427 // psTrace("psastro.ghost",5, 428 " in ghost: %d/%ld: ref: (%f,%f) or (%s) ghost: (%f,%f) or (%f,%f,%s) %f inner: (%f,%f,%f) outer: (%f,%f,%f)", 429 i,refstars->n, 430 ref->FP->x,ref->FP->y, 431 psMetadataLookupStr(NULL,chip->concepts,"CHIP.NAME"), 432 ghost->FP->x,ghost->FP->y, 433 ghost->chip->x,ghost->chip->y,psMetadataLookupStr(NULL,ghostChip->concepts,"CHIP.NAME"), 434 C, 435 ghost->inner.major,ghost->inner.minor,ghost->inner.theta, 436 ghost->outer.major,ghost->outer.minor,ghost->outer.theta); 437 } 438 else { 439 psTrace("psastro.ghost",5," in ghost: %d/%ld: ref: (%f,%f) ghost: (%f,%f) or (%f,%f,%s) inner: (%f,%f,%f) outer: (%f,%f,%f)", 440 i,refstars->n, 441 ref->FP->x,ref->FP->y, 442 ghost->FP->x,ghost->FP->y, 443 ghost->chip->x,ghost->chip->y,"NONE", 444 ghost->inner.major,ghost->inner.minor,ghost->inner.theta, 445 ghost->outer.major,ghost->outer.minor,ghost->outer.theta); 446 } 447 448 449 450 if (!ghostChip) goto skip; 451 if (!ghostChip->cells) goto skip; 452 if (!ghostChip->cells->n) goto skip; 453 454 455 pmCell *ghostCell = ghostChip->cells->data[0]; 456 if (!ghostCell) goto skip; 457 if (!ghostCell->readouts) goto skip; 458 if (!ghostCell->readouts->n) goto skip; 459 pmReadout *ghostReadout = ghostCell->readouts->data[0]; 460 if (!ghostReadout) goto skip; 461 462 psArray *ghosts = psMetadataLookupPtr (&status, ghostReadout->analysis, "PSASTRO.GHOSTS"); 463 if (ghosts == NULL) { 464 ghosts = psArrayAllocEmpty (100); 465 if (!psMetadataAdd (ghostReadout->analysis, PS_LIST_TAIL, "PSASTRO.GHOSTS", PS_DATA_ARRAY, "astrometry matches", ghosts)) { 466 psError(PSASTRO_ERR_CONFIG, false, "failure to add ghosts to readout"); 467 goto escape; 468 } 469 psFree (ghosts); 470 } 471 472 psArrayAdd (ghosts, 100, ghost); 473 474 skip: 475 476 psFree (ghost); 477 } 478 } 479 } 480 } 481 482 psastroExtractFreeChipBounds(); 483 484 psFree (C_terms); 485 psFree (R_terms); 486 // psFree (ghostModel); 487 psFree (view); 488 return true; 489 490 escape: 491 psFree (C_terms); 492 psFree (R_terms); 493 // psFree (ghostModel); 494 psFree (view); 495 return false; 496 }
Note:
See TracChangeset
for help on using the changeset viewer.
