コード例 #1
0
ファイル: panel_plot.py プロジェクト: mwit78/libmpdataxx
def panel_plot(plot_data, fname='panel.pdf'):
    set_rc_params(tickfs=30)

    levels = np.linspace(-0.05, 1.15, 25)

    fig, axarr = plt.subplots(2,
                              2,
                              figsize=(20, 14),
                              sharex='col',
                              sharey='row')
    field2pos = {'gh': (0, 0), 'cb': (0, 1), 'ccb': (1, 1), 'sc': (1, 0)}
    field2title = {
        'gh': '(a) Gaussian hills',
        'cb': '(b) cosine bells',
        'ccb': "(d) 'correlated' cosine bells",
        'sc': '(c) slotted cylinders'
    }

    for f in plot_data.keys():
        field = np.transpose(plot_data[f])
        ny, nx = field.shape
        cmap = plt.get_cmap('terrain')
        i = field2pos[f]
        p = axarr[i].contourf(field, levels=levels, zorder=1, cmap=cmap)
        axarr[i].contour(field, levels=levels, zorder=1, cmap=cmap)
        axarr[i].set_title(field2title[f], fontsize=30, y=1.02)

    for ax in axarr.flatten():
        ax.set_xticks(
            [0, (nx - 1) / 4, (nx - 1) / 2, 3 * (nx - 1) / 4, nx - 1])
        ax.set_xticklabels(
            [r'$0$', r'$\pi$/2', r'$\pi$', r'$3\pi/2$', r'$2\pi$'])

        ax.set_yticks([0, (ny + 0.5) / 2, ny - 1])
        ax.set_yticklabels([r'$-\pi/2$', r'$0$', r'$\pi/2$'])
        ax.grid(color='w', lw=2, linestyle=':')

    plt.subplots_adjust(bottom=0.2)

    cbaxes = fig.add_axes([0.1, 0.1, 0.8, 0.02])
    plt.colorbar(p, cax=cbaxes, ticks=levels[1:-1:2], orientation='horizontal')

    #plt.tight_layout(pad=1., w_pad=5., h_pad=1)
    plt.savefig(fname, bbox_inches='tight')
コード例 #2
0
ファイル: conv_plot.py プロジェクト: djarecka/libmpdataxx
def conv_plot(plot_data, ord_data, fname = 'fig.pdf'):
    set_rc_params()
    fs = 45

    lab2ls = {'Mp3' : 'ks-', 'Mp3cc' : 'bo-', 'Mg3No' : 'gD-', 'Mg2No' : 'r^-'}
    lab2dsh = {'Mp3' : [], 'Mp3cc' : [6, 1], 'Mg3No' : [1, 1], 'Mg2No' : [6, 1, 1 ,1]}

    fig, axarr = plt.subplots(1, 1, figsize=(14,12))

    plots = {}
    for x, y, opt in plot_data:
        zo = 2.0
        lab = opt2lab[opt]
        if lab == 'Mg3No':
            zo = 2.1
        p, = axarr.loglog(x, y, lab2ls[lab], label = lab, lw = 6, ms = 16, dashes = lab2dsh[lab], zorder = zo)
        plots[lab] = p

    for x, y, x0, y0, t, a in ord_data:
        axarr.loglog(x, y, color = 'gray', lw = 6)
        axarr.text(x0, y0, t, rotation = a, size = 28, backgroundcolor = 'w', zorder=2.1)

    axarr.xaxis.set_ticks(plot_data[0][0])
    axarr.xaxis.set_tick_params(direction = 'in')
    axarr.yaxis.set_tick_params(direction = 'in')
    axarr.minorticks_off()

    axarr.get_xaxis().set_major_formatter(ScalarFormatter())

    axarr.set_xlabel('$N$', fontsize = fs)
    axarr.set_ylabel('$\ell_2$ error norm', fontsize = fs)

    labels = list(range(len(plots.keys())))
    for lab in plots.keys():
        labels[lab2pos[lab]] = lab
    handles = [plots[lab] for lab in labels]
    l = axarr.legend(handles, labels, fontsize=fs, numpoints=1, edgecolor = 'k', framealpha = 1.0, loc = 3, handlelength = 2.5)
    l.get_frame().set_linewidth(3)

    axarr.grid(color = 'k', lw = 2, linestyle = ':')

    plt.tight_layout(pad=1., w_pad=5., h_pad=1)
    plt.savefig(fname)
