import seaborn as sns
import gapflow
import matplotlib.pyplot as plt
import matplotlib.gridspec as gridspec
from datetime import timedelta
from rv_utilities import discrete_cmap

from matplotlib import rcParams

rcParams['xtick.labelsize'] = 15
rcParams['ytick.labelsize'] = 15
rcParams['axes.labelsize'] = 15
rcParams['mathtext.default'] = 'sf'

cmap = discrete_cmap(7, base_cmap='Set1')
color1 = cmap(0)
color2 = cmap(1)

# import os
# homed = os.path.expanduser('~')
homed = '/Users/raulvalenzuela/Data'


def get_subdates(gf, tta):

    bool_list = list()

    "mesowest obs have 55 minutes offset "
    offset = timedelta(minutes=55)
Esempio n. 2
0
gauge_res = 0.254
nbins = 100
H, xed, yed = np.histogram2d(xlist,
                             ylist,
                             bins=np.arange(-gauge_res / 2.,
                                            gauge_res * 0.5 * nbins * 2,
                                            gauge_res),
                             normed=False)

#Hm = np.ma.masked_where(H<=2,H)

fig, ax = plt.subplots(figsize=(10, 8))

im = ax.pcolormesh(xed, yed, H, norm=LogNorm(), cmap='inferno', vmax=1e3)
''' 1:3 line '''
cmap = discrete_cmap(7, base_cmap='Set3')
color = cmap(0)
ax.plot([-gauge_res / 2., 12], [4, -gauge_res / 2.],
        color=color,
        lw=3,
        zorder=1000)
ax.text(6, 2, '1:3', rotation=-22, color=color, weight='bold', fontsize=18)

ax.set_xlabel('rain czd $[mm\,h^{-1}]$')
ax.set_ylabel('rain bby $[mm\,h^{-1}]$')

axlim = 15
ax.set_xlim([-gauge_res / 2., axlim + gauge_res])
ax.set_ylim([-gauge_res / 2., axlim + gauge_res])
plt.colorbar(im, label='count')
plt.grid()
Esempio n. 3
0
def plot_colored_staff(ax=None,
                       wspd=None,
                       wdir=None,
                       time=None,
                       height=None,
                       cmap=None,
                       spd_range=None,
                       spd_delta=None,
                       vdensity=None,
                       hdensity=None,
                       title=None,
                       cbar=True):
    ''' 
        NOAA wind profiler files after year 2000 indicate
        the start time of averaging period; so a timestamp of
        13 UTC indicates average between 13 and 14 UTC 
    
        There is a bug that plots wrong staff when using
        meridional winds only     
    
    '''

    from matplotlib import rcParams
    rcParams['mathtext.default'] = 'sf'

    spd_array = wspd
    time_array = time
    height_array = height
    ''' make a color map of fixed colors '''
    cmap = discrete_cmap(24, base_cmap=cmap, norm_range=[0.1, 0.9])
    if len(spd_range) == 2:
        bounds = range(spd_range[0], spd_range[1] + spd_delta, spd_delta)
#        vmin = spd_range[0]
#        vmax = spd_range[1]
    else:
        bounds = spd_range


#        vmin = spd_range[0]
#        vmax = spd_range[-1]
    norm = colors.BoundaryNorm(bounds, cmap.N)

    nrows, ncols = spd_array.shape
    ''' derive U and V components '''
    U = -wspd * np.sin(wdir * np.pi / 180.)
    V = -wspd * np.cos(wdir * np.pi / 180.)
    x = np.array(range(len(time))) + 0.5  # wind staff in the middle of pixel
    # wind staff in the middle of pixel
    y = np.array(range(height_array.size)) + 0.5
    X = np.tile(x, (y.size, 1))  # repeats x y.size times to make 2D array
    Y = np.tile(y, (x.size, 1)).T  # repeates y x.size times to make 2D array
    Uzero = U - U
    Vzero = V - V
    ''' change arrays density '''
    if vdensity == 0 or hdensity == 0:
        pass
    else:
        U = fill2D_with_nans(inarray=U,
                             start=[3, 0],
                             size=[vdensity, hdensity])
        V = fill2D_with_nans(inarray=V,
                             start=[3, 0],
                             size=[vdensity, hdensity])

    ax.barbs(X,
             Y,
             U,
             V,
             np.sqrt(U * U + V * V),
             sizes={'height': 0},
             length=5,
             linewidth=0.5,
             barb_increments={'half': 1},
             cmap=cmap,
             norm=norm)
    barb = ax.barbs(X,
                    Y,
                    Uzero,
                    Vzero,
                    np.sqrt(U * U + V * V),
                    sizes={'emptybarb': 0.05},
                    fill_empty=True,
                    cmap=cmap,
                    norm=norm)

    if isinstance(cbar, maxes._subplots.Axes):
        hcbar = add_colorbar(cbar,
                             barb,
                             loc='right',
                             label='[m s-1]',
                             labelpad=20,
                             fontsize=12)
    elif isinstance(cbar, bool) and cbar:
        hcbar = add_colorbar(ax, barb, loc='right')
    else:
        hcbar = None

    ax.set_xlim([-3.0, len(time_array) + 3.0])
    format_xaxis(ax, time_array, delta_hours=1)
    ax.invert_xaxis()
    ax.set_xlabel(r'$\leftarrow UTC \left[\stackrel{day}{time}\right]$',
                  fontsize=12)

    format_yaxis2(ax, height_array)
    ax.set_ylabel('Altitude MSL [km]')

    if title is not None:
        ax.text(0., 1.01, title, transform=ax.transAxes)

    plt.subplots_adjust(left=0.08, right=0.95)
    plt.draw()

    return [ax, hcbar]
            catalog_df[year][hist.index] = hist.values

    data = {'h': hours, 'year': range(1998, 2013), 'th': [th] * hours.size}
    df = pd.DataFrame(data=data)
    hours_df = hours_df.append(df)

    data = {'h': events, 'year': range(1998, 2013), 'th': [th] * events.size}
    df = pd.DataFrame(data=data)
    events_df = events_df.append(df)

labs = [str(int(np.mod(y, 100.))).zfill(2) for y in range(1998, 2013)]
panels = ('(a)', '(b) Events of 1 or more hours', '(c)')
ylims = [[0, 250], [0, 100], [1.8, 4]]
# cls = sns.color_palette('Set3')
dcmap = discrete_cmap(7, base_cmap='Set1')
cls = [dcmap(0), dcmap(1), dcmap(2)]
scale = 1.3
fig, axes = plt.subplots(3, 1, figsize=(5 * scale, 6 * scale), sharex=True)
for n in range(3):
    axes[n].set_gid(n)

sns.barplot(
    x='year',
    y='h',
    # hue='th',
    data=hours_df,
    ax=axes[0],
    # palette='GnBu',
    color=cls[0])
for p in axes[0].patches:
Esempio n. 5
0
def plot_time_height(ax=None,
                     wspd=None,
                     time=None,
                     height=None,
                     spd_range=None,
                     spd_delta=None,
                     cmap=None,
                     title=None,
                     cbar=None,
                     cbarinvi=False,
                     timelabstep=None,
                     kind='pcolormesh',
                     cbar_label=None):
    ''' NOAA wind profiler files after year 2000 indicate
    the start time of averaging period; so a timestamp of
    13 UTC indicates average between 13 and 14 UTC '''
    ''' make a color map of fixed colors '''
    if len(spd_range) == 2:
        bounds = range(spd_range[0], spd_range[1] + spd_delta, spd_delta)
    else:
        bounds = spd_range
    cmap = discrete_cmap(len(bounds) + 1,
                         base_cmap=cmap,
                         norm_range=[0.2, 1.0])
    norm = colors.BoundaryNorm(bounds, cmap.N)

    x = np.linspace(0, len(time), len(time) + 1)
    y = np.linspace(0, height.size, height.size + 1)

    wspdm = ma.masked_where(np.isnan(wspd), wspd)
    #    wspdm = ma.masked_where(wspdm<0, wspdm)

    if kind == 'contourf':
        x, y = np.meshgrid(np.linspace(0, len(time), len(time)),
                           np.linspace(0, height.size, height.size))
        img = ax.contourf(x, y, wspdm, cmap=cmap, norm=norm)
    else:
        img = ax.pcolormesh(x, y, wspdm, cmap=cmap, norm=norm)

    hcbar = add_colorbar(cbar,
                         img,
                         loc='right',
                         label=cbar_label,
                         labelpad=20,
                         fontsize=12,
                         invisible=cbarinvi)

    ax.set_xlim([-1.0, len(time) + 1.0])

    if timelabstep is None:
        timelabstep = '1H'

    format_xaxis2(ax, time, timelabstep=timelabstep)
    ax.invert_xaxis()
    ax.set_xlabel(r'$\leftarrow UTC \left[\stackrel{day}{time}\right]$',
                  fontsize=20)
    ax.set_ylabel('Altitude MSL [km]')

    if title is not None:
        ax.text(0., 1.01, title, transform=ax.transAxes)

    plt.subplots_adjust(left=0.08, right=0.95)

    return [ax, hcbar, img]