def do_work(it): print '[' + dt.now().strftime('%H:%M:%S') + '] time ' + str(int(times[it])) print '[' + dt.now().strftime('%H:%M:%S') + '] Calculating cross sections' shf_1 = bilinear_interpolation(X, Y, fluxes_nc.variables[shf_key][it, :, :, :], x_cs, y_cs, kind=2) print '[' + dt.now().strftime( '%H:%M:%S') + '] Completed cross section for shf' lhf_1 = bilinear_interpolation(X, Y, fluxes_nc.variables[lhf_key][it, :, :, :], x_cs, y_cs, kind=2) print '[' + dt.now().strftime( '%H:%M:%S') + '] Completed cross section for lhf' # calculate the tke data u_p = (wind_nc.variables[u_key][it, :, :, :].transpose() - np.nanmean( wind_nc.variables[u_key][it, :, :, :], axis=(1, 2))).transpose() v_p = (wind_nc.variables[v_key][it, :, :, :].transpose() - np.nanmean( wind_nc.variables[v_key][it, :, :, :], axis=(1, 2))).transpose() w_p = (wind_nc.variables[w_key][it, :, :, :].transpose() - np.nanmean( wind_nc.variables[w_key][it, :, :, :], axis=(1, 2))).transpose() tke_data = 0.5 * (u_p**2 + v_p**2 + w_p**2) tke_1 = bilinear_interpolation(X, Y, tke_data, x_cs, y_cs, kind=2) print '[' + dt.now().strftime( '%H:%M:%S') + '] Completed cross section for tke' return shf_1, lhf_1, tke_1
def createSwathNC(hour): ############################################################################ # # # Section Two: Read in the netCDF, do any processing and concatenate # # # ############################################################################ print '[' + dt.now().strftime("%H:%M:%S") + '] Reading input variable for ' + hour input_nc = Dataset(path + nc_in + '_' + hour + '.nc', 'r') time_key = [i for i in input_nc.variables.keys() if 'min' in i][0] # Initialise the any timeseries arrays input_times = input_nc.variables[time_key][:] output_var = np.zeros((input_nc.variables[var_in].shape[0], input_nc.variables[var_in].shape[1], swath_x.shape[0], swath_x.shape[1])) output_anom = np.zeros_like(output_var) for it in xrange(input_nc.variables[var_in][:].shape[0]): output_var[it,:,:,:] = bilinear_interpolation(X, Y, input_nc.variables[var_in][it,:,:,:], swath_x.flatten(), swath_y.flatten(), kind = 2).reshape((len(z), int(swath_width/res + 1), len(R))) # Create the anomaly field from the horizontal mean mean = np.nanmean(input_nc.variables[var_in][it,:,:,:], axis = (1, 2))
def createSwathNC(hour): ############################################################################ # # # Section Two: Read in the netCDF, do any processing and concatenate # # # ############################################################################ print '[' + dt.now().strftime("%H:%M:%S") + '] Reading input variable for ' + hour input_nc = Dataset(path + nc_in + '_' + hour + '.nc', 'r') time_key = [i for i in input_nc.variables.keys() if 'min' in i][0] # Initialise the any timeseries arrays input_times = input_nc.variables[time_key][:] output_var = np.zeros((input_nc.variables[var_in].shape[0], input_nc.variables[var_in].shape[1], swath_x.shape[0], swath_x.shape[1])) for it in xrange(input_nc.variables[var_in][:].shape[0]): output_var[it,:,:,:] = bilinear_interpolation(X, Y, input_nc.variables[var_in][it,:,:,:], swath_x.flatten(), swath_y.flatten(), kind = 2).reshape((len(z), int(swath_width/res + 1), len(R))) ############################################################################ # # # Section Three: Save new netCDF # # # ############################################################################ print '[' + dt.now().strftime("%H:%M:%S") + '] Creating new netCDF' # Create a new netcdf for the regridded wind components output_nc = Dataset(path + nc_out + '_' + hour + '.nc', 'w') print '[' + dt.now().strftime("%H:%M:%S") + '] Creating dimensions for the netCDF' # Create dimensions for that netcdf time_dim = output_nc.createDimension(time_key, input_nc.variables[var_in][:].shape[0]) z_dim = output_nc.createDimension('thlev_zsea_theta', input_nc.variables[var_in][:].shape[1]) y_dim = output_nc.createDimension('y_prime', swath_y.shape[0]) x_dim = output_nc.createDimension('x_prime', swath_x.shape[1]) print '[' + dt.now().strftime("%H:%M:%S") + '] Creating variables for the netCDF' # Create variables for each dimension times_var = output_nc.createVariable(time_key, np.float32, (time_key,)) z_var = output_nc.createVariable('thlev_zsea_theta', np.float32, ('thlev_zsea_theta',)) ys_var = output_nc.createVariable('y_prime', np.float32, ('y_prime','x_prime')) xs_var = output_nc.createVariable('x_prime', np.float32, ('y_prime','x_prime')) # Create the variables to store the wind components out_var = output_nc.createVariable(var_in, np.float64, (time_key, 'thlev_zsea_theta', 'y_prime', 'x_prime')) lsm_var = output_nc.createVariable('lsm', np.float32, ('y_prime', 'x_prime')) print '[' + dt.now().strftime("%H:%M:%S") + '] Populating the dimension variables' # populate the dimension variables times_var[:] = input_times z_var[:] = input_nc.variables['thlev_zsea_theta'][:] ys_var[:] = swath_y[:] xs_var[:] = swath_x[:] print '[' + dt.now().strftime("%H:%M:%S") + '] Populating the variable' out_var[:] = output_var[:]*1. lsm_var[:] = lsm_var_interp[:]*1. print '[' + dt.now().strftime("%H:%M:%S") + '] Closing the input ncs' input_nc.close() print '[' + dt.now().strftime("%H:%M:%S") + '] Closing the output_nc' output_nc.close() print '[' + dt.now().strftime("%H:%M:%S") + '] Complete.'
print '[' + dt.now().strftime("%H:%M:%S") + '] Closing the input ncs' input_nc.close() print '[' + dt.now().strftime("%H:%M:%S") + '] Closing the output_nc' output_nc.close() print '[' + dt.now().strftime("%H:%M:%S") + '] Complete.' # Create the land-sea mask interpolated field <<<<<<< HEAD lsm_nc = Dataset('/work/n02/n02/xb899100/island_masks/lsm50_1600m.nc', 'r') ======= lsm_nc = Dataset('/work/n02/n02/xb899100/island_masks/lsm50.nc', 'r') >>>>>>> 62279a4ff074ba2a906de6d583e07e7c7ce0c696 lsm_var_interp = bilinear_interpolation(X, Y, lsm_nc.variables['lsm'][0,:,:,:], swath_x.flatten(), swath_y.flatten(), kind = 2).reshape((int(swath_width/res + 1), len(R))) lsm_nc.close() p = Pool(processes = len(hours)) p.map(createSwathNC, hours) p.close() p.join() <<<<<<< HEAD send_email(message = 'Completed w swath for ' + my_path.split('/')[-2] + ' experiment.', subject = 'regrid_w_along_flow.py', attachments = [''], isAttach = False) ======= #in_plane_winds(u, v, orientation = 90.) >>>>>>> 62279a4ff074ba2a906de6d583e07e7c7ce0c696
print 'Working on height ' + str(int(z[iz])) + ' m' for hour in hours: # read in the data print 'Reading hour ' + hour bouy_nc = Dataset('../bouy_' + hour + '.nc', 'r') if hour == '00': # skip the first time step to avoid issue with moisture resetting it_start = 1 else: it_start = 0 for key in var_keys.keys(): hovmollers[key][18 * hours.index(hour):( 18 * hours.index(hour) + 18), :] = bilinear_interpolation( X, Y, bouy_nc.variables[var_keys[key]][it_start:, iz, :, :], x_cs, y_cs, kind=3) bouy_nc.close() for key in var_keys.keys(): print 'Making Hovmoller for ' + key + ' at height ' + str(int( z[iz])) + ' m' cbar_min = round( var_factor[key] * (np.nanmean(hovmollers[key]) - np.max(3 * np.std(hovmollers[key]), 0.5)), 1) cbar_max = round( var_factor[key] * (np.nanmean(hovmollers[key]) + np.max(3 * np.std(hovmollers[key]), 0.5)), 1) if var_cmaps[key] == 'bwr':
# skip the first time step to avoid issue with moisture resetting it_start = 1 iz = np.where(np.abs(z - 360.) == np.min(np.abs(z - 360.)))[0][ 0] # these is a height from Matthews et al (2007) else: it_start = 0 # Calculate the hovmoller and cross section for key in dict_keys: print '[' + dt.now().strftime( '%H:%M:%S') + '] Working on ' + key + 'm smoothing Radius' hovmoller_dict[key][18 * hours.index(hour):( 18 * hours.index(hour) + 18), :] = bilinear_interpolation( X, Y, bouy_nc.variables[q_key][it_start:, iz, :, :], x_cs, y_cs, kind=3, d=int(key)) if hour == '09': print '[' + dt.now().strftime( '%H:%M:%S' ) + '] Doing the selected points, boundary layer depth, and cross section smoothing' # Offline, get the selected points for i in xrange(len(x_cs)): r = np.sqrt((X - x_cs[i])**2 + (Y - y_cs[i])**2) iy, ix = np.where((r < int(key))) selected_pts_dict[key][iy, ix] = 1.0 # Additionally read in the boundary layer height
for key in var_keys.keys(): hovmollers[key] = np.zeros((18 * len(hours), len(x_cs))) # convert island radius and along wind distance from m into km R_i /= 1000. R = -np.sign(x_cs - x_c) * np.sqrt((x_cs - x_c)**2 + (y_cs - y_c)**2) / 1000. # create a times array in units of hours for key in var_keys.keys(): times[key] = np.arange(10., 1440.1, 10.) / 60. ### Do for the liquid water path data ### print 'Reading the liquid water path netCDF and computing the hovmoller for it' lwp_nc = Dataset('../lwp_00.nc', 'r') times['lwp'] = lwp_nc.variables['min5_0'][1:] / 60. hovmollers['lwp'] = bilinear_interpolation( X, Y, lwp_nc.variables[var_keys['lwp']][1:, :, :], x_cs, y_cs, kind=3) lwp_nc.close() ### Do for the boundary layer depth data ### for hour in hours: # read in the data print 'Reading hour ' + hour zi_nc = Dataset('../zi_' + hour + '.nc', 'r') it_start = 0 for key in var_keys.keys(): if var_keys[key] in zi_nc.variables.keys(): print 'interpolating' hovmollers[key][18 * hours.index(hour):( 18 * hours.index(hour) + 18), :] = bilinear_interpolation( X, Y,
def get_soundings(it): """ Plots a swath of soundings for each time 'it' that is input """ # For the skewT plots # Get a sounding every 5 km downwind h = 100.0 # copied from above because for some reason, we cannot see this here. i_cs = np.where(R % 5000. < h)[0] temp_cs_soundings = bilinear_interpolation( X, Y, bouy_nc.variables[temp_key][it, :, :, :] * 1., x_cs[i_cs], y_cs[i_cs], kind=3) # mean within a radius pres_cs_soundings = bilinear_interpolation( X, Y, fluxes_nc.variables[pres_key][it, :, :, :] * 1., x_cs[i_cs], y_cs[i_cs], kind=3) q_cs_soundings = bilinear_interpolation( X, Y, bouy_nc.variables[q_key][it, :, :, :] * 1., x_cs[i_cs], y_cs[i_cs], kind=3) u_cs_soundings = bilinear_interpolation( X, Y, wind_nc.variables[u_key][it, :, :, :] * 1., x_cs[i_cs], y_cs[i_cs], kind=3) v_cs_soundings = bilinear_interpolation( X, Y, wind_nc.variables[v_key][it, :, :, :] * 1., x_cs[i_cs], y_cs[i_cs], kind=3) dew_cs_soundings = getDew(q_cs_soundings, pres_cs_soundings / 100.) # Ensure our soundings directory exists, if not create it if not os.path.isdir('../Soundings/'): os.mkdir('../Soundings/') #Plot the soundings as well for i in xrange(len(i_cs)): if not os.path.isdir('../Soundings/Radius_' + "{0:02d}".format(int(R[i_cs[i]] / 1000.)) + '/'): os.mkdir('../Soundings/Radius_' + "{0:02d}".format(int(R[i_cs[i]] / 1000.)) + '/') plotSkewT(temp_cs_soundings[:-1, i] - 273.15, dew_cs_soundings[:-1, i] - 273.15, pres_cs_soundings[:-1, i] / 100., u_cs_soundings[:-1, i], v_cs_soundings[:-1, i], my_title='T+' + str(int(times[it])) + 'mins, ' + str(int(R[i_cs[i]] / 1000.)) + 'km downwind', CAPE=True) plt.savefig('../Soundings/Radius_' + "{0:02d}".format(int(R[i_cs[i]] / 1000.)) + '/AlongWind_sounding_T' + "{0:04d}".format(int(times[it])) + '_R' + "{0:02d}".format(int(R[i_cs[i]] / 1000.)) + '.png', dpi=100) plt.close('all') print "{0:02d}".format(int( R[i_cs[i]] / 1000.)) + 'km Sounding Complete.'
def interpolateMap(variable): print '[' + dt.now().strftime('%H:%M:%S') + '] inside interpolateMap' temp = bilinear_interpolation(X, Y, variable, chunks_x[chunk_key].flatten(), chunks_y[chunk_key].flatten(), kind = 2).reshape((len(z), int(chunk_length/h + 1), int(chunk_width/res + 1))) print '[' + dt.now().strftime('%H:%M:%S') + '] exiting interpolateMap' return temp
def get_cs(it): # only need data to the height just above 3000 m iz3000 = np.where(np.abs(z - 5000) == np.min(np.abs(z - 5000)))[0][0] + 1 # leave the rest of the levels = 0 my_kind = 2 d = 2000. print('[' + dt.now().strftime("%H:%M:%S") + '] Interpolating to the cross section coordinates...') START = dt.now() print('[' + dt.now().strftime("%H:%M:%S") + '] Starting interpolation...') start = dt.now() theta_cs = bilinear_interpolation( X, Y, bouy_nc.variables[theta_key][it, :iz3000, :, :] * 1., x_cs, y_cs, kind=my_kind, d=d) end = dt.now() print('Finished interpolating Theta, elapsed time: ' + str(end - start)) start = dt.now() q_cs = bilinear_interpolation(X, Y, bouy_nc.variables[q_key][it, :iz3000, :, :] * 1., x_cs, y_cs, kind=my_kind, d=d) end = dt.now() print('Finished interpolating q, elapsed time: ' + str(end - start)) start = dt.now() w_cs = bilinear_interpolation(X, Y, bouy_nc.variables[w_key][it, :iz3000, :, :] * 1., x_cs, y_cs, kind=my_kind, d=d) end = dt.now() print('Finished interpolating w, elapsed time: ' + str(end - start)) start = dt.now() zi_cs = bilinear_interpolation(X, Y, zi_nc.variables[zi_key][:], x_cs, y_cs, kind=my_kind, d=d) end = dt.now() print('Finished interpolating zi, elapsed time: ' + str(end - start)) start = dt.now() lcl_cs = bilinear_interpolation(X, Y, zi_nc.variables[lcl_key][:], x_cs, y_cs, kind=my_kind, d=d) end = dt.now() print('Finished interpolating lcl, elapsed time: ' + str(end - start)) END = dt.now() print('[' + dt.now().strftime("%H:%M:%S") + '] Completed interpolation in ' + str(END - START) + "...") #================================= Section 4 ==================================# # # # Plot the cross section and anomalies # # # #==============================================================================# #print('Starting section 4') # Translate the cross section coordinates into the distance downwind of the island R = np.sign(x_c - x_cs) * np.sqrt((x_cs - x_c)**2 + (y_cs - y_c)**2) # Calculate the anomaly from the horizontal mean theta_cs_anom = np.zeros_like(theta_cs) q_cs_anom = np.zeros_like(q_cs) theta_hm = np.nanmean(bouy_nc.variables[theta_key][it, :iz3000, :, :], axis=(1, 2)) q_hm = np.nanmean(bouy_nc.variables[q_key][it, :iz3000, :, :], axis=(1, 2)) for i in xrange(theta_cs.shape[1]): theta_cs_anom[:, i] = theta_cs[:, i] - theta_hm q_cs_anom[:, i] = q_cs[:, i] - q_hm # Plotting params text_pos_x = -R_i / 1000. + R_i * 0.1 / 1000. text_pos_y = 100. fig_width = 10 # inches fig = plt.figure() fig.set_size_inches(fig_width, fig_width / 1.5) ax = plt.subplot(311) plt.contourf(R / 1000., z[:iz3000] / 1000., theta_cs_anom, cmap='bwr', levels=[l for l in np.linspace(-1., 1., 11) if l != 0.], extend='both') plt.colorbar(label=r'$\theta$ Anomaly (K)') plt.title('Potential Temperature Anomaly (K) Cross Section') plt.ylim([0, 5]) r_i = np.array([-R_i, R_i]) / 1000. plt.plot(r_i, [0, 0], 'k', lw=5) plt.text(text_pos_x, text_pos_y, 'Island') plt.plot(R / 1000., zi_cs[it, :] / 1000., 'k', lw=2) plt.plot(R / 1000., lcl_cs[it, :] / 1000., 'grey', lw=2) plt.ylabel('Height (km)') plt.setp(ax.get_xticklabels(), visible=False) ax1 = plt.subplot(312, sharex=ax) plt.contourf(R / 1000., z[:iz3000] / 1000., q_cs_anom * 1000., cmap='BrBG', levels=[l for l in np.linspace(-2., 2., 11) if l != 0.], extend='both') plt.colorbar(label=r'q Anomaly (g kg$^{-1}$)') plt.title('Specific Humidity Anomaly (g kg$^{-1}$) Cross Section') plt.ylim([0, 5]) plt.plot(r_i, [0, 0], 'k', lw=5) plt.text(text_pos_x, text_pos_y, 'Island') plt.plot(R / 1000., zi_cs[it, :] / 1000., 'k', lw=2) plt.plot(R / 1000., lcl_cs[it, :] / 1000., 'grey', lw=2) plt.ylabel('Height (km)') plt.setp(ax1.get_xticklabels(), visible=False) plt.subplot(313, sharex=ax) plt.contourf(R / 1000., z[:iz3000] / 1000., w_cs, cmap='bwr', levels=[l for l in np.linspace(-2.5, 2.5, 11) if l != 0.], extend='both') plt.colorbar(label=r'w (m s$^{-1}$)') plt.title('Vertical Velocity (m s$^{-1}$) Cross Section') plt.ylim([0, 5]) plt.plot(r_i, [0, 0], 'k', lw=5) plt.text(text_pos_x, text_pos_y, 'Island') plt.plot(R / 1000., zi_cs[it, :] / 1000., 'k', lw=2) plt.plot(R / 1000., lcl_cs[it, :] / 1000., 'grey', lw=2) plt.ylabel('Height (km)') plt.xlabel('Distance from Island mid-point (km)') plt.suptitle('Along-wind Cross Section, at T+' + str(int(times[it])) + 'mins', fontsize=15) plt.tight_layout() fig.subplots_adjust(top=0.88) plt.savefig('../AlongWind_interpolated_T' + "{0:04d}".format(int(times[it])) + '.png', dpi=100) plt.close('all') #plt.show() #================================= Section 5 ==================================# # # # Calculate cross sections perpendicular to the flow and plot them # # # #==============================================================================# # Choose distance from island mid-point to do the cross section # e.g. 20 km r_targets = [10000.0, 20000.0, 40000.0, 60000.0] for r_target in r_targets: # Find where the distance to the island is nearest to the target distance R_pos = np.where((R > 0), R, np.nan) iR = np.where( np.abs(R_pos - r_target) == np.nanmin(np.abs(R_pos - r_target)))[0][0] x_cs2, y_cs2 = get_cs_coords(x_cs[iR], y_cs[iR], wind_dir_0 + 90., X, Y, h=100.0) ### Testing ### if testing: fig = plt.figure() my_x = 12. fig.set_size_inches(my_x, my_x * 32. / 116.) plt.contourf(X / 1000., Y / 1000., lwp_data, levels=[0, 1e-8, 1], colors=['k', 'w']) plt.contourf(X / 1000., Y / 1000., lsm, levels=[0, 1e-16, 1], colors=['w', 'b'], alpha=0.5) plt.plot(x_cs / 1000., y_cs / 1000., 'r', lw=3) plt.plot(x_cs2 / 1000., y_cs2 / 1000., 'b', lw=3) plt.ylabel('y (km)') plt.xlabel('x (km)') plt.text(x_cs[0], y_cs[0], 'A', fontsize=20) plt.text(x_cs[-1], y_cs[-1], 'B', fontsize=20) plt.text(x_cs2[0], y_cs2[0], 'C', fontsize=20) plt.text(x_cs2[-1], y_cs2[-1], 'D', fontsize=20) plt.title('Cross Section Path') plt.tight_layout() plt.savefig('../Cross_Section_location2.png', dpi=100) plt.show() f = open("output.txt", "a") f.write('[' + dt.now().strftime("%H:%M:%S") + '] Starting interpolation...\n') f.close() START = dt.now() # Interpolate to cs2 start = dt.now() theta_cs2 = bilinear_interpolation( X, Y, bouy_nc.variables[theta_key][it, :iz3000, :, :], x_cs2, y_cs2, kind=my_kind, d=d) end = dt.now() print('Finished interpolating Theta, elapsed time: ' + str(end - start)) start = dt.now() q_cs2 = bilinear_interpolation( X, Y, bouy_nc.variables[q_key][it, :iz3000, :, :], x_cs2, y_cs2, kind=my_kind, d=d) end = dt.now() print('Finished interpolating q, elapsed time: ' + str(end - start)) start = dt.now() w_cs2 = bilinear_interpolation( X, Y, bouy_nc.variables[w_key][it, :iz3000, :, :], x_cs2, y_cs2, kind=my_kind, d=d) end = dt.now() print('Finished interpolating w, elapsed time: ' + str(end - start)) END = dt.now() start = dt.now() zi_cs2 = bilinear_interpolation(X, Y, zi_nc.variables[zi_key][:], x_cs2, y_cs2, kind=my_kind, d=d) end = dt.now() print('Finished interpolating zi, elapsed time: ' + str(end - start)) END = dt.now() start = dt.now() lcl_cs2 = bilinear_interpolation(X, Y, zi_nc.variables[lcl_key][:], x_cs2, y_cs2, kind=my_kind, d=d) end = dt.now() print('Finished interpolating lcl, elapsed time: ' + str(end - start)) END = dt.now() f = open('output.txt', 'a') f.write('[' + dt.now().strftime("%H:%M:%S") + '] Completed interpolation in ' + str(END - START) + "...\n") f.close() # Translate the cross section coordinates into the distance away from the island downwind mid-point R2 = -np.sign(x_cs[iR] - x_cs2) * np.sqrt((x_cs2 - x_cs[iR])**2 + (y_cs2 - y_cs[iR])**2) # Calculate the anomaly from the horizontal mean theta_cs2_anom = np.zeros_like(theta_cs2) q_cs2_anom = np.zeros_like(q_cs2) for i in xrange(theta_cs2.shape[1]): theta_cs2_anom[:, i] = theta_cs2[:, i] - theta_hm q_cs2_anom[:, i] = q_cs2[:, i] - q_hm # Plotting params text_pos_x = -R_i / 1000. + R_i * 0.1 / 1000. text_pos_y = 100. fig = plt.figure() ax = plt.subplot(311) plt.contourf(R2 / 1000., z[:iz3000] / 1000., theta_cs2_anom, cmap='bwr', levels=[l for l in np.linspace(-1., 1., 11) if l != 0.], extend='both') plt.colorbar() plt.title('Potential Temperature Anomaly (K) Cross Section') plt.ylim([0, 5]) r_i = np.array([-R_i, R_i]) / 1000. plt.plot(r_i, [0, 0], 'k', lw=10) plt.text(text_pos_x, text_pos_y, 'Island') plt.plot(R2 / 1000., zi_cs2[it, :] / 1000., 'k', lw=2) plt.plot(R2 / 1000., lcl_cs2[it, :] / 1000., 'grey', lw=2) plt.ylabel('Height (m)') plt.setp(ax.get_xticklabels(), visible=False) ax1 = plt.subplot(312, sharex=ax) plt.contourf(R2 / 1000., z[:iz3000] / 1000., q_cs2_anom * 1000., cmap='BrBG', levels=[l for l in np.linspace(-2., 2., 11) if l != 0.], extend='both') plt.colorbar() plt.title('Specific Humidity Anomaly (g kg$^{-1}$) Cross Section') plt.ylim([0, 5]) plt.plot(r_i, [0, 0], 'k', lw=10) plt.text(text_pos_x, text_pos_y, 'Island') plt.plot(R2 / 1000., zi_cs2[it, :] / 1000., 'k', lw=2) plt.plot(R2 / 1000., lcl_cs2[it, :] / 1000., 'grey', lw=2) plt.ylabel('Height (m)') plt.setp(ax1.get_xticklabels(), visible=False) plt.subplot(313, sharex=ax) plt.contourf(R2 / 1000., z[:iz3000] / 1000., w_cs2, cmap='bwr', levels=[l for l in np.linspace(-2.5, 2.5, 11) if l != 0.], extend='both') plt.colorbar() plt.title('Vertical Velocity (m s$^{-1}$) Cross Section') plt.ylim([0, 5]) plt.plot(r_i, [0, 0], 'k', lw=10) plt.text(text_pos_x, text_pos_y, 'Island') plt.plot(R2 / 1000., zi_cs2[it, :] / 1000., 'k', lw=2) plt.plot(R2 / 1000., lcl_cs2[it, :] / 1000., 'grey', lw=2) plt.ylabel('Height (m)') plt.xlabel('Distance from Island mid-point (km)') plt.suptitle('Cross-wind Cross Section (' + str(int(r_target / 1000.)) + 'km downwind), at T+' + str(int(times[it])) + 'mins', fontsize=15) plt.tight_layout() fig.subplots_adjust(top=0.88) plt.savefig('../CrossWind_smoothed_' + str(int(r_target / 1000.)) + 'km_T' + "{0:04d}".format(int(times[it])) + '.png', dpi=100) plt.close('all')
else: it += 1 point = [(np.nan, np.nan)] it = it%len(its) print point ax.cla() ax.contourf(X, Y, lwp_data[its[it],:,:]*1000., levels = np.arange(0., 1000.1, 50.), cmap = 'Greys_r', extend = 'max') ax.contour(X, Y, lsm, levels = [0,1e-16], colors = ['r']) ax.plot(point[0][0], point[0][1], 'r*', markersize = 20) ax.set_title('T+' + "{0:04d}".format(int(lwp_times[its[it]])) + ' mins') plt.pause(1) plt.close('all') print 'Calculating temperature at this point...' temperature_prof = np.array([obs[0] for obs in bilinear_interpolation(X, Y, bouy_nc.variables[temp_key][it,:,:,:], [point[0][0]], [point[0][1]], kind = 2)]) print 'Calculating dewpoint at this point...' dewpoint_prof = np.array([obs[0] for obs in bilinear_interpolation(X, Y, getDew(bouy_nc.variables[q_key][it,:,:,:], fluxes_nc.variables[p_key][it,:,:,:], q_units = 'kg/kg', p_units = 'Pa'), [point[0][0]], [point[0][1]], kind = 2)]) print 'Calculating winds at this point...' u_prof = np.array([obs[0] for obs in bilinear_interpolation(X, Y, wind_nc.variables[u_key][it,:,:,:], [point[0][0]], [point[0][1]], kind = 2)]) v_prof = np.array([obs[0] for obs in bilinear_interpolation(X, Y, wind_nc.variables[v_key][it,:,:,:], [point[0][0]], [point[0][1]], kind = 2)]) p_prof = np.array([obs[0] for obs in bilinear_interpolation(X, Y, fluxes_nc.variables[p_key][it,:,:,:], [point[0][0]], [point[0][1]], kind = 2)]) if l_skewT: ######################################################################## # Plot a skewT ######################################################################## print 'Plotting data on a SkewT...' fig = plt.figure(figsize = (5, 7.5)) ax = fig.add_subplot(1, 2, 1, adjustable = 'box', aspect = 1) plotSkewT(temperature_prof[:-1]-273.15, dewpoint_prof[:-1]-273.15, p_prof[:-1]/100., u_prof[:-1], v_prof[:-1])
# calculate the tke data u_p = (wind_nc.variables[u_key][it,:,:,:].transpose() - np.nanmean(wind_nc.variables[u_key][it,:,:,:], axis = (1, 2))).transpose() v_p = (wind_nc.variables[v_key][it,:,:,:].transpose() - np.nanmean(wind_nc.variables[v_key][it,:,:,:], axis = (1, 2))).transpose() w_p = (wind_nc.variables[w_key][it,:,:,:].transpose() - np.nanmean(wind_nc.variables[w_key][it,:,:,:], axis = (1, 2))).transpose() tke_data = 0.5*(u_p**2 + v_p**2 + w_p**2) tke_cs += bilinear_interpolation(X, Y, tke_data, x_cs, y_cs, kind = 2) print '[' + dt.now().strftime('%H:%M:%S') + '] Completed cross section for tke' """ p = Pool() crash #shf_cs, lhf_cs, tke_cs += p.map(do_work, range(len(times))) p.close() zi_cs += np.sum(bilinear_interpolation(X, Y, zi_nc.variables[zi_key][:], x_cs, y_cs, kind=2), axis=0) nt += len(times) fluxes_nc.close() wind_nc.close() shf_cs /= nt lhf_cs /= nt tke_cs /= nt zi_cs /= nt # Plot the Cross Section fig = plt.figure(figsize=(10, 10)) # Sensible heat flux cross section
target_grid_nc = Dataset(my_path + 'wind_' + hour + '.nc', 'r') input_data = regrid(target_grid_nc, input_nc, rho_key) <<<<<<< HEAD time_key = [i for i in target_grid_nc.variables.keys() if 'min' in i][0] # Initialise the any timeseries arrays input_times = target_grid_nc.variables[time_key][:] ======= time_key = [i for i in input_nc.variables.keys() if 'min' in i][0] # Initialise the any timeseries arrays input_times = input_nc.variables[time_key][:] >>>>>>> 62279a4ff074ba2a906de6d583e07e7c7ce0c696 output_var = np.zeros((input_data.shape[0], input_data.shape[1], swath_x.shape[0], swath_x.shape[1])) for it in xrange(input_data[:].shape[0]): output_var[it,:,:,:] = bilinear_interpolation(X, Y, input_data[it,:,:,:], swath_x.flatten(), swath_y.flatten(), kind = 2).reshape((len(z), int(swath_width/res + 1), len(R))) ############################################################################ # # # Section Three: Save new netCDF # # # ############################################################################ print '[' + dt.now().strftime("%H:%M:%S") + '] Creating new netCDF' # Create a new netcdf for the regridded wind components output_nc = Dataset(my_path + nc_out + '_' + hour + '.nc', 'w') print '[' + dt.now().strftime("%H:%M:%S") + '] Creating dimensions for the netCDF' # Create dimensions for that netcdf <<<<<<< HEAD time_dim = output_nc.createDimension(time_key, output_var.shape[0])