def main(variable): # RMS errors cubes = second_analysis.get_data('rms_error_24_air_pressure', 'full') plot_errors(cubes, variable, '-kx') cubes = second_analysis.get_data('mean_error_24_air_pressure', 'full') plot_errors(cubes, variable, '--kx')
def profile(coord, mappings, domains, title, xlabel, ylabel, xlims, ylims): ncols = len(mappings) nrows = len(domains) # Initialise the plot fig = plt.figure(figsize=(18, 25)) # Loop over mappings for m, domain in enumerate(domains): cubes = second_analysis.get_data(coord, domain) for n, mapping in enumerate(mappings): mapping = second_analysis.mappings[mapping] ax = plt.subplot2grid((nrows, ncols), (m, n)) profile_multi(cubes, ax, mapping, coord) ax.set_xlim(*xlims[n]) ax.set_ylim(*ylims) if m == 0: ax.set_title(title[n]) else: ax.set_title('') if m == nrows - 1: legend(ax, key=second_analysis.get_idx, loc='upper left', ncol=2, bbox_to_anchor=(0.05, -0.25)) else: ax.get_xaxis().set_ticklabels([]) if n == 0: if m == 1: ax.set_ylabel(ylabel) else: ax.set_ylabel('') else: ax.set_ylabel('') ax.get_yaxis().set_ticklabels([]) if m == nrows - 1 and n == 1: ax.set_xlabel(xlabel) else: ax.set_xlabel('') ax.axvline(color='k') ax.axhline(color='k') if coord == 'air_pressure': ax.set_ylim(ax.get_ylim()[::-1]) multilabel(ax, n + m * ncols) fig.subplots_adjust(bottom=0.4) return
def _single_fit(coord, subdomain, dz, function, **kwargs): cubes = second_analysis.get_data(coord, subdomain) pv = convert.calc(variable, cubes) x, y, dy = function(pv, coord, dz) popt, pcov, rmse = fit_curve(x, y, dy) print(popt, rmse) plot_fit(x, y, dy, popt, **kwargs) return popt, rmse
def tropopause_profile(): # Initialise the plot fig = plt.figure(figsize=(18, 15)) # Loop over mappings for n, mapping in enumerate(mappings): mapping = second_analysis.mappings[mapping] for m, domain in enumerate(['ridges', 'troughs']): cubes = second_analysis.get_data(coord, domain) ax = plt.subplot2grid((2, ncols), (m, n)) if n == 0: profile_error(cubes, ax, mapping, coord) else: profile_multi(cubes, ax, mapping, coord) plt.title(title[n]) ax.set_xlim(*xlims[n]) ax.set_ylim(*ylim) legend(ax, key=second_analysis.get_idx, loc='best', ncol=2, bbox_to_anchor=(0.9, -0.2)) if n == 0: ax.set_ylabel(ylabel) else: ax.set_ylabel('') ax.get_yaxis().set_ticklabels([]) if n == 1: ax.set_xlabel(xlabel) else: ax.set_xlabel('') plt.title('') plt.axvline(color='k') plt.axhline(color='k') # if coord == 'air_pressure': # ax.set_ylim(ax.get_ylim()[::-1]) for n, ax in enumerate(fig.axes): multilabel(ax, n) fig.subplots_adjust(bottom=0.4) #plt.savefig(plotdir + 'ch7_low/height_profile.pdf') plt.show() return
def pv_gradients(coord, alpha, fig): # Rows are Ridges and troughs for n, subdomain in enumerate(['ridges', 'troughs']): cubes = second_analysis.get_data(coord, subdomain) # Columns are for different mappings for m, mapping in enumerate(['pv_full', 'pv_main', 'pv_phys']): mapping = second_analysis.mappings[mapping] ax = fig.axes[n * 3 + m] pv_gradients_multi(cubes, coord, ax, mapping, alpha) return
def make_table(): for coord in ([ 'distance_from_dynamical_tropopause', 'distance_from_advection_only_tropopause' ]): for subdomain in (['ridges', 'troughs']): cubes = second_analysis.get_data(coord, subdomain) pv = convert.calc(variable, cubes)[:, 1:] x, y, dy = pv_contrast(pv, coord, 1000) popt, pcov, rmse = fit_curve(x, y, dy) print(subdomain.capitalize() + ' & ' + str(round(popt[0], 1)) + ' & ' + str(round(popt[1], 3)) + ' & ' + str(round(popt[2], 3)) + ' & ' + str(round(rmse, 3))) return
def main(**kwargs): # Initialise the plot fig = plt.figure(figsize=(18, 15)) for n, coord in enumerate(coords): for m, subdomain in enumerate(['ridges', 'troughs']): cubes = second_analysis.get_data(coord, subdomain) cube = convert.calc(name, cubes) cube.coord(coord).convert_units('km') mean, std_err = second_analysis.extract_statistics( cube, 'forecast_index') ax = plt.subplot2grid((2, 2), (n, m)) im = iplt.contourf(mean, even_cscale(0.18), cmap='coolwarm') # X-axis - Same for both columns ax.set_xticks([0, 12, 24, 36, 48, 60]) if n == 0: ax.get_xaxis().set_ticklabels([]) ax.set_title(subdomain.capitalize()) # Y-axis - Same for both rows ax.set_ylim(-2, 2) ax.set_yticks([-2, -1.5, -1, -0.5, 0, 0.5, 1, 1.5, 2]) ax.axhline(color='k') if m > 0: ax.get_yaxis().set_ticklabels([]) add_labels(fig) fig.text(0.5, 0.2, 'Forecast Lead Time (hours)', ha='center') for n, axis in enumerate(fig.axes): multilabel(axis, n) cbar = plt.colorbar(im, ax=fig.axes, orientation='horizontal', fraction=0.05, spacing='proportional') cbar.set_ticks([-0.18, -0.09, 0, 0.09, 0.18]) cbar.set_label('PVU') plt.savefig(plotdir + 'inconsistency.pdf') plt.show() return
def tropopause_profile(coord, alpha, fig): # Columns are Ridges and troughs for n, subdomain in enumerate(['ridges', 'troughs']): cubes = second_analysis.get_data(coord, subdomain) # Rows are for different mappings for m, mapping in enumerate(['pv_full', 'pv_main', 'pv_phys']): mapping = second_analysis.mappings[mapping] ax = fig.axes[n * 3 + m] if m == 0: # First column is forecast error profile_error(cubes, coord, ax, mapping, alpha) else: # Columns 2 and 3 show full accumulation profile_multi(cubes, coord, ax, mapping, alpha) return
def varying_depth(widths, function): fig = plt.figure(figsize=(18, 8)) axes = [] for n in range(1): for m in range(2): axes.append(plt.subplot2grid((1, 2), (n, m))) for coord, color in coords: for subdomain, linestyle in subdomains: cubes = second_analysis.get_data(coord, subdomain) pv = convert.calc(variable, cubes) if subdomain == 'ridges': x, y, dy = pv_contrast(pv, coord, 1000) popt, pcov, rmse = fit_curve(x, y, dy) axes[0].errorbar(x, y, yerr=dy, linestyle=linestyle, color=color) pv = pv[:, 1:] if subdomain == 'ridges': x2, y, dy = pv_contrast(pv, coord, 1000) popt, pcov, rmse = fit_curve(x2, y, dy) axes[0].plot(x, func(x, *popt), color=color, linestyle='', marker='o') timescale = [] grad_0 = [] grad_inf = [] errors = [] for dz in widths: if dz == 200: x, y, dy = pv_gradient(pv, coord, dz) else: x, y, dy = function(pv, coord, dz) popt, pcov, rmse = fit_curve(x, y, dy) timescale.append(popt[0]) grad_0.append(popt[1]) grad_inf.append(popt[2]) errors.append(rmse) grad_0 = np.array(grad_0) grad_inf = np.array(grad_inf) # axes[2].plot(widths * 1e-3, grad_0, # color=color, linestyle=linestyle, marker='x') # axes[3].plot(widths * 1e-3, grad_0 - grad_inf, # color=color, linestyle=linestyle, marker='x') axes[1].plot(widths * 1e-3, timescale, color=color, linestyle=linestyle, marker='x') # axes[5].plot(widths * 1e-3, errors, # color=color, linestyle=linestyle, marker='x') # Set figure labels axes[0].set_title(r'$\Delta q_{adv}(t)$ in ridges') axes[0].set_xlabel('Forecast Lead Time (hours)') axes[0].set_ylabel('PVU') axes[1].set_title('Timescale') axes[1].set_xlabel(r'$\pm \tilde{z}$ (km)', fontsize=20) axes[1].set_ylabel(r'$\tau$ (Hours)') """ axes[2].set_title(r'$\Delta q_{adv}(0)$') axes[2].set_xlabel(r'$\pm \tilde{z}$ (km)', fontsize=20) axes[2].set_ylabel('PVU') #axes[2].set_ylim(0, 5) axes[3].set_title(r'$\Delta q_{adv}(0) - \Delta q_{adv}(\infty)$') axes[3].set_xlabel(r'$\pm \tilde{z}$ (km)', fontsize=20) axes[3].set_ylabel('PVU') #axes[3].set_ylim(0, 5) """ for n, axis in enumerate(axes): multilabel(axis, n) # Create legend table fig2 = plt.figure() ax = fig2.add_subplot(111) lines = [] for subdomain, linestyle in subdomains: for coord, color in coords: lines.append( ax.plot([0, 1], [0, 1], linestyle=linestyle, color=color)[0]) # create blank rectangle extra = Rectangle((0, 0), 1, 1, fc="w", fill=False, edgecolor='none', linewidth=0) # Create organized list containing all handles for table. Extra represent # empty space legend_handle = [ extra, extra, extra, extra, lines[0], lines[1], extra, lines[2], lines[3] ] # Define the labels label_column_1 = ["", r"$z(q{=}2)$", r"$z(q_{adv}{=}2)$"] label_column_2 = ["Ridges", "", ""] label_column_3 = ["Troughs", "", ""] # organize labels for table construction legend_labels = np.concatenate( [label_column_1, label_column_2, label_column_3]) # Create legend axes[1].legend(legend_handle, legend_labels, loc='best', ncol=3, shadow=True, handletextpad=-2) fig.savefig(plotdir + 'q_adv_decay_parameters.pdf') # plt.show() return
def humidity_gradients(): # Initialise the plot fig = plt.figure(figsize=(18, 15)) # Columns are Ridges and troughs for n, variable in enumerate(variables): row = n / ncols col = n - row * ncols print(row, col) ax = plt.subplot2grid((nrows, ncols), (row, col)) for subdomain, linestyle in [('ridges', '-'), ('troughs', '--')]: cubes = second_analysis.get_data(coord, subdomain) cube = convert.calc(variable, cubes) cube.coord(coord).convert_units('km') mean, std_err = second_analysis.extract_statistics( cube, 'forecast_index') if variable == 'vertical_vorticity': mean.data = mean.data + 1e-4 else: mean.data = mean.data * 1e3 std_err.data = std_err.data * 1e3 iplt.plot( mean[0], mean.coord(coord), # xerr=std_err[0], linestyle=linestyle, label=subdomain.capitalize(), color='k', marker='x', ms=5) ax.set_ylabel('') ax.set_ylim(-2, 2) if col > 0: ax.get_yaxis().set_ticklabels([]) if variable == 'specific_humidity': ax.set_title('Specific Humidity') ax.set_xlabel(r'Mass Fraction (g kg$^{-1}$)') elif variable == 'vertical_vorticity': ax.set_title('Vertical Vorticity') ax.set_xlabel(r'Vorticity (s$^{-1}$)') elif variable == 'mass_fraction_of_cloud_liquid_water_in_air': ax.set_title('Cloud Liquid') ax.set_xlabel(r'Mass Fraction (g kg$^{-1}$)') elif variable == 'mass_fraction_of_cloud_ice_in_air': ax.set_title('Cloud Ice') ax.set_xlabel(r'Mass Fraction (g kg$^{-1}$)') plt.axhline(color='k') multilabel(ax, n) legend(ax=fig.axes[0], loc='best') fig.text(0.075, 0.5, 'Vertical distance from tropopause (km)', va='center', rotation='vertical') plt.savefig(plotdir + 'analysis_profiles.pdf') plt.show()
def main(): # Initialise the plot fig = plt.figure(figsize=(18, 12)) # Add subfigures for n in range(2): for m in range(3): plt.subplot2grid((2, 3), (n, m)) # Plot composites pv_gradients('distance_from_dynamical_tropopause', 1, fig) # Add faint lines for q_adv #pv_gradients('distance_from_advection_only_tropopause', 0.25, fig) for n, subdomain in enumerate(['ridges', 'troughs']): coord = 'distance_from_advection_only_tropopause' alpha = 0.3 cubes = second_analysis.get_data(coord, subdomain) m = 1 mapping = second_analysis.mappings['pv_main'] mapping = { k: mapping[k] for k in ('dynamics_tracer_inconsistency', 'sum_of_physics_pv_tracers') } ax = fig.axes[n * 3 + m] pv_gradients_multi(cubes, coord, ax, mapping, alpha) fig.subplots_adjust(bottom=0.2) # Set labels and limits on plots for n, subdomain in enumerate(['ridges', 'troughs']): for m in range(3): ax = fig.axes[n * 3 + m] # X-axis - Same for both rows ax.set_xticks([0, 12, 24, 36, 48, 60]) if n == 0: ax.get_xaxis().set_ticklabels([]) # Set Titles if m == 0: ax.set_title('Forecast') elif m == 1: ax.set_title('PV budget') elif m == 2: ax.set_title('Physics PV tracers') else: legend(ax, key=second_analysis.get_idx, loc='best', ncol=2, bbox_to_anchor=(1.0, -0.2), fontsize=25) if m == 1: ax.set_xlabel('Forecast lead time (hours)') # Y-Axis if m == 0: # First column custom if n == 0: ax.set_ylim(3.0, 3.6) else: ax.set_ylim(2.4, 3.0) elif m == 1: # Columns 2 ax.set_ylim(-0.1, 0.5) else: ax.set_ylim(-0.05, 0.25) multilabel(ax, n * 3 + m) fig.text(0.075, 0.55, 'PV (PVU)', va='center', rotation='vertical', fontsize=20) fig.text(0.05, 0.75, 'Ridges', va='center', rotation='vertical', fontsize=20) fig.text(0.05, 0.35, 'Troughs', va='center', rotation='vertical', fontsize=20) plt.savefig(plotdir + 'pv_gradients_new.pdf') plt.show() return
def main(): # Initialise the plot fig = plt.figure(figsize=(18, 12)) # Add subfigures for n in range(2): for m in range(3): plt.subplot2grid((2, 3), (n, m)) # Plot composites tropopause_profile('distance_from_dynamical_tropopause', 1, fig) # Add faint lines for q_adv #tropopause_profile('distance_from_advection_only_tropopause', 0.25, fig) for n, subdomain in enumerate(['ridges', 'troughs']): coord = 'distance_from_advection_only_tropopause' alpha = 0.3 cubes = second_analysis.get_data(coord, subdomain) m = 1 mapping = second_analysis.mappings['pv_main'] mapping = { k: mapping[k] for k in ('dynamics_tracer_inconsistency', 'sum_of_physics_pv_tracers') } ax = fig.axes[n * 3 + m] profile_multi(cubes, coord, ax, mapping, alpha) fig.subplots_adjust(bottom=0.2) # Set labels and limits on plots for n, subdomain in enumerate(['ridges', 'troughs']): for m in range(3): ax = fig.axes[n * 3 + m] # X-axis - Same for all plots if m == 0: ax.set_xlim(-0.5, 0.2) ax.set_xticks([-0.4, -0.2, 0, 0.2]) else: ax.set_xlim(-0.2, 0.3) ax.set_xticks([-0.2, -0.1, 0, 0.1, 0.2, 0.3]) if n == 0: ax.get_xaxis().set_ticklabels([]) # Set Titles if m == 0: ax.set_title('Forecast minus analysis') elif m == 1: ax.set_title('PV budget') elif m == 2: ax.set_title('Physics PV tracers') else: legend(ax, key=second_analysis.get_idx, loc='best', ncol=2, bbox_to_anchor=(1.0, -0.2), fontsize=25) if m == 1: ax.set_xlabel('PV (PVU)') # Y-axis - Same for all plots ax.set_ylim(-2, 2) ax.set_yticks([-2, -1.5, -1, -0.5, 0, 0.5, 1, 1.5, 2]) if m != 0: ax.get_yaxis().set_ticklabels([]) multilabel(ax, n * 3 + m) fig.text(0.075, 0.55, 'Vertical distance from tropopause (km)', va='center', rotation='vertical', fontsize=20) fig.text(0.05, 0.75, 'Ridges', va='center', rotation='vertical', fontsize=20) fig.text(0.05, 0.35, 'Troughs', va='center', rotation='vertical', fontsize=20) plt.savefig(plotdir + 'tropopause_profile_new.pdf') # plt.show() return