コード例 #1
0
ファイル: mccd_test.py プロジェクト: gulsumsr/hipercam
    def setUp(self):

        # build an MCCD
        self.level1 = 10.
        win1 = Winhead(31, 41, 5, 5, 1, 2)
        data1 = np.empty((win1.ny, win1.nx))
        data1[:] = self.level1
        wind1 = Window(win1, data1)

        self.level3 = 20.
        win2 = Winhead(250, 561, 5, 5, 1, 2)
        data2 = np.empty((win1.ny, win1.nx))
        data2[:] = self.level3
        wind2 = Window(win2, data2)

        winds = ((1, wind1), (3, wind2))

        head = fits.Header()
        head['OBJECT'] = ('Fake 1', 'Name')
        head['FILTER'] = ('r', 'Filter')
        ccd1 = CCD(winds, 2048, 1024, head)

        ccd2 = ccd1.copy()
        ccd2.head['FILTER'] = ('g', 'Filter')

        ccds = ((3, ccd1), (5, ccd2))
        head = fits.Header()
        head['TEST'] = 'This is HiPERCAM'

        self.mccd = MCCD(ccds, head)
コード例 #2
0
 def setUp(self):
     self.agroup = Agroup()
     win = Winhead(1, 1, 10, 10, 1, 1)
     self.val1 = 1.
     wind = Window(win, self.val1 * np.ones((win.ny, win.nx)))
     self.agroup[1] = wind
     win = Winhead(100, 200, 10, 10, 1, 1)
     self.val2 = 10.
     wind = Window(win, self.val2 * np.ones((win.ny, win.nx)))
     self.agroup[2] = wind
コード例 #3
0
ファイル: windat_test.py プロジェクト: gulsumsr/hipercam
    def setUp(self):

        # build some (small) Windows
        self.win1 = Winhead(31,41,3,4,1,2)
        self.data1 = np.ones((self.win1.ny,self.win1.nx))
        self.wind1 = Window(self.win1, self.data1)

        # should be compatible with win1
        self.wind2 = copy.deepcopy(self.wind1)

        # designed to be incompatible with win1
        self.wind3 = copy.deepcopy(self.wind1)
        self.wind3.llx += 1
コード例 #4
0
ファイル: windat_test.py プロジェクト: gulsumsr/hipercam
 def test_windat_rhdu(self):
     # writes to and then reads from an HDU
     hdu = self.wind1.whdu()
     wind = Window.rhdu(hdu)
     self.assertEqual(wind, self.wind1,
                      'recovered Window differs from original format')
     self.assertTrue((wind.data == self.wind1.data).all(),
                      'recovered Window differs from original data')
コード例 #5
0
ファイル: ccd_test.py プロジェクト: gulsumsr/hipercam
    def setUp(self):

        # build a CCD
        self.level1 = 10.
        win1 = Winhead(31,41,5,5,1,2)
        data1 = np.empty((win1.ny,win1.nx))
        data1[:] = self.level1
        wind1 = Window(win1,data1)

        self.level3 = 20.
        win2 = Winhead(250,561,5,5,1,2)
        data2 = np.empty((win1.ny,win1.nx))
        data2[:] = self.level3
        wind2 = Window(win2,data2)

        winds = ((1,wind1),(3,wind2))

        head = fits.Header()
        head['OBJECT'] = ('Fake 1','Name')
        self.ccd = CCD(winds, 2048, 1024, head)
コード例 #6
0
ファイル: windat_test.py プロジェクト: gulsumsr/hipercam
    def test_windat_add_noise(self):
        """Rather crude test this, but it should pick up disasters"""
        win = Winhead(1,1,100,100,1,1)
        data = np.zeros((win.ny,win.nx))
        wind = Window(win, data)

        wind.add_noise(1.,1.)
        mean = wind.mean()
        std = wind.std()
        npix = wind.size

        self.assertTrue(abs(mean) < 7./np.sqrt(npix),
                        'mean out of expected range')
        self.assertTrue(abs(std - 1.) < 7./np.sqrt(2*np.sqrt(npix)),
                        'standard deviation out of expected range')
