Ejemplo n.º 1
0
 def test_04(self):
     """TestXGrid.test_04(): ctor uses default _setInterval(), test _getInterval()."""
     #print()
     myXs = XGrid.XGrid(200)
     #print(myXs._getInterval(b'FEET'))
     self.assertEqual(
         {
             2   : Stroke.Stroke(width=0.25, colour='black', coding=None, opacity=1.0),
             10  : Stroke.Stroke(width=0.5, colour='black', coding=None, opacity=1.0),
             50  : Stroke.Stroke(width=0.75, colour='black', coding=None, opacity=1.0),
             100 : Stroke.Stroke(width=1.0, colour='black', coding=None, opacity=1.0),
         },
         myXs._getInterval(b'FEET'),
     )
Ejemplo n.º 2
0
    def test_01(self):
        """CurveCfgXMLRead.test_01(): tests single channel read."""
        # Say in <LgTrack UniqueId="track1">
        xStr = """<LgCurve UniqueId="Cali" xmlns="x-schema:LgSchema2.xml">
    <ChannelName>CALI</ChannelName>
    <Color>FF0000</Color>
    <LeftLimit>6</LeftLimit>
    <LineStyle>LG_DASH_LINE</LineStyle>
    <RightLimit>16</RightLimit>
    <Thickness>2</Thickness>
    <WrapCount>1</WrapCount>
</LgCurve>"""
        root = etree.fromstring(xStr)
        myCcxr = PRESCfgXML.CurveCfgXMLRead(root, "track1", self._fcxr)
        #        print()
        #        print('myCcxr._filmTrackWidthMap [{:d}]'.format(len(myCcxr._filmTrackWidthMap)))
        #        pprint.pprint(myCcxr._filmTrackWidthMap)
        #        print()
        #        print('myCcxr._filmTrackFnMap [{:d}]'.format(len(myCcxr._filmTrackFnMap)))
        #        pprint.pprint(myCcxr._filmTrackFnMap)
        self.assertEqual('Cali', myCcxr.mnem)
        self.assertEqual('CALI', myCcxr.outp)
        self.assertEqual(True, myCcxr.stat)
        self.assertEqual('track1', myCcxr.trac)
        self.assertEqual(
            Stroke.Stroke(width=0.5,
                          colour='rgb(255,0,0)',
                          coding=(4, 4),
                          opacity=1.0),
            myCcxr.codiStroke,
        )
Ejemplo n.º 3
0
 def test_01(self):
     """TestXGridRange.test_01(): genXAxisRange()."""
     myXs = XGrid.XGrid(200)
     myVals = [
         v for v in myXs.genXAxisRange(EngVal.EngVal(4001.0, b'FEET'),
                                       EngVal.EngVal(3987.0, b'FEET'))
     ]
     #print()
     #pprint.pprint(myVals)
     self.assertEqual(
         [
             (Coord.Dim(value=-0.06000000000000001, units='in'),
              Stroke.Stroke(
                  width=1.0, colour='black', coding=None, opacity=1.0)),
             (Coord.Dim(value=-0.18000000000000005, units='in'),
              Stroke.Stroke(
                  width=0.25, colour='black', coding=None, opacity=1.0)),
             (Coord.Dim(value=-0.3, units='in'),
              Stroke.Stroke(
                  width=0.25, colour='black', coding=None, opacity=1.0)),
             (Coord.Dim(value=-0.42, units='in'),
              Stroke.Stroke(
                  width=0.25, colour='black', coding=None, opacity=1.0)),
             (Coord.Dim(value=-0.54, units='in'),
              Stroke.Stroke(
                  width=0.25, colour='black', coding=None, opacity=1.0)),
             (Coord.Dim(value=-0.66, units='in'),
              Stroke.Stroke(
                  width=0.5, colour='black', coding=None, opacity=1.0)),
             (Coord.Dim(value=-0.78, units='in'),
              Stroke.Stroke(
                  width=0.25, colour='black', coding=None, opacity=1.0)),
         ],
         myVals,
     )