コード例 #3
0
ファイル: panel_plot.py プロジェクト: djarecka/libmpdataxx
def panel_plot(plot_data, fname = 'panel.pdf'):
    set_rc_params(tickfs = 30)

    levels = np.linspace(-0.05, 1.15, 25)

    fig, axarr = plt.subplots(2, 2, figsize=(20, 14), sharex = 'col', sharey = 'row')
    field2pos = {'gh' :  (0, 0), 'cb' : (0, 1), 'ccb' : (1, 1), 'sc' : (1, 0) }
    field2title = {'gh' :  '(a) Gaussian hills',
                   'cb' : '(b) cosine bells',
                   'ccb' : "(d) 'correlated' cosine bells",
                   'sc' : '(c) slotted cylinders'}

    for f in plot_data.keys():
        field = np.transpose(plot_data[f])
        ny, nx = field.shape
        cmap = plt.get_cmap('terrain')
        i = field2pos[f]
        p = axarr[i].contourf(field, levels = levels, zorder = 1, cmap = cmap)
        axarr[i].contour(field, levels = levels, zorder = 1, cmap = cmap)
        axarr[i].set_title(field2title[f], fontsize = 30, y = 1.02)

    for ax in axarr.flatten():
        ax.set_xticks([0, (nx - 1) / 4, (nx - 1) / 2, 3 * (nx - 1) / 4, nx - 1])
        ax.set_xticklabels([r'$0$', r'$\pi$/2', r'$\pi$', r'$3\pi/2$', r'$2\pi$'])

        ax.set_yticks([0, (ny+0.5) / 2, ny - 1])
        ax.set_yticklabels([r'$-\pi/2$', r'$0$', r'$\pi/2$'])
        ax.grid(color = 'w', lw = 2, linestyle = ':')

    plt.subplots_adjust(bottom=0.2)

    cbaxes = fig.add_axes([0.1, 0.1, 0.8, 0.02])
    plt.colorbar(p, cax = cbaxes, ticks = levels[1:-1:2], orientation = 'horizontal')

    #plt.tight_layout(pad=1., w_pad=5., h_pad=1)
    plt.savefig(fname, bbox_inches='tight')
