Changeset 40490 for trunk/psastro/src/psastroLoadGlints.c
- Timestamp:
- Jun 27, 2018, 4:11:05 PM (8 years ago)
- Location:
- trunk/psastro
- Files:
-
- 2 edited
-
. (modified) (1 prop)
-
src/psastroLoadGlints.c (modified) (3 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/psastroLoadGlints.c
r24645 r40490 44 44 double GLINT_LENGTH_MAG_ZERO = psMetadataLookupF32 (&status, recipe, "GLINT_LENGTH_MAG_ZERO"); 45 45 double glintWidth = psMetadataLookupF32 (&status, recipe, "GLINT_WIDTH"); 46 double pixelScale = psMetadataLookupF32 (&status, recipe, "PSASTRO.PIXEL.SCALE"); 47 46 48 47 49 // select the set of glint regions (GLINT.REGION is a MULTI of METADATA items) … … 95 97 psProject (star->TP, star->sky, fpa->toSky); 96 98 psPlaneTransformApply (star->FP, fpa->fromTPA, star->TP); 97 fprintf (stderr, "glint: %7.2f @ %8.1f, %8.1f \n", star->Mag, star->FP->x, star->FP->y);99 fprintf (stderr, "glint: %7.2f @ %8.1f, %8.1f (%f %f) %8.1f %8.1f\n", star->Mag, star->FP->x, star->FP->y, star->sky->r * PS_DEG_RAD, star->sky->d * PS_DEG_RAD, star->TP->x,star->TP->y); 98 100 99 101 // find the GLINT.REGION this star lands in (if any) … … 298 300 } 299 301 } 302 if (!strcasecmp(glintType, "HSC")) { 303 // It's inefficient to keep looking these up. 304 double GLINT_RADIUS_INNER = psMetadataLookupF32(&status, glintItem->data.md, "GLINT.RADIUS.INNER"); 305 double GLINT_RADIUS_OUTER = psMetadataLookupF32(&status, glintItem->data.md, "GLINT.RADIUS.OUTER"); 306 307 // double R_FPA = sqrt(pow(star->FP->y,2) + pow(star->FP->x,2)); 308 double R_FPA = sqrt(pow(star->TP->y,2) + pow(star->TP->x,2)); 309 // R_FPA *= 1.30; 310 if (R_FPA < GLINT_RADIUS_INNER) { continue; } 311 if (R_FPA > GLINT_RADIUS_OUTER) { continue; } 312 psTrace("psastro.masks",4,"HSC_GLINT_STARS: %f %f %f\n", 313 // star->FP->x,star->FP->y,star->Mag); 314 star->TP->x,star->TP->y,star->Mag); 315 psVector *C_terms; 316 psVector *R_terms; 317 double scale_factor = 1.0; 318 319 char *filter = psMetadataLookupStr (&status, fpa->concepts, "FPA.FILTERID"); 320 psMetadataItem *item = psMetadataLookup(glintItem->data.md, "GLINT.FILTER.TERM"); 321 if (!item) { 322 psLogMsg ("psastro", PS_LOG_INFO, "GLINT.FILTER.TERM data missing"); 323 return false; 324 } 325 if (item->type != PS_DATA_METADATA_MULTI) { 326 psLogMsg ("psastro", PS_LOG_INFO, "GLINT.FILTER.TERM not multi"); 327 return false; 328 } 329 psListIterator *iter = psListIteratorAlloc(item->data.list,PS_LIST_HEAD, false); 330 psMetadataItem *refItem = NULL; 331 while ((refItem = psListGetAndIncrement(iter))) { 332 if (refItem->type != PS_DATA_METADATA) { 333 psLogMsg ("psastro", PS_LOG_INFO, "GLINT.FILTER.TERM entry not metadata"); 334 return false; 335 } 336 char *refFilter = psMetadataLookupStr (&status, refItem->data.md, "FILTER"); 337 if (!status) { 338 // psLogMsg ("psastro", PS_LOG_INFO, "a PHOTCODE.DATA recipe folder is missing FILTER"); 339 continue; 340 } 341 if (strcmp(refFilter, filter)) continue; 342 343 C_terms = psMetadataLookupPtr(&status, refItem->data.md, "C_TERMS"); 344 R_terms = psMetadataLookupPtr(&status, refItem->data.md, "R_TERMS"); 345 scale_factor = psMetadataLookupF32(&status, refItem->data.md, "FACTOR"); 346 double limit = psMetadataLookupF32(&status, refItem->data.md, "LIMIT"); 347 limit += MagOffset; 348 if (star->Mag > limit) { continue; } 349 } 350 // check 351 double glintPixelScale = psMetadataLookupF32(&status, glintItem->data.md, "GLINT.PIXEL.SCALE"); 352 // psMetadata *GLINT_PARAMETER_SET = psMetadataLookupPtr(&status, glintItem->data.md, "GLINT.FILTER.TERM"); 353 // psMetadata *GLINT_PARAMETERS = psMetadataLookupPtr(&status, GLINT_PARAMETER_SET, filter); 354 355 356 // double theta0 = atan2(star->FP->y,star->FP->x); 357 double theta0 = atan2(star->TP->y,star->TP->x); 358 double star_radius_deg = R_FPA * glintPixelScale; 359 360 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); 361 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); 362 363 double inner_edge_angle, outer_edge_angle; 364 if (star_radius_deg < 0.8831) { 365 outer_edge_angle = 0.0; 366 } 367 else if (star_radius_deg < 0.9368) { 368 outer_edge_angle = 46.2985 * sqrt(star_radius_deg - 0.8831); 369 } 370 else { 371 outer_edge_angle = -2.67 + 14.3 * star_radius_deg; 372 } 373 if (star_radius_deg < 0.964) { 374 inner_edge_angle = -243.866 * pow(star_radius_deg - 0.932,2) + 2.4636; 375 } 376 else { 377 inner_edge_angle = 66.2061 * sqrt(star_radius_deg - 0.9635); 378 } 379 380 inner_edge_angle = inner_edge_angle * PS_RAD_DEG; 381 outer_edge_angle = outer_edge_angle * PS_RAD_DEG; 382 383 // These define the ends of a single arc in arc-centric coordinates 384 double x1 = C - R * cos(inner_edge_angle); 385 double y1 = R * sin(inner_edge_angle); 386 double x2 = C - R * cos(outer_edge_angle); 387 double y2 = R * sin(outer_edge_angle); 388 389 // Create the endpoints for the pair of arcs in device coordinates (in millimeters) 390 double theta1 = theta0 + M_PI / 2.0; 391 double x1s = (x1 * cos(theta1) - y1 * sin(theta1)) * scale_factor; 392 double y1s = (y1 * cos(theta1) + x1 * sin(theta1)) * scale_factor; 393 double x1e = (x2 * cos(theta1) - y2 * sin(theta1)) * scale_factor; 394 double y1e = (y2 * cos(theta1) + x2 * sin(theta1)) * scale_factor; 395 396 double x2s = (x1 * cos(theta1) + y1 * sin(theta1)) * scale_factor; 397 double y2s = (-1.0 * y1 * cos(theta1) + x1 * sin(theta1)) * scale_factor; 398 double x2e = (x2 * cos(theta1) + y2 * sin(theta1)) * scale_factor; 399 double y2e = (-1.0 * y2 * cos(theta1) + x2 * sin(theta1)) * scale_factor; 400 401 psVector *x_start = psVectorAlloc(4,PS_TYPE_F32); 402 psVector *y_start = psVectorAlloc(4,PS_TYPE_F32); 403 psVector *x_end = psVectorAlloc(4,PS_TYPE_F32); 404 psVector *y_end = psVectorAlloc(4,PS_TYPE_F32); 405 406 // CZW: I know this looks like a typo, but trust me, it's not a typo. 407 psPlane *fp = psPlaneAlloc(); 408 psPlane *tp = psPlaneAlloc(); 409 410 fprintf(stderr,"HSC GLINT %f: x1x2(%f %f) (%f %f) x1sx1e (%f %f %f %f) x2sx2e (%f %f %f %f)\n", 411 star->Mag, 412 x1,y1,x2,y2, 413 x1s,y1s,x1e,y1e, 414 x2s,y2s,x2e,y2e); 415 416 417 tp->x = 13.5 * (y1s / 0.015 + 12.78); 418 tp->y = 13.5 * (x1s / -0.015 + 57.74); 419 psPlaneTransformApply(fp,fpa->fromTPA, tp); 420 x_start->data.F32[0] = fp->x; 421 y_start->data.F32[0] = fp->y; 422 // x_start->data.F32[0] = tp->x; 423 // y_start->data.F32[0] = tp->y; 424 425 tp->x = 13.5 * (y1e / 0.015 + 12.78); 426 tp->y = 13.5 * (x1e / -0.015 + 57.74); 427 psPlaneTransformApply(fp,fpa->fromTPA, tp); 428 x_end->data.F32[0] = fp->x; 429 y_end->data.F32[0] = fp->y; 430 // x_end->data.F32[0] = tp->x; 431 // y_end->data.F32[0] = tp->y; 432 433 x_start->data.F32[1] = x_end->data.F32[0]; 434 y_start->data.F32[1] = y_end->data.F32[0]; 435 x_end->data.F32[1] = x_start->data.F32[0]; 436 y_end->data.F32[1] = y_start->data.F32[0]; 437 438 tp->x = 13.5 * (y2s / 0.015 + 12.78); 439 tp->y = 13.5 * (x2s / -0.015 + 57.74); 440 psPlaneTransformApply(fp,fpa->fromTPA, tp); 441 x_start->data.F32[2] = fp->x; 442 y_start->data.F32[2] = fp->y; 443 // x_start->data.F32[2] = tp->x; 444 // y_start->data.F32[2] = tp->y; 445 446 tp->x = 13.5 * (y2e / 0.015 + 12.78); 447 tp->y = 13.5 * (x2e / -0.015 + 57.74); 448 psPlaneTransformApply(fp,fpa->fromTPA, tp); 449 x_end->data.F32[2] = fp->x; 450 y_end->data.F32[2] = fp->y; 451 // x_end->data.F32[2] = tp->x; 452 // y_end->data.F32[2] = tp->y; 453 454 x_start->data.F32[3] = x_end->data.F32[2]; 455 y_start->data.F32[3] = y_end->data.F32[2]; 456 x_end->data.F32[3] = x_start->data.F32[2]; 457 y_end->data.F32[3] = y_start->data.F32[2]; 458 459 psFree(fp); 460 psFree(tp); 461 462 for (int glint_point = 0; glint_point < 4; glint_point++) { 463 for (int nChip = 0; nChip < fpa->chips->n; nChip++) { 464 pmChip *chip = fpa->chips->data[nChip]; 465 if (!chip) continue; 466 467 if (!psastroFindChipInYrange (fpa, nChip, x_start->data.F32[glint_point], y_start->data.F32[glint_point])) { 468 continue; 469 } 470 if (!psastroFindChipInXrange (fpa, nChip, x_start->data.F32[glint_point], y_start->data.F32[glint_point])) { 471 continue; 472 } 473 474 double xChip0, yChip0, xChip1, yChip1, chip_angle, glint_length; 475 psastroFPAtoChip (&xChip0, &yChip0, fpa, nChip, x_start->data.F32[glint_point], y_start->data.F32[glint_point]); 476 psastroFPAtoChip (&xChip1, &yChip1, fpa, nChip, x_end->data.F32[glint_point], y_end->data.F32[glint_point]); 477 478 chip_angle = atan2(yChip1 - yChip0, xChip1 - xChip0); 479 glint_length = sqrt(pow(yChip1 - yChip0,2) + pow(xChip1 - xChip0,2)); 480 481 // select the 0th readout of the 0th cell for this chip 482 if (!chip->cells) continue; 483 if (!chip->cells->n) continue; 484 pmCell *glintCell = chip->cells->data[0]; 485 if (!glintCell) continue; 486 if (!glintCell->readouts) continue; 487 if (!glintCell->readouts->n) continue; 488 pmReadout *glintReadout = glintCell->readouts->data[0]; 489 if (!glintReadout) continue; 490 491 // save the glints on the readout->analysis metadata, creating if needed 492 psArray *glints = psMetadataLookupPtr (&status, glintReadout->analysis, "PSASTRO.GLINTS.HSC"); 493 if (glints == NULL) { 494 glints = psArrayAllocEmpty (100); 495 if (!psMetadataAdd (glintReadout->analysis, PS_LIST_TAIL, "PSASTRO.GLINTS.HSC", PS_DATA_ARRAY, "astrometry matches", glints)) { 496 psWarning("failure to add glints to readout"); 497 psFree (glints); 498 continue; 499 } 500 psFree (glints); 501 } 502 503 fprintf (stderr, "glint %s : %d %f,%f to %f,%f (%f %f %f)\n", glintType, nChip, xChip0, yChip0, xChip1, yChip1, glint_length, glintWidth, chip_angle); 504 psTrace("psastro.masks",4,"HSC_GLINT: Star: %f %f Glint CR %f %f Parameters: %f %f %f Ends: %f %f -> %f %f Chip: %f %f -> %f %f @ %s %f\n", 505 star->FP->x,star->FP->y, 506 C,R, 507 inner_edge_angle,outer_edge_angle,theta0, 508 x_start->data.F32[glint_point],y_start->data.F32[glint_point],x_end->data.F32[glint_point],y_end->data.F32[glint_point], 509 xChip0,yChip0,xChip1,yChip1, 510 psMetadataLookupStr(&status,glintReadout->parent->parent->concepts,"CHIP.NAME"),chip_angle); 511 psVector *glint = psVectorAlloc(5,PS_TYPE_F32); 512 glint->data.F32[0] = xChip0; 513 glint->data.F32[1] = yChip0; 514 glint->data.F32[2] = glint_length * pixelScale / pixelScale; 515 glint->data.F32[3] = glintWidth; 516 glint->data.F32[4] = chip_angle; 517 518 psArrayAdd (glints, 100, glint); 519 520 psFree (glint); 521 } // End loop over chips 522 } // End loop over glint endpoints 523 524 psFree(x_start); 525 psFree(x_end); 526 psFree(y_start); 527 psFree(y_end); 528 } // End HSC glint block 529 300 530 } 301 531 }
Note:
See TracChangeset
for help on using the changeset viewer.
