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 setUp(self): self.network = copy.deepcopy(network_empirical_simplified_wcm) # empirical origins obs1 = tigernet.testing_data("CensusBlocks_Leon_FL_2010") # empirical destinations obs2 = tigernet.testing_data("WeightedParcels_Leon_FL_2010") # associate origins with the network args = self.network, obs1.copy() kwargs = {"df_name": "obs1", "df_key": "GEOID", "snap_to": "nodes"} self.net_obs1 = tigernet.Observations(*args, **kwargs) # associate destinations with the network args = self.network, obs2.copy() kwargs = {"df_name": "obs2", "df_key": "PARCEL_ID", "snap_to": "nodes"} self.net_obs2 = tigernet.Observations(*args, **kwargs)
def setUp(self): network = copy.deepcopy(network_empirical_simplified) # generate synthetic observations obs = tigernet.testing_data("WeightedParcels_Leon_FL_2010") # associate observations with the network args = network, obs.copy() kwargs = {"df_name": "obs1", "df_key": "PARCEL_ID"} self.net_obs = tigernet.Observations(*args, **kwargs)
def setUp(self): self.network = copy.deepcopy(network_empirical_simplified_wcm) # empirical observations obs = tigernet.testing_data("CensusBlocks_Leon_FL_2010") # associate observations with the network args = self.network, obs.copy() kwargs = {"df_name": "obs1", "df_key": "GEOID"} self.net_obs = tigernet.Observations(*args, **kwargs)
def setUp(self): network = copy.deepcopy(network_empirical_simplified) # generate synthetic observations obs = tigernet.testing_data("WeightedParcels_Leon_FL_2010") # associate observations with the network args = network, obs.copy() kwargs = {"df_name": "obs1", "df_key": "PARCEL_ID", "snap_to": "nodes"} kwargs.update({"restrict_col": "MTFCC"}) kwargs.update({"remove_restricted": ["S1100", "S1630", "S1640"]}) self.net_obs = tigernet.Observations(*args, **kwargs)
def setUp(self): network = copy.deepcopy(network_empirical_simplified) # generate synthetic observations ---------------------------------------- 1 self.obs1 = tigernet.testing_data("WeightedParcels_Leon_FL_2010") # associate observations with the network args = network, self.obs1.copy() kwargs = {"df_name": "obs1", "df_key": "PARCEL_ID", "snap_to": "segments"} kwargs.update({"obs_pop": "SUM_EST_PO", "restrict_col": "MTFCC"}) kwargs.update({"remove_restricted": ["S1100", "S1630", "S1640"]}) self.net_obs1 = tigernet.Observations(*args, **kwargs) # generate synthetic observations ---------------------------------------- 2 self.obs2 = tigernet.testing_data("CensusBlocks_Leon_FL_2010") # associate observations with the network args = network, self.obs2.copy() kwargs = {"df_name": "obs2", "df_key": "GEOID", "snap_to": "segments"} kwargs.update({"obs_pop": "POP100", "restrict_col": "MTFCC"}) kwargs.update({"remove_restricted": ["S1100", "S1630", "S1640"]}) self.net_obs2 = tigernet.Observations(*args, **kwargs)
def test_read_data_bbox_5_int_coords(self): with self.assertRaises(ValueError): tigernet.testing_data(self.dset, bbox=[1, 1, 2, 2, 2])
def test_read_data_bbox_5_coords(self): with self.assertRaises(ValueError): tigernet.testing_data(self.dset, bbox=[1.0, 1.0, 2.0, 2.0, 2.0])
def test_read_data_bbox_not_iterable(self): with self.assertRaises(ValueError): tigernet.testing_data(self.dset, bbox=2020)
def test_read_data_bbox_bad_str(self): with self.assertRaises(ValueError): tigernet.testing_data(self.dset, bbox="bad_description")
def test_good_read_from_coords(self): known_recs = 4 bbox = (-84.34, 30.4935, -84.3378, 30.494) observed_recs = tigernet.testing_data(self.dset, bbox=bbox).shape[0] self.assertEqual(observed_recs, known_recs)
def test_good_read_no_bbox(self): known_recs = 37798 bbox = None observed_recs = tigernet.testing_data(self.dset, bbox=bbox).shape[0] self.assertEqual(observed_recs, known_recs)
# used in: # - test_obs2obs_synthetic.TestSyntheticObservationsOrigToXXXXSegments # - test_obs2obs_synthetic.TestSyntheticObservationsOrigToXXXXNodes # - test_obs2obs_synthetic.TestSyntheticObservationsOrigToDestSegments # - test_obs2obs_synthetic.TestSyntheticObservationsOrigToDestNodes h1v1 = {"n_hori_lines": 1, "n_vert_lines": 1} lattice = tigernet.generate_lattice(bounds=[0, 0, 4, 4], **h1v1) network_lattice_1x1_small = tigernet.Network(lattice, **kws) network_lattice_1x1_small.cost_matrix() ############################################################################### ############################### Empirical networks ############################ ############################################################################### # get the roads shapefile as a GeoDataFrame gdf = tigernet.testing_data("Edges_Leon_FL_2010") # filter out only roads 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