Exemple #1
0
def plot_sensitivity(dataset_name, save):
    conf = arim.io.load_conf(dataset_name)
    result_dir = conf["result_dir"]
    with open(result_dir / "sensitivity_images.pickle", "rb") as f:
        loaded = pickle.load(f)

    grid = loaded["grid"]

    ncols = 3
    nrows = 7
    fig, axes = plt.subplots(
        ncols=ncols, nrows=nrows, figsize=(7.4, 8), sharex=False, sharey=False
    )

    xmin = grid.xmin
    xmax = grid.xmax
    zmin = conf["frontwall"]["z"]
    zmax = conf["backwall"]["z"]

    ref_db = max(np.nanmax(np.abs(data)) for data in loaded["images"].values())

    for (viewname, data), ax in zip(loaded["images"].items(), axes.ravel()):
        clim = [-40, 0.]
        ax, im = aplt.plot_oxz(
            data,
            grid,
            ax=ax,
            scale="db",
            ref_db=ref_db,
            clim=clim,
            interpolation="none",
            savefig=False,
            draw_cbar=False,
        )
        ax.set_title(viewname, y=.9, size="small")
        ax.set_adjustable("box")
        ax.axis([xmin, xmax, zmax, zmin])

        if ax in axes[-1, :]:
            ax.set_xlabel("x (mm)")
            ax.set_xticks([xmin, xmax, np.round((xmin + xmax) / 2, decimals=3)])
        else:
            ax.set_xlabel("")
            ax.set_xticks([])
        if ax in axes[:, 0]:
            ax.set_ylabel("z (mm)")
            ax.set_yticks([zmax, zmin, np.round((zmin + zmax) / 2, decimals=3)])
        else:
            ax.set_ylabel("")
            ax.set_yticks([])

    cbar = fig.colorbar(
        im, ax=axes.ravel().tolist(), location="top", fraction=0.05, aspect=40, pad=0.03
    )
    cbar.ax.set_ylabel("dB")

    if save:
        fig.savefig(str(result_dir / "sensitivity"))
Exemple #2
0
def test_plot_oxz(show_plots):
    grid = arim.Grid(-5e-3, 5e-3, 0, 0, 0, 15e-3, 0.1e-3)
    k = 2 * np.pi / 10e-3
    data = (np.cos(grid.x * 2 * k) * np.sin(grid.z * k)) * (grid.z**2)

    # check it works without error
    ax, im = aplt.plot_oxz(data, grid)
    plt.close("all")

    ax, im = aplt.plot_oxz(
        data.reshape((grid.numx, grid.numz)),
        grid,
        scale="linear",
        title="some linear stuff",
    )
    if show_plots:
        plt.show()
    else:
        plt.close("all")

    with tempfile.TemporaryDirectory() as dirname:
        out_file = Path(dirname) / Path("toto.png")
        ax, im = aplt.plot_oxz(
            data,
            grid,
            title="some db stuff",
            scale="db",
            clim=[-12, 0],
            savefig=True,
            filename=str(out_file),
        )
        if show_plots:
            plt.show()
        else:
            plt.close("all")
        assert out_file.exists()