Exemple #1
0
 def testConvertFails(self):
     """Dim() convert() fails."""
     myObj = Coord.Dim(72, 'WTF')
     self.assertRaises(Coord.ExceptionCoordUnitConvert, myObj.convert, 'in')
     myObj = Coord.Dim(72, 'px')
     self.assertRaises(Coord.ExceptionCoordUnitConvert, myObj.convert,
                       'WTF')
    def __init__(self, root):
        assert (root.tag == self.tagInNs('LgFormat')
                ), 'Wrong root element {:s}'.format(root.tag)
        myName = self.elemID(root)
        # Tracks, create a list of Track.Track objects
        # NOTE: This is not quite like the LIS track buildup where the tracks are single
        # and in order so when we encounter T23 we span tracks T2 and T3 (by ordinal).
        # Here we get a separate track description 'track23' which has the width and grid
        # generator, 'track2' and 'track3' may be blank.
        # I suppose also that the order of tracks in the XML file is not significant but
        # we treat is so here.
        myTrackS = []
        # Make an additional data structure that maps the track name to ordinal
        self._trackNameOrdinalMap = {}
        for t, aT in enumerate(root.findall(self.tagInNs('LgTrack'))):
            l = Coord.Dim(self.float(aT, self.tagInNs('LeftPosition'), 0.0),
                          'in')
            r = Coord.Dim(self.float(aT, self.tagInNs('RightPosition'), 0.0),
                          'in')
            myTrackS.append(
                Track.Track(
                    leftPos=l,
                    rightPos=r,
                    # Figure out track grid function
                    gridGn=self._retGridGen(aT),
                    plotXLines=self.bool(aT, self.tagInNs('IndexLinesVisible'),
                                         True),
                    plotXAlpha=self.bool(aT,
                                         self.tagInNs('IndexNumbersVisible'),
                                         False),
                ))
            trackID = self.elemID(aT)
            if trackID is None:
                raise ExceptionFILMCfgXMLRead(
                    'PhysFilmCfgXMLRead.__init__(): Missing track UniqueId'.
                    format(trackID))
            if trackID in self._trackNameOrdinalMap:
                raise ExceptionFILMCfgXMLRead(
                    'PhysFilmCfgXMLRead.__init__(): Duplicate track UniqueId="{:s}"'
                    .format(trackID))
            # Add the track ordinal
            self._trackNameOrdinalMap[trackID] = t


#        myXPath = self.tagsInNs('LgFormat', 'LgVerticalScale', 'IndexScaler')
#        myElem = root.find(myXPath)
#        myX = self.int(root, self.tagsInNs('LgVerticalScale', 'IndexScaler'))
#        print()
#        print('TRACE:', myXPath, myElem, myX)
        myXScale = self.int(root,
                            self.tagsInNs('LgVerticalScale', 'IndexScaler'),
                            None)
        assert (myXScale is not None)
        super().__init__(
            theName=myName,
            theTracks=myTrackS,
            # This does not seem to be used by the parent class
            theDest=None,
            theX=myXScale,
        )
Exemple #3
0
 def test_zeroBaseUnitsPt(self):
     """zeroBaseUnitsPt()."""
     myPt = Coord.zeroBaseUnitsPt()
     #print()
     #print(myPt)
     self.assertEqual(Coord.Dim(0, Coord.BASE_UNITS), myPt.x)
     self.assertEqual(Coord.Dim(0, Coord.BASE_UNITS), myPt.y)
