예제 #1
0
class TestUniSlicerEqual(unittest.TestCase):

    def setUp(self):
        self.testslicer = UniSlicer()
        dvmin = 0
        dvmax = 1
        nvalues = 1000
        dv = makeDataValues(nvalues, dvmin, dvmax, random=3482)
        self.testslicer.setupSlicer(dv)

    def tearDown(self):
        del self.testslicer
        self.testslicer = None

    def testEquivalence(self):
        """Test equals method."""
        # Note that two uni slicers will be considered equal if they are both the same kind of
        # slicer (unislicer). They will not necessarily slice data equally though (the indices are
        #  not necessarily the same!).
        # These should be the same, even though data is not the same.
        testslicer2 = UniSlicer()
        dv2 = makeDataValues(100, 0, 1, random=43298)
        testslicer2.setupSlicer(dv2)
        self.assertEqual(self.testslicer, testslicer2)
        # these will not be the same, as different slicer type.
        testslicer2 = OneDSlicer(sliceColName='testdata', bins=10)
        testslicer2.setupSlicer(dv2)
        self.assertNotEqual(self.testslicer, testslicer2)
예제 #2
0
class TestUniSlicerIteration(unittest.TestCase):

    def setUp(self):
        self.testslicer = UniSlicer()

    def tearDown(self):
        del self.testslicer
        self.testslicer = None

    def testIteration(self):
        """Test iteration -- which is a one-step identity op for a unislicer."""
        dvmin = 0
        dvmax = 1
        nvalues = 1000
        dv = makeDataValues(nvalues, dvmin, dvmax, random=432)
        self.testslicer.setupSlicer(dv)
        for i, b in enumerate(self.testslicer):
            pass
        self.assertEqual(i, 0)

    def testGetItem(self):
        """Test that can return an individual indexed values of the slicer."""
        dvmin = 0
        dvmax = 1
        nvalues = 1000
        dv = makeDataValues(nvalues, dvmin, dvmax, random=1192)
        self.testslicer.setupSlicer(dv)
        self.assertEqual(self.testslicer[0]['slicePoint']['sid'], 0)
예제 #3
0
 def setUp(self):
     self.testslicer = UniSlicer()
     dvmin = 0
     dvmax = 1
     nvalues = 1000
     dv = makeDataValues(nvalues, dvmin, dvmax, random=3482)
     self.testslicer.setupSlicer(dv)
예제 #4
0
class TestUniSlicerSetupAndSlice(unittest.TestCase):

    def setUp(self):
        self.testslicer = UniSlicer()

    def tearDown(self):
        del self.testslicer
        self.testslicer = None

    def testSlicertype(self):
        """Test instantiation of slicer sets slicer type as expected."""
        self.assertEqual(self.testslicer.slicerName, self.testslicer.__class__.__name__)
        self.assertEqual(self.testslicer.slicerName, 'UniSlicer')

    def testSlicerNbins(self):
        self.assertEqual(self.testslicer.nslice, 1)

    def testSetupSlicerIndices(self):
        """Test slicer returns correct indices (all) after setup. Note this also tests slicing."""
        dvmin = 0
        dvmax = 1
        nvalues = 1000
        dv = makeDataValues(nvalues, dvmin, dvmax, random=672)
        self.testslicer.setupSlicer(dv)
        # test slicing
        self.assertEqual(len(self.testslicer.indices), len(dv['testdata']))
        np.testing.assert_equal(dv[self.testslicer.indices], dv)
예제 #5
0
class TestUniSlicerEqual(unittest.TestCase):
    def setUp(self):
        self.testslicer = UniSlicer()
        dvmin = 0
        dvmax = 1
        nvalues = 1000
        dv = makeDataValues(nvalues, dvmin, dvmax, random=3482)
        self.testslicer.setupSlicer(dv)

    def tearDown(self):
        del self.testslicer
        self.testslicer = None

    def testEquivalence(self):
        """Test equals method."""
        # Note that two uni slicers will be considered equal if they are both the same kind of
        # slicer (unislicer). They will not necessarily slice data equally though (the indices are
        #  not necessarily the same!).
        # These should be the same, even though data is not the same.
        testslicer2 = UniSlicer()
        dv2 = makeDataValues(100, 0, 1, random=43298)
        testslicer2.setupSlicer(dv2)
        self.assertEqual(self.testslicer, testslicer2)
        # these will not be the same, as different slicer type.
        testslicer2 = OneDSlicer(sliceColName='testdata', bins=10)
        testslicer2.setupSlicer(dv2)
        self.assertNotEqual(self.testslicer, testslicer2)
