def testPopulationFromTimeHgValues3(self):
        """
        test one specific example with stride of 5
        and a number of timeHgValues that is not a multiple of stride
        """
        timeHgValues = np.array([0,0,10,20,0,0,5,6,7,8,9,1,99])
        populationMax = 40
        stride = 5
        threshold = 15
        d = Cosmic.populationFromTimeHgValues(timeHgValues, populationMax, 
                                              stride, threshold)
        
        populationTrue = np.zeros(populationMax)
        populationTrue[26] = 1
        populationTrue[30] = 1
        populationTrue[35] = 1

        self.assertEquals(None, np.testing.assert_array_equal(
                d['populationHg'][0], 
                populationTrue))

        self.assertEquals(None, np.testing.assert_array_equal(
                d['cosmicTimeList'],
                np.array([0,2,5])))

        self.assertEquals(None, np.testing.assert_array_equal(
                d['binContents'],
                np.array([30,35,26])))
    def testPopulationFromTimeHgValues1(self):
        """
        test one specific example with stride of 4
        """
        timeHgValues = np.array([0,0,10,20,0,0,5,6,7,8,9,1])
        populationMax = 40
        stride = 4
        threshold = 15
        d = Cosmic.populationFromTimeHgValues(timeHgValues, populationMax, 
                                              stride, threshold)
        
        populationTrue = np.zeros(populationMax)
        populationTrue[11] = 1
        populationTrue[25] = 1
        populationTrue[26] = 1
        populationTrue[30] = 2

        self.assertEquals(None, np.testing.assert_array_equal(
                d['populationHg'][0], 
                populationTrue))

        self.assertEquals(None, np.testing.assert_array_equal(
                d['cosmicTimeList'],
                np.array([0,2,6,8])))

        self.assertEquals(None, np.testing.assert_array_equal(
                d['binContents'],
                np.array([30,30,26,25])))
    def test_pfthv2(self):
        """
        Demonstrate the static method  populationFromTimeHgValues

        Put 1 photon in 10 successive time ticks (starting at tick 15), 
        and 0 photons in the rest of the time ticks.

        For a stride of 10, the method samples 7 time bins.  The bins overlap
        by stride/2.

        The populationHg returned reports that 4 of these bins have zero photons,
        2 of the bins have 5 photons, and 1 bin has 10 photons.

        """
        length = 40
        timeHgValues = np.zeros(length, dtype=np.int64)
        for i in range(15,25,1):
            timeHgValues[i] = 1

        populationMax = 40
        stride = 10
        threshold = 4
        pfthv = Cosmic.populationFromTimeHgValues(timeHgValues, populationMax,
                                                  stride, threshold)
        self.assertEquals(populationMax, len(pfthv['populationHg'][0]))
        self.assertEquals(4, pfthv['populationHg'][0][0])
        self.assertEquals(2, pfthv['populationHg'][0][5])
        self.assertEquals(1, pfthv['populationHg'][0][10])
    def testPopulationFromTimeHgValues0(self):
        """
        test one specific example with stride of 1
        """
        timeHgValues = np.array([0,10,5,0,0,0,0,10,8,1,0,0,0,0,0,0])
        populationMax = 20
        stride = 1
        threshold = 9
        d = Cosmic.populationFromTimeHgValues(timeHgValues, populationMax, 
                                              stride, threshold)
        
        self.assertEquals(None, np.testing.assert_array_equal(
                d['populationHg'][0], 
                np.array([11,1,0,0,0,1,0,0,1,0,2,0,0,0,0,0,0,0,0,0])))

        self.assertEquals(None, np.testing.assert_array_equal(
                d['cosmicTimeList'],
                np.array([1,7])))

        self.assertEquals(None, np.testing.assert_array_equal(
                d['binContents'],
                np.array([10,10])))
    def test_populationFromTimeHgValues(self):
        """
        test the funcion Cosmic.populationFromTimeHgValues.

        Make a time stream where in successive time values you have 1,3,1
        photons.  Look for cosmic events with a threshold of 4.  Arrange
        the time stream so that one of the large bins (starting at 89995)
        overlaps the time stamps with all five photons, but the next one
        (starting at 90000) only overlaps 4 photons.  With the threshold
        set to 4, the bin starting at 89995 is found and the bin starting
        at 90000 is not found.
        """
        minLength = 1000000
        timeHgValues = np.zeros(minLength, dtype=np.int64)
        timeHgValues[89999] = 1
        timeHgValues[90000] = 3
        timeHgValues[90001] = 1

        populationMax = 10
        stride = 10
        threshold = 4
        pfthv = Cosmic.populationFromTimeHgValues(
            timeHgValues, populationMax, stride, threshold)

        cosmicTimeList = pfthv['cosmicTimeList']
        #print "cosmicTimeList=",cosmicTimeList
        self.assertEquals(cosmicTimeList.size,1)
        self.assertEquals(cosmicTimeList[0], 89995)
        populationHg = pfthv['populationHg']
        #print "populationHg[0]=",populationHg[0]
        self.assertEquals(populationHg[0][0], 199996)
        self.assertEquals(populationHg[0][1], 1)
        self.assertEquals(populationHg[0][2], 0)
        self.assertEquals(populationHg[0][3], 0)
        self.assertEquals(populationHg[0][4], 1)
        self.assertEquals(populationHg[0][5], 1)