Exemple #4
0
    def test_07(self):
        """TestPhysFilmCfgXMLRead.test_07(): Test reading track1 with no x Axis lines but with Y grid."""
        root = etree.fromstring(
            """<LgFormat UniqueId="TestOneTrack" xmlns="x-schema:LgSchema2.xml">
    <LgVerticalScale UniqueId="VerticalScale">
        <IndexScaler>100</IndexScaler>
        <IndexUnit>Ft</IndexUnit>
        <PaperScaler>5</PaperScaler>
        <PaperUnit>LG_PAPER_INCH</PaperUnit>
    </LgVerticalScale>
    <LgTrack UniqueId="Track1">
        <Description>Depth Track</Description>
        <IndexLinesVisible>0</IndexLinesVisible>
        <IndexNumbersVisible>0</IndexNumbersVisible>
        <RightPosition>2.4</RightPosition>
        <LgLinearGrid UniqueId="minorGrid1">
            <Color>818181</Color>
            <LineCount>11</LineCount>
        </LgLinearGrid>
        <LgLinearGrid UniqueId="majorGrid11">
            <Color>818181</Color>
            <LineCount>3</LineCount>
            <Thickness>2</Thickness>
        </LgLinearGrid>
    </LgTrack>
</LgFormat>""")
        myFcxr = FILMCfgXML.PhysFilmCfgXMLRead(root)
        self.assertEqual(1, len(myFcxr))
        self.assertEqual(Coord.Dim(value=0.0, units='in'), myFcxr[0].left)
        self.assertEqual(Coord.Dim(value=2.4, units='in'), myFcxr[0].right)
        self.assertTrue(myFcxr[0].hasGrid)
        self.assertFalse(myFcxr[0].plotXLines)
        self.assertFalse(myFcxr[0].plotXAlpha)
Exemple #5
0
 def testCmp_01(self):
     """Dim() cmp() [01]."""
     myObj_0 = Coord.Dim(1, 'in')
     myObj_1 = Coord.Dim(1, 'in')
     self.assertEqual(myObj_0, myObj_1)
     self.assertEqual(myObj_0, myObj_1)
     self.assertTrue(myObj_0 == myObj_1)
Exemple #6
0
 def test_05(self):
     """TestPlotTrack.test_05(): Construct a blank track without failure."""
     myT = Track.Track(leftPos=Coord.Dim(3.2, 'in'),
                       rightPos=Coord.Dim(5.6, 'in'),
                       gridGn=None)
     self.assertEqual(Coord.Dim(3.2, 'in'), myT.left)
     self.assertEqual(Coord.Dim(5.6, 'in'), myT.right)
     self.assertFalse(myT.hasGrid)
Exemple #7
0
 def test_zeroBaseUnitsBox(self):
     """zeroBaseUnitsBox()."""
     myBox = Coord.zeroBaseUnitsBox()
     #print()
     #print(myBox)
     self.assertEqual(Coord.Dim(0, Coord.BASE_UNITS), myBox.width)
     self.assertEqual(Coord.Dim(0, Coord.BASE_UNITS), myBox.depth)
     self.assertEqual('Box(width=Dim(0.0px), depth=Dim(0.0px))', str(myBox))
Exemple #8
0
 def testAdd(self):
     """Dim() addition."""
     myObj_0 = Coord.Dim(1, 'in')
     myObj_1 = Coord.Dim(18, 'px')
     myResult = myObj_0 + myObj_1
     #print myResult
     self.assertEqual(myResult.value, 1.25)
     self.assertEqual(myResult.units, 'in')
Exemple #9
0
 def testSub(self):
     """Dim() subtraction."""
     myObj_0 = Coord.Dim(1, 'in')
     myObj_1 = Coord.Dim(18, 'px')
     myResult = myObj_0 - myObj_1
     #print myResult
     self.assertEqual(myResult.value, 0.75)
     self.assertEqual(myResult.units, 'in')
Exemple #10
0
 def testIadd_00(self):
     """Dim() +=."""
     myObj_0 = Coord.Dim(1, 'in')
     myObj_1 = Coord.Dim(18, 'px')
     myObj_0 += myObj_1
     #print myObj
     self.assertEqual(myObj_0.value, 1.25)
     self.assertEqual(myObj_0.units, 'in')
 def test_11(self):
     """TestLogHeaderLAS.test_11(): Plot as top of log with CONS data."""
     myLh = LogHeader.APIHeaderLAS(isTopOfLog=True)
     fp = TestPlotShared.outPath(TEST_SVG_FILE_MAP_HDR[56].fileName)
     tl = Coord.Pt(Coord.Dim(0.5, 'in'), Coord.Dim(0.25, 'in'))
     viewPort = myLh.viewPort(tl)
     with SVGWriter.SVGWriter(open(fp, 'w'), viewPort) as xS:
         myLh.plot(xS, tl, self._lasFile)
 def test_05(self):
     """TestLogHeaderLAS.test_05(): Plot as not top of log."""
     myLh = LogHeader.APIHeaderLAS(isTopOfLog=False)
     fp = TestPlotShared.outPath(TEST_SVG_FILE_MAP_HDR[50].fileName)
     tl = Coord.Pt(Coord.Dim(0.0, 'in'), Coord.Dim(0.0, 'in'))
     viewPort = myLh.viewPort(tl)
     with SVGWriter.SVGWriter(open(fp, 'w'), viewPort) as xS:
         myLh.plot(xS, tl)