コード例 #4
0
ファイル: panel_plot.py プロジェクト: mwit78/libmpdataxx
def panel_plot(geo_data, field_data, opt, time, ny, fname):
    set_rc_params(onlytex=True)

    nx, ny = geo_data[ny]['g'].shape
    X = geo_data[ny]['di'] * np.arange(nx)
    Y = geo_data[ny]['dj'] * (np.arange(ny) + 0.5) - pi / 2
    # extend Y values to cover the poles
    Y = np.concatenate([[-pi / 2], Y, [pi / 2]])
    X, Y = np.meshgrid(X, Y, indexing='ij')

    init = asolution(0.0, X, Y)
    asol = asolution(float(time), X, Y)
    nsol = field_data[ny][opt][time]['psi']
    nsol = np.concatenate([np.zeros((nx, 1)), nsol, np.zeros((nx, 1))], axis=1)
    errf = nsol - asol

    panel_fields = {'init': init, 'asol': asol, 'nsol': nsol, 'errf': errf}

    XI, YI, XN, YN = transform_iso_coord(X, Y)

    for pf in panel_fields:
        panel_fields[pf] = transform_iso_field(panel_fields[pf], X, Y)

    levels = [0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6]
    colors = [
        'white', 'slateblue', 'indigo', 'mediumblue', 'blue', 'darkolivegreen',
        'olive', 'lawngreen', 'yellowgreen', 'darkorange', 'red', 'firebrick'
    ]
    err_levels = [-0.021, -0.015, -0.009, -0.003, 0.003, 0.009, 0.015, 0.021]
    err_colors = [
        'slateblue', 'blue', 'indigo', 'white', 'darkorange', 'red',
        'firebrick'
    ]
    fig, axarr = plt.subplots(2, 2, figsize=(15, 12))

    for ax in axarr.flatten():
        ax.axis('off')
        ax.contour(XI,
                   YI,
                   XN,
                   levels=xlevels,
                   linewidths=(0.5, ),
                   colors=('k', ),
                   linestyles=('dashed', ))
        ax.contour(XI,
                   YI,
                   YN,
                   levels=ylevels,
                   linewidths=(0.5, ),
                   colors=('k', ),
                   linestyles=('dashed', ))

    p = axarr[0, 0].contourf(XI,
                             YI,
                             panel_fields['init'],
                             levels=levels,
                             colors=colors)
    cb1 = fig.colorbar(p, ax=axarr[0, 0], ticks=levels[1:-1])

    p = axarr[0, 1].contourf(XI,
                             YI,
                             panel_fields['asol'],
                             levels=levels,
                             colors=colors)
    cb2 = fig.colorbar(p, ax=axarr[0, 1], ticks=levels[1:-1])

    p = axarr[1, 1].contourf(XI,
                             YI,
                             panel_fields['nsol'],
                             levels=levels,
                             colors=colors)
    cb3 = fig.colorbar(p, ax=axarr[1, 1], ticks=levels[1:-1])

    p = axarr[1, 0].contourf(XI,
                             YI,
                             panel_fields['errf'],
                             levels=err_levels,
                             colors=err_colors)
    cb4 = fig.colorbar(p, ax=axarr[1, 0], ticks=err_levels[1:-1])

    for cb in [cb1, cb2, cb3, cb4]:
        ticklabs = cb.ax.get_yticklabels()
        cb.ax.tick_params(labelsize=16)

    axarr[0, 0].set_title('(a) Initial condition', y=1.02, fontsize=30)
    axarr[0, 1].set_title(r'(b) Exact solution $t = 12$ days',
                          y=1.02,
                          fontsize=30)
    axarr[1, 0].set_title(r'(c) Difference $t = 12$ days', y=1.02, fontsize=30)
    axarr[1, 1].set_title(r'(d) Numerical solution $t = 12$ days',
                          y=1.02,
                          fontsize=30)

    cb4.ax.set_yticklabels(ticklabs, ha='right')
    cb4.ax.yaxis.set_tick_params(pad=50)
    plt.tight_layout(pad=1., w_pad=5., h_pad=1)
    plt.savefig(fname, transparent=True)
