def test_schedules(): l1 = glm.load("./tests/data/appliance_schedules.glm") l2 = glm.load("./tests/data/schedule1.glm") assert l1 == json.load(open("./tests/data/appliance_schedules.json")) assert l2 == json.load(open("./tests/data/schedule1.json"))
def test_IEEE_13_glm(): l1 = glm.load("./tests/data/IEEE-13.glm") l2 = glm.load("./tests/data/IEEE_13_Node_Test_Feeder.glm") l3 = glm.load("./tests/data/IEEE_13_Node_With_Houses.glm") assert l1 == json.load(open("./tests/data/IEEE-13.json")) assert l2 == json.load(open("./tests/data/IEEE_13_Node_Test_Feeder.json")) assert l3 == json.load(open("./tests/data/IEEE_13_Node_With_Houses.json"))
def test_4node(): l1 = glm.load("./tests/data/4node.glm") l2 = glm.load("./tests/data/powerflow_IEEE_4node.glm") assert l1 == json.load(open("./tests/data/4node.json")) assert l2 == json.load(open("./tests/data/powerflow_IEEE_4node.json")) with open("./tests/data/4node.glm") as f: l1 = glm.load(f) assert l1 == json.load(open("./tests/data/4node.json")) with open("./tests/data/powerflow_IEEE_4node.glm") as f: l2 = glm.load(f) assert l2 == json.load(open("./tests/data/powerflow_IEEE_4node.json"))
def create(networkFile, excludedCapacitors): global EXCLUDED EXCLUDED = excludedCapacitors network = glm.load(networkFile) capacitors = extract_all_capacitors_from_network(network) allOptionsForWorkingCapacitors = generate_all_possible_options_for_capacity( capacitors) create_network_for_each_capacitor_setup(network, allOptionsForWorkingCapacitors, capacitors)
def makeMapNodeNameNominalVoltage(): totalMap = {} network = glm.load(inputFile) for obj in network["objects"]: if (obj["name"] == "node" or obj["name"] == "triplex_node"): totalMap[obj["attributes"] ["name"]] = obj["attributes"]["nominal_voltage"] return totalMap
def glm_load(fn): ''' Def: This function parses through a given glm file and returns the objects & modules of the passed glm file Input: name of of the glm file (string) Output: objects, modules (tuple of lists) Note: objs & mods are lists of DICTS! objs: {'name': ..., 'attributes':..., 'children':...} mods: {'name': ..., 'attributes':...} ''' with open(fn, 'r') as f: G = glm.load(f) #del G['includes'] #del G['schedules'] return G
def addCapacitor(file, name, parent, phase, cap_nominal_voltage, A, B, C): network = glm.load(file) lstOfObj = network['objects'] dictMap = {} dictMap["name"] = "capacitor" dictAttr = {} dictAttr["name"] = name dictAttr["parent"] = parent dictAttr["phases"] = phase dictAttr["phases_connected"] = phase dictAttr["cap_nominal_voltage"] = cap_nominal_voltage dictAttr["capacitor_B"] = B # 'capacitor_B': '300000', dictAttr["capacitor_C"] = C dictAttr["capacitor_A"] = A dictAttr["switchA"] = "CLOSED" dictAttr["switchB"] = "CLOSED" dictAttr["switchC"] = "CLOSED" dictMap["attributes"] = dictAttr dictMap["children"] = [] lstOfObj.append(dictMap) glm.dump(network, file)
def test_taxonomy_feeder_R1_12_47_1(): l1 = glm.load("./tests/data/taxonomy_feeder_R1-12.47-1.glm") assert l1 == json.load( open("./tests/data/taxonomy_feeder_R1-12.47-1.json"))
def test_nested(): len(glm.load("./tests/data/configuration.glm")) == 7
def addCapacitor(file, name, parent, phase, cap_nominal_voltage, A, B, C): network = glm.load(file) lstOfObj = network['objects'] dictMap = {} dictMap["name"] = "capacitor" dictAttr = {} dictAttr["name"] = name dictAttr["parent"] = parent dictAttr["phases"] = phase dictAttr["phases_connected"] = phase dictAttr["cap_nominal_voltage"] = cap_nominal_voltage dictAttr["capacitor_B"] = B # 'capacitor_B': '300000', dictAttr["capacitor_C"] = C dictAttr["capacitor_A"] = A dictAttr["switchA"] = "CLOSED" dictAttr["switchB"] = "CLOSED" dictAttr["switchC"] = "CLOSED" dictMap["attributes"] = dictAttr dictMap["children"] = [] lstOfObj.append(dictMap) glm.dump(network, file) # replaceClock(file) # def replaceClock(pathFile): # entries = os.scandir('analytic_data/folder1/') # counter = 0 # lines=[] # for entry in entries: # if(entry.name == "myTest.glm"): # with open(entry) as f: # lines = f.readlines() # lines[1]= " timestamp '2000-01-01 0:00:00';" # lines[2]= " stoptime '2000-01-01 0:02:00';" # # f.close() # with open(entry, "w") as f: # f.writelines(lines) # f.close() # # with open(entry, 'r+') as f: # # content = f.read() # # f.seek(0, 0) # # line = "// European LV Test Feeder \n" # # f.write(line + '\n' + content) # # a = os.getcwd() # os.chdir("./analytic_data/folder1/") # os.system("gridlabd myTest.glm") # os.chdir(a) # # checkAllOptions("output_voltage_1.csv",1) # bestConfig(1) # if __name__== "__main__": # network_capacitors_placement.addCapacitorText("./analytic_data/folder1/myTest.glm", "Test", "Bus32","ABC",240.177712,1000,1000,1000 ) # # network_capacitors_placement.addCapacitor("./analytic_data/folder1/gridLAB_D_Model.glm", "Test", "Bus32","ABC",240.177712,1000,1000,1000 ) # # # # a = os.getcwd() # os.chdir("./analytic_data/folder1/") # os.system("gridlabd myTest.glm") # os.chdir(a) # checkAllOptions("output_voltage_1.csv",1) # bestConfig(1)