def get_layout(o_dir, layout_name):
    """
    **Layout functions in mne depreciated.**
    Read or generate layout. Layout generated by clicking on input image.

    Parameters
    ----------
    o_dir : dir
        dir in which layout is to be read or saved into
    layout_name : str, default None
        basename of image used as layout template. if None, "topo.lout" is used.

    Returns
    -------
    lt : mne layout object

    """
    # Layout function depreciated. Load tetrode layout
    layout_path = o_dir
    if layout_name is None:
        layout_name = "SA5_topo.lout"
    try:
        lt = mne.channels.read_layout(layout_name,
                                      path=layout_path,
                                      scale=False)
    except:
        # Generate layout of tetrodes
        # This code opens the image so you can click on it to designate tetrode positions
        from mne.viz import ClickableImage  # noqa
        from mne.viz import (plot_alignment, snapshot_brain_montage,
                             set_3d_view)
        # The click coordinates are stored as a list of tuples
        template_loc = r'F:\!Imaging\LKC\SA5\SA5_Histology-07.tif'  # template location
        im = plt.imread(template_loc)
        click = ClickableImage(im)
        click.plot_clicks()

        # Generate a layout from our clicks and normalize by the image
        print('Generating and saving layout...')
        lt = click.to_layout()
        # To save if we want
        lt.save(os.path.join(layout_path, layout_name))
        print('Saved layout to', os.path.join(layout_path, layout_name))

    # Load and display layout
    lt = mne.channels.read_layout(layout_name, path=layout_path, scale=False)
    x = lt.pos[:, 0] * float(im.shape[1])
    y = (1 - lt.pos[:, 1]) * float(im.shape[0])  # Flip the y-position
    fig, ax = plt.subplots()
    ax.imshow(im)
    ax.scatter(x, y, s=120, color='r')
    plt.autoscale(tight=True)
    ax.set_axis_off()
    plt.show()

    return lt
def test_clickable_image():
    """Test the ClickableImage class."""
    # Gen data and create clickable image
    im = np.random.randn(100, 100)
    clk = ClickableImage(im)
    clicks = [(12, 8), (46, 48), (10, 24)]

    # Generate clicks
    for click in clicks:
        _fake_click(clk.fig, clk.ax, click, xform='data')
    assert_allclose(np.array(clicks), np.array(clk.coords))
    assert_true(len(clicks) == len(clk.coords))

    # Exporting to layout
    lt = clk.to_layout()
    assert_true(lt.pos.shape[0] == len(clicks))
    assert_allclose(lt.pos[1, 0] / lt.pos[2, 0],
                    clicks[1][0] / float(clicks[2][0]))
Exemple #3
0
def test_clickable_image():
    """Test the ClickableImage class."""
    # Gen data and create clickable image
    im = np.random.RandomState(0).randn(100, 100)
    clk = ClickableImage(im)
    clicks = [(12, 8), (46, 48), (10, 24)]

    # Generate clicks
    for click in clicks:
        _fake_click(clk.fig, clk.ax, click, xform='data')
    assert_allclose(np.array(clicks), np.array(clk.coords))
    assert (len(clicks) == len(clk.coords))

    # Exporting to layout
    lt = clk.to_layout()
    assert (lt.pos.shape[0] == len(clicks))
    assert_allclose(lt.pos[1, 0] / lt.pos[2, 0],
                    clicks[1][0] / float(clicks[2][0]))
    clk.plot_clicks()
    plt.close('all')