Skip to content

Commit

Permalink
Merge pull request #676 from jGaboardi/update_warnings
Browse files Browse the repository at this point in the history
Update warnings, etc.
  • Loading branch information
jGaboardi authored Oct 11, 2022
2 parents d34bfff + 227b3c3 commit 8bd68d5
Show file tree
Hide file tree
Showing 14 changed files with 259 additions and 240 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build_docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
strategy:
matrix:
os: ['ubuntu-latest']
environment-file: [ci/39.yaml]
environment-file: [ci/310.yaml]
experimental: [false]
defaults:
run:
Expand Down
22 changes: 16 additions & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
repos:
- repo: https://github.com/psf/black
rev: 22.6.0
hooks:
- id: black
language_version: python3
repos:
- repo: https://github.com/pycqa/isort
rev: 5.10.1
hooks:
- id: isort
language_version: python3
- repo: https://github.com/pycqa/flake8
rev: 5.0.4
hooks:
- id: flake8
language_version: python3
- repo: https://github.com/psf/black
rev: 22.6.0
hooks:
- id: black
language_version: python3
6 changes: 0 additions & 6 deletions ci/39.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,3 @@ dependencies:
- pytest-xdist
# optional
- geopandas>=0.7.0
# for docs build action (this env only)
- nbsphinx
- numpydoc
- sphinx
- sphinxcontrib-bibtex
- sphinx_bootstrap_theme
12 changes: 7 additions & 5 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
# directories to sys.path here. If the directory is relative to the documentation root,
# use os.path.abspath to make it absolute, like shown here.

import sys, os
import os
import sys

import sphinx_bootstrap_theme

# import your package to obtain the version info to display on the docs website
Expand Down Expand Up @@ -189,8 +191,8 @@
(
master_doc,
"%s.tex" % project,
u"%s Documentation" % project,
u"pysal developers",
"%s Documentation" % project,
"pysal developers",
"manual",
)
]
Expand All @@ -200,7 +202,7 @@

# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [(master_doc, "%s" % project, u"%s Documentation" % project, [author], 1)]
man_pages = [(master_doc, "%s" % project, "%s Documentation" % project, [author], 1)]