Exemple #13
0
 def test_10(self):
     """TestLogHeader.test_10(): Plot as not top of log with CONS data."""
     myLh = LogHeader.APIHeaderLIS(isTopOfLog=False)
     fp = TestPlotShared.outPath(TEST_SVG_FILE_MAP_HDR[45].fileName)
     tl = Coord.Pt(Coord.Dim(0.25, 'in'), Coord.Dim(0.5, 'in'))
     viewPort = myLh.viewPort(tl)
     with SVGWriter.SVGWriter(open(fp, 'w'), viewPort) as xS:
         myLh.plot(xS, tl, [self._lrCONS,])
Exemple #14
0
 def testCmp_00(self):
     """Dim() cmp() [00]."""
     myObj_0 = Coord.Dim(1, 'in')
     myObj_1 = Coord.Dim(72, 'px')
     #print myObj_0 == myObj_1
     self.assertEqual(myObj_0, myObj_1)
     self.assertEqual(myObj_0, myObj_1)
     self.assertTrue(myObj_0 == myObj_1)
Exemple #15
0
 def testStr(self):
     """Pt() __str__()."""
     myPt = Coord.Pt(
         Coord.Dim(12, 'px'),
         Coord.Dim(24, 'px'),
     )
     #print myPt
     self.assertEqual(str(myPt), 'Pt(x=Dim(12px), y=Dim(24px))')
Exemple #16
0
 def testConstructor(self):
     """Pt() constructor."""
     myPt = Coord.Pt(
         Coord.Dim(12, 'px'),
         Coord.Dim(24, 'px'),
     )
     #print myPt
     self.assertEqual(myPt.x, Coord.Dim(12, 'px'))
     self.assertEqual(myPt.y, Coord.Dim(24, 'px'))
Exemple #17
0
 def testSum_00(self):
     """Dim() sum(...) raises type error [00]."""
     myObj_0 = Coord.Dim(71, 'px')
     myObj_1 = Coord.Dim(72, 'px')
     try:
         sum([myObj_0, myObj_1])
         self.fail('TypeError not raised')
     except TypeError:
         pass
Exemple #18
0
 def test_11(self):
     """TestPlotTrack.test_11(): Construct a linear track with left edge < right edge - fails."""
     try:
         Track.Track(leftPos=Coord.Dim(5.6, 'in'),
                     rightPos=Coord.Dim(3.2, 'in'),
                     gridGn=Track.genLinear10)
         self.fail('Track.ExceptionTotalDepthLISPlotTrack not raised')
     except Track.ExceptionTotalDepthLISPlotTrack:
         pass
Exemple #19
0
 def test_01(self):
     """TestPlotTrack.test_01(): Construct a linear track without failure and check default values."""
     myT = Track.Track(leftPos=Coord.Dim(3.2, 'in'),
                       rightPos=Coord.Dim(5.6, 'in'),
                       gridGn=Track.genLinear10)
     self.assertEqual(Coord.Dim(3.2, 'in'), myT.left)
     self.assertEqual(Coord.Dim(5.6, 'in'), myT.right)
     self.assertTrue(myT.hasGrid)
     self.assertTrue(myT.plotXLines)
     self.assertFalse(myT.plotXAlpha)
Exemple #20
0
 def testCmp_03(self):
     """Dim() cmp() [03]."""
     myObj_0 = Coord.Dim(1, 'in')
     myObj_1 = Coord.Dim(73, 'px')
     self.assertFalse(myObj_0 == myObj_1)
     self.assertTrue(myObj_0 <= myObj_1)
     self.assertFalse(myObj_0 >= myObj_1)
     self.assertTrue(myObj_0 != myObj_1)
     self.assertTrue(myObj_0 < myObj_1)
     self.assertFalse(myObj_0 > myObj_1)
