Skip to content

Commit

Permalink
Merge pull request #320 from NREL/kd/consolidation
Browse files Browse the repository at this point in the history
  • Loading branch information
kdheepak authored Apr 29, 2020
2 parents 0833c56 + d5c96ac commit 9d9c53a
Show file tree
Hide file tree
Showing 35 changed files with 4,550 additions and 429 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
ditto/readers/synergi/mdbtools.tar.gz
ditto/readers/synergi/mdbtools

# Editor generated files #
##########################
Expand Down Expand Up @@ -142,4 +144,3 @@ venv.bak/


# End of https://www.gitignore.io/api/python,jupyternotebook

7 changes: 4 additions & 3 deletions ditto/default_values/opendss_default_values.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"X1":0.1206,
"R0":0.1784,
"X0":0.4047,
"C1":3.4e-9,
"C0":1.6e-9,
"C1":3.4,
"C0":1.6,
"length":1,
"rmatrix":[
[
Expand Down Expand Up @@ -63,7 +63,8 @@
},
"Wire":{
"ampacity":400.0,
"emergency_ampacity":600.0
"emergency_ampacity":600.0,
"insulation_thickness":0
},
"Capacitor":{
"connection_type":"Y",
Expand Down
2 changes: 1 addition & 1 deletion ditto/models/line.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class Line(DiTToHasTraits):
default_value=None,
)
line_type = Unicode(
help="""Whether the line is overhead or underground""", default_value="overhead"
help="""Whether the line is overhead or underground""", default_value=None
)
length = Float(
help="""This parameter is the length of the Line.""", default_value=0
Expand Down
79 changes: 79 additions & 0 deletions ditto/reader_validation/create_compare.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
from ditto.store import Store
from ditto.readers.synergi.read import Reader as Synergi_Reader
from ditto.readers.opendss.read import Reader as OpenDSS_Reader
from ditto.readers.cyme.read import Reader as Cyme_Reader
from ditto.readers.gridlabd.read import Reader as Gridlabd_Reader
from ditto.writers.opendss.write import Writer as OpenDSS_Writer
import opendssdirect as dss
import os, shutil
import matplotlib.pyplot as plt
import pandas as pd
from collections import defaultdict


def create_output_dir(tests_dir):
"""Reading the input from every reader for each test case and creating the Opendss output."""
# Creating output directory
current_dir = os.path.realpath(os.path.dirname(__file__))
validation_dir = os.path.join(current_dir, "validation_outputs")
if os.path.exists(validation_dir):
shutil.rmtree(validation_dir)
for each in os.listdir(tests_dir):
if each == "cim" or each == "demo":
continue
for dirname in os.listdir(os.path.join(tests_dir, each)):
if dirname == "storage_test":
continue
output_dir = os.path.join(validation_dir, dirname, each + "_output")
test_path = os.path.join(tests_dir, each, dirname)
m = Store()
if each == "opendss":
r1 = OpenDSS_Reader(master_file=os.path.join(test_path, "master.dss"))
elif each == "synergi":
if dirname == "ieee_4node":
r1 = Synergi_Reader(
input_file=os.path.join(test_path, "network.mdb")
)
elif each == "cyme":
r1 = Cyme_Reader(data_folder_path=os.path.join(test_path))
elif each == "gridlabd":
r1 = Gridlabd_Reader(input_file=os.path.join(test_path, "node.glm"))
r1.parse(m)
w1 = OpenDSS_Writer(output_path=output_dir)
w1.write(m, separate_feeders=True)
return validation_dir


def create_dict(output_dir):
"""Do the fault study for each reader and create a dictonary which contains the sequence impedances for each node.
These values are used for comparison of fault study of readers"""
comp_values = defaultdict()
for case_dir in os.listdir(output_dir):
comp_values[case_dir] = defaultdict()
for dir_name in os.listdir(os.path.join(output_dir, case_dir)):
comp_values[case_dir][dir_name] = {}
with open(
os.path.join(output_dir, case_dir, dir_name, "Master.dss"), "r"
) as rfile:
filedata = rfile.read()
filedata = filedata.replace("Solve", "Solve mode=faultstudy")
with open(
os.path.join(output_dir, case_dir, dir_name, "Faultstudy_Master.dss"),
"w",
) as file:
file.write(filedata)

dss.run_command(
"Redirect {}".format(
os.path.join(
output_dir, case_dir, dir_name, "Faultstudy_Master.dss"
)
)
)
for i in dss.Circuit.AllBusNames():
dss.Circuit.SetActiveBus(i)
comp_values[case_dir][dir_name][dss.Bus.Name()] = (
dss.Bus.Zsc0() + dss.Bus.Zsc1()
)

return comp_values
24 changes: 24 additions & 0 deletions ditto/reader_validation/create_excel.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import pandas as pd
import os

# This function needs more improving with regards to formatting the excel output

# Writing the output to excel


def write_to_excel(comp_values):
current_dir = os.path.realpath(os.path.dirname(__file__))
df = pd.DataFrame(comp_values)
with pd.ExcelWriter(os.path.join(current_dir, "output" + ".xlsx")) as writer:
for col in df:
df1 = pd.concat([df[col], df[col].apply(pd.Series)], axis=1).drop(
[col], axis=1
)
df1.to_excel(writer, sheet_name=col)
worksheet = writer.sheets[col]
worksheet.set_column(0, 19, 16)


# Tests for running the plots independently
# if __name__ == "__main__":
# write_to_excel({'ieee_4node': {'cyme_output': {'1': [1.796043190045738, 5.388117303585387, 0.10784685850195197, 0.5904760366014294], '2': [2.0202605985010313, 6.518985500570162, 0.22820004614399358, 0.8158267453203445], '3': [0.2536631703405771, 0.8984713888134145, 0.06581202655980385, 0.24831713333607722], '4': [0.5340964354229437, 2.3119539172019614, 0.23396047634518685, 0.46239954705589636]}, 'demo_output': {}, 'gridlabd_output': {'sourcebus': [1.7960358301233543, 5.388107490370064, 1.6037668205527515, 6.415067282211007], 'node2': [11.615625751028661, 11.520529778987775, 9.073598525409436, 5.8609512435066655], 'node3': [1.2918305507375225, 1.2769209930818217, 1.0089298663668416, 0.6470699623879508], 'load4': [0.8640026377752124, 0.41845221416471984, 0.8640056993976751, 0.4184497947877163], 'node1': [11.95788550650638, 12.207304856874984, 9.189536257036401, 6.043847565567804]}, 'opendss_output': {'sourcebus': [0.0002463564270509644, 0.0007390394604267333, 0.00018858267905109123, 0.0007542723977164494], 'n2': [0.29564583680274237, 0.7167450994489304, 0.11638654713225582, 0.2358768460293939], 'n3': [0.06870713919610347, 0.23863115122119738, 0.048858783362332986, 0.18910852255356034], 'n4': [0.5051857600366919, 0.7781653125896516, 0.21133259350889166, 0.4141945608522559]}, 'synergi_output': {'node_61746791326': [0.000999999415454687, 0.0009999923015324673, 0.0009999996415073831, 0.0009999921771822826], 'node_61746791327': [1.4052433405517772, 0.8534261345199505, 1.100207413576314, 0.09925701086833777], 'node_61746839533': [0.5767771891663984, 1.2140898058567755, 0.5400898631419725, 1.138540681909626], 'node_61746842036': [2.2802968553458975, 1.9930774142792114, 1.8176517572334512, 1.1452767401123385]}}, 'ieee_13node': {'cyme_output': {'650': [1.6442002249862027, 2.525071217368887, 0.00175590064769382, 0.013818660541591976], '633': [2.191962671993786, 2.7645145724914206, 0.13502678340376117, 0.30258402028428943], '634': [0.03373885959967424, 0.0437948202860033, 0.006851233217346727, 0.01281928879314106], '7': [1.6444948113338582, 2.5248296649991535, 0.0027565424317121945, 0.014811194353743895], 'rg60': [1.6444956621823732, 2.524829864977333, 0.002756707027920302, 0.014813876873885912], '632': [2.1103087225772716, 2.527515777000864, 0.0791161472443358, 0.2320482533916044], '652': [1.2506186991395154, 1.2878722947329384, 1.2506186991395154, 1.2878722947329384], '611': [1.1239472985549395, 1.3770646713358636, 1.1239472985549395, 1.3770646713358636], '692': [2.631742710227492, 2.70681263013228, 0.16404792757812026, 0.44179116013620445], '645': [2.2388323604857887, 2.784026210466048, 0.1850730276433944, 0.31739303544051045], '646':[2.317657028721549, 2.949917446377885, 0.24850513527121498, 0.3676808102436452], '671': [2.630682474394549, 2.706364834017407, 0.16301316760562778, 0.44085146992520197], '675': [2.7067614833052813, 2.7173749384388346, 0.23870615585157873, 0.47708961405564254], '684': [2.6970360888981926, 2.8036701407791496, 0.23157910972791085, 0.5317115549334911], '680': [2.7200580191836536, 3.2662254613120227, 0.19824054093535326, 0.5540558678888127]}, 'demo_output': {}, 'gridlabd_output': {}, 'opendss_output': {'sourcebus': [0.17960357997560872, 0.5388107499674782, 0.16044213136336458, 0.6414216083753025], '650': [3.46173977571697e-05, 0.00027688611330264445, 0.00024463297015852746, 0.0011161493255213788], 'rg60': [0.0003803596442662037, 0.0006225803505498496, 0.0005903829452526287, 0.0014616392165030185], '633': [0.38047984831844595, 0.8729366035169337, 0.13271664569004354, 0.28972479926771977], '634': [0.010133922766079825, 0.020570453379602505, 0.006830751758597249, 0.012931935773494248], '671': [0.6108771018713602, 1.3265863413420522, 0.16093756369535386, 0.42423496513300524], '645': [0.4373080269407039, 0.8584390204064538, 0.18280284255143675, 0.32024566175842095], '646': [0.536560726260114, 0.9883607573047537, 0.24564544687076215, 0.36912074589189336], '692': [0.6119751654440972, 1.3274110796789444, 0.16196524206540175, 0.4251679482288616], '675': [0.7447836834016821, 1.3496142794655475, 0.20882248763406844, 0.46165856154276824], '611': [0.47109807838681994, 0.8597942885112269, 0.47109807838681994, 0.8597942885112269], '652': [0.5900525671135924, 0.8394468662430931, 0.5900525671135924, 0.8394468662430931], '670': [0.3852338293138269, 0.8975161336344963, 0.1039477429886314, 0.2879817616207214], '632': [0.2799093266146708, 0.6803831271514527, 0.07670340676752073, 0.21819919790776035], '680': [0.7346431542735055, 1.6877642140995293, 0.19615949605780691, 0.5372620670065573], '684': [0.7244901189090343, 1.397819420078607, 0.22833210323410577, 0.4698019455814719]}, 'synergi_output': {}}})
Loading

0 comments on commit 9d9c53a

Please sign in to comment.