예제 #1
0
def test_binning2d_iadd():
    x_axis = core.Axis(np.linspace(-180, 180, 1), is_circle=True)
    y_axis = core.Axis(np.linspace(-90, 90, 1))

    binning = core.Binning2DFloat64(x_axis, y_axis, None)
    binning.push([-180], [-90], [np.pi])

    other = copy.copy(binning)
    other += binning

    assert np.all(binning.count() == 1)
    assert np.all(binning.mean() == np.pi)
    assert np.all(binning.min() == np.pi)
    assert np.all(binning.max() == np.pi)
    assert np.all(binning.sum() == np.pi)
    assert np.all(binning.sum_of_weights() == 1)
    assert np.all(binning.variance() == 0)
    assert np.all(np.isnan(other.skewness()))
    assert np.all(np.isnan(other.kurtosis()))

    assert np.all(other.count() == 2)
    assert np.all(other.mean() == np.pi)
    assert np.all(other.min() == np.pi)
    assert np.all(other.max() == np.pi)
    assert np.all(other.sum() == np.pi * 2)
    assert np.all(other.sum_of_weights() == 2)
    assert np.all(other.variance() == 0)
    assert np.all(np.isnan(other.skewness()))
    assert np.all(np.isnan(other.kurtosis()))
예제 #2
0
    def test_binning2d_acessors(self):
        x_axis = core.Axis(np.linspace(-180, 180, 10), is_circle=True)
        y_axis = core.Axis(np.linspace(-90, 90, 10))

        binning = core.Binning2DFloat64(x_axis, y_axis)
        self.assertIsInstance(binning.x, core.Axis)
        self.assertIsInstance(binning.y, core.Axis)
        # The class must return a reference on the axes provided during
        # construction
        self.assertEqual(id(x_axis), id(binning.x))
        self.assertEqual(id(y_axis), id(binning.y))

        binning.clear()
        count = binning.count()
        self.assertIsInstance(count, np.ndarray)
        self.assertEqual(count.size, len(x_axis) * len(y_axis))
        self.assertEqual(count.mean(), 0)
예제 #3
0
def test_binning2d_acessors():
    x_axis = core.Axis(np.linspace(-180, 180, 10), is_circle=True)
    y_axis = core.Axis(np.linspace(-90, 90, 10))

    binning = core.Binning2DFloat64(x_axis, y_axis)
    assert isinstance(binning.x, core.Axis)
    assert isinstance(binning.y, core.Axis)

    # The class must return a reference on the axes provided during
    # construction
    assert id(x_axis) == id(binning.x)
    assert id(y_axis) == id(binning.y)

    binning.clear()
    count = binning.count()
    assert isinstance(count, np.ndarray)
    assert count.size == len(x_axis) * len(y_axis)
    assert count.mean() == 0
예제 #4
0
    def test_binning2d_methods(self):
        x_axis = core.Axis(np.linspace(-180, 180, 361 // 4), is_circle=True)
        y_axis = core.Axis(np.linspace(-90, 90, 180 // 4))

        binning = core.Binning2DFloat64(x_axis, y_axis, None)
        x, y, z = self.load_data()
        mx, my = np.meshgrid(x, y, indexing='ij')
        binning.push(mx.flatten(), my.flatten(), z.flatten())

        count = binning.count()
        self.assertNotEqual(count.max(), 0)
        simple_mean = np.ma.fix_invalid(binning.mean())
        if HAVE_PLT:
            mx, my = np.meshgrid(x_axis[:], y_axis[:], indexing='ij')
            plot(mx, my, simple_mean, "binning2d_simple.png")

        mx, my = np.meshgrid(x, y, indexing='ij')
        binning.clear()
        binning.push(mx.flatten(), my.flatten(), z.flatten(), simple=False)

        count = binning.count()
        self.assertNotEqual(count.max(), 0)
        linear_mean = np.ma.fix_invalid(binning.mean())
        if HAVE_PLT:
            mx, my = np.meshgrid(x_axis[:], y_axis[:], indexing='ij')
            plot(mx, my, linear_mean, "binning2d_linear.png")

        self.assertFalse(np.all(linear_mean == simple_mean))

        # Test of access to statistical variables
        self.assertIsInstance(binning.kurtosis(), np.ndarray)
        self.assertIsInstance(binning.max(), np.ndarray)
        self.assertIsInstance(binning.median(), np.ndarray)
        self.assertIsInstance(binning.min(), np.ndarray)
        self.assertIsInstance(binning.skewness(), np.ndarray)
        self.assertIsInstance(binning.sum(), np.ndarray)
        self.assertIsInstance(binning.sum_of_weights(), np.ndarray)
        self.assertIsInstance(binning.variance(), np.ndarray)