Exemple #21
0
 def test_04(self):
     """TestFILMCfgXML.test_04(): "Micro_Resistivity_3Track.xml" tracks."""
     myFcxr = FILMCfgXML.FilmCfgXMLRead()
     self.assertEqual(29, len(myFcxr))
     self.assertTrue("Micro_Resistivity_3Track.xml" in myFcxr)
     #        print()
     #        print('Micro Res:', myFcxr["Micro_Resistivity_3Track.xml"])
     # Four tracks
     self.assertEqual(4, len(myFcxr["Micro_Resistivity_3Track.xml"]))
     #        for i, t in enumerate(myFcxr["Micro_Resistivity_3Track.xml"].genTracks()):
     #            print(i, t)
     #        print(myFcxr["Micro_Resistivity_3Track.xml"][0].left)
     self.assertEqual(Coord.Dim(0, 'in'),
                      myFcxr["Micro_Resistivity_3Track.xml"][0].left)
     leftRight = [
         (t.left, t.right)
         for t in myFcxr["Micro_Resistivity_3Track.xml"].genTracks()
     ]
     #        print(leftRight)
     expResult = [
         (Coord.Dim(value=0.0, units='in'), Coord.Dim(value=2.4,
                                                      units='in')),
         (Coord.Dim(value=2.4, units='in'), Coord.Dim(value=3.2,
                                                      units='in')),
         (Coord.Dim(value=3.2, units='in'), Coord.Dim(value=5.6,
                                                      units='in')),
         (Coord.Dim(value=5.6, units='in'), Coord.Dim(value=8.0,
                                                      units='in')),
     ]
     self.assertEqual(expResult, leftRight)
Exemple #22
0
 def testScale(self):
     """Pt() scale()."""
     myPt_0 = Coord.Pt(
         Coord.Dim(20, 'mm'),
         Coord.Dim(7, 'px'),
     )
     myPt_1 = myPt_0.scale(2.0)
     self.assertEqual(myPt_1.x, Coord.Dim(40, 'mm'))
     self.assertEqual(myPt_1.y, Coord.Dim(14, 'px'))
     self.assertEqual(myPt_1.x.units, 'mm')
     self.assertEqual(myPt_1.y.units, 'px')
 def test_02(self):
     """TestFILMRead.test_02(): PhysFilmCfg.interpretTrac(), typical three track film."""
     # 2     E2E   -4--  PF2   D200
     myPfc = self._fc[b'2\x00\x00\x00']
     #        print()
     #        print(myPfc.interpretTrac(b'T1  '))
     self.assertEqual(
         (
             Coord.Dim(value=0.0, units='in'),
             Coord.Dim(value=2.4, units='in'),
             0,
             2,
         ),
         myPfc.interpretTrac(b'T1  '),
     )
     self.assertEqual(
         (
             Coord.Dim(value=2.4, units='in'),
             Coord.Dim(value=3.2, units='in'),
             2,
             2,
         ),
         myPfc.interpretTrac(b'TD  '),
     )
     self.assertEqual(
         (
             Coord.Dim(value=3.2, units='in'),
             Coord.Dim(value=5.6, units='in'),
             4,
             2,
         ),
         myPfc.interpretTrac(b'T2  '),
     )
     self.assertEqual(
         (
             Coord.Dim(value=5.6, units='in'),
             Coord.Dim(value=8.0, units='in'),
             6,
             2,
         ),
         myPfc.interpretTrac(b'T3  '),
     )
     #        print()
     #        print(myPfc.interpretTrac(b'T23 '))
     self.assertEqual(
         (
             Coord.Dim(value=3.2, units='in'),
             Coord.Dim(value=8, units='in'),
             4,
             4,
         ),
         myPfc.interpretTrac(b'T23 '),
     )
Exemple #24
0
 def _plotBackGround(self, xS):
     """Plot the background stuff."""
     # Top black background
     with SVGWriter.SVGRect(
             xS, self._ptZero(),
             Coord.Box(PlotConstants.STANDARD_PAPER_DEPTH,
                       Coord.Dim(2.0, HEADER_PLOT_UNITS)), {
                           'fill': "black",
                       }):
         pass
     # Logo
     self._plotLogo(xS)
