Ejemplo n.º 1
0
class TestHealpixSlicerIteration(unittest.TestCase):

    def setUp(self):
        self.nside = 8
        self.testslicer = HealpixSlicer(nside=self.nside, verbose=False, lonCol='ra', latCol='dec')
        nvalues = 10000
        self.dv = makeDataValues(size=nvalues, minval=0., maxval=1.,
                                 ramin=0, ramax=2*np.pi,
                                 decmin=-np.pi, decmax=0,
                                 random=True)
        self.testslicer.setupSlicer(self.dv)

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

    def testIteration(self):
        """Test iteration goes through expected range and ra/dec are in expected range (radians)."""
        npix = hp.nside2npix(self.nside)
        for i, s in enumerate(self.testslicer):
            self.assertEqual(i, s['slicePoint']['sid'])
            ra = s['slicePoint']['ra']
            dec = s['slicePoint']['dec']
            self.assertGreaterEqual(ra, 0)
            self.assertLessEqual(ra, 2*np.pi)
            self.assertGreaterEqual(dec, -np.pi)
            self.assertLessEqual(dec, np.pi)
        # npix would count starting at 1, while i counts starting at 0 ..
        #  so add one to check end point
        self.assertEqual(i+1, npix)

    def testGetItem(self):
        """Test getting indexed value."""
        for i, s in enumerate(self.testslicer):
            np.testing.assert_equal(self.testslicer[i], s)
Ejemplo n.º 2
0
class TestHealpixSlicerIteration(unittest.TestCase):

    def setUp(self):
        self.nside = 8
        self.testslicer = HealpixSlicer(nside=self.nside, verbose=False, lonCol='ra', latCol='dec')
        nvalues = 10000
        self.dv = makeDataValues(size=nvalues, minval=0., maxval=1.,
                                 ramin=0, ramax=2*np.pi,
                                 decmin=-np.pi, decmax=0,
                                 random=33)
        self.testslicer.setupSlicer(self.dv)

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

    def testIteration(self):
        """Test iteration goes through expected range and ra/dec are in expected range (radians)."""
        npix = hp.nside2npix(self.nside)
        for i, s in enumerate(self.testslicer):
            self.assertEqual(i, s['slicePoint']['sid'])
            ra = s['slicePoint']['ra']
            dec = s['slicePoint']['dec']
            self.assertGreaterEqual(ra, 0)
            self.assertLessEqual(ra, 2*np.pi)
            self.assertGreaterEqual(dec, -np.pi)
            self.assertLessEqual(dec, np.pi)
        # npix would count starting at 1, while i counts starting at 0 ..
        #  so add one to check end point
        self.assertEqual(i+1, npix)

    def testGetItem(self):
        """Test getting indexed value."""
        for i, s in enumerate(self.testslicer):
            np.testing.assert_equal(self.testslicer[i], s)
Ejemplo n.º 3
0
class TestHealpixSlicerPlotting(unittest.TestCase):

    def setUp(self):
        self.nside = 16
        self.radius = 1.8
        self.testslicer = HealpixSlicer(nside=self.nside, verbose=False,
                                        lonCol='ra', latCol='dec', radius=self.radius)
        nvalues = 10000
        self.dv = makeDataValues(size=nvalues, minval=0., maxval=1.,
                                 ramin=0, ramax=2*np.pi,
                                 decmin=-np.pi, decmax=0,
                                 random=True)
        self.testslicer.setupSlicer(self.dv)
        self.metricdata = ma.MaskedArray(data=np.zeros(len(self.testslicer), dtype='float'),
                                         mask=np.zeros(len(self.testslicer), 'bool'),
                                         fill_value=self.testslicer.badval)
        for i, b in enumerate(self.testslicer):
            idxs = b['idxs']
            if len(idxs) > 0:
                self.metricdata.data[i] = np.mean(self.dv['testdata'][idxs])
            else:
                self.metricdata.mask[i] = True
        self.metricdata2 = ma.MaskedArray(data=np.random.rand(len(self.testslicer)),
                                          mask=np.zeros(len(self.testslicer), 'bool'),
                                          fill_value=self.testslicer.badval)

    def tearDown(self):
        del self.testslicer
        self.testslicer = None
