r.connectivity.network: replace R with Python#1109
r.connectivity.network: replace R with Python#1109ninsbl wants to merge 3 commits intoOSGeo:grass8from
Conversation
|
|
||
| """ | ||
| MODULE: r.connectivity.network | ||
| AUTHOR(S): Stefan Blumentrath <stefan dot blumentrath at nina dot no> | ||
| PURPOSE: Compute connectivity measures for a set of habitat patches | ||
| based on graph-theory (using the igraph-package in R). | ||
| based on graph-theory (usig the igraph-package in R). |
There was a problem hiding this comment.
| based on graph-theory (usig the igraph-package in R). | |
| based on graph-theory (using the igraph-package in R). |
| @@ -17,7 +16,7 @@ | |||
|
|
|||
| r.connectivity.network is the 2nd tool of the | |||
| r.connectivity.* toolchain and performs the (core) network | |||
| analysis (using the igraph-package in R) on the network | |||
| analysis (usig the igraph-package in R) on the network | |||
There was a problem hiding this comment.
| analysis (usig the igraph-package in R) on the network | |
| analysis (using the igraph-package in R) on the network |
| in a plot showing an overview over number of connections, | ||
| number of components and and the size of the largest |
There was a problem hiding this comment.
| in a plot showing an overview over number of connections, | |
| number of components and and the size of the largest | |
| in a plot showing an overview over the number of connections, | |
| number of components and the size of the largest |
| " (use PYTHONPATH variable)." | ||
| ) | ||
| gscript.fatal( | ||
| "Could not import igraph library! To install it run:", |
There was a problem hiding this comment.
| "Could not import igraph library! To install it run:", | |
| "Could not import igraph library! To install it run: ", |
ecodiv
left a comment
There was a problem hiding this comment.
A few suggestions for changes. Also with those changes, I can't get it to run.
| # %flag | ||
| # % key: r | ||
| # % description: Remove indirect connections from network | ||
| # %end | ||
|
|
||
| import atexit | ||
| import os | ||
| from io import BytesIO |
There was a problem hiding this comment.
| from io import BytesIO | |
| from io import StringIO |
|
|
||
| gscript.verbose(_("Reading and preparing input data...\n")) | ||
| vertices = np.gefromtext( | ||
| BytesIO( |
There was a problem hiding this comment.
| BytesIO( | |
| StringIO( |
Following example in https://numpy.org/doc/stable/user/basics.io.genfromtxt.html
| "{}".format(verbose).upper() | ||
| # Read edge data | ||
| edges = np.gefromtext( | ||
| BytesIO( |
There was a problem hiding this comment.
| BytesIO( | |
| StringIO( |
Following example in https://numpy.org/doc/stable/user/basics.io.genfromtxt.html
| gscript.read_command( | ||
| "v.db.select", | ||
| flags="c", | ||
| map=in_edges, |
There was a problem hiding this comment.
| map=in_edges, | |
| map=network_map, |
There was a problem hiding this comment.
A few additional suggestions
Replace:
# %option
# % key: cores
# % type: integer
# % description: Number of cores to be used for computation (if <= 1 no parallelisation is applied)
# % guisection: Parallelisation
# % required: no
# % answer: 1
# %end
with:
# %option G_OPT_M_NPROCS
# % required: no
# %end
Remove:
i_flag = flags["i"]
| @@ -289,17 +266,16 @@ def main(): | |||
| prefix = options["prefix"] | |||
| cores = options["cores"] | |||
There was a problem hiding this comment.
| cores = options["cores"] | |
| cores = int(options["nprocs"]) |
| # Build directed graph | ||
| gscript.verbose(_("Building the graph...")) | ||
|
|
||
| g = Graph().as_directed() |
There was a problem hiding this comment.
| g = Graph().as_directed() | |
| g = igraph.Graph().as_directed() |
This is a first start to replace the use of R with Python