Exemple #25
0
 def test_zeroBaseUnitsPad(self):
     """zeroBaseUnitsPad()."""
     myPad = Coord.zeroBaseUnitsPad()
     #print()
     #print(myPad)
     self.assertEqual(Coord.Dim(0, Coord.BASE_UNITS), myPad.prev)
     self.assertEqual(Coord.Dim(0, Coord.BASE_UNITS), myPad.next)
     self.assertEqual(Coord.Dim(0, Coord.BASE_UNITS), myPad.parent)
     self.assertEqual(Coord.Dim(0, Coord.BASE_UNITS), myPad.child)
     self.assertEqual(
         'Pad(prev=Dim(0.0px), next=Dim(0.0px), parent=Dim(0.0px), child=Dim(0.0px))',
         str(myPad),
     )
 def test_02(self):
     """TestFILMReadFourTrack.test_02(): interpretTrac()."""
     myPfc = self._fc[Mnem.Mnem(b'A\x00\x00\x00')]
     #        print()
     #        print('FD', myPfc.interpretTrac(b'FD  '))
     #        print('F1', myPfc.interpretTrac(b'F1  '))
     self.assertEqual(
         (
             Coord.Dim(value=0.0, units='in'),
             Coord.Dim(value=1.0, units='in'),
             0,  # Half track start
             2,  # Half track span
         ),
         myPfc.interpretTrac(b'FD  '),
     )
     self.assertEqual(
         (
             Coord.Dim(value=1.0, units='in'),
             Coord.Dim(value=2.75, units='in'),
             2,  # Half track start
             2,  # Half track span
         ),
         myPfc.interpretTrac(b'F1  '),
     )
     self.assertEqual(
         (
             Coord.Dim(value=2.75, units='in'),
             Coord.Dim(value=4.5, units='in'),
             4,  # Half track start
             2,  # Half track span
         ),
         myPfc.interpretTrac(b'F2  '),
     )
     self.assertEqual(
         (
             Coord.Dim(value=4.5, units='in'),
             Coord.Dim(value=6.25, units='in'),
             6,  # Half track start
             2,  # Half track span
         ),
         myPfc.interpretTrac(b'F3  '),
     )
     self.assertEqual(
         (
             Coord.Dim(value=6.25, units='in'),
             Coord.Dim(value=8.0, units='in'),
             8,  # Half track start
             2,  # Half track span
         ),
         myPfc.interpretTrac(b'F4  '),
     )
    def test_00(self):
        """TestSVGWriter.test_00(): construction."""
        myF = io.StringIO()
        myViewPort = Coord.Box(
            Coord.Dim(100, 'mm'),
            Coord.Dim(20, 'mm'),
        )
        with SVGWriter.SVGWriter(myF, myViewPort):
            pass
        #print
        #print myF.getvalue()
        self.assertEqual(myF.getvalue(), """<?xml version='1.0' encoding="utf-8"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg height="20mm" version="1.1" width="100mm" xmlns="http://www.w3.org/2000/svg"/>\n""")
 def test_20(self):
     """TestFILMRead.test_20(): PhysFilmCfg.interpretTrac() using curve destination b'1' and b'2', track b'T1  '."""
     self.assertEqual((
         Coord.Dim(value=0.0, units='in'),
         Coord.Dim(value=2.4, units='in'),
         0,
         2,
     ), self._fc.interpretTrac(Mnem.Mnem(b'1'), Mnem.Mnem(b'1'), b'T1  '))
     self.assertEqual((
         Coord.Dim(value=0.0, units='in'),
         Coord.Dim(value=2.4, units='in'),
         0,
         2,
     ), self._fc.interpretTrac(Mnem.Mnem(b'2'), Mnem.Mnem(b'2'), b'T1  '))
 def test_01(self):
     """TestFILMRead.test_01(): Constructor."""
     self.assertEqual(2, len(self._fc))
     self.assertEqual([b'1\x00\x00\x00', b'2\x00\x00\x00'],
                      sorted(list(self._fc.keys())))
     #        print()
     #        print(self._fc[b'1\x00\x00\x00'])
     #        print(self._fc[b'1\x00\x00\x00'].name)
     #        print(self._fc[b'1\x00\x00\x00'].xScale)
     #        print(len(self._fc[b'1\x00\x00\x00']))
     self.assertEqual(b'1\x00\x00\x00', self._fc[b'1\x00\x00\x00'].name)
     self.assertEqual(200, self._fc[b'1\x00\x00\x00'].xScale)
     self.assertEqual(4, len(self._fc[b'1\x00\x00\x00']))
     #        print('left', self._fc[b'1\x00\x00\x00'][0].left)
     #        print('right', self._fc[b'1\x00\x00\x00'][0].right)
     self.assertEqual(Coord.Dim(0.0, 'in'),
                      self._fc[b'1\x00\x00\x00'][0].left)
     self.assertEqual(Coord.Dim(2.4, 'in'),
                      self._fc[b'1\x00\x00\x00'][0].right)
     self.assertEqual(Coord.Dim(2.4, 'in'),
                      self._fc[b'1\x00\x00\x00'][1].left)
     self.assertEqual(Coord.Dim(3.2, 'in'),
                      self._fc[b'1\x00\x00\x00'][1].right)
     self.assertEqual(Coord.Dim(3.2, 'in'),
                      self._fc[b'1\x00\x00\x00'][2].left)
     self.assertEqual(Coord.Dim(5.6, 'in'),
                      self._fc[b'1\x00\x00\x00'][2].right)
     self.assertEqual(Coord.Dim(5.6, 'in'),
                      self._fc[b'1\x00\x00\x00'][3].left)
     self.assertEqual(Coord.Dim(8.0, 'in'),
                      self._fc[b'1\x00\x00\x00'][3].right)
