field_coords=eval("dict("+line+")")# literal_eval does not accept dict definition via constructor. Make sure config file is not writable to prevent code execution!
# This module provides functions for easy creation of a Lofar LTA SIP document.
# It builds upon a Pyxb-generated API from the schema definition, which is very clever but hard to use, since
# the arguments in class constructors and functions definitions are not verbose and there is no intuitive way
# to determine the mandatory and optional elements to create a valid SIP document. This module is designed to
# provide easy-to-use functions that bridges this shortcoming of the Pyxb API.
#
# Usage: Import module. Create an instance of Sip.
# Add elements through the Sip.add_X functions. Many require instances of other classes of the module.
# call getprettyxml() and e.g. save to disk.
#
# Note on validation: From construction through every addition, the SIP should remain valid (or throw an error
# that clearly points out where e.g. a given value does not meet the restrictions of the SIP schema.
#
# Note on code structure: This has to be seen as a compromise between elegant and maintainable code with well-
# structured inheritance close to the schema definition on the one hand, and something more straightforward to use,
# with flatter hierarchies on the other hand.
#
# Note on parameter maps: The ...Map objects are helper objects to create dictionaries for the commonly used
# constructor arguments of several other objects. This could alternatively also be implemented via inheritance from
# a supertype, and indeed is solved like this in the pyxb code. However, this then requires the use of an argument
# list pointer, which hides the list of required and optional arguments from the user. Alternatively, all arguments
# have to be mapped in all constructors repeatedly, creating lots of boilerplate code. This is the nicest approach
# I could think of that keeps the whole thing reasonably maintainable AND usable.
importos
d=os.path.dirname(os.path.realpath(__file__))
STATION_CONFIG_PATH=d+'/station_coordinates.conf'
defparse_station_coordinates()->dict:
"""
:return: a dict mapping station field name, e.g. "CS002_LBA", to a dict containing ITRF coordinates
"""
station_coordinates={}
withopen(STATION_CONFIG_PATH,'r')asf:
forlineinf.readlines():
ifline.strip():
field_coords=eval("dict("+line+")")# literal_eval does not accept dict definition via constructor. Make sure config file is not writable to prevent code execution!