Ejemplo n.º 4
0
class TestHealpixSlicerEqual(unittest.TestCase):

    def setUp(self):
        self.nside = 16
        self.testslicer = HealpixSlicer(nside=self.nside, verbose=False, lonCol='ra', latCol='dec')
        nvalues = 10000
        self.dv = makeDataValues(size=nvalues, minval=0., maxval=1.,
                                 ramin=0, ramax=2*np.pi,
                                 decmin=-np.pi, decmax=0,
                                 random=True)
        self.testslicer.setupSlicer(self.dv)

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

    def testSlicerEquivalence(self):
        """Test that slicers are marked equal when appropriate, and unequal when appropriate."""
        # Note that they are judged equal based on nsides (not on data in ra/dec spatial tree).
        testslicer2 = HealpixSlicer(nside=self.nside, verbose=False, lonCol='ra', latCol='dec')
        self.assertEqual(self.testslicer, testslicer2)
        assert((self.testslicer != testslicer2) is False)
        testslicer2 = HealpixSlicer(nside=self.nside/2.0, verbose=False, lonCol='ra', latCol='dec')
        self.assertNotEqual(self.testslicer, testslicer2)
        assert((self.testslicer != testslicer2) is True)
Ejemplo n.º 5
0
class TestHealpixChipGap(unittest.TestCase):
    # Note that this is really testing baseSpatialSlicer, as slicing is done there for healpix grid
    def setUp(self):
        self.nside = 8
        self.radius = 2.041
        self.testslicer = HealpixSlicer(nside=self.nside, verbose=False,
                                        lonCol='ra', latCol='dec',
                                        radius=self.radius, useCamera=True,
                                        chipNames=['R:1,1 S:1,1'])
        nvalues = 1000
        self.dv = makeDataValues(size=nvalues, minval=0., maxval=1.,
                                ramin=0, ramax=2*np.pi,
                                decmin=-np.pi, decmax=0,
                                random=True)

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

    def testSlicing(self):
        """Test slicing returns (most) data points which are within 'radius' of bin point."""
        # Test that slicing fails before setupSlicer
        self.assertRaises(NotImplementedError, self.testslicer._sliceSimData, 0)
        # Set up and test actual slicing.
        self.testslicer.setupSlicer(self.dv)
        for s in self.testslicer:
            ra = s['slicePoint']['ra']
            dec = s['slicePoint']['dec']
            distances = calcDist_vincenty(ra, dec, self.dv['ra'], self.dv['dec'])
            didxs = np.where(distances<=np.radians(self.radius))
            sidxs = s['idxs']
            self.assertTrue(len(sidxs) <= len(didxs[0]))
            if len(sidxs) > 0:
                for indx in sidxs:
                    self.assertTrue( self.dv['testdata'][indx] in self.dv['testdata'][didxs])
Ejemplo n.º 6
0
 def setUp(self):
     rng = np.random.RandomState(713244122)
     self.nside = 16
     self.radius = 1.8
     self.testslicer = HealpixSlicer(nside=self.nside,
                                     verbose=False,
                                     latLonDeg=False,
                                     lonCol='ra',
                                     latCol='dec',
                                     radius=self.radius)
     nvalues = 10000
     self.dv = makeDataValues(size=nvalues,
                              minval=0.,
                              maxval=1.,
                              ramin=0,
                              ramax=2 * np.pi,
                              decmin=-np.pi,
                              decmax=0,
                              random=66)
     self.testslicer.setupSlicer(self.dv)
     self.metricdata = ma.MaskedArray(data=np.zeros(len(self.testslicer),
                                                    dtype='float'),
                                      mask=np.zeros(len(self.testslicer),
                                                    'bool'),
                                      fill_value=self.testslicer.badval)
     for i, b in enumerate(self.testslicer):
         idxs = b['idxs']
         if len(idxs) > 0:
             self.metricdata.data[i] = np.mean(self.dv['testdata'][idxs])
         else:
             self.metricdata.mask[i] = True
     self.metricdata2 = ma.MaskedArray(data=rng.rand(len(self.testslicer)),
                                       mask=np.zeros(
                                           len(self.testslicer), 'bool'),
                                       fill_value=self.testslicer.badval)
