Changeset 38289
- Timestamp:
- May 18, 2015, 8:26:24 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/ipp-20150419/Ohana/src/relphot/src/setMrelCatalog.c
r38153 r38289 86 86 // error for the ap mags, but krons have their own errors. it is an open question if I 87 87 // should be doing weighted or unweighted fits (this is a user option) 88 double *Mpsflist = results->Mpsflist; 89 double *dpsflist = results->dpsflist; 90 double *wpsflist = results->wpsflist; 91 92 double *Maplist = results->Maplist; 93 double *daplist = results->daplist; 94 double *waplist = results->waplist; 95 96 double *Mkronlist = results->Mkronlist; 97 double *dkronlist = results->dkronlist; 98 double *wkronlist = results->wkronlist; 88 89 // these lists are pre-allocated to the max length 90 double **Mpsflist = results->Mpsflist; 91 double **dpsflist = results->dpsflist; 92 double **wpsflist = results->wpsflist; 93 94 double **Maplist = results->Maplist; 95 double **daplist = results->daplist; 96 double **waplist = results->waplist; 97 98 double **Mkronlist = results->Mkronlist; 99 double **dkronlist = results->dkronlist; 100 double **wkronlist = results->wkronlist; 99 101 100 102 StatType *psfstats = &results->psfstats; … … 108 110 fprintf (stderr, "test obj\n"); 109 111 print_measure_set_alt (average, secfilt, measure); 112 } 113 114 // first pass: check for PS1[n], Synth, Tycho, 2MASS 115 116 // first, determine the state of things for each of the main filters: 117 // in this bit, we are using hardwired photcode values: 118 // PS1_g, PS1_r, PS1_i, PS1_z, PS1_y, PS1_w == (1,2,3,4,5,6); 0 == none 119 // note that Nsec = PS_N - 1 120 121 int havePS1[7]; 122 int haveSYN[7]; 123 int needSYN[7]; 124 int measSYN[7]; 125 126 int haveTYCHO = FALSE; 127 int have2MASS = FALSE; 128 129 // was: 13.64, 13.76, 13.74, 12.94, 12.01 130 float MaxMagForceSynth[] = {0.0, 13.5, 13.5, 13.5, 13.0, 12.0, 13.5}; 131 // NONE, g, r, i, z, y, w 132 133 for (i = 0; i < 7; i++) { 134 havePS1[i] = FALSE; // do we have any PS1 measurement for this filter? 135 haveSYN[i] = FALSE; // do we have any synthetic measurement for this filter? 136 needSYN[i] = FALSE; // force the use of the synthetic measurement for this filter? 137 measSYN[i] = -1; // which entries carries the synthetic measurement for this filter? 138 } 139 140 for (k = 0; k < average[0].Nmeasure; k++) { 141 142 // skip measurements that do not have a valid photcode (which ones lack photcode?) 143 PhotCode *code = GetPhotcodebyCode (measure[k].photcode); 144 if (!code) continue; 145 146 // is this synth_grizy? 147 // is this PS1? 148 149 // are we a PS1 exposure photcode? 150 if (isGPC1chip(measure[k].photcode)) { 151 int Nfilter = whichGPC1filter (measure[k].photcode); 152 havePS1[Nfilter] = TRUE; 153 } 154 if (isGPC1synth(measure[k].photcode)) { 155 int Nfilter = measure[k].photcode - 3000; 156 haveSYN[Nfilter] = TRUE; 157 measSYN[Nfilter] = k; 158 159 // force the use of SYN even if we have PS1 mags? 160 if (measure[k].M < MaxMagForceSynth[Nfilter]) { 161 needSYN[Nfilter] = TRUE; 162 } 163 } 164 if (isTycho(measure[k].photcode)) { 165 haveTYCHO = TRUE; 166 } 167 if (is2MASS(measure[k].photcode)) { 168 have2MASS = TRUE; 169 } 110 170 } 111 171 … … 450 510 } 451 511 512 // set mean of chip measurements (selected by photcode range for now): 513 int setMrelAverageExposure_old (off_t measureOffset, int cat, int pass, FlatCorrectionTable *flatcorr, SetMrelInfo *results, Average *average, AverageTiny *averageT, SecFilt *secfilt, Measure *measure, MeasureTiny *measureT, off_t *found) { 514 515 off_t k; 516 float Msys = 0, Mcal= 0, Mmos = 0, Mgrid = 0; 517 518 // we are measuring means for 3 types of mags: psf, ap, kron. I am using the psf mag 519 // error for the ap mags, but krons have their own errors. it is an open question if I 520 // should be doing weighted or unweighted fits (this is a user option) 521 double *Mpsflist = results->Mpsflist; 522 double *dpsflist = results->dpsflist; 523 double *wpsflist = results->wpsflist; 524 525 double *Maplist = results->Maplist; 526 double *daplist = results->daplist; 527 double *waplist = results->waplist; 528 529 double *Mkronlist = results->Mkronlist; 530 double *dkronlist = results->dkronlist; 531 double *wkronlist = results->wkronlist; 532 533 StatType *psfstats = &results->psfstats; 534 StatType *apstats = &results->apstats; 535 StatType *kronstats = &results->kronstats; 536 537 int isSetMrelFinal = (pass >= 0); 538 539 // option for a test print 540 if (FALSE && (average[0].objID == 0x7146) && (average[0].catID == 0x49d8)) { 541 fprintf (stderr, "test obj\n"); 542 print_measure_set_alt (average, secfilt, measure); 543 } 544 545 int GoodPS1 = FALSE; 546 int Good2MASS = FALSE; 547 int Galaxy2MASS = FALSE; 548 549 int NextPS1 = 0; 550 int NpsfPS1 = 0; 551 552 int Ns; 553 for (Ns = 0; Ns < Nphotcodes; Ns++) { 554 555 int thisCode = photcodes[Ns][0].code; 556 int Nsec = GetPhotcodeNsec(thisCode); 557 558 /* calculate the average mag in this SEC photcode for a single star */ 559 560 /* star/photcodes already calibrated */ 561 if ( isSetMrelFinal && found[Nsec]) continue; 562 563 // skip bad stars 564 if (!isSetMrelFinal && (secfilt[Nsec].flags & STAR_BAD)) continue; 565 566 int NexpPS1 = 0; 567 int Ncode = 0; 568 int Next = 0; 569 int haveSynth = FALSE; 570 int havePS1 = FALSE; 571 572 int forceSynth = FALSE; 573 int forceSynthEntry = -1; 574 575 int haveUbercal = FALSE; 576 577 int minUbercalDist = 1000; 578 579 off_t meas = measureOffset; 580 581 float psfQfMax = 0.0; 582 float psfQfPerfMax = 0.0; 583 584 int Nap = 0; 585 int Npsf = 0; 586 int Nkron = 0; 587 for (k = 0; k < averageT[0].Nmeasure; k++, meas++) { 588 589 // skip measurements that do not match the current photcode 590 PhotCode *code = GetPhotcodebyCode (measureT[k].photcode); 591 if (!code) continue; 592 if (code->equiv != thisCode) { continue; } 593 Ncode ++; 594 595 // are we a PS1 exposure photcode? 596 if (isGPC1chip(measureT[k].photcode)) NexpPS1 ++; 597 598 // SKIP gpc1 stack data 599 if (isGPC1stack(measureT[k].photcode)) continue; 600 601 // SKIP gpc1 forced-warp data 602 if (isGPC1warp(measureT[k].photcode)) continue; 603 604 if (isSetMrelFinal) { 605 if (measure[k].psfQF > psfQfMax) psfQfMax = measure[k].psfQF; 606 if (measure[k].psfQFperf > psfQfPerfMax) psfQfPerfMax = measure[k].psfQFperf; 607 } 608 609 if (measureT[k].dbFlags & MEAS_BAD) SKIP_THIS_MEAS(Nbad); 610 611 if (getImageEntry (meas, cat) < 0) { 612 // measurements without an image are either external reference photometry or 613 // data for which the associated image has not been loaded (probably because of 614 // overlaps). Msys + measure.Mcal is our best guess of the true magnitude 615 Mmos = Mgrid = 0; 616 Mcal = measureT[k].Mcal; // check that this is zero for loaded REF value 617 } else { 618 Mcal = getMcal_alt (meas, cat, flatcorr, measureT[k].Xccd, measureT[k].Yccd); 619 if (isnan(Mcal)) SKIP_THIS_MEAS(Ncal); 620 Mmos = getMmos (meas, cat); 621 if (isnan(Mmos)) SKIP_THIS_MEAS(Nmos); 622 Mgrid = getMgrid (meas, cat); 623 if (isnan(Mgrid)) SKIP_THIS_MEAS(Ngrid); 624 } 625 626 // skip some absurd values NAN, < 0.0, > 30.0 627 Msys = PhotSysTiny (&measureT[k], &averageT[0], &secfilt[0], MAG_CLASS_PSF); 628 if (isnan(Msys)) SKIP_THIS_MEAS(Nsys); 629 if (Msys < 0.0) SKIP_THIS_MEAS(Nsys); 630 if (Msys > 30.0) SKIP_THIS_MEAS(Nsys); 631 632 int myUbercalDist = getUbercalDist(meas, cat); 633 minUbercalDist = MIN(minUbercalDist, myUbercalDist); 634 635 int isUbercal = (measureT[k].dbFlags & ID_MEAS_PHOTOM_UBERCAL); 636 float dMpsf = MAX (hypot(measureT[k].dM, code->photomErrSys), MIN_ERROR); 637 638 if (isUbercal) haveUbercal = TRUE; // haveUbercal is set per secfilt, isUbercal is per measure 639 640 if (isSetMrelFinal) { 641 // special options for PS1 data 642 if ((measure[k].photcode >= 10000) && (measure[k].photcode <= 10500)) { 643 // count the extended detections 644 if (!isnan(measure[k].Map)) { 645 float dMagAp = measure[k].M - measure[k].Map; 646 float SigmaAp = hypot(0.1, 2.5*measure[k].dM); 647 // XXX this is still quite ad hoc, but at least it: 648 // (a) converges to 0.1 mag offset at the bright end 649 // (b) converges to 0.5 mag offset at the faint end (dM = 0.2) 650 if (dMagAp > SigmaAp) { 651 Next ++; 652 NextPS1 ++; 653 } else { 654 NpsfPS1 ++; 655 } 656 } 657 havePS1 = TRUE; 658 } 659 660 // count extended detections for 2MASS (XXX NOTE hardwired photcodes 2011, 2012, 2013) 661 if ((measure[k].photcode >= 2011) && (measure[k].photcode <= 2013)) { 662 if (measure[k].photFlags & 0x00c00000) { 663 Next ++; 664 Galaxy2MASS = TRUE; 665 } 666 if (pass == 0) { 667 if (measure[k].photFlags & 0x00000007) { 668 Good2MASS = TRUE; 669 } else { 670 // detections without one of these bits should only be used in PASS_1 671 SKIP_THIS_MEAS(Nbad); 672 } 673 } 674 } 675 676 // Blindly accepth the SYNTH mags if we are above saturation, otherwise, 677 // ignore SYNTH photcodes until PASS == 4 (where we also accept saturated stars) 678 if ((measure[k].photcode >= 3001) && (measure[k].photcode <= 3005)) { 679 // something of a hack: force object to use synth values if synth mags >> 680 // saturation (3pi instrumental mags < -15) 681 float MaxMagForceSynth = NAN; 682 switch (measure[k].photcode) { 683 case 3001: 684 MaxMagForceSynth = 13.64; 685 break; 686 case 3002: 687 MaxMagForceSynth = 13.76; 688 break; 689 case 3003: 690 MaxMagForceSynth = 13.74; 691 break; 692 case 3004: 693 MaxMagForceSynth = 12.94; 694 break; 695 case 3005: 696 MaxMagForceSynth = 12.01; 697 break; 698 } 699 if (measureT[k].M < MaxMagForceSynth) { 700 forceSynth = TRUE; 701 forceSynthEntry = Npsf; 702 } else { 703 if (pass < 4) { 704 SKIP_THIS_MEAS(Nbad); 705 } 706 haveSynth = TRUE; 707 } 708 } 709 710 // Map (Maplist) and Mkron (Mkronlist,dkronlist) are used to calculate mean mags per filter 711 float Map = PhotCat (&measure[k], MAG_CLASS_APER); 712 if (!isnan(Map)) { 713 Maplist[Nap] = Map - Mcal - Mmos - Mgrid; 714 daplist[Nap] = dMpsf;// XXX check on this... 715 waplist[Nap] = isUbercal ? UBERCAL_WEIGHT : 1.0; 716 Nap ++; 717 } 718 719 float Mkron = PhotCat (&measure[k], MAG_CLASS_KRON); 720 if (!isnan(Mkron)) { 721 Mkronlist[Nkron] = Mkron - Mcal - Mmos - Mgrid; 722 dkronlist[Nkron] = measure[k].dMkron; 723 wkronlist[Nkron] = isUbercal ? UBERCAL_WEIGHT : 1.0; 724 Nkron ++; 725 } 726 } // if (isSetMrelFinal) 727 728 // dlist gives the error per measurement, wlist gives the weight 729 // we can modify the error and weight in a few ways: 730 // 1) MIN_ERROR guarantees a floor 731 // 2) photomErrSys is added in quadrature as a sytematic error, set per photcode 732 // 3) UBERCAL measurements can have their weight increased by a big factor to help tie down the averages 733 // 4) some reference photcode of some kind can be specified as fixed and have a high weight 734 Mpsflist[Npsf] = Msys - Mcal - Mmos - Mgrid; 735 dpsflist[Npsf] = dMpsf; 736 wpsflist[Npsf] = isUbercal ? UBERCAL_WEIGHT : 1.0; 737 738 // NOTE: 739 // Msys is measure[i].M + zp corrections 740 // Mcal is image[j].Mcal 741 // Mmos and Mgrid are offsets for mosaic and grid 742 743 // tie down reference photometry if the -refcode (code) option is selected 744 // eg, -refcode g_SDSS 745 // this probably makes no sense in the context of multifilter analysis 746 // XXX probably need to use the photocde table to assign reference mag weights. 747 if (refPhotcode) { 748 if (code->code == refPhotcode->code) { 749 wpsflist[Npsf] = UBERCAL_WEIGHT; 750 } 751 } 752 Npsf ++; 753 } 754 755 int Nminmeas = isSetMrelFinal ? 1 : STAR_TOOFEW + 1; 756 757 // XXX : ugh : another hard-wired photcode entry... 758 if (isSetMrelFinal && (pass == 0)) { 759 if ((thisCode < 6) || (thisCode == 9)) { 760 secfilt[Nsec].Ncode = NexpPS1; 761 } else { 762 secfilt[Nsec].Ncode = Ncode; // 2MASS data if it exists 763 } 764 } 765 766 // when performing the grid analysis, STAR_TOOFEW should be set to 1; 767 if (Npsf < Nminmeas) { /* too few measurements */ 768 // fprintf (f, "%10.6f %10.6f %d %d %d\n", averageT[0].R, averageT[0].D, measureT[0].imageID, Npsf, STAR_TOOFEW); 769 secfilt[Nsec].flags |= ID_STAR_FEW; 770 if (Ncode == 0) { 771 results->Ncode ++; 772 } else { 773 results->Nfew ++; 774 } 775 continue; 776 } else { 777 secfilt[Nsec].flags &= ~ID_STAR_FEW; 778 } 779 780 if (forceSynth) { 781 // use the single SYNTH value instead of the other mags here 782 myAssert ((forceSynthEntry < Npsf) && (forceSynthEntry >= 0), "programming error"); 783 Mpsflist[0] = Mpsflist[forceSynthEntry]; 784 dpsflist[0] = dpsflist[forceSynthEntry]; 785 wpsflist[0] = wpsflist[forceSynthEntry]; 786 Npsf = 1; 787 } 788 liststats (Mpsflist, dpsflist, wpsflist, Npsf, psfstats); 789 790 secfilt[Nsec].M = psfstats->mean; 791 secfilt[Nsec].dM = psfstats->error; 792 secfilt[Nsec].Mchisq = (psfstats->Nmeas > 1) ? psfstats->chisq : NAN; 793 794 // when running -averages, we have no information about the images, so we cannot set this 795 if (minUbercalDist > -1) { 796 secfilt[Nsec].ubercalDist = minUbercalDist; 797 } 798 799 if (isSetMrelFinal) { 800 found[Nsec] = TRUE; 801 802 secfilt[Nsec].Mstdev = psfstats->sigma; // Mstdev is in millimags (not enough space for more precision) 803 // secfilt[Nsec].Ncode = Ncode; 804 secfilt[Nsec].Nused = psfstats->Nmeas; 805 806 secfilt[Nsec].Mmax = psfstats->max; 807 secfilt[Nsec].Mmin = psfstats->min; 808 809 secfilt[Nsec].psfQfMax = psfQfMax; 810 secfilt[Nsec].psfQfPerfMax = psfQfPerfMax; 811 812 // NOTE : use the modified weight for apmags as well as psf mags 813 liststats (Maplist, daplist, waplist, Nap, apstats); 814 secfilt[Nsec].Map = Nap > 0 ? apstats->mean : NAN; 815 secfilt[Nsec].dMap = Nap > 0 ? apstats->error : NAN; 816 secfilt[Nsec].sMap = Nap > 0 ? apstats->sigma : NAN; 817 secfilt[Nsec].NusedAp = Nap; 818 819 liststats (Mkronlist, dkronlist, wkronlist, Nkron, kronstats); 820 secfilt[Nsec].Mkron = Nkron > 0 ? kronstats->mean : NAN; 821 secfilt[Nsec].dMkron = Nkron > 0 ? kronstats->error : NAN; 822 secfilt[Nsec].sMkron = Nkron > 0 ? kronstats->sigma : NAN; 823 secfilt[Nsec].NusedKron = Nkron; 824 825 // NOTE: for 2MASS measurements, Next should be 1, as should N 826 if ((Next > 0) && (Next > 0.5*Npsf)) { 827 secfilt[Nsec].flags |= ID_SECF_OBJ_EXT; 828 } 829 830 switch (pass) { 831 case 0: 832 secfilt[Nsec].flags |= ID_PHOTOM_PASS_0; 833 if (havePS1) GoodPS1 = TRUE; 834 break; 835 case 1: 836 secfilt[Nsec].flags |= ID_PHOTOM_PASS_1; 837 if (havePS1) GoodPS1 = TRUE; 838 break; 839 case 2: 840 secfilt[Nsec].flags |= ID_PHOTOM_PASS_2; 841 if (havePS1) GoodPS1 = TRUE; 842 break; 843 case 3: 844 secfilt[Nsec].flags |= ID_PHOTOM_PASS_3; 845 break; 846 case 4: 847 secfilt[Nsec].flags |= ID_PHOTOM_PASS_4; 848 break; 849 } 850 if (haveSynth) { 851 secfilt[Nsec].flags |= ID_SECF_USE_SYNTH; 852 } 853 if (havePS1) { 854 secfilt[Nsec].flags |= ID_SECF_HAS_PS1; 855 } 856 if (haveUbercal) { 857 secfilt[Nsec].flags |= ID_SECF_USE_UBERCAL; 858 } 859 } 860 } 861 862 if (isSetMrelFinal) { 863 if (pass == 0) { 864 DVOAverageFlags flagBits = ID_OBJ_EXT | ID_OBJ_EXT_ALT | ID_OBJ_GOOD | ID_OBJ_GOOD_ALT; 865 // we attempt to set a few flags here; reset those bits before trying: 866 average[0].flags &= ~flagBits; 867 } 868 869 if (NextPS1 && (NextPS1 > NpsfPS1)) { 870 average[0].flags |= ID_OBJ_EXT; 871 } 872 if (GoodPS1) { 873 average[0].flags |= ID_OBJ_GOOD; 874 } 875 if (Galaxy2MASS) { 876 average[0].flags |= ID_OBJ_EXT_ALT; 877 } 878 if (Good2MASS) { 879 average[0].flags |= ID_OBJ_GOOD_ALT; 880 } 881 } 882 return (TRUE); 883 } 884 452 885 // only apply Stack operation on setMrelFinal in first pass 453 886 // this function has 3 goals, not to be confused:
Note:
See TracChangeset
for help on using the changeset viewer.
