Exporting graph object for later use

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
12
down vote

favorite












We are planning to analyze geometry of artery branch pattern. We convert the binarized image into graph object using MorphologicalGraph. To avoid the complexity of the code for later analysis, we want to save the graph objects to a separate file. We tried



Export["graphList.m", obtainBranchGraphList]


and tried to use the object later. When we import the data using



g2 = Import["graphList.m"]


resulting g2 seem to contain all the information of the graph. However, the content of g2 is something like



Graph[3, 5, 4, 13, 17, 26, 21, 42, 3 [UndirectedEdge] 5, 
4 [UndirectedEdge] 5, 17 [UndirectedEdge] 26,
21 [UndirectedEdge] 26, 21 [UndirectedEdge] 5,
42 [UndirectedEdge] 26,
21 [UndirectedEdge]
13, VertexLabels -> "Name", 8 -> None, 12 -> None, 22 -> None,
14 -> None, 2 -> None, 29 -> None, 41 -> None, 38 -> None,
37 -> None, 20 -> None, 32 -> None, 18 -> None, 25 -> None,
7 -> None, 9 -> None, 19 -> None, 30 -> None, 16 -> None,
23 -> None, 39 -> None, 34 -> None, 40 -> None, 11 -> None,
44 -> None, 6 -> None, 36 -> None, 33 -> None, 1 -> None,
15 -> None, 35 -> None, 28 -> None, 24 -> None, 10 -> None,
27 -> None, 43 -> None, 31 -> None,
VertexCoordinates -> 2096.5, 1813.5, 2093.5, 1795.5, 2144.5,
1810.5, 2243.5, 1600.5, 1892.5, 1581.5, 1926.5,
1559.5, 1942.5, 1571.5, 1713.5, 1298.5]


and we could not reconstruct the graph from g2. Is there any way to convert this text to graph object?



Thank you very much in advance.



Takashi.







share|improve this question






















  • if you comment out VertexLabels -> ..., part or change it to VertexLabels -> "Name" it works fine.
    – kglr
    Aug 14 at 8:04











  • see also DumpSave and Get, e.g. DumpSave["graphList.mx", obtainBranchGraphList] and Get["graphList.mx"]
    – kglr
    Aug 14 at 8:11










  • @kglr DumpSave will only hide the internal corruption temporarily. The bug is still there and will no doubt surface in a nastier way later.
    – Szabolcs
    Aug 14 at 10:06










  • @Szabolcs, right; I didn't mean to suggest DumpSave/Get as a fix; just as an alternative to Export/Import.
    – kglr
    Aug 14 at 19:49














up vote
12
down vote

favorite












We are planning to analyze geometry of artery branch pattern. We convert the binarized image into graph object using MorphologicalGraph. To avoid the complexity of the code for later analysis, we want to save the graph objects to a separate file. We tried



Export["graphList.m", obtainBranchGraphList]


and tried to use the object later. When we import the data using



g2 = Import["graphList.m"]


resulting g2 seem to contain all the information of the graph. However, the content of g2 is something like



Graph[3, 5, 4, 13, 17, 26, 21, 42, 3 [UndirectedEdge] 5, 
4 [UndirectedEdge] 5, 17 [UndirectedEdge] 26,
21 [UndirectedEdge] 26, 21 [UndirectedEdge] 5,
42 [UndirectedEdge] 26,
21 [UndirectedEdge]
13, VertexLabels -> "Name", 8 -> None, 12 -> None, 22 -> None,
14 -> None, 2 -> None, 29 -> None, 41 -> None, 38 -> None,
37 -> None, 20 -> None, 32 -> None, 18 -> None, 25 -> None,
7 -> None, 9 -> None, 19 -> None, 30 -> None, 16 -> None,
23 -> None, 39 -> None, 34 -> None, 40 -> None, 11 -> None,
44 -> None, 6 -> None, 36 -> None, 33 -> None, 1 -> None,
15 -> None, 35 -> None, 28 -> None, 24 -> None, 10 -> None,
27 -> None, 43 -> None, 31 -> None,
VertexCoordinates -> 2096.5, 1813.5, 2093.5, 1795.5, 2144.5,
1810.5, 2243.5, 1600.5, 1892.5, 1581.5, 1926.5,
1559.5, 1942.5, 1571.5, 1713.5, 1298.5]


and we could not reconstruct the graph from g2. Is there any way to convert this text to graph object?



Thank you very much in advance.



Takashi.







share|improve this question






















  • if you comment out VertexLabels -> ..., part or change it to VertexLabels -> "Name" it works fine.
    – kglr
    Aug 14 at 8:04











  • see also DumpSave and Get, e.g. DumpSave["graphList.mx", obtainBranchGraphList] and Get["graphList.mx"]
    – kglr
    Aug 14 at 8:11










  • @kglr DumpSave will only hide the internal corruption temporarily. The bug is still there and will no doubt surface in a nastier way later.
    – Szabolcs
    Aug 14 at 10:06










  • @Szabolcs, right; I didn't mean to suggest DumpSave/Get as a fix; just as an alternative to Export/Import.
    – kglr
    Aug 14 at 19:49












up vote
12
down vote

favorite









up vote
12
down vote

favorite











We are planning to analyze geometry of artery branch pattern. We convert the binarized image into graph object using MorphologicalGraph. To avoid the complexity of the code for later analysis, we want to save the graph objects to a separate file. We tried



Export["graphList.m", obtainBranchGraphList]


and tried to use the object later. When we import the data using



g2 = Import["graphList.m"]


resulting g2 seem to contain all the information of the graph. However, the content of g2 is something like



Graph[3, 5, 4, 13, 17, 26, 21, 42, 3 [UndirectedEdge] 5, 
4 [UndirectedEdge] 5, 17 [UndirectedEdge] 26,
21 [UndirectedEdge] 26, 21 [UndirectedEdge] 5,
42 [UndirectedEdge] 26,
21 [UndirectedEdge]
13, VertexLabels -> "Name", 8 -> None, 12 -> None, 22 -> None,
14 -> None, 2 -> None, 29 -> None, 41 -> None, 38 -> None,
37 -> None, 20 -> None, 32 -> None, 18 -> None, 25 -> None,
7 -> None, 9 -> None, 19 -> None, 30 -> None, 16 -> None,
23 -> None, 39 -> None, 34 -> None, 40 -> None, 11 -> None,
44 -> None, 6 -> None, 36 -> None, 33 -> None, 1 -> None,
15 -> None, 35 -> None, 28 -> None, 24 -> None, 10 -> None,
27 -> None, 43 -> None, 31 -> None,
VertexCoordinates -> 2096.5, 1813.5, 2093.5, 1795.5, 2144.5,
1810.5, 2243.5, 1600.5, 1892.5, 1581.5, 1926.5,
1559.5, 1942.5, 1571.5, 1713.5, 1298.5]


and we could not reconstruct the graph from g2. Is there any way to convert this text to graph object?



Thank you very much in advance.



Takashi.







share|improve this question














We are planning to analyze geometry of artery branch pattern. We convert the binarized image into graph object using MorphologicalGraph. To avoid the complexity of the code for later analysis, we want to save the graph objects to a separate file. We tried



Export["graphList.m", obtainBranchGraphList]


and tried to use the object later. When we import the data using



g2 = Import["graphList.m"]


resulting g2 seem to contain all the information of the graph. However, the content of g2 is something like



Graph[3, 5, 4, 13, 17, 26, 21, 42, 3 [UndirectedEdge] 5, 
4 [UndirectedEdge] 5, 17 [UndirectedEdge] 26,
21 [UndirectedEdge] 26, 21 [UndirectedEdge] 5,
42 [UndirectedEdge] 26,
21 [UndirectedEdge]
13, VertexLabels -> "Name", 8 -> None, 12 -> None, 22 -> None,
14 -> None, 2 -> None, 29 -> None, 41 -> None, 38 -> None,
37 -> None, 20 -> None, 32 -> None, 18 -> None, 25 -> None,
7 -> None, 9 -> None, 19 -> None, 30 -> None, 16 -> None,
23 -> None, 39 -> None, 34 -> None, 40 -> None, 11 -> None,
44 -> None, 6 -> None, 36 -> None, 33 -> None, 1 -> None,
15 -> None, 35 -> None, 28 -> None, 24 -> None, 10 -> None,
27 -> None, 43 -> None, 31 -> None,
VertexCoordinates -> 2096.5, 1813.5, 2093.5, 1795.5, 2144.5,
1810.5, 2243.5, 1600.5, 1892.5, 1581.5, 1926.5,
1559.5, 1942.5, 1571.5, 1713.5, 1298.5]


and we could not reconstruct the graph from g2. Is there any way to convert this text to graph object?



Thank you very much in advance.



Takashi.









share|improve this question













share|improve this question




share|improve this question








edited Aug 14 at 13:32









Chris K

5,54221638




5,54221638










asked Aug 14 at 7:55









Takashi Miura

712




712











  • if you comment out VertexLabels -> ..., part or change it to VertexLabels -> "Name" it works fine.
    – kglr
    Aug 14 at 8:04











  • see also DumpSave and Get, e.g. DumpSave["graphList.mx", obtainBranchGraphList] and Get["graphList.mx"]
    – kglr
    Aug 14 at 8:11










  • @kglr DumpSave will only hide the internal corruption temporarily. The bug is still there and will no doubt surface in a nastier way later.
    – Szabolcs
    Aug 14 at 10:06










  • @Szabolcs, right; I didn't mean to suggest DumpSave/Get as a fix; just as an alternative to Export/Import.
    – kglr
    Aug 14 at 19:49
















  • if you comment out VertexLabels -> ..., part or change it to VertexLabels -> "Name" it works fine.
    – kglr
    Aug 14 at 8:04











  • see also DumpSave and Get, e.g. DumpSave["graphList.mx", obtainBranchGraphList] and Get["graphList.mx"]
    – kglr
    Aug 14 at 8:11










  • @kglr DumpSave will only hide the internal corruption temporarily. The bug is still there and will no doubt surface in a nastier way later.
    – Szabolcs
    Aug 14 at 10:06










  • @Szabolcs, right; I didn't mean to suggest DumpSave/Get as a fix; just as an alternative to Export/Import.
    – kglr
    Aug 14 at 19:49















if you comment out VertexLabels -> ..., part or change it to VertexLabels -> "Name" it works fine.
– kglr
Aug 14 at 8:04





if you comment out VertexLabels -> ..., part or change it to VertexLabels -> "Name" it works fine.
– kglr
Aug 14 at 8:04













see also DumpSave and Get, e.g. DumpSave["graphList.mx", obtainBranchGraphList] and Get["graphList.mx"]
– kglr
Aug 14 at 8:11




see also DumpSave and Get, e.g. DumpSave["graphList.mx", obtainBranchGraphList] and Get["graphList.mx"]
– kglr
Aug 14 at 8:11












@kglr DumpSave will only hide the internal corruption temporarily. The bug is still there and will no doubt surface in a nastier way later.
– Szabolcs
Aug 14 at 10:06




@kglr DumpSave will only hide the internal corruption temporarily. The bug is still there and will no doubt surface in a nastier way later.
– Szabolcs
Aug 14 at 10:06












@Szabolcs, right; I didn't mean to suggest DumpSave/Get as a fix; just as an alternative to Export/Import.
– kglr
Aug 14 at 19:49




@Szabolcs, right; I didn't mean to suggest DumpSave/Get as a fix; just as an alternative to Export/Import.
– kglr
Aug 14 at 19:49










1 Answer
1






active

oldest

votes

















up vote
11
down vote













This is, sadly, due to some long-standing bugs in Mathematica that I have reported multiple times, but Wolfram fails to take seriously. I don't understand how they can seriously keep marketing Mathematica for graph/network analysis for as long as even basic things don't work.



Here's what happens, in short:



There are several operations (such as VertexDelete, EdgeDelete, etc.) which will corrupt the internal structure of the graph whenever properties are present. Properties can be something as harmless looking as vertex labels.



Graph is an atomic object, and it is not represented internally through its InputForm. However, when you export it (as well as in several other situations) it does need to be converted to input form. When you re-import it, Mathematica notices that the structure is corrupted and refuses to construct the graph.



