.. role:: bash(code)
:language: bash
.. role:: python(code)
:language: python
.. image:: ./docs/img/Ga4Py.png
:align: center
:alt: Logo
:width: 400px
----
.. image:: https://img.shields.io/pypi/v/graphab4py.svg
:target: https://pypi.org/project/graphab4py/
.. image:: https://img.shields.io/pypi/pyversions/graphab4py.svg
:target: https://pypi.org/project/graphab4py
.. _Supported Python Versions: https://pypi.org/project/graphab4py
.. image:: https://travis-ci.org/username/graphab4py.svg?branch=master
:target: https://travis-ci.org/username/graphab4py
.. _Build Status: https://travis-ci.org/username/graphab4py
.. image:: https://img.shields.io/pypi/dm/graphab4py.svg?label=PyPI%20downloads
:target: https://pypi.org/project/graphab4py
.. _PyPI Downloads: https://pypi.org/project/graphab4py
.. image:: https://img.shields.io/badge/license-UNLICENSE-green.svg
:target: https://unlicense.org/
=====
About
=====
This package provides a Python interface to the program `Graphab <https://sourcesup.renater.fr/www/graphab/en/home.html/>`_.
The author(s) of this Python package are not developing Graphab.
Rather, Graphab is an independent software which provides a graphical user interface, as well as a command line interface.
Further information on Graphab can be found `here <https://sourcesup.renater.fr/www/graphab/en/home.html>`_.
Also view the `documentation <https://htmlpreview.github.io/?https://github.com/ManuelPopp/graphab4py/blob/main/docs/build/html/index.html>`_ of this Python package.
=============
Prerequisites
=============
In order to install and use Graphab4py, `Python <https://www.python.org>`_ >= 3.8 and `Java <https://www.java.com>`_ >= 8 are both required.
It is also recommended to have `pip <https://pip.pypa.io/en/stable/installation/>`_ available to install the `latest version <https://pypi.org/project/graphab4py/#history>`_ of Graphab4py.
Graphab is not required for installation. It can be installed through Graphab4py if missing. Alternatively, Graphab4py can be set up to use an existing Graphab Java executable.
============
Installation
============
Graphab4Py is available on `PyPI <https://pypi.org/project/graphab4py>`_. To install Graphab4Py, simply run the following line:
.. code-block:: console
pip install graphab4py
========
Examples
========
With Graphab4py installed, we will now look at a few examples.
Creating a project
++++++++++++++++++
In the following, we will create a new Graphab project from scratch.
.. code-block:: python
import graphab4py
graphab4py.set_graphab("/home/rca/opt/")
prj = graphab4py.Project()
prj.create_project(
name = "MyProject", patches = "/home/rca/dat/pat/Patches.tif",
habitat = 1, directory = "/home/rca/prj"
)
prj.create_linkset(
disttype = "cost",
linkname = "L1",
threshold = 100000,
cost_raster = "/home/rca/dat/res/resistance_surface.tif"
)
prj.create_graph(graphname = "G1")
prj.save()
In this example, Graphab has already been downloaded and saved to a folder named :bash:`/home/rca/opt/`.
In a first step, Graphab4py is pointed to this folder. ALternatively, the :python:`get_graphab()` function can be used to download Graphab to a specific location.
Subsequently, the project is initialized. Here, the project is given a name and a project folder is created. Moreover, a file containing habitat patches must be provided.
This file is a raster (e.g., a GeoTIFF \*.tif file) with values encoded as INT2S. (Graphab does not accept another format.) The value or values for habitat patches must also be provided.
Now, we create a linkset. The values allowed for :python:`disttype` are :python:`"euclid"` and :python:`"cost"`, which refer to euclidean distance and cumulated cost.
For a linkset based on euclidean distances, the :python:`cost_raster` argument is not used. When, instead, a resistance surface is used, it needs to be provided as a raster file, as indicated in the example.
Moreover, a threshold can be set, to limit the distance for which links are calculated. This may be necessary when dealing with large sets of habitat patches in order to limit computing time.
Finally, we create a graph and save the project.
Loading an existing project
+++++++++++++++++++++++++++
Graphab4py can load existing Graphab projects (\*.xml). However, it also has its own format (\*.g4p) to save and load projects.
.. code-block:: python
import graphab4py
prj = graphab4py.Project()
prj.load_project_xml("/home/rca/prj/MyProject/MyProject.g4p")
prj.enable_distance_conversion(
save_plot = "/home/rca/out/Distance_conversion.png", max_euc = 2200
)
prj.convert_distance(500, regression = "log")
out = prj.calculate_metric(metric = "EC", d = 1500, p = 0.05)
ec = out["metric_value"]
In this example, we load a project from a Graphab4py project file. Subsequently, we use the linkset that we have created in the previous step to establish a relationship between euclidean and cost distance.
We can set limits to the euclidean distance considered for fitting the model, in order to fit the model to a relevant interval of our data.
When :python:`save_plot` is set to a valid path, a figure is created, so we can inspect the relationship and decide whether we want to use the respective regression mode.
By default, a linear regression is forced through zero. We decided that in our case, a log-log regression might give better results.
We can use the :python:`convert_distance` function directly to establish a relationship and return an estimation for a distance translation.
If no relationship for the given distance interval and regression model has established so far, the method will internally call :python:`enable_distance_conversion` and pass the required arguments.
Note that changing the distance interval will overwrite any previously fit model for the same linkset and model type.
In the last line, we calculate the metric "equivalent connectivity" (EC) for the entire graph. This metric requires additional parameters :python:`d` and :python:`p`.
Other metrics might not require additional parameters. A list of all the available metrics and their parameters and properties can be viewed in the original `Graphab manual <https://sourcesup.renater.fr/www/graphab/en/documentation.html>`_.
=======
License
=======
This is free and unencumbered software released into the public domain, as declared in the `LICENSE <https://github.com/ManuelPopp/graphab4py/blob/main/LICENSE>`_ file.
Raw data
{
"_id": null,
"home_page": "https://github.com/ManuelPopp/graphab4py",
"name": "graphab4py",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.8",
"maintainer_email": "",
"keywords": "Graphab,Network analysis",
"author": "Manuel R. Popp",
"author_email": "\"Manuel R. Popp\" <requests@cdpopp.de>",
"download_url": "https://files.pythonhosted.org/packages/8b/4c/fa838de38b119e5cf7086afd4286f7b7168c914b0af89cb240c65e30d915/graphab4py-1.0.5.tar.gz",
"platform": null,
"description": ".. role:: bash(code)\r\n :language: bash\r\n\r\n.. role:: python(code)\r\n :language: python\r\n\r\n\r\n.. image:: ./docs/img/Ga4Py.png\r\n :align: center\r\n :alt: Logo\r\n :width: 400px\r\n \r\n\r\n----\r\n\r\n.. image:: https://img.shields.io/pypi/v/graphab4py.svg\r\n :target: https://pypi.org/project/graphab4py/\r\n\r\n.. image:: https://img.shields.io/pypi/pyversions/graphab4py.svg\r\n :target: https://pypi.org/project/graphab4py\r\n\r\n.. _Supported Python Versions: https://pypi.org/project/graphab4py\r\n\r\n.. image:: https://travis-ci.org/username/graphab4py.svg?branch=master\r\n :target: https://travis-ci.org/username/graphab4py\r\n\r\n.. _Build Status: https://travis-ci.org/username/graphab4py\r\n\r\n.. image:: https://img.shields.io/pypi/dm/graphab4py.svg?label=PyPI%20downloads\r\n :target: https://pypi.org/project/graphab4py\r\n\r\n.. _PyPI Downloads: https://pypi.org/project/graphab4py\r\n\r\n.. image:: https://img.shields.io/badge/license-UNLICENSE-green.svg\r\n :target: https://unlicense.org/\r\n\r\n=====\r\nAbout\r\n=====\r\nThis package provides a Python interface to the program `Graphab <https://sourcesup.renater.fr/www/graphab/en/home.html/>`_.\r\nThe author(s) of this Python package are not developing Graphab.\r\nRather, Graphab is an independent software which provides a graphical user interface, as well as a command line interface.\r\nFurther information on Graphab can be found `here <https://sourcesup.renater.fr/www/graphab/en/home.html>`_.\r\n\r\nAlso view the `documentation <https://htmlpreview.github.io/?https://github.com/ManuelPopp/graphab4py/blob/main/docs/build/html/index.html>`_ of this Python package.\r\n\r\n=============\r\nPrerequisites\r\n=============\r\nIn order to install and use Graphab4py, `Python <https://www.python.org>`_ >= 3.8 and `Java <https://www.java.com>`_ >= 8 are both required.\r\nIt is also recommended to have `pip <https://pip.pypa.io/en/stable/installation/>`_ available to install the `latest version <https://pypi.org/project/graphab4py/#history>`_ of Graphab4py.\r\nGraphab is not required for installation. It can be installed through Graphab4py if missing. Alternatively, Graphab4py can be set up to use an existing Graphab Java executable.\r\n\r\n============\r\nInstallation\r\n============\r\nGraphab4Py is available on `PyPI <https://pypi.org/project/graphab4py>`_. To install Graphab4Py, simply run the following line:\r\n\r\n.. code-block:: console\r\n \r\n pip install graphab4py\r\n \r\n\r\n========\r\nExamples\r\n========\r\nWith Graphab4py installed, we will now look at a few examples.\r\n\r\nCreating a project\r\n++++++++++++++++++\r\nIn the following, we will create a new Graphab project from scratch.\r\n\r\n.. code-block:: python\r\n \r\n import graphab4py\r\n graphab4py.set_graphab(\"/home/rca/opt/\")\r\n prj = graphab4py.Project()\r\n \r\n prj.create_project(\r\n name = \"MyProject\", patches = \"/home/rca/dat/pat/Patches.tif\",\r\n habitat = 1, directory = \"/home/rca/prj\"\r\n )\r\n \r\n prj.create_linkset(\r\n disttype = \"cost\",\r\n linkname = \"L1\",\r\n threshold = 100000,\r\n cost_raster = \"/home/rca/dat/res/resistance_surface.tif\"\r\n )\r\n \r\n prj.create_graph(graphname = \"G1\")\r\n \r\n prj.save()\r\n \r\nIn this example, Graphab has already been downloaded and saved to a folder named :bash:`/home/rca/opt/`.\r\nIn a first step, Graphab4py is pointed to this folder. ALternatively, the :python:`get_graphab()` function can be used to download Graphab to a specific location.\r\nSubsequently, the project is initialized. Here, the project is given a name and a project folder is created. Moreover, a file containing habitat patches must be provided.\r\nThis file is a raster (e.g., a GeoTIFF \\*.tif file) with values encoded as INT2S. (Graphab does not accept another format.) The value or values for habitat patches must also be provided.\r\nNow, we create a linkset. The values allowed for :python:`disttype` are :python:`\"euclid\"` and :python:`\"cost\"`, which refer to euclidean distance and cumulated cost.\r\nFor a linkset based on euclidean distances, the :python:`cost_raster` argument is not used. When, instead, a resistance surface is used, it needs to be provided as a raster file, as indicated in the example.\r\nMoreover, a threshold can be set, to limit the distance for which links are calculated. This may be necessary when dealing with large sets of habitat patches in order to limit computing time.\r\nFinally, we create a graph and save the project.\r\n\r\nLoading an existing project\r\n+++++++++++++++++++++++++++\r\nGraphab4py can load existing Graphab projects (\\*.xml). However, it also has its own format (\\*.g4p) to save and load projects.\r\n\r\n.. code-block:: python\r\n \r\n import graphab4py\r\n prj = graphab4py.Project()\r\n prj.load_project_xml(\"/home/rca/prj/MyProject/MyProject.g4p\")\r\n \r\n prj.enable_distance_conversion(\r\n save_plot = \"/home/rca/out/Distance_conversion.png\", max_euc = 2200\r\n )\r\n \r\n prj.convert_distance(500, regression = \"log\")\r\n \r\n out = prj.calculate_metric(metric = \"EC\", d = 1500, p = 0.05)\r\n ec = out[\"metric_value\"]\r\n \r\nIn this example, we load a project from a Graphab4py project file. Subsequently, we use the linkset that we have created in the previous step to establish a relationship between euclidean and cost distance.\r\nWe can set limits to the euclidean distance considered for fitting the model, in order to fit the model to a relevant interval of our data.\r\nWhen :python:`save_plot` is set to a valid path, a figure is created, so we can inspect the relationship and decide whether we want to use the respective regression mode.\r\nBy default, a linear regression is forced through zero. We decided that in our case, a log-log regression might give better results.\r\nWe can use the :python:`convert_distance` function directly to establish a relationship and return an estimation for a distance translation.\r\nIf no relationship for the given distance interval and regression model has established so far, the method will internally call :python:`enable_distance_conversion` and pass the required arguments.\r\nNote that changing the distance interval will overwrite any previously fit model for the same linkset and model type.\r\nIn the last line, we calculate the metric \"equivalent connectivity\" (EC) for the entire graph. This metric requires additional parameters :python:`d` and :python:`p`.\r\nOther metrics might not require additional parameters. A list of all the available metrics and their parameters and properties can be viewed in the original `Graphab manual <https://sourcesup.renater.fr/www/graphab/en/documentation.html>`_.\r\n\r\n=======\r\nLicense\r\n=======\r\nThis is free and unencumbered software released into the public domain, as declared in the `LICENSE <https://github.com/ManuelPopp/graphab4py/blob/main/LICENSE>`_ file.\r\n",
"bugtrack_url": null,
"license": "",
"summary": "A Python package to execute Graphab analyses.",
"version": "1.0.5",
"project_urls": {
"Homepage": "https://github.com/manuelpopp/graphab4py",
"Issues": "https://github.com/manuelpopp/graphab4py/issues"
},
"split_keywords": [
"graphab",
"network analysis"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "86111bb2e2ae8920de601aa989afcc8dbecfa515ff4fee8f59465184950f4b51",
"md5": "f260c00207fff197434eeacb90e9d4e3",
"sha256": "9ca7f980431f1a910651409df0c6d54a1c5bf73ec00c476d71eb209cbe6ac638"
},
"downloads": -1,
"filename": "graphab4py-1.0.5-py3-none-any.whl",
"has_sig": false,
"md5_digest": "f260c00207fff197434eeacb90e9d4e3",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8",
"size": 20208,
"upload_time": "2024-02-29T17:40:36",
"upload_time_iso_8601": "2024-02-29T17:40:36.282096Z",
"url": "https://files.pythonhosted.org/packages/86/11/1bb2e2ae8920de601aa989afcc8dbecfa515ff4fee8f59465184950f4b51/graphab4py-1.0.5-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "8b4cfa838de38b119e5cf7086afd4286f7b7168c914b0af89cb240c65e30d915",
"md5": "d2dcbd111183c4698e38002714cef3c7",
"sha256": "bbf0e1014b2b5ebc2a61b5b0af83c383c3ff161f3dd6fd4214444998447a2d7e"
},
"downloads": -1,
"filename": "graphab4py-1.0.5.tar.gz",
"has_sig": false,
"md5_digest": "d2dcbd111183c4698e38002714cef3c7",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 22033,
"upload_time": "2024-02-29T17:40:37",
"upload_time_iso_8601": "2024-02-29T17:40:37.691578Z",
"url": "https://files.pythonhosted.org/packages/8b/4c/fa838de38b119e5cf7086afd4286f7b7168c914b0af89cb240c65e30d915/graphab4py-1.0.5.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-02-29 17:40:37",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "ManuelPopp",
"github_project": "graphab4py",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "graphab4py"
}