Example #1
0
# Get the horizontally averaged mixed layer depth
for ncfile in zi_files:
    zi_nc = Dataset(my_path + ncfile, 'r')
    if ncfile == zi_files[0]:
        zi = np.nanmean(zi_nc.variables[zi_new_key][:], axis = (1, 2))
    else:
        zi = np.concatenate((zi, np.nanmean(zi_nc.variables[zi_new_key][:], axis = (1, 2))), axis = 0)
    zi_nc.close()

# Get the time averaged mixed layer depth
zi = np.nanmean(zi, axis = 0)

# Get the mixed layer mean wind direction
u_ML = getML_mean(u, z, zi)
v_ML = getML_mean(v, z, zi)
orientation_in = fromComponents(u_ML, v_ML)[1]

print '[' + dt.now().strftime("%H:%M:%S") + '] Defining the swath coordinates to interpolate onto'
# We know from our domain definition where the centre of the island should be
R_i = 1000.0*(50.0/np.pi)**0.5 # Island radius m
x_c = 100000.0 + R_i           # x-coordinate for the island centre
y_c = 4*R_i                    # y-coordinate for the island centre

# Create the coordinate system for this data
<<<<<<< HEAD
dx = 1600.0
X, Y = np.meshgrid(np.arange(74)*dx, np.arange(20)*dx)

# Get coordinates of the cross section along the swath
h = dx*1. # Resolution in the along-swath direction
=======
Example #2
0
            np.arange(bouy_nc.variables[theta_key].shape[3]) * 100.0,
            np.arange(bouy_nc.variables[theta_key].shape[2]) * 100.0)
        time_key = [
            tkey for tkey in bouy_nc.variables.keys() if 'min' in tkey
        ][0]
        sim100['times'] = bouy_nc.variables[time_key]

        # 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))
                get_lcl(temp=PTtoTemp(
                    theta=mass_flux_xs[key][theta_key][idx, 0, :, :],
                    PIN=mass_flux_xs[key][pthe_key][idx, 0, :, :],
                    t_units='K',
                    p_units='Pa'),
                        q=mass_flux_xs[key][q_key][idx, 0, :, :],
                        pres=mass_flux_xs[key][pthe_key][idx, :, :, :],
                        z=z_theta) for idx in t_idx
            ])) if pthe_key in mass_flux_xs[key].keys() else 650.0
    ][0]

    # 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]
    speed, wind_dir = fromComponents(
        u=np.nanmean(mass_flux_xs[key][u_key][t_idx, :iz_LCL, :, :]),
        v=np.nanmean(mass_flux_xs[key][v_key][t_idx, :iz_LCL, :, :]))
    # 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,
Example #4
0
x, y = np.meshgrid(
    np.arange(u_data.shape[3]) * 0.1,
    np.arange(u_data.shape[2]) * 0.1)

# compute the theta anomalies at the horizontal mean height of the boundary layer at a given time
# choose times of interest
times_of_interest = [6, 9, 12]
# convert from hours to minutes since simulation start
times_of_interest = [time * 60.0 for time in times_of_interest]
# find the horizontal mean boundary layer height at these times
wind_select = []
iz = np.where(np.abs(z - 10.0) == np.min(np.abs(z - 10.0)))[0][0] + 1
for time in times_of_interest:
    it = np.where(time == times)[0][0]
    wind_spd, wind_dir = fromComponents(u_data[it, iz, :, :], v_data[it,
                                                                     iz, :, :])
    wind_select.append(wind_spd)

wind_select = np.array(wind_select)

# define plotting parameters
my_levels = np.array(
    [level
     for level in np.arange(-3.0, 3.1, 0.5) if level != 0.0]) + 8.0  #wind_spd

island_area = 50.0
island_radius = np.sqrt(island_area / np.pi)
island_x = 100.0 + island_radius
island_y = 4 * island_radius
R = np.sqrt((x - island_x)**2 + (y - island_y)**2)
island_mask = np.where(R > island_radius, 1.0, 0.0)
# Radius of the island, m
island_area = 50.0 # km^2
R_i = 1000.0*np.sqrt(island_area/np.pi)
x_c = 100000.0 + R_i
y_c = 4*R_i

# 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))
 # use our new function to define a rectangle downwind
 # Define the existing cartesian coordinate system
 X, Y = np.meshgrid(np.arange(thermo_nc.variables[theta_key][0,0,0,:].shape[0])*100.0, np.arange(thermo_nc.variables[theta_key][0,0,:,0].shape[0])*100.0)
 
 # Compute and store the horizontal mean LCL
 lcl[key] = np.nanmean(zi_nc.variables[lcl_key][t_idx2,:,:])
 zi[key] = np.nanmean(zi_nc.variables[zi_new_key][t_idx2,:,:])
 
 # 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