print(tfiles[k]) # Load the SSH field and remask it. ssh = nemo.load_field('sossheig', '', '', tfiles[k], 'T') ssh = nemo.mask_field(ssh, tmask) # Calculate the geostrophic velocities. ssu = -2.0 * g * nemo.grad_dtdy(ssh.data, e2v, vmask, nx, ny, 1) / (f[0:nx, :, :] + f[1:nx + 1, :, :]) ssu = ssu * vmask ssv = 2.0 * g * nemo.grad_dtdx(ssh.data, e1u, umask, nx, ny, 1) / (f[:, 0:ny, :] + f[:, 1:ny + 1, :]) ssv = ssv * umask # Calculate the geostrophic KE for the current geostrophic velocity fields ssk = ssk + nemo.calc_ke(ssv, ssu, nx, ny, 1, tmask) # Increment the counter by 1. counter = counter + 1 # --------------------------------------------------------------------------- # # Now the loop over all the files is complete, divide the accumulations by counter. ssk = ssk / counter # Save the averaged field to a numpy matrix file for later plotting. np.save( ''.join([ homedir, nemodir, 'TIDY/ARCHIVE/POST/geoke_ANN_', str(init_year), '-', str(init_year + num_years - 1)
# Preallocate the output variable. meanke = np.ndarray(shape=[len(ufiles), 2]) # Loop over the U/V files and load the surface velocity. for k in range(len(ufiles)): print(ufiles[k]) # Load & mask the current U velocity field. ssu = nemo.load_field('sossussu', '', '', ufiles[k], 'U') ssu = nemo.mask_field(ssu, umask) # Load and mask the current V velocity field. ssv = nemo.load_field('sossvssv', '', '', vfiles[k], 'V') ssv = nemo.mask_field(ssv, vmask) # Calculate the KE for the current velocity fields ssk = nemo.calc_ke(ssu.data, ssv.data, nx, ny, 1, tmask) # Calculate the area average surface KE. meanke[k, 0] = ufiles[k].split('/ORCH0083-LIM3_', 1)[1].split('_U', 1)[0] meanke[k, 1] = (ssk * area).sum() / area.sum() # --------------------------------------------------------------------------- # # Spit the numbers out to file, if requested. if save_output: np.save(''.join([homedir, nemodir, 'TIDY/ARCHIVE/POST/meanke']), meanke) # --------------------------------------------------------------------------- # # If we're not saving the number, we're loading them. if not save_output: meanke = np.load(''.join(
u = nemo.mask_field(u, umask) e3u = np.squeeze(nemo.load_field('e3u', '', '', ufiles[k], 'U')) e3u = nemo.mask_field(e3u, umask) u = u / e3u e3u = None # Load and mask the current V velocity field. v = np.squeeze(nemo.load_field('vomece3v', '', '', vfiles[k], 'V')) v = nemo.mask_field(v, vmask) e3v = np.squeeze(nemo.load_field('e3v', '', '', vfiles[k], 'V')) e3v = nemo.mask_field(e3v, vmask) v = v / e3v e3v = None # Calculate the KE for the current velocity fields ke = nemo.calc_ke(u.data, v.data, nx, ny, nz, tmask) # Calculate the area average surface temperature. meanke[k, 0] = ufiles[k].split('/ORCH0083-LIM3_', 1)[1].split('_U', 1)[0] meanke[k, 1:] = np.sum(ke * area, axis=(0, 1)) / np.sum(area, axis=(0, 1)) # --------------------------------------------------------------------------- # # Spit the numbers out to file, if requested. if save_output: np.save(''.join([homedir, nemodir, 'TIDY/ARCHIVE/POST/meankine']), meanke) # --------------------------------------------------------------------------- # # If we're not saving the number, we're loading them. if not save_output:
ssu = nemo.mask_field(ssu, umask) ssu2 = nemo.load_field('sossusqu', homedir, nemodir, ufilename, 'U') ssu2 = nemo.mask_field(ssu2, umask) ssv = nemo.load_field('sossvssv', homedir, nemodir, vfilename, 'V') ssv = nemo.mask_field(ssv, vmask) ssv2 = nemo.load_field('sossvsqu', homedir, nemodir, vfilename, 'V') ssv2 = nemo.mask_field(ssv2, vmask) # --------------------------------------------------------------------------- # # Calculate the Total Kinetic Energy. tke = nemo.calc_uv_on_t(ssu2.data, ssv2.data, nx, ny, nz, tmask) # Calculate the Mean Kinetic Energy. mke = nemo.calc_ke(ssu.data, ssv.data, nx, ny, nz, tmask) # Calculate the Eddy Kinetic Energy. eke = nemo.calc_eke(ssu.data, ssu2.data, ssv.data, ssv2.data, nx, ny, 1, tmask) # --------------------------------------------------------------------------- # # Create a new figure window. plt.figure(figsize=(8.0, 8.0)) # Specify some things to make the plot look nice. map = Basemap(projection='spaeqd', boundinglat=-35, lon_0=-150, round='true') # Draw grid lines and label the longitudes. map.drawparallels(np.arange(-80, 0, 20), linewidth=0.25, color='w') map.drawmeridians(np.arange(-180, 180, 30),