Exemplo n.º 1
0
 def __init__(self, theDfsr, theFileId, xAxisIndex=0):
     """Constructed with an EFLR i.e. a DFSR
     
     theDfsr - The DFSR.
 
     theFileId - The ID of the file, this will be checked against any File object passed to me.
 
     xAxisIndex - The index of the DSB block that describes the X axis, if indirect X this is ignored.
     """
     # Check input. We take a strict view here of what a LogPass can support
     # The DFSR must have at least one DSB even if indirect X otherwise
     # a LogPass does not make a lot of sense when there are zero channels.
     if len(theDfsr.dsbBlocks) == 0:
         raise ExceptionLogPassCtor('LogPass.__init__(): xAxisIndex no channels to process')
     if xAxisIndex < 0 or xAxisIndex >= len(theDfsr.dsbBlocks):
         raise ExceptionLogPassCtor('LogPass.__init__(): xAxisIndex {:s} out of range when number of DSB blocks={:d}'.format(str(xAxisIndex), len(theDfsr.dsbBlocks)))
     self._dfsr = theDfsr
     self._fileId = theFileId
     self._plan = Type01Plan.FrameSetPlan(self._dfsr)
     self._xAxisIndex = xAxisIndex
     # This is a map of {MNEM : (extCh, sub_ch), ...}
     # Warnings are produced for duplicates which are ignored. In principle
     # as a PRES table (for example) can only identify a channel by MNEM
     # then we assume here that the MNEM is unique.
     self._chMap = self._retChMap()
     # A map of {Mnem.Mnem(MNEM) : Mnem.Mnem(UNITS), ...} from the DFSR
     self._unitMap = self._retUnitMap()
     # Populated by setFrameSet() when the time comes
     self._frameSet = None
     # Set up RLE object
     if self.isIndirectX:
         self._rle = Rle.RLEType01(self._dfsr.ebs.depthUnits)
     else:
         assert(self._xAxisIndex >= 0 and self._xAxisIndex < len(self._dfsr.dsbBlocks))
         self._rle = Rle.RLEType01(self._dfsr.dsbBlocks[self._xAxisIndex].units)
Exemplo n.º 2
0
 def test_02(self):
     """TestRleType01.test_02(): Basic test, variable frame size, variable X axis value."""
     myR = Rle.RLEType01(b'FEET')
     myInput = range(0, 3 * 8, 3)
     for i, v in enumerate(myInput):
         #print('test_01()', v)
         if i % 4 == 0:
             myR.add(v, 1024, 4.2 * i)
         else:
             myR.add(v, 512, 4.2 * i)
     self.assertEqual(len(myR), 4)
     #print()
     #print([aV for aV in myR.values()])
     self.assertEqual(myR.num_values(), len(myInput))
     self.assertEqual([aV for aV in myR.values()],
                      [(0, 1024, 0.0), (3, 512, 4.2), (6, 512, 2 * 4.2),
                       (9, 512, 3 * 4.2), (12, 1024, 4 * 4.2),
                       (15, 512, 5 * 4.2), (18, 512, 6 * 4.2),
                       (21, 512, 29.400000000000006)])
     for i, v in enumerate(myInput):
         self.assertEqual(myR.value(i)[0], v)
     # Check property access
     print(str(myR))
     self.assertEqual(myR[0].datum, 0)
     self.assertEqual(myR[0].stride, 0)
     self.assertEqual(myR[0].repeat, 0)
Exemplo n.º 3
0
 def test_00(self):
     """TestRleType01.test_00(): Basic test, single range."""
     myR = Rle.RLEType01(b'FEET')
     myInput = range(0, 3 * 8, 3)
     for v in myInput:
         myR.add(v, 1024, 4.2)
     self.assertEqual(len(myR), 1)
     self.assertEqual(myR.num_values(), len(myInput))
     #print([aV for aV in myR.values()])
     self.assertEqual([aV for aV in myR.values()], [(0, 1024, 4.2),
                                                    (3, 1024, 4.2),
                                                    (6, 1024, 4.2),
                                                    (9, 1024, 4.2),
                                                    (12, 1024, 4.2),
                                                    (15, 1024, 4.2),
                                                    (18, 1024, 4.2),
                                                    (21, 1024, 4.2)])
     for i, v in enumerate(myInput):
         self.assertEqual(myR.value(i)[0], v)
     # Check property access
     self.assertEqual(myR[0].datum, 0)
     self.assertEqual(myR[0].stride, 3)
     self.assertEqual(myR[0].repeat, 7)
     #print()
     #print('myR.rangeList()', myR.rangeList())
     #print('list of lists', [list(r) for r in myR.rangeList()])
     #print('First/last:', 'First', myR.first(), 'Last', myR.last())
     self.assertEqual([[0, 3, 6, 9, 12, 15, 18, 21]],
                      [list(r) for r in myR.ranges()])
     self.assertEqual(0, myR.first())
     self.assertEqual(21, myR.last())
