Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download

All published worksheets from http://sagenb.org

Views: 168733
Image: ubuntu2004
import re file = open(DATA+'IEEE37node.glm') data = file.read() # Strip comments. data = re.sub(r'\/\/.*\n', '', data) # Also strip non-single whitespace because it's only for humans: data = data.replace('\n','').replace('\r','').replace('\t','') basicList = data.split('}') # And get rid of the first and last garbage objects. basicList = basicList[1:-1]
# Bring in a basic object and parse it. testob = basicList[3] print testob + '\n\n' splitPoint = testob.find('{') # Find all the properties props = testob[splitPoint+1:].split(';')[:-1] obj = dict(map(str.split, props)) # Add the type obj['type'] = testob[:splitPoint].split()[1] obj
object underground_line_conductor { name ug_lc_7230; outer_diameter 1.100000; conductor_gmr 0.012500; conductor_diameter 0.414000; conductor_resistance 0.769000; neutral_gmr 0.002080; neutral_resistance 14.872000; neutral_diameter 0.064000; neutral_strands 7.000000; shield_gmr 0.000000; shield_resistance 0.000000; {'name': 'ug_lc_7230', 'conductor_resistance': '0.769000', 'shield_resistance': '0.000000', 'neutral_gmr': '0.002080', 'outer_diameter': '1.100000', 'neutral_strands': '7.000000', 'neutral_resistance': '14.872000', 'neutral_diameter': '0.064000', 'type': 'underground_line_conductor', 'conductor_diameter': '0.414000', 'shield_gmr': '0.000000', 'conductor_gmr': '0.012500'}
# Turn all the objects into dicts. dictList = [] for x in basicList: splitPoint = x.find('{') # Find all the properties props = x[splitPoint+1:].split(';')[:-1] obj = dict(map(lambda x:x.split(None,1), props)) # Add the type obj['type'] = x[:splitPoint].split()[1] dictList.append(obj)
dictList
[{'solver_method': 'NR', 'type': 'powerflow'}, {'name': 'ug_lc_7210', 'conductor_resistance': '0.105000', 'shield_resistance': '0.000000', 'neutral_gmr': '0.003310', 'outer_diameter': '1.980000', 'neutral_strands': '20.000000', 'neutral_resistance': '5.903000', 'neutral_diameter': '0.102000', 'type': 'underground_line_conductor', 'conductor_diameter': '1.150000', 'shield_gmr': '0.000000', 'conductor_gmr': '0.036800'}, {'name': 'ug_lc_7220', 'conductor_resistance': '0.206000', 'shield_resistance': '0.000000', 'neutral_gmr': '0.002620', 'outer_diameter': '1.560000', 'neutral_strands': '16.000000', 'neutral_resistance': '9.375000', 'neutral_diameter': '0.081000', 'type': 'underground_line_conductor', 'conductor_diameter': '0.813000', 'shield_gmr': '0.000000', 'conductor_gmr': '0.026000'}, {'name': 'ug_lc_7230', 'conductor_resistance': '0.769000', 'shield_resistance': '0.000000', 'neutral_gmr': '0.002080', 'outer_diameter': '1.100000', 'neutral_strands': '7.000000', 'neutral_resistance': '14.872000', 'neutral_diameter': '0.064000', 'type': 'underground_line_conductor', 'conductor_diameter': '0.414000', 'shield_gmr': '0.000000', 'conductor_gmr': '0.012500'}, {'name': 'ug_lc_7240', 'conductor_resistance': '1.540000', 'shield_resistance': '0.000000', 'neutral_gmr': '0.002080', 'outer_diameter': '0.980000', 'neutral_strands': '6.000000', 'neutral_resistance': '14.872000', 'neutral_diameter': '0.064000', 'type': 'underground_line_conductor', 'conductor_diameter': '0.292000', 'shield_gmr': '0.000000', 'conductor_gmr': '0.008830'}, {'distance_BC': '0.500000', 'name': 'spacing_515', 'distance_CN': '0.000000', 'distance_AN': '0.000000', 'distance_AB': '0.500000', 'distance_BN': '0.000000', 'distance_AC': '1.000000', 'type': 'line_spacing'}, {'name': 'lc_7211', 'conductor_A': 'ug_lc_7210', 'spacing': 'spacing_515', 'type': 'line_configuration', 'conductor_C': 'ug_lc_7210', 'conductor_B': 'ug_lc_7210'}, {'name': 'lc_7221', 'conductor_A': 'ug_lc_7220', 'spacing': 'spacing_515', 'type': 'line_configuration', 'conductor_C': 'ug_lc_7220', 'conductor_B': 'ug_lc_7220'}, {'name': 'lc_7231', 'conductor_A': 'ug_lc_7230', 'spacing': 'spacing_515', 'type': 'line_configuration', 'conductor_C': 'ug_lc_7230', 'conductor_B': 'ug_lc_7230'}, {'name': 'lc_7241', 'conductor_A': 'ug_lc_7240', 'spacing': 'spacing_515', 'type': 'line_configuration', 'conductor_C': 'ug_lc_7240', 'conductor_B': 'ug_lc_7240'}, {'phases': '"ABC"', 'from': 'load701', 'name': 'node701-702', 'to': 'node702', 'length': '960', 'configuration': 'lc_7221', 'type': 'underground_line'}, {'phases': '"ABC"', 'from': 'node702', 'name': 'node702-705', 'to': 'node705', 'length': '400', 'configuration': 'lc_7241', 'type': 'underground_line'}, {'phases': '"ABC"', 'from': 'node702', 'name': 'node702-713', 'to': 'load713', 'length': '360', 'configuration': 'lc_7231', 'type': 'underground_line'}, {'phases': '"ABC"', 'from': 'node702', 'name': 'node702-703', 'to': 'node703', 'length': '1320', 'configuration': 'lc_7221', 'type': 'underground_line'}, {'phases': '"ABC"', 'from': 'node703', 'name': 'node703-727', 'to': 'load727', 'length': '240', 'configuration': 'lc_7241', 'type': 'underground_line'}, {'phases': '"ABC"', 'from': 'node703', 'name': 'node703-730', 'to': 'load730', 'length': '600', 'configuration': 'lc_7231', 'type': 'underground_line'}, {'phases': '"ABC"', 'from': 'node704', 'name': 'node704-714', 'to': 'load714', 'length': '80', 'configuration': 'lc_7241', 'type': 'underground_line'}, {'phases': '"ABC"', 'from': 'node704', 'name': 'node704-720', 'to': 'load720', 'length': '800', 'configuration': 'lc_7231', 'type': 'underground_line'}, {'phases': '"ABC"', 'from': 'node705', 'name': 'node705-742', 'to': 'load742', 'length': '320', 'configuration': 'lc_7241', 'type': 'underground_line'}, {'phases': '"ABC"', 'from': 'node705', 'name': 'node705-712', 'to': 'load712', 'length': '240', 'configuration': 'lc_7241', 'type': 'underground_line'}, {'phases': '"ABC"', 'from': 'node706', 'name': 'node706-725', 'to': 'load725', 'length': '280', 'configuration': 'lc_7241', 'type': 'underground_line'}, {'phases': '"ABC"', 'from': 'node707', 'name': 'node707-724', 'to': 'load724', 'length': '760', 'configuration': 'lc_7241', 'type': 'underground_line'}, {'phases': '"ABC"', 'from': 'node707', 'name': 'node707-722', 'to': 'load722', 'length': '120', 'configuration': 'lc_7241', 'type': 'underground_line'}, {'phases': '"ABC"', 'from': 'node708', 'name': 'node708-733', 'to': 'load733', 'length': '320', 'configuration': 'lc_7231', 'type': 'underground_line'}, {'phases': '"ABC"', 'from': 'node708', 'name': 'node708-732', 'to': 'load732', 'length': '320', 'configuration': 'lc_7241', 'type': 'underground_line'}, {'phases': '"ABC"', 'from': 'node709', 'name': 'node709-731', 'to': 'load731', 'length': '600', 'configuration': 'lc_7231', 'type': 'underground_line'}, {'phases': '"ABC"', 'from': 'node709', 'name': 'node709-708', 'to': 'node708', 'length': '320', 'configuration': 'lc_7231', 'type': 'underground_line'}, {'phases': '"ABC"', 'from': 'node710', 'name': 'node710-735', 'to': 'load735', 'length': '200', 'configuration': 'lc_7241', 'type': 'underground_line'}, {'phases': '"ABC"', 'from': 'node710', 'name': 'node710-736', 'to': 'load736', 'length': '1280', 'configuration': 'lc_7241', 'type': 'underground_line'}, {'phases': '"ABC"', 'from': 'node711', 'name': 'node711-741', 'to': 'load741', 'length': '400', 'configuration': 'lc_7231', 'type': 'underground_line'}, {'phases': '"ABC"', 'from': 'node711', 'name': 'node711-740', 'to': 'load740', 'length': '200', 'configuration': 'lc_7241', 'type': 'underground_line'}, {'phases': '"ABC"', 'from': 'load713', 'name': 'node713-704', 'to': 'node704', 'length': '520', 'configuration': 'lc_7231', 'type': 'underground_line'}, {'phases': '"ABC"', 'from': 'load714', 'name': 'node714-718', 'to': 'load718', 'length': '520', 'configuration': 'lc_7241', 'type': 'underground_line'}, {'phases': '"ABC"', 'from': 'load720', 'name': 'node720-707', 'to': 'node707', 'length': '920', 'configuration': 'lc_7241', 'type': 'underground_line'}, {'phases': '"ABC"', 'from': 'load720', 'name': 'node720-706', 'to': 'node706', 'length': '600', 'configuration': 'lc_7231', 'type': 'underground_line'}, {'phases': '"ABC"', 'from': 'load727', 'name': 'node727-744', 'to': 'load744', 'length': '280', 'configuration': 'lc_7231', 'type': 'underground_line'}, {'phases': '"ABC"', 'from': 'load730', 'name': 'node730-709', 'to': 'node709', 'length': '200', 'configuration': 'lc_7231', 'type': 'underground_line'}, {'phases': '"ABC"', 'from': 'load733', 'name': 'node733-734', 'to': 'load734', 'length': '560', 'configuration': 'lc_7231', 'type': 'underground_line'}, {'phases': '"ABC"', 'from': 'load734', 'name': 'node734-737', 'to': 'load737', 'length': '640', 'configuration': 'lc_7231', 'type': 'underground_line'}, {'phases': '"ABC"', 'from': 'load734', 'name': 'node734-710', 'to': 'node710', 'length': '520', 'configuration': 'lc_7241', 'type': 'underground_line'}, {'phases': '"ABC"', 'from': 'load737', 'name': 'node737-738', 'to': 'load738', 'length': '400', 'configuration': 'lc_7231', 'type': 'underground_line'}, {'phases': '"ABC"', 'from': 'load738', 'name': 'node738-711', 'to': 'node711', 'length': '400', 'configuration': 'lc_7231', 'type': 'underground_line'}, {'phases': '"ABC"', 'from': 'load744', 'name': 'node744-728', 'to': 'load728', 'length': '200', 'configuration': 'lc_7241', 'type': 'underground_line'}, {'phases': '"ABC"', 'from': 'node781', 'name': 'node781-701', 'to': 'load701', 'length': '1850', 'configuration': 'lc_7211', 'type': 'underground_line'}, {'phases': '"ABC"', 'from': 'load744', 'name': 'node744-729', 'to': 'load729', 'length': '200', 'configuration': 'lc_7241', 'type': 'underground_line'}, {'phases': '"ABC"', 'name': 'node781', 'bustype': 'SWING', 'voltage_B': '-2504.88-1446.19314229j', 'voltage_C': '-44.88+2814.65184433j', 'voltage_A': '2504.88-1446.19314229j', 'nominal_voltage': '4800', 'type': 'node'}, {'phases': '"ABC"', 'name': 'node702', 'voltage_B': '-2400.000000 -1385.640646j', 'voltage_C': '0.000000+2771.281292j', 'voltage_A': '2400.000000 -1385.640646j', 'nominal_voltage': '4800', 'type': 'node'}, {'phases': '"ABC"', 'name': 'node703', 'voltage_B': '-2400.000000 -1385.640646j', 'voltage_C': '0.000000+2771.281292j', 'voltage_A': '2400.000000 -1385.640646j', 'nominal_voltage': '4800', 'type': 'node'}, {'phases': '"ABC"', 'name': 'node704', 'voltage_B': '-2400.000000 -1385.640646j', 'voltage_C': '0.000000+2771.281292j', 'voltage_A': '2400.000000 -1385.640646j', 'nominal_voltage': '4800', 'type': 'node'}, {'phases': '"ABC"', 'name': 'node705', 'voltage_B': '-2400.000000 -1385.640646j', 'voltage_C': '0.000000+2771.281292j', 'voltage_A': '2400.000000 -1385.640646j', 'nominal_voltage': '4800', 'type': 'node'}, {'phases': '"ABC"', 'name': 'node706', 'voltage_B': '-2400.000000 -1385.640646j', 'voltage_C': '0.000000+2771.281292j', 'voltage_A': '2400.000000 -1385.640646j', 'nominal_voltage': '4800', 'type': 'node'}, {'phases': '"ABC"', 'name': 'node707', 'voltage_B': '-2400.000000 -1385.640646j', 'voltage_C': '0.000000+2771.281292j', 'voltage_A': '2400.000000 -1385.640646j', 'nominal_voltage': '4800', 'type': 'node'}, {'phases': '"ABC"', 'name': 'node708', 'voltage_B': '-2400.000000 -1385.640646j', 'voltage_C': '0.000000+2771.281292j', 'voltage_A': '2400.000000 -1385.640646j', 'nominal_voltage': '4800', 'type': 'node'}, {'phases': '"ABC"', 'name': 'node709', 'voltage_B': '-2400.000000 -1385.640646j', 'voltage_C': '0.000000+2771.281292j', 'voltage_A': '2400.000000 -1385.640646j', 'nominal_voltage': '4800', 'type': 'node'}, {'phases': '"ABC"', 'name': 'node710', 'voltage_B': '-2400.000000 -1385.640646j', 'voltage_C': '0.000000+2771.281292j', 'voltage_A': '2400.000000 -1385.640646j', 'nominal_voltage': '4800', 'type': 'node'}, {'phases': '"ABC"', 'name': 'node711', 'voltage_B': '-2400.000000 -1385.640646j', 'voltage_C': '0.000000+2771.281292j', 'voltage_A': '2400.000000 -1385.640646j', 'nominal_voltage': '4800', 'type': 'node'}, {'phases': '"ABCD"', 'name': 'load701', 'voltage_B': '-2400.000000 -1385.640646j', 'voltage_C': '0.000000+2771.281292j', 'voltage_A': '2400.000000 -1385.640646j', 'constant_power_C': '350000.000000+175000.000000j', 'constant_power_B': '140000.000000+70000.000000j', 'constant_power_A': '140000.000000+70000.000000j', 'nominal_voltage': '4800', 'type': 'load'}, {'phases': '"ABCD"', 'name': 'load712', 'voltage_B': '-2400.000000 -1385.640646j', 'voltage_C': '0.000000+2771.281292j', 'voltage_A': '2400.000000 -1385.640646j', 'constant_power_C': '85000.000000+40000.000000j', 'nominal_voltage': '4800', 'type': 'load'}, {'phases': '"ABCD"', 'name': 'load713', 'voltage_B': '-2400.000000 -1385.640646j', 'voltage_C': '0.000000+2771.281292j', 'voltage_A': '2400.000000 -1385.640646j', 'constant_power_C': '85000.000000+40000.000000j', 'nominal_voltage': '4800', 'type': 'load'}, {'constant_current_A': '3.541667 -1.666667j', 'phases': '"ABCD"', 'name': 'load714', 'voltage_B': '-2400.000000 -1385.640646j', 'voltage_C': '0.000000+2771.281292j', 'voltage_A': '2400.000000 -1385.640646j', 'constant_current_B': '-3.991720 -2.747194j', 'nominal_voltage': '4800', 'type': 'load'}, {'phases': '"ABCD"', 'name': 'load718', 'voltage_B': '-2400.000000 -1385.640646j', 'voltage_C': '0.000000+2771.281292j', 'voltage_A': '2400.000000 -1385.640646j', 'nominal_voltage': '4800', 'type': 'load', 'constant_impedance_A': '221.915014+104.430595j'}, {'phases': '"ABCD"', 'name': 'load720', 'voltage_B': '-2400.000000 -1385.640646j', 'voltage_C': '0.000000+2771.281292j', 'voltage_A': '2400.000000 -1385.640646j', 'constant_power_C': '85000.000000+40000.000000j', 'nominal_voltage': '4800', 'type': 'load'}, {'phases': '"ABCD"', 'name': 'load722', 'voltage_B': '-2400.000000 -1385.640646j', 'voltage_C': '0.000000+2771.281292j', 'constant_current_C': '-0.383280+4.830528j', 'voltage_A': '2400.000000 -1385.640646j', 'constant_current_B': '-27.212870 -17.967408j', 'nominal_voltage': '4800', 'type': 'load'}, {'phases': '"ABCD"', 'name': 'load724', 'constant_impedance_B': '438.857143+219.428571j', 'voltage_B': '-2400.000000 -1385.640646j', 'voltage_C': '0.000000+2771.281292j', 'voltage_A': '2400.000000 -1385.640646j', 'nominal_voltage': '4800', 'type': 'load'}, {'phases': '"ABCD"', 'name': 'load725', 'voltage_B': '-2400.000000 -1385.640646j', 'voltage_C': '0.000000+2771.281292j', 'voltage_A': '2400.000000 -1385.640646j', 'nominal_voltage': '4800', 'constant_power_B': '42000.000000+21000.000000j', 'type': 'load'}, {'phases': '"ABCD"', 'name': 'load727', 'voltage_B': '-2400.000000 -1385.640646j', 'voltage_C': '0.000000+2771.281292j', 'voltage_A': '2400.000000 -1385.640646j', 'constant_power_C': '42000.000000+21000.000000j', 'nominal_voltage': '4800', 'type': 'load'}, {'phases': '"ABCD"', 'name': 'load728', 'voltage_B': '-2400.000000 -1385.640646j', 'voltage_C': '0.000000+2771.281292j', 'voltage_A': '2400.000000 -1385.640646j', 'constant_power_C': '42000.000000+21000.000000j', 'constant_power_B': '42000.000000+21000.000000j', 'constant_power_A': '42000.000000+21000.000000j', 'nominal_voltage': '4800', 'type': 'load'}, {'constant_current_A': '8.750000 -4.375000j', 'phases': '"ABCD"', 'name': 'load729', 'voltage_B': '-2400.000000 -1385.640646j', 'voltage_C': '0.000000+2771.281292j', 'voltage_A': '2400.000000 -1385.640646j', 'nominal_voltage': '4800', 'type': 'load'}, {'phases': '"ABCD"', 'name': 'load730', 'constant_impedance_C': '221.915014+104.430595j', 'voltage_B': '-2400.000000 -1385.640646j', 'voltage_C': '0.000000+2771.281292j', 'voltage_A': '2400.000000 -1385.640646j', 'nominal_voltage': '4800', 'type': 'load'}, {'phases': '"ABCD"', 'name': 'load731', 'constant_impedance_B': '221.915014+104.430595j', 'voltage_B': '-2400.000000 -1385.640646j', 'voltage_C': '0.000000+2771.281292j', 'voltage_A': '2400.000000 -1385.640646j', 'nominal_voltage': '4800', 'type': 'load'}, {'phases': '"ABCD"', 'name': 'load732', 'voltage_B': '-2400.000000 -1385.640646j', 'voltage_C': '0.000000+2771.281292j', 'voltage_A': '2400.000000 -1385.640646j', 'constant_power_C': '42000.000000+21000.000000j', 'nominal_voltage': '4800', 'type': 'load'}, {'constant_current_A': '17.708333 -8.333333j', 'phases': '"ABCD"', 'name': 'load733', 'voltage_B': '-2400.000000 -1385.640646j', 'voltage_C': '0.000000+2771.281292j', 'voltage_A': '2400.000000 -1385.640646j', 'nominal_voltage': '4800', 'type': 'load'}, {'phases': '"ABCD"', 'name': 'load734', 'voltage_B': '-2400.000000 -1385.640646j', 'voltage_C': '0.000000+2771.281292j', 'voltage_A': '2400.000000 -1385.640646j', 'constant_power_C': '42000.000000+21000.000000j', 'nominal_voltage': '4800', 'type': 'load'}, {'phases': '"ABCD"', 'name': 'load735', 'voltage_B': '-2400.000000 -1385.640646j', 'voltage_C': '0.000000+2771.281292j', 'voltage_A': '2400.000000 -1385.640646j', 'constant_power_C': '85000.000000+40000.000000j', 'nominal_voltage': '4800', 'type': 'load'}, {'phases': '"ABCD"', 'name': 'load736', 'constant_impedance_B': '438.857143+219.428571j', 'voltage_B': '-2400.000000 -1385.640646j', 'voltage_C': '0.000000+2771.281292j', 'voltage_A': '2400.000000 -1385.640646j', 'nominal_voltage': '4800', 'type': 'load'}, {'constant_current_A': '29.166667 -14.583333j', 'phases': '"ABCD"', 'name': 'load737', 'voltage_B': '-2400.000000 -1385.640646j', 'voltage_C': '0.000000+2771.281292j', 'voltage_A': '2400.000000 -1385.640646j', 'nominal_voltage': '4800', 'type': 'load'}, {'phases': '"ABCD"', 'name': 'load738', 'voltage_B': '-2400.000000 -1385.640646j', 'voltage_C': '0.000000+2771.281292j', 'voltage_A': '2400.000000 -1385.640646j', 'nominal_voltage': '4800', 'constant_power_A': '126000.000000+62000.000000j', 'type': 'load'}, {'phases': '"ABCD"', 'name': 'load740', 'voltage_B': '-2400.000000 -1385.640646j', 'voltage_C': '0.000000+2771.281292j', 'voltage_A': '2400.000000 -1385.640646j', 'constant_power_C': '85000.000000+40000.000000j', 'nominal_voltage': '4800', 'type': 'load'}, {'phases': '"ABCD"', 'name': 'load741', 'voltage_B': '-2400.000000 -1385.640646j', 'voltage_C': '0.000000+2771.281292j', 'constant_current_C': '-0.586139+9.765222j', 'voltage_A': '2400.000000 -1385.640646j', 'nominal_voltage': '4800', 'type': 'load'}, {'phases': '"ABCD"', 'name': 'load742', 'constant_impedance_B': '221.915014+104.430595j', 'voltage_B': '-2400.000000 -1385.640646j', 'voltage_C': '0.000000+2771.281292j', 'voltage_A': '2400.000000 -1385.640646j', 'nominal_voltage': '4800', 'type': 'load', 'constant_impedance_A': '2304.000000+1152.000000j'}, {'phases': '"ABCD"', 'name': 'load744', 'voltage_B': '-2400.000000 -1385.640646j', 'voltage_C': '0.000000+2771.281292j', 'voltage_A': '2400.000000 -1385.640646j', 'nominal_voltage': '4800', 'constant_power_A': '42000.000000+21000.000000j', 'type': 'load'}, {'phases': '"ABCD"', 'name': 'load745', 'parent': 'node775', 'voltage_B': '-240.000000 -138.564065j', 'voltage_C': '-0.000000+277.128129j', 'voltage_A': '240.000000 -138.564065j', 'nominal_voltage': '480', 'constant_power_A': '4200+2100j', 'type': 'load'}, {'power_rating': '500', 'primary_voltage': '4800', 'install_type': 'PADMOUNT', 'secondary_voltage': '480', 'connect_type': '2', 'resistance': '0.09', 'reactance': '1.81', 'type': 'transformer_configuration', 'name': 'trans_conf_400'}, {'phases': '"ABC"', 'from': 'node709', 'name': '"xform709-775"', 'to': 'node775', 'configuration': 'trans_conf_400', 'type': 'transformer'}, {'phases': '"ABC"', 'name': 'node775', 'voltage_B': '-240.000000 -138.564065j', 'voltage_C': '-0.000000+277.128129j', 'voltage_A': '240.000000 -138.564065j', 'nominal_voltage': '480', 'type': 'node'}]
y = 0 for x in dictList: if x['type']=='node': y+=1 print 'This .glm has ' + str(y) + ' nodes.'
This .glm has 12 nodes.
# And let's make it a graph! G = Graph() for x in dictList: if x.has_key('from') and x.has_key('to'): G.add_edge(x['to'],x['from']) plot(G)