コード例 #5
0
ファイル: panel_plot.py プロジェクト: djarecka/libmpdataxx
def panel_plot(geo_data, field_data, opt, time, ny, fname):
    set_rc_params(onlytex = True)

    nx, ny = geo_data[ny]['g'].shape
    X = geo_data[ny]['di'] * np.arange(nx)
    Y = geo_data[ny]['dj'] * (np.arange(ny) + 0.5) - pi / 2
    # extend Y values to cover the poles
    Y = np.concatenate([[-pi / 2], Y, [pi / 2]])
    X, Y = np.meshgrid(X, Y, indexing ='ij')

    init = asolution(0.0, X, Y)
    asol = asolution(float(time), X, Y)
    nsol = field_data[ny][opt][time]['psi']
    nsol = np.concatenate([np.zeros((nx, 1)), nsol, np.zeros((nx, 1))], axis = 1)
    errf = nsol - asol

    panel_fields = {'init' : init, 'asol' : asol, 'nsol' : nsol, 'errf' : errf}

    XI, YI, XN, YN = transform_iso_coord(X, Y)

    for pf in panel_fields:
        panel_fields[pf] = transform_iso_field(panel_fields[pf], X, Y)

    levels = [0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6]
    colors = ['white',
              'slateblue',
              'indigo',
              'mediumblue',
              'blue',
              'darkolivegreen',
              'olive',
              'lawngreen',
              'yellowgreen',
              'darkorange',
              'red',
              'firebrick'
              ]
    err_levels = [-0.021, -0.015, -0.009, -0.003,  0.003,  0.009, 0.015, 0.021]
    err_colors = [
              'slateblue',
              'blue',
              'indigo',
              'white',
              'darkorange',
              'red',
              'firebrick'
              ]
    fig, axarr = plt.subplots(2, 2, figsize = (15, 12))

    for ax in axarr.flatten():
        ax.axis('off')
        ax.contour(XI, YI, XN, levels = xlevels, linewidths = (0.5,), colors = ('k',), linestyles = ('dashed',))
        ax.contour(XI, YI, YN, levels = ylevels, linewidths = (0.5,), colors = ('k',), linestyles = ('dashed',))

    p = axarr[0, 0].contourf(XI, YI, panel_fields['init'], levels = levels, colors = colors)
    cb1 = fig.colorbar(p, ax = axarr[0, 0], ticks = levels[1:-1])

    p = axarr[0, 1].contourf(XI, YI, panel_fields['asol'], levels = levels, colors = colors)
    cb2 = fig.colorbar(p, ax = axarr[0, 1], ticks = levels[1:-1])

    p = axarr[1, 1].contourf(XI, YI, panel_fields['nsol'], levels = levels, colors = colors)
    cb3 = fig.colorbar(p, ax = axarr[1, 1], ticks = levels[1:-1])

    p = axarr[1, 0].contourf(XI, YI, panel_fields['errf'], levels = err_levels, colors = err_colors)
    cb4 = fig.colorbar(p, ax = axarr[1, 0], ticks = err_levels[1:-1])

    for cb in [cb1, cb2, cb3, cb4]:
        ticklabs = cb.ax.get_yticklabels()
        cb.ax.tick_params(labelsize=16)

    axarr[0, 0].set_title('(a) Initial condition', y = 1.02, fontsize = 30)
    axarr[0, 1].set_title(r'(b) Exact solution $t = 12$ days', y = 1.02, fontsize = 30)
    axarr[1, 0].set_title(r'(c) Difference $t = 12$ days', y = 1.02, fontsize = 30)
    axarr[1, 1].set_title(r'(d) Numerical solution $t = 12$ days', y = 1.02, fontsize = 30)


    cb4.ax.set_yticklabels(ticklabs,ha='right')
    cb4.ax.yaxis.set_tick_params(pad=50)
    plt.tight_layout(pad=1., w_pad=5., h_pad=1)
    plt.savefig(fname, transparent = True)
