Example #1
0
def mmm_wrap(_ax,
             _graph,
             _layer_spec,
             _n_iters,
             _spans,
             _bands=9,
             _tiers=3,
             _title='',
             _random_seed=0):
    landuse_state = mmm_layercake_diversity(_graph,
                                            _layer_spec,
                                            _n_iters,
                                            _spans,
                                            _bands=_bands,
                                            _tiers=_tiers,
                                            random_seed=_random_seed)

    print('done')

    xs = []
    for n, d in _graph.nodes(data=True):
        xs.append(d['x'])

    plotter(_ax,
            _n_iters,
            xs,
            _res_factor=1,
            _plot_maps=[
                pop_map, capacitance_maps[0], landuse_maps[0],
                spillover_maps[0]
            ])

    _ax.set_title(_title + f' sum l.u: {landuse_maps[0].sum()}')
Example #2
0
def mmm_single(_graph,
               _iters,
               _layer_specs,
               _title='',
               random_seed=0,
               figsize=(12, 20),
               theme=None,
               path=None,
               dark=False):
    xs = []
    for n, d in _graph.nodes(data=True):
        xs.append(d['x'])

    util_funcs.plt_setup(dark=dark)

    if isinstance(_layer_specs, dict):
        pop_map, landuse_maps, capacitance_maps, flow_maps = mmm_layercake_phd(_graph,
                                                                               _iters,
                                                                               _layer_specs=_layer_specs,
                                                                               random_seed=random_seed)
        fig, ax = plt.subplots(1, 1, figsize=figsize)
        caps = capacitance_maps[0]
        lus = landuse_maps[0]
        flows = flow_maps[0]
        plotter(ax, _iters, xs, _res_factor=1,
                _plot_maps=[pop_map, caps, lus, flows],
                _plot_scales=(1, 1.5, 0.75, 1))
        title = _title + f'l.u: {np.round(np.sum(landuse_maps), 2)}'
        style_ax(ax, title, _iters, dark=dark)

    else:
        assert isinstance(_layer_specs, (list, tuple))
        n_ax = len(_layer_specs)
        fig, axes = plt.subplots(1, n_ax, figsize=figsize)
        if isinstance(_title, str):
            _title = [_title] * n_ax
        else:
            assert isinstance(_title, (list, tuple))
            assert len(_title) == len(_layer_specs)
        for ax, title, layer_spec in zip(axes, _title, _layer_specs):
            pop_map, landuse_maps, capacitance_maps, flow_maps = mmm_layercake_phd(_graph,
                                                                                   _iters,
                                                                                   _layer_specs=layer_spec,
                                                                                   random_seed=random_seed)
            caps = capacitance_maps[0]
            lus = landuse_maps[0]
            flows = flow_maps[0]
            plotter(ax, _iters, xs, _res_factor=1, _plot_maps=[pop_map, caps, lus, flows])
            title = title + f'l.u: {np.round(np.sum(landuse_maps), 2)}'
            style_ax(ax, title, _iters, dark=dark)

    if theme is not None:
        fig.suptitle(theme)

    if path is not None:
        plt.savefig(path, dpi=300)
Example #3
0
def mmm_nested_split(_graph,
                     _iters,
                     _layer_specs,
                     _title='',
                     random_seed=0,
                     figsize=(30, 20),
                     theme=None,
                     path=None,
                     dark=False):
    xs = []
    for n, d in _graph.nodes(data=True):
        xs.append(d['x'])

    util_funcs.plt_setup(dark=dark)

    assert isinstance(_layer_specs, (list, tuple))
    fig, axes = plt.subplots(1, 3, figsize=figsize)

    pop_map, landuse_maps, capacitance_maps, flow_maps = mmm_layercake_phd(_graph,
                                                                           _iters,
                                                                           _layer_specs=
                                                                           _layer_specs[0],
                                                                           random_seed=random_seed)
    plotter(axes[0], _iters, xs, _res_factor=1, _plot_maps=[pop_map,
                                                            capacitance_maps[0],
                                                            landuse_maps[0]],
            _plot_colours=['#555555', '#d32f2f', '#2e7d32'])
    title = _title + f'l.u: {np.round(np.sum(landuse_maps), 2)}'
    style_ax(axes[0], title, _iters, dark=dark)

    # both
    pop_map, landuse_maps, capacitance_maps, flow_maps = mmm_layercake_phd(_graph,
                                                                           _iters,
                                                                           _layer_specs=_layer_specs,
                                                                           random_seed=random_seed)
    plotter(axes[1], _iters, xs, _res_factor=1, _plot_maps=[pop_map,
                                                            np.sum(capacitance_maps, axis=0),
                                                            landuse_maps[0],
                                                            landuse_maps[1]],
            _plot_colours=['#555555', '#d32f2f', '#2e7d32', '#0064b7'])
    title = _title + f'l.u: {np.round(np.sum(landuse_maps), 2)}'
    style_ax(axes[1], title, _iters, dark=dark)

    pop_map, landuse_maps, capacitance_maps, flow_maps = mmm_layercake_d(_graph,
                                                                         _iters,
                                                                         _layer_specs=
                                                                         _layer_specs[1],
                                                                         random_seed=random_seed)
    plotter(axes[2], _iters, xs, _res_factor=1, _plot_maps=[pop_map,
                                                            capacitance_maps[0],
                                                            landuse_maps[0]],
            _plot_colours=['#555555', '#d32f2f', '#0064b7'])
    title = _title + f'l.u: {np.round(np.sum(landuse_maps), 2)}'
    style_ax(axes[2], title, _iters, dark=dark)

    if theme is not None:
        fig.suptitle(theme)

    if path is not None:
        plt.savefig(path, dpi=300)
