region.tests.util module

region.tests.util.compare_region_lists(actual, desired)
Parameters:
  • actual (list) – Every element (of type set) represents a region.
  • desired (list) – Every element (of type set) represents a region.
Raises:

AssertionError – If the two arguments don’t represent the same clustering.

region.tests.util.convert_from_geodataframe(gdf)

Convert a GeoDataFrame to other types representing the contiguity relation of the GeoDataFrame’s areas.

Parameters:gdf (GeoDataFrame) –
Returns:other_formats – The 1st entry is a sparse adjacency matrix of type scipy.sparse.csr_matrix. The 2nd entry is a networkx graph. The 3rd entry is a dict. Each key is an area and each value is an iterable of the key area’s neighbors. The 4th entry is a PySAL W object.
Return type:tuple
region.tests.util.region_list_from_array(labels)
Parameters:labels (numpy.ndarray) – One-dimensional array of the areas’ region labels.
Returns:region_list – Each element is a set of areas belonging to the same region. The list’s elements (the sets) are sorted by their smallest entry.
Return type:list

Examples

>>> import numpy as np
>>> labels = np.array([0, 0, 0,
...                    1, 1, 0,
...                    1, 1, 1])
>>> desired = [{0, 1, 2, 5}, {3, 4, 6, 7, 8}]
>>> all(r1 == r2
...     for r1, r2 in zip(region_list_from_array(labels), desired))
True