Created
August 31, 2017 03:53
-
-
Save cptncrnch/d0aa4d1d3e287c41c1aa8b6cfa55170c to your computer and use it in GitHub Desktop.
Parsing and plotting points from CYME XML
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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