def find_mean_cloudlet_velocity(cloudlets, u, v, w, MC): dx, dy, dz, dt = MC['dx'], MC['dy'], MC['dz'], MC['dt'] ug, vg = MC['ug'], MC['vg'] for cloudlet in cloudlets: if len(cloudlet['condensed']) > 0: K, J, I = index_to_zyx( cloudlet['condensed'], MC ) # find the mean motion of the cloudlet u_mean = u[K, J, I].mean()-ug v_mean = v[K, J, I].mean()-vg w_mean = w[K, J, I].mean() cloudlet['u_condensed'] = round(u_mean*dt/dx) cloudlet['v_condensed'] = round(v_mean*dt/dy) cloudlet['w_condensed'] = round(w_mean*dt/dz) else: cloudlet['u_condensed'] = 0. cloudlet['v_condensed'] = 0. cloudlet['w_condensed'] = 0. K, J, I = index_to_zyx( cloudlet['plume'], MC ) # find the mean motion of the cloudlet u_mean = u[K, J, I].mean()-ug v_mean = v[K, J, I].mean()-vg w_mean = w[K, J, I].mean() cloudlet['u_plume'] = round(u_mean*dt/dx) cloudlet['v_plume'] = round(v_mean*dt/dy) cloudlet['w_plume'] = round(w_mean*dt/dz) return cloudlets
def calc_env(index, shellindex, edgeindex, MC): if len(shellindex) > 0: K_J_I = index_to_zyx(shellindex, MC) n = 6 for i in range(n): # Find all the points just outside the clouds stacklist = [K_J_I, ] for item in ((0, -1, 0), (0, 1, 0), (0, 0, -1), (0, 0, 1)): stacklist.append( K_J_I + numpy.array(item)[:, numpy.newaxis] ) maskindex = numpy.hstack(stacklist) maskindex[1, :] = maskindex[1, :] % MC['ny'] maskindex[2, :] = maskindex[2, :] % MC['nx'] maskindex = numpy.unique( zyx_to_index(maskindex[0, :], maskindex[1, :], maskindex[2, :], MC) ) # From the expanded mask, select the points outside the cloud envindex = numpy.setdiff1d(maskindex, index, assume_unique = True) K_J_I = index_to_zyx(envindex, MC) # Select the points within 4 grid cells of cloud r = calc_radii(envindex, edgeindex, MC) mask = r < 4.5 envindex = envindex[mask] else: envindex = [] return envindex
def find_mean_cloudlet_velocity(cloudlets, u, v, w, MC): dx, dy, dz, dt = MC['dx'], MC['dy'], MC['dz'], MC['dt'] ug, vg = MC['ug'], MC['vg'] for cloudlet in cloudlets: if len(cloudlet['condensed']) > 0: K, J, I = index_to_zyx(cloudlet['condensed'], MC) # find the mean motion of the cloudlet u_mean = u[K, J, I].mean() - ug v_mean = v[K, J, I].mean() - vg w_mean = w[K, J, I].mean() cloudlet['u_condensed'] = round(u_mean * dt / dx) cloudlet['v_condensed'] = round(v_mean * dt / dy) cloudlet['w_condensed'] = round(w_mean * dt / dz) else: cloudlet['u_condensed'] = 0. cloudlet['v_condensed'] = 0. cloudlet['w_condensed'] = 0. K, J, I = index_to_zyx(cloudlet['plume'], MC) # find the mean motion of the cloudlet u_mean = u[K, J, I].mean() - ug v_mean = v[K, J, I].mean() - vg w_mean = w[K, J, I].mean() cloudlet['u_plume'] = round(u_mean * dt / dx) cloudlet['v_plume'] = round(v_mean * dt / dy) cloudlet['w_plume'] = round(w_mean * dt / dz) return cloudlets
def calc_env(index, shellindex, edgeindex, MC): if len(shellindex) > 0: K_J_I = index_to_zyx(shellindex, MC) n = 6 for i in range(n): # Find all the points just outside the clouds stacklist = [ K_J_I, ] for item in ((0, -1, 0), (0, 1, 0), (0, 0, -1), (0, 0, 1)): stacklist.append(K_J_I + numpy.array(item)[:, numpy.newaxis]) maskindex = numpy.hstack(stacklist) maskindex[1, :] = maskindex[1, :] % MC['ny'] maskindex[2, :] = maskindex[2, :] % MC['nx'] maskindex = numpy.unique( zyx_to_index(maskindex[0, :], maskindex[1, :], maskindex[2, :], MC)) # From the expanded mask, select the points outside the cloud envindex = numpy.setdiff1d(maskindex, index, assume_unique=True) K_J_I = index_to_zyx(envindex, MC) # Select the points within 4 grid cells of cloud r = calc_radii(envindex, edgeindex, MC) mask = r < 4.5 envindex = envindex[mask] else: envindex = [] return envindex
def calc_com(mask, MC): ny, nx = MC['ny'], MC['nx'] pts = index_to_zyx( mask, MC ) z = pts[0,:].astype(float).mean() # Correct Center of Mass for reentrant domain y1 = pts[1,:].astype(float) x1 = pts[2,:].astype(float) y2 = (y1 < ny/2.)*y1 + (y1>= ny/2.)*(y1 - ny) x2 = (x1 < nx/2.)*x1 + (x1>= nx/2.)*(x1 - nx) y1m = y1.mean() y2m = y2.mean() x1m = x1.mean() x2m = x2.mean() if numpy.var(y2 - y2m) > numpy.var(y1 - y1m): y = y1m else: y = (y2m + .5)%ny - .5 if numpy.var(y2 - y2m) > numpy.var(y1 - y1m): y = y1m else: y = (y2m + .5)%ny - .5 if numpy.var(x2 - x2m) > numpy.var(x1 - x1m): x = x1m else: x = (x2m + .5)%nx - .5 return numpy.array(([z], [y], [x]))
def calc_com(mask, MC): ny, nx = MC['ny'], MC['nx'] pts = index_to_zyx(mask, MC) z = pts[0, :].astype(float).mean() # Correct Center of Mass for reentrant domain y1 = pts[1, :].astype(float) x1 = pts[2, :].astype(float) y2 = (y1 < ny / 2.) * y1 + (y1 >= ny / 2.) * (y1 - ny) x2 = (x1 < nx / 2.) * x1 + (x1 >= nx / 2.) * (x1 - nx) y1m = y1.mean() y2m = y2.mean() x1m = x1.mean() x2m = x2.mean() if numpy.var(y2 - y2m) > numpy.var(y1 - y1m): y = y1m else: y = (y2m + .5) % ny - .5 if numpy.var(y2 - y2m) > numpy.var(y1 - y1m): y = y1m else: y = (y2m + .5) % ny - .5 if numpy.var(x2 - x2m) > numpy.var(x1 - x1m): x = x1m else: x = (x2m + .5) % nx - .5 return numpy.array(([z], [y], [x]))
def save_text_file(clouds, t, MC): count = 0 for id in clouds: for point_type in clouds[id]: count = count + len(clouds[id][point_type]) recarray = numpy.zeros(count, dtype=[('id', 'i4'), ('type', 'a14'), ('x', 'i4'), ('y', 'i4'), ('z', 'i4')]) count = 0 for id in clouds: for point_type in clouds[id]: data = clouds[id][point_type] n = len(data) if n == 0: continue recarray['id'][count:n + count] = id recarray['type'][count:n + count] = point_type z, y, x = index_to_zyx(data, MC) recarray['x'][count:n + count] = x recarray['y'][count:n + count] = y recarray['z'][count:n + count] = z count = count + n recarray.tofile(open('output/clouds_at_time_%08g.txt' % t, 'w'), '\r\n')
def advect_indexes(indexes, u, v, w, MC): K_J_I = index_to_zyx(indexes, MC) K_J_I[0, :] = K_J_I[0, :] - w K_J_I[1, :] = K_J_I[1, :] - v K_J_I[2, :] = K_J_I[2, :] - u K_J_I[0, K_J_I[0, :] >= MC['nz']] = MC['nz'] - 1 K_J_I[0, K_J_I[0, :] < 0] = 0 K_J_I[1, :] = K_J_I[1, :] % MC['ny'] K_J_I[2, :] = K_J_I[2, :] % MC['nx'] advected_indexes = zyx_to_index(K_J_I[0, :], K_J_I[1, :], K_J_I[2, :], MC) return advected_indexes
def advect_indexes(indexes, u, v, w, MC): K_J_I = index_to_zyx(indexes, MC) K_J_I[0, :] = K_J_I[0, :] - w K_J_I[1, :] = K_J_I[1, :] - v K_J_I[2, :] = K_J_I[2, :] - u K_J_I[0, K_J_I[0, :] >= MC['nz']] = MC['nz']-1 K_J_I[0, K_J_I[0, :] < 0] = 0 K_J_I[1, :] = K_J_I[1, :] % MC['ny'] K_J_I[2, :] = K_J_I[2, :] % MC['nx'] advected_indexes = zyx_to_index(K_J_I[0,:], K_J_I[1,:], K_J_I[2,:], MC) return advected_indexes
def save_text_file(clouds, t, MC): count = 0 for id in clouds: for point_type in clouds[id]: count = count + len(clouds[id][point_type]) recarray = numpy.zeros(count, dtype=[('id', 'i4'),('type', 'a14'),('x','i4'),('y', 'i4'), ('z', 'i4')]) count = 0 for id in clouds: for point_type in clouds[id]: data = clouds[id][point_type] n = len(data) if n == 0: continue recarray['id'][count:n + count] = id recarray['type'][count:n + count] = point_type z, y, x = index_to_zyx(data, MC) recarray['x'][count:n + count] = x recarray['y'][count:n + count] = y recarray['z'][count:n + count] = z count = count + n recarray.tofile(open('output/clouds_at_time_%08g.txt' % t, 'w'), '\r\n')