コード例 #1
0
def test_network(bbox=bb_athens,
                 path=path_data,
                 osm_filter=adj_filter,
                 save_shp=False,
                 save_pickle=True,
                 reload=False):
    tic = time.time()
    print('Start: …load network ')
    if reload:
        network_df = cn.CreateNetwork(bounding_box=bbox,
                                      custom_filter=osm_filter)
        _ = network_df.network_dfs()
        if save_pickle:
            write_pickle(network_df, 'network', path)
    else:
        try:
            network_df = read_pickle('network', path)
        except FileNotFoundError:
            network_df = cn.CreateNetwork(bounding_box=bbox,
                                          custom_filter=osm_filter)
            _ = network_df.network_dfs()
            if save_pickle:
                write_pickle(network_df, 'network', path)

    if save_shp:
        network_df.save_graph_to_shp()
        print('Shapefiles stored')
    toc = time.time()
    print(f'Network loaded, took {toc - tic} sec')
    return network_df
コード例 #2
0
def get_path_dict(path=path_data, reset=False):
    name = 'path_dict'
    if not reset:
        try:
            path_dict = read_pickle(name, path=path)
            return path_dict
        except FileNotFoundError:
            path_dict = {'hdf_path': init_hdf(), 'groups': {}, 'current_resample_step': {}, 'extra': 'all_data'}
            write_pickle(path_dict, name, path=path_data)
            return path_dict
    else:
        path_dict = {'hdf_path': init_hdf(), 'groups': {}, 'current_resample_step': {}, 'extra': 'all_data'}
        write_pickle(path_dict, name, path=path_data)
        return path_dict
コード例 #3
0
def test_detectors(network_df,
                   path,
                   number_detectors=n_det,
                   detector_length=len_det,
                   distance_from_intersection=dfi,
                   double_loops=None,
                   lonlat=False,
                   save_shp=False):
    double_l = False
    dl_tmp = 0
    if double_loops is not None:
        if type(double_loops) in (int, float):
            if double_loops > 0:
                double_l = double_loops
            else:
                print(
                    f'unrealistic length: {double_loops}, default of 1 m is used'
                )
                double_l = 1
            dl_tmp = double_l
        else:
            raise TypeError(
                '"double_loops" parameter not of the right type, should be integer or float'
            )
    name = f'{number_detectors}_{distance_from_intersection}_{detector_length}_{dl_tmp}'
    try:
        det = read_pickle(f'detectors_{name}', path=path)
    except FileNotFoundError:
        det = md.Detectors(network_df.network_edges,
                           length_detector=detector_length,
                           dfi=distance_from_intersection,
                           n_det=number_detectors,
                           double_loops=double_l,
                           lonlat=lonlat,
                           gdf_special=network_df.node_tags)
        det.detector_projected()
        det.features_projected()
        write_pickle(det, f'detectors_{name}', path=path)
        print('Virtual detectors created for edges')
        if save_shp:
            det.detector_to_shapefile()
            print('Shapefiles stored')
    return det