Пример #1
0
def _convertForCvr(stdPath, seqPath, outFilePath):
	''' Convert a feeder to a GLM'''
	with open(stdPath) as stdFile, open(seqPath) as seqFile:
		stdString = stdFile.read()
		seqString = seqFile.read()
	tree,xScale,yScale = milToGridlab.convert(stdString,seqString)
	with open(outFilePath,'w') as glmFile:
		glmFile.write(feeder.sortedWrite(tree))
Пример #2
0
Файл: web.py Проект: cdkkim/omf
def milImportBackground(owner, feederName, stdString, seqString):
	''' Function to run in the background for Milsoft import. '''
	newFeeder = dict(**feeder.newFeederWireframe)
	[newFeeder["tree"], xScale, yScale] = milToGridlab.convert(stdString, seqString)
	newFeeder["layoutVars"]["xScale"] = xScale
	newFeeder["layoutVars"]["yScale"] = yScale
	with open("./schedules.glm","r") as schedFile:
		newFeeder["attachments"] = {"schedules.glm":schedFile.read()}
	with open("data/Feeder/" + owner + "/" + feederName + ".json", "w") as outFile:
		json.dump(newFeeder, outFile, indent=4)
	os.remove("data/Conversion/" + owner + "/" + feederName + ".json")
Пример #3
0
def milImportBackground(owner, feederName, stdString, seqString):
	''' Function to run in the background for Milsoft import. '''
	newFeeder = dict(**feeder.newFeederWireframe)
	[newFeeder["tree"], xScale, yScale] = milToGridlab.convert(stdString, seqString)
	newFeeder["layoutVars"]["xScale"] = xScale
	newFeeder["layoutVars"]["yScale"] = yScale
	with open("./schedules.glm","r") as schedFile:
		newFeeder["attachments"] = {"schedules.glm":schedFile.read()}
	with open("data/Feeder/" + owner + "/" + feederName + ".json", "w") as outFile:
		json.dump(newFeeder, outFile, indent=4)
	os.remove("data/Conversion/" + owner + "/" + feederName + ".json")
Пример #4
0
def testFile(stdName, seqName):
	try:
		outGlmString = milToGridlab.convert('../../uploads/' + stdName + '.std','../../uploads/' + seqName)
		outGlmString += 'object voltdump {\nfilename ' + stdName + '.VOLTS.csv;\n};'
		with open(stdName + '.glm','w') as outFile:
			outFile.write(outGlmString)
		print stdName + ' converted.'
		proc = subprocess.Popen(['gridlabd','-w', stdName + '.glm'], cwd='.')
		proc.wait()
	except:
		print 'Conversion error! With ' + stdName
		traceback.print_exc(file=sys.stdout)
Пример #5
0
def milsoftToGridlabTests(keepFiles=False):
	openPrefix = '../uploads/'
	outPrefix = './milToGridlabTests/'
	import os, json, traceback, shutil
	from omf.solvers import gridlabd
	from matplotlib import pyplot as plt
	from milToGridlab import convert
	import omf.feeder as feeder
	try:
		os.mkdir(outPrefix)
	except:
		pass # Directory already there.
	exceptionCount = 0
	# testFiles = [('INEC-RENOIR.std','INEC.seq'), ('INEC-GRAHAM.std','INEC.seq'),
	#   ('Olin-Barre.std','Olin.seq'), ('Olin-Brown.std','Olin.seq'),
	#   ('ABEC-FRANK.std','ABEC.seq'), ('ABEC-COLUMBIA.std','ABEC.seq'),('OMF_Norfork1.std', 'OMF_Norfork1.seq')]
	testFiles = [('Olin-Brown.std', 'Olin.seq')]
	testAttachments = {'schedules.glm':''}
	# testAttachments = {'schedules.glm':'', 'climate.tmy2':open('./data/Climate/KY-LEXINGTON.tmy2','r').read()}
	for stdString, seqString in testFiles:
		try:
			# Convert the std+seq.
			with open(openPrefix + stdString,'r') as stdFile, open(openPrefix + seqString,'r') as seqFile:
				outGlm,x,y = convert(stdFile.read(),seqFile.read())
			with open(outPrefix + stdString.replace('.std','.glm'),'w') as outFile:
				outFile.write(feeder.sortedWrite(outGlm))
			print 'WROTE GLM FOR', stdString
			try:
				# Draw the GLM.
				myGraph = feeder.treeToNxGraph(outGlm)
				feeder.latLonNxGraph(myGraph, neatoLayout=False)
				plt.savefig(outPrefix + stdString.replace('.std','.png'))
				print 'DREW GLM OF', stdString
			except:
				exceptionCount += 1
				print 'FAILED DRAWING', stdString
			try:
				# Run powerflow on the GLM. HACK:blank attachments for now.
				output = gridlabd.runInFilesystem(outGlm, attachments=testAttachments, keepFiles=False)
				with open(outPrefix + stdString.replace('.std','.json'),'w') as outFile:
					json.dump(output, outFile, indent=4)
				print 'RAN GRIDLAB ON', stdString
			except:
				exceptionCount += 1
				print 'POWERFLOW FAILED', stdString
		except:
			print 'FAILED CONVERTING', stdString
			exceptionCount += 1
			traceback.print_exc()
	if not keepFiles:
		shutil.rmtree(outPrefix)
	return exceptionCount
