Пример #1
0
def _plot_2D_component(factors, idx, axes_manager,
                       calibrate=True, ax=None,
                       comp_label=None, cmap=plt.cm.gray,
                       axes_decor='all'
                       ):
    shape = axes_manager._signal_shape_in_array
    factors = to_numpy(factors[:, idx].reshape(shape))
    if ax is None:
        ax = plt.gca()
    axes = axes_manager.signal_axes[::-1]
    extent = None
    if calibrate:
        extent = (axes[1].low_value,
                  axes[1].high_value,
                  axes[0].high_value,
                  axes[0].low_value)
    if comp_label:
        plt.title(f'{idx}')
    im = ax.imshow(factors, cmap=cmap, interpolation='nearest', extent=extent)

    # Set axes decorations based on user input
    set_axes_decor(ax, axes_decor)

    div = make_axes_locatable(ax)
    cax = div.append_axes("right", size="5%", pad=0.05)
    plt.colorbar(im, cax=cax)
    return ax
Пример #2
0
def _plot_loading(loadings, idx, axes_manager, ax=None,
                  comp_label=None, no_nans=True,
                  calibrate=True, cmap=plt.cm.gray,
                  same_window=False, axes_decor='all'):
    loadings = to_numpy(loadings[idx])
    if ax is None:
        ax = plt.gca()
    if no_nans:
        loadings = np.nan_to_num(loadings)
    axes = axes_manager.navigation_axes
    if axes_manager.navigation_dimension == 2:
        extent = None
        # get calibration from a passed axes_manager
        shape = axes_manager._navigation_shape_in_array
        if calibrate:
            extent = (axes[0].low_value,
                      axes[0].high_value,
                      axes[1].high_value,
                      axes[1].low_value)
        im = ax.imshow(loadings.reshape(shape),
                       cmap=cmap, extent=extent,
                       interpolation='nearest')
        if calibrate:
            plt.xlabel(axes[0].units)
            plt.ylabel(axes[1].units)
        else:
            plt.xlabel('pixels')
            plt.ylabel('pixels')
        if comp_label:
            if same_window:
                plt.title(f'{idx}')
            else:
                plt.title(f'{idx} #{idx}')

        # Set axes decorations based on user input
        set_axes_decor(ax, axes_decor)

        div = make_axes_locatable(ax)
        cax = div.append_axes("right", size="5%", pad=0.05)
        plt.colorbar(im, cax=cax)
    elif axes_manager.navigation_dimension == 1:
        if calibrate:
            x = axes[0].axis
        else:
            x = np.arange(axes[0].size)
        ax.step(x, loadings, label=f'{idx}')
        if comp_label and not same_window:
            plt.title(f'{comp_label} #{idx}')
        plt.ylabel('Score (a. u.)')
        if calibrate:
            if axes[0].units is not Undefined:
                plt.xlabel(axes[0].units)
            else:
                plt.xlabel('depth')
        else:
            plt.xlabel('depth')
    else:
        raise ValueError('View not supported')
Пример #3
0
def _plot_1D_component(factors, idx, axes_manager, ax=None,
                       calibrate=True, comp_label=None,
                       same_window=False):
    if ax is None:
        ax = plt.gca()
    axis = axes_manager.signal_axes[0]
    if calibrate:
        x = axis.axis
        plt.xlabel(axis.units)
    else:
        x = np.arange(axis.size)
        plt.xlabel('Channel index')
    ax.plot(x, to_numpy(factors[:, idx]), label=f'{idx}')
    if comp_label and not same_window:
        plt.title(f'{comp_label}')
    return ax
Пример #4
0
def test_to_numpy_error():
    da_array = da.array([0, 1, 2])
    with pytest.raises(LazyCupyConversion):
        to_numpy(da_array)
Пример #5
0
def test_to_numpy():
    cp_array = cp.array([0, 1, 2])
    np_array = np.array([0, 1, 2])
    np.testing.assert_allclose(to_numpy(cp_array), np_array)
    np.testing.assert_allclose(to_numpy(np_array), np_array)