Exemplo n.º 4
0
 def test_01(self):
     """TestRle.test_01(): Basic test, multiple ranges."""
     myR = Rle.RLE()
     myInput = list(range(0, 3 * 8, 3)) + list(range(72, 95, 1)) + list(
         range(105, 117, 2))
     for v in myInput:
         myR.add(v)
     # Three ranges
     self.assertEqual(len(myR), 3)
     self.assertEqual(myR.numValues(), len(myInput))
     self.assertEqual([aV for aV in myR.values()], myInput)
     for i, v in enumerate(myInput):
         self.assertEqual(myR.value(i), v)
     # Check property access
     self.assertEqual(myR[0].datum, 0)
     self.assertEqual(myR[0].stride, 3)
     self.assertEqual(myR[0].repeat, 7)
     self.assertEqual(myR[1].datum, 72)
     self.assertEqual(myR[1].stride, 1)
     self.assertEqual(myR[1].repeat, 95 - 72 - 1)
     self.assertEqual(myR[2].datum, 105)
     self.assertEqual(myR[2].stride, 2)
     self.assertEqual(myR[2].repeat, ((117 - 105) // 2) - 1)
     #print()
     #print(myR)
     str(myR)
Exemplo n.º 5
0
 def test_00_00(self):
     """TestRle.test_00_00(): Basic test, empty."""
     myR = Rle.RLE()
     self.assertEqual(len(myR), 0)
     self.assertEqual(myR.numValues(), 0)
     self.assertEqual([aV for aV in myR.values()], [])
     self.assertRaises(IndexError, myR.value, 0)
Exemplo n.º 6
0
 def test_05(self):
     """TestRle.test_05(): Basic test, multiple ranges, first/last and range recovery."""
     myR = Rle.RLE()
     myInput = list(range(0, 3 * 8, 3)) + list(range(72, 95, 1)) + list(
         range(105, 117, 2))
     for v in myInput:
         myR.add(v)
     # Three ranges
     self.assertEqual(len(myR), 3)
     self.assertEqual(myR.numValues(), len(myInput))
     self.assertEqual([aV for aV in myR.values()], myInput)
     myList = list(myInput)
     #print()
     #print(myList)
     for i in range(-1, -1 * (len(myInput) + 1), -1):
         #print(i, myList[i], myR.value(i))
         self.assertEqual(myR.value(i), myList[i])
     #print(myR.rangeList())
     #print([list(r) for r in myR.rangeList()])
     # Can not do direct range() comparison
     self.assertEqual([
         list(range(0, 24, 3)),
         list(range(72, 95)),
         list(range(105, 117, 2))
     ], [list(r) for r in myR.rangeList()])
     #print(myR.first())
     self.assertEqual(0, myR.first())
     #print(myR.last())
     self.assertEqual(115, myR.last())
Exemplo n.º 7
0
 def test_00(self):
     """TestRleType01XAxis.test_00(): Basic test, single range, down log."""
     myR = Rle.RLEType01(b'FEET')
     myInput = range(0, 2048, 128)
     totalF = 0
     for i, v in enumerate(myInput):
         myR.add(v, 8, 8 * 0.5 * i)
         totalF += 8
     self.assertEqual(len(myR), 1)
     self.assertEqual(myR.totalFrames(), totalF)
     #        print()
     #        #print(myR)
     #        print('X first', myR.xAxisFirst())
     #        print('X last', myR.xAxisLast())
     #        print('X units', myR.xAxisUnits)
     #        print('Frame spacing', myR.frameSpacing())
     #        print('Total Frames', myR.totalFrames())
     #        print('4.2*i', 4.2*i)
     str(myR)
     self.assertEqual(b'FEET', myR.xAxisUnits)
     self.assertTrue(myR.hasXaxisData)
     self.assertEqual(0.0, myR.xAxisFirst())
     self.assertEqual(60.0, myR.xAxisLast())
     self.assertEqual(63.5, myR.xAxisLastFrame())
     self.assertEqual(0.5, myR.frameSpacing())
     self.assertEqual(128, myR.totalFrames())
Exemplo n.º 8
0
 def test_00_01(self):
     """TestRle.test_00_01(): Basic test, single value."""
     myR = Rle.RLE()
     myR.add(8)
     self.assertEqual(len(myR), 1)
     self.assertEqual(myR.numValues(), 1)
     self.assertEqual([aV for aV in myR.values()], [
         8,
     ])
     self.assertEqual(myR.value(0), 8)
     # Check property access
     self.assertEqual(myR[0].datum, 8)
     self.assertEqual(myR[0].stride, None)
     self.assertEqual(myR[0].repeat, 0)
Exemplo n.º 9
0
 def test_00(self):
     """TestRle.test_00(): Basic test, single range."""
     myR = Rle.RLE()
     myInput = range(0, 3 * 8, 3)
     for v in myInput:
         myR.add(v)
     self.assertEqual(len(myR), 1)
     self.assertEqual(myR.numValues(), len(myInput))
     self.assertEqual([aV for aV in myR.values()], list(myInput))
     for i, v in enumerate(myInput):
         self.assertEqual(myR.value(i), v)
     # Check property access
     self.assertEqual(myR[0].datum, 0)
     self.assertEqual(myR[0].stride, 3)
     self.assertEqual(myR[0].repeat, 7)
Exemplo n.º 10
0
 def test_04(self):
     """TestRle.test_04(): Basic test, single range of constant numbers."""
     myR = Rle.RLE()
     v = 1
     for v in range(4):
         myR.add(1)
     self.assertEqual(len(myR), 1)
     self.assertEqual(myR.numValues(), 4)
     self.assertEqual([aV for aV in myR.values()], [1, 1, 1, 1])
     for i, v in enumerate(range(4)):
         self.assertEqual(myR.value(i), 1)
     # Check property access
     self.assertEqual(myR[0].datum, 1)
     self.assertEqual(myR[0].stride, 0)
     self.assertEqual(myR[0].repeat, 3)
Exemplo n.º 11
0
 def test_03(self):
     """TestRle.test_03(): Basic test, multiple ranges, negative indexing."""
     myR = Rle.RLE()
     #myInput = list(range(0, 3*2, 3)) + list(range(72, 75, 1)) + list(range(105, 109, 2))
     myInput = list(range(0, 3 * 8, 3)) + list(range(72, 95, 1)) + list(
         range(105, 117, 2))
     for v in myInput:
         myR.add(v)
     # Three ranges
     self.assertEqual(len(myR), 3)
     self.assertEqual(myR.numValues(), len(myInput))
     self.assertEqual([aV for aV in myR.values()], myInput)
     myList = list(myInput)
     #print(myList)
     for i in range(-1, -1 * (len(myInput) + 1), -1):
         #print(i, myList[i], myR.value(i))
         self.assertEqual(myR.value(i), myList[i])
Exemplo n.º 12
0
 def test_02(self):
     """TestRle.test_02(): Basic test, single range, negative indexing."""
     myR = Rle.RLE()
     myInput = range(0, 3 * 8, 3)
     for v in myInput:
         myR.add(v)
     self.assertEqual(len(myR), 1)
     self.assertEqual([aV for aV in myR.values()], list(myInput))
     # Check property access
     self.assertEqual(myR[0].datum, 0)
     self.assertEqual(myR[0].stride, 3)
     self.assertEqual(myR[0].repeat, 7)
     # Test access from end
     myList = list(myInput)
     #print(myList)
     for i in range(-1, -1 * (len(myInput) + 1), -1):
         #print(i, myList[i], myR.value(i))
         self.assertEqual(myR.value(i), myList[i])
Exemplo n.º 13
0
 def test_03(self):
     """TestRleType01.test_02(): Basic test, variable frame size, variable X axis value. totalFrames()."""
     myR = Rle.RLEType01(b'FEET')
     myInput = range(0, 3 * 8, 3)
     totalF = 0
     for i, v in enumerate(myInput):
         #print('test_01()', v)
         if i % 4 == 0:
             myR.add(v, 1024, 4.2 * i)
             totalF += 1024
         else:
             myR.add(v, 512, 4.2 * i)
             totalF += 512
     self.assertEqual(len(myR), 4)
     self.assertEqual(myR.totalFrames(), totalF)
     self.assertEqual(myR[0].totalFrames(), 1024)
     self.assertEqual(myR[1].totalFrames(), 3 * 512)
     self.assertEqual(myR[2].totalFrames(), 1024)
     self.assertEqual(myR[3].totalFrames(), 3 * 512)
Exemplo n.º 14
0
 def test_04(self):
     """TestRleType01.test_04(): Basic test, 128 byte LR, 4 frames each. tellLrForFrame()."""
     myR = Rle.RLEType01(b'FEET')
     myInput = range(0, 512, 128)
     fTotal = 0
     for i, v in enumerate(myInput):
         myR.add(v, 4, 4 * 0.5 * i)
         fTotal += 4
     #print()
     #print(myR)
     self.assertEqual(len(myR), 1)
     # 4 * 512 // 128 = 16
     self.assertEqual(fTotal, 16)
     self.assertEqual(myR.totalFrames(), fTotal)
     str(myR)
     #        self.assertEqual(str(myR), """RLEType01: func=None
     #  RLEItemType01: datum=0 stride=128 repeat=3 frames=4""")
     #for f in range(totalF):
     #    print(f, myR.tellLrForFrame(f))
     # RLEItem[0]
     self.assertEqual(myR.tellLrForFrame(0), (0, 0))
     self.assertEqual(myR.tellLrForFrame(1), (0, 1))
     self.assertEqual(myR.tellLrForFrame(2), (0, 2))
     self.assertEqual(myR.tellLrForFrame(3), (0, 3))
     self.assertEqual(myR.tellLrForFrame(4), (128, 0))
     self.assertEqual(myR.tellLrForFrame(5), (128, 1))
     self.assertEqual(myR.tellLrForFrame(6), (128, 2))
     self.assertEqual(myR.tellLrForFrame(7), (128, 3))
     self.assertEqual(myR.tellLrForFrame(8), (2 * 128, 0))
     self.assertEqual(myR.tellLrForFrame(9), (2 * 128, 1))
     self.assertEqual(myR.tellLrForFrame(10), (2 * 128, 2))
     self.assertEqual(myR.tellLrForFrame(11), (2 * 128, 3))
     self.assertEqual(myR.tellLrForFrame(12), (3 * 128, 0))
     self.assertEqual(myR.tellLrForFrame(13), (3 * 128, 1))
     self.assertEqual(myR.tellLrForFrame(14), (3 * 128, 2))
     self.assertEqual(myR.tellLrForFrame(15), (3 * 128, 3))
     # Failures
     self.assertRaises(IndexError, myR.tellLrForFrame, -1)
     self.assertRaises(IndexError, myR.tellLrForFrame, 16)
Exemplo n.º 15
0
 def test_00_00(self):
     """TestRleType01.test_00_00(): Basic test, single range with float() function."""
     myR = Rle.RLEType01(b'FEET', float)
     myInput = range(0, 3 * 8, 3)
     for v in myInput:
         myR.add(v, 1024, 4.2)
     self.assertEqual(len(myR), 1)
     self.assertEqual(myR.num_values(), len(myInput))
     #print([aV for aV in myR.values()])
     self.assertEqual([aV for aV in myR.values()], [(0, 1024, 4.2),
                                                    (3, 1024, 4.2),
                                                    (6, 1024, 4.2),
                                                    (9, 1024, 4.2),
                                                    (12, 1024, 4.2),
                                                    (15, 1024, 4.2),
                                                    (18, 1024, 4.2),
                                                    (21, 1024, 4.2)])
     for i, v in enumerate(myInput):
         self.assertEqual(myR.value(i)[0], v)
     # Check property access
     self.assertEqual(myR[0].datum, 0)
     self.assertEqual(myR[0].stride, 3)
     self.assertEqual(myR[0].repeat, 7)
Exemplo n.º 16
0
 def test_01(self):
     """TestRleType01.test_01(): Basic test, single range, variable X axis value."""
     myR = Rle.RLEType01(b'FEET')
     myInput = range(0, 3 * 8, 3)
     for i, v in enumerate(myInput):
         myR.add(v, 1024, 4.2 * i)
     self.assertEqual(len(myR), 1)
     self.assertEqual(myR.num_values(), len(myInput))
     #print([aV for aV in myR.values()])
     self.assertEqual([aV for aV in myR.values()], [(0, 1024, 0.0),
                                                    (3, 1024, 4.2),
                                                    (6, 1024, 2 * 4.2),
                                                    (9, 1024, 3 * 4.2),
                                                    (12, 1024, 4 * 4.2),
                                                    (15, 1024, 5 * 4.2),
                                                    (18, 1024, 6 * 4.2),
                                                    (21, 1024, 7 * 4.2)])
     for i, v in enumerate(myInput):
         self.assertEqual(myR.value(i)[0], v)
     # Check property access
     self.assertEqual(myR[0].datum, 0)
     self.assertEqual(myR[0].stride, 3)
     self.assertEqual(myR[0].repeat, 7)
Exemplo n.º 17
0
 def test_05(self):
     """TestRleType01.test_05(): Basic test, variable frame size, variable X axis value. tellLrForFrame()."""
     myR = Rle.RLEType01(b'FEET')
     myInput = range(0, 2048, 128)
     totalF = 0
     for i, v in enumerate(myInput):
         #print('test_01()', v)
         if i % 6 * 128 == 0:
             myR.add(v, 2, 4.2 * i)
             totalF += 2
         else:
             myR.add(v, 1, 4.2 * i)
             totalF += 1
     #print()
     #print(myR)
     self.assertEqual(len(myR), 6)
     self.assertEqual(myR.totalFrames(), totalF)
     str(myR)
     #        self.assertEqual(str(myR), """RLEType01: func=None
     #  RLEItemType01: datum=0 stride=None repeat=0 frames=2
     #  RLEItemType01: datum=128 stride=128 repeat=4 frames=1
     #  RLEItemType01: datum=768 stride=None repeat=0 frames=2
     #  RLEItemType01: datum=896 stride=128 repeat=4 frames=1
     #  RLEItemType01: datum=1536 stride=None repeat=0 frames=2
     #  RLEItemType01: datum=1664 stride=128 repeat=2 frames=1""")
     #for f in range(totalF):
     #    print(f, myR.tellLrForFrame(f))
     # RLEItem[0]
     self.assertEqual(myR.tellLrForFrame(0), (0, 0))
     self.assertEqual(myR.tellLrForFrame(1), (0, 1))
     # RLEItem[1]
     self.assertEqual(myR.tellLrForFrame(2), (128, 0))
     self.assertEqual(myR.tellLrForFrame(3), (2 * 128, 0))
     self.assertEqual(myR.tellLrForFrame(4), (3 * 128, 0))
     self.assertEqual(myR.tellLrForFrame(5), (4 * 128, 0))
     self.assertEqual(myR.tellLrForFrame(6), (5 * 128, 0))
     # RLEItem[2]
     self.assertEqual(myR.tellLrForFrame(7), (6 * 128, 0))
     self.assertEqual(myR.tellLrForFrame(8), (6 * 128, 1))
     # RLEItem[3]
     self.assertEqual(myR.tellLrForFrame(9), (7 * 128, 0))
     self.assertEqual(myR.tellLrForFrame(10), (8 * 128, 0))
     self.assertEqual(myR.tellLrForFrame(11), (9 * 128, 0))
     self.assertEqual(myR.tellLrForFrame(12), (10 * 128, 0))
     self.assertEqual(myR.tellLrForFrame(13), (11 * 128, 0))
     # RLEItem[4]
     self.assertEqual(myR.tellLrForFrame(14), (12 * 128, 0))
     self.assertEqual(myR.tellLrForFrame(15), (12 * 128, 1))
     # RLEItem[3]
     self.assertEqual(myR.tellLrForFrame(16), (13 * 128, 0))
     self.assertEqual(myR.tellLrForFrame(17), (14 * 128, 0))
     self.assertEqual(myR.tellLrForFrame(18), (15 * 128, 0))
     # Failures
     self.assertRaises(IndexError, myR.tellLrForFrame, -1)
     self.assertRaises(IndexError, myR.tellLrForFrame, 19)
     #print()
     #print(myR.rangeList())
     #print([list(r) for r in myR.rangeList()])
     #print('First/last:', 'First', myR.first(), 'Last', myR.last())
     self.assertEqual(
         [[0], [128, 256, 384, 512, 640], [768],
          [896, 1024, 1152, 1280, 1408], [1536], [1664, 1792, 1920]],
         [list(r) for r in myR.ranges()])
     self.assertEqual(0, myR.first())
     self.assertEqual(1920, myR.last())