Open aagervasi opened 7 years ago
Does the shapefile need to be projected before attempting to run this tool?
There seems to be an issue regarding the size of this network shapefile and NetworkX running out of memory when creating a graph.
I will try with a smaller network (tried with 1706 which is a HUC4)
On Mon, Jun 19, 2017 at 5:30 PM, Jesse Langdon notifications@github.com wrote:
There seems to be an issue regarding the size of this network shapefile and NetworkX running out of memory when creating a graph.
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/SouthForkResearch/pyGNAT/issues/27#issuecomment-309610231, or mute the thread https://github.com/notifications/unsubscribe-auth/AX5oVoABEcWLshOi17EP9tT3jPDXaqZeks5sFxLBgaJpZM4N6fEp .
So the network shapefile in question is pretty big (the whole Snake River basin, i.e. a "HUC 2"), with ~260,000 stream reaches. Within the network.py/import_shp
function, after importing this shapefile as a networkx graph, then sending the DiGraph to the get_subgraphs
function, I get a Memory Error (I did this manually using PyCharm's python interpreter):
File "<input>", line 1, in <module>
File "C:\Python27\ArcGIS10.1\Lib\site-packages\networkx\algorithms\components\connected.py", line 111, in connected_component_subgraphs
yield G.subgraph(c).copy()
File "C:\Python27\ArcGIS10.1\Lib\site-packages\networkx\classes\graph.py", line 1448, in copy
return deepcopy(self)
File "C:\OSGeo4W\apps\Python27\lib\copy.py", line 190, in deepcopy
y = _reconstruct(x, rv, 1, memo)
File "C:\OSGeo4W\apps\Python27\lib\copy.py", line 334, in _reconstruct
state = deepcopy(state, memo)
File "C:\OSGeo4W\apps\Python27\lib\copy.py", line 163, in deepcopy
y = copier(x, memo)
File "C:\OSGeo4W\apps\Python27\lib\copy.py", line 257, in _deepcopy_dict
y[deepcopy(key, memo)] = deepcopy(value, memo)
File "C:\OSGeo4W\apps\Python27\lib\copy.py", line 163, in deepcopy
y = copier(x, memo)
File "C:\OSGeo4W\apps\Python27\lib\copy.py", line 257, in _deepcopy_dict
y[deepcopy(key, memo)] = deepcopy(value, memo)
File "C:\OSGeo4W\apps\Python27\lib\copy.py", line 163, in deepcopy
y = copier(x, memo)
File "C:\OSGeo4W\apps\Python27\lib\copy.py", line 257, in _deepcopy_dict
y[deepcopy(key, memo)] = deepcopy(value, memo)
File "C:\OSGeo4W\apps\Python27\lib\copy.py", line 163, in deepcopy
y = copier(x, memo)
File "C:\OSGeo4W\apps\Python27\lib\copy.py", line 257, in _deepcopy_dict
y[deepcopy(key, memo)] = deepcopy(value, memo)
File "C:\OSGeo4W\apps\Python27\lib\copy.py", line 192, in deepcopy
memo[d] = y
MemoryError
My local OSGeo4W install of Python is 32bit, but the original error that Arielle reported occurred on her local machine, which uses a 64bit OSGeo4W install. So maybe this is a limitation of the NetworkX library? This is the first time I've encountered this issue with NetworkX, but this is also the largest shapefile we've ever tried to process...
I haven't looked into it but I think networkx
is a red herring. Everything I've seen leads me to believe that networkx can handle as big a network as you give it.
We might be running out of memory but if that's the case maybe we should investigate how many attributes we're storing. For example, if all we do is load the linkages and then do lookups for the attributes later that may save us quite a bit of breathing room.
Failing that we can look at storing the networks in a file format (like hdf5) and querying them on disk instead of in memory.
For what it's worth, there are only 15 attribute fields associated with this particular shapefile. I also imported the shapefile to graph in a 'simplified' format, so no intermediate nodes included...
An error has occurred while executing Python code: