# Get the distance away from the island-edge of the surface warm plume. R_wp = np.nanmax( np.where( np.nanmean( mass_flux_xs[key][theta_key][start_idx:end_idx, 0, :, :], axis=0) - np.nanmean( mass_flux_xs[key][theta_key][start_idx:end_idx, 0, :, :]) > 0.1, np.sqrt((X - x_c)**2 + (Y - y_c)**2) - R_i, np.nan)) # Compute the rectangle and the new cartesian coordinate system mask, mass_flux_xs[key]['y_prime'], mass_flux_xs[key][ 'x_prime'] = downwind_rectangle( wind_dir=wind_dir, x_c=x_c, y_c=y_c, X=X, Y=Y, island_radius=R_i, dist_0=0 + R_wp, dist_1=(end_t - start_t) * 60.0 * speed + R_wp, half_width=5000.0) print '[' + dt.now().strftime('%H:%M:%S') + '] Computing mass flux...' # Convert rho from rho levels to theta levels rho_theta_levels = np.array([ interpolate.interp1d(x=z_rho, y=mass_flux_xs[key][rho_key][idx, :, :, :], axis=0, fill_value='extrapolate')(z_theta[iz_LCL]) for idx in t_idx ]) # Average in time mf = np.nanmean(rho_theta_levels *
# define the CT region, and mask over it R_i = 1000.0 * (50.0 / np.pi)**0.5 # island radius, metres # centrepoint coordinates of the island x_c = 100000.0 + R_i y_c = 4 * R_i iz = np.where(np.abs(z_rho - 650.0) == np.min(np.abs(z_rho - 650.0)))[0][0] speed, wind_dir = fromComponents( u=np.nanmean(u_nc.variables[u_key][0, :iz, :, :]), v=np.nanmean(v_nc.variables[v_key][0, :iz, :, :])) mask, y_prime, x_prime = downwind_rectangle(wind_dir=wind_dir, x_c=x_c, y_c=y_c, X=X, Y=Y, island_radius=R_i, dist_0=0, dist_1=100000.0, half_width=7500.0) # mask over it and store to the dictionary sim100['theta'] = np.nanmean(mask * bouy_nc.variables[theta_key][1:, :, :, :], axis=(2, 3)) sim100['q'] = np.nanmean(mask * bouy_nc.variables[q_key][1:, :, :, :], axis=(2, 3)) sim100['u'] = np.nanmean(mask * u_nc.variables[u_key][1:, :, :, :], axis=(2, 3)) sim100['v'] = np.nanmean(mask * v_nc.variables[v_key][1:, :, :, :], axis=(2, 3))
# Distance from the island, m R = np.sqrt((x - x_c)**2 + (y - y_c)**2) # Find the mean boundary layer wind speed and direction zi_mean = np.nanmean(my_data[zi_new_key][0,:,:]) iz = np.where(np.abs(my_data['z'] - zi_mean) == np.min(np.abs(my_data['z'] - zi_mean)))[0][0] U_mean = np.nanmean(integrate.trapz(x = my_data['z'][:iz], y = my_data[u_key][:iz,:,:], axis = 0)/my_data['z'][iz]) V_mean = np.nanmean(integrate.trapz(x = my_data['z'][:iz], y = my_data[v_key][:iz,:,:], axis = 0)/my_data['z'][iz]) wind_spd, wind_dir = fromComponents(U_mean, V_mean) # Use the wind direction to define our downwind rectangular region d_min = -12000.0 d_max = 50000.0 d_mid = 3000.0 mask, y_prime, x_prime = downwind_rectangle(wind_dir, x_c, y_c, x, y, R_i, dist_0 = d_min, dist_1 = d_max, half_width = d_mid) # Compute the s-wind cross section x_prime_new = np.arange(d_min, d_max + 0.1, dx) s_xcs = np.array([[np.nanmean(np.where((x_0 <= x_prime)*(x_prime <= (x_0 + dx)), mask*my_data[s_key][it,:,:,:], np.nan), axis = (1, 2)) for x_0 in x_prime_new] for it in [-1]]) # array[t, x', z] zi_xcs = np.transpose(np.array([[np.nanmean(np.where((x_0 <= x_prime)*(x_prime <= (x_0 + dx)), mask*my_data[zi_new_key][it,:,:], np.nan)) for x_0 in x_prime_new] for it in [-1]])) lcl_xcs = np.transpose(np.array([[np.nanmean(np.where((x_0 <= x_prime)*(x_prime <= (x_0 + dx)), mask*my_data[lcl_key][it,:,:], np.nan)) for x_0 in x_prime_new] for it in [-1]])) # Compute the s-wind anomaly from the surface parcel ascent s_anom_xcs = s_xcs[it,:,:] - my_data[s_key][it,:,:,:].mean(axis = (1, 2)) # Compute the n-wind cross section y_prime_new = np.arange(-d_mid, d_mid + 0.1, dx) n_ycs = np.array([[np.nanmean(np.where((y_0 <= y_prime)*(y_prime <= (y_0 + dx)), mask*my_data[n_key][it,:,:,:], np.nan), axis = (1, 2)) for y_0 in y_prime_new] for it in [-1]]) zi_ycs = np.transpose(np.array([[np.nanmean(np.where((y_0 <= y_prime)*(y_prime <= (y_0 + dx)), mask*my_data[zi_new_key][it,:,:], np.nan)) for y_0 in y_prime_new] for it in [-1]])) lcl_ycs = np.transpose(np.array([[np.nanmean(np.where((y_0 <= y_prime)*(y_prime <= (y_0 + dx)), mask*my_data[lcl_key][it,:,:], np.nan)) for y_0 in y_prime_new] for it in [-1]]))
# Get the mean wind speed and direction below LCL iz_LCL = np.where(np.abs(z_theta - lcl[key]) == np.min(np.abs(z_theta - lcl[key])))[0][0] iz_zi = np.where(np.abs(z_theta - zi[key]) == np.min(np.abs(z_theta - zi[key])))[0][0] u_mean = np.array([u_nc.variables[u_key][idx,:iz_zi,:,:] for idx in t_idx]).mean(axis = (0, 2, 3)) v_mean = np.array([v_nc.variables[v_key][idx,:iz_zi,:,:] for idx in t_idx]).mean(axis = (0, 2, 3)) U_zi = integrate.trapz(x = z_theta[:iz_zi], y = u_mean)/zi[key] V_zi = integrate.trapz(x = z_theta[:iz_zi], y = v_mean)/zi[key] speed, wind_dir = fromComponents(u = U_zi, v = V_zi) # Get the distance away from the island-edge of the surface warm plume. mass_flux_xs[key]['theta_anom'] = np.nanmean(np.array([thermo_nc.variables[theta_key][idx,1,:,:] - thermo_nc.variables[theta_key][idx,1,:,:].mean() for idx in t_idx]), axis = 0) R_wp = 4*R_i#np.nanmax(np.where(mass_flux_xs[key]['theta_anom'] > 0.1, np.sqrt((X-x_c)**2 + (Y-y_c)**2) - R_i, np.nan)) # Compute the rectangle and the new cartesian coordinate system # distance travelled during time averaging period mass_flux_xs[key]['mask'], mass_flux_xs[key]['y_prime'], mass_flux_xs[key]['x_prime'] = downwind_rectangle(wind_dir = wind_dir, x_c = x_c, y_c = y_c, X = X, Y = Y, island_radius = R_i, dist_0 = R_wp, dist_1 = R_wp + ((end_t-start_t)*60.0*speed - R_wp), half_width = 3000.0) print '[' + dt.now().strftime('%H:%M:%S') + '] Computing mass flux...' # Convert rho from rho levels to theta levels rho_theta_levels = np.array([interpolate.interp1d(x = rho_nc.variables['rholev_zsea_rho'][:], y = rho_nc.variables[rho_key][idx,:,:,:], axis = 0, fill_value = 'extrapolate')(z_theta[iz_zi]) for idx in t_idx]) # Average in time mf = np.nanmean(rho_theta_levels*thermo_nc.variables[w_key][t_idx,iz_zi,:,:], axis = 0) mass_flux_xs[key]['mass_flux'] = mf mass_flux_xs[key]['mass_flux_masked'] = mf*mass_flux_xs[key]['mask'] rho_nc.close() u_nc.close() v_nc.close() thermo_nc.close() zi_nc.close()
U_mean = integrate.trapz(x = z_int, y = U_fun)/z_int.max() V_mean = integrate.trapz(x = z_int, y = V_fun)/z_int.max() wind_spd, wind_dir = fromComponents(U_mean, V_mean) # Define the original coordinate system dx = 100.0 x, y = np.meshgrid(np.arange(my_data[lwp_key].shape[2])*dx, np.arange(my_data[lwp_key].shape[1])*dx) island_area = 50.0 island_radius = np.sqrt(island_area/np.pi)*1000.0 x_c = [108000.0 if label != 'Control' else 100000.0 + island_radius][0] y_c = [16000.0 if label != 'Control' else 4*island_radius][0] R = np.sqrt((x - x_c)**2 + (y - y_c)**2) # Define the downwind rectangle mask, y_prime, x_prime = downwind_rectangle(wind_dir, x_c, y_c, x, y, island_radius, dist_0 = -20000.0, dist_1 = 100000.0, half_width = 3000.0) # Compute the daytime cloud frequency start = np.where(my_data['lwp_times'] == 360.)[0][0] end = np.where(my_data['lwp_times'] == 1080.)[0][0] + 1 cloud_frequency = np.nanmean(np.where(my_data[lwp_key][start:end,:,:] > 0, 1.0, 0.0), axis = 0) cloud_frequency_before = np.nanmean(np.where(my_data[lwp_key][:(start+1),:,:] > 0, 1.0, 0.0), axis = 0) # Collapse cloud frequency from array[x_prime, y_prime] -> array[x_prime] cloud_frequency_x = np.array([np.nanmean(np.where((x_0 <= x_prime)*(x_prime <= (x_0 + dx)), mask*cloud_frequency, np.nan)) for x_0 in np.arange(-4*island_radius, 100000.1, dx)]) x_prime_new = np.arange(-4*island_radius, 100000.1, dx) new_mask = np.where(mask==mask, 1.0, 0.0) axa.plot(x_prime_new/1000., cloud_frequency_x, color = my_cmap((labels.index(label)+1)/(len(labels)+1)), lw = [1 if label != 'Control' else 2][0])
integrate.trapz( x=my_data['z'][:iz], y=my_data[u_key][0, :iz, :, :], axis=0) / my_data['z'][iz]) V_mean = np.nanmean( integrate.trapz( x=my_data['z'][:iz], y=my_data[v_key][0, :iz, :, :], axis=0) / my_data['z'][iz]) wind_spd, wind_dir = fromComponents(U_mean, V_mean) # Use the wind direction to define our downwind rectangular region mask, y_prime, x_prime = downwind_rectangle(wind_dir, x_c, y_c, x, y, R_i, dist_0=-4 * R_i, dist_1=80000.0, half_width=5000.0) # Compute the potential temperature cross section x_prime_new = np.arange(-4 * R_i, 80000.1, dx) theta_cs = np.array([[ np.nanmean(np.where((x_0 <= x_prime) * (x_prime <= (x_0 + dx)), mask * my_data[theta_key][it, :, :, :], np.nan), axis=(1, 2)) for x_0 in x_prime_new ] for it in [-1]]) # array[t, x', z] w_cs = np.array([[ np.nanmean(np.where((x_0 <= x_prime) * (x_prime <= (x_0 + dx)),
integrate.trapz( x=my_data['z'][:iz], y=my_data[u_key][0, :iz, :, :], axis=0) / my_data['z'][iz]) V_mean = np.nanmean( integrate.trapz( x=my_data['z'][:iz], y=my_data[v_key][0, :iz, :, :], axis=0) / my_data['z'][iz]) wind_spd, wind_dir = fromComponents(U_mean, V_mean) # Use the wind direction to define our downwind rectangular region mask, y_prime, x_prime = downwind_rectangle(wind_dir, x_c, y_c, x, y, R_i, dist_0=-12000.0, dist_1=100000.0, half_width=3000.0) # Compute the potential temperature cross section x_prime_new = np.arange(-12000.0, 100000.1, dx) theta_cs = np.array([[ np.nanmean(np.where((x_0 <= x_prime) * (x_prime <= (x_0 + dx)), mask * my_data[theta_key][it, :, :, :], np.nan), axis=(1, 2)) for x_0 in x_prime_new ] for it in [-1]]) # array[t, x', z] w_cs = np.array([[ np.nanmean(np.where((x_0 <= x_prime) * (x_prime <= (x_0 + dx)),