Ejemplo n.º 1
0
def rain_plotter(ax,
                 lightrain,
                 medrain,
                 heavyrain,
                 snow,
                 rdates,
                 dsize=78,
                 ssize=55,
                 dstring=(2, 0, 45)):

    dt = datetime.timedelta(hours=0.9)  #used to shift symbols left/right
    dropletpath = droplet(rot=-30)
    snowmarker = (6, 2, 0)

    # light snow
    ax.scatter([d for d, s in zip(rdates, snow) if s],
               np.zeros_like(rdates)[snow],
               ssize * 0.8,
               color=lightrain[snow, :],
               marker=snowmarker)

    # light rain
    ax.scatter([d for d, s in zip(rdates, snow) if ~s],
               np.zeros_like(rdates)[~snow],
               dsize * 0.9,
               color=lightrain[~snow, :],
               marker=dropletpath)

    # medium snow
    ax.scatter([d + 1.3 * dt for d, s in zip(rdates, snow) if s],
               1.06 + np.zeros_like(rdates)[snow],
               ssize,
               color=medrain[snow, :],
               marker=snowmarker)
    ax.scatter([d - 1.3 * dt for d, s in zip(rdates, snow) if s],
               0.94 + np.zeros_like(rdates)[snow],
               ssize,
               color=medrain[snow, :],
               marker=snowmarker)

    # medium rain
    ax.scatter([d + dt for d, s in zip(rdates, snow) if ~s],
               1.05 + np.zeros_like(rdates)[~snow],
               dsize,
               color=medrain[~snow, :],
               marker=dropletpath)
    ax.scatter([d - dt for d, s in zip(rdates, snow) if ~s],
               0.95 + np.zeros_like(rdates)[~snow],
               dsize,
               color=medrain[~snow, :],
               marker=dropletpath)

    # heavy snow
    ax.scatter([d - 0.6 * dt for d, s in zip(rdates, snow) if s],
               2.18 + np.zeros_like(rdates)[snow],
               ssize,
               color=heavyrain[snow, :],
               marker=snowmarker)
    ax.scatter([d + 1.3 * dt for d, s in zip(rdates, snow) if s],
               1.88 + np.zeros_like(rdates)[snow],
               ssize * 0.9,
               color=heavyrain[snow, :],
               marker=snowmarker)
    ax.scatter([d - 1.3 * dt for d, s in zip(rdates, snow) if s],
               1.78 + np.zeros_like(rdates)[snow],
               ssize * 0.8,
               color=heavyrain[snow, :],
               marker=snowmarker)

    # heavy rain
    ax.scatter([d for d, s in zip(rdates, snow) if ~s],
               2.1 + np.zeros_like(rdates)[~snow],
               dsize * 1.1,
               color=heavyrain[~snow, :],
               marker=dropletpath)
    ax.scatter([d + dt for d, s in zip(rdates, snow) if ~s],
               1.87 + np.zeros_like(rdates)[~snow],
               dsize * 1.1,
               color=heavyrain[~snow, :],
               marker=dropletpath)
    ax.scatter([d - 2.2 * dt for d, s in zip(rdates, snow) if ~s],
               1.95 + np.zeros_like(rdates)[~snow],
               dsize * 1.1,
               color=heavyrain[~snow, :],
               marker=dropletpath)
Ejemplo n.º 2
0
import sys
import matplotlib.pyplot as plt
import os
import numpy as np
sys.path.insert(0,"../droplet/")
from droplet import droplet

if __name__ == "__main__":
    d = droplet(os.getcwd() + '/droplet_data/eqrun0p05.tpr',\
            os.getcwd() + '/droplet_data/traj_compp5_pbc.xtc')
    u = d.u
    N = len(u.trajectory)
    c = 2.0

    x1 = (-50,50,101)
    x2 = (15,55,51)
    f = d.densityfield2d("resname RM1",x1,x2,150,N,verbose=True)
    contour = droplet.findcontour(f,2.0)[0]
    xc,yc,Ri = droplet.fitcircle(contour)

    plt.scatter(contour[:,0],contour[:,1])
    theta = np.linspace(0,2*np.pi,100)
    xcircle = Ri*np.cos(theta) + xc
    ycircle = Ri*np.sin(theta) + yc
    print(xc)
    print(yc)
    plt.plot(xcircle,ycircle)

    plt.savefig("droplet_test.png")
Ejemplo n.º 3
0
def rain_ax_format(ax,
                   dates,
                   rain_explanation,
                   snow,
                   dsize=78,
                   dstring=(2, 0, 45)):
    ax.set_xlim(dates[0], dates[-1])
    ax.set_ylim(-0.5, 2.5)
    ax.set_yticks([])
    #ax.xaxis.grid(alpha=0.2)
    #ax.xaxis.set_major_locator(WeekdayLocator(byweekday=range(7)))
    #ax.set_xticklabels([])
    ax.xaxis.set_minor_locator(HourLocator(np.arange(0, 25, 6)))  # minor
    ax.xaxis.set_major_locator(WeekdayLocator(byweekday=range(5)))
    ax.get_xaxis().set_tick_params(which='minor', direction='in')
    ax.get_xaxis().set_tick_params(which='major', direction='in')
    ax.set_xticklabels([])

    bg_rect = Rectangle((0.84, 0),
                        0.16,
                        1.,
                        linewidth=.3,
                        edgecolor='k',
                        facecolor='w',
                        transform=ax.transAxes,
                        zorder=2)
    ax.add_patch(bg_rect)

    # distinguish between rain and snow
    if np.all(snow):  # only snowfall
        ax.scatter([0.917, 0.917], [0.25, 0.5],
                   dsize * 0.6,
                   color=rain_explanation,
                   transform=ax.transAxes,
                   marker=(6, 2, 0),
                   zorder=3)
        ax.text(0.992,
                0.70,
                "snowfall",
                fontsize=8,
                fontweight="bold",
                transform=ax.transAxes,
                ha="right")
        ax.text(0.992,
                0.45,
                "very likely",
                fontsize=8,
                transform=ax.transAxes,
                ha="right")
        ax.text(0.992,
                0.2,
                "less likely",
                fontsize=8,
                transform=ax.transAxes,
                ha="right")
    elif np.all(~snow):  # only rainfall
        ax.scatter([0.917, 0.917], [0.25, 0.5],
                   dsize,
                   color=rain_explanation,
                   transform=ax.transAxes,
                   marker=droplet(rot=-30),
                   zorder=3)
        ax.text(0.992,
                0.70,
                "rainfall",
                fontsize=8,
                fontweight="bold",
                transform=ax.transAxes,
                ha="right")
        ax.text(0.992,
                0.45,
                "very likely",
                fontsize=8,
                transform=ax.transAxes,
                ha="right")
        ax.text(0.992,
                0.2,
                " less likely",
                fontsize=8,
                transform=ax.transAxes,
                ha="right")
    else:  # mix of snow and rain
        ax.scatter([0.919, 0.919], [0.16, 0.41],
                   dsize,
                   color=rain_explanation,
                   transform=ax.transAxes,
                   marker=droplet(rot=-30),
                   zorder=3)
        ax.scatter([0.914, 0.914], [0.24, 0.49],
                   dsize * 0.42,
                   color=rain_explanation,
                   transform=ax.transAxes,
                   marker=(6, 2, 0),
                   zorder=3)
        ax.text(0.992,
                0.61,
                "snow or\n rainfall",
                fontsize=8,
                fontweight="bold",
                transform=ax.transAxes,
                ha="right")
        ax.text(0.992,
                0.4,
                "very likely",
                fontsize=8,
                transform=ax.transAxes,
                ha="right")
        ax.text(0.992,
                0.15,
                " less likely",
                fontsize=8,
                transform=ax.transAxes,
                ha="right")

    ax.text(0.84,
            0.75,
            u"\u25B8 heavy",
            fontsize=8,
            transform=ax.transAxes,
            ha="left")
    ax.text(0.84,
            0.43,
            u"\u25B8 medium",
            fontsize=8,
            transform=ax.transAxes,
            ha="left")
    ax.text(0.84,
            0.11,
            u"\u25B8 light",
            fontsize=8,
            transform=ax.transAxes,
            ha="left")