Пример #1
0
import numpy as np
import matplotlib.cm as cm
from matplotlib.colors import rgb2hex, XKCD_COLORS

# up to ~1000 colors
ID_TO_COL = {i: col for i, col in enumerate(XKCD_COLORS.values())}
DIST_TO_COL = np.vectorize(lambda x: rgb2hex(cm.Blues_r(x)))
Пример #2
0
    frame = event.frame
    image_feat = recog_net.feat_extract(frame)
    image_feature[counter, :] = image_feat.data.squeeze().unsqueeze_(0).numpy()
    counter += 1
event = env.step(action=dict(action='RotateRight', rotation=90.0))

# low dimensional embedding
svd = TruncatedSVD(n_components=50, n_iter=10)
image_feature_SVD = svd.fit_transform(image_feature)
image_embedded = TSNE(n_components=2).fit_transform(image_feature_SVD)

# plot embeddings
ff1 = plt.figure(figsize=(8, 6))
counter = 0
for i in range(100):
    plt.scatter(image_embedded[counter,0], image_embedded[counter,1],c=cm.Purples_r(i / 100.0))
    counter += 1
for i in range(100):
    plt.scatter(image_embedded[counter,0], image_embedded[counter,1],c=cm.Greens_r(i / 100.0))
    counter += 1
for i in range(100):
    plt.scatter(image_embedded[counter,0], image_embedded[counter,1],c=cm.Blues_r(i / 100.0))
    counter += 1
for i in range(100):
    plt.scatter(image_embedded[counter,0], image_embedded[counter,1],c=cm.Oranges_r(i / 100.0))
    counter += 1
plt.tight_layout()
plt.savefig('embedding3_ResNet3.png')
plt.close(ff1)

