Esempio n. 1
0
def load_data_and_reshape(dirname, names, remap_infinity=False):
    d = {}
    for name in names:
        # print("reading " + name)
        if "estimate_MFPT" in dirname:
            # Use a masked array. Mask missing values...
            m = np.genfromtxt(dirname + "/" + name + ".dat",
                              usemask=True,
                              missing_values="NaN,nan")
            # ... mask the diagonal...
            np.fill_diagonal(m, np.ma.masked)

            # ... and those where mfpte-len < 5...
            filename = dirname + "/MFPTE_len.dat"
            mfpte_len = np.genfromtxt(filename)
            min_vals = 5  # an attempt at reliability
            m[mfpte_len < min_vals] = np.ma.masked

            # FIXME mask those where MFPT < 0.1?
        else:
            m = np.genfromtxt(dirname + "/" + name + ".dat")

        if remap_infinity:
            # substitute an arbitrary large value for any infinities
            map_infinity_to_large(m)

        d[name] = m.reshape(len(m)**2)
    return d
Esempio n. 2
0
def load_data_and_reshape(dirname, names, remap_infinity=False):
    d = {}
    for name in names:
        # print("reading " + name)
        if "estimate_MFPT" in dirname:
            # Use a masked array. Mask missing values...
            m = np.genfromtxt(dirname + "/" + name + ".dat",
                              usemask=True, missing_values="NaN,nan")
            # ... mask the diagonal...
            np.fill_diagonal(m, np.ma.masked)

            # ... and those where mfpte-len < 5...
            filename = dirname + "/MFPTE_len.dat"
            mfpte_len = np.genfromtxt(filename)
            min_vals = 5 # an attempt at reliability
            m[mfpte_len < min_vals] = np.ma.masked

            # FIXME mask those where MFPT < 0.1?
        else:
            m = np.genfromtxt(dirname + "/" + name + ".dat")

        if remap_infinity:
            # substitute an arbitrary large value for any infinities
            map_infinity_to_large(m)

        d[name] = m.reshape(len(m)**2)
    return d
Esempio n. 3
0
def make_grid(w, names, filename, colour_map=None, bar=True):
    # we dont rescale the data. matshow() internally scales the data
    # so that the smallest numbers go to black and largest to white.

    # A uniform array will cause a "RuntimeWarning: invalid value
    # encountered in divide" when calculating the colorbar. So ignore
    # that.
    old = np.seterr(invalid='ignore')

    # Can put NaN on the diagonal to avoid plotting it -- makes a bit
    # more space available for other data. But misleading.

    # w += np.diag(np.ones(len(w)) * np.nan)

    # if w contains any NaNs we'll get a misleading result: they won't
    # be plotted, so will appear white, as will the largest finite
    # values of w. So first, replace them with a large value -- 100
    # times the largest finite value.
    map_infinity_to_large(w)

    side = 8.0
    figsize = (side, side)
    fig = plt.figure(figsize=figsize)
    ax = fig.add_subplot(1, 1, 1)
    # consider other colour maps: cm.gray_r for reversed, autumn, hot,
    # gist_earth, copper, ocean, some others, or a custom one for
    # nicer images (not for publication, maybe).
    # im = ax.matshow(w, cmap=cm.gray, interpolation="none")
    if colour_map is None: colour_map = cm.gray
    im = ax.matshow(w, cmap=colour_map, interpolation="nearest")
    if bar:
        fig.colorbar(im, shrink=0.775)

    if names:
        # Turn labels on
        ax.xaxis.set_major_locator(MyLocator(1, 0))
        ax.yaxis.set_major_locator(MyLocator(1, 0))
        ax.set_xticklabels(names, range(len(names)), rotation=90, size=1.0)
        ax.set_yticklabels(names, range(len(names)), size=1.0)
    else:
        # Turn them off
        ax.set_xticklabels([], [])
        ax.set_yticklabels([], [])

    ax.tick_params(length=0, pad=3.0)
    fig.savefig(filename + ".pdf", dpi=300, bbox_inches='tight')
    fig.savefig(filename + ".eps", dpi=300, bbox_inches='tight')
    fig.savefig(filename + ".png", dpi=300, bbox_inches='tight')
    plt.close(fig)

    # restore old error settings
    np.seterr(**old)
Esempio n. 4
0
def make_grid(w, names, filename, colour_map=None, bar=True):
    # we dont rescale the data. matshow() internally scales the data
    # so that the smallest numbers go to black and largest to white.

    # A uniform array will cause a "RuntimeWarning: invalid value
    # encountered in divide" when calculating the colorbar. So ignore
    # that.
    old = np.seterr(invalid='ignore')

    # Can put NaN on the diagonal to avoid plotting it -- makes a bit
    # more space available for other data. But misleading.

    # w += np.diag(np.ones(len(w)) * np.nan)

    # if w contains any NaNs we'll get a misleading result: they won't
    # be plotted, so will appear white, as will the largest finite
    # values of w. So first, replace them with a large value -- 100
    # times the largest finite value.
    map_infinity_to_large(w)

    side = 8.0
    figsize = (side, side)
    fig = plt.figure(figsize=figsize)
    ax = fig.add_subplot(1, 1, 1)
    # consider other colour maps: cm.gray_r for reversed, autumn, hot,
    # gist_earth, copper, ocean, some others, or a custom one for
    # nicer images (not for publication, maybe).
    # im = ax.matshow(w, cmap=cm.gray, interpolation="none")
    if colour_map is None: colour_map = cm.gray
    im = ax.matshow(w, cmap=colour_map, interpolation="nearest")
    if bar:
        fig.colorbar(im, shrink=0.775)

    if names:
        # Turn labels on
        ax.xaxis.set_major_locator(MyLocator(1, 0))
        ax.yaxis.set_major_locator(MyLocator(1, 0))
        ax.set_xticklabels(names, range(len(names)), rotation=90, size=1.0)
        ax.set_yticklabels(names, range(len(names)), size=1.0)
    else:
        # Turn them off
        ax.set_xticklabels([], [])
        ax.set_yticklabels([], [])

    ax.tick_params(length=0, pad=3.0)
    fig.savefig(filename + ".pdf", dpi=300, bbox_inches='tight')
    fig.savefig(filename + ".eps", dpi=300, bbox_inches='tight')
    fig.savefig(filename + ".png", dpi=300, bbox_inches='tight')
    plt.close(fig)
    
    # restore old error settings
    np.seterr(**old)