Ejemplo n.º 4
0
 def test_20(self):
     """TestXGridRange.test_20(): genXAxisRange() with 'non-optical' units b'.1IN'."""
     myXs = XGrid.XGrid(200)
     myVals = [
         v for v in myXs.genXAxisRange(
             EngVal.EngVal(4001.0, b'FEET').newEngValInUnits(b'.1IN'),
             EngVal.EngVal(3987.0, b'FEET').newEngValInUnits(b'.1IN'),
         )
     ]
     self.assertEqual(7, len(myVals))
     #        print()
     #        pprint.pprint(myVals)
     self.assertEqual(
         #            [
         #                (Coord.Dim(value=-0.06000000000000001, units='in'),
         #                 Stroke.Stroke(width=1.0, colour='black', coding=None, opacity=1.0)),
         #                (Coord.Dim(value=-0.18000000000000005, units='in'),
         #                 Stroke.Stroke(width=0.25, colour='black', coding=None, opacity=1.0)),
         #                (Coord.Dim(value=-0.3, units='in'),
         #                 Stroke.Stroke(width=0.25, colour='black', coding=None, opacity=1.0)),
         #                (Coord.Dim(value=-0.42, units='in'),
         #                 Stroke.Stroke(width=0.25, colour='black', coding=None, opacity=1.0)),
         #                (Coord.Dim(value=-0.54, units='in'),
         #                 Stroke.Stroke(width=0.25, colour='black', coding=None, opacity=1.0)),
         #                (Coord.Dim(value=-0.66, units='in'),
         #                 Stroke.Stroke(width=0.5, colour='black', coding=None, opacity=1.0)),
         #                (Coord.Dim(value=-0.78, units='in'),
         #                 Stroke.Stroke(width=0.25, colour='black', coding=None, opacity=1.0)),
         #            ],
         [
             (Coord.Dim(value=-0.060000000000027295, units='in'),
              Stroke.Stroke(
                  width=1.0, colour='black', coding=None, opacity=1.0)),
             (Coord.Dim(value=-0.18000000000002728, units='in'),
              Stroke.Stroke(
                  width=0.25, colour='black', coding=None, opacity=1.0)),
             (Coord.Dim(value=-0.3000000000000273, units='in'),
              Stroke.Stroke(
                  width=0.25, colour='black', coding=None, opacity=1.0)),
             (Coord.Dim(value=-0.4200000000000273, units='in'),
              Stroke.Stroke(
                  width=0.25, colour='black', coding=None, opacity=1.0)),
             (Coord.Dim(value=-0.5400000000000273, units='in'),
              Stroke.Stroke(
                  width=0.25, colour='black', coding=None, opacity=1.0)),
             (Coord.Dim(value=-0.6600000000000272, units='in'),
              Stroke.Stroke(
                  width=0.5, colour='black', coding=None, opacity=1.0)),
             (Coord.Dim(value=-0.7800000000000273, units='in'),
              Stroke.Stroke(
                  width=0.25, colour='black', coding=None, opacity=1.0)),
         ],
         myVals,
     )
Ejemplo n.º 5
0
 def plotSVG(self, topLeft, depth, theSVGWriter):
     """Plot the track gridlines.
     topLeft - A Coord.Pt() object that is the top left of the canvas.
     depth - A Coord.Dim() object that is the total depth of the grid below topLeft.
     drive - The plot driver."""
     if self._gridGn is not None:
         botLeft = Coord.newPt(topLeft, incY=depth)
         for stroke, pos in self._gridGn(self._lP.value, self._rP.value):
             # Compute the line position
             topP = Coord.newPt(topLeft,
                                incX=Coord.Dim(pos, self._lP.units))
             botP = Coord.newPt(botLeft,
                                incX=Coord.Dim(pos, self._lP.units))
             with SVGWriter.SVGLine(
                     theSVGWriter,
                     topP,
                     botP,
                     attrs=Stroke.retSVGAttrsFromStroke(stroke)):
                 pass