Пример #3
0
def plot_convergence(npy, file_name, model):

    converged_idx = 0

    if model == 'befavor':
        linspace = [
            np.linspace(3.4, 14.6, 8),
            np.linspace(1.0, 1.45, 6),
            np.linspace(0.0, 1.00, 5),
            np.linspace(0.0, 1.0, 5),
            np.linspace(50, 130, 5),
            np.linspace(0, 0.1, 5)
        ]
    if model == 'aara' or model == 'acol' or model == 'bcmi':
        linspace = [
            np.linspace(3.4, 14.6, 8),
            np.linspace(1.0, 1.45, 6),
            np.linspace(0.0, 1.00, 5),
            np.linspace(12., 14.0, 5),
            np.linspace(0., 30.0, 5),
            np.linspace(0.5, 2.0, 4),
            np.linspace(0.0, 1.0, 5),
            np.linspace(50, 130, 5),
            np.linspace(0, 0.1, 5)
        ]
    if model == 'beatlas':
        linspace = [
            np.linspace(3.8, 14.6, 5),
            np.linspace(1.0, 1.45, 6),
            np.linspace(0.0, 1.00, 5),
            np.linspace(3.0, 4.5, 4),
            np.linspace(0.0, 1.0, 5),
            np.linspace(50, 130, 5),
            np.linspace(0, 0.1, 5)
        ]
    # Map the codified parameter names to their sexy latex equivalents
    if model == 'befavor':
        param_to_latex = dict(mass=r'$M\,[M_\odot]$',
                              oblat=r"$R_\mathrm{eq} / R_\mathrm{pole}$",
                              age=r"$H_\mathrm{frac}$",
                              inc=r'$\cos i$',
                              dis=r'$d\,[pc]$',
                              ebv=r'$E(B-V)$')
        params = ["mass", "oblat", "age", "inc", "dis", "ebv"]
        fig = plt.figure(figsize=(16, 20.6))
    if model == 'aara' or model == 'acol' or model == 'bcmi':
        param_to_latex = dict(mass=r'$M\,[M_\odot]$',
                              oblat=r"$R_\mathrm{eq} / R_\mathrm{pole}$",
                              age=r"$H_\mathrm{frac}$",
                              logn0=r'$\log \, n_0 \, [\mathrm{cm}^{-3}]$',
                              rdk=r'$R_\mathrm{D}\, [R_\star]$',
                              inc=r'$\cos i$',
                              nix=r'$m$',
                              dis=r'$d\,[\mathrm{pc}]$',
                              ebv=r'$E(B-V)$')
        params = [
            "mass", "oblat", "age", "logn0", "rdk", "nix", "inc", "dis", "ebv"
        ]
        fig = plt.figure(figsize=(16, 24.6))
    if model == 'beatlas':
        param_to_latex = dict(mass=r'$M\,[M_\odot]$',
                              oblat=r"$R_\mathrm{eq} / R_\mathrm{pole}$",
                              sig0=r'$\Sigma_0$',
                              nix=r'$n$',
                              inc=r'$\cos i$',
                              dis=r'$d\,[pc]$',
                              ebv=r'$E(B-V)$')
        params = ["mass", "oblat", "sig0", "nix", "inc", "dis", "ebv"]
        fig = plt.figure(figsize=(16, 20.6))

    chain = np.load(npy)

    # chain = chain[(acceptance_fractions > 0.20) &
    #               (acceptance_fractions < 0.5)]

    gs = gridspec.GridSpec(len(params), 3)
    # gs.update(hspace=0.10, wspace=0.025, top=0.85, bottom=0.44)
    gs.update(hspace=0.25)

    for ii, param in enumerate(params):
        these_chains = chain[:, :, ii]

        max_var = max(np.var(these_chains[:, converged_idx:], axis=1))

        ax1 = plt.subplot(gs[ii, :2])

        ax1.axvline(0, color="#67A9CF", alpha=0.7, linewidth=2)

        for walker in these_chains:
            ax1.plot(np.arange(len(walker)) - converged_idx,
                     walker,
                     drawstyle="steps",
                     color=cm.Blues_r(
                         np.var(walker[converged_idx:]) / max_var),
                     alpha=0.5)

        ax1.set_ylabel(param_to_latex[param],
                       fontsize=30,
                       labelpad=18,
                       rotation="vertical",
                       color=font_color)

        # Don't show ticks on the y-axis
        ax1.yaxis.set_ticks([])

        # For the plot on the bottom, add an x-axis label. Hide all others
        if ii == len(params) - 1:
            ax1.set_xlabel("step number",
                           fontsize=24,
                           labelpad=18,
                           color=font_color)
        else:
            ax1.xaxis.set_visible(False)

        ax2 = plt.subplot(gs[ii, 2])

        ax2.hist(np.ravel(these_chains[:, converged_idx:]),
                 bins=np.linspace(ax1.get_ylim()[0],
                                  ax1.get_ylim()[1], 20),
                 orientation='horizontal',
                 facecolor="#67A9CF",
                 edgecolor="none",
                 normed=True,
                 histtype='barstacked')

        ax2.xaxis.set_visible(False)
        ax2.yaxis.tick_right()

        # print(ii)
        # print(param)
        ax2.set_yticks(linspace[ii])
        ax1.set_ylim(ax2.get_ylim())

        if ii == 0:
            t = ax1.set_title("Walkers", fontsize=30, color=font_color)
            t.set_y(1.01)
            t = ax2.set_title("Posterior", fontsize=30, color=font_color)
            t.set_y(1.01)

        ax1.tick_params(axis='x',
                        pad=2,
                        direction='out',
                        colors=tick_color,
                        labelsize=22)
        ax2.tick_params(axis='y',
                        pad=2,
                        direction='out',
                        colors=tick_color,
                        labelsize=22)

        ax1.get_xaxis().tick_bottom()

    fig.subplots_adjust(hspace=0.0,
                        wspace=0.0,
                        bottom=0.075,
                        top=0.9,
                        left=0.12,
                        right=0.88)
    plt.savefig(file_name + '.png')
Пример #4
0
view.camera = 'arcball'
# view.camera = 'fly'
#

Globe = np.load(sys.argv[1])
Elevation = np.load(sys.argv[2])
Temps = np.load(sys.argv[3])

if len(sys.argv) > 4:
    Rads =np.ones(Globe[0].shape)+0.01*Elevation
else:
    Rads = np.ones(Globe[0].shape)

colors = np.empty((*Elevation.shape,4))
colors[Elevation>0.45] = cm.YlGn_r(Elevation)[Elevation>0.45]
colors[Elevation<=0.45] = cm.Blues_r(Elevation)[Elevation<=0.45]

Tempcolors = np.zeros_like(colors)
Tempcolors[np.where(Temps < 0.15)] = cm.cool(Temps, alpha = 0.8)[np.where(Temps < 0.15)]

# print(Tempcolors)

def toCart(p,t,r):
    return r*np.cos(t)*np.sin(p),r*np.sin(t)*np.sin(p),r*np.cos(p)

BumpySphereCart = toCart(*Globe,Rads)
BumpySphereCart2 = toCart(*Globe,Rads+0.001)

