def test_cor_math(self): """Test mathematical operations on COR frame data via frames.""" fh = open(corFile, 'rb') # Frames 1 through 29 frames = [] for i in range(1, 30): frames.append(cor.read_frame(fh)) fh.close() # Multiplication frameT = frames[0] * 2.0 for i in range(72): for j in range(2): for k in range(2): self.assertAlmostEqual(frameT.payload.data[i, j, k], 2 * frames[0].payload.data[i, j, k], 2) frameT *= 2.0 for i in range(72): for j in range(2): for k in range(2): self.assertAlmostEqual(frameT.payload.data[i, j, k], 4 * frames[0].payload.data[i, j, k], 2) frameT = frames[0] * frames[1] for i in range(72): for j in range(2): for k in range(2): self.assertAlmostEqual( frameT.payload.data[i, j, k], frames[0].payload.data[i, j, k] * frames[1].payload.data[i, j, k], 2) # Addition frameA = frames[0] + 2.0 for i in range(72): for j in range(2): for k in range(2): self.assertAlmostEqual(frameA.payload.data[i, j, k], 2 + frames[0].payload.data[i, j, k], 2) frameA += 2.0 for i in range(72): for j in range(2): for k in range(2): self.assertAlmostEqual(frameA.payload.data[i, j, k], 4 + frames[0].payload.data[i, j, k], 2) frameA = frames[0] + frames[1] for i in range(72): for j in range(2): for k in range(2): self.assertAlmostEqual( frameA.payload.data[i, j, k], frames[0].payload.data[i, j, k] + frames[1].payload.data[i, j, k], 2)
def test_cor_read(self): """Test reading in a frame from a COR file.""" fh = open(corFile, 'rb') # First frame is really COR and check the basic metadata frame1 = cor.read_frame(fh) self.assertTrue(frame1.header.is_cor) self.assertEqual(frame1.header.first_chan, 1584) self.assertEqual(frame1.id, (1, 1)) self.assertEqual(frame1.integration_time, 5) self.assertEqual(frame1.gain, 1) # Second frame frame2 = cor.read_frame(fh) self.assertTrue(frame2.header.is_cor) self.assertEqual(frame2.header.first_chan, 1584) self.assertEqual(frame2.id, (1, 2)) self.assertEqual(frame2.integration_time, 5) self.assertEqual(frame2.gain, 1) fh.close()
def test_cor_sort(self): """Test sorting COR frames by time tags.""" fh = open(corFile, 'rb') # Frames 1 through 29 frames = [] for i in range(1, 30): frames.append(cor.read_frame(fh)) fh.close() frames.sort() frames = frames[::-1] for i in range(1, len(frames)): self.assertTrue(frames[i - 1] >= frames[i])
def test_cor_comps(self): """Test the COR frame comparison operators (>, <, etc.) for time tags.""" fh = open(corFile, 'rb') # Frames 1 through 29 frames = [] for i in range(1, 30): frames.append(cor.read_frame(fh)) fh.close() self.assertTrue(0 < frames[0]) self.assertFalse(0 > frames[0]) self.assertTrue(frames[-1] >= frames[0]) self.assertTrue(frames[-1] <= frames[0]) self.assertTrue(frames[0] == frames[0]) self.assertFalse(frames[0] != frames[-1]) self.assertFalse(frames[0] != frames[0])
def test_cor_errors(self): """Test COR reading errors.""" fh = open(corFile, 'rb') # Frames 1 through 65 for i in range(1, 66): frame = cor.read_frame(fh) # Last frame should be an error (errors.EOFError) self.assertRaises(errors.EOFError, cor.read_frame, fh) fh.close() # If we offset in the file by 1 byte, we should be a # sync error (errors.SyncError). fh = open(corFile, 'rb') fh.seek(1) self.assertRaises(errors.SyncError, cor.read_frame, fh) fh.close()
def test_cor_math(self): """Test mathematical operations on COR frame data via frames.""" fh = open(corFile, 'rb') # Frames 1 through 29 frames = [] for i in range(1, 30): frames.append(cor.read_frame(fh)) fh.close() # Multiplication frameT = frames[0] * 2.0 numpy.testing.assert_allclose(frameT.payload.data, 2 * frames[0].payload.data, atol=1e-6) frameT *= 2.0 numpy.testing.assert_allclose(frameT.payload.data, 4 * frames[0].payload.data, atol=1e-6) frameT = frames[0] * frames[1] numpy.testing.assert_allclose(frameT.payload.data, frames[0].payload.data * frames[1].payload.data, atol=1e-6) # Addition frameA = frames[0] + 2.0 numpy.testing.assert_allclose(frameA.payload.data, 2 + frames[0].payload.data, atol=1e-6) frameA += 2.0 numpy.testing.assert_allclose(frameA.payload.data, 4 + frames[0].payload.data, atol=1e-6) frameA = frames[0] + frames[1] numpy.testing.assert_allclose(frameA.payload.data, frames[0].payload.data + frames[1].payload.data, atol=1e-6)