Ejemplo n.º 6
0
    def test_11(self):
        """CurveCfgXMLRead.test_11(): tests single colour OK."""
        # Say in <LgTrack UniqueId="track1">
        xStr = """<LgCurve UniqueId="ROP5" xmlns="x-schema:LgSchema2.xml">
    <ChannelName>ROP5</ChannelName>
    <Color>0000FF</Color>
    <LeftLimit>500</LeftLimit>
    <RightLimit>0</RightLimit>
    <LineStyle>LG_DASH_LINE</LineStyle>
    <Thickness>1.75</Thickness>
    <WrapMode>LG_LEFT_WRAPPED</WrapMode>
</LgCurve>"""
        root = etree.fromstring(xStr)
        myCcxr = PRESCfgXML.CurveCfgXMLRead(root, "track1", self._fcxr)
        self.assertEqual(
            Stroke.Stroke(width=0.5,
                          colour='rgb(0,0,255)',
                          coding=(4, 4),
                          opacity=1.0),
            myCcxr.codiStroke,
        )
Ejemplo n.º 7
0
    def test_00_11(self):
        """CurveCfgXMLRead.test_00_11(): tests low-level: _retCoding()."""
        # Say in <LgTrack UniqueId="track1">
        xStr = """<LgCurve UniqueId="Cali" xmlns="x-schema:LgSchema2.xml">
    <ChannelName>CALI</ChannelName>
    <Color>FF0000</Color>
    <LeftLimit>6</LeftLimit>
    <LineStyle>LG_DASH_LINE</LineStyle>
    <RightLimit>16</RightLimit>
    <Thickness>2</Thickness>
    <WrapCount>1</WrapCount>
</LgCurve>"""
        root = etree.fromstring(xStr)
        myCcxr = PRESCfgXML.CurveCfgXMLRead(root, "track1", self._fcxr)
        myV = myCcxr._retCoding(
            etree.fromstring("""<LgCurve xmlns="x-schema:LgSchema2.xml">
    <Color>FF0000</Color>
    <LineStyle>LG_DASH_LINE</LineStyle>
</LgCurve>"""))
        self.assertEqual(
            Stroke.Stroke(width=0.5,
                          colour='rgb(255,0,0)',
                          coding=(4, 4),
                          opacity=1.0), myV)