I do not know which specific bug (or which function) corrupted your graph. It is likely one of the ones I mentioned (edge/vertex deletions or additions).



However, I can see that vertex labels are assigned to non-existent vertices, such as vertex 8. You probably VertexDeleted these, which may have also triggered adding the v -> None rules to the vertex labels (yet another long-standing bug).



You can recover your graph by deleting the VertexLabels -> ... bit, e.g. using



DeleteCases[yourImportedGraph, VertexLabels -> _, Infinity]


But once again: this is not your fault, it's due to a set of bugs affecting even the most fundamental operations one would want to do with graphs in Mathematica. So please do complain and report it to Wolfram Support.






share|improve this answer






















  • Thank you very much for your reply! It makes sense since we used VertexDelete to simplify the network structure. And we succeeded in recovering the original graph using DeleteCases.
    – Takashi Miura
    Aug 14 at 10:14










Your Answer




StackExchange.ifUsing("editor", function ()
return StackExchange.using("mathjaxEditing", function ()
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
);
);
, "mathjax-editing");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "387"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f179988%2fexporting-graph-object-for-later-use%23new-answer', 'question_page');

);

Post as a guest






























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
11
down vote













This is, sadly, due to some long-standing bugs in Mathematica that I have reported multiple times, but Wolfram fails to take seriously. I don't understand how they can seriously keep marketing Mathematica for graph/network analysis for as long as even basic things don't work.



Here's what happens, in short:



There are several operations (such as VertexDelete, EdgeDelete, etc.) which will corrupt the internal structure of the graph whenever properties are present. Properties can be something as harmless looking as vertex labels.



Graph is an atomic object, and it is not represented internally through its InputForm. However, when you export it (as well as in several other situations) it does need to be converted to input form. When you re-import it, Mathematica notices that the structure is corrupted and refuses to construct the graph.



I do not know which specific bug (or which function) corrupted your graph. It is likely one of the ones I mentioned (edge/vertex deletions or additions).



However, I can see that vertex labels are assigned to non-existent vertices, such as vertex 8. You probably VertexDeleted these, which may have also triggered adding the v -> None rules to the vertex labels (yet another long-standing bug).



You can recover your graph by deleting the VertexLabels -> ... bit, e.g. using



DeleteCases[yourImportedGraph, VertexLabels -> _, Infinity]


But once again: this is not your fault, it's due to a set of bugs affecting even the most fundamental operations one would want to do with graphs in Mathematica. So please do complain and report it to Wolfram Support.






share|improve this answer






















  • Thank you very much for your reply! It makes sense since we used VertexDelete to simplify the network structure. And we succeeded in recovering the original graph using DeleteCases.
    – Takashi Miura
    Aug 14 at 10:14














up vote
11
down vote













This is, sadly, due to some long-standing bugs in Mathematica that I have reported multiple times, but Wolfram fails to take seriously. I don't understand how they can seriously keep marketing Mathematica for graph/network analysis for as long as even basic things don't work.



Here's what happens, in short:



There are several operations (such as VertexDelete, EdgeDelete, etc.) which will corrupt the internal structure of the graph whenever properties are present. Properties can be something as harmless looking as vertex labels.



Graph is an atomic object, and it is not represented internally through its InputForm. However, when you export it (as well as in several other situations) it does need to be converted to input form. When you re-import it, Mathematica notices that the structure is corrupted and refuses to construct the graph.



I do not know which specific bug (or which function) corrupted your graph. It is likely one of the ones I mentioned (edge/vertex deletions or additions).



However, I can see that vertex labels are assigned to non-existent vertices, such as vertex 8. You probably VertexDeleted these, which may have also triggered adding the v -> None rules to the vertex labels (yet another long-standing bug).



You can recover your graph by deleting the VertexLabels -> ... bit, e.g. using



DeleteCases[yourImportedGraph, VertexLabels -> _, Infinity]


But once again: this is not your fault, it's due to a set of bugs affecting even the most fundamental operations one would want to do with graphs in Mathematica. So please do complain and report it to Wolfram Support.