Ejemplo n.º 7
0
class TestHealpixSlicerPlotting(unittest.TestCase):

    def setUp(self):
        rng = np.random.RandomState(713244122)
        self.nside = 16
        self.radius = 1.8
        self.testslicer = HealpixSlicer(nside=self.nside, verbose=False, latLonDeg=False,
                                        lonCol='ra', latCol='dec', radius=self.radius)
        nvalues = 10000
        self.dv = makeDataValues(size=nvalues, minval=0., maxval=1.,
                                 ramin=0, ramax=2*np.pi,
                                 decmin=-np.pi, decmax=0,
                                 random=66)
        self.testslicer.setupSlicer(self.dv)
        self.metricdata = ma.MaskedArray(data=np.zeros(len(self.testslicer), dtype='float'),
                                         mask=np.zeros(len(self.testslicer), 'bool'),
                                         fill_value=self.testslicer.badval)
        for i, b in enumerate(self.testslicer):
            idxs = b['idxs']
            if len(idxs) > 0:
                self.metricdata.data[i] = np.mean(self.dv['testdata'][idxs])
            else:
                self.metricdata.mask[i] = True
        self.metricdata2 = ma.MaskedArray(data=rng.rand(len(self.testslicer)),
                                          mask=np.zeros(len(self.testslicer), 'bool'),
                                          fill_value=self.testslicer.badval)

    def tearDown(self):
        del self.testslicer
        self.testslicer = None
Ejemplo n.º 8
0
class TestHealpixSlicerEqual(unittest.TestCase):

    def setUp(self):
        self.nside = 16
        self.testslicer = HealpixSlicer(nside=self.nside, verbose=False, lonCol='ra', latCol='dec')
        nvalues = 10000
        self.dv = makeDataValues(size=nvalues, minval=0., maxval=1.,
                                 ramin=0, ramax=2*np.pi,
                                 decmin=-np.pi, decmax=0,
                                 random=22)
        self.testslicer.setupSlicer(self.dv)

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

    def testSlicerEquivalence(self):
        """Test that slicers are marked equal when appropriate, and unequal when appropriate."""
        # Note that they are judged equal based on nsides (not on data in ra/dec spatial tree).
        testslicer2 = HealpixSlicer(nside=self.nside, verbose=False, lonCol='ra', latCol='dec')
        self.assertEqual(self.testslicer, testslicer2)
        assert((self.testslicer != testslicer2) is False)
        testslicer2 = HealpixSlicer(nside=self.nside/2.0, verbose=False, lonCol='ra', latCol='dec')
        self.assertNotEqual(self.testslicer, testslicer2)
        assert((self.testslicer != testslicer2) is True)
Ejemplo n.º 9
0
 def setUp(self):
     self.nside = 16
     self.testslicer = HealpixSlicer(nside=self.nside, verbose=False, lonCol='ra', latCol='dec')
     nvalues = 10000
     self.dv = makeDataValues(size=nvalues, minval=0., maxval=1.,
                              ramin=0, ramax=2*np.pi,
                              decmin=-np.pi, decmax=0,
                              random=True)
     self.testslicer.setupSlicer(self.dv)
Ejemplo n.º 10
0
 def testSlicerEquivalence(self):
     """Test that slicers are marked equal when appropriate, and unequal when appropriate."""
     # Note that they are judged equal based on nsides (not on data in ra/dec spatial tree).
     testslicer2 = HealpixSlicer(nside=self.nside, verbose=False, lonCol='ra', latCol='dec')
     self.assertEqual(self.testslicer, testslicer2)
     assert((self.testslicer != testslicer2) is False)
     testslicer2 = HealpixSlicer(nside=self.nside/2.0, verbose=False, lonCol='ra', latCol='dec')
     self.assertNotEqual(self.testslicer, testslicer2)
     assert((self.testslicer != testslicer2) is True)