Ejemplo n.º 8
0
 def test_11(self):
     """TestXGrid.test_11(): genXPosStroke() plotting UP with FEET and 1/200."""
     #print()
     myXs = XGrid.XGrid(200)
     v = 0
     eventS = []
     for e in myXs.genXPosStroke(xFrom=4307.5, xInc=False, units=b'FEET'):
         #print(e)
         eventS.append(e)
         v += 1
         if v > 30:
             break
     #pprint.pprint(eventS)
     self.assertEqual([
         (Coord.Dim(value=-0.09000000000000002, units='in'),
          Stroke.Stroke(
              width=0.25, colour='black', coding=None, opacity=1.0)),
         (Coord.Dim(value=-0.21, units='in'),
          Stroke.Stroke(
              width=0.25, colour='black', coding=None, opacity=1.0)),
         (Coord.Dim(value=-0.33, units='in'),
          Stroke.Stroke(
              width=0.25, colour='black', coding=None, opacity=1.0)),
         (Coord.Dim(value=-0.45, units='in'),
          Stroke.Stroke(width=1.0, colour='black', coding=None,
                        opacity=1.0)),
         (Coord.Dim(value=-0.57, units='in'),
          Stroke.Stroke(
              width=0.25, colour='black', coding=None, opacity=1.0)),
         (Coord.Dim(value=-0.6900000000000002, units='in'),
          Stroke.Stroke(
              width=0.25, colour='black', coding=None, opacity=1.0)),
         (Coord.Dim(value=-0.81, units='in'),
          Stroke.Stroke(
              width=0.25, colour='black', coding=None, opacity=1.0)),
         (Coord.Dim(value=-0.93, units='in'),
          Stroke.Stroke(
              width=0.25, colour='black', coding=None, opacity=1.0)),
         (Coord.Dim(value=-1.05, units='in'),
          Stroke.Stroke(width=0.5, colour='black', coding=None,
                        opacity=1.0)),
         (Coord.Dim(value=-1.17, units='in'),
          Stroke.Stroke(
              width=0.25, colour='black', coding=None, opacity=1.0)),
         (Coord.Dim(value=-1.29, units='in'),
          Stroke.Stroke(
              width=0.25, colour='black', coding=None, opacity=1.0)),
         (Coord.Dim(value=-1.4100000000000004, units='in'),
          Stroke.Stroke(
              width=0.25, colour='black', coding=None, opacity=1.0)),
         (Coord.Dim(value=-1.53, units='in'),
          Stroke.Stroke(
              width=0.25, colour='black', coding=None, opacity=1.0)),
         (Coord.Dim(value=-1.65, units='in'),
          Stroke.Stroke(width=0.5, colour='black', coding=None,
                        opacity=1.0)),
         (Coord.Dim(value=-1.77, units='in'),
          Stroke.Stroke(
              width=0.25, colour='black', coding=None, opacity=1.0)),
         (Coord.Dim(value=-1.8900000000000003, units='in'),
          Stroke.Stroke(
              width=0.25, colour='black', coding=None, opacity=1.0)),
         (Coord.Dim(value=-2.0100000000000002, units='in'),
          Stroke.Stroke(
              width=0.25, colour='black', coding=None, opacity=1.0)),
         (Coord.Dim(value=-2.1300000000000003, units='in'),
          Stroke.Stroke(
              width=0.25, colour='black', coding=None, opacity=1.0)),
         (Coord.Dim(value=-2.25, units='in'),
          Stroke.Stroke(width=0.5, colour='black', coding=None,
                        opacity=1.0)),
         (Coord.Dim(value=-2.37, units='in'),
          Stroke.Stroke(
              width=0.25, colour='black', coding=None, opacity=1.0)),
         (Coord.Dim(value=-2.49, units='in'),
          Stroke.Stroke(
              width=0.25, colour='black', coding=None, opacity=1.0)),
         (Coord.Dim(value=-2.61, units='in'),
          Stroke.Stroke(
              width=0.25, colour='black', coding=None, opacity=1.0)),
         (Coord.Dim(value=-2.7300000000000004, units='in'),
          Stroke.Stroke(
              width=0.25, colour='black', coding=None, opacity=1.0)),
         (Coord.Dim(value=-2.8500000000000005, units='in'),
          Stroke.Stroke(width=0.5, colour='black', coding=None,
                        opacity=1.0)),
         (Coord.Dim(value=-2.97, units='in'),
          Stroke.Stroke(
              width=0.25, colour='black', coding=None, opacity=1.0)),
         (Coord.Dim(value=-3.09, units='in'),
          Stroke.Stroke(
              width=0.25, colour='black', coding=None, opacity=1.0)),
         (Coord.Dim(value=-3.21, units='in'),
          Stroke.Stroke(
              width=0.25, colour='black', coding=None, opacity=1.0)),
         (Coord.Dim(value=-3.33, units='in'),
          Stroke.Stroke(
              width=0.25, colour='black', coding=None, opacity=1.0)),
         (Coord.Dim(value=-3.45, units='in'),
          Stroke.Stroke(
              width=0.75, colour='black', coding=None, opacity=1.0)),
         (Coord.Dim(value=-3.57, units='in'),
          Stroke.Stroke(
              width=0.25, colour='black', coding=None, opacity=1.0)),
         (Coord.Dim(value=-3.69, units='in'),
          Stroke.Stroke(
              width=0.25, colour='black', coding=None, opacity=1.0)),
     ], eventS)