예제 #6
0
class TestUniSlicerIteration(unittest.TestCase):
    def setUp(self):
        self.testslicer = UniSlicer()

    def tearDown(self):
        del self.testslicer
        self.testslicer = None

    def testIteration(self):
        """Test iteration -- which is a one-step identity op for a unislicer."""
        dvmin = 0
        dvmax = 1
        nvalues = 1000
        dv = makeDataValues(nvalues, dvmin, dvmax, random=432)
        self.testslicer.setupSlicer(dv)
        for i, b in enumerate(self.testslicer):
            pass
        self.assertEqual(i, 0)

    def testGetItem(self):
        """Test that can return an individual indexed values of the slicer."""
        dvmin = 0
        dvmax = 1
        nvalues = 1000
        dv = makeDataValues(nvalues, dvmin, dvmax, random=1192)
        self.testslicer.setupSlicer(dv)
        self.assertEqual(self.testslicer[0]['slicePoint']['sid'], 0)
예제 #7
0
class TestUniSlicerSetupAndSlice(unittest.TestCase):
    def setUp(self):
        self.testslicer = UniSlicer()

    def tearDown(self):
        del self.testslicer
        self.testslicer = None

    def testSlicertype(self):
        """Test instantiation of slicer sets slicer type as expected."""
        self.assertEqual(self.testslicer.slicerName,
                         self.testslicer.__class__.__name__)
        self.assertEqual(self.testslicer.slicerName, 'UniSlicer')

    def testSlicerNbins(self):
        self.assertEqual(self.testslicer.nslice, 1)

    def testSetupSlicerIndices(self):
        """Test slicer returns correct indices (all) after setup. Note this also tests slicing."""
        dvmin = 0
        dvmax = 1
        nvalues = 1000
        dv = makeDataValues(nvalues, dvmin, dvmax, random=672)
        self.testslicer.setupSlicer(dv)
        # test slicing
        self.assertEqual(len(self.testslicer.indices), len(dv['testdata']))
        np.testing.assert_equal(dv[self.testslicer.indices], dv)
예제 #8
0
 def setUp(self):
     self.testslicer = UniSlicer()
     dvmin = 0
     dvmax = 1
     nvalues = 1000
     dv = makeDataValues(nvalues, dvmin, dvmax, random=3482)
     self.testslicer.setupSlicer(dv)
예제 #9
0
 def testEquivalence(self):
     """Test equals method."""
     # Note that two ND slicers will be considered equal if they are both the same kind of
     # slicer AND have the same bins in all dimensions.
     # Set up another slicer to match (same bins, although not the same data).
     dv2 = makeDataValues(100, self.dvmin, self.dvmax, self.nd, random=True)
     dvlist = dv2.dtype.names
     testslicer2 = NDSlicer(sliceColList=dvlist, binsList=self.testslicer.bins)
     testslicer2.setupSlicer(dv2)
     self.assertEqual(self.testslicer, testslicer2)
     # Set up another slicer that should not match (different bins)
     dv2 = makeDataValues(1000, self.dvmin+1, self.dvmax+1, self.nd, random=True)
     testslicer2 = NDSlicer(sliceColList=dvlist, binsList=100)
     testslicer2.setupSlicer(dv2)
     self.assertNotEqual(self.testslicer, testslicer2)
     # Set up another slicer that should not match (different dimensions)
     dv2 = makeDataValues(1000, self.dvmin, self.dvmax, self.nd-1, random=True)
     testslicer2 = NDSlicer(dv2.dtype.names, binsList=100)
     testslicer2.setupSlicer(dv2)
     self.assertNotEqual(self.testslicer, testslicer2)
     # Set up a different kind of slicer that should not match.
     testslicer2 = UniSlicer()
     dv2 = makeDataValues(100, 0, 1, random=True)
     testslicer2.setupSlicer(dv2)
     self.assertNotEqual(self.testslicer, testslicer2)
