Skip to content

Instantly share code, notes, and snippets.

@cptncrnch
Created August 31, 2017 03:53
Show Gist options
  • Select an option

  • Save cptncrnch/d0aa4d1d3e287c41c1aa8b6cfa55170c to your computer and use it in GitHub Desktop.

Select an option

Save cptncrnch/d0aa4d1d3e287c41c1aa8b6cfa55170c to your computer and use it in GitHub Desktop.
Parsing and plotting points from CYME XML
# Parse an XML file exported from CYME for all node points and plot them by Section.
# Run script with XML file in the same directory.
###
import matplotlib.pyplot as plt
import xml.etree.ElementTree as ET
tree = ET.parse('sample.xml') # Replace with name of XML file
root = tree.getroot() # Get root XML elements in tree
# Find all elements that are Sections
for section in root.findall('./Network/Sections/Section'):
xpts = []
ypts = []
# Find From node in Section
fromNodeID = section.find('FromNodeID').text
for node in root.findall('./Network/Nodes/Node'):
if node[0].text == fromNodeID:
xpts.append(int(float(node[2].text)))
ypts.append(int(float(node[3].text)))
# Find all Intermediate Points in Section
for point in section.findall('./IntermediatePoints/Point'):
xpts.append(int(float(point[0].text)))
ypts.append(int(float(point[1].text)))
# Find To node in Section
toNodeID = section.find('ToNodeID').text
for node in root.findall('./Network/Nodes/Node'):
if node[0].text == toNodeID:
xpts.append(int(float(node[2].text)))
ypts.append(int(float(node[3].text)))
# Plot x- and y-points
plt.plot(xpts,ypts,'-o')
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment