def f(x, pos): return aq.to_datetime(x).strftime('%d/%m\n%H:%M')
def plot_profile(plot_type, d, cax=None, subcolumn=0, sigma=5, remove_bmol=True, vlim=None, vlog=None, zres=50, zlim=None, **opts): if plot_type == 'backscatter': cmap = copy.copy(mpl.cm.get_cmap('viridis')) under = '#222222' label = 'Att. vol. backscattering coef. (×10$^{-6}$ m$^{-1}$sr$^{-1}$)' if vlim is None: vlim = [0.1, 200] if vlog is None: vlog = True if len(d['backscatter'].shape) == 3: b = d['backscatter'][:, :, subcolumn] cloud_mask = d['cloud_mask'][:, :, subcolumn] bsd = d['backscatter_sd'][:,:,subcolumn] if 'backscatter_sd' in d \ else np.zeros(b.shape, dtype=np.float64) else: b = d['backscatter'] cloud_mask = d['cloud_mask'] bsd = d['backscatter_sd'] if 'backscatter_sd' in d \ else np.zeros(b.shape, dtype=np.float64) if sigma > 0: b -= sigma * bsd if remove_bmol and 'backscatter_mol' in d: bmol = d['backscatter_mol'] mask = ~np.isnan(bmol) b[mask] -= bmol[mask] x = b * 1e6 x[x <= 0.] = 0.5 * vlim[0] # A value below the limit. time = d['time'] zfull = d['zfull'] elif plot_type in ('clw', 'cli', 'cl'): cmap = copy.copy( mpl.cm.get_cmap({ 'clw': 'Reds', 'cli': 'Blues', 'cl': 'Greys_r', }[plot_type])) under = { 'clw': 'white', 'cli': 'white', 'cl': 'k', }[plot_type] label = { 'clw': 'Cloud water (g/kg)', 'cli': 'Cloud ice (g/kg)', 'cl': 'Cloud fraction (%)', }[plot_type] if vlim is None: vlim = { 'clw': [1e-3, 1], 'cli': [1e-3, 1], 'cl': [0, 100], }[plot_type] if vlog is None: vlog = {'clw': True, 'cli': True, 'cl': False}[plot_type] x = d[plot_type] if plot_type in ('clw', 'cli', 'clw+cli'): x *= 1e3 if x.shape == 3: x = x[:, :, subcolumn] if zlim is None: zlim = [np.min(d['zfull']), np.max(d['zfull'])] zhalf = np.arange(zlim[0], zlim[1] + zres, zres) zfull = 0.5 * (zhalf[1:] + zhalf[:-1]) xp = np.full((x.shape[0], len(zfull)), np.nan, np.float64) for i in range(xp.shape[0]): zhalfi = misc.half(d['zfull'][i, :]) xp[i, :] = algorithms.interp(zhalfi, x[i, :], zhalf) x = xp time = d['time'] else: raise ValueError('Invalid plot type "%s"' % plot_type) if vlog: norm = LogNorm(vlim[0], vlim[1]) else: norm = Normalize(vlim[0], vlim[1]) t1 = time[0] - 0.5 * (time[1] - time[0]) t2 = time[-1] + 0.5 * (time[-1] - time[-2]) z1 = zfull[0] - 0.5 * (zfull[1] - zfull[0]) z2 = zfull[-1] + 0.5 * (zfull[-1] - zfull[-2]) im = plt.imshow( x.T, extent=(t1, t2, z1 * 1e-3, z2 * 1e-3), aspect='auto', origin='lower', norm=norm, cmap=cmap, ) im.cmap.set_under(under) cb = plt.colorbar( cax=cax, label=label, pad=0.03, fraction=0.05, aspect='auto', extend='both', ) if zlim is not None: plt.ylim(zlim[0] * 1e-3, zlim[1] * 1e-3) plt.xlabel('Time (UTC)') plt.ylabel('Height (km)') formatter = plt.FuncFormatter(lambda t, p: \ aq.to_datetime(t).strftime('%d/%m\n%H:%M')) locator = AutoDateLocator() plt.gca().xaxis.set_major_formatter(formatter) plt.gca().xaxis.set_major_locator(locator) if plot_type == 'backscatter' and opts.get('cloud_mask'): cf = plt.contour( d['time'], d['zfull'] * 1e-3, cloud_mask.T, colors='red', linewidths=1, linestyles='dashed', levels=[-1., 0.5, 2.], ) plot_legend(handles=[ mlines.Line2D([], [], color='red', linestyle='dashed', label='Cloud mask') ], theme='dark') if 'altitude' in d: plt.plot(d['time'], d['altitude'] * 1e-3, color='red', lw=0.5)
def formatter_f(t, pos): return aq.to_datetime(t).strftime('%d/%m\n%H:%M')