Пример #6
0
def milImportBackground(owner, modelName, feederName, feederNum, stdString, seqString):
	''' Function to run in the background for Milsoft import. '''
	modelDir = "data/Model/"+owner+"/"+modelName
	feederDir = modelDir+"/"+feederName+".omd"
	newFeeder = dict(**feeder.newFeederWireframe)
	[newFeeder["tree"], xScale, yScale] = milToGridlab.convert(stdString, seqString)
	newFeeder["layoutVars"]["xScale"] = xScale
	newFeeder["layoutVars"]["yScale"] = yScale
	with open("./schedules.glm","r") as schedFile:
		newFeeder["attachments"] = {"schedules.glm":schedFile.read()}
	try: os.remove(feederDir)
	except: pass
	with open(feederDir, "w") as outFile:
		json.dump(newFeeder, outFile, indent=4)
	os.remove("data/Conversion/" + owner + "/" + feederName + ".json")
	removeFeeder(modelName, feederNum)
	writeToInput(modelDir, feederName, 'feederName'+str(feederNum))
Пример #7
0
def handleMilFile(std_path, seq_path, failure=False):
    ''' Conversion routine for the std and seq files. '''
    # Attempt to open std and seq files and convert to glm.
    try:
        with open(std_path, 'r') as std_file, open(seq_path, 'r') as seq_file:
            output_path = std_path.split('/')[-1].replace(
                '.std', '.glm'
            )  # We wish to put the file in the current running directory.
            output_file = open(output_path, 'w')
            glm, x_scale, y_scale = mil.convert(std_file.read(),
                                                seq_file.read())
            output_file.write(feeder.sortedWrite(glm))
            print 'GLM FILE WRITTEN FOR STD/SEQ COMBO.'
    except IOError:
        print 'UNABLE TO WRITE GLM FILE.'
        failure = True
    finally:
        output_file.close()
    return failure
Пример #8
0
def milImportBackground(owner, modelName, feederName, feederNum, stdString,
                        seqString):
    ''' Function to run in the background for Milsoft import. '''
    modelDir = "data/Model/" + owner + "/" + modelName
    feederDir = modelDir + "/" + feederName + ".omd"
    newFeeder = dict(**feeder.newFeederWireframe)
    [newFeeder["tree"], xScale,
     yScale] = milToGridlab.convert(stdString, seqString)
    newFeeder["layoutVars"]["xScale"] = xScale
    newFeeder["layoutVars"]["yScale"] = yScale
    with open("./schedules.glm", "r") as schedFile:
        newFeeder["attachments"] = {"schedules.glm": schedFile.read()}
    try:
        os.remove(feederDir)
    except:
        pass
    with open(feederDir, "w") as outFile:
        json.dump(newFeeder, outFile, indent=4)
    os.remove("data/Conversion/" + owner + "/" + feederName + ".json")
    removeFeeder(owner, modelName, feederNum)
    writeToInput(modelDir, feederName, 'feederName' + str(feederNum))
