Exemple #1
0
    def test_indexed(self):

        # Here we slice two of the dimensions and then compare the results to a
        # manually sliced dataset.

        derived = IndexedData(self.data, (None, 2, None, 4, None))
        manual = Data()
        manual.add_component(self.data[self.x_id][:, 2, :, 4, :], label=self.x_id)
        manual.add_component(self.data[self.y_id][:, 2, :, 4, :], label=self.y_id)

        assert derived.label == 'Test data[:,2,:,4,:]'
        assert derived.shape == manual.shape
        assert [str(c) for c in derived.main_components] == [str(c) for c in manual.main_components]
        assert derived.get_kind(self.x_id) == manual.get_kind(self.x_id)

        for view in [None, (1, slice(None), slice(1, 4))]:

            assert_equal(derived.get_data(self.x_id, view=view),
                         manual.get_data(self.x_id, view=view))

            assert_equal(derived.get_mask(self.subset_state, view=view),
                         manual.get_mask(self.subset_state, view=view))

        bounds = [2, (-5, 5, 10), (-3, 3, 10)]
        assert_equal(derived.compute_fixed_resolution_buffer(bounds=bounds, target_cid=self.x_id),
                     manual.compute_fixed_resolution_buffer(bounds=bounds, target_cid=self.x_id))

        assert_equal(derived.compute_statistic('mean', self.x_id),
                     manual.compute_statistic('mean', self.x_id))

        assert_equal(derived.compute_statistic('mean', self.x_id, axis=2),
                     manual.compute_statistic('mean', self.x_id, axis=2))

        assert_equal(derived.compute_statistic('mean', self.x_id, subset_state=self.subset_state),
                     manual.compute_statistic('mean', self.x_id, subset_state=self.subset_state))

        assert_equal(derived.compute_histogram([self.x_id], range=[(0, 1000)], bins=[30]),
                     manual.compute_histogram([self.x_id], range=[(0, 1000)], bins=[30]))

        assert_equal(derived.compute_histogram([self.x_id], range=[(0, 1000)], bins=[30], subset_state=self.subset_state),
                     manual.compute_histogram([self.x_id], range=[(0, 1000)], bins=[30], subset_state=self.subset_state))
Exemple #2
0
    def test_identity(self):

        # In this test, we don't actually slice any dimensions

        derived = IndexedData(self.data, (None,) * 5)

        assert derived.label == 'Test data[:,:,:,:,:]'
        assert derived.shape == self.data.shape
        assert [str(c) for c in derived.main_components] == [str(c) for c in self.data.main_components]
        assert derived.get_kind(self.x_id) == self.data.get_kind(self.x_id)

        for view in [None, (1, slice(None), slice(None), slice(1, 4), slice(0, 7, 2))]:

            assert_equal(derived.get_data(self.x_id, view=view),
                         self.data.get_data(self.x_id, view=view))

            assert_equal(derived.get_mask(self.subset_state, view=view),
                         self.data.get_mask(self.subset_state, view=view))

        bounds = [2, (-5, 5, 10), 3, 4, (-3, 3, 10)]
        assert_equal(derived.compute_fixed_resolution_buffer(bounds=bounds, target_cid=self.x_id),
                     self.data.compute_fixed_resolution_buffer(bounds=bounds, target_cid=self.x_id))

        assert_equal(derived.compute_statistic('mean', self.x_id),
                     self.data.compute_statistic('mean', self.x_id))

        assert_equal(derived.compute_statistic('mean', self.x_id, axis=2),
                     self.data.compute_statistic('mean', self.x_id, axis=2))

        assert_equal(derived.compute_statistic('mean', self.x_id, subset_state=self.subset_state),
                     self.data.compute_statistic('mean', self.x_id, subset_state=self.subset_state))

        assert_equal(derived.compute_histogram([self.x_id], range=[(0, 1000)], bins=[30]),
                     self.data.compute_histogram([self.x_id], range=[(0, 1000)], bins=[30]))

        assert_equal(derived.compute_histogram([self.x_id], range=[(0, 1000)], bins=[30], subset_state=self.subset_state),
                     self.data.compute_histogram([self.x_id], range=[(0, 1000)], bins=[30], subset_state=self.subset_state))