예제 #10
0
    def testSlicerEquivalence(self):
        """Test that slicers are marked equal when appropriate, and unequal when appropriate."""
        # Note that opsimfield slicers are considered 'equal' when all fieldId's, RA and Decs match.
        testslicer2 = OpsimFieldSlicer()
        fieldData2 = np.copy(self.fieldData)
        testslicer2.setupSlicer(self.simData, fieldData2)
        # These slicers should be equal.
        self.assertTrue(self.testslicer == testslicer2)
        self.assertFalse(self.testslicer != testslicer2)
        # These slicers should not be equal.
        fieldData2['fieldId'] = fieldData2['fieldId'] + 1
        testslicer2.setupSlicer(self.simData, fieldData2)
        self.assertTrue(self.testslicer != testslicer2)
        self.assertFalse(self.testslicer == testslicer2)
        # Test a slicer that is not the same kind.
        testslicer2 = UniSlicer()
        self.assertNotEqual(self.testslicer, testslicer2)
        # Test slicers that haven't been setup
        ts1 = OpsimFieldSlicer()
        ts2 = OpsimFieldSlicer()

        self.assertTrue(ts1 == ts2)
        self.assertFalse(ts1 != ts2)
        # Set up one with an odd value.
        ts2 = OpsimFieldSlicer(fieldRaColName='WackyName')
        self.assertTrue(ts1 != ts2)
        self.assertFalse(ts1 == ts2)
예제 #11
0
 def testEquivalence(self):
     """Test equals method."""
     # Note that two OneD slicers will be considered equal if they are both the same kind of
     # slicer AND have the same bins.
     # Set up self..
     dvmin = 0
     dvmax = 1
     nvalues = 1000
     bins = np.arange(dvmin, dvmax, 0.01)
     dv = makeDataValues(nvalues, dvmin, dvmax, random=32499)
     self.testslicer = OneDSlicer(sliceColName='testdata', bins=bins)
     self.testslicer.setupSlicer(dv)
     # Set up another slicer to match (same bins, although not the same data).
     dv2 = makeDataValues(nvalues + 100, dvmin, dvmax, random=334)
     testslicer2 = OneDSlicer(sliceColName='testdata', bins=bins)
     testslicer2.setupSlicer(dv2)
     self.assertTrue(self.testslicer == testslicer2)
     self.assertFalse(self.testslicer != testslicer2)
     # Set up another slicer that should not match (different bins)
     dv2 = makeDataValues(nvalues, dvmin + 1, dvmax + 1, random=445)
     testslicer2 = OneDSlicer(sliceColName='testdata', bins=len(bins))
     testslicer2.setupSlicer(dv2)
     self.assertTrue(self.testslicer != testslicer2)
     self.assertFalse(self.testslicer == testslicer2)
     # Set up a different kind of slicer that should not match.
     dv2 = makeDataValues(100, 0, 1, random=12)
     testslicer2 = UniSlicer()
     testslicer2.setupSlicer(dv2)
     self.assertTrue(self.testslicer != testslicer2)
     self.assertFalse(self.testslicer == testslicer2)
     # Get another oneDslicer that is not set up, and check equivalence.
     testslicer2 = OneDSlicer(sliceColName='testdata')
     self.assertTrue(self.testslicer != testslicer2)
     self.assertFalse(self.testslicer == testslicer2)
     testslicer2 = OneDSlicer(sliceColName='testdata',
                              binMin=0,
                              binMax=1,
                              binsize=0.5)
     testslicer3 = OneDSlicer(sliceColName='testdata',
                              binMin=0,
                              binMax=1,
                              binsize=0.5)
     self.assertTrue(testslicer2 == testslicer3)
     self.assertFalse(testslicer2 != testslicer3)
     testslicer3 = OneDSlicer(sliceColName='testdata', binMin=0, binMax=1)
     self.assertFalse(testslicer2 == testslicer3)
     self.assertTrue(testslicer2 != testslicer3)
     usebins = np.arange(0, 1, 0.1)
     testslicer2 = OneDSlicer(sliceColName='testdata', bins=usebins)
     testslicer3 = OneDSlicer(sliceColName='testdata', bins=usebins)
     self.assertTrue(testslicer2 == testslicer3)
     self.assertFalse(testslicer2 != testslicer3)
     testslicer3 = OneDSlicer(sliceColName='testdata', bins=usebins + 1)
     self.assertFalse(testslicer2 == testslicer3)
     self.assertTrue(testslicer2 != testslicer3)
