Tm1.shape = [Nt, nk] Sm1 = nmp.zeros(Nt * nk) Sm1.shape = [Nt, nk] Ztmp[:, :] = ze1t[j1:j2, i1:i2] * ze2t[j1:j2, i1:i2] for jk in range(nk): rarea = nmp.sum(Ztmp[:, :] * Xmask[jk, j1:j2, i1:i2]) if rarea > 0.: Zar2[:, :] = Ztmp[:, :] * Xmask[jk, j1:j2, i1:i2] for jt in range(Nt): # Sigma0 Zm1[jt, jk] = nmp.sum( bphy.sigma0(Xtheta[jt, jk, j1:j2, i1:i2], Xsali[jt, jk, j1:j2, i1:i2]) * Zar2[:, :]) / rarea # Theta Tm1[jt, jk] = nmp.sum( Xtheta[jt, jk, j1:j2, i1:i2] * Zar2[:, :]) / rarea # Salinity Sm1[jt, jk] = nmp.sum( Xsali[jt, jk, j1:j2, i1:i2] * Zar2[:, :]) / rarea else: Zm1[:, jk] = nmp.nan Tm1[:, jk] = nmp.nan Sm1[:, jk] = nmp.nan # Writing in output file ########################
bt.chck4f(cf_mesh_mask) id_mm = Dataset(cf_mesh_mask) Xmask = id_mm.variables['tmask'][0,:,j1:j2,i1:i2] ze1t = id_mm.variables['e1t'] [0,j1:j2,i1:i2] ze2t = id_mm.variables['e2t'] [0,j1:j2,i1:i2] if jb == 0: zgdept = id_mm.variables['gdept_1d'][0,:] zgdepw = id_mm.variables['gdepw_1d'][0,:] nk = len(zgdept) id_mm.close() xsurf[:,:] = ze1t[:,:]*ze2t[:,:] # Surface Sigma0 xsg0 = bph.sigma0(xsst, xsss) # 3D sigma0 Xsig0 = bph.sigma0(xtpot, xsali) # Depth of interest (between 300. and 2000.): #if jb == 0: # jk1 = bt.find_index_from_value(300., zgdepw) # jk2 = bt.find_index_from_value(2000., zgdepw) # nb_zcrit = len(zgdepw[jk1:jk2]) nb_zcrit = nk ; jk1 = 0 ; jk2 = nk-1 rmean_sss0_deep_jfm = nmp.zeros(nb_zcrit) rmean_sss0_deep_m03 = nmp.zeros(nb_zcrit) nbp_deeper_zcrit = nmp.zeros(nb_zcrit)
if nb_dim == 4: xtht = f_nemo_T.variables[cv_T][jt, :, :, :] xsal = f_nemo_T.variables[cv_S][jt, :, :, :] if nb_dim == 3: xtht = f_nemo_T.variables[cv_T][jt, :, :] xsal = f_nemo_T.variables[cv_S][jt, :, :] if jt == 0: if nb_dim == 4: (nk, nj, ni) = nmp.shape(xtht) xsg0 = nmp.zeros((nk, nj, ni)) if nb_dim == 3: (nj, ni) = nmp.shape(xtht) xsg0 = nmp.zeros((nj, ni)) xsg0 = bp.sigma0(xtht, xsal) # computing Sigma0 at current time record ! if jt == 0: f_out = Dataset(cf_out, 'w', format='NETCDF3_CLASSIC') # Dimensions: f_out.createDimension('x', ni) f_out.createDimension('y', nj) if nb_dim == 4: f_out.createDimension('deptht', nk) f_out.createDimension('time_counter', None) id_lon = f_out.createVariable('nav_lon', 'f4', ( 'y', 'x', ))
if nj != nj0 or ni != ni0 or nk != nk0: print 'ERROR: 3D clim and NEMO file do no agree in shape!' print ' clim => ' + str(ni0) + ', ' + str(nj0) + ', ' + str( nk0) + ' (' + vdic['F_T_CLIM_3D_12'] + ')' print ' NEMO => ' + str(ni) + ', ' + str(nj) + ', ' + str(nk) sys.exit(0) ############# # M A R C H # ############# imnth = 2 # march # Computing sigma0 3D field: Sigma0 = bphys.sigma0(Tclim[imnth, :, :, :], Sclim[imnth, :, :, :]) * Xmask[:, :, :] if ldebug: Sigma0_nemo = bphys.sigma0(Tnemo[imnth:, :, :], Snemo[imnth, :, :, :]) * Xmask[:, :, :] Xmld_obs = nmp.zeros((nj, ni)) mmask = nmp.zeros((nj, ni)) mmask[:, :] = 1. for jk in range(nk - 1): zz = vlev[jk] Sigma0[jk, :, :] = Sigma0[jk, :, :] * mmask[:, :] Sigma0[jk + 1, :, :] = Sigma0[jk + 1, :, :] * mmask[:, :] ijloc = nmp.where(Sigma0[jk + 1, :, :] - 0.01 > Sigma0[jk, :, :]) mmask[ijloc] = 0.
bt.chck4f(cf_mesh_mask) id_mm = Dataset(cf_mesh_mask) Xmask = id_mm.variables['tmask'][0, :, j1:j2, i1:i2] ze1t = id_mm.variables['e1t'][0, j1:j2, i1:i2] ze2t = id_mm.variables['e2t'][0, j1:j2, i1:i2] if jb == 0: zgdept = id_mm.variables['gdept_1d'][0, :] zgdepw = id_mm.variables['gdepw_1d'][0, :] nk = len(zgdept) id_mm.close() xsurf[:, :] = ze1t[:, :] * ze2t[:, :] # Surface Sigma0 xsg0 = bph.sigma0(xsst, xsss) # 3D sigma0 Xsig0 = bph.sigma0(xtpot, xsali) # Depth of interest (between 300. and 2000.): #if jb == 0: # jk1 = bt.find_index_from_value(300., zgdepw) # jk2 = bt.find_index_from_value(2000., zgdepw) # nb_zcrit = len(zgdepw[jk1:jk2]) nb_zcrit = nk jk1 = 0 jk2 = nk - 1 rmean_sss0_deep_jfm = nmp.zeros(nb_zcrit)
# Want PmE (positive when ocean gains FW), in NEMO files its the oposite EmP... if 'wfo' in list_variables[:]: Zpme = -id_in_T.variables['wfo'] [:,:,:] ; # wfo same as below = EmP, > 0 when ocean losing water lpme = True if 'sowaflup' in list_variables[:]: Zpme = -id_in_T.variables['sowaflup'] [:,:,:] ; # Net Downward Heat Flux # # sowaflup = EmP (>0 if more evaporation than P) lpme = True print '(has ',Xtemp.shape[0],' time snapshots)\n' id_in_T.close() [ Nt, nk, nj, ni ] = Xtemp.shape ; print 'Nt, nk, nj, ni =', Nt, nk, nj, ni Zss0 = sigma0( Zsst, Zsss ) print len(ve3t[:]) if len(ve3t[:]) != nk: print 'Problem with nk!!!'; sys.exit(0) # NEMO output, Grid U and V # ~~~~~~~~~~~~~~~~~~~~~~~~~ if luv: id_in_U = Dataset(cf_in_U) list_variables = id_in_U.variables.keys() if NN_TAUX in list_variables[:]:
print ' clim => '+str(ni0)+', '+str(nj0)+', '+str(nk0)+' ('+F_T_CLIM_3D_12+')' print ' NEMO => '+str(ni)+', '+str(nj)+', '+str(nk) sys.exit(0) ############# # M A R C H # ############# imnth = 2 ; # march # Computing sigma0 3D field: Sigma0 = bphys.sigma0(Tclim[imnth,:,:,:], Sclim[imnth,:,:,:])*Xmask[:,:,:] if ldebug: Sigma0_nemo = bphys.sigma0(Tnemo[imnth:,:,:], Snemo[imnth,:,:,:])*Xmask[:,:,:] Xmld_obs = nmp.zeros(nj*ni) ; Xmld_obs.shape = [nj,ni] mmask = nmp.zeros(nj*ni) ; mmask.shape = [nj,ni] mmask[:,:] = 1. for jk in range(nk-1): zz = vlev[jk] Sigma0[jk,:,:] = Sigma0[jk,:,:]*mmask[:,:] Sigma0[jk+1,:,:] = Sigma0[jk+1,:,:]*mmask[:,:]
Zpme = -id_in_T.variables['wfo'][:, :, :] # wfo same as below = EmP, > 0 when ocean losing water lpme = True if 'sowaflup' in list_variables[:]: Zpme = -id_in_T.variables['sowaflup'][:, :, :] # Net Downward Heat Flux # # sowaflup = EmP (>0 if more evaporation than P) lpme = True print '(has ', Xtemp.shape[0], ' time snapshots)\n' id_in_T.close() [Nt, nk, nj, ni] = Xtemp.shape print 'Nt, nk, nj, ni =', Nt, nk, nj, ni Zss0 = sigma0(Zsst, Zsss) print len(ve3t[:]) if len(ve3t[:]) != nk: print 'Problem with nk!!!' sys.exit(0) # NEMO output, Grid U and V # ~~~~~~~~~~~~~~~~~~~~~~~~~ if luv: id_in_U = Dataset(cf_in_U) list_variables = id_in_U.variables.keys() if vdic_uv['NN_TAUX'] in list_variables[:]: Ztaux = id_in_U.variables[vdic_uv['NN_TAUX']][:, :, :] # Net Downward Heat Flux ltau = True
Tm1.shape = [Nt, nk] Sm1 = nmp.zeros(Nt * nk) Sm1.shape = [Nt, nk] Ztmp[:, :] = ze1t[j1:j2, i1:i2] * ze2t[j1:j2, i1:i2] for jk in range(nk): rarea = nmp.sum(Ztmp[:, :] * Xmask[jk, j1:j2, i1:i2]) if rarea > 0.0: Zar2[:, :] = Ztmp[:, :] * Xmask[jk, j1:j2, i1:i2] for jt in range(Nt): # Sigma0 Zm1[jt, jk] = ( nmp.sum(bphy.sigma0(Xtheta[jt, jk, j1:j2, i1:i2], Xsali[jt, jk, j1:j2, i1:i2]) * Zar2[:, :]) / rarea ) # Theta Tm1[jt, jk] = nmp.sum(Xtheta[jt, jk, j1:j2, i1:i2] * Zar2[:, :]) / rarea # Salinity Sm1[jt, jk] = nmp.sum(Xsali[jt, jk, j1:j2, i1:i2] * Zar2[:, :]) / rarea else: Zm1[:, jk] = nmp.nan Tm1[:, jk] = nmp.nan Sm1[:, jk] = nmp.nan # Writing in output file ######################## cf_out = DIAG_D + "/TS_z_box_" + cbox + "_" + CONFRUN + ".nc"