Changeset 40248
- Timestamp:
- Dec 6, 2017, 8:25:46 AM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/ohana.20170822/src/relphot/src/setMrelCatalog.c
r40246 r40248 540 540 SecFilt *secfilt = &catalog[0].secfilt[ave*Nsecfilt]; 541 541 542 off_t k;543 544 542 float McalPSF = 0, McalAPER = 0, Mmos = 0, Mgrid = 0; 545 543 … … 558 556 int haveStackObject = FALSE; 559 557 560 int Ns; 561 for (Ns = 0; Ns < Nphotcodes; Ns++) { 558 for (int Ns = 0; Ns < Nphotcodes; Ns++) { 562 559 563 560 int thisCode = photcodes[Ns][0].code; … … 568 565 int haveStack = FALSE; 569 566 570 float psfQFbest = 0.0;571 float SNbest = 0.0;572 573 off_t stackBestMeasure = -1;574 567 off_t stackPrimaryMeasure = -1; 575 568 … … 577 570 int isSuspect = FALSE; 578 571 579 int Nstack = 0; // number for this photcode 580 int NstackDet = 0; // number for this photcode 572 int NstackMeas = 0; // number of stack measurements for this photcode 573 int NstackDet = 0; // number of stack detections for this photcode (not forced) 574 575 int bestLevelMax = 0; 576 off_t bestEntryMax = -1; 577 float bestValueMax = 0.0; 578 579 int Nprimary = 0; 581 580 582 581 secfilt[Nsec].stackBestOff = -1; … … 584 583 585 584 off_t meas = measureOffset; 586 for ( k = 0; k < Nmeasure; k++, meas++) {585 for (off_t k = 0; k < Nmeasure; k++, meas++) { 587 586 588 587 // only examine gpc1 stack data … … 594 593 if (code->equiv != thisCode) { continue; } 595 594 596 Nstack ++;595 NstackMeas ++; 597 596 if ((measure[k].photFlags2 & 0x00000004) == 0) NstackDet ++; 598 597 … … 603 602 haveStack = TRUE; 604 603 haveStackObject = TRUE; 604 605 XXX ??? if (measure[k].dbFlags & MEAS_BAD) SKIP_THIS_MEAS_STACK(Nbad); 606 607 int isPrimary = FALSE; 605 608 606 // ** find the PRIMARY measurement607 608 // if we request the primary (USE_TREE_FOR_PRIMARY), this is true if the measurement is from the609 // primary skycell for this position609 // ** is this a PRIMARY measurement? (there may be more than one) 610 611 // if we request the primary (USE_TREE_FOR_PRIMARY), this is true if the measurement 612 // is from the primary skycell for this position 610 613 if (MatchImageSkycellID (meas, cat, tessID, projectID, skycellID)) { 611 stackPrimaryMeasure = k;612 614 measure[k].dbFlags |= ID_MEAS_STACK_PRIMARY; 613 secfilt[Nsec].stackPrmryOff = meas; 614 myAssert (secfilt[Nsec].stackPrmryOff <= catalog[0].Nmeasure, "stackPrmryOff out of range"); 615 } 616 617 // ** now choose the BEST measurements (may also be PRIMARY) 618 619 // ensure that we at least have a single best measure 620 if (stackBestMeasure == -1) stackBestMeasure = k; 621 622 // choose the best psfQFperf value for the BEST measurement 623 if (isfinite(measure[k].psfQFperf) && (measure[k].psfQFperf > psfQFbest)) { 624 psfQFbest = measure[k].psfQFperf; 625 stackBestMeasure = k; 626 } 627 // ... UNLESS psfQFperf > 0.98 for the primary, in which case just use the primary. 628 if ((measure[k].dbFlags & ID_MEAS_STACK_PRIMARY) && isfinite(measure[k].psfQFperf) && (measure[k].psfQFperf > 0.98)) { 629 psfQFbest = 1000; // force this to be the best entry 630 stackBestMeasure = k; 631 } 632 633 if (measure[k].dbFlags & MEAS_BAD) SKIP_THIS_MEAS_STACK(Nbad); 634 615 isPrimary = TRUE; 616 Nprimary ++; 617 } 618 619 int psfQFperfAboveLimit = isfinite(measure[k].psfQFperf) && (measure[k].psfQFperf > 0.95); 620 621 // ** determine the BEST level 622 int bestLevel = 0; 623 if (!isPrimary && !psfQFperfAboveLimit) bestLevel = 1; 624 if ( isPrimary && !psfQFperfAboveLimit) bestLevel = 2; 625 if (!isPrimary && psfQFperfAboveLimit) bestLevel = 3; 626 if ( isPrimary && psfQFperfAboveLimit) bestLevel = 4; 627 628 // here is the rule for choosing the best value: 629 // XXX what if dM = 0.0 or NAN? (treat as bestLevel 1 or 2?) 630 bestValue = (bestLevel > 2) ? 1.0 / measure[k].dM : measure[k].psfQFperf; 631 632 // if we have not reached this level before, set the new level 633 if (bestLevelMax < bestLevel) { 634 bestValueMax = bestValue; 635 bestLevelMax = bestLevel; 636 bestEntryMax = k; 637 } 638 // if we have reached this level before, set the new value if we beat the old one 639 if ((bestLevelMax == bestLevel) && (bestValueMax < bestValue)) { 640 bestValueMax = bestValue; 641 bestEntryMax = k; 642 } 643 myAssert (bestEntryMax > -1, "this should not happen"); 644 645 // ** determine the PRIMARY level 646 int primaryLevel = 0; 647 if ( isPrimary && !psfQFperfAboveLimit) primaryLevel = 1; 648 if ( isPrimary && psfQFperfAboveLimit) primaryLevel = 2; 649 650 // here is the rule for choosing the PRIMARY value: 651 // XXX what if dM = 0.0 or NAN? (treat as bestLevel 1 or 2?) 652 primaryValue = 0.0; 653 if (primaryLevel == 1) { primaryValue = measure[k].psfQFperf; } 654 if (primaryLevel == 2) { primaryValue = 1.0 / measure[k].dM; } 655 656 // if we have not reached this level before, set the new level 657 if (isPrimary && (primaryLevelMax < primaryLevel)) { 658 primaryValueMax = primaryValue; 659 primaryLevelMax = primaryLevel; 660 primaryEntryMax = k; 661 } 662 // if we have reached this level before, set the new value if we beat the old one 663 if (isPrimary && (primaryLevelMax == primaryLevel) && (primaryValueMax < primaryValue)) { 664 primaryValueMax = primaryValue; 665 primaryEntryMax = k; 666 } 667 } 668 669 // if we do not have a stack measurement for this photcode, skip everything below 670 if (!haveStack) continue; 671 672 // now we have a BEST and a PRIMARY entry (may be the same entry) 673 674 secfilt[Nsec].stackPrmryOff = (primaryEntryMax == -1) ? -1 : primaryEntryMax + measureOffset; 675 myAssert (secfilt[Nsec].stackPrmryOff <= catalog[0].Nmeasure, "stackPrmryOff out of range"); 676 677 meas = bestEntryMax; 678 myAssert (meas >= 0, "this should not happen"); 679 680 // measurements without an image are either external reference photometry or 681 // data for which the associated image has not been loaded (probably because of 682 // overlaps). we only want measurements associated with stack images in this loop 683 684 // match measurement to its image (this is just a check, right?) 685 if (getImageEntry (meas, cat) < 0) { 635 686 // measurements without an image are either external reference photometry or 636 687 // data for which the associated image has not been loaded (probably because of 637 // overlaps). we only want measurements associated with stack images in this loop 638 639 // match measurement to its image (this is just a check, right?) 640 if (getImageEntry (meas, cat) < 0) { 641 // measurements without an image are either external reference photometry or 642 // data for which the associated image has not been loaded (probably because of 643 // overlaps). Msys + measure.Mcal is our best guess of the true magnitude 644 Mmos = Mgrid = 0; 645 McalPSF = measure[k].McalPSF; // check that this is zero for loaded REF value 646 McalAPER = McalPSF; // check that this is zero for loaded REF value 647 } else { 648 McalPSF = getMcal (meas, cat, MAG_CLASS_PSF); 649 if (isnan(McalPSF)) SKIP_THIS_MEAS_STACK(Ncal); // XXX really skip? 650 651 McalAPER = getMcal (meas, cat, MAG_CLASS_KRON); 652 if (isnan(McalAPER)) SKIP_THIS_MEAS_STACK(Ncal); // XXX really skip? 653 654 Mmos = getMmos (meas, cat); 655 if (isnan(Mmos)) SKIP_THIS_MEAS_STACK(Nmos); 656 Mgrid = getMgrid (meas, cat); 657 if (isnan(Mgrid)) SKIP_THIS_MEAS_STACK(Ngrid); 658 } 659 660 // NOTE: negative and insignificant flux values are allowed, but not NAN flux values 661 float Finst = PhotFluxInst (&measure[k], MAG_CLASS_PSF); 662 if (isnan(Finst)) SKIP_THIS_MEAS_STACK(Ninst); 663 664 // data quality assessment 665 isBad |= (measure[k].photFlags & code->photomBadMask); 666 isBad |= (measure[k].psfQF < 0.85); 667 isBad |= isnan(measure[k].psfQF); 668 isBad |= measure[k].dM > 0.2; // S/N < 5.0 669 670 isSuspect |= (measure[k].photFlags & code->photomPoorMask); 671 isSuspect |= (measure[k].psfQFperf < 0.85); 672 } 673 674 if (!haveStack) continue; 688 // overlaps). Msys + measure.Mcal is our best guess of the true magnitude 689 Mmos = Mgrid = 0; 690 McalPSF = measure[meas].McalPSF; // check that this is zero for loaded REF value 691 McalAPER = McalPSF; // check that this is zero for loaded REF value 692 } else { 693 McalPSF = getMcal (meas, cat, MAG_CLASS_PSF); 694 if (isnan(McalPSF)) SKIP_THIS_MEAS_STACK(Ncal); // XXX really skip? 695 696 McalAPER = getMcal (meas, cat, MAG_CLASS_KRON); 697 if (isnan(McalAPER)) SKIP_THIS_MEAS_STACK(Ncal); // XXX really skip? 698 699 Mmos = getMmos (meas, cat); 700 if (isnan(Mmos)) SKIP_THIS_MEAS_STACK(Nmos); 701 Mgrid = getMgrid (meas, cat); 702 if (isnan(Mgrid)) SKIP_THIS_MEAS_STACK(Ngrid); 703 } 704 705 // NOTE: negative and insignificant flux values are allowed, but not NAN flux values 706 float Finst = PhotFluxInst (&measure[meas], MAG_CLASS_PSF); 707 if (isnan(Finst)) SKIP_THIS_MEAS_STACK(Ninst); 708 709 // data quality assessment 710 isBad |= (measure[meas].photFlags & code->photomBadMask); 711 isBad |= (measure[meas].psfQF < 0.85); 712 isBad |= isnan(measure[meas].psfQF); 713 isBad |= measure[meas].dM > 0.2; // S/N < 5.0 714 715 isSuspect |= (measure[meas].photFlags & code->photomPoorMask); 716 isSuspect |= (measure[meas].psfQFperf < 0.85); 675 717 676 718 if (!isSuspect && !isBad) { … … 680 722 NstackSuspect ++; 681 723 } 682 683 // measurements which are bad will not have a valid stack entry and are skipped 684 k = (stackBestMeasure >= 0) ? stackBestMeasure : stackPrimaryMeasure; 685 if (k < 0) continue; 686 724 687 725 // we are now populating stackDetectID not stack Image ID in secfilt 688 726 // ID = (stackPrimaryMeasureMin >= 0) ? stackPrimaryIDmin : stackCenterIDmin; 689 // ID = measure[k].extID; // for the stack, this is the stackDetectID 690 691 // get the zero point for the selected image 692 // Use a different zero point for the PSF-like and APERTURE-like magnitudes 693 float zpPSF = PhotZeroPoint (&measure[k], &average[0], &secfilt[0]) - (McalPSF + Mmos + Mgrid); 694 float zpAPER = PhotZeroPoint (&measure[k], &average[0], &secfilt[0]) - (McalAPER + Mmos + Mgrid); 727 // ID = measure[meas].extID; // for the stack, this is the stackDetectID 728 729 // ** Here is the math to relate mag,zp to flux 695 730 696 731 // flux_cgs : erg sec^1 cm^-2 Hz^-1 … … 723 758 // flux_Jy = flux_inst * ten(-0.4*ZP + 3.56) 724 759 760 // get the zero point for the selected image 761 // Use a different zero point for the PSF-like and APERTURE-like magnitudes 762 float zpPSF = PhotZeroPoint (&measure[meas], &average[0], &secfilt[0]) - (McalPSF + Mmos + Mgrid); 763 float zpAPER = PhotZeroPoint (&measure[meas], &average[0], &secfilt[0]) - (McalAPER + Mmos + Mgrid); 764 725 765 // zpFactor to go from instrumental flux to Janskies 726 766 float zpFactorPSF = pow(10.0, -0.4*zpPSF + 3.56); … … 728 768 729 769 // need to put in AB mag factor to get to Janskies (or uJy?) 730 secfilt[Nsec].FpsfStk = zpFactorPSF * measure[ k].FluxPSF;731 secfilt[Nsec].dFpsfStk = zpFactorPSF * measure[ k].dFluxPSF;732 secfilt[Nsec].FkronStk = zpFactorAPER * measure[ k].FluxKron;733 secfilt[Nsec].dFkronStk = zpFactorAPER * measure[ k].dFluxKron;734 secfilt[Nsec].FapStk = zpFactorAPER * measure[ k].FluxAp;770 secfilt[Nsec].FpsfStk = zpFactorPSF * measure[meas].FluxPSF; 771 secfilt[Nsec].dFpsfStk = zpFactorPSF * measure[meas].dFluxPSF; 772 secfilt[Nsec].FkronStk = zpFactorAPER * measure[meas].FluxKron; 773 secfilt[Nsec].dFkronStk = zpFactorAPER * measure[meas].dFluxKron; 774 secfilt[Nsec].FapStk = zpFactorAPER * measure[meas].FluxAp; 735 775 736 776 // NOTE: for PV3, apFluxErr is broken (see pmSourcePhotometry.c:245). we are going to 737 777 // use PSF flux error instead here: 738 // secfilt[Nsec].dFapStk = zpFactorAPER * measure[ k].dFluxAp;739 secfilt[Nsec].dFapStk = zpFactorAPER * measure[ k].dFluxPSF;778 // secfilt[Nsec].dFapStk = zpFactorAPER * measure[meas].dFluxAp; 779 secfilt[Nsec].dFapStk = zpFactorAPER * measure[meas].dFluxPSF; 740 780 741 781 // Jy to AB mags 742 secfilt[Nsec].MpsfStk = (measure[k].FluxPSF > 0.0) ? 8.9 - 2.5*log10(secfilt[Nsec].FpsfStk) : NAN; 743 secfilt[Nsec].MkronStk = (measure[k].FluxKron > 0.0) ? 8.9 - 2.5*log10(secfilt[Nsec].FkronStk) : NAN; 744 secfilt[Nsec].MapStk = (measure[k].FluxAp > 0.0) ? 8.9 - 2.5*log10(secfilt[Nsec].FapStk) : NAN; 745 746 secfilt[Nsec].stackBestOff = k + measureOffset; 782 secfilt[Nsec].MpsfStk = (measure[meas].FluxPSF > 0.0) ? 8.9 - 2.5*log10(secfilt[Nsec].FpsfStk) : NAN; 783 secfilt[Nsec].MkronStk = (measure[meas].FluxKron > 0.0) ? 8.9 - 2.5*log10(secfilt[Nsec].FkronStk) : NAN; 784 secfilt[Nsec].MapStk = (measure[meas].FluxAp > 0.0) ? 8.9 - 2.5*log10(secfilt[Nsec].FapStk) : NAN; 785 786 // record the measurement which gave the best value 787 secfilt[Nsec].stackBestOff = (bestEntryMax > -1) ? bestEntryMax + measureOffset; 747 788 myAssert (secfilt[Nsec].stackBestOff <= catalog[0].Nmeasure, "stackBestOff out of range"); 748 789 749 secfilt[Nsec].Nstack = Nstack ;790 secfilt[Nsec].Nstack = NstackMeas; 750 791 secfilt[Nsec].NstackDet = NstackDet; 751 792 752 793 // this is the measurement used by secfilt[] 753 measure[ k].dbFlags |= ID_MEAS_STACK_PHOT_SRC;754 if ( k == stackPrimaryMeasure) {794 measure[meas].dbFlags |= ID_MEAS_STACK_PHOT_SRC; 795 if (Nprimary) { 755 796 secfilt[Nsec].flags |= ID_SECF_STACK_PRIMARY; 797 if (Nprimary > 1) { 798 secfilt[Nsec].flags |= ID_SECF_STACK_PRIMARY_MULTIPLE; 799 } 756 800 } 757 801 758 802 // stack measurement used for 'best' was a detection (not forced from the other bands) 759 if ((measure[ k].photFlags2 & 0x00000004) == 0) {803 if ((measure[meas].photFlags2 & 0x00000004) == 0) { 760 804 secfilt[Nsec].flags |= ID_SECF_STACK_BESTDET; 761 805 } 762 806 // stack measurement used for 'primary' was a detection (not forced from the other bands) 763 if (( stackPrimaryMeasure >= 0) && ((measure[stackPrimaryMeasure].photFlags2 & 0x00000004) == 0)) {807 if ((primaryEntryMax >= 0) && ((measure[primaryEntryMax].photFlags2 & 0x00000004) == 0)) { 764 808 secfilt[Nsec].flags |= ID_SECF_STACK_PRIMDET; 765 809 }
Note:
See TracChangeset
for help on using the changeset viewer.