예제 #12
0
 def testEquivalence(self):
     """Test equals method."""
     # Note that two uni slicers will be considered equal if they are both the same kind of
     # slicer (unislicer). They will not necessarily slice data equally though (the indices are
     #  not necessarily the same!).
     # These should be the same, even though data is not the same.
     testslicer2 = UniSlicer()
     dv2 = makeDataValues(100, 0, 1, random=43298)
     testslicer2.setupSlicer(dv2)
     self.assertEqual(self.testslicer, testslicer2)
     # these will not be the same, as different slicer type.
     testslicer2 = OneDSlicer(sliceColName='testdata', bins=10)
     testslicer2.setupSlicer(dv2)
     self.assertNotEqual(self.testslicer, testslicer2)
예제 #13
0
 def testEquivalence(self):
     """Test equals method."""
     # Note that two uni slicers will be considered equal if they are both the same kind of
     # slicer (unislicer). They will not necessarily slice data equally though (the indices are
     #  not necessarily the same!).
     # These should be the same, even though data is not the same.
     testslicer2 = UniSlicer()
     dv2 = makeDataValues(100, 0, 1, random=43298)
     testslicer2.setupSlicer(dv2)
     self.assertEqual(self.testslicer, testslicer2)
     # these will not be the same, as different slicer type.
     testslicer2 = OneDSlicer(sliceColName='testdata', bins=10)
     testslicer2.setupSlicer(dv2)
     self.assertNotEqual(self.testslicer, testslicer2)
예제 #14
0
 def testEquivalence(self):
     """Test equals method."""
     # Note that two Movie slicers will be considered equal if they are both the same kind of
     # slicer AND have the same bins.
     # Set up self..
     dvmin = 0
     dvmax = 1
     nvalues = 1000
     bins = np.arange(dvmin, dvmax, 0.01)
     dv = makeTimes(nvalues, dvmin, dvmax)
     self.testslicer = MovieSlicer(sliceColName='times',
                                   bins=bins,
                                   cumulative=False,
                                   forceNoFfmpeg=True)
     self.testslicer.setupSlicer(dv)
     # Set up another slicer to match (same bins, although not the same data).
     dv2 = makeTimes(nvalues + 100, dvmin, dvmax)
     testslicer2 = MovieSlicer(sliceColName='times',
                               bins=bins,
                               cumulative=False,
                               forceNoFfmpeg=True)
     testslicer2.setupSlicer(dv2)
     self.assertEqual(self.testslicer, testslicer2)
     # Set up another slicer that should not match (different bins)
     dv2 = makeTimes(nvalues, dvmin + 1, dvmax + 1)
     testslicer2 = MovieSlicer(sliceColName='times',
                               bins=len(bins),
                               cumulative=False,
                               forceNoFfmpeg=True)
     testslicer2.setupSlicer(dv2)
     self.assertNotEqual(self.testslicer, testslicer2)
     # Set up a different kind of slicer that should not match.
     dv2 = makeTimes(100, 0, 1)
     testslicer2 = UniSlicer()
     testslicer2.setupSlicer(dv2)
     self.assertNotEqual(self.testslicer, testslicer2)
예제 #15
0
 def setUp(self):
     self.testslicer = UniSlicer()
예제 #16
0
 def setUp(self):
     self.testslicer = UniSlicer()