# bumpy = geometry.MeshData(vertices = BumpySphereCart)
scene.visuals.GridMesh(*BumpySphereCart,parent=view.scene, colors = colors,shading = None)
scene.visuals.GridMesh(*BumpySphereCart2,parent=view.scene, colors = Tempcolors,shading = None)
Пример #5
0
def main(args):
    df1 = pd.read_csv(args.top_csv)
    df2 = pd.read_csv(args.bot_csv)
    top = df1.values[:, 1:]
    top = np.array(top)
    max_top = np.ptp(top)
    bot = df2.values[:, 1:]
    bot = np.array(bot)
    max_bot = np.ptp(bot)

    # I need f(y) : f(mx) = T, f(0) = 0
    # Scale 0 -> T to 0 to mx
    def rescale(m, mx):
        nm = np.where(m > 0, m, int(1e9))
        T = 0.35
        mn = np.min(nm)

        #print(mn)
        def alter(x):
            if x == 0:
                return 1.0
            #print(x, mn)
            shift_x = x - mn
            sc = shift_x / mx
            assert 0 <= sc and sc <= 1
            rsc = sc * T

            return 1 - rsc
            #return 1-((x-mn)/mx)*T

        #scale = lambda x: alter(x)
        return alter

    top_scale = rescale(top, max_top)
    bot_scale = rescale(bot, max_bot)

    # print(scale(m))
    #keys = df1.columns[1:]
    def f(c, v):
        r, g, b, a = c
        g = lambda x: '{:3f}'.format(x)
        cstring = ','.join(map(g, c[:3]))
        color = '\\cellcolor[rgb]{{{c}}}{{{v}}}'.format(c=cstring, v=v)
        return color

    for ii in range(1, len(df1.index) + 1):
        vals = []
        i = ii - 1
        for j in range(0, len(df2.index) + 1):
            if j == 0:
                vals.append(str(df1.values[i, j]))

            elif ii < j:
                x = int(top_scale(df1.values[i, j]) * 255)
                color = cm.Blues_r(x)
                cell = f(c=color, v=df1.values[i, j])
                vals.append(cell)
            elif ii > j:
                x = int(bot_scale(df2.values[i, j]) * 255)
                color = cm.Reds_r(x)
                cell = f(c=color, v=df2.values[i, j])
                vals.append(cell)
            else:
                vals.append('')
            #print(df1.values[i,j],df2.values[i,j],i,j)
            # for idx, row in df1.iterrows():
            #
            #     for key in keys:
            #         v = row[key]
            #         cell = ('\\cc{{{c:.3f}}}{{{v}}}'
            #                 .format(c=scale(v), v=v))
            #         vals.append(cell)

        print('&'.join(vals), end='')
        print('\\\\')
Пример #6
0
def plotConvergence(npy, filename, ranges, inclFlag):
    converged_idx = 0

    if inclFlag:  #If multiple inclinations are given
        linspace = [
            np.linspace(ranges[0][0], ranges[0][1], 5),
            np.linspace(ranges[1][0], ranges[1][1], 5),
            np.linspace(ranges[2][0], ranges[2][1], 5),
            np.linspace(ranges[3][0], ranges[3][1], 5)
        ]

        param_to_latex = dict(inc=r'$i [^{\circ}$]',
                              f_e=r'$f_{e}$',
                              v_h=r'$v_{h} [km/s]$',
                              v_e=r'$v_{e}$ [km/s]')
        params = ["inc", "f_e", "v_h", "v_e"]
        fig = plt.figure(num=None, figsize=(6, 8), dpi=100, facecolor='w',\
         edgecolor='k')

    else:  #If only one inclination is given
        linspace = [
            np.linspace(ranges[0][0], ranges[0][1], 5),
            np.linspace(ranges[1][0], ranges[1][1], 5),
            np.linspace(ranges[2][0], ranges[2][1], 5)
        ]

        param_to_latex = dict(f_e=r'$f_{e}$', v_h=r'$v_{h} [km/s]$',\
         v_e=r'$v_{e} [km/s]$')
        params = ["f_e", "v_h", "v_e"]
        fig = plt.figure(num=None, figsize=(6, 8), dpi=100, facecolor='w',\
         edgecolor='k')

    chain = np.load(npy)

    gs = gridspec.GridSpec(len(params), 3)
    gs.update(hspace=0.25)

    for ii, param in enumerate(params):
        these_chains = chain[:, :, ii]

        max_var = max(np.var(these_chains[:, converged_idx:], axis=1))

        ax1 = plt.subplot(gs[ii, :2])

        ax1.axvline(0, color="#67A9CF", alpha=0.7, linewidth=2)

        for walker in these_chains:
            ax1.plot(np.arange(len(walker)) - converged_idx,
                     walker,
                     drawstyle="steps",
                     color=cm.Blues_r(
                         np.var(walker[converged_idx:]) / max_var),
                     alpha=0.5)

        ax1.set_ylabel(param_to_latex[param],
                       fontsize='xx-large',
                       labelpad=18,
                       rotation="vertical",
                       color=font_color)

        # Don't show ticks on the y-axis
        ax1.yaxis.set_ticks([])

        # For the plot on the bottom, add an x-axis label. Hide all others
        if ii == len(params) - 1:
            ax1.set_xlabel("step number",
                           fontsize='x-large',
                           labelpad=18,
                           color=font_color)
        else:
            ax1.xaxis.set_visible(False)

        ax2 = plt.subplot(gs[ii, 2])

        ax2.hist(np.ravel(these_chains[:, converged_idx:]),
                 bins=np.linspace(ax1.get_ylim()[0],
                                  ax1.get_ylim()[1], 20),
                 orientation='horizontal',
                 facecolor="#67A9CF",
                 edgecolor="none",
                 normed=True,
                 histtype='barstacked')

        ax2.xaxis.set_visible(False)
        ax2.yaxis.tick_right()

        ax2.set_yticks(linspace[ii])
        ax1.set_ylim(ax2.get_ylim())

        if ii == 0:
            t = ax1.set_title("Walkers", fontsize='x-large', color=font_color)
            t.set_y(1.01)
            t = ax2.set_title("Posterior",
                              fontsize='x-large',
                              color=font_color)
            t.set_y(1.01)

        ax1.tick_params(axis='x',
                        pad=2,
                        direction='out',
                        colors=tick_color,
                        labelsize='large')
        ax2.tick_params(axis='y',
                        pad=2,
                        direction='out',
                        colors=tick_color,
                        labelsize='large')

        ax1.get_xaxis().tick_bottom()

    fig.subplots_adjust(hspace=0.0,
                        wspace=0.0,
                        bottom=0.10,
                        top=0.93,
                        left=0.12,
                        right=0.87)
    #plt.show()
    plt.savefig(filename + '.png')