Пример #9
0
def convertTests():
    ''' Test convert every windmil feeder we have (in uploads). Return number of exceptions we hit. '''
    exceptionCount = 0
    testFiles = [('OrvilleTreePond.std', 'OrvilleTreePond.seq')]
    # ,('OlinBarre.std','OlinBarre.seq'),('OlinBeckenham.std','OlinBeckenham.seq'), ('AutocliAlberich.std','AutocliAlberich.seq')
    for stdString, seqString in testFiles:
        try:
            # Convert the std+seq.
            with open(stdString, 'r') as stdFile, open(seqString,
                                                       'r') as seqFile:
                outGlm, x, y = milToGridlab.convert(stdFile.read(),
                                                    seqFile.read())
            with open(stdString.replace('.std', '.glm'), 'w') as outFile:
                outFile.write(feeder.sortedWrite(outGlm))
            print 'WROTE GLM FOR', stdString
            try:
                # Draw the GLM.
                myGraph = feeder.treeToNxGraph(outGlm)
                feeder.latLonNxGraph(myGraph, neatoLayout=False)
                plt.savefig(stdString.replace('.std', '.png'))
                print 'DREW GLM OF', stdString
            except:
                exceptionCount += 1
                print 'FAILED DRAWING', stdString
            try:
                # Run powerflow on the GLM.
                output = gridlabd.runInFilesystem(outGlm, keepFiles=False)
                with open(stdString.replace('.std', '.json'), 'w') as outFile:
                    json.dump(output, outFile, indent=4)
                print 'RAN GRIDLAB ON', stdString
            except:
                exceptionCount += 1
                print 'POWERFLOW FAILED', stdString
        except:
            print 'FAILED CONVERTING', stdString
            exceptionCount += 1
            traceback.print_exc()
    print exceptionCount
Пример #10
0
def _tests():
    pathPrefix = '../../uploads/'
    testFiles = [
        ('INEC-RENOIR.std', 'INEC.seq'), ('INEC-GRAHAM.std', 'INEC.seq'),
        ('Olin-Barre.std', 'Olin.seq'), ('Olin-Brown.std', 'Olin.seq'),
        ('ABEC-Frank.std', 'ABEC.seq'), ('ABEC-COLUMBIA.std', 'ABEC.seq')
    ]

    for stdPath, seqPath in testFiles:
        try:
            # Conver the std+seq.
            with open(pathPrefix + stdPath,
                      'r') as stdFile, open(pathPrefix + seqPath,
                                            'r') as seqFile:
                outGlm, x, y = m2g.convert(stdFile.read(), seqFile.read())
            with open(stdPath.replace('.std', '.glm'), 'w') as outFile:
                outFile.write(feeder.sortedWrite(outGlm))
            print 'WROTE GLM FOR', stdPath
            try:
                # Draw the GLM.
                myGraph = feeder.treeToNxGraph(outGlm)
                feeder.latLonNxGraph(myGraph, neatoLayout=False)
                plt.savefig(stdPath.replace('.std', '.png'))
            except:
                print 'FAILED DRAWING', stdPath
            try:
                # Run powerflow on the GLM.
                output = gridlabd.runInFilesystem(outGlm, keepFiles=False)
                with open(stdPath.replace('.std', '.json'), 'w') as outFile:
                    json.dump(output, outFile, indent=4)
            except:
                print 'POWERFLOW FAILED', stdPath
        except:
            print 'FAILED CONVERTING', stdPath
            traceback.print_exc()

    print os.listdir('.')
