Skip to content

Commit

Permalink
Merge b8e983f into 961a7ef
Browse files Browse the repository at this point in the history
  • Loading branch information
smmaurer committed Aug 6, 2019
2 parents 961a7ef + b8e983f commit 434aa29
Show file tree
Hide file tree
Showing 19 changed files with 299 additions and 133 deletions.
55 changes: 23 additions & 32 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,40 +1,31 @@
language: python
sudo: false

python:
- '2.7'
- '3.5'
addons:
apt:
sources:
- ubuntu-toolchain-r-test
packages:
- g++-4.9
- '2.7'
- '3.5'
- '3.6'

# This section can be removed when Python 3.7 is more cleanly supported in Travis
matrix:
include:
- python: '3.7'
dist: xenial
sudo: true

install:
- if [[ "$TRAVIS_PYTHON_VERSION" == "2.7" ]]; then
wget http://repo.continuum.io/miniconda/Miniconda-latest-Linux-x86_64.sh -O miniconda.sh;
else
wget http://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh -O miniconda.sh;
fi
- bash miniconda.sh -b -p $HOME/miniconda
- export PATH="$HOME/miniconda/bin:$PATH"
- hash -r
- conda config --set always_yes yes --set changeps1 no
- conda update -q conda
- conda info -a
- |
conda create -q -n test-environment python=$TRAVIS_PYTHON_VERSION basemap matplotlib numpy pandas pip pytables requests cython scikit-learn "pytest<4.0"
- source activate test-environment
- pip install pytest-cov coveralls pycodestyle osmnet
- CC=gcc-4.9 CXX=g++-4.9 python setup.py install
- pip install .
- pip install -r requirements-dev.txt
- pip list
- pip show pandana

script:
- pycodestyle pandana
- python setup.py test --pytest-args "--cov pandana --cov-report term-missing"
- pycodestyle pandana
- python setup.py test --pytest-args "--cov pandana --cov-report term-missing"

after_success:
- coveralls
- bin/build_docs.sh
notifications:
slack:
secure: a6RjANmfIyE0s3iAz4LPy2wS0bOd+ijGlhh7CJf4bRwVnQPuihDTwzQiT92Uje1rHZVUTY0r5A7QzBcg7QcACs/b3hLQ6nYQ0kIm/beC5DfZUqlyHQAuRl6eK76cEg9Le7bX8OXrjWyfTs9jgH7Z2mRGutMieNXVYQG5wMlEKlU=
- coveralls
- bin/build_docs.sh

env:
global:
secure: CMG0rjBgDBNy5FdfXawaaCCJm9ChzHk7e21ywVhIc1jbVS6lMn6bqwKJUnLaJAyjDhhZuxXTcHy+SALJgbzqLrH4GM5hOOL+8Rf4Jf9ESZzTBryvypRecVnUnk63SpJiq2Ki8maNrOcK1IBUAoFhFzptSgE4MDkxZ0LjsDAums8=
File renamed without changes.
File renamed without changes.
9 changes: 8 additions & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
include ez_setup.py
# files to include in the source distribution on pypi (setup.py and README.md are included automatically)

include CHANGELOG.md
include LICENSE.txt
include README.rst
include requirements-dev.txt
include setup.cfg

recursive-include examples *.ipynb *.py
recursive-include src *.h *.cpp
38 changes: 38 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,41 @@ Related UDST libraries
.. _forum: http://discussion.urbansim.com/
.. _OSMnet: https://github.com/udst/osmnet
.. _UrbanAccess: https://github.com/UDST/urbanaccess


Developer notes
---------------

**Linux installation**


1. Make an installation to obtain file `cyaccess.cpp`. Errors may occur, ignore them:

.. code-block::
git clone git@github.com:UDST/pandana.git
git checkout develop
virtualenv venv --python=python3.6 numpy brewer2mpl tables
source venv/bin/activate
cd pandana
pip install .
CC=gcc CXX=g++ python setup.py develop
This will generate the file `cyaccess.cpp` within `src/`

2. In your final project directory install the `pandana` develop branch

.. code-block::
git clone git@github.com:UDST/pandana.git
virtualenv venv --python=python3.6 numpy brewer2mpl tables
source venv/bin/activate
cd pandana
Copy file `cyaccess.cpp` from previous `pandana` installation into `src/`

