Skip to content

Commit

Permalink
move import down (#144)
Browse files Browse the repository at this point in the history
move import down
  • Loading branch information
knaaptime authored Jan 25, 2020
2 parents 83311ca + 76fb0cf commit ff2b6b7
Show file tree
Hide file tree
Showing 48 changed files with 103 additions and 102 deletions.
17 changes: 9 additions & 8 deletions segregation/network/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,6 @@
from segregation.util import project_gdf
import os
import sys
try:
import pandana as pdna
from urbanaccess.osm.load import ua_network_from_bbox
except ImportError:
warn(
"You need pandana and urbanaccess to work with segregation's network module\n"
"You can install them with `pip install urbanaccess pandana` "
"or `conda install -c udst pandana urbanaccess`")


# This class allows us to hide the diagnostic messages from urbanaccess if the `quiet` flag is set
Expand Down Expand Up @@ -54,6 +46,15 @@ def get_osm_network(geodataframe, maxdist=5000, quiet=True, **kwargs):
spatial segregation measures that include a distance decay
"""
try:
import pandana as pdna
from urbanaccess.osm.load import ua_network_from_bbox
except ImportError:
raise ImportError(
"You need pandana and urbanaccess to work with segregation's network module\n"
"You can install them with `pip install urbanaccess pandana` "
"or `conda install -c udst pandana urbanaccess`")

gdf = geodataframe.copy()
gdf = project_gdf(gdf)
gdf = gdf.buffer(maxdist)
Expand Down
4 changes: 2 additions & 2 deletions segregation/tests/test_absolute_centralization.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import unittest
import libpysal
from libpysal.examples import load_example
import geopandas as gpd
import numpy as np
from segregation.spatial import AbsoluteCentralization


class Absolute_Centralization_Tester(unittest.TestCase):
def test_Absolute_Centralization(self):
s_map = gpd.read_file(libpysal.examples.get_path("sacramentot2.shp"))
s_map = gpd.read_file(load_example("Sacramento1").get_path("sacramentot2.shp"))
df = s_map[['geometry', 'HISP_', 'TOT_POP']]
index = AbsoluteCentralization(df, 'HISP_', 'TOT_POP')
np.testing.assert_almost_equal(index.statistic, 0.6891422368736286)
Expand Down
4 changes: 2 additions & 2 deletions segregation/tests/test_absolute_clustering.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import unittest
import libpysal
from libpysal.examples import load_example
import geopandas as gpd
import numpy as np
from segregation.spatial import AbsoluteClustering


class Absolute_Clustering_Tester(unittest.TestCase):
def test_Absolute_Clustering(self):
s_map = gpd.read_file(libpysal.examples.get_path("sacramentot2.shp"))
s_map = gpd.read_file(load_example("Sacramento1").get_path("sacramentot2.shp"))
df = s_map[['geometry', 'HISP_', 'TOT_POP']]
index = AbsoluteClustering(df, 'HISP_', 'TOT_POP')
np.testing.assert_almost_equal(index.statistic, 0.005189287311955573)
Expand Down
4 changes: 2 additions & 2 deletions segregation/tests/test_absolute_concentration.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import unittest
import libpysal
from libpysal.examples import load_example
import geopandas as gpd
import numpy as np
from segregation.spatial import AbsoluteConcentration


class Absolute_Concentration_Tester(unittest.TestCase):
def test_Absolute_Concentration(self):
s_map = gpd.read_file(libpysal.examples.get_path("sacramentot2.shp"))
s_map = gpd.read_file(load_example("Sacramento1").get_path("sacramentot2.shp"))
df = s_map[['geometry', 'HISP_', 'TOT_POP']]
index = AbsoluteConcentration(df, 'HISP_', 'TOT_POP')
np.testing.assert_almost_equal(index.statistic, 0.8512824549657465)
Expand Down
4 changes: 2 additions & 2 deletions segregation/tests/test_atkinson.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import unittest
import libpysal
from libpysal.examples import load_example
import geopandas as gpd
import numpy as np
from segregation.aspatial import Atkinson


class Atkinson_Tester(unittest.TestCase):
def test_Atkinson(self):
s_map = gpd.read_file(libpysal.examples.get_path("sacramentot2.shp"))
s_map = gpd.read_file(load_example("Sacramento1").get_path("sacramentot2.shp"))
df = s_map[['geometry', 'HISP_', 'TOT_POP']]
index = Atkinson(df, 'HISP_', 'TOT_POP')
np.testing.assert_almost_equal(index.statistic, 0.15079259382667654)
Expand Down
4 changes: 2 additions & 2 deletions segregation/tests/test_bias_corrected_dissimilarity.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import unittest
import libpysal
from libpysal.examples import load_example
import geopandas as gpd
import numpy as np
from segregation.aspatial import BiasCorrectedDissim


class Bias_Corrected_Dissim_Tester(unittest.TestCase):
def test_Bias_Corrected_Dissim(self):
s_map = gpd.read_file(libpysal.examples.get_path("sacramentot2.shp"))
s_map = gpd.read_file(load_example("Sacramento1").get_path("sacramentot2.shp"))
df = s_map[['geometry', 'HISP_', 'TOT_POP']]
np.random.seed(1234)
index = BiasCorrectedDissim(df, 'HISP_', 'TOT_POP')
Expand Down
4 changes: 2 additions & 2 deletions segregation/tests/test_boundary_spatial_dissimilarity.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import unittest
import libpysal
from libpysal.examples import load_example
import geopandas as gpd
import numpy as np
from segregation.spatial import BoundarySpatialDissim


class Boundary_Spatial_Dissim_Tester(unittest.TestCase):
def test_Boundary_Spatial_Dissim(self):
s_map = gpd.read_file(libpysal.examples.get_path("sacramentot2.shp"))
s_map = gpd.read_file(load_example("Sacramento1").get_path("sacramentot2.shp"))
df = s_map[['geometry', 'HISP_', 'TOT_POP']]
index = BoundarySpatialDissim(df, 'HISP_', 'TOT_POP')
np.testing.assert_almost_equal(index.statistic, 0.2667626367289605)
Expand Down
4 changes: 2 additions & 2 deletions segregation/tests/test_compute_all.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import unittest
import libpysal
from libpysal.examples import load_example
import geopandas as gpd
import numpy as np
from segregation.compute_all import ComputeAllAspatialSegregation, ComputeAllSpatialSegregation, ComputeAllSegregation


class ComputeAll_Tester(unittest.TestCase):
def test_ComputeAll(self):
s_map = gpd.read_file(libpysal.examples.get_path("sacramentot2.shp"))
s_map = gpd.read_file(load_example("Sacramento1").get_path("sacramentot2.shp"))

np.random.seed(123)
res = ComputeAllAspatialSegregation(s_map, 'HISP_', 'TOT_POP')
Expand Down
4 changes: 2 additions & 2 deletions segregation/tests/test_conprof.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import unittest
import libpysal
from libpysal.examples import load_example
import geopandas as gpd
import numpy as np
from segregation.aspatial import ConProf


class Con_Prof_Tester(unittest.TestCase):
def test_Con_Prof(self):
s_map = gpd.read_file(libpysal.examples.get_path("sacramentot2.shp"))
s_map = gpd.read_file(load_example("Sacramento1").get_path("sacramentot2.shp"))
df = s_map[['geometry', 'HISP_', 'TOT_POP']]
index = ConProf(df, 'HISP_', 'TOT_POP')
np.testing.assert_almost_equal(index.statistic, 0.1376874794741899)
Expand Down
4 changes: 2 additions & 2 deletions segregation/tests/test_correlationr.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import unittest
import libpysal
from libpysal.examples import load_example
import geopandas as gpd
import numpy as np
from segregation.aspatial import CorrelationR


class Correlation_R_Tester(unittest.TestCase):
def test_Correlation_R(self):
s_map = gpd.read_file(libpysal.examples.get_path("sacramentot2.shp"))
s_map = gpd.read_file(load_example("Sacramento1").get_path("sacramentot2.shp"))
df = s_map[['geometry', 'HISP_', 'TOT_POP']]
index = CorrelationR(df, 'HISP_', 'TOT_POP')
np.testing.assert_almost_equal(index.statistic, 0.09164042012926693)
Expand Down
4 changes: 2 additions & 2 deletions segregation/tests/test_decomposition.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import unittest
import libpysal
from libpysal.examples import load_example
import geopandas as gpd
import numpy as np
from segregation.aspatial import Dissim
Expand All @@ -8,7 +8,7 @@

class Decomposition_Tester(unittest.TestCase):
def test_Decomposition(self):
s_map = gpd.read_file(libpysal.examples.get_path("sacramentot2.shp"))
s_map = gpd.read_file(load_example("Sacramento1").get_path("sacramentot2.shp"))
index1 = Dissim(s_map, 'HISP_', 'TOT_POP')
index2 = Dissim(s_map, 'BLACK_', 'TOT_POP')
res = DecomposeSegregation(index1, index2, counterfactual_approach = "composition")
Expand Down
4 changes: 2 additions & 2 deletions segregation/tests/test_delta.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import unittest
import libpysal
from libpysal.examples import load_example
import geopandas as gpd
import numpy as np
from segregation.spatial import Delta


class Delta_Tester(unittest.TestCase):
def test_Delta(self):
s_map = gpd.read_file(libpysal.examples.get_path("sacramentot2.shp"))
s_map = gpd.read_file(load_example("Sacramento1").get_path("sacramentot2.shp"))
df = s_map[['geometry', 'HISP_', 'TOT_POP']]
index = Delta(df, 'HISP_', 'TOT_POP')
np.testing.assert_almost_equal(index.statistic, 0.8044969214141899)
Expand Down
4 changes: 2 additions & 2 deletions segregation/tests/test_density_corrected_dissimilarity.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import unittest
import libpysal
from libpysal.examples import load_example
import geopandas as gpd
import numpy as np
from segregation.aspatial import DensityCorrectedDissim
Expand All @@ -8,7 +8,7 @@
class Density_Corrected_Dissim_Tester(unittest.TestCase):

def test_Density_Corrected_Dissim(self):
s_map = gpd.read_file(libpysal.examples.get_path("sacramentot2.shp"))
s_map = gpd.read_file(load_example("Sacramento1").get_path("sacramentot2.shp"))
df = s_map[['geometry', 'HISP_', 'TOT_POP']]
index = DensityCorrectedDissim(df, 'HISP_', 'TOT_POP')
np.testing.assert_almost_equal(index.statistic, 0.295205155464069)
Expand Down
4 changes: 2 additions & 2 deletions segregation/tests/test_dissim.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import unittest
import libpysal
from libpysal.examples import load_example
import geopandas as gpd
import numpy as np
from segregation.aspatial import Dissim


class Dissim_Tester(unittest.TestCase):
def test_Dissim(self):
s_map = gpd.read_file(libpysal.examples.get_path("sacramentot2.shp"))
s_map = gpd.read_file(load_example("Sacramento1").get_path("sacramentot2.shp"))
df = s_map[['geometry', 'HISP_', 'TOT_POP']]
index = Dissim(df, 'HISP_', 'TOT_POP')
np.testing.assert_almost_equal(index.statistic, 0.32184656076566864)
Expand Down
4 changes: 2 additions & 2 deletions segregation/tests/test_distance_decay_exposure.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import unittest
import libpysal
from libpysal.examples import load_example
import geopandas as gpd
import numpy as np
from segregation.spatial import DistanceDecayExposure


class Distance_Decay_Exposure_Tester(unittest.TestCase):
def test_Distance_Decay_Exposure(self):
s_map = gpd.read_file(libpysal.examples.get_path("sacramentot2.shp"))
s_map = gpd.read_file(load_example("Sacramento1").get_path("sacramentot2.shp"))
df = s_map[['geometry', 'HISP_', 'TOT_POP']]
index = DistanceDecayExposure(df, 'HISP_', 'TOT_POP')
np.testing.assert_almost_equal(index.statistic, 0.8396583368412371)
Expand Down
4 changes: 2 additions & 2 deletions segregation/tests/test_distance_decay_isolation.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import unittest
import libpysal
from libpysal.examples import load_example
import geopandas as gpd
import numpy as np
from segregation.spatial import DistanceDecayIsolation


class Distance_Decay_Isolation_Tester(unittest.TestCase):
def test_Distance_Decay_Isolation(self):
s_map = gpd.read_file(libpysal.examples.get_path("sacramentot2.shp"))
s_map = gpd.read_file(load_example("Sacramento1").get_path("sacramentot2.shp"))
df = s_map[['geometry', 'HISP_', 'TOT_POP']]
index = DistanceDecayIsolation(df, 'HISP_', 'TOT_POP')
np.testing.assert_almost_equal(index.statistic, 0.1562162475606278)
Expand Down
4 changes: 2 additions & 2 deletions segregation/tests/test_entropy.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import unittest
import libpysal
from libpysal.examples import load_example
import geopandas as gpd
import numpy as np
from segregation.aspatial import Entropy


class Entropy_Tester(unittest.TestCase):
def test_Entropy(self):
s_map = gpd.read_file(libpysal.examples.get_path("sacramentot2.shp"))
s_map = gpd.read_file(load_example("Sacramento1").get_path("sacramentot2.shp"))
df = s_map[['geometry', 'HISP_', 'TOT_POP']]
index = Entropy(df, 'HISP_', 'TOT_POP')
np.testing.assert_almost_equal(index.statistic, 0.09459760633014454)
Expand Down
4 changes: 2 additions & 2 deletions segregation/tests/test_exposure.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import unittest
import libpysal
from libpysal.examples import load_example
import geopandas as gpd
import numpy as np
from segregation.aspatial import Exposure


class Exposure_Tester(unittest.TestCase):
def test_Exposure(self):
s_map = gpd.read_file(libpysal.examples.get_path("sacramentot2.shp"))
s_map = gpd.read_file(load_example("Sacramento1").get_path("sacramentot2.shp"))
df = s_map[['geometry', 'HISP_', 'TOT_POP']]
index = Exposure(df, 'HISP_', 'TOT_POP')
np.testing.assert_almost_equal(index.statistic, 0.7680384513540848)
Expand Down
4 changes: 2 additions & 2 deletions segregation/tests/test_gini_seg.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import unittest
import libpysal
from libpysal.examples import load_example
import geopandas as gpd
import numpy as np
from segregation.aspatial import GiniSeg
Expand All @@ -8,7 +8,7 @@
class Gini_Seg_Tester(unittest.TestCase):

def test_Gini_Seg(self):
s_map = gpd.read_file(libpysal.examples.get_path("sacramentot2.shp"))
s_map = gpd.read_file(load_example("Sacramento1").get_path("sacramentot2.shp"))
df = s_map[['geometry', 'HISP_', 'TOT_POP']]
index = GiniSeg(df, 'HISP_', 'TOT_POP')
np.testing.assert_almost_equal(index.statistic, 0.43506510676886234)
Expand Down
4 changes: 2 additions & 2 deletions segregation/tests/test_inference.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import unittest
import libpysal
from libpysal.examples import load_example
import geopandas as gpd
import numpy as np
from segregation.aspatial import Dissim, MultiDissim
Expand All @@ -8,7 +8,7 @@

class Inference_Tester(unittest.TestCase):
def test_Inference(self):
s_map = gpd.read_file(libpysal.examples.get_path("sacramentot2.shp"))
s_map = gpd.read_file(load_example("Sacramento1").get_path("sacramentot2.shp"))
index1 = Dissim(s_map, 'HISP_', 'TOT_POP')
index2 = Dissim(s_map, 'BLACK_', 'TOT_POP')

Expand Down
4 changes: 2 additions & 2 deletions segregation/tests/test_isolation.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import unittest
import libpysal
from libpysal.examples import load_example
import geopandas as gpd
import numpy as np
from segregation.aspatial import Isolation


class Isolation_Tester(unittest.TestCase):
def test_Isolation(self):
s_map = gpd.read_file(libpysal.examples.get_path("sacramentot2.shp"))
s_map = gpd.read_file(load_example("Sacramento1").get_path("sacramentot2.shp"))
df = s_map[['geometry', 'HISP_', 'TOT_POP']]
index = Isolation(df, 'HISP_', 'TOT_POP')
np.testing.assert_almost_equal(index.statistic, 0.2319615486459151)
Expand Down
4 changes: 2 additions & 2 deletions segregation/tests/test_local_multi_local_diversity.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import unittest
import libpysal
from libpysal.examples import load_example
import geopandas as gpd
import numpy as np
from segregation.local import MultiLocalDiversity


class Multi_Local_Diversity_Tester(unittest.TestCase):
def test_Multi_Local_Diversity(self):
s_map = gpd.read_file(libpysal.examples.get_path("sacramentot2.shp"))
s_map = gpd.read_file(load_example("Sacramento1").get_path("sacramentot2.shp"))
groups_list = ['WHITE_', 'BLACK_', 'ASIAN_','HISP_']
df = s_map[groups_list]
index = MultiLocalDiversity(df, groups_list)
Expand Down
4 changes: 2 additions & 2 deletions segregation/tests/test_local_multi_local_entropy.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import unittest
import libpysal
from libpysal.examples import load_example
import geopandas as gpd
import numpy as np
from segregation.local import MultiLocalEntropy


class Multi_Local_Entropy_Tester(unittest.TestCase):
def test_Multi_Local_Entropy(self):
s_map = gpd.read_file(libpysal.examples.get_path("sacramentot2.shp"))
s_map = gpd.read_file(load_example("Sacramento1").get_path("sacramentot2.shp"))
groups_list = ['WHITE_', 'BLACK_', 'ASIAN_','HISP_']
df = s_map[groups_list]
index = MultiLocalEntropy(df, groups_list)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import unittest
import libpysal
from libpysal.examples import load_example
import geopandas as gpd
import numpy as np
from segregation.local import MultiLocalSimpsonConcentration


class Multi_Local_Simpson_Concentration_Tester(unittest.TestCase):
def test_Multi_Local_Simpson_Concentration(self):
s_map = gpd.read_file(libpysal.examples.get_path("sacramentot2.shp"))
s_map = gpd.read_file(load_example("Sacramento1").get_path("sacramentot2.shp"))
groups_list = ['WHITE_', 'BLACK_', 'ASIAN_','HISP_']
df = s_map[groups_list]
index = MultiLocalSimpsonConcentration(df, groups_list)
Expand Down
Loading

0 comments on commit ff2b6b7

Please sign in to comment.