Exemple #1
0
    def test_add_2_histograms_same_data(self, rotate):
        """
        Tests that adding 2 histograms with the same data is ok.
        """
        item = HistogramItem(rotate=rotate)

        data = np.random.random(100)

        item.add_histogram(data)

        item.add_histogram(data)
        self._assert_histogram_item_array_lengths(item, 2)
Exemple #2
0
    def __init__(self):
        super(EventAnalysisPlotWidget, self).__init__()

        self.plot_event_depth = HistogramItem(title='Event Depth', rotate=True)
        self.addItem(self.plot_event_depth)
        self.plot_event_depth.setMouseEnabled(x=False, y=True)
        self.plot_event_dur_event_depth = self.addPlot(
            name='Depth vs. Duration', title='Depth vs. Duration')
        self.plot_event_depth.setYLink('Depth vs. Duration')

        self.nextRow()

        self.plot_scatter_select = self.addPlot(title='Single Event')

        self.plot_event_dur = HistogramItem(title='Event Duration')
        self.addItem(self.plot_event_dur)
        self.plot_event_dur.setXLink('Depth vs. Duration')
        self.plot_event_dur.setMouseEnabled(x=True, y=False)

        self.last_scatter_clicked = []

        self.n_bins = 0
        self.bins = np.zeros(0)
Exemple #3
0
    def test_add_histogram(self, rotate):
        """
        Tests adding a histogram.
        """
        item = HistogramItem(rotate=rotate)

        # Assert no data items.
        self._assert_histogram_item_array_lengths(item, 0)

        data = np.random.random(100)

        item.add_histogram(data)

        data_items = item.listDataItems()
        self._assert_histogram_item_array_lengths(item, 1)
Exemple #4
0
    def test_remove_only_histogram(self, rotate):
        """
        Tests that removing the only item works.
        """
        item = HistogramItem(rotate=rotate)

        data = np.random.random(100)

        item.add_histogram(data)

        self._assert_histogram_item_array_lengths(item, 1)

        item.remove_item_at(0)

        self._assert_histogram_item_array_lengths(item, 0)
Exemple #5
0
    def test_add_2nd_histogram_less_points(self, rotate):
        """
        Tests that adding a 2nd histogram with less points doesn't change number of bins.
        """
        item = HistogramItem(rotate=rotate)

        data = np.random.random(1000)

        item.add_histogram(data)
        n_bins = item.n_bins

        data2 = np.random.random(100)

        item.add_histogram(data2)

        self._assert_histogram_item_array_lengths(item, 2)
        self.assertEqual(item.n_bins, n_bins)
Exemple #6
0
    def test_add_2nd_histogram_more_points(self, rotate):
        """
        Tests that adding a 2nd histogram with more points increases the number of bins.
        """
        item = HistogramItem(rotate=rotate)

        data = np.random.random(100)

        item.add_histogram(data)
        n_bins = item.n_bins

        data2 = np.random.random(1000)

        item.add_histogram(data2)

        self._assert_histogram_item_array_lengths(item, 2)
        self.assertGreater(item.n_bins, n_bins)
Exemple #7
0
    def test_remove_first_histogram(self, rotate):
        """
        Tests that removing the first histogram works.
        """
        item = HistogramItem(rotate=rotate)

        data = np.random.random(100)

        item.add_histogram(data)

        data2 = np.random.random(200)

        item.add_histogram(data2)

        data_item2 = item.listDataItems()[1]

        item.remove_item_at(0)

        self._assert_histogram_item_array_lengths(item, 1)

        data_item_left = item.listDataItems()[0]

        self.assertEqual(data_item2, data_item_left)
Exemple #8
0
    def test_add_2nd_histogram_wider_range(self, rotate):
        """
        Tests that we can add a 2nd histogram with wider data. The max should increase, min
        should decrease, n_bins should stay same (default n_bins depends on length of data).
        """
        item = HistogramItem(rotate=rotate)

        # 0 < data[i] < 1
        data = np.random.random(100)
        # -50 < data[i] < 50
        data2 = np.random.random(100) * 100 - 50

        item.add_histogram(data)

        maximum = item.maximum
        minimum = item.minimum
        n_bins = item.n_bins

        item.add_histogram(data2)

        self._assert_histogram_item_array_lengths(item, 2)
        self.assertLess(item.minimum, minimum)
        self.assertGreater(item.maximum, maximum)
        self.assertEqual(item.n_bins, n_bins)
Exemple #9
0
    def test_add_2nd_histogram_narrower_range(self, rotate):
        """
        Tests that we can add a 2nd histogram with narrower (max-min) data. This should not
        change the histograms max/min or the number of bins.
        """
        item = HistogramItem(rotate=rotate)

        # -50 < data[i] < 50
        data = np.random.random(100) * 100 - 50

        item.add_histogram(data)

        maximum = item.maximum
        minimum = item.minimum
        n_bins = item.n_bins

        # 0 < data[i] < 1
        data2 = np.random.random(100)
        item.add_histogram(data2)

        self._assert_histogram_item_array_lengths(item, 2)
        self.assertEqual(item.maximum, maximum)
        self.assertEqual(item.minimum, minimum)
        self.assertEqual(item.n_bins, n_bins)