Note
Click here to download the full example code
Parse xml configuration file#
import os.path as path
import xml.etree.ElementTree as et
from numpy import array
from cherab.iter.tools import xml
###################
# Load config file#
config = path.join(path.dirname(__file__), "template.xml")
tree = et.parse(config)
root = tree.getroot()
###################
# User option #
user_options = xml.parse_user_options(config)
print("User options:")
for option, value in user_options.items():
if isinstance(value, bool):
print("{}: {}".format(option.replace("_", " "), xml.bool2str(value)))
else:
print("{}: {}".format(option.replace("_", " "), value))
print()
###################
# Emission lines #
emission_lines = xml.parse_emission_lines(config)
for line in emission_lines:
print("<Line: element={}, charge={}, transition={}>".format(line.element, line.charge, line.transition))
print()
###################
# Beam config #
source, direction = xml.parse_beam_geometry(config)
print("Beam")
print("Source: {}".format(source))
print("Direction: {}".format(direction))
print()
###################
# Camera config #
user_options = root.find("user_options")
camera_pixels = user_options.find("camera_pixels")
print("Nested list of camera pixels: {}".format(xml.read_xml_entry(camera_pixels, rtype=array)))
print()
for name in ["E1", "EC", "EF"]:
aperture_position, intersection_radii = xml.parse_diagnostic_geometry(config, name)
print("Diagnostic: {}".format(name))
print("Aperture position: {}".format(aperture_position))
print("Intersection radii: {}".format(intersection_radii))
print()
Total running time of the script: ( 0 minutes 0.000 seconds)