Ejemplo n.º 9
0
 def test_10(self):
     """TestXGrid.test_10(): genXAxisStroke() plotting UP with FEET and 1/200."""
     #print()
     myXs = XGrid.XGrid(200)
     v = 0
     eventS = []
     for e in myXs._genXAxisStroke(xFrom=4307.5, xInc=False, units=b'FEET'):
         #print(e)
         eventS.append(e)
         v += 1
         if v > 30:
             break
     #pprint.pprint(eventS)
     self.assertEqual([
         (4306,
          Stroke.Stroke(
              width=0.25, colour='black', coding=None, opacity=1.0)),
         (4304,
          Stroke.Stroke(
              width=0.25, colour='black', coding=None, opacity=1.0)),
         (4302,
          Stroke.Stroke(
              width=0.25, colour='black', coding=None, opacity=1.0)),
         (4300,
          Stroke.Stroke(width=1.0, colour='black', coding=None,
                        opacity=1.0)),
         (4298,
          Stroke.Stroke(
              width=0.25, colour='black', coding=None, opacity=1.0)),
         (4296,
          Stroke.Stroke(
              width=0.25, colour='black', coding=None, opacity=1.0)),
         (4294,
          Stroke.Stroke(
              width=0.25, colour='black', coding=None, opacity=1.0)),
         (4292,
          Stroke.Stroke(
              width=0.25, colour='black', coding=None, opacity=1.0)),
         (4290,
          Stroke.Stroke(width=0.5, colour='black', coding=None,
                        opacity=1.0)),
         (4288,
          Stroke.Stroke(
              width=0.25, colour='black', coding=None, opacity=1.0)),
         (4286,
          Stroke.Stroke(
              width=0.25, colour='black', coding=None, opacity=1.0)),
         (4284,
          Stroke.Stroke(
              width=0.25, colour='black', coding=None, opacity=1.0)),
         (4282,
          Stroke.Stroke(
              width=0.25, colour='black', coding=None, opacity=1.0)),
         (4280,
          Stroke.Stroke(width=0.5, colour='black', coding=None,
                        opacity=1.0)),
         (4278,
          Stroke.Stroke(
              width=0.25, colour='black', coding=None, opacity=1.0)),
         (4276,
          Stroke.Stroke(
              width=0.25, colour='black', coding=None, opacity=1.0)),
         (4274,
          Stroke.Stroke(
              width=0.25, colour='black', coding=None, opacity=1.0)),
         (4272,
          Stroke.Stroke(
              width=0.25, colour='black', coding=None, opacity=1.0)),
         (4270,
          Stroke.Stroke(width=0.5, colour='black', coding=None,
                        opacity=1.0)),
         (4268,
          Stroke.Stroke(
              width=0.25, colour='black', coding=None, opacity=1.0)),
         (4266,
          Stroke.Stroke(
              width=0.25, colour='black', coding=None, opacity=1.0)),
         (4264,
          Stroke.Stroke(
              width=0.25, colour='black', coding=None, opacity=1.0)),
         (4262,
          Stroke.Stroke(
              width=0.25, colour='black', coding=None, opacity=1.0)),
         (4260,
          Stroke.Stroke(width=0.5, colour='black', coding=None,
                        opacity=1.0)),
         (4258,
          Stroke.Stroke(
              width=0.25, colour='black', coding=None, opacity=1.0)),
         (4256,
          Stroke.Stroke(
              width=0.25, colour='black', coding=None, opacity=1.0)),
         (4254,
          Stroke.Stroke(
              width=0.25, colour='black', coding=None, opacity=1.0)),
         (4252,
          Stroke.Stroke(
              width=0.25, colour='black', coding=None, opacity=1.0)),
         (4250,
          Stroke.Stroke(
              width=0.75, colour='black', coding=None, opacity=1.0)),
         (4248,
          Stroke.Stroke(
              width=0.25, colour='black', coding=None, opacity=1.0)),
         (4246,
          Stroke.Stroke(
              width=0.25, colour='black', coding=None, opacity=1.0)),
     ], eventS)
Ejemplo n.º 10
0
import logging
#import collections
import math

from TotalDepth.LIS import ExceptionTotalDepthLIS
from TotalDepth.LIS.core import Units
from TotalDepth.util.plot import Coord
from TotalDepth.util.plot import Stroke

class ExceptionPlotXGrid(ExceptionTotalDepthLIS):
    """Exception for plotting."""
    pass