# -- Options for Texinfo output -------------------------------------------
Expand All @@ -212,7 +214,7 @@
(
master_doc,
"%s" % project,
u"%s Documentation" % project,
"%s Documentation" % project,
author,
"%s" % project,
"SPAtial GrapHs: nETworks, Topology, & Inference",
Expand Down
1 change: 1 addition & 0 deletions requirements_tests.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ pytest-cov
pytest-timeout
pytest-xdist
codecov
coverage
twine
wheel
5 changes: 5 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,8 @@ versionfile_source = spaghetti/_version.py
versionfile_build = spaghetti/_version.py
tag_prefix = v
parentdir_prefix = spaghetti-

[flake8]
# Black enforces 88 characters line length
max_line_length = 88
exclude = *__init__.py, docs/conf.py, versioneer.py, spaghetti/_version.py
2 changes: 2 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from distutils.command.build_py import build_py

from setuptools import setup

import versioneer

package = "spaghetti"
Expand Down
13 changes: 9 additions & 4 deletions spaghetti/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,15 @@
# `spaghetti` --- Spatial Graphs: Networks, Topology, & Inference
"""

from .network import Network, PointPattern, SimulatedPointPattern
from .network import extract_component, spanning_tree
from .network import element_as_gdf, regular_lattice

from . import _version
from .network import (
Network,
PointPattern,
SimulatedPointPattern,
element_as_gdf,
extract_component,
regular_lattice,
spanning_tree,
)

__version__ = _version.get_versions()["version"]
2 changes: 1 addition & 1 deletion spaghetti/analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def validatedistribution(self):
"""Ensure the statistical distribution is supported."""

valid_distributions = ["uniform"]
if not self.distribution in valid_distributions:
if self.distribution not in valid_distributions:
msg = "%s distribution not currently supported." % self.distribution
raise RuntimeError(msg)

Expand Down
69 changes: 38 additions & 31 deletions spaghetti/network.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
from collections import defaultdict, OrderedDict
import copy
import os
import pickle
import warnings
from collections import OrderedDict, defaultdict
from itertools import islice
import copy, os, pickle, warnings

import esda
import numpy
from libpysal import cg, weights
from libpysal.common import requires

from .analysis import GlobalAutoK
from . import util
from libpysal import cg, examples, weights
from libpysal.common import requires
from .analysis import GlobalAutoK

try:
from libpysal import open
Expand All @@ -32,7 +35,7 @@
"requiring network and point pattern input as ``libpysal.cg`` "
"geometries should prepare for this simply by converting "
"to ``shapely`` geometries."
)
)
warnings.warn(f"{dep_msg}", FutureWarning)


Expand All @@ -45,7 +48,7 @@ class Network:
Parameters
----------
in_data : {str, iterable (list, tuple, numpy.ndarray), libpysal.cg.Chain, geopandas.GeoDataFrame}
in_data : {str, iterable, libpysal.cg.Chain, geopandas.GeoDataFrame}
The input geographic data. Either (1) a path to a shapefile
(str); (2) an iterable containing ``libpysal.cg.Chain``
objects; (3) a single ``libpysal.cg.Chain``; or
Expand Down Expand Up @@ -188,7 +191,7 @@ class Network:
network structure will generally have (1) more vertices and links than may expected,
and, (2) many degree-2 vertices, which differs from a truly graph-theoretic object.
This is demonstrated in the
`Caveats Tutorial <https://pysal.org/spaghetti/notebooks/caveats.html#4.-Understanding-network-generation>`_.
`Caveats Tutorial <https://pysal.org/spaghetti/notebooks/caveats.html>`_.
See :cite:`Cliff1981`, :cite:`Tansel1983a`,
:cite:`AhujaRavindraK`, :cite:`Labbe1995`,
Expand Down Expand Up @@ -314,7 +317,7 @@ def __init__(
as_graph = False
network_weightings = False

if weightings == True:
if weightings:
# set network arc weights to length if weights are
# desired, but no other input in given
weightings = self.arc_lengths
Expand Down Expand Up @@ -437,7 +440,7 @@ def identify_components(self, w, graph=False):
c2l_ = component2link[cpl]
arclens_ = self.arc_lengths.items()
component_lengths[cpl] = sum([v for k, v in arclens_ if k in c2l_])
component_vertices[cpl] = list(set([v for l in c2l_ for v in l]))
component_vertices[cpl] = list(set([v for link in c2l_ for v in link]))
component_vertex_count[cpl] = len(component_vertices[cpl])

# longest and largest components
Expand Down Expand Up @@ -1011,7 +1014,7 @@ def distancebandweights(self, threshold, n_processes=1, gen_tree=False):
>>> ntw = spaghetti.Network(in_data=streets_file)
Create a contiguity-based ``W`` object based on network distance, ``500``
`US feet in this case <https://github.com/pysal/libpysal/blob/master/libpysal/examples/geodanet/streets.prj>`_.
US feet in this case.
>>> w = ntw.distancebandweights(threshold=500)
Expand Down Expand Up @@ -1409,12 +1412,12 @@ def _newpoint_coords(self, arc, distance):
# if the horizontal direction is negative from
# vertex 1 to vertex 2 on the euclidean plane
if x1 > x2:
x0 = x1 - distance / numpy.sqrt(1 + m ** 2)
x0 = x1 - distance / numpy.sqrt(1 + m**2)

# if the horizontal direction is positive from
# vertex 1 to vertex 2 on the euclidean plane
elif x1 < x2:
x0 = x1 + distance / numpy.sqrt(1 + m ** 2)
x0 = x1 + distance / numpy.sqrt(1 + m**2)

# calculate the (y) coordinate
y0 = m * (x0 - x1) + y1
Expand Down Expand Up @@ -2290,7 +2293,7 @@ def split_arcs(self, split_param, split_by="distance", w_components=True):
>>> ntw = spaghetti.Network(examples.get_path("streets.shp"))
Split the network into a segments of 200 distance units in length
(`US feet in this case <https://github.com/pysal/libpysal/blob/master/libpysal/examples/geodanet/streets.prj>`_.).
(US feet in this case).
This will include "remainder" segments unless the network is
comprised of arcs with lengths exactly divisible by ``distance``.
Expand Down Expand Up @@ -2319,6 +2322,12 @@ def split_arcs(self, split_param, split_by="distance", w_components=True):
"""

def int_coord(c):
"""convert coordinates for integers if possible
e.g., (1.0, 0.5) --> (1, 0.5)
"""
return int(c) if (type(c) == float and c.is_integer()) else c

# catch invalid split types
split_by = split_by.lower()
valid_split_types = ["distance", "count"]
Expand All @@ -2339,10 +2348,6 @@ def split_arcs(self, split_param, split_by="distance", w_components=True):
msg += f"Currently 'split_param' is set to {split_param}."
raise TypeError(msg)

# convert coordinates for integers if possible
# e.g., (1.0, 0.5) --> (1, 0.5)
int_coord = lambda c: int(c) if (type(c) == float and c.is_integer()) else c

# create new shell network instance
split_network = Network()

Expand Down Expand Up @@ -2487,7 +2492,8 @@ def GlobalAutoK(
upperbound=None,
):
r"""Compute a global auto :math:`K`-function based on a network constrained
cost matrix through `Monte Carlo simulation <https://en.wikipedia.org/wiki/Monte_Carlo_method>`_
cost matrix through
`Monte Carlo simulation <https://en.wikipedia.org/wiki/Monte_Carlo_method>`_
according to the formulation adapted from
:cite:`doi:10.1002/9780470549094.ch5`. See the **Notes**
section for further description.
Expand Down Expand Up @@ -2525,11 +2531,12 @@ def GlobalAutoK(
\displaystyle K(r)=\frac{\sum^n_{i=1} \#[\hat{A} \in D(a_i, r)]}{n\lambda},
where $n$ is the set cardinality of :math:`A`, :math:`\hat{A}` is the subset of
observations in :math:`A` that are within :math:`D` units of distance from :math:`a_i`
(each single observation in :math:`A`), and :math:`r` is the range of distance
values over which the :math:`K`-function is calculated. The :math:`\lambda` term
is the intensity of observations along the network, calculated as:
where $n$ is the set cardinality of :math:`A`, :math:`\hat{A}` is the
subset of observations in :math:`A` that are within :math:`D` units of
distance from :math:`a_i` (each single observation in :math:`A`), and :math:`r`
is the range of distance values over which the :math:`K`-function is
calculated. The :math:`\lambda` term is the intensity of observations
along the network, calculated as:
.. math::
Expand All @@ -2541,7 +2548,8 @@ def GlobalAutoK(
distance buffers :math:`D \in r`. The :math:`K`-function improves upon
nearest-neighbor distance measures through the analysis of all neighbor
distances. For an explanation on how to interpret the results of the
:math:`K`-function see the `Network Spatial Dependence tutorial <https://pysal.org/spaghetti/notebooks/network-spatial-dependence.html>`_.
:math:`K`-function see the Network Spatial Dependence tutorial
`here <https://pysal.org/spaghetti/notebooks/network-spatial-dependence.html>`_.
For original implementation see :cite:`Ripley1976`
and :cite:`Ripley1977`.
Expand Down Expand Up @@ -2598,8 +2606,8 @@ def Moran(self, pp_name, permutations=999, graph=False):
while considering both attribute values and spatial relationships.
A value of closer to +1 indicates absolute clustering while a
value of closer to -1 indicates absolute dispersion. Complete
spatial randomness takes the value of 0. See the
`esda documentation <https://pysal.org/esda/generated/esda.Moran.html#esda.Moran>`_
spatial randomness takes the value of 0. See the ``esda``
`documentation <https://pysal.org/esda/generated/esda.Moran.html#esda.Moran>`_
for in-depth descriptions and tutorials.
Parameters
Expand Down Expand Up @@ -2873,8 +2881,7 @@ def _reassign(attr, cid):
warnings.warn(msg)
for attr in [dm, nt]:
if hasattr(net, attr):
_attr = getattr(net, attr)
del _attr
delattr(net, attr)

# make initial copy of the network
cnet = copy.deepcopy(net)
Expand Down Expand Up @@ -3212,8 +3219,8 @@ def element_as_gdf(


def regular_lattice(bounds, nh, nv=None, exterior=False):
"""Generate a regular lattice of line segments
(`libpysal.cg.Chain objects <https://pysal.org/libpysal/generated/libpysal.cg.Chain.html#libpysal.cg.Chain>`_).
"""Generate a regular lattice of line segments (``libpysal.cg.Chain``
`objects <https://pysal.org/libpysal/generated/libpysal.cg.Chain.html>`_).
Parameters
----------
Expand Down
Loading

0 comments on commit 8bd68d5

Please sign in to comment.