.. code-block::
CC=gcc CXX=g++ python setup.py develop
4 changes: 0 additions & 4 deletions bin/build_docs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,6 @@ if [ "$TRAVIS_REPO_SLUG" == "UDST/pandana" ] && \
[ "$TRAVIS_PULL_REQUEST" == "false" ] && \
[ "$ACTUAL_TRAVIS_JOB_NUMBER" == "1" ]; then

echo "Installing dependencies"
conda install --yes --quiet sphinx numpydoc
pip install sphinx_rtd_theme

echo "Building docs"
cd docs
make clean
Expand Down
4 changes: 2 additions & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@
# built documents.
#
# The short X.Y version.
version = '0.4.1'
version = '0.4.2'
# The full version, including alpha/beta/rc tags.
release = '0.4.1'
release = '0.4.2'

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand Down
13 changes: 11 additions & 2 deletions docs/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,18 @@ correctly. Check the compile output for the gcc compiler you specified
with :code:`CC` and :code:`CXX` - you might need to change the name slightly depending
on your platform - for instance :code:`g++-mp-4.9` or :code:`g++-4.8`.

Installation on Windows
-----------------------
`Microsoft Visual C++ 2008 SP1 Redistributable Package (x64)
<https://www.microsoft.com/en-us/download/details.aspx?id=2092>`_ is required for running
Pandana on Windows. This package enables parallel computations with `OpenMP`_. Building Pandana
from source also requires `Microsoft Visual C++ Compiler for Python 2.7
<https://www.microsoft.com/en-us/download/details.aspx?id=44266>`_.


.. _Anaconda: http://docs.continuum.io/anaconda/
.. _pip: https://pip.pypa.io/en/latest/
.. _OpenMP: http://openmp.org/wp/
.. _OpenMP: http://openmp.org/
.. _GNU GCC: https://gcc.gnu.org/
.. _Homebrew: http://brew.sh/
.. _MacPorts: https://www.macports.org/
Expand All @@ -115,4 +124,4 @@ on your platform - for instance :code:`g++-mp-4.9` or :code:`g++-4.8`.
.. _numpy: http://www.numpy.org/
.. _pandas: http://pandas.pydata.org/
.. _tables: http://www.pytables.org/
.. _osmnet: http://github.com/udst/osmnet
.. _osmnet: http://github.com/udst/osmnet
2 changes: 1 addition & 1 deletion pandana/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from .network import Network

version = __version__ = '0.4.1'
version = __version__ = '0.4.2'
78 changes: 69 additions & 9 deletions pandana/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,24 @@

from .cyaccess import cyaccess
from .loaders import pandash5 as ph5
import warnings


def reserve_num_graphs(num):
raise Exception("reserve_num_graphs is no longer required - remove from your code")
"""
This function was previously used to reserve memory space for multiple graphs.
It is no longer needed in Pandana 0.4+, and will be removed in a future version.
Parameters
----------
num : int
Number of graph to be reserved in memory
"""
warnings.warn(
"Function reserve_num_graphs() is no longer needed in Pandana 0.4+\
and will be removed in a future version",
DeprecationWarning
)
return None


class Network:
Expand Down Expand Up @@ -54,7 +68,6 @@ class Network:

def __init__(self, node_x, node_y, edge_from, edge_to, edge_weights,
twoway=True):

nodes_df = pd.DataFrame({'x': node_x, 'y': node_y})
edges_df = pd.DataFrame({'from': edge_from, 'to': edge_to}).\
join(edge_weights)
Expand All @@ -76,19 +89,19 @@ def __init__(self, node_x, node_y, edge_from, edge_to, edge_weights,
index=nodes_df.index)

edges = pd.concat([self._node_indexes(edges_df["from"]),
self._node_indexes(edges_df["to"])], axis=1)
self._node_indexes(edges_df["to"])], axis=1)

self.net = cyaccess(self.node_idx.values,
nodes_df.astype('double').as_matrix(),
edges.as_matrix(),
nodes_df.astype('double').values,
edges.values,
edges_df[edge_weights.columns].transpose()
.astype('double')
.as_matrix(),
.values,
twoway)

self._twoway = twoway

