Ejemplo n.º 1
0
def TestInfiniteSlope():
    xScreen = [45, 587, 45]
    yScreen = [327, 171, 15]
    xGraph = [0, 14, 0]
    yGraph = [-1.5, 0, 1.5]
    xPoints = 55
    yPoints = 96
    title = '.TestInfiniteSlope.dig'
    TDG.createTestCase(np.array([xScreen, xGraph]), np.array([yScreen,
                                                              yGraph]),
                       xPoints, yPoints, 'Linear', 'Linear', title)
    ParseDig.callEngauge(['-exportonly', title], DEBUG_ENABLE)
    engaugeOutput = pd.read_csv(title[:-3] + 'csv')
    parsedData = np.array(parseDigFile(title).iloc[:, :2])[0]
    testData = np.array(engaugeOutput.iloc[:, :2])[0]
    for i in range(len(testData)):
        decimalIndex = str(testData[i]).find('.')
        decimals = len(str(testData[i])) - decimalIndex - 1
        parsedData[i] = np.round(parsedData[i], decimals)
    showResults(inspect.stack()[0][3], testData, parsedData)
Ejemplo n.º 2
0
def parseDigFile(fileName):
    parseDig = ParseDig(fileName)
    curveNames = parseDig.curveNames()
    exportDelimiter = parseDig.exportDelimiter()
    try:
        f = open(fileName[:-4] + 'Parsed' + '.csv', 'w')
    except Exception as e:
        f = open(fileName[:-4] + 'Parsed' + '.csv', 'w+')
    for curveName in curveNames:

        header = ("# {}".format(curveName))
        f.write(header + exportDelimiter + exportDelimiter + exportDelimiter +
                '\n')
        curve = parseDig.curve(curveName)

        for row in curve:
            xGraph = row[0]
            yGraph = row[1]
            (xScreen,
             yScreen) = parseDig.transformGraphToScreen(xGraph, yGraph)
            dataLine = ("{}{}{}{}{}{}{}".format(xGraph, exportDelimiter,
                                                yGraph, exportDelimiter,
                                                xScreen, exportDelimiter,
                                                yScreen))
            f.write(dataLine + '\n')
    f.close()
    return pd.read_csv(fileName[:-4] + 'Parsed' + '.csv')
# script can be converted to other uses by replacing the local print statements with new code to export
# to a new format
#
# Requirements:
# 1) python3 (versus python2)
# 2) numpy
# 3) DefaultListOrderedDict.py from the Engauge scripts directory
# 4) ParseDig.py from the Engauge scripts directory

from ParseDig import ParseDig
import sys

if len(sys.argv) < 2:
    print ("Usage: python3 ExampleParseDig.py <dig file>")
else:
    parseDig = ParseDig (sys.argv [1])
    curveNames = parseDig.curveNames()
    print ("Curve names = ", curveNames, "\n")
    for curveName in curveNames:

        # Show (x,y) points as Nx2 matrix
        curve = parseDig.curve (curveName)
        print ("Curve ", "'" + curveName + "'", " = ", curve, "\n");

        # Show (x,y) points as 2 vectors
        x = [row [0] for row in curve]
        y = [row [1] for row in curve]
        print ("x=", x, "y=", y)


Ejemplo n.º 4
0
from numpy import poly1d
from numpy import polyfit

import sys

defaultHighestOrder = 3
if len(sys.argv) < 2:
    print("Usage: python3 CurveFitting.py <dig file> [<highest order>]")
    print("where:")
    print("  <dig file>      Version 6 or newer DIG file")
    print(
        "  <highest order> Highest order of polynomial to be fit to the data. Default is "
        + defaultHighestOrder)
    print("Example: python3 CurveFitting.py samples/CurveFitting.dig")
else:
    parseDig = ParseDig(sys.argv[1])
    highestOrderUser = defaultHighestOrder
    if len(sys.argv) == 3:
        highestOrderUser = int(sys.argv[2])
    curveNames = parseDig.curveNames()
    for curveName in curveNames:

        print()

        # Show (x,y) points as Nx2 matrix
        curve = parseDig.curve(curveName)

        # Show (x,y) points as 2 vectors
        xVector = [row[0] for row in curve]
        yVector = [row[1] for row in curve]
Ejemplo n.º 5
0
# 2) Between each field is the export delimiter selected in the DIG file
#
# Requirements:
# 1) python3 (versus python2)
# 2) numpy
# 3) DefaultListOrderedDict.py from the Engauge scripts directory
# 4) ParseDig.py from the Engauge scripts directory

import os
from ParseDig import ParseDig
import sys

if len(sys.argv) != 2 or not os.path.exists(sys.argv[1]):
    print("Usage: python3 DumpGraphAndScreenCoordinates.py <dig file>")
else:
    parseDig = ParseDig(sys.argv[1])
    curveNames = parseDig.curveNames()
    exportDelimiter = parseDig.exportDelimiter()
    for curveName in curveNames:

        print("# {}".format(curveName))
        curve = parseDig.curve(curveName)

        for row in curve:
            xGraph = row[0]
            yGraph = row[1]
            (xScreen,
             yScreen) = parseDig.transformGraphToScreen(xGraph, yGraph)
            print("{}{}{}{}{}{}{}".format(xGraph, exportDelimiter, yGraph,
                                          exportDelimiter, xScreen,
                                          exportDelimiter, yScreen))
# 2) Between each field is the export delimiter selected in the DIG file
#
# Requirements:
# 1) python3 (versus python2)
# 2) numpy
# 3) DefaultListOrderedDict.py from the Engauge scripts directory
# 4) ParseDig.py from the Engauge scripts directory

import os
from ParseDig import ParseDig
import sys

if len(sys.argv) != 2 or not os.path.exists(sys.argv[1]):
    print("Usage: python3 DumpGraphAndScreenCoordinates.py <dig file>")
else:
    parseDig = ParseDig(sys.argv[1])
    curveNames = parseDig.curveNames()
    exportDelimiter = parseDig.exportDelimiter()
    for curveName in curveNames:

        print("# {}".format(curveName))
        curve = parseDig.curve(curveName)

        for row in curve:
            xGraph = row[0]
            yGraph = row[1]
            (xScreen, yScreen) = row[2], row[
                3]  #parseDig.transformGraphToScreen (xGraph, yGraph)
            print("{}{}{}{}{}{}{}".format(xGraph, exportDelimiter, yGraph,
                                          exportDelimiter, xScreen,
                                          exportDelimiter, yScreen))