Exemple #30
0
    def test_02(self):
        """TestPhysFilmCfgXMLRead.test_02(): Test reading a single track, log scale OK."""
        root = etree.fromstring(
            """<LgFormat UniqueId="TestOneTrack" xmlns="x-schema:LgSchema2.xml">
    <LgVerticalScale UniqueId="VerticalScale">
        <IndexScaler>100</IndexScaler>
        <IndexUnit>Ft</IndexUnit>
        <PaperScaler>5</PaperScaler>
        <PaperUnit>LG_PAPER_INCH</PaperUnit>
    </LgVerticalScale>
    <LgTrack UniqueId="track23">
        <Description>Track 23</Description>
        <LeftPosition>3.2</LeftPosition>
        <RightPosition>8</RightPosition>
        <LgLogarithmicGrid UniqueId="logGrid3">
            <Color>818181</Color>
            <Decade>4</Decade>
            <LogScale>LG_LOG_2</LogScale>
        </LgLogarithmicGrid>
        <LgCurve UniqueId="ATR">
            <ChannelName>ATR</ChannelName>
            <Color>FF0000</Color>
            <LeftLimit>0.2</LeftLimit>
            <RightLimit>2000</RightLimit>
            <LineStyle>LG_DASH_LINE</LineStyle>
            <Thickness>2</Thickness>
            <Transform>LG_LOGARITHMIC</Transform>
            <WrapCount>0</WrapCount>
        </LgCurve>
    </LgTrack>
</LgFormat>""")
        myFcxr = FILMCfgXML.PhysFilmCfgXMLRead(root)
        self.assertEqual(1, len(myFcxr))
        self.assertEqual('TestOneTrack', myFcxr.name)
        self.assertEqual(100, myFcxr.xScale)
        # This does nto work as interpret track needs track 2 and three to interpret T23
        #        self.assertEqual(
        #            (Coord.Dim(value=0.0, units='in'), Coord.Dim(value=2.4, units='in'), 0, 2),
        #            myFcxr.interpretTrac(b'T23 ')
        #        )
        self.assertRaises(FILMCfg.ExceptionFILMCfg, myFcxr.interpretTrac,
                          b'T2  ')
        # Get the track object
        #        print(myFcxr[0])
        self.assertEqual(Coord.Dim(value=3.2, units='in'), myFcxr[0].left)
        self.assertEqual(Coord.Dim(value=8.0, units='in'), myFcxr[0].right)
        self.assertTrue(myFcxr[0].plotXLines)
        self.assertFalse(myFcxr[0].plotXAlpha)