Ejemplo n.º 11
0
 def setUp(self):
     self.nside = 8
     self.radius = 1.8
     self.testslicer = HealpixSlicer(nside=self.nside, verbose=False,
                                     lonCol='ra', latCol='dec', latLonDeg=False,
                                     radius=self.radius)
     nvalues = 10000
     self.dv = makeDataValues(size=nvalues, minval=0., maxval=1.,
                              ramin=0, ramax=2*np.pi,
                              decmin=-np.pi, decmax=0,
                              random=44)
Ejemplo n.º 12
0
 def setUp(self):
     self.nside = 8
     self.radius = 2.041
     self.testslicer = HealpixSlicer(nside=self.nside, verbose=False,
                                     lonCol='ra', latCol='dec',
                                     radius=self.radius, useCamera=True,
                                     chipNames=['R:1,1 S:1,1'])
     nvalues = 1000
     self.dv = makeDataValues(size=nvalues, minval=0., maxval=1.,
                              ramin=0, ramax=2*np.pi,
                              decmin=-np.pi, decmax=0,
                              random=True)
Ejemplo n.º 13
0
 def testNsidesNbins(self):
     """Test that number of sides passed to slicer produces expected number of bins."""
     nsides = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512]
     npixx = [12, 48, 192, 768, 3072, 12288, 49152, 196608, 786432, 3145728]
     for nside, npix in zip(nsides, npixx):
         testslicer = HealpixSlicer(nside=nside, verbose=False)
         self.assertEqual(testslicer.nslice, npix)
Ejemplo n.º 14
0
class TestHealpixSlicerSlicing(unittest.TestCase):
    # Note that this is really testing baseSpatialSlicer, as slicing is done there for healpix grid

    def setUp(self):
        self.nside = 8
        self.radius = 1.8
        self.testslicer = HealpixSlicer(nside=self.nside,
                                        verbose=False,
                                        lonCol='ra',
                                        latCol='dec',
                                        latLonDeg=False,
                                        radius=self.radius)
        nvalues = 10000
        self.dv = makeDataValues(size=nvalues,
                                 minval=0.,
                                 maxval=1.,
                                 ramin=0,
                                 ramax=2 * np.pi,
                                 decmin=-np.pi,
                                 decmax=0,
                                 random=44)

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

    def testSlicing(self):
        """Test slicing returns (all) data points which are within 'radius' of bin point."""
        # Test that slicing fails before setupSlicer
        self.assertRaises(NotImplementedError, self.testslicer._sliceSimData,
                          0)
        # Set up and test actual slicing.
        self.testslicer.setupSlicer(self.dv)
        for s in self.testslicer:
            ra = s['slicePoint']['ra']
            dec = s['slicePoint']['dec']
            distances = calcDist_vincenty(ra, dec, self.dv['ra'],
                                          self.dv['dec'])
            didxs = np.where(distances <= np.radians(self.radius))
            sidxs = s['idxs']
            self.assertEqual(len(sidxs), len(didxs[0]))
            if len(sidxs) > 0:
                didxs = np.sort(didxs[0])
                sidxs = np.sort(sidxs)
                np.testing.assert_equal(self.dv['testdata'][didxs],
                                        self.dv['testdata'][sidxs])
Ejemplo n.º 15
0
 def setUp(self):
     self.nside = 16
     self.testslicer = HealpixSlicer(nside=self.nside, verbose=False, lonCol='ra', latCol='dec')
     nvalues = 10000
     self.dv = makeDataValues(size=nvalues, minval=0., maxval=1.,
                              ramin=0, ramax=2*np.pi,
                              decmin=-np.pi, decmax=0,
                              random=22)
     self.testslicer.setupSlicer(self.dv)