Пример #11
0
def convertTests():
	''' Test convert every windmil feeder we have (in uploads). Return number of exceptions we hit. '''
	exceptionCount = 0
	testFiles = [('OrvilleTreePond.std','OrvilleTreePond.seq')]
	# ,('OlinBarre.std','OlinBarre.seq'),('OlinBeckenham.std','OlinBeckenham.seq'), ('AutocliAlberich.std','AutocliAlberich.seq')
	for stdString, seqString in testFiles:
		try:
			# Convert the std+seq.
			with open(stdString,'r') as stdFile, open(seqString,'r') as seqFile:
				outGlm,x,y = milToGridlab.convert(stdFile.read(),seqFile.read())
			with open(stdString.replace('.std','.glm'),'w') as outFile:
				outFile.write(feeder.sortedWrite(outGlm))
			print 'WROTE GLM FOR', stdString
			try:
				# Draw the GLM.
				myGraph = feeder.treeToNxGraph(outGlm)
				feeder.latLonNxGraph(myGraph, neatoLayout=False)
				plt.savefig(stdString.replace('.std','.png'))
				print 'DREW GLM OF', stdString
			except:
				exceptionCount += 1
				print 'FAILED DRAWING', stdString
			try:
				# Run powerflow on the GLM.
				output = gridlabd.runInFilesystem(outGlm, keepFiles=False)
				with open(stdString.replace('.std','.json'),'w') as outFile:
					json.dump(output, outFile, indent=4)
				print 'RAN GRIDLAB ON', stdString					
			except:
				exceptionCount += 1
				print 'POWERFLOW FAILED', stdString
		except:
			print 'FAILED CONVERTING', stdString
			exceptionCount += 1
			traceback.print_exc()
	print exceptionCount
Пример #12
0
from pprint import pprint

glmTree = tp.parse('ILEC-Rembrandt.glm')

lineCoords = [x for x in glmTree if 'object' in glmTree[x] and (glmTree[x]['object'] == 'underground_line' or glmTree[x]['object'] == 'overhead_line')]
print lineCoords

# Here are the keys for a line:
print [x for x in glmTree[12]]

# Replace the embedded configurations with refs to config objects.
for coord in lineCoords:
	intKeys = [x for x in glmTree[coord] if type(x) is int]
	if len(intKeys) == 1:
		target = intKeys[0]
		del glmTree[coord][target]
		if glmTree[coord]['object'] == 'underground_line':
			glmTree[coord]['configuration'] = 'lc_7211'
		elif glmTree[coord]['object'] == 'overhead_line':
			glmTree[coord]['configuration'] = 'ohconfig'

# Just write it out.
outGlmString = tp.sortedWrite(glmTree)
with open('ILEC-Rembrandt-SYNTH.glm','w') as synthFile:
	synthFile.write(outGlmString)


# Do a regular conversion
outGlm = milToGridlab.convert('../../uploads/ILEC-Rembrandt.std','../../uploads/ILEC.seq')
with open('ILEC-Rembrandt-AUTOSYNTH.glm','w') as synthFile2:
	synthFile2.write(outGlm)
Пример #13
0
#!/usr/bin/env python

'''
Get the ACEC Friendship feeder into a GLM file.
'''

import os
import sys
sys.path.append(os.path.dirname(os.path.dirname(os.getcwd())))
import feeder as tp
import milToGridlab
from pprint import pprint

outGlm = milToGridlab.convert('../../uploads/ACEC-Friendship.std','../../uploads/ACEC.seq')
outGlm += 'object voltdump {\nfilename output_voltage.csv;\n};'
with open('ACEC-Friendship-NEOSYNTH.glm','w') as outFile:
	outFile.write(outGlm)
Пример #14
0
lineCoords = [
    x for x in glmTree
    if 'object' in glmTree[x] and (glmTree[x]['object'] == 'underground_line'
                                   or glmTree[x]['object'] == 'overhead_line')
]
print lineCoords

# Here are the keys for a line:
print[x for x in glmTree[12]]

# Replace the embedded configurations with refs to config objects.
for coord in lineCoords:
    intKeys = [x for x in glmTree[coord] if type(x) is int]
    if len(intKeys) == 1:
        target = intKeys[0]
        del glmTree[coord][target]
        if glmTree[coord]['object'] == 'underground_line':
            glmTree[coord]['configuration'] = 'lc_7211'
        elif glmTree[coord]['object'] == 'overhead_line':
            glmTree[coord]['configuration'] = 'ohconfig'

# Just write it out.
outGlmString = tp.sortedWrite(glmTree)
with open('ILEC-Rembrandt-SYNTH.glm', 'w') as synthFile:
    synthFile.write(outGlmString)

# Do a regular conversion
outGlm = milToGridlab.convert('../../uploads/ILEC-Rembrandt.std',
                              '../../uploads/ILEC.seq')
with open('ILEC-Rembrandt-AUTOSYNTH.glm', 'w') as synthFile2:
    synthFile2.write(outGlm)