Example #4
0
def mmm_single(_graph,
               _iters,
               _layer_specs,
               _title='',
               seed=False,
               random_seed=0,
               figsize=(12, 20),
               theme=None,
               path=None,
               dark=False):
    xs = []
    for n, d in _graph.nodes(data=True):
        xs.append(d['x'])

    background_col = '#ffffff'
    if dark:
        background_col = '#2e2e2e'

    util_funcs.plt_setup()

    if isinstance(_layer_specs, dict):
        pop_map, landuse_maps, capacitance_maps = mmm_layercake_b(
            _graph,
            _iters,
            _layer_specs=_layer_specs,
            seed=seed,
            random_seed=random_seed)
        fig, ax = plt.subplots(1, 1, figsize=figsize, facecolor=background_col)
        caps = capacitance_maps[0]
        lus = landuse_maps[0] * caps
        plotter(ax, _iters, xs, _res_factor=1, _plot_maps=[pop_map, caps, lus])
        title = _title + f'l.u: {landuse_maps[0].sum()}'
        style_ax(ax, title, _iters)

    else:
        assert isinstance(_layer_specs, (list, tuple))
        n_ax = len(_layer_specs)
        fig, axes = plt.subplots(1,
                                 n_ax,
                                 figsize=figsize,
                                 facecolor=background_col)
        if isinstance(_title, str):
            _title = [_title] * n_ax
        else:
            assert isinstance(_title, (list, tuple))
            assert len(_title) == len(_layer_specs)
        for ax, title, layer_spec in zip(axes, _title, _layer_specs):
            pop_map, landuse_maps, capacitance_maps = mmm_layercake_b(
                _graph,
                _iters,
                _layer_specs=layer_spec,
                seed=seed,
                random_seed=random_seed)
            caps = capacitance_maps[0]
            lus = landuse_maps[0] * caps
            plotter(ax,
                    _iters,
                    xs,
                    _res_factor=1,
                    _plot_maps=[pop_map, caps, lus])
            title = title + f'l.u: {landuse_maps[0].sum()}'
            style_ax(ax, title, _iters)

    if theme is not None:
        fig.suptitle(theme)

    if path is not None:
        plt.savefig(path,
                    facecolor=fig.get_facecolor(),
                    edgecolor='none',
                    dpi=300,
                    transparent=True)

    plt.show()
Example #5
0
        dens[np.isnan(dens)] = 0
        # set the centrality weights accordingly
        Netw_Layer.weights = dens / np.nanmax(dens)  # normalised
        # calculate the density weighted centrality
        Netw_Layer.gravity_index()
        cent_pop_wt = Netw_Layer.metrics['centrality']['gravity_index'][400]
        # reassign people from low to high pressure
        pressure_reallocation(cent_pop_wt,
                              Netw_Layer._nodes,
                              Pop_Layer._data,
                              _iters=50,
                              _max=40)

    plotter(axes[ax_n],
            iters,
            Netw_Layer.x_arr,
            _res_factor=1,
            _grey_map=pop_map)

theme = 'density_agglomeration'
fig.suptitle(theme)
plt.savefig(f'./src/explore/H_mmm/exploratory_plots/{theme}.png', dpi=300)
plt.show()

#  %%
'''
2 - density vis-a-vis mixed-uses

Scenarios: sequential, random, random with topo stretch
1) People pursue mixed uses
2) Centrality is aggregate weighted by people, and destination weighted by respective R, G, B flows