#: Definition of a grey solid stroke
#: Usage: StrokeBlackGrey._replace(width=2.0)
StrokeGreySolid = Stroke.Stroke('1', 'grey', None, 1.0)

class XGrid(object):
    """Class that can generate depth line grid and alphanumeric values.
    Constructed with integer scale.
    """
    #: Default for unknown units and scale, this is basically like
    #: simple graph paper
    DEFAULT_INTERVAL_MAP = {
        1   : Stroke.StrokeBlackSolid._replace(width=0.5),
        10  : Stroke.StrokeBlackSolid._replace(width=1.0),
    }
    #: Default position for text on the X axis
    DEFAULT_INTERVAL_TEXT = 100
    def __init__(self, scale):
        """Constructor with integer scale. We make scale a constructor argument
Ejemplo n.º 11
0
 def test_00(self):
     """TestPlotTrack.test_00(): Construct a lin/log/log track with FEET 1/200 and plot it in SVG."""
     myCnv = Plot.Canvas(Coord.Dim(8.5, 'in'), Coord.Dim(12, 'in'),
                         PlotConstants.MarginQtrInch)
     myViewPort = Coord.Box(
         width=myCnv.width,
         depth=myCnv.depth,
     )
     myTopLeft = Coord.Pt(Coord.Dim(0.25, 'in'), Coord.Dim(0.25, 'in'))
     myF = io.StringIO()
     myTracks = [
         Track.Track(leftPos=Coord.Dim(0.0, 'in'),
                     rightPos=Coord.Dim(2.4, 'in'),
                     gridGn=Track.genLinear10),
         Track.Track(
             leftPos=Coord.Dim(2.4, 'in'),
             rightPos=Coord.Dim(3.2, 'in'),
             gridGn=None,
             plotXAxis=True,
         ),
         Track.Track(leftPos=Coord.Dim(3.2, 'in'),
                     rightPos=Coord.Dim(5.6, 'in'),
                     gridGn=Track.genLog10Decade2Start2),
         Track.Track(leftPos=Coord.Dim(5.6, 'in'),
                     rightPos=Coord.Dim(8, 'in'),
                     gridGn=Track.genLog10Decade2Start2),
     ]
     with SVGWriter.SVGWriter(myF, myViewPort) as xS:
         # Do tracks first
         for t in myTracks:
             #xS.comment(str(t))
             if t.hasGrid:
                 t.plotSVG(
                     myTopLeft,
                     myCnv.depth - myCnv.margins.top - myCnv.margins.bottom,
                     xS,
                 )
         # Now XGrid
         # We are plotting up so xPosStart is at bottom
         myXposStart = myCnv.depth - myCnv.margins.bottom
         myXposStop = myCnv.margins.top
         myXg = XGrid.XGrid(200)
         # Plot depth lines
         for pos, stroke in myXg.genXPosStroke(xFrom=4307.5,
                                               xInc=False,
                                               units=b'FEET'):
             myXpos = myXposStart + pos
             if myXpos < myXposStop:
                 break
             for t in myTracks:
                 if t.hasGrid:
                     with SVGWriter.SVGLine(
                             xS,
                             Coord.Pt(t.left + myCnv.margins.left, myXpos),
                             Coord.Pt(t.right + myCnv.margins.left, myXpos),
                             attrs=Stroke.retSVGAttrsFromStroke(stroke)):
                         pass
         # Plot depth text
         textAttrs = {
             'text-anchor': 'end',
             'dominant-baseline': 'middle',
         }
         for pos, val in myXg.genXPosText(xFrom=4307.5,
                                          xInc=False,
                                          units=b'FEET'):
             myXpos = myXposStart + pos
             if myXpos < myXposStop:
                 break
             for t in myTracks:
                 if t.plotXAxis:
                     myPt = Coord.Pt(
                         t.right + myCnv.margins.left -
                         Coord.Dim(0.05, 'in'), myXpos)
                     with SVGWriter.SVGText(xS, myPt, 'Courier', 16,
                                            textAttrs):
                         xS.characters(str(val))
     print()
     print(myF.getvalue())