コード例 #6
0
ファイル: mixing.py プロジェクト: djarecka/libmpdataxx
def plot_mixing(field_data, mixing_diags, ny, fname = 'mixing.pdf'):
    set_rc_params()
    matplotlib.rcParams['text.latex.preamble']=[r"\usepackage{amsmath}"]

    plt.clf()
    fig, axarr = plt.subplots(2, 2, sharex='col', sharey = 'row', figsize=(14, 12))

    c = 'red'
    s = 1
    marker = '.'
    edgecolor = 'r'
    fs = 22
    lw = 2

    x = np.linspace(xmin, xmax)

    for opt in field_data[ny]:
        cb, ccb = field_data[ny][opt]['2.5']['cb'].flatten(), field_data[ny][opt]['2.5']['ccb'].flatten()

        lab = opt2lab[opt]

        lab2num = {'Mp3' : (0, 1), 'Mp3cc' : (0, 0), 'Mg2No' : (1, 0), 'Mg3No' : (1, 1)}
        num = lab2num[lab]

        axarr[num].scatter(cb, ccb, c = c, s = s, marker = marker, edgecolor = edgecolor, rasterized = True)
        axarr[num].plot(x, corr_func(x), 'k-', lw = lw)
        axarr[num].plot(x, ymin * x / x, 'k-', lw = lw)
        axarr[num].plot(xmax * x / x, np.linspace(ymax, ymin), 'k-', lw = lw)
        axarr[num].plot(x, line_func(x), 'k-', lw = lw)

        axarr[num].set_ylim([0, 1])
        axarr[num].set_xlim([0, 1.1])
        axarr[num].set_title(lab, fontsize = fs + 8, y = 1.02)
        if (num not in [(0, 0), (0, 1)]):
            axarr[num].set_xlabel('$\\chi$', fontsize = fs+2)
        if (num not in [(1, 1), (0, 1)]):
            axarr[num].set_ylabel('$\\xi$', fontsize = fs+2)

        axarr[num].xaxis.set_tick_params(direction = 'in', top = True, labelsize = 20)
        axarr[num].xaxis.set_ticks([0.0, 0.2, 0.4, 0.6, 0.8, 1.0])
        #if (num in [(1, 0), (1, 1)]):
        axarr[num].yaxis.set_ticks([0.0, 0.2, 0.4, 0.6, 0.8, 1.0])
        axarr[num].yaxis.set_tick_params(direction = 'in', right = True, labelsize = 20)
        axarr[num].minorticks_off()

        axarr[num].grid()

        lr, lu, lo = mixing_diags[ny][opt]

        expformat = '{} \\times 10^{{{}}}'

        lrs = '{:.2e}'.format(lr)
        l_r_d, l_r_e = (lrs[0:4], int(lrs[5:]))

        lus = '{:.2e}'.format(lu)
        l_u_d, l_u_e = lus[0:4], int(lus[5:])

        if lo != 0:
            los = '{:.2e}'.format(lo)
            lo = (los[0:4], int(los[5:]))
            loformat = expformat
        else:
            lo = (lo,)
            loformat = '{:g}'

        test2 = (
                '''\\begin{{{{align}}}}'''
                '''l_r &= {l_r_format}\\\\'''
                '''l_u &= {l_u_format}\\\\'''
                '''l_o &= {l_o_format}\\\\'''
                '''\\end{{{{align}}}}'''
               )
        test = test2.format(l_r_format = expformat,
                            l_u_format = expformat,
                            l_o_format = loformat)

        axarr[num].text(0.1,
                        0.05,
                        test.format(l_r_d, l_r_e, l_u_d, l_u_e, *lo),
                        size = 28,
                        multialignment = 'left'
                       )
    plt.tight_layout(pad=1., w_pad=5., h_pad=1)
    plt.savefig(fname)
コード例 #7
0
ファイル: mixing.py プロジェクト: trontrytel/libmpdataxx
def plot_mixing(field_data, mixing_diags, ny, fname='mixing.pdf'):
    set_rc_params()
    matplotlib.rcParams['text.latex.preamble'] = [r"\usepackage{amsmath}"]

    plt.clf()
    fig, axarr = plt.subplots(2,
                              2,
                              sharex='col',
                              sharey='row',
                              figsize=(14, 12))

    c = 'red'
    s = 1
    marker = '.'
    edgecolor = 'r'
    fs = 22
    lw = 2

    x = np.linspace(xmin, xmax)

    for opt in field_data[ny]:
        cb, ccb = field_data[ny][opt]['2.5']['cb'].flatten(
        ), field_data[ny][opt]['2.5']['ccb'].flatten()

        lab = opt2lab[opt]

        lab2num = {
            'Mp3': (0, 1),
            'Mp3cc': (0, 0),
            'Mg2No': (1, 0),
            'Mg3No': (1, 1)
        }
        num = lab2num[lab]

        axarr[num].scatter(cb,
                           ccb,
                           c=c,
                           s=s,
                           marker=marker,
                           edgecolor=edgecolor,
                           rasterized=True)
        axarr[num].plot(x, corr_func(x), 'k-', lw=lw)
        axarr[num].plot(x, ymin * x / x, 'k-', lw=lw)
        axarr[num].plot(xmax * x / x, np.linspace(ymax, ymin), 'k-', lw=lw)
        axarr[num].plot(x, line_func(x), 'k-', lw=lw)

        axarr[num].set_ylim([0, 1])
        axarr[num].set_xlim([0, 1.1])
        axarr[num].set_title(lab, fontsize=fs + 8, y=1.02)
        if (num not in [(0, 0), (0, 1)]):
            axarr[num].set_xlabel('$\\chi$', fontsize=fs + 2)
        if (num not in [(1, 1), (0, 1)]):
            axarr[num].set_ylabel('$\\xi$', fontsize=fs + 2)

        axarr[num].xaxis.set_tick_params(direction='in',
                                         top=True,
                                         labelsize=20)
        axarr[num].xaxis.set_ticks([0.0, 0.2, 0.4, 0.6, 0.8, 1.0])
        #if (num in [(1, 0), (1, 1)]):
        axarr[num].yaxis.set_ticks([0.0, 0.2, 0.4, 0.6, 0.8, 1.0])
        axarr[num].yaxis.set_tick_params(direction='in',
                                         right=True,
                                         labelsize=20)
        axarr[num].minorticks_off()

        axarr[num].grid()

        lr, lu, lo = mixing_diags[ny][opt]

        expformat = '{} \\times 10^{{{}}}'

        lrs = '{:.2e}'.format(lr)
        l_r_d, l_r_e = (lrs[0:4], int(lrs[5:]))

        lus = '{:.2e}'.format(lu)
        l_u_d, l_u_e = lus[0:4], int(lus[5:])

        if lo != 0:
            los = '{:.2e}'.format(lo)
            lo = (los[0:4], int(los[5:]))
            loformat = expformat
        else:
            lo = (lo, )
            loformat = '{:g}'

        test2 = ('''\\begin{{{{align}}}}'''
                 '''l_r &= {l_r_format}\\\\'''
                 '''l_u &= {l_u_format}\\\\'''
                 '''l_o &= {l_o_format}\\\\'''
                 '''\\end{{{{align}}}}''')
        test = test2.format(l_r_format=expformat,
                            l_u_format=expformat,
                            l_o_format=loformat)

        axarr[num].text(0.1,
                        0.05,
                        test.format(l_r_d, l_r_e, l_u_d, l_u_e, *lo),
                        size=28,
                        multialignment='left')
    plt.tight_layout(pad=1., w_pad=5., h_pad=1)
    plt.savefig(fname)
