def _tests(): feederDict = feeder.parse('./IEEE13Basic.glm') model_name = 'testing_model_13Node' scada = {'summerDay' : '2012-06-29', 'winterDay' : '2012-01-19', 'shoulderDay' : '2012-04-10', 'summerPeakKW' : 5931.56, 'summerTotalEnergy' : 107380.8, 'summerPeakHour' : 17, 'summerMinimumKW' : 2988, 'summerMinimumHour' : 6, 'winterPeakKW' : 3646.08, 'winterTotalEnergy' : 75604.32, 'winterPeakHour' : 21, 'winterMinimumKW' : 2469.60, 'winterMinimumHour' : 1, 'shoulderPeakKW' : 2518.56 , 'shoulderTotalEnergy' : 52316.64, 'shoulderPeakHour' : 21, 'shoulderMinimumKW' : 1738.08, 'shoulderMinimumHour' : 2} calibration_config = None case_flag = -1 # base case, do not put None calibratedFeederDict, calibrationDict = OMFmain(feederDict, scada, case_flag, calibration_config, model_name, 1) assert calibratedFeederDict != None assert calibrationDict != None
def _tests(): feederDict = feeder.parse('./IEEE13Basic.glm') model_name = 'testing_model_13Node' scada = { 'summerDay': '2012-06-29', 'winterDay': '2012-01-19', 'shoulderDay': '2012-04-10', 'summerPeakKW': 5931.56, 'summerTotalEnergy': 107380.8, 'summerPeakHour': 17, 'summerMinimumKW': 2988, 'summerMinimumHour': 6, 'winterPeakKW': 3646.08, 'winterTotalEnergy': 75604.32, 'winterPeakHour': 21, 'winterMinimumKW': 2469.60, 'winterMinimumHour': 1, 'shoulderPeakKW': 2518.56, 'shoulderTotalEnergy': 52316.64, 'shoulderPeakHour': 21, 'shoulderMinimumKW': 1738.08, 'shoulderMinimumHour': 2 } calibration_config = None case_flag = -1 # base case, do not put None calibratedFeederDict, calibrationDict = OMFmain(feederDict, scada, case_flag, calibration_config, model_name, 1) assert calibratedFeederDict != None assert calibrationDict != None
def _tests(): #tests here glm_object_dict = feeder.parse('./IEEE13Basic.glm') baseGLM, last_key = GLD_Feeder(glm_object_dict, 0, None) glm_string = feeder.sortedWrite(baseGLM) file = open('./IEEE13BasePopulation.glm', 'w') file.write(glm_string) file.close() print('success!')
def _tests(): #tests here glm_object_dict = feeder.parse('./IEEE13Basic.glm') baseGLM, last_key = GLD_Feeder(glm_object_dict,0,None) glm_string = feeder.sortedWrite(baseGLM) file = open('./IEEE13BasePopulation.glm','w') file.write(glm_string) file.close() print('success!')
def getTreeOrCache(): # Cache this; it takes 30 seconds on my laptop to get the dang thing going. if 'AutocliAlberichCache.json' not in os.listdir('.'): tree = feeder.parse('2. edited.glm') with open('AutocliAlberichCache.json','w') as cFile: json.dump(tree, cFile, indent=4) else: with open('AutocliAlberichCache.json', 'r') as iFile: tree = json.load(iFile) return tree
def getTreeOrCache(): # Cache this; it takes 30 seconds on my laptop to get the dang thing going. if 'AutocliAlberichCache.json' not in os.listdir('.'): tree = feeder.parse('2. edited.glm') with open('AutocliAlberichCache.json', 'w') as cFile: json.dump(tree, cFile, indent=4) else: with open('AutocliAlberichCache.json', 'r') as iFile: tree = json.load(iFile) return tree
def gridlabImportBackground(owner, feederName, glmString): ''' Function to run in the background for Milsoft import. ''' newFeeder = dict(**feeder.newFeederWireframe) newFeeder["tree"] = feeder.parse(glmString, False) newFeeder["layoutVars"]["xScale"] = 0 newFeeder["layoutVars"]["yScale"] = 0 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")
def gridlabdImport(): '''This function is used for gridlabdImporting''' feederName = str(request.form.get("feederName","")) newFeeder = dict(**feeder.newFeederWireframe) newFeeder["tree"] = feeder.parse(request.files["glmFile"].stream.read(), False) newFeeder["layoutVars"]["xScale"] = 0 newFeeder["layoutVars"]["yScale"] = 0 with open("./schedules.glm","r") as schedFile: newFeeder["attachments"] = {"schedules.glm":schedFile.read()} with open("data/Feeder/" + User.cu() + "/" + feederName + ".json", "w") as outFile: json.dump(newFeeder, outFile, indent=4) return redirect("/#feeders")
def gridlabImportBackground(owner, modelName, feederName, feederNum, glmString): ''' Function to run in the background for Milsoft import. ''' modelDir = "data/Model/"+owner+"/"+modelName feederDir = modelDir+"/"+feederName+".omd" newFeeder = dict(**feeder.newFeederWireframe) newFeeder["tree"] = feeder.parse(glmString, False) newFeeder["layoutVars"]["xScale"] = 0 newFeeder["layoutVars"]["yScale"] = 0 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))
def gridlabImportBackground(owner, modelName, feederName, feederNum, glmString): ''' Function to run in the background for Milsoft import. ''' modelDir = "data/Model/" + owner + "/" + modelName feederDir = modelDir + "/" + feederName + ".omd" newFeeder = dict(**feeder.newFeederWireframe) newFeeder["tree"] = feeder.parse(glmString, False) newFeeder["layoutVars"]["xScale"] = 0 newFeeder["layoutVars"]["yScale"] = 0 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))
def _tests(): #Import GLM and convert to dictionary when directly called from the command line. When used as a Python module, # will be handed a dictionary containing the feeder model and the parameters for the battery being added. convOut = feeder.parse(sys.argv[1]) nodeList = ['Node633'] battDict = {'feederDict':convOut, 'battNode': nodeList, 'battEnergyRatingkWh':250, 'invPowerRatingkW': 100, 'battSOCpu': 0.5, 'invControl':'LOAD_following', 'controlSenseNode': 'Node633', 'invChargeOnThresholdkW': 1500, 'invChargeOffThresholdkW': 1700, 'invDischargeOnThresholdkW': 1800, 'invDischargeOffThresholdkW': 1750, } outTree = addBattery(battDict) if outTree == 0: print 'Failed to add battery. Continuing on...' GLM = feeder.sortedWrite(outTree) f = open('testFeeder.glm','w') f.write(GLM)
def _tests(): '''Self-test to verify module functions correctly.''' logger.info('Started parsing .glm...') input_glm_dict = feeder.parse("/Users/hard312/Documents/Projects/TSP/rev0/" "models/gridlabd/testbed2/" "R2_1247_2_t0_growth.glm", filePath=True) logger.info('Done parsing .glm. Now de-embedding') feeder.fullyDeEmbed(input_glm_dict) logger.info('Completed de-embedding.') logger.debug('Final input .glm dictionary...') logger.debug(pp.pformat(input_glm_dict)) house_stats = gather_house_stats(input_glm_dict) # xfmr_summary = summarize_xfmr_stats(house_stats) mod_glm_dict = copy.deepcopy(input_glm_dict) mod_glm_dict = update_brownfield_loads(mod_glm_dict, 0.05) mod_glm_dict, house_stats = add_greenfield_loads(input_glm_dict, house_stats, 0.90) logger.info('Completed modification of feeder.') logger.debug(pp.pformat(mod_glm_dict)) feeder_str = feeder.sortedWrite(mod_glm_dict) glm_file = open('./modified_feeder.glm', 'w') glm_file.write(feeder_str) glm_file.close()
def _test(): ''' Calibrates an IEEE 13 test feeder using loadshapes and returns the resulting feeder tree and calibration configuration dictionary.''' feederTree = feeder.parse('./uploads/IEEE-13.glm') model_name = 'calibrated_model_IEEE13' working_directory = tempfile.mkdtemp() print "Calibration testing in ", working_directory scada = {'summerDay' : '2012-06-29', 'winterDay' : '2012-01-19', 'shoulderDay' : '2012-04-10', 'summerPeakKW' : 5931.56, 'summerTotalEnergy' : 107380.8, 'summerPeakHour' : 17, 'summerMinimumKW' : 2988, 'summerMinimumHour' : 6, 'winterPeakKW' : 3646.08, 'winterTotalEnergy' : 75604.32, 'winterPeakHour' : 21, 'winterMinimumKW' : 2469.60, 'winterMinimumHour' : 1, 'shoulderPeakKW' : 2518.56 , 'shoulderTotalEnergy' : 52316.64, 'shoulderPeakHour' : 21, 'shoulderMinimumKW' : 1738.08, 'shoulderMinimumHour' : 2} calibration_config = {'timezone' : 'CST+6CDT', 'startdate' : '2012-01-01 0:00:00', 'stopdate' : '2013-01-01 0:00:00', 'region' : 6, 'feeder_rating' : 600, 'nom_volt' : 15000, 'voltage_players' : [os.path.abspath('./uploads/VA.player').replace('\\', '/'), os.path.abspath('./uploads/VB.player').replace('\\', '/'), os.path.abspath('./uploads/VC.player').replace('\\', '/')], 'load_shape_scalar' : 1.0, 'load_shape_player_file' : os.path.abspath('./uploads/load_shape_player.player').replace('\\', '/'), 'weather_file' : os.path.abspath('./uploads/SCADA_weather_NC_gld_shifted.csv').replace('\\', '/')} calibratedFeederTree, calibrationConfiguration = startCalibration(working_directory, feederTree, scada, model_name, calibration_config) assert None != calibratedFeederTree assert None != calibrationConfiguration
#!/usr/bin/env python import os import sys sys.path.append(os.path.dirname(os.path.dirname(os.getcwd()))) import feeder as tp from pprint import pformat tree=tp.parse('main.glm') with open('out.txt','w') as outFile: outFile.write(pformat(tree)) with open('out.glm','w') as outGlm: outGlm.write(tp.sortedWrite(tree))
1. Loads into triplex nodes with constant power. 2. Nodes on loads into meters. 3. Transformer phase fix. 4. Length and power order of magnitude fixes. ''' import os import sys from os.path import dirname # go two layers up and add that to this file's temp path sys.path.append(dirname(dirname(os.getcwd()))) import feeder as tp from pprint import pprint glm = tp.parse('ACEC-Friendship-AUTOSYNTH.glm') def secondarySystemFix(glm): allLoadKeys = [x for x in glm if 'object' in glm[x] and glm[x]['object']=='load'] print 'Number of loads (some group on one transformer):' print str(len(allLoadKeys)) + '\n' allNamesNodesOnLoads = list(set([glm[key]['parent'] for key in allLoadKeys])) print 'Number of nodes on loads:' print str(len(allNamesNodesOnLoads)) + '\n' allNodesOnLoadsKeys = [x for x in glm if 'name' in glm[x] and glm[x]['name'] in allNamesNodesOnLoads] print 'Example node:' print glm[allNodesOnLoadsKeys[1]]
import os import sys sys.path.append(os.path.dirname(os.path.dirname(os.getcwd()))) import feeder as tp from pprint import pprint import pickle haveCache = False dirFiles = os.listdir('.') if 'acec.pickle' in dirFiles: haveCache = True with open('acec.pickle') as cache: glm = pickle.load(cache) else: glm = tp.parse('ACEC-Friendship-handedit.glm') allLoads = [ glm[x] for x in glm if 'object' in glm[x] and glm[x]['object'] == 'load' ] allTransformers = [ glm[x] for x in glm if 'object' in glm[x] and glm[x]['object'] == 'transformer' ] print 'Number of loads (some group on one transformer):' print len(allLoads) nodesOnLoadsNames = list(set([x['parent'] for x in allLoads])) print 'Number of nodes on loads:' print len(nodesOnLoadsNames) print 'Number of transformers:' print len(allTransformers)
#!/usr/bin/env python 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 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'
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 import pickle if 'disembed.pickle' in os.listdir('.'): with open('disembed.pickle', 'r') as pickFile: glm = pickle.load(pickFile) else: glm = tp.parse('ACEC-Friendship-NEOSYNTH.glm') tp.fullyDeEmbed(glm) with open('disembed.pickle', 'w') as pickFile: pickle.dump(glm, pickFile) def dedupGlm(compName, glmRef): ''' Assume compName is transformer_configuration 1. pull out a list of all transformer_configuration dicts. 2. process to make redundant ones into tuples 3. go through the list backwards and collapse chains of references. or fold carefully until we can't fold any more. 4. actually replace the names on other objects and then delete the tuples. ''' def isSameMinusName(x, y): newX = {val: x[val] for val in x if val != 'name'}
def makeCalibrationJsons(fPrefix): tree = feeder.parse(fPrefix+'Debugged.glm') wrappedTree = {'tree':tree, 'attachments':{}} with open(fPrefix+'ForCalibration.json','w') as caliFile: json.dump(wrappedTree, caliFile, indent=4)
def makeCalibrationJsons(fPrefix): tree = feeder.parse(fPrefix + 'Debugged.glm') wrappedTree = {'tree': tree, 'attachments': {}} with open(fPrefix + 'ForCalibration.json', 'w') as caliFile: json.dump(wrappedTree, caliFile, indent=4)
#!/usr/bin/env python import os import sys sys.path.append(os.path.dirname(os.path.dirname(os.getcwd()))) import feeder as tp from pprint import pformat tree = tp.parse('main.glm') with open('out.txt', 'w') as outFile: outFile.write(pformat(tree)) with open('out.glm', 'w') as outGlm: outGlm.write(tp.sortedWrite(tree))
def readSCADA(scadaFile): scada = {'timestamp' : [], 'phaseAW' : [], 'phaseBW' : [], 'phaseCW' : [], 'phaseAVAR' : [], 'phaseBVAR' : [], 'phaseCVAR' : [], 'totalVA' : [], 'pfA' : [], 'pfB' : [], 'pfC' : [], 'puLoad' : [], 'VoltageA' : [], 'VoltageB' : [], 'VoltageC' : []} scadaInfo = {'summerDay' : None, 'winterDay' : None, 'shoulderDay' : None, 'summerPeakKW' : 0, 'summerTotalEnergy' : 30134.0730, 'summerPeakHour' : None, 'summerMinimumKW' : 1e15, 'summerMinimumHour' : None, 'winterPeakKW' : 0, 'winterTotalEnergy' : 37252.8585, 'winterPeakHour' : None, 'winterMinimumKW' : 1e15, 'winterMinimumHour' : None, 'shoulderPeakKW' : 0, 'shoulderTotalEnergy' : 38226.7564, 'shoulderPeakHour' : None, 'shoulderMinimumKW' : 1e15, 'shoulderMinimumHour' : None} scadaRaw = _readCsv(scadaFile)[1:] index = 0 loadMax = 0.0 voltA = 120.0 voltB = 120.0 voltC = 120.0 for row in scadaRaw: if float(row[4]) >= 114.0: voltA = float(row[4]) if float(row[5]) >= 114.0: voltB = float(row[5]) if float(row[6]) >= 114.0: voltC = float(row[6]) scada['timestamp'].append(datetime.datetime.strptime(row[0], "%m/%d/%Y %H:%M")) scada['phaseAW'].append(float(row[1])*voltA*7200.0*abs(float(row[7]))/120.0) scada['phaseBW'].append(float(row[2])*voltB*7200.0*abs(float(row[8]))/120.0) scada['phaseCW'].append(float(row[3])*voltC*7200.0*abs(float(row[9]))/120.0) if float(row[7]) >= 0.0: scada['phaseAVAR'].append(float(row[1])*voltA*7200.0*math.sqrt(1-(abs(float(row[7])))**2)/120.0) else: scada['phaseAVAR'].append(-1.0*float(row[1])*voltA*7200.0*math.sqrt(1-(abs(float(row[7])))**2)/120.0) if float(row[8]) >= 0.0: scada['phaseBVAR'].append(float(row[2])*voltB*7200.0*math.sqrt(1-(abs(float(row[8])))**2)/120.0) else: scada['phaseBVAR'].append(-1.0*float(row[2])*voltB*7200.0*math.sqrt(1-(abs(float(row[8])))**2)/120.0) if float(row[9]) >= 0.0: scada['phaseCVAR'].append(float(row[3])*voltC*7200.0*math.sqrt(1-(abs(float(row[9])))**2)/120.0) else: scada['phaseCVAR'].append(-1.0*float(row[3])*voltC*7200.0*math.sqrt(1-(abs(float(row[9])))**2)/120.0) scada['pfA'].append(float(row[7])) scada['pfB'].append(float(row[8])) scada['pfC'].append(float(row[9])) scada['VoltageA'].append(str(complex(voltA*7200.0/120.0, 0.0)).replace('(','').replace(')','')) scada['VoltageB'].append(str(complex(-voltB*7200.0*0.5/120.0, -voltB*7200.0*math.sqrt(3)*0.5/120.0)).replace('(','').replace(')','')) scada['VoltageC'].append(str(complex(-voltC*7200.0*0.5/120.0, voltC*7200.0*math.sqrt(3)*0.5/120.0)).replace('(','').replace(')','')) scada['totalVA'].append(complex(scada['phaseAW'][index] + scada['phaseBW'][index] + scada['phaseCW'][index], scada['phaseAVAR'][index] + scada['phaseBVAR'][index] + scada['phaseCVAR'][index])) if scada['timestamp'][index].year == 2013: if scada['timestamp'][index].month in [1, 2, 12]: if scadaInfo['winterPeakKW'] < scada['totalVA'][index].real/1000.0: scadaInfo['winterPeakKW'] = scada['totalVA'][index].real/1000.0 scadaInfo['winterDay'] = scada['timestamp'][index].strftime("%Y-%m-%d") scadaInfo['winterPeakHour'] = float(scada['timestamp'][index].hour) elif scada['timestamp'][index].month in [3, 4, 5, 9, 10, 11]: if scadaInfo['shoulderPeakKW'] < scada['totalVA'][index].real/1000.0: scadaInfo['shoulderPeakKW'] = scada['totalVA'][index].real/1000.0 scadaInfo['shoulderDay'] = scada['timestamp'][index].strftime("%Y-%m-%d") scadaInfo['shoulderPeakHour'] = float(scada['timestamp'][index].hour) elif scada['timestamp'][index].month in [6, 7 , 8]: if scadaInfo['summerPeakKW'] < scada['totalVA'][index].real/1000.0: scadaInfo['summerPeakKW'] = scada['totalVA'][index].real/1000.0 scadaInfo['summerDay'] = scada['timestamp'][index].strftime("%Y-%m-%d") scadaInfo['summerPeakHour'] = float(scada['timestamp'][index].hour) if loadMax <= abs(scada['totalVA'][index]): loadMax = abs(scada['totalVA'][index]) index += 1 for load in scada['totalVA']: scada['puLoad'].append(abs(load)/loadMax) for index in xrange(len(scada['timestamp'])): if scadaInfo['winterDay'] == scada['timestamp'][index].strftime("%Y-%m-%d") and scadaInfo['winterMinimumKW'] > scada['totalVA'][index].real/1000.0 and scada['totalVA'][index] != 0.0: scadaInfo['winterMinimumKW'] = scada['totalVA'][index].real/1000.0 scadaInfo['winterMinimumHour'] = float(scada['timestamp'][index].hour) if scadaInfo['summerDay'] == scada['timestamp'][index].strftime("%Y-%m-%d") and scadaInfo['summerMinimumKW'] > scada['totalVA'][index].real/1000.0 and scada['totalVA'][index] != 0.0: scadaInfo['summerMinimumKW'] = scada['totalVA'][index].real/1000.0 scadaInfo['summerMinimumHour'] = float(scada['timestamp'][index].hour) if scadaInfo['shoulderDay'] == scada['timestamp'][index].strftime("%Y-%m-%d") and scadaInfo['shoulderMinimumKW'] > scada['totalVA'][index].real/1000.0 and scada['totalVA'][index] != 0.0: scadaInfo['shoulderMinimumKW'] = scada['totalVA'][index].real/1000.0 scadaInfo['shoulderMinimumHour'] = float(scada['timestamp'][index].hour) for key in scadaInfo.keys(): print key, scadaInfo[key] loadShapeFile = open('./loadShapeScalar.player', 'w') for index in xrange(len(scada['timestamp'])): if scada['puLoad'][index] != 0.0: if scada['timestamp'][index].month in [1, 2, 12]: loadShapeFile.write('{:s} CST,{:0.6f}\n'.format(scada['timestamp'][index].strftime("%Y-%m-%d %H:%M:%S"), scada['puLoad'][index])) elif scada['timestamp'][index].month in [4, 5, 6, 7, 8, 9, 10]: loadShapeFile.write('{:s} CDT,{:0.6f}\n'.format(scada['timestamp'][index].strftime("%Y-%m-%d %H:%M:%S"), scada['puLoad'][index])) elif scada['timestamp'][index].month == 3: if scada['timestamp'][index].day < 10: loadShapeFile.write('{:s} CST,{:0.6f}\n'.format(scada['timestamp'][index].strftime("%Y-%m-%d %H:%M:%S"), scada['puLoad'][index])) elif scada['timestamp'][index].day > 10: loadShapeFile.write('{:s} CDT,{:0.6f}\n'.format(scada['timestamp'][index].strftime("%Y-%m-%d %H:%M:%S"), scada['puLoad'][index])) elif scada['timestamp'][index].day == 10: if scada['timestamp'][index].hour < 2: loadShapeFile.write('{:s} CST,{:0.6f}\n'.format(scada['timestamp'][index].strftime("%Y-%m-%d %H:%M:%S"), scada['puLoad'][index])) elif scada['timestamp'][index].hour > 2: loadShapeFile.write('{:s} CDT,{:0.6f}\n'.format(scada['timestamp'][index].strftime("%Y-%m-%d %H:%M:%S"), scada['puLoad'][index])) elif scada['timestamp'][index].month == 11: if scada['timestamp'][index].day < 3: loadShapeFile.write('{:s} CDT,{:0.6f}\n'.format(scada['timestamp'][index].strftime("%Y-%m-%d %H:%M:%S"), scada['puLoad'][index])) elif scada['timestamp'][index].day > 3: loadShapeFile.write('{:s} CST,{:0.6f}\n'.format(scada['timestamp'][index].strftime("%Y-%m-%d %H:%M:%S"), scada['puLoad'][index])) elif scada['timestamp'][index].day == 3: if index < 29380: loadShapeFile.write('{:s} CDT,{:0.6f}\n'.format(scada['timestamp'][index].strftime("%Y-%m-%d %H:%M:%S"), scada['puLoad'][index])) else: loadShapeFile.write('{:s} CST,{:0.6f}\n'.format(scada['timestamp'][index].strftime("%Y-%m-%d %H:%M:%S"), scada['puLoad'][index])) loadShapeFile.close() loadShapeFile = open('./phaseApf.player', 'w') for index in xrange(len(scada['timestamp'])): if scada['puLoad'][index] != 0.0: if scada['timestamp'][index].month in [1, 2, 12]: loadShapeFile.write('{:s} CST,{:0.6f}\n'.format(scada['timestamp'][index].strftime("%Y-%m-%d %H:%M:%S"), scada['pfA'][index])) elif scada['timestamp'][index].month in [4, 5, 6, 7, 8, 9, 10]: loadShapeFile.write('{:s} CDT,{:0.6f}\n'.format(scada['timestamp'][index].strftime("%Y-%m-%d %H:%M:%S"), scada['pfA'][index])) elif scada['timestamp'][index].month == 3: if scada['timestamp'][index].day < 10: loadShapeFile.write('{:s} CST,{:0.6f}\n'.format(scada['timestamp'][index].strftime("%Y-%m-%d %H:%M:%S"), scada['pfA'][index])) elif scada['timestamp'][index].day > 10: loadShapeFile.write('{:s} CDT,{:0.6f}\n'.format(scada['timestamp'][index].strftime("%Y-%m-%d %H:%M:%S"), scada['pfA'][index])) elif scada['timestamp'][index].day == 10: if scada['timestamp'][index].hour < 2: loadShapeFile.write('{:s} CST,{:0.6f}\n'.format(scada['timestamp'][index].strftime("%Y-%m-%d %H:%M:%S"), scada['pfA'][index])) elif scada['timestamp'][index].hour > 2: loadShapeFile.write('{:s} CDT,{:0.6f}\n'.format(scada['timestamp'][index].strftime("%Y-%m-%d %H:%M:%S"), scada['pfA'][index])) elif scada['timestamp'][index].month == 11: if scada['timestamp'][index].day < 3: loadShapeFile.write('{:s} CDT,{:0.6f}\n'.format(scada['timestamp'][index].strftime("%Y-%m-%d %H:%M:%S"), scada['pfA'][index])) elif scada['timestamp'][index].day > 3: loadShapeFile.write('{:s} CST,{:0.6f}\n'.format(scada['timestamp'][index].strftime("%Y-%m-%d %H:%M:%S"), scada['pfA'][index])) elif scada['timestamp'][index].day == 3: if index < 29380: loadShapeFile.write('{:s} CDT,{:0.6f}\n'.format(scada['timestamp'][index].strftime("%Y-%m-%d %H:%M:%S"), scada['pfA'][index])) else: loadShapeFile.write('{:s} CST,{:0.6f}\n'.format(scada['timestamp'][index].strftime("%Y-%m-%d %H:%M:%S"), scada['pfA'][index])) loadShapeFile.close() loadShapeFile = open('./phaseBpf.player', 'w') for index in xrange(len(scada['timestamp'])): if scada['puLoad'][index] != 0.0: if scada['timestamp'][index].month in [1, 2, 12]: loadShapeFile.write('{:s} CST,{:0.6f}\n'.format(scada['timestamp'][index].strftime("%Y-%m-%d %H:%M:%S"), scada['pfB'][index])) elif scada['timestamp'][index].month in [4, 5, 6, 7, 8, 9, 10]: loadShapeFile.write('{:s} CDT,{:0.6f}\n'.format(scada['timestamp'][index].strftime("%Y-%m-%d %H:%M:%S"), scada['pfB'][index])) elif scada['timestamp'][index].month == 3: if scada['timestamp'][index].day < 10: loadShapeFile.write('{:s} CST,{:0.6f}\n'.format(scada['timestamp'][index].strftime("%Y-%m-%d %H:%M:%S"), scada['pfB'][index])) elif scada['timestamp'][index].day > 10: loadShapeFile.write('{:s} CDT,{:0.6f}\n'.format(scada['timestamp'][index].strftime("%Y-%m-%d %H:%M:%S"), scada['pfB'][index])) elif scada['timestamp'][index].day == 10: if scada['timestamp'][index].hour < 2: loadShapeFile.write('{:s} CST,{:0.6f}\n'.format(scada['timestamp'][index].strftime("%Y-%m-%d %H:%M:%S"), scada['pfB'][index])) elif scada['timestamp'][index].hour > 2: loadShapeFile.write('{:s} CDT,{:0.6f}\n'.format(scada['timestamp'][index].strftime("%Y-%m-%d %H:%M:%S"), scada['pfB'][index])) elif scada['timestamp'][index].month == 11: if scada['timestamp'][index].day < 3: loadShapeFile.write('{:s} CDT,{:0.6f}\n'.format(scada['timestamp'][index].strftime("%Y-%m-%d %H:%M:%S"), scada['pfB'][index])) elif scada['timestamp'][index].day > 3: loadShapeFile.write('{:s} CST,{:0.6f}\n'.format(scada['timestamp'][index].strftime("%Y-%m-%d %H:%M:%S"), scada['pfB'][index])) elif scada['timestamp'][index].day == 3: if index < 29380: loadShapeFile.write('{:s} CDT,{:0.6f}\n'.format(scada['timestamp'][index].strftime("%Y-%m-%d %H:%M:%S"), scada['pfB'][index])) else: loadShapeFile.write('{:s} CST,{:0.6f}\n'.format(scada['timestamp'][index].strftime("%Y-%m-%d %H:%M:%S"), scada['pfB'][index])) loadShapeFile.close() loadShapeFile = open('./phaseCpf.player', 'w') for index in xrange(len(scada['timestamp'])): if scada['puLoad'][index] != 0.0: if scada['timestamp'][index].month in [1, 2, 12]: loadShapeFile.write('{:s} CST,{:0.6f}\n'.format(scada['timestamp'][index].strftime("%Y-%m-%d %H:%M:%S"), scada['pfC'][index])) elif scada['timestamp'][index].month in [4, 5, 6, 7, 8, 9, 10]: loadShapeFile.write('{:s} CDT,{:0.6f}\n'.format(scada['timestamp'][index].strftime("%Y-%m-%d %H:%M:%S"), scada['pfC'][index])) elif scada['timestamp'][index].month == 3: if scada['timestamp'][index].day < 10: loadShapeFile.write('{:s} CST,{:0.6f}\n'.format(scada['timestamp'][index].strftime("%Y-%m-%d %H:%M:%S"), scada['pfC'][index])) elif scada['timestamp'][index].day > 10: loadShapeFile.write('{:s} CDT,{:0.6f}\n'.format(scada['timestamp'][index].strftime("%Y-%m-%d %H:%M:%S"), scada['pfC'][index])) elif scada['timestamp'][index].day == 10: if scada['timestamp'][index].hour < 2: loadShapeFile.write('{:s} CST,{:0.6f}\n'.format(scada['timestamp'][index].strftime("%Y-%m-%d %H:%M:%S"), scada['pfC'][index])) elif scada['timestamp'][index].hour > 2: loadShapeFile.write('{:s} CDT,{:0.6f}\n'.format(scada['timestamp'][index].strftime("%Y-%m-%d %H:%M:%S"), scada['pfC'][index])) elif scada['timestamp'][index].month == 11: if scada['timestamp'][index].day < 3: loadShapeFile.write('{:s} CDT,{:0.6f}\n'.format(scada['timestamp'][index].strftime("%Y-%m-%d %H:%M:%S"), scada['pfC'][index])) elif scada['timestamp'][index].day > 3: loadShapeFile.write('{:s} CST,{:0.6f}\n'.format(scada['timestamp'][index].strftime("%Y-%m-%d %H:%M:%S"), scada['pfC'][index])) elif scada['timestamp'][index].day == 3: if index < 29380: loadShapeFile.write('{:s} CDT,{:0.6f}\n'.format(scada['timestamp'][index].strftime("%Y-%m-%d %H:%M:%S"), scada['pfC'][index])) else: loadShapeFile.write('{:s} CST,{:0.6f}\n'.format(scada['timestamp'][index].strftime("%Y-%m-%d %H:%M:%S"), scada['pfC'][index])) loadShapeFile.close() loadShapeFile = open('./phaseAVoltage.player', 'w') for index in xrange(len(scada['timestamp'])): if scada['puLoad'][index] != 0.0: if scada['timestamp'][index].month in [1, 2, 12]: loadShapeFile.write('{:s} CST,{:s}\n'.format(scada['timestamp'][index].strftime("%Y-%m-%d %H:%M:%S"), scada['VoltageA'][index])) elif scada['timestamp'][index].month in [4, 5, 6, 7, 8, 9, 10]: loadShapeFile.write('{:s} CDT,{:s}\n'.format(scada['timestamp'][index].strftime("%Y-%m-%d %H:%M:%S"), scada['VoltageA'][index])) elif scada['timestamp'][index].month == 3: if scada['timestamp'][index].day < 10: loadShapeFile.write('{:s} CST,{:s}\n'.format(scada['timestamp'][index].strftime("%Y-%m-%d %H:%M:%S"), scada['VoltageA'][index])) elif scada['timestamp'][index].day > 10: loadShapeFile.write('{:s} CDT,{:s}\n'.format(scada['timestamp'][index].strftime("%Y-%m-%d %H:%M:%S"), scada['VoltageA'][index])) elif scada['timestamp'][index].day == 10: if scada['timestamp'][index].hour < 2: loadShapeFile.write('{:s} CST,{:s}\n'.format(scada['timestamp'][index].strftime("%Y-%m-%d %H:%M:%S"), scada['VoltageA'][index])) elif scada['timestamp'][index].hour > 2: loadShapeFile.write('{:s} CDT,{:s}\n'.format(scada['timestamp'][index].strftime("%Y-%m-%d %H:%M:%S"), scada['VoltageA'][index])) elif scada['timestamp'][index].month == 11: if scada['timestamp'][index].day < 3: loadShapeFile.write('{:s} CDT,{:s}\n'.format(scada['timestamp'][index].strftime("%Y-%m-%d %H:%M:%S"), scada['VoltageA'][index])) elif scada['timestamp'][index].day > 3: loadShapeFile.write('{:s} CST,{:s}\n'.format(scada['timestamp'][index].strftime("%Y-%m-%d %H:%M:%S"), scada['VoltageA'][index])) elif scada['timestamp'][index].day == 3: if index < 29380: loadShapeFile.write('{:s} CDT,{:s}\n'.format(scada['timestamp'][index].strftime("%Y-%m-%d %H:%M:%S"), scada['VoltageA'][index])) else: loadShapeFile.write('{:s} CST,{:s}\n'.format(scada['timestamp'][index].strftime("%Y-%m-%d %H:%M:%S"), scada['VoltageA'][index])) loadShapeFile.close() loadShapeFile = open('./phaseBVoltage.player', 'w') for index in xrange(len(scada['timestamp'])): if scada['puLoad'][index] != 0.0: if scada['timestamp'][index].month in [1, 2, 12]: loadShapeFile.write('{:s} CST,{:s}\n'.format(scada['timestamp'][index].strftime("%Y-%m-%d %H:%M:%S"), scada['VoltageB'][index])) elif scada['timestamp'][index].month in [4, 5, 6, 7, 8, 9, 10]: loadShapeFile.write('{:s} CDT,{:s}\n'.format(scada['timestamp'][index].strftime("%Y-%m-%d %H:%M:%S"), scada['VoltageB'][index])) elif scada['timestamp'][index].month == 3: if scada['timestamp'][index].day < 10: loadShapeFile.write('{:s} CST,{:s}\n'.format(scada['timestamp'][index].strftime("%Y-%m-%d %H:%M:%S"), scada['VoltageB'][index])) elif scada['timestamp'][index].day > 10: loadShapeFile.write('{:s} CDT,{:s}\n'.format(scada['timestamp'][index].strftime("%Y-%m-%d %H:%M:%S"), scada['VoltageB'][index])) elif scada['timestamp'][index].day == 10: if scada['timestamp'][index].hour < 2: loadShapeFile.write('{:s} CST,{:s}\n'.format(scada['timestamp'][index].strftime("%Y-%m-%d %H:%M:%S"), scada['VoltageB'][index])) elif scada['timestamp'][index].hour > 2: loadShapeFile.write('{:s} CDT,{:s}\n'.format(scada['timestamp'][index].strftime("%Y-%m-%d %H:%M:%S"), scada['VoltageB'][index])) elif scada['timestamp'][index].month == 11: if scada['timestamp'][index].day < 3: loadShapeFile.write('{:s} CDT,{:s}\n'.format(scada['timestamp'][index].strftime("%Y-%m-%d %H:%M:%S"), scada['VoltageB'][index])) elif scada['timestamp'][index].day > 3: loadShapeFile.write('{:s} CST,{:s}\n'.format(scada['timestamp'][index].strftime("%Y-%m-%d %H:%M:%S"), scada['VoltageB'][index])) elif scada['timestamp'][index].day == 3: if index < 29380: loadShapeFile.write('{:s} CDT,{:s}\n'.format(scada['timestamp'][index].strftime("%Y-%m-%d %H:%M:%S"), scada['VoltageB'][index])) else: loadShapeFile.write('{:s} CST,{:s}\n'.format(scada['timestamp'][index].strftime("%Y-%m-%d %H:%M:%S"), scada['VoltageB'][index])) loadShapeFile.close() loadShapeFile = open('./phaseCVoltage.player', 'w') for index in xrange(len(scada['timestamp'])): if scada['puLoad'][index] != 0.0: if scada['timestamp'][index].month in [1, 2, 12]: loadShapeFile.write('{:s} CST,{:s}\n'.format(scada['timestamp'][index].strftime("%Y-%m-%d %H:%M:%S"), scada['VoltageC'][index])) elif scada['timestamp'][index].month in [4, 5, 6, 7, 8, 9, 10]: loadShapeFile.write('{:s} CDT,{:s}\n'.format(scada['timestamp'][index].strftime("%Y-%m-%d %H:%M:%S"), scada['VoltageC'][index])) elif scada['timestamp'][index].month == 3: if scada['timestamp'][index].day < 10: loadShapeFile.write('{:s} CST,{:s}\n'.format(scada['timestamp'][index].strftime("%Y-%m-%d %H:%M:%S"), scada['VoltageC'][index])) elif scada['timestamp'][index].day > 10: loadShapeFile.write('{:s} CDT,{:s}\n'.format(scada['timestamp'][index].strftime("%Y-%m-%d %H:%M:%S"), scada['VoltageC'][index])) elif scada['timestamp'][index].day == 10: if scada['timestamp'][index].hour < 2: loadShapeFile.write('{:s} CST,{:s}\n'.format(scada['timestamp'][index].strftime("%Y-%m-%d %H:%M:%S"), scada['VoltageC'][index])) elif scada['timestamp'][index].hour > 2: loadShapeFile.write('{:s} CDT,{:s}\n'.format(scada['timestamp'][index].strftime("%Y-%m-%d %H:%M:%S"), scada['VoltageC'][index])) elif scada['timestamp'][index].month == 11: if scada['timestamp'][index].day < 3: loadShapeFile.write('{:s} CDT,{:s}\n'.format(scada['timestamp'][index].strftime("%Y-%m-%d %H:%M:%S"), scada['VoltageC'][index])) elif scada['timestamp'][index].day > 3: loadShapeFile.write('{:s} CST,{:s}\n'.format(scada['timestamp'][index].strftime("%Y-%m-%d %H:%M:%S"), scada['VoltageC'][index])) elif scada['timestamp'][index].day == 3: if index < 29380: loadShapeFile.write('{:s} CDT,{:s}\n'.format(scada['timestamp'][index].strftime("%Y-%m-%d %H:%M:%S"), scada['VoltageC'][index])) else: loadShapeFile.write('{:s} CST,{:s}\n'.format(scada['timestamp'][index].strftime("%Y-%m-%d %H:%M:%S"), scada['VoltageC'][index])) loadShapeFile.close() configInfo= {'timezone' : 'CST+6CDT', 'startdate' : '2013-01-01 0:00:00', 'stopdate' : '2014-01-01 0:00:00', 'feeder_rating' : loadMax*1.15, 'nom_volt' : 7200, 'voltage_players' : [os.path.abspath('./phaseAVoltage.player').replace('\\', '/'), os.path.abspath('./phaseBVoltage.player').replace('\\', '/'), os.path.abspath('./phaseCVoltage.player').replace('\\', '/')], 'load_shape_scalar' : 1.0, 'r_p_pfA' : os.path.abspath('./phaseApf.player').replace('\\', '/'), 'r_p_pfB' : os.path.abspath('./phaseBpf.player').replace('\\', '/'), 'r_p_pfC' : os.path.abspath('./phaseCpf.player').replace('\\', '/'), 'load_shape_player_file' : os.path.abspath('./loadShapeScalar.player').replace('\\', '/')} working_directory = tempfile.mkdtemp() feederTree = feeder.parse('./faNewestConversionNoRecorder.glm') calibratedFeederTree, calibrationConfiguration = feederCalibrate.startCalibration(working_directory, feederTree, scadaInfo, 'MavaCapBank', configInfo) print(calibrationConfiguration['load_shape_scalar']) calibratedFile = open('./mavaCapBanksBaseCase.glm', 'w') glmstring = feeder.sortedWrite(calibratedFeederTree) calibratedFile.write(glmstring) calibratedFile.close()
def testFriendship(): tree = feeder.parse('sourceData/ACEC-Friendship.glm') monthData = _scadaCleanup('Friendship') runAnalysis(tree, monthData, rates)
def testColoma(): tree = feeder.parse('sourceData/ACEC-Coloma.glm') monthData = _scadaCleanup('Coloma') runAnalysis(tree, monthData, rates)
#!/usr/bin/env python 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 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:
#!/usr/bin/env python ''' take a PNNL reference feeder and clean up the object name:number convention.''' import sys sys.path.append('C:/Users/dwp0/Dropbox/OMF/omf') import feeder as tp from pprint import pprint import re # INPUT filename = 'main3.glm' # get the tree tree = tp.parse(filename) # modify the tree for leafId in tree: leaf = tree[leafId] if 'object' in leaf: # fix the config naming. for key in leaf: if key in [ 'configuration', 'spacing', 'conductor_A', 'conductor_B', 'conductor_C', 'conductor_N' ]: leaf[key] = leaf[key].replace(':', '_') # fix those without names. if 'name' not in leaf and 'recorder' != leaf['object']: leaf['name'] = leaf['object'].replace(':', '_') # last, fix the object. colon = leaf['object'].find(':')