Menu

Python Editor

Kyle Anderson

Purpose and Description:

The python editor files are useful for quick change and analysis of gridlabd .glm input files. They allow for a .glm file to be parsed into a system of python objects, making it easy to change property values and create automated programs that continually run gridlabd on a changing glm file. It also allows for a quick way to dump a .glm file to its .xml format. Additionally, adding objects to the system is quick and easy.


The editor relies on python classes generated for all of the classes in the gridlabd modules. These files can be updated as the core files of gridlabd are updated by simply calling the commandline option "gridlab --generate_python" from the gridlabd directory.


The core of this editor is contained in the classes of "glmParseTools.py", which includes the classes glmParser, which parses a glm file into lists of class objects, glmWriter, which writes these objects back out to .glm format, and xmlWriter, which writes these objects back out to .xml format. Example uses of these base classes can be seen in the files "parseGLM.py" and "glmToXml.py"

Example Usage

parseGLM.py: this snippet parses the glm "ifile" and writes it back out in glm form to some output
file "ofile"

myglmParser = glmParser()
myglmParser.parseGLM(ifile)
myglmWriter = glmWriter(ofile,myglmParser)
myglmWriter.writeToGLM()

changePropValues.py: this snippet changes the E_Max value of all batteries in the system to "1000"

myglmParser = glmParser()
myglmParser.parseGLM(ifile)
changeObjectProperty(myglmParser,"battery","E_Max",1000)
where changeObjectProperty checks if the class name and property exist and then changes the given
field in all objects of the specified class