Skip to content

Commit

Permalink
Fix xy coordinate data extract from cyme converter (#111)
Browse files Browse the repository at this point in the history
Signed-off-by: Mitchell Victoriano <mitchell.victoriano@gmail.com>
Signed-off-by: David P. Chassin <dchassin@slac.stanford.edu>
Signed-off-by: David P. Chassin <david.chassin@me.com>
Co-authored-by: David P. Chassin <dchassin@slac.stanford.edu>
Signed-off-by: David P. Chassin <david.chassin@me.com>
  • Loading branch information
2 people authored and dchassin committed Oct 16, 2023
1 parent b6bffa2 commit 590e681
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 53 deletions.
26 changes: 26 additions & 0 deletions converters/autotest/IEEE-13-cyme-xy-coordinates.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
node,x,y
611,-497.529638,-296.406716
632,-102.564756,-82.359153
633,96.981706,-82.359153
634,296.528167,-82.359153
645,-303.611567,-82.359153
646,-503.158028,-82.359153
650,-101.871718,202.525349
652,-305.42555,-388.033675
671,-102.564756,-295.840278
675,177.685724,-296.168228
680,-102.216065,-385.711768
684,-305.569538,-295.821338
692,95.477648,-295.827775
7,-102.140153,119.727044
L611CAP,-591.552268,-296.394266
L675CAP,375.26425,-296.626671
LOAD611,-497.577422,-322.467031
LOAD634,296.529235,-104.537935
LOAD645,-303.611567,-102.823074
LOAD646,-503.140358,-104.938533
LOAD652,-305.36199,-423.410687
LOAD671,-130.812161,-270.135734
LOAD675,177.693667,-331.639128
LOAD692,95.481356,-329.791363
RG60,-102.134091,-103.005827
9 changes: 9 additions & 0 deletions converters/autotest/test_mdb2glm_xy_coordinates.glm
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#ifexist ../IEEE-13-cyme.mdb
#define DIR=..
#endif // exist ../IEEE-13-cyme.mdb

#input "${DIR:-.}/IEEE-13-cyme.mdb" -t cyme -o test-IEEE-13.glm -p coordinateCSV=test-IEEE-13-cyme-xy-coordinates.csv

#ifexist ../IEEE-13-cyme-xy-coordinates.csv
#on_exit 0 diff -I '^[#/]' ../IEEE-13-cyme-xy-coordinates.csv test-IEEE-13-cyme-xy-coordinates.csv > gridlabd.diff
#endif // exist ../IEEE-13-cyme-xy-coordinates.csv
12 changes: 2 additions & 10 deletions converters/autotest/test_mdbtable2glm.glm
Original file line number Diff line number Diff line change
@@ -1,17 +1,9 @@
#ifmissing /usr/local/bin/mdb-schema

#warning mdbtools is not available

#else // found /usr/local/bin/mdb-schema

#ifexist ../IEEE-13-cyme.mdb
#define DIR=..
#endif // exist ../IEEE-13-cyme.mdb

#input "${DIR:-.}/IEEE-13-cyme.mdb" -o IEEE-13-cyme-network.glm -t cyme
#input "${DIR:-.}/IEEE-13-cyme.mdb" -o ./IEEE-13-cyme-network.glm -t cyme

#ifexist ../IEEE-13-cyme-network.glm
#on_exit 0 diff -I '^[#/]' ../IEEE-13-cyme-network.glm IEEE-13-cyme-network.glm > gridlabd.diff
#endif // exist ../IEEE-13-cyme-network.glm

#endif // missing /usr/local/bin/mdb-schema
#endif // exist ../IEEE-13-cyme-network.glm
10 changes: 1 addition & 9 deletions converters/autotest/test_mdbtable2glmobject.glm
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
#ifmissing ${GLD_BIN}/mdb-schema

#warning mdbtools is not available

#else // found ${GLD_BIN}/mdb-schema

#ifexist ../IEEE-13-cyme.mdb
#define DIR=..
#endif // exist ../IEEE-13-cyme.mdb
Expand All @@ -12,6 +6,4 @@

#ifexist ../IEEE-13-cyme-object.glm
#on_exit 0 diff -I '^[#/]' ../IEEE-13-cyme-object.glm IEEE-13-cyme-object.glm > gridlabd.diff
#endif // exist ../IEEE-13-cyme-object.glm

#endif // missing ${GLD_BIN}/mdb-schema
#endif // exist ../IEEE-13-cyme-object.glm
10 changes: 1 addition & 9 deletions converters/autotest/test_mdbtable2glmplayer.glm
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,6 @@
// To access this data you must read, agree to, and sign the NDA covering this data.
//

#ifmissing ${GLD_BIN}/mdb-schema

#warning mdbtools is not available

#else

#ifmissing ami_data.mdb

#ifmissing ami_data.mdb.zip
Expand Down Expand Up @@ -78,6 +72,4 @@ object collector
#on_exit 0 diff ../test_mdbtable2glmplayer.csv test_mdbtable2glmplayer.csv > gridlabd.diff
#endif // exist ../test_mdbtable2glmplayer.csv

#endif // exist ami_data.mdb

#endif // missing ${GLD_BIN}/mdb-schema
#endif // exist ami_data.mdb
54 changes: 29 additions & 25 deletions converters/mdb-cyme2glm.py
Original file line number Diff line number Diff line change
Expand Up @@ -978,29 +978,7 @@ def add_link(self, section_id, section, version, **kwargs):
# add node to glm file
def add_node(self, node_id, node_links, device_dict, version, **kwargs):
phase = 0
if geodata_file:
node_geodata_id = f"{node_id}_{network_id}"
if node_geodata_id not in node_geodata.keys():
all_node = kwargs["node_info"]["all_node"]
try:
node_X = float(all_node[all_node["NodeId"] == node_id]["X"].values)
node_Y = float(all_node[all_node["NodeId"] == node_id]["Y"].values)
except:
warning(
f"{cyme_mdbname}@{network_id}: cannot add coordinates for node_id"
)
node_X = np.nan
node_Y = np.nan
node_geodata[node_geodata_id] = {
"NotworkID": network_id,
"node": node_id,
"x": node_X,
"y": node_Y,
}
else:
raise Exception(
f"{cyme_mdbname}@{network_id}: multiple definition for {node_id}"
)

for device_id in node_links[node_id]:
phase |= glm_phase_code[device_dict[device_id]["phases"]]
obj = self.object(
Expand Down Expand Up @@ -3259,10 +3237,36 @@ def cyme_extract_9(network_id, network, conversion_info):

# generate coordinate file
if geodata_file:
all_node = table_find(cyme_table["node"], NetworkId=network_id)
df_all_nodes = pd.DataFrame.from_dict(all_node)

for index, row in df_all_nodes.iterrows():
node_id = row["NodeId"]
if node_id not in node_geodata.keys():
try:
node_X = float(row["X"])
node_Y = float(row["Y"])
except:
warning(
f"{cyme_mdbname}@{network_id}: cannot add coordinates for node_id"
)
node_X = np.nan
node_Y = np.nan
node_geodata[node_id] = {
"NetworkID": network_id,
"node": node_id,
"x": node_X,
"y": node_Y,
}
else:
raise Exception(
f"{cyme_mdbname}@{network_id}: multiple definition for {node_id}"
)

df_node = pd.DataFrame.from_dict(node_geodata)
df_node = df_node.T
df_node.drop(df_node[df_node[:]["NotworkID"] != network_id].index, inplace=True)
df_node = df_node.drop(["NotworkID"], axis=1)
df_node.drop(df_node[df_node[:]["NetworkID"] != network_id].index, inplace=True)
df_node = df_node.drop(["NetworkID"], axis=1)
df_node.to_csv(f"{output_folder}/{geodata_file}", index=False, header=True)

glm.close()
Expand Down

0 comments on commit 590e681

Please sign in to comment.