def test_lattice_network_wcomps_eta(self): # with recorded components net_wcomps = tigernet.Network(s_data=self.lats.copy(), record_components=True) with self.assertWarns(UserWarning): net_wcomps.calc_net_stats(conn_stat="eta") known_eta = 2.75 observed_eta = net_wcomps.eta self.assertEqual(observed_eta, known_eta)
def test_lattice_network_segment_entropy_xvariation(self): net = tigernet.Network(s_data=self.lat.copy()) net.calc_entropy("MTFCC", "s_data") known_entropies = {"S1400": 0.0} observed_entropies = net.mtfcc_entropies self.assertEqual(observed_entropies, known_entropies) known_entropy = -0.0 observed_entropy = net.network_mtfcc_entropy self.assertEqual(observed_entropy, known_entropy)
def test_lattice_network_node_entropy(self): _lat = self.lat.copy() net = tigernet.Network(s_data=_lat) net.calc_entropy("degree", "n_data") known_entropies = {1: -0.2575424759098898, 4: -0.46438561897747244} observed_entropies = net.degree_entropies for k, v in known_entropies.items(): self.assertAlmostEqual(observed_entropies[k], v) known_entropy = 0.7219280948873623 observed_entropy = net.network_degree_entropy self.assertAlmostEqual(observed_entropy, known_entropy)
def setUp(self): sine = tigernet.generate_sine_lines() sine = tigernet.generate_sine_lines() sine = sine[sine["SegID"].isin([0, 1, 2, 3])] # full network self.network = tigernet.Network(s_data=sine.copy()) with self.assertWarns(UserWarning): self.network.calc_net_stats() # simplified network self.graph = self.network.simplify_network() with self.assertWarns(UserWarning): self.graph.calc_net_stats()
def test_discard_segments(self): # 1------------------------------------------------------------------------- known_shape_after_discard = 47 kws = {"bbox": "discard", "direc": "test_data"} gdf = tigernet.testing_data("Edges_Leon_FL_2010", **kws) discard = tigernet.get_discard_segms("2010", "12", "073") observed_shape_after_discard = gdf[~gdf["TLID"].isin(discard)].shape[0] self.assertEqual(observed_shape_after_discard, known_shape_after_discard) # 2------------------------------------------------------------------------- known_shape_after_discard = 23 # filter out only roads gdf = tigernet.testing_data("Edges_Leon_FL_2010", **kws) yes_roads = gdf["MTFCC"].str.startswith("S") roads = gdf[yes_roads].copy() # Tiger attributes primary and secondary ATTR1, ATTR2 = "MTFCC", "TLID" # segment welding and splitting stipulations INTRST = "S1100" # interstates mtfcc code RAMP = "S1630" # ramp mtfcc code SERV_DR = "S1640" # service drive mtfcc code SPLIT_GRP = "FULLNAME" # grouped by this variable SPLIT_BY = [RAMP, SERV_DR] # split interstates by ramps & service SKIP_RESTR = True # no weld retry if still MLS kwargs = {"from_raw": True, "attr1": ATTR1, "attr2": ATTR2} comp_kws = {"record_components": True, "largest_component": True} kwargs.update(comp_kws) geom_kws = {"record_geom": True, "calc_len": True} kwargs.update(geom_kws) mtfcc_kws = {"skip_restr": SKIP_RESTR} mtfcc_kws.update({"mtfcc_split": INTRST, "mtfcc_intrst": INTRST}) mtfcc_kws.update({"mtfcc_split_grp": SPLIT_GRP, "mtfcc_ramp": RAMP}) mtfcc_kws.update({"mtfcc_split_by": SPLIT_BY, "mtfcc_serv": SERV_DR}) kwargs.update(mtfcc_kws) network = tigernet.Network(roads, discard_segs=("2010", "12", "073"), **kwargs) network.simplify_network( record_components=True, record_geom=True, largest_component=False, def_graph_elems=True, inplace=True, ) observed_shape_after_discard = network.s_data.shape[0] self.assertEqual(observed_shape_after_discard, known_shape_after_discard)
def test_lattice_network_segment_entropy_wvariation(self): _lat = self.lat.copy() _lat["MTFCC"] = ["S1100", "S1200", "S1400", "S1700"] net = tigernet.Network(s_data=_lat) net.calc_entropy("MTFCC", "s_data") known_entropies = { "S1100": -0.5, "S1200": -0.5, "S1400": -0.5, "S1700": -0.5 } observed_entropies = net.mtfcc_entropies self.assertEqual(observed_entropies, known_entropies) known_entropy = 2.0 observed_entropy = net.network_mtfcc_entropy self.assertEqual(observed_entropy, known_entropy)
def setUp(self): lat = tigernet.generate_lattice(n_hori_lines=1, n_vert_lines=1, wbox=True) lat = lat[~lat["SegID"].isin([3, 5, 8])] rec = { "geometry": LineString(((4.5, 9), (4.5, 13.5))), "SegID": 13, "MTFCC": "S1400", } barb = lat.append(rec, ignore_index=True) # full network self.network = tigernet.Network(s_data=barb.copy()) with self.assertWarns(UserWarning): self.network.calc_net_stats() # simplified network self.graph = self.network.simplify_network() with self.assertWarns(UserWarning): self.graph.calc_net_stats()
def test_lattice_network_wcomps_connectivity(self): # with recorded components net_wcomps = tigernet.Network(s_data=self.lats.copy(), record_components=True) with self.assertWarns(UserWarning): net_wcomps.calc_net_stats(conn_stat="all") known_alpha = 0.0 observed_alpha = net_wcomps.alpha self.assertEqual(observed_alpha, known_alpha) known_beta = 0.8 observed_beta = net_wcomps.beta self.assertEqual(observed_beta, known_beta) known_gamma = 0.3333333333333333 observed_gamma = net_wcomps.gamma self.assertEqual(observed_gamma, known_gamma) known_eta = 2.75 observed_eta = net_wcomps.eta self.assertEqual(observed_eta, known_eta)
def setUp(self): self.lat = tigernet.generate_lattice(n_hori_lines=1, n_vert_lines=1) self.net = tigernet.Network(s_data=self.lat) self.net.cost_matrix() self.net.calc_net_stats()
############################################################################### ############################### Synthetic networks ############################ ############################################################################### # -------------------------------------------------------------------------- # One 1x1 lattice network # used in: # - test_tigernet_synthetic.TestNetworkBuildLattice1x1 # - test_tigernet_synthetic.TestNetworkTopologyLattice1x1 # - test_data_generation.TestObservationDataGenerationSynthetic # - test_errors.TestObservationsErrors # - test_errors.TestUtilsErrors # - test_errors.TestStatsErrors h1v1 = {"n_hori_lines": 1, "n_vert_lines": 1} lattice = tigernet.generate_lattice(**h1v1) network_lattice_1x1_no_args = tigernet.Network(lattice) # -------------------------------------------------------------------------- # Two 1x1 lattices network (both components) # used in: # - test_tigernet_synthetic.TestNetworkComponentsLattice1x1 lattice1 = tigernet.generate_lattice(**h1v1) lattice2 = tigernet.generate_lattice(bounds=[6, 6, 8, 8], **h1v1) lattice = lattice1.append(lattice2) lattice.reset_index(drop=True, inplace=True) kws = {"record_components": True} network_lattice_2x1x1_all = tigernet.Network(lattice, **kws) # -------------------------------------------------------------------------- # Two 1x1 lattices network (both components) with a calculated cost matrix (and paths) # used in: