Commits

C. Enrique Garcia Dabo authored ca21f516edf
Add test for SPWs without averaging

This adds a unit test to check for cases in which the chanbin parameter specifies no averaging in some SPWs. The SPW subtable is also properly tested. Fixes partially CAS-11988
No tags

code/mstransform/TVI/test/tChannelAverageTVI.cc

Modified
635 635 std::vector<String> assocNature(1);
636 636 assocSpwId[0] = 2; //SPW0 refers to SPW2 (old SPW0)
637 637 assocNature[0] = "CH_AVG";
638 638 ASSERT_EQ(spwcols.assocSpwId()(0).tovector(), assocSpwId);
639 639 ASSERT_EQ(spwcols.assocNature()(0).tovector(), assocNature);
640 640 assocSpwId[0] = 3; //SPW1 refers to SPW3 (old SPW1)
641 641 ASSERT_EQ(spwcols.assocSpwId()(1).tovector(), assocSpwId);
642 642 ASSERT_EQ(spwcols.assocNature()(1).tovector(), assocNature);
643 643 }
644 644
645 +TEST_F(ChannelAverageTVISpwChannTest, CheckSecondPartialAvgSpwChannelsAndSpwSubtable)
646 +{
647 + addExtraAvgTVI(true);
648 + std::vector<int> chanbinSecondTVI{0,5,0,0};
649 + setChanBinSecondTVI(chanbinSecondTVI);
650 + createTVIs();
651 + size_t nRows = 0;
652 + size_t nRowsSpw0 = 0;
653 + size_t nRowsSpw1 = 0;
654 + // Check that after averaging with chanbin=5 and further averaging with
655 + // chanbin=(0,5,0,0), the first spectral window (which had 100 channels)
656 + // has now 20 channels and the second
657 + // spectral window (which had 50 channnels) has now 2
658 + visitIterator([&]() -> void {auto shape = vb_p->visCube().shape();
659 + if(allEQ(vb_p->spectralWindows(), 0)) //SPW0
660 + {
661 + nRowsSpw0+=shape[2];
662 + ASSERT_EQ(vb_p->nChannels(), 20);
663 + }
664 + else if(allEQ(vb_p->spectralWindows(), 1)) //SPW1
665 + {
666 + nRowsSpw1+=shape[2];
667 + ASSERT_EQ(vb_p->nChannels(), 2);
668 + }
669 + //Both TVIs duplicate the existing SPWs (CAS-10294)
670 + ASSERT_EQ(vi_p->nSpectralWindows(), 8);
671 + nRows+=vb_p->visCube().shape()[2];});
672 +
673 + //All the original rows
674 + size_t expectedRows = 300;
675 + //The synthetic MS has half of the rows in each SPW
676 + size_t expectedRowsSpw0 = expectedRows / 2;
677 + size_t expectedRowsSpw1 = expectedRows / 2;
678 +
679 + //Check that we get the number of expected rows for each spw
680 + ASSERT_EQ(nRows, expectedRows);
681 + ASSERT_EQ(nRowsSpw0, expectedRowsSpw0);
682 + ASSERT_EQ(nRowsSpw1, expectedRowsSpw1);
683 +
684 + //Check that now the number of SPWs has been duplicated twice (two TVIs):
685 + //the old ones are appended at the end of the SPW table and the new ones
686 + //prepended.
687 + //After averaging with chanbin=5 the first spectral window has 20
688 + //channels and the second spectral window has 10 channel
689 + auto & spwcols = vi_p->spectralWindowSubtablecols();
690 + ASSERT_EQ(spwcols.nrow(), (unsigned int)8);
691 +
692 + //The number of channels expected in all the SPWs:
693 + int nChannelSpw0 = nChannelsOrig_p[0] / chanBinFirst_p; //Original SPW0 after second TVI (note that chanbin=0 for this SPW)
694 + int nChannelSpw1 = nChannelsOrig_p[1] / chanBinFirst_p / chanBinSecond_p[1]; // Original SPW1 after second TVI
695 + int nChannelSpw2 = nChannelsOrig_p[0]; //Copy of original SPW0 after second TVI (note that chanbin=0 for this SPW)
696 + int nChannelSpw3 = nChannelsOrig_p[1]; //Copy of original SPW1 after second TVI (note that chanbin=0 for this SPW)
697 + int nChannelSpw4 = nChannelsOrig_p[0] / chanBinFirst_p; //Original SPW0 after first TVI
698 + int nChannelSpw5 = nChannelsOrig_p[1] / chanBinFirst_p; //Original SPW0 after firstTVI
699 + int nChannelSpw6 = nChannelsOrig_p[0]; //Copy of original SPW0
700 + int nChannelSpw7 = nChannelsOrig_p[1]; //Copy of original SPW1
701 +
702 + ASSERT_EQ(spwcols.numChan()(0), nChannelSpw0);
703 + ASSERT_EQ(spwcols.numChan()(1), nChannelSpw1);
704 + ASSERT_EQ(spwcols.numChan()(2), nChannelSpw2);
705 + ASSERT_EQ(spwcols.numChan()(3), nChannelSpw3);
706 + ASSERT_EQ(spwcols.numChan()(4), nChannelSpw4);
707 + ASSERT_EQ(spwcols.numChan()(5), nChannelSpw5);
708 + ASSERT_EQ(spwcols.numChan()(6), nChannelSpw6);
709 + ASSERT_EQ(spwcols.numChan()(7), nChannelSpw7);
710 +
711 + //Check that the new SPWs refer to the old one:
712 + std::vector<int> assocSpwId(1);
713 + assocSpwId[0] = 4; //SPW0 refers to SPW4 (SPW0 after first TVI)
714 + ASSERT_EQ(spwcols.assocSpwId()(0).tovector(), assocSpwId);
715 + assocSpwId[0] = 5; //SPW1 refers to SPW5 (SPW1 after first TVI)
716 + ASSERT_EQ(spwcols.assocSpwId()(1).tovector(), assocSpwId);
717 + assocSpwId[0] = 6; //SPW2 refers to SPW6 (original SPW0)
718 + ASSERT_EQ(spwcols.assocSpwId()(2).tovector(), assocSpwId);
719 + assocSpwId[0] = 7; //SPW3 refers to SPW7 (original SPW1)
720 + ASSERT_EQ(spwcols.assocSpwId()(3).tovector(), assocSpwId);
721 + assocSpwId[0] = 6; //SPW4 refers to SPW6 (original SPW0)
722 + ASSERT_EQ(spwcols.assocSpwId()(4).tovector(), assocSpwId);
723 + assocSpwId[0] = 7; //SPW5 refers to SPW7 (original SPW1)
724 + ASSERT_EQ(spwcols.assocSpwId()(5).tovector(), assocSpwId);
725 + ASSERT_EQ(spwcols.assocSpwId()(6).tovector(), std::vector<int>()); //Original assoc was empty
726 + ASSERT_EQ(spwcols.assocSpwId()(7).tovector(), std::vector<int>()); //Original assoc was empty
727 +}
728 +
645 729 TEST_F(ChannelAverageTVISpwChannTest, LastChannelNotDivisibleCheckOutputSpwSubtable)
646 730 {
647 731 //This setting will do channel average with a number of input channels
648 732 //which are not divisible by the chanbin
649 733 setChanBinFirstTVI(7);
650 734 createTVIs();
651 735
652 736 //Check that the number of channels is correct.
653 737 //The +1 is to account for the last residual channel
654 738 auto & spwcols = vi_p->spectralWindowSubtablecols();
714 798 if(allEQ(vb_p->spectralWindows(), 0)) //SPW0
715 799 {
716 800 nRowsSpw0+=shape[2];
717 801 ASSERT_EQ(vb_p->nChannels(), 4);
718 802 }
719 803 else if(allEQ(vb_p->spectralWindows(), 1)) //SPW1
720 804 {
721 805 nRowsSpw1+=shape[2];
722 806 ASSERT_EQ(vb_p->nChannels(), 2);
723 807 }
724 - //The TVI duplicates the existing SPWs (CAS-10294)
808 + //Both TVIs duplicate the existing SPWs (CAS-10294)
725 809 ASSERT_EQ(vi_p->nSpectralWindows(), 8);
726 810 nRows+=vb_p->visCube().shape()[2];});
727 811
728 812 //After selection we have only half of the original rows
729 813 //and all of them belong to SPW0.
730 814 size_t expectedRows = 150;
731 815 size_t expectedRowsSpw0 = expectedRows;
732 816 size_t expectedRowsSpw1 = 0;
733 817
734 818 //Check that we get the number of expected rows for each spw

Everything looks good. We'll let you know here if there's anything you should know about.

Add shortcut