Exemple #3
0
    def test_indexed(self):

        # Here we slice two of the dimensions and then compare the results to a
        # manually sliced dataset.

        derived = IndexedData(self.data, (None, 2, None, 4, None))
        manual = Data()
        manual.add_component(self.data[self.x_id][:, 2, :, 4, :],
                             label=self.x_id)
        manual.add_component(self.data[self.y_id][:, 2, :, 4, :],
                             label=self.y_id)

        assert derived.label == 'Test data[:,2,:,4,:]'
        assert derived.shape == manual.shape
        assert [str(c) for c in derived.main_components
                ] == [str(c) for c in manual.main_components]
        assert derived.get_kind(self.x_id) == manual.get_kind(self.x_id)

        for view in [None, (1, slice(None), slice(1, 4))]:

            assert_equal(derived.get_data(self.x_id, view=view),
                         manual.get_data(self.x_id, view=view))

            assert_equal(derived.get_mask(self.subset_state, view=view),
                         manual.get_mask(self.subset_state, view=view))

        bounds = [2, (-5, 5, 10), (-3, 3, 10)]
        assert_equal(
            derived.compute_fixed_resolution_buffer(bounds=bounds,
                                                    target_cid=self.x_id),
            manual.compute_fixed_resolution_buffer(bounds=bounds,
                                                   target_cid=self.x_id))

        assert_equal(derived.compute_statistic('mean', self.x_id),
                     manual.compute_statistic('mean', self.x_id))

        assert_equal(derived.compute_statistic('mean', self.x_id, axis=2),
                     manual.compute_statistic('mean', self.x_id, axis=2))

        assert_equal(
            derived.compute_statistic('mean',
                                      self.x_id,
                                      subset_state=self.subset_state),
            manual.compute_statistic('mean',
                                     self.x_id,
                                     subset_state=self.subset_state))

        assert_equal(
            derived.compute_histogram([self.x_id],
                                      range=[(0, 1000)],
                                      bins=[30]),
            manual.compute_histogram([self.x_id], range=[(0, 1000)],
                                     bins=[30]))

        assert_equal(
            derived.compute_histogram([self.x_id],
                                      range=[(0, 1000)],
                                      bins=[30],
                                      subset_state=self.subset_state),
            manual.compute_histogram([self.x_id],
                                     range=[(0, 1000)],
                                     bins=[30],
                                     subset_state=self.subset_state))
Exemple #4
0
    def test_identity(self):

        # In this test, we don't actually slice any dimensions

        derived = IndexedData(self.data, (None, ) * 5)

        assert derived.label == 'Test data[:,:,:,:,:]'
        assert derived.shape == self.data.shape
        assert [str(c) for c in derived.main_components
                ] == [str(c) for c in self.data.main_components]
        assert derived.get_kind(self.x_id) == self.data.get_kind(self.x_id)

        for view in [
                None, (1, slice(None), slice(None), slice(1,
                                                          4), slice(0, 7, 2))
        ]:

            assert_equal(derived.get_data(self.x_id, view=view),
                         self.data.get_data(self.x_id, view=view))

            assert_equal(derived.get_mask(self.subset_state, view=view),
                         self.data.get_mask(self.subset_state, view=view))

        bounds = [2, (-5, 5, 10), 3, 4, (-3, 3, 10)]
        assert_equal(
            derived.compute_fixed_resolution_buffer(bounds=bounds,
                                                    target_cid=self.x_id),
            self.data.compute_fixed_resolution_buffer(bounds=bounds,
                                                      target_cid=self.x_id))

        assert_equal(derived.compute_statistic('mean', self.x_id),
                     self.data.compute_statistic('mean', self.x_id))

        assert_equal(derived.compute_statistic('mean', self.x_id, axis=2),
                     self.data.compute_statistic('mean', self.x_id, axis=2))

        assert_equal(
            derived.compute_statistic('mean',
                                      self.x_id,
                                      subset_state=self.subset_state),
            self.data.compute_statistic('mean',
                                        self.x_id,
                                        subset_state=self.subset_state))

        assert_equal(
            derived.compute_histogram([self.x_id],
                                      range=[(0, 1000)],
                                      bins=[30]),
            self.data.compute_histogram([self.x_id],
                                        range=[(0, 1000)],
                                        bins=[30]))

        assert_equal(
            derived.compute_histogram([self.x_id],
                                      range=[(0, 1000)],
                                      bins=[30],
                                      subset_state=self.subset_state),
            self.data.compute_histogram([self.x_id],
                                        range=[(0, 1000)],
                                        bins=[30],
                                        subset_state=self.subset_state))