self.kdtree = KDTree(nodes_df.as_matrix())
self.kdtree = KDTree(nodes_df.values)

@classmethod
def from_hdf5(cls, filename):
Expand Down Expand Up @@ -368,7 +381,7 @@ def get_node_ids(self, x_col, y_col, mapping_distance=None):
"""
xys = pd.DataFrame({'x': x_col, 'y': y_col})

distances, indexes = self.kdtree.query(xys.as_matrix())
distances, indexes = self.kdtree.query(xys.values)
indexes = np.transpose(indexes)[0]
distances = np.transpose(distances)[0]

Expand Down Expand Up @@ -455,7 +468,35 @@ def plot(

return bmap, fig, ax

def set_pois(self, category, maxdist, maxitems, x_col, y_col):
def init_pois(self, num_categories, max_dist, max_pois):
"""
Initialize the point of interest infrastructure.
This is no longer needed in Pandana 0.4+ and will be removed in a future version
Parameters
----------
num_categories : int
Number of categories of POIs
max_dist : float
Maximum distance that will be tested to nearest POIs. This will
usually be a distance unit in meters however if you have
customized the impedance this could be in other
units such as utility or time etc.
max_pois :
Maximum number of POIs to return in the nearest query
"""
self.num_categories = num_categories
self.max_dist = max_dist
self.max_pois = max_pois
warnings.warn(
"Method init_pois() is no longer needed in Pandana 0.4+ and will be removed in a \
future version; maxdist and maxitems should now be passed to set_pois()",
DeprecationWarning
)
return None

def set_pois(self, category=None, maxdist=None, maxitems=None, x_col=None, y_col=None):
"""
Set the location of all the pois of this category. The pois are
connected to the closest node in the Pandana network which assumes
Expand All @@ -478,7 +519,26 @@ def set_pois(self, category, maxdist, maxitems, x_col, y_col):
Returns
-------
Nothing
"""
# condition to check if missing arguments for keyword arguments using set_pois() from v0.3
if maxitems is None:
print('Reading parameters from init_pois()')
maxitems = self.max_pois

# condition to check for positional arguments in set_pois() from v0.3
elif isinstance(maxitems, type(pd.Series())):
y_col = maxitems
maxitems = self.max_pois

if maxdist is None:
print('Reading parameters from init_pois()')
maxdist = self.max_dist

elif isinstance(maxdist, type(pd.Series())):
x_col = maxdist
maxdist = self.max_dist

if category not in self.poi_category_names:
self.poi_category_names.append(category)

Expand Down
38 changes: 33 additions & 5 deletions pandana/tests/test_pandana.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,6 @@ def random_x_y(sample_osm, ssize):
return x, y


def test_reserve_num_graphs_raises(sample_osm):
with pytest.raises(Exception):
pdna.reserve_num_graphs(1)


def test_agg_variables_accuracy(sample_osm):
net = sample_osm

Expand Down Expand Up @@ -318,7 +313,40 @@ def test_pois2(second_sample_osm):
net2.nearest_pois(2000, "restaurants", num_pois=10)


def test_pois_pandana3(second_sample_osm):
net2 = second_sample_osm

ssize = 50
np.random.seed(0)
x, y = random_x_y(second_sample_osm, ssize)
pdna.reserve_num_graphs(1)

net2.init_pois(num_categories=1, max_dist=2000, max_pois=10)

# make sure poi searches work on second graph
net2.set_pois(category="restaurants", x_col=x, y_col=y)

net2.nearest_pois(2000, "restaurants", num_pois=10)


def test_pois_pandana3_pos_args(second_sample_osm):
net2 = second_sample_osm

ssize = 50
np.random.seed(0)
x, y = random_x_y(second_sample_osm, ssize)
pdna.reserve_num_graphs(1)

net2.init_pois(1, 2000, 10)

# make sure poi searches work on second graph
net2.set_pois("restaurants", x, y)

net2.nearest_pois(2000, "restaurants", num_pois=10)

# test items are sorted


def test_sorted_pois(sample_osm):
net = sample_osm

Expand Down
9 changes: 9 additions & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# requirements for development and testing

coveralls
numpydoc
pycodestyle
pytest>=3.6,<4.0
pytest-cov
sphinx
sphinx_rtd_theme

0 comments on commit 434aa29

Please sign in to comment.