Skip to content

Commit

Permalink
save changes to serialize skeletons
Browse files Browse the repository at this point in the history
  • Loading branch information
eberrigan committed Sep 11, 2024
1 parent 5decb55 commit 622853c
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions sleap/skeleton.py
Original file line number Diff line number Diff line change
Expand Up @@ -1082,15 +1082,16 @@ def to_json(self, node_to_idx: Optional[Dict[Node, int]] = None) -> str:
"type": edge_type,
}
)

# Create graph field
graph = {
"name": self.name,
"num_edges_inserted": len(self.edges),
}
# Create skeleton dict.
if self.is_template:
skeleton_dict = {
"directed": True,
"graph": {
"name": self.name,
"num_edges_inserted": len(self.edges),
},
"nx_graph": graph,
"links": edges_dicts,
"multigraph": True,
# In the order in Skeleton.nodes and must match up with nodes_dicts.
Expand All @@ -1101,14 +1102,16 @@ def to_json(self, node_to_idx: Optional[Dict[Node, int]] = None) -> str:
else:
skeleton_dict ={
"directed": True,
"graph": {
"name": self.name,
"num_edges_inserted": len(self.edges),
},
"nx_graph": graph,
"links": edges_dicts,
"multigraph": True,
# In the order in Skeleton.nodes and must match up with nodes_dicts.
"nodes": [{"id": {"py/id": node_to_id[node]}} for node in self.nodes],}

print(f'skeleton_dict: {skeleton_dict}')
json_str = json.dumps(skeleton_dict)
print(f'json_str: {json_str}')
return json_str

# jsonpickle.set_encoder_options("simplejson", sort_keys=True, indent=4)
# if node_to_idx is not None:
Expand Down

0 comments on commit 622853c

Please sign in to comment.