share|improve this answer






















  • Thank you very much for your reply! It makes sense since we used VertexDelete to simplify the network structure. And we succeeded in recovering the original graph using DeleteCases.
    – Takashi Miura
    Aug 14 at 10:14












up vote
11
down vote










up vote
11
down vote









This is, sadly, due to some long-standing bugs in Mathematica that I have reported multiple times, but Wolfram fails to take seriously. I don't understand how they can seriously keep marketing Mathematica for graph/network analysis for as long as even basic things don't work.



Here's what happens, in short:



There are several operations (such as VertexDelete, EdgeDelete, etc.) which will corrupt the internal structure of the graph whenever properties are present. Properties can be something as harmless looking as vertex labels.



Graph is an atomic object, and it is not represented internally through its InputForm. However, when you export it (as well as in several other situations) it does need to be converted to input form. When you re-import it, Mathematica notices that the structure is corrupted and refuses to construct the graph.



I do not know which specific bug (or which function) corrupted your graph. It is likely one of the ones I mentioned (edge/vertex deletions or additions).



However, I can see that vertex labels are assigned to non-existent vertices, such as vertex 8. You probably VertexDeleted these, which may have also triggered adding the v -> None rules to the vertex labels (yet another long-standing bug).



You can recover your graph by deleting the VertexLabels -> ... bit, e.g. using



DeleteCases[yourImportedGraph, VertexLabels -> _, Infinity]


But once again: this is not your fault, it's due to a set of bugs affecting even the most fundamental operations one would want to do with graphs in Mathematica. So please do complain and report it to Wolfram Support.






share|improve this answer














This is, sadly, due to some long-standing bugs in Mathematica that I have reported multiple times, but Wolfram fails to take seriously. I don't understand how they can seriously keep marketing Mathematica for graph/network analysis for as long as even basic things don't work.



Here's what happens, in short:



There are several operations (such as VertexDelete, EdgeDelete, etc.) which will corrupt the internal structure of the graph whenever properties are present. Properties can be something as harmless looking as vertex labels.



Graph is an atomic object, and it is not represented internally through its InputForm. However, when you export it (as well as in several other situations) it does need to be converted to input form. When you re-import it, Mathematica notices that the structure is corrupted and refuses to construct the graph.



I do not know which specific bug (or which function) corrupted your graph. It is likely one of the ones I mentioned (edge/vertex deletions or additions).



However, I can see that vertex labels are assigned to non-existent vertices, such as vertex 8. You probably VertexDeleted these, which may have also triggered adding the v -> None rules to the vertex labels (yet another long-standing bug).



You can recover your graph by deleting the VertexLabels -> ... bit, e.g. using



DeleteCases[yourImportedGraph, VertexLabels -> _, Infinity]


But once again: this is not your fault, it's due to a set of bugs affecting even the most fundamental operations one would want to do with graphs in Mathematica. So please do complain and report it to Wolfram Support.







share|improve this answer














share|improve this answer



share|improve this answer








edited Aug 14 at 10:57

























answered Aug 14 at 10:05









Szabolcs

152k12415896




152k12415896











  • Thank you very much for your reply! It makes sense since we used VertexDelete to simplify the network structure. And we succeeded in recovering the original graph using DeleteCases.
    – Takashi Miura
    Aug 14 at 10:14
















  • Thank you very much for your reply! It makes sense since we used VertexDelete to simplify the network structure. And we succeeded in recovering the original graph using DeleteCases.
    – Takashi Miura
    Aug 14 at 10:14















Thank you very much for your reply! It makes sense since we used VertexDelete to simplify the network structure. And we succeeded in recovering the original graph using DeleteCases.
– Takashi Miura
Aug 14 at 10:14




Thank you very much for your reply! It makes sense since we used VertexDelete to simplify the network structure. And we succeeded in recovering the original graph using DeleteCases.
– Takashi Miura
Aug 14 at 10:14

















 

draft saved


draft discarded















































 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f179988%2fexporting-graph-object-for-later-use%23new-answer', 'question_page');

);

Post as a guest













































































Comments

Popular posts from this blog

What does second last employer means? [closed]

Installing NextGIS Connect into QGIS 3?

One-line joke