Пример #7
0
def MakeColArr(Elv, LI, newL):
    colorArr = np.zeros((newL[1], newL[0], 4))
    colorArr[LI.T] = cm.YlGn_r(Elv.T)[LI]
    colorArr[np.invert(LI.T)] = cm.Blues_r(Elv.T)[np.invert(LI.T)]
    return colorArr
Пример #8
0
    t = np.linspace(0, 20, tn + 1).reshape((1, tn + 1))
    Space, Time = np.meshgrid(s, t)

    s_i = s - c * (t)
    wave_surf = wave_phi(s_i)
    wave_surf = wave_surf.T
    """
        plot original wave
    """
    figcont += 1
    fig = plt.figure(figsize=(8, 4))
    ax = Axes3D(fig)
    ax.plot_surface(Space,
                    Time,
                    wave_surf,
                    facecolors=cm.Blues_r(wave_surf / 4 * wave_surf.max()),
                    antialiased=False,
                    shade=False)
    ax.view_init(elev=40, azim=235)
    ax.set_zlim(-2, 2)
    ax.set_zticks(np.array([0, 1, 2]))
    ax.grid(False)
    plt.xlim(-0.05, 1)
    plt.ylim(-0.5, 20)
    plt.xlabel("space(s)", size=12)
    plt.ylabel("time(t)", size=12)
    plt.xticks(np.linspace(0, 1, 6))
    plt.yticks(np.linspace(0, tn, tn // 5 + 1))
    plt.tick_params(labelsize='10')
    plt.title("true wave", fontsize=15)
    plt.grid()
Пример #9
0
    ax3.plot(exc_range,
             inh_exc_stn_ff[inh_count],
             color=cm.Greens_r(inh_count * 30),
             lw=3.,
             label=str(inh_val))
    ax2.plot(exc_range,
             inh_exc_gpe_fr[inh_count],
             color=cm.Reds_r(inh_count * 30),
             lw=3.)
    ax4.plot(exc_range,
             inh_exc_gpe_ff[inh_count],
             color=cm.Greens_r(inh_count * 30),
             lw=3.)
    ax5.plot(exc_range,
             inh_exc_stn_spec[inh_count],
             color=cm.Blues_r(inh_count * 30),
             lw=3.,
             label=str(inh_val))
    ax6.plot(exc_range,
             inh_exc_gpe_spec[inh_count],
             color=cm.Blues_r(inh_count * 30),
             lw=3.)
ax1.legend(prop={'size': 7.}, title='BS frac. GPe')
ax1.set_ylabel('Firing rate (Bq)')

ax3.legend(prop={'size': 7.}, title='BS frac. GPe')
ax3.set_ylabel('Fano Factor')

ax5.legend(prop={'size': 7.}, title='BS frac. GPe')
ax5.set_ylabel('spectral entropy')
ax6.set_xlabel('BS ratio STN')