コード例 #8
0
def conv_plot(plot_data, ord_data, fname='fig.pdf'):
    set_rc_params()
    fs = 45

    lab2ls = {'Mp3': 'ks-', 'Mp3cc': 'bo-', 'Mg3No': 'gD-', 'Mg2No': 'r^-'}
    lab2dsh = {
        'Mp3': [],
        'Mp3cc': [6, 1],
        'Mg3No': [1, 1],
        'Mg2No': [6, 1, 1, 1]
    }

    fig, axarr = plt.subplots(1, 1, figsize=(14, 12))

    plots = {}
    for x, y, opt in plot_data:
        zo = 2.0
        lab = opt2lab[opt]
        if lab == 'Mg3No':
            zo = 2.1
        p, = axarr.loglog(x,
                          y,
                          lab2ls[lab],
                          label=lab,
                          lw=6,
                          ms=16,
                          dashes=lab2dsh[lab],
                          zorder=zo)
        plots[lab] = p

    for x, y, x0, y0, t, a in ord_data:
        axarr.loglog(x, y, color='gray', lw=6)
        axarr.text(x0,
                   y0,
                   t,
                   rotation=a,
                   size=28,
                   backgroundcolor='w',
                   zorder=2.1)

    axarr.xaxis.set_ticks(plot_data[0][0])
    axarr.xaxis.set_tick_params(direction='in')
    axarr.yaxis.set_tick_params(direction='in')
    axarr.minorticks_off()

    axarr.get_xaxis().set_major_formatter(ScalarFormatter())

    axarr.set_xlabel('$N$', fontsize=fs)
    axarr.set_ylabel('$\ell_2$ error norm', fontsize=fs)

    labels = list(range(len(plots.keys())))
    for lab in plots.keys():
        labels[lab2pos[lab]] = lab
    handles = [plots[lab] for lab in labels]
    l = axarr.legend(handles,
                     labels,
                     fontsize=fs,
                     numpoints=1,
                     edgecolor='k',
                     framealpha=1.0,
                     loc=3,
                     handlelength=2.5)
    l.get_frame().set_linewidth(3)

    axarr.grid(color='k', lw=2, linestyle=':')

    plt.tight_layout(pad=1., w_pad=5., h_pad=1)
    plt.savefig(fname)