{ "info": { "author": "Benny Chin", "author_email": "wcchin.88@gmal.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 3 - Alpha", "Intended Audience :: Science/Research", "License :: OSI Approved :: MIT License", "Programming Language :: Python :: 2.7", "Topic :: Scientific/Engineering :: GIS" ], "description": "# Geographical PageRank Algorithms\n\nA set of algorithms for measuring concentration distribution in a spatial network.\n\nLink to pypi: https://pypi.python.org/pypi/GPRas\n\n==============================\n\n## published article\nfor more detail info and applications\n\narticle:\nChin, W. C. B., & Wen, T. H. (2015). Geographically Modified PageRank Algorithms: Identifying the Spatial Concentration of Human Movement in a Geospatial Network. PLoS ONE 10(10): e0139509. DOI:10.1371/journal.pone.0139509.\n\narticle authors:\n**Wei-Chien-Benny Chin**, Tzai-Hung Wen\n\nopen access link:\nthe article (PLoSONE)\n\n==============================\n\n## Intro.\nThe algorithm can be used to calculate these from a spatial network, i.e. network with x, y coordinates that can be used to calculate distance (i.e. projected accordingly from longitude and latitude):\n\n- PR\n- WPR\n- DDPR (proposed in the PloSOne article above)\n- GPR (proposed in the PloSOne article above)\n- eDDPR (proposed in the PloSOne article above)\n- eGPR (proposed in the PloSOne article above)\n\n==============================\n\n## dependencies\n\n- numpy\n- pandas\n- geopandas\n- shapely\n- networkx\n\n==============================\n\n## installing GPRas\n\non windows:\n\ninstall shapely first. can use conda if you are using anaconda(miniconda).\n\n```\nconda install -c scitools shapely=1.5.13\n```\n\nGeopandas is needed to be installed before installing this, which could be hard to install.\nFirst download these from here: http://www.lfd.uci.edu/~gohlke/pythonlibs/\n\n- GDAL\n- pyproj\n- Fiona\n\nThen, install them with pip install\n\n```sh\npip install xxx-GDAL--.whl\npip install xxx-pyproj--.whl\npip install xxx-Fiona--.whl\n\n```\n\nThen, install GPRas\n\n```sh\npip install GPRas\n```\n\n==============================\n\n## Usage\n\nimport the module\n\n```python\nimport GPRas as gpr\n\n```\n\n### data input and create the spatial graph concentration object\nTwo ways of data input: csv file, nx.Graph object\n\n**for csv file**:\nprepare the file paths and file setup info\n\n```python\nnodefile = 'test_data/TP_nodes.csv'\nlinkfile = 'test_data/TP_links.csv'\nnode_filesetup = {'node_id':'nid', 'xcor':'xcor', 'ycor':'ycor'}\nlink_filesetup = {'ori':'ori', 'des':'des', 'weight':'time'}\n```\n\ncreate the spatial_graph object\n\n```python\nsg = gpr.GPRas()\n```\n\nset the dataset from csv files\n```python\nsg.dataset.from_csv(nodefile, linkfile, node_filesetup, link_filesetup)\n```\n\n**for nx.Graph object**\n```python\nimport networkx as nx\nimport pandas as pd ## just for the reading of file before creating nx.Graph\nndf = pd.read_csv(nodefile)\nnii = ndf[node_filesetup['node_id']].tolist()\nnxx = ndf[node_filesetup['xcor']].tolist()\nnyy = ndf[node_filesetup['ycor']].tolist()\nnodes_lis = [ (ii, dict(xxx=xx,yyy=yy)) for ii,xx,yy in zip(nii,nxx,nyy) ]\nedf = pd.read_csv(linkfile)\neoo = edf[link_filesetup['ori']].tolist()\nedd = edf[link_filesetup['des']].tolist()\nedges_lis = [ (oo,dd) for oo,dd in zip(eoo,edd) ]\n\nG = nx.Graph()\nG.add_nodes_from(nodes_lis)\nag.add_edges_from(edges_lis)\n\n## graph setup info\nnode_setup = dict(xcor='xxx', ycor='yyy') ## x,y columns from the nodes attr.\nlink_setup = None\n\nsg = sgc()\nsg.dataset.from_nx(ag, node_setup, link_setup)\n```\n\n### prepare and calculate\nFirst, initialize the parameters\n\n```python\nsg.Initialize(iteration=5000, alpha=1., beta=1., gamma=1.)\n```\n\nCalculate all of them (6 PRs) using the above parameter\n```python\nsg.CalculateAll()\n```\n\nCalculate each of them using updated parameters\n```python\nsg.PR()\nsg.WPR(alpha=2, update=True)\nsg.DDPR(beta=2, update=True)\nsg.GPR(alpha=3, beta=2, update=True)\nsg.eDDPR(gamma=0.6, update=True)\nsg.eGPR(alpha=3, gamma=0.2, update=True)\n```\nthese calculation will change the parameters for summary output, but not the default paramters (for calculation with no paramter setup, eg. alpha=None), which are set from the initialization.\n\n### get the results in Pandas DataFrame format\nget summary df\n\n```python\nsummary_df = sg.get_summary()\nprint summary_df.head()\n```\n\nget the nodes concentration results\n\n```python\nresult_df = sg.get_results() ## default to all 6\nprint result_df.head()\n\npart_result_df = sg.get_results(items=['pr', 'wpr']) ## export only PR and WPR\nprint part_result_df.head()\n```\n\n### export results\nthe results can be export directly to csv format and shapfile format\n\n**summary table**\n\n```python\nsg.output_summary(filename='result/temp_summary.csv')\n```\n\n**to csv file**\n```python\nsg.to_csv(filename='result/temp_output_dd_g.csv', items=['ddpr','gpr'])\n\n# also same as to_csv() with items=None\nsg.All_to_csv(filename='result/temp_output.csv')\n```\n\n**to shp file**\nprepare a crs string, or it will be default to None\n```python\ncrs67 = '+proj=tmerc +lat_0=0 +lon_0=121 +k=0.9999 +x_0=250000 +y_0=0 +ellps=aust_SA +towgs84=-752,-358,-179,-0.0000011698,0.0000018398,0.0000009822,0.00002329 +units=m +no_defs'\n```\n\nexport the files, which include a point shpfile for nodes and the concentration results, and a line shpfile for edge (no result inside, just for mapping)\n\noutput two of the results (PR and WPR) into one file\n\n```python\nsg.to_shps(filename_prefix='result/temp_shp_pr_wpr', crs=crs67, items=['pr','wpr'])\n```\n\noutput all 6 PRs\n\n```python\nsg.All_to_shps(filename_prefix='result/temp_shp', crs=crs67)\n```\n\n### to networkx graph object\nsimilar to the previous export\n\n```python\nag,pos = sg.to_nx() ## default to all 6 PRs\n\nag,pos = sg.to_nx(items=[\"DDPR\"])\n```\n\ndemo for drawing the networkx object\n```python\nimport matplotlib.pyplot as plt\n\nss = []\nfor n,d in ag.nodes_iter(data=True):\n ss.append(d['DDPR_score']*5000.)\n\nfig,ax = plt.subplots()\nnx.draw_networkx_nodes(ag, pos=pos, node_size=ss)\nnx.draw_networkx_edges(ag, pos=pos, alpha=0.3)\nax.set_aspect('equal')\nplt.show()\n```\n\n==============================\n## file structure\n\n```sh\nGeographical PageRank Algorithms\n.\n\u251c\u2500\u2500 build\n\u2502\u00a0\u00a0 \u251c\u2500\u2500 bdist.linux-x86_64\n\u2502\u00a0\u00a0 \u2514\u2500\u2500 lib\n\u2502\u00a0\u00a0 \u2514\u2500\u2500 GPRas\n\u2502\u00a0\u00a0 \u251c\u2500\u2500 GPRa\n\u2502\u00a0\u00a0 \u2502\u00a0\u00a0 \u251c\u2500\u2500 GPR_algorithms.py\n\u2502\u00a0\u00a0 \u2502\u00a0\u00a0 \u251c\u2500\u2500 __init__.py\n\u2502\u00a0\u00a0 \u2502\u00a0\u00a0 \u251c\u2500\u2500 input_func.py\n\u2502\u00a0\u00a0 \u2502\u00a0\u00a0 \u251c\u2500\u2500 input_funcs\n\u2502\u00a0\u00a0 \u2502\u00a0\u00a0 \u2502\u00a0\u00a0 \u251c\u2500\u2500 DataImport_nx.py\n\u2502\u00a0\u00a0 \u2502\u00a0\u00a0 \u2502\u00a0\u00a0 \u251c\u2500\u2500 FileReading_csv.py\n\u2502\u00a0\u00a0 \u2502\u00a0\u00a0 \u2502\u00a0\u00a0 \u2514\u2500\u2500 __init__.py\n\u2502\u00a0\u00a0 \u2502\u00a0\u00a0 \u251c\u2500\u2500 output_func.py\n\u2502\u00a0\u00a0 \u2502\u00a0\u00a0 \u2514\u2500\u2500 output_funcs\n\u2502\u00a0\u00a0 \u2502\u00a0\u00a0 \u251c\u2500\u2500 __init__.py\n\u2502\u00a0\u00a0 \u2502\u00a0\u00a0 \u251c\u2500\u2500 to_csv.py\n\u2502\u00a0\u00a0 \u2502\u00a0\u00a0 \u251c\u2500\u2500 to_nx.py\n\u2502\u00a0\u00a0 \u2502\u00a0\u00a0 \u2514\u2500\u2500 to_shps.py\n\u2502\u00a0\u00a0 \u251c\u2500\u2500 GPRas.py\n\u2502\u00a0\u00a0 \u2514\u2500\u2500 __init__.py\n\u251c\u2500\u2500 dist\n\u2502\u00a0\u00a0 \u251c\u2500\u2500 GPRas-0.1.0-py2.7.egg\n\u2502\u00a0\u00a0 \u251c\u2500\u2500 GPRas-0.1.0-py2-none-any.whl\n\u2502\u00a0\u00a0 \u2514\u2500\u2500 GPRas-0.1.0.tar.gz\n\u251c\u2500\u2500 GPRas\n\u2502\u00a0\u00a0 \u251c\u2500\u2500 example\n\u2502\u00a0\u00a0 \u2502\u00a0\u00a0 \u251c\u2500\u2500 example_nx.py\n\u2502\u00a0\u00a0 \u2502\u00a0\u00a0 \u251c\u2500\u2500 example.py\n\u2502\u00a0\u00a0 \u2502\u00a0\u00a0 \u251c\u2500\u2500 result\n\u2502\u00a0\u00a0 \u2502\u00a0\u00a0 \u2502\u00a0\u00a0 \u2514\u2500\u2500 demo results\n\u2502\u00a0\u00a0 \u2502\u00a0\u00a0 \u2514\u2500\u2500 test_data\n\u2502\u00a0\u00a0 \u2502\u00a0\u00a0 \u251c\u2500\u2500 KH_links.csv\n\u2502\u00a0\u00a0 \u2502\u00a0\u00a0 \u251c\u2500\u2500 KH_nodes.csv\n\u2502\u00a0\u00a0 \u2502\u00a0\u00a0 \u251c\u2500\u2500 TC_links.csv\n\u2502\u00a0\u00a0 \u2502\u00a0\u00a0 \u251c\u2500\u2500 TC_nodes.csv\n\u2502\u00a0\u00a0 \u2502\u00a0\u00a0 \u251c\u2500\u2500 TP_links.csv\n\u2502\u00a0\u00a0 \u2502\u00a0\u00a0 \u2514\u2500\u2500 TP_nodes.csv\n\u2502\u00a0\u00a0 \u251c\u2500\u2500 GPRa\n\u2502\u00a0\u00a0 \u2502\u00a0\u00a0 \u251c\u2500\u2500 GPR_algorithms.py\n\u2502\u00a0\u00a0 \u2502\u00a0\u00a0 \u251c\u2500\u2500 __init__.py\n\u2502\u00a0\u00a0 \u2502\u00a0\u00a0 \u251c\u2500\u2500 input_func.py\n\u2502\u00a0\u00a0 \u2502\u00a0\u00a0 \u251c\u2500\u2500 input_funcs\n\u2502\u00a0\u00a0 \u2502\u00a0\u00a0 \u2502\u00a0\u00a0 \u251c\u2500\u2500 DataImport_nx.py\n\u2502\u00a0\u00a0 \u2502\u00a0\u00a0 \u2502\u00a0\u00a0 \u251c\u2500\u2500 FileReading_csv.py\n\u2502\u00a0\u00a0 \u2502\u00a0\u00a0 \u2502\u00a0\u00a0 \u2514\u2500\u2500 __init__.py\n\u2502\u00a0\u00a0 \u2502\u00a0\u00a0 \u251c\u2500\u2500 output_func.py\n\u2502\u00a0\u00a0 \u2502\u00a0\u00a0 \u2514\u2500\u2500 output_funcs\n\u2502\u00a0\u00a0 \u2502\u00a0\u00a0 \u251c\u2500\u2500 __init__.py\n\u2502\u00a0\u00a0 \u2502\u00a0\u00a0 \u251c\u2500\u2500 to_csv.py\n\u2502\u00a0\u00a0 \u2502\u00a0\u00a0 \u251c\u2500\u2500 to_nx.py\n\u2502\u00a0\u00a0 \u2502\u00a0\u00a0 \u2514\u2500\u2500 to_shps.py\n\u2502\u00a0\u00a0 \u251c\u2500\u2500 GPRas.py\n\u2502\u00a0\u00a0 \u2514\u2500\u2500 __init__.py\n\u251c\u2500\u2500 GPRas.egg-info\n\u2502\u00a0\u00a0 \u251c\u2500\u2500 dependency_links.txt\n\u2502\u00a0\u00a0 \u251c\u2500\u2500 PKG-INFO\n\u2502\u00a0\u00a0 \u251c\u2500\u2500 requires.txt\n\u2502\u00a0\u00a0 \u251c\u2500\u2500 SOURCES.txt\n\u2502\u00a0\u00a0 \u2514\u2500\u2500 top_level.txt\n\u251c\u2500\u2500 LICENSE.txt\n\u251c\u2500\u2500 MANIFEST.in\n\u251c\u2500\u2500 README.md\n\u2514\u2500\u2500 setup.py\n\n```", "description_content_type": null, "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://bitbucket.org/wcchin/gpras", "keywords": "spatial network concentration", "license": "", "maintainer": "", "maintainer_email": "", "name": "GPRas", "package_url": "https://pypi.org/project/GPRas/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/GPRas/", "project_urls": { "Homepage": "https://bitbucket.org/wcchin/gpras" }, "release_url": "https://pypi.org/project/GPRas/0.1.1/", "requires_dist": [ "geopandas", "networkx", "numpy", "pandas", "shapely" ], "requires_python": "", "summary": "algorithms for measuring concentration distribution in a spatial network.", "version": "0.1.1" }, "last_serial": 2650040, "releases": { "0.1.0": [ { "comment_text": "", "digests": { "md5": "d18c5aa5e1a37b2d2918ca811c4fe3ac", "sha256": "0911434cc4be2c9055088db02abf8b4899d0659219165b11511aa3538d86735b" }, "downloads": -1, "filename": "GPRas-0.1.0-py2.7.egg", "has_sig": false, "md5_digest": "d18c5aa5e1a37b2d2918ca811c4fe3ac", "packagetype": "bdist_egg", "python_version": "2.7", "requires_python": null, "size": 28667, "upload_time": "2017-02-17T08:55:32", "url": "https://files.pythonhosted.org/packages/b4/90/3147e4fd281bd9ca9457a90c46feafa346cdd105793dbfccf51aa60e135e/GPRas-0.1.0-py2.7.egg" }, { "comment_text": "", "digests": { "md5": "0a45e3b1d345c20edf827d5f1debfd3a", "sha256": "4aa1f8fd88e6edc64348225c98f9df447550e672430d0de2522dccde3828cd5f" }, "downloads": -1, "filename": "GPRas-0.1.0-py2-none-any.whl", "has_sig": false, "md5_digest": "0a45e3b1d345c20edf827d5f1debfd3a", "packagetype": "bdist_wheel", "python_version": "py2", "requires_python": null, "size": 13251, "upload_time": "2017-02-17T08:55:30", "url": "https://files.pythonhosted.org/packages/b0/da/84677c58c297c77016e51e093ad718822f7242d5bd91f427afbea3758b6a/GPRas-0.1.0-py2-none-any.whl" }, { "comment_text": "", "digests": { "md5": "12bb6f7874340df847cf8bb1651102eb", "sha256": "864a8606206455acc5352a4923baf7e8d6a49c887e8c6624c08c6e9a640725bf" }, "downloads": -1, "filename": "GPRas-0.1.0.tar.gz", "has_sig": false, "md5_digest": "12bb6f7874340df847cf8bb1651102eb", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7571, "upload_time": "2017-02-17T08:55:34", "url": "https://files.pythonhosted.org/packages/4f/e7/3c21a99ac499c5210f8a65fd363fc6354fd49451edd93909171b1fe1ab98/GPRas-0.1.0.tar.gz" } ], "0.1.1": [ { "comment_text": "", "digests": { "md5": "b3f4c42c923f8ddf5a1f9cef22e03e55", "sha256": "029d71b94351d339d5c801b97e3775831612e540ba6ce562d5be4366d5a8a2f4" }, "downloads": -1, "filename": "GPRas-0.1.1-py2-none-any.whl", "has_sig": false, "md5_digest": "b3f4c42c923f8ddf5a1f9cef22e03e55", "packagetype": "bdist_wheel", "python_version": "py2", "requires_python": null, "size": 18866, "upload_time": "2017-02-17T17:05:03", "url": "https://files.pythonhosted.org/packages/95/28/53bc44d6545d57356396cec9f740e17713d59c2523ff8ed55f9a17a33161/GPRas-0.1.1-py2-none-any.whl" }, { "comment_text": "", "digests": { "md5": "9025022289d8dded7f40c39492932de0", "sha256": "ecd6be526e99bb4fbf1502d214ec04eefd3d58df8c045b539bc1f16fa3962580" }, "downloads": -1, "filename": "GPRas-0.1.1.tar.gz", "has_sig": false, "md5_digest": "9025022289d8dded7f40c39492932de0", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 10323, "upload_time": "2017-02-17T17:05:06", "url": "https://files.pythonhosted.org/packages/0f/94/dc05f4b2942c79e2846365a07bf32ad00453881bb106f26399192feea133/GPRas-0.1.1.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "b3f4c42c923f8ddf5a1f9cef22e03e55", "sha256": "029d71b94351d339d5c801b97e3775831612e540ba6ce562d5be4366d5a8a2f4" }, "downloads": -1, "filename": "GPRas-0.1.1-py2-none-any.whl", "has_sig": false, "md5_digest": "b3f4c42c923f8ddf5a1f9cef22e03e55", "packagetype": "bdist_wheel", "python_version": "py2", "requires_python": null, "size": 18866, "upload_time": "2017-02-17T17:05:03", "url": "https://files.pythonhosted.org/packages/95/28/53bc44d6545d57356396cec9f740e17713d59c2523ff8ed55f9a17a33161/GPRas-0.1.1-py2-none-any.whl" }, { "comment_text": "", "digests": { "md5": "9025022289d8dded7f40c39492932de0", "sha256": "ecd6be526e99bb4fbf1502d214ec04eefd3d58df8c045b539bc1f16fa3962580" }, "downloads": -1, "filename": "GPRas-0.1.1.tar.gz", "has_sig": false, "md5_digest": "9025022289d8dded7f40c39492932de0", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 10323, "upload_time": "2017-02-17T17:05:06", "url": "https://files.pythonhosted.org/packages/0f/94/dc05f4b2942c79e2846365a07bf32ad00453881bb106f26399192feea133/GPRas-0.1.1.tar.gz" } ] }