コード例 #7
0
ファイル: windat_test.py プロジェクト: gulsumsr/hipercam
class TestWindow(unittest.TestCase):
    """Provides simple tests of almost every Window method and attribute. If any
    of these fail, something is badly wrong.

    """

    def setUp(self):

        # build some (small) Windows
        self.win1 = Winhead(31,41,3,4,1,2)
        self.data1 = np.ones((self.win1.ny,self.win1.nx))
        self.wind1 = Window(self.win1, self.data1)

        # should be compatible with win1
        self.wind2 = copy.deepcopy(self.wind1)

        # designed to be incompatible with win1
        self.wind3 = copy.deepcopy(self.wind1)
        self.wind3.llx += 1

    def test_windat_size(self):
        self.assertEqual(self.wind1.size, self.win1.nx*self.win1.ny,
                         'incorrect number of pixels returned')

    def test_windat_win(self):
        self.assertEqual(self.wind1.win, self.win1,
                         'incorrect Winhead returned')

    def test_windat_set_const(self):
        self.wind3.set_const(10.)
        self.assertEqual(self.wind3.data[0,0],10.,
                         'incorrect value returned')

    def test_windat_copy(self):
        wind = self.wind1.copy()
        wind.data[0,0] += 10
        self.assertEqual(wind.data[0,0],self.wind1.data[0,0]+10,
                         'data not correctly copied')

    def test_windat_nx_ny(self):
        self.wind1.data = np.ones((self.win1.ny+1,self.win1.nx+1))
        self.assertEqual(self.wind1.nx,self.win1.nx + 1,
                         'nx not working')
        self.assertEqual(self.wind1.ny,self.win1.ny + 1,
                         'ny not working')
 
    def test_windat_add_noise(self):
        """Rather crude test this, but it should pick up disasters"""
        win = Winhead(1,1,100,100,1,1)
        data = np.zeros((win.ny,win.nx))
        wind = Window(win, data)

        wind.add_noise(1.,1.)
        mean = wind.mean()
        std = wind.std()
        npix = wind.size

        self.assertTrue(abs(mean) < 7./np.sqrt(npix),
                        'mean out of expected range')
        self.assertTrue(abs(std - 1.) < 7./np.sqrt(2*np.sqrt(npix)),
                        'standard deviation out of expected range')

    def test_windat_whdu(self):
        hdu = self.wind1.whdu()
        self.assertIsInstance(hdu,fits.ImageHDU)
        head = hdu.header
        self.assertTrue('LLX' in head, 'LLX not found in HDU')
        self.assertTrue('LLY' in head, 'LLX not found in HDU')
        self.assertTrue('XBIN' in head, 'LLX not found in HDU')
        self.assertTrue('YBIN' in head, 'LLX not found in HDU')

    def test_windat_rhdu(self):
        # writes to and then reads from an HDU
        hdu = self.wind1.whdu()
        wind = Window.rhdu(hdu)
        self.assertEqual(wind, self.wind1,
                         'recovered Window differs from original format')
        self.assertTrue((wind.data == self.wind1.data).all(),
                         'recovered Window differs from original data')

    def test_windat_min(self):
        self.wind3.set_const(0.)
        self.wind3.data[0,0] = -1.
        self.assertEqual(self.wind3.min(), -1.,
                         'incorrect minimum returned')

    def test_windat_max(self):
        self.wind3.set_const(0.)
        self.wind3.data[0,0] = 1.
        self.assertEqual(self.wind3.max(), 1.,
                         'incorrect maxiumum returned')

    def test_windat_mean(self):
        self.wind3.set_const(0.)
        self.wind3.data[0,0] = 1.
        self.wind3.data[0,1] = -1.
        self.assertEqual(self.wind3.mean(), 0.,
                         'incorrect mean returned')

    def test_windat_std(self):
        win = Winhead(1,1,2,2,1,1)
        data = np.array([[-1.,-1.],[1.,1.]])
        wind = Window(win, data)
        self.assertEqual(wind.std(), 1.,
                         'incorrect standard deviation returned')

    def test_windat_percentile(self):
        win = Winhead(1,1,3,3,1,1)
        data = np.array([[-1.,-1.,-1.],[-1.,0.,1.],[1.,1.,1.]])
        wind = Window(win, data)
        self.assertEqual(wind.percentile(50.), 0.,
                         'incorrect percentile value returned')

    def test_windat_iadd(self):
        self.wind3.set_const(1.)
        self.wind3 += 1.
        self.assertEqual(self.wind3.data[0,0],2.,
                         'in place addition of constant failed')
        self.wind3 += self.wind3
        self.assertEqual(self.wind3.data[0,0],4.,
                         'in place addition of Window failed')

    def test_windat_isub(self):
        self.wind3.set_const(10.)
        self.wind3 -= 1.
        self.assertEqual(self.wind3.data[0,0],9.,
                         'in place subtraction of constant failed')
        self.wind3 -= self.wind3
        self.assertEqual(self.wind3.data[0,0],0.,
                         'in place subtraction of Window failed')

    def test_windat_imul(self):
        self.wind3.set_const(10.)
        self.wind3 *= 2.
        self.assertEqual(self.wind3.data[0,0],20.,
                         'in place multiplcation by constant failed')
        self.wind3 *= self.wind3
        self.assertEqual(self.wind3.data[0,0],400.,
                         'in place multiplcation by Window failed')

    def test_windat_itruediv(self):
        self.wind3.set_const(21.)
        self.wind3 /= 2.
        self.assertEqual(self.wind3.data[0,0],10.5,
                         'in place division by constant failed')
        self.wind3 /= self.wind3
        self.assertEqual(self.wind3.data[0,0],1.,
                         'in place division by Window failed')

    def test_windat_add(self):
        self.wind3.set_const(1.)
        self.wind3 = self.wind3 + 1.
        self.assertEqual(self.wind3.data[0,0],2.,
                         'addition of constant failed')
        self.wind3 = self.wind3 + self.wind3
        self.assertEqual(self.wind3.data[0,0],4.,
                         'addition of Window failed')

    def test_windat_sub(self):
        self.wind3.set_const(10.)
        self.wind3 = self.wind3 -  1.
        self.assertEqual(self.wind3.data[0,0],9.,
                         'subtraction of constant failed')
        self.wind3 = self.wind3 - self.wind3
        self.assertEqual(self.wind3.data[0,0],0.,
                         'subtraction of Window failed')

    def test_windat_mul(self):
        self.wind3.set_const(2.)
        self.wind3 = self.wind3 *  2.
        self.assertEqual(self.wind3.data[0,0],4.,
                         'multiplication by constant failed')
        self.wind3 = self.wind3 * self.wind3
        self.assertEqual(self.wind3.data[0,0],16.,
                         'multiplication by Window failed')

    def test_windat_truediv(self):
        self.wind3.set_const(6.)
        self.wind3 = self.wind3 /  2.
        self.assertEqual(self.wind3.data[0,0],3.,
                         'division by constant failed')
        self.wind3 = self.wind3 / self.wind3
        self.assertEqual(self.wind3.data[0,0],1.,
                         'division by Window failed')

    def test_windat_radd(self):
        self.wind3.set_const(1.)
        self.wind3 = 1. + self.wind3
        self.assertEqual(self.wind3.data[0,0],2.,
                         'addition to a constant failed')

    def test_windat_rsub(self):
        self.wind3.set_const(1.)
        self.wind3 = 10. - self.wind3
        self.assertEqual(self.wind3.data[0,0],9.,
                         'subtraction from a constant failed')

    def test_windat_rmul(self):
        self.wind3.set_const(2.)
        self.wind3 = 10. * self.wind3
        self.assertEqual(self.wind3.data[0,0],20.,
                         'multiplication of a constant failed')

    def test_windat_rtruediv(self):
        self.wind3.set_const(2.)
        self.wind3 = 10. / self.wind3
        self.assertEqual(self.wind3.data[0,0],5.,
                         'division of a constant failed')
コード例 #8
0
ファイル: windat_test.py プロジェクト: gulsumsr/hipercam
 def test_windat_percentile(self):
     win = Winhead(1,1,3,3,1,1)
     data = np.array([[-1.,-1.,-1.],[-1.,0.,1.],[1.,1.,1.]])
     wind = Window(win, data)
     self.assertEqual(wind.percentile(50.), 0.,
                      'incorrect percentile value returned')
コード例 #9
0
ファイル: windat_test.py プロジェクト: gulsumsr/hipercam
 def test_windat_std(self):
     win = Winhead(1,1,2,2,1,1)
     data = np.array([[-1.,-1.],[1.,1.]])
     wind = Window(win, data)
     self.assertEqual(wind.std(), 1.,
                      'incorrect standard deviation returned')