Ejemplo n.º 16
0
 def setUp(self):
     self.nside = 8
     self.radius = 1.8
     self.testslicer = HealpixSlicer(nside=self.nside, verbose=False,
                                     lonCol='ra', latCol='dec', latLonDeg=False,
                                     radius=self.radius)
     nvalues = 10000
     self.dv = makeDataValues(size=nvalues, minval=0., maxval=1.,
                              ramin=0, ramax=2*np.pi,
                              decmin=-np.pi, decmax=0,
                              random=44)
Ejemplo n.º 17
0
 def setUp(self):
     self.nside = 8
     self.radius = 2.041
     self.testslicer = HealpixSlicer(nside=self.nside, verbose=False,
                                     lonCol='ra', latCol='dec', latLonDeg=False,
                                     radius=self.radius, useCamera=True,
                                     chipNames=['R:1,1 S:1,1'])
     nvalues = 1000
     self.dv = makeDataValues(size=nvalues, minval=0., maxval=1.,
                              ramin=0, ramax=2*np.pi,
                              decmin=-np.pi, decmax=0,
                              random=55)
Ejemplo n.º 18
0
class TestHealpixSlicerSlicing(unittest.TestCase):
    # Note that this is really testing baseSpatialSlicer, as slicing is done there for healpix grid

    def setUp(self):
        self.nside = 8
        self.radius = 1.8
        self.testslicer = HealpixSlicer(nside=self.nside, verbose=False,
                                        lonCol='ra', latCol='dec', latLonDeg=False,
                                        radius=self.radius)
        nvalues = 10000
        self.dv = makeDataValues(size=nvalues, minval=0., maxval=1.,
                                 ramin=0, ramax=2*np.pi,
                                 decmin=-np.pi, decmax=0,
                                 random=44)

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

    def testSlicing(self):
        """Test slicing returns (all) data points which are within 'radius' of bin point."""
        # Test that slicing fails before setupSlicer
        self.assertRaises(NotImplementedError, self.testslicer._sliceSimData, 0)
        # Set up and test actual slicing.
        self.testslicer.setupSlicer(self.dv)
        for s in self.testslicer:
            ra = s['slicePoint']['ra']
            dec = s['slicePoint']['dec']
            distances = calcDist_vincenty(ra, dec, self.dv['ra'], self.dv['dec'])
            didxs = np.where(distances <= np.radians(self.radius))
            sidxs = s['idxs']
            self.assertEqual(len(sidxs), len(didxs[0]))
            if len(sidxs) > 0:
                didxs = np.sort(didxs[0])
                sidxs = np.sort(sidxs)
                np.testing.assert_equal(self.dv['testdata'][didxs], self.dv['testdata'][sidxs])
 def setUp(self):
     self.nside = 16
     self.radius = 1.8
     self.testslicer = HealpixSlicer(nside=self.nside, verbose=False,
                                     lonCol='ra', latCol='dec', radius=self.radius)
     nvalues = 10000
     self.dv = makeDataValues(size=nvalues, minval=0., maxval=1.,
                             ramin=0, ramax=2*np.pi,
                             decmin=-np.pi, decmax=0,
                             random=True)
     self.testslicer.setupSlicer(self.dv)
     self.metricdata = ma.MaskedArray(data = np.zeros(len(self.testslicer), dtype='float'),
                                      mask = np.zeros(len(self.testslicer), 'bool'),
                                      fill_value = self.testslicer.badval)
     for i, b in enumerate(self.testslicer):
         idxs = b['idxs']
         if len(idxs) > 0:
             self.metricdata.data[i] = np.mean(self.dv['testdata'][idxs])
         else:
             self.metricdata.mask[i] = True
     self.metricdata2 = ma.MaskedArray(data = np.random.rand(len(self.testslicer)),
                                       mask = np.zeros(len(self.testslicer), 'bool'),
                                       fill_value = self.testslicer.badval)
Ejemplo n.º 20
0
 def testSlicertype(self):
     """Test instantiation of slicer sets slicer type as expected."""
     testslicer = HealpixSlicer(nside=16, verbose=False)
     self.assertEqual(testslicer.slicerName, testslicer.__class__.__name__)
     self.assertEqual(testslicer.slicerName, 'HealpixSlicer')