예제 #1
0
def TimeDeriv(tstep, vprime, Hist, HistFile, Avg, AvgFile, Diag, dA_xy, Masks):
    """
    Exact volume time derivative of variance squared
    """
    #change in vertical thickness of cell at average point
    deltaA = np.diff(dep._set_depth(AvgFile, None, 'w', \
                                             Avg.variables['h'][:], \
                                             Avg.variables['zeta'][tstep,:,:]),
                              n = 1, axis = 0)

    #diagnostic rate
    var_rate = Diag.variables['salt_rate'][tstep, :, :, :] * Masks['RhoMask']

    #change in vertical cell thickness at history points
    deltaH0 = np.diff(dep._set_depth(HistFile, None, 'w', \
                                             Hist.variables['h'][:], \
                                             Hist.variables['zeta'][tstep,:,:]),
                              n = 1, axis = 0)*Masks['RhoMask']

    deltaH1 = np.diff(dep._set_depth(HistFile, None, 'w', \
                                             Hist.variables['h'][:], \
                                             Hist.variables['zeta'][tstep+1,:,:]),
                              n = 1, axis = 0)*Masks['RhoMask']

    dtH = Hist.variables['ocean_time'][tstep +
                                       1] - Hist.variables['ocean_time'][tstep]

    #time derivative of cell volume on avg points
    dDelta_dt = (deltaH1 - deltaH0) / dtH

    #compute volume
    dV = dA_xy * deltaA

    salt = Avg.variables['salt'][tstep, :, :, :] * Masks['RhoMask']

    vprime = vprime * Masks['RhoMask']

    Int_Sprime = np.sum(2 * vprime * (var_rate - (salt / deltaA) * dDelta_dt) *
                        dV)

    return Int_Sprime
예제 #2
0
def dAz_psi(RomsFile):
    """Compute differential area of each cell using a trapazoid at psi points"""
    #load roms file
    RomsNC = nc4(RomsFile, 'r')

    #compute z
    romsvars = {'h' : RomsNC.variables['h'], \
                'zeta' : RomsNC.variables['zeta']}

    #compute depth at w points
    depth_domain = dep._set_depth(RomsFile, None, 'psi', romsvars['h'],
                                  romsvars['zeta'])
    dz = np.diff(depth_domain, n=1, axis=0)

    #compute lengths of horizontal cell directions repeat over depth axis
    dx = np.repeat(1 / np.array(RomsNC.variables['pm'])[np.newaxis, :, :],
                   dz.shape[0],
                   axis=0)
    dy = np.repeat(1 / np.array(RomsNC.variables['pn'])[np.newaxis, :, :],
                   dz.shape[0],
                   axis=0)

    #compute differential area assuming trapizoidal shape
    A_xz = np.empty(dz.shape)
    A_xz.fill(np.nan)

    A_yz = np.empty(dz.shape)
    A_yz.fill(np.nan)

    Lm = dz.shape[1]
    Mm = dz.shape[2]

    #x area and y area
    for k in range(1, dz.shape[1] - 1):
        A_xz[:, k - 1, :] = 0.5 * (dz[:, k, 0:Mm] +
                                   dz[:, k - 1, 0:Mm]) * dx[:, k - 1, 0:Mm]

    for k in range(1, dz.shape[2] - 1):
        A_yz[:, :,
             k - 1] = 0.5 * (dz[:, 0:Lm, k] + dz[:, 0:Lm, k - 1]) * dy[:, 0:Lm,
                                                                       k - 1]

    return A_xz, A_yz
예제 #3
0
def ModelDepth(RomsFile, point_type, IndBounds):
    """Computes ROMS depth within control volume defined by lat and lon bounds
    uses obs_depth, converted from set_depth.m"""
    #load nc file
    RomsNC = dt(RomsFile, 'r')

    #ROMS variables
    romsvars = {'h' : RomsNC.variables['h'], \
                'zeta' : RomsNC.variables['zeta'],\
                'N' : RomsNC.variables['Cs_r'].size}
    #compute depth
    depth_domain = dep._set_depth(RomsFile, None, point_type, romsvars['h'],
                                  romsvars['zeta'])

    #subset at control volume
    depth = np.array(depth_domain[:,IndBounds['Rho']['lat_li']:IndBounds['Rho']['lat_ui'],\
                                  IndBounds['Rho']['lon_li']:IndBounds['Rho']['lon_ui']])

    return depth
예제 #4
0
AdvFlux.fill(np.nan)
DifFlux = np.empty(time.shape)
DifFlux.fill(np.nan)
IntMix = np.empty(time.shape)
IntMix.fill(np.nan)
HuonFlux = np.empty(time.shape)
HuonFlux.fill(np.nan)

##Loop on time step
for tstep in range(time.shape[0]):
    #compute variance at time step
    var = Avg.variables['salt'][tstep, :, :, :]

    #compute depth at averg points
    dz = np.diff(dep._set_depth(AvgFile, None, 'w',\
                                Avg.variables['h'][:],\
                                Avg.variables['zeta'][tstep, :, :]), \
                 n = 1, axis = 0)

    #compute cell areas
    Areas = ebt.CellAreas(dx, dy, dz, Masks)

    #time derivative of salinity variance squared
    dsdt_dV[tstep] = ebt.TimeDeriv(tstep, var, Hist, HistFile, Avg, AvgFile,
                                   Diag, Areas['Axy'], Masks)

    #Advective flux
    AdvFlux[tstep] = ebt.Adv_Flux_west(tstep, var, Avg, Areas, Masks)

    HuonFlux[tstep] = np.sum(
        Avg.variables['Huon_salt'][tstep, :, :, :][Masks['WFace']])
#load dx and dy for gradients
dx = np.repeat(1/np.array(Avg.variables['pm'][:])[np.newaxis, :, :], \
               Avg.variables['salt'][0,:,0,0].size, axis = 0)
dy = np.repeat(1/np.array(Avg.variables['pn'][:])[np.newaxis, :, :], \
               Avg.variables['salt'][0,:,0,0].size, axis = 0)

EstEr = np.empty((dy[Masks['RhoMask']].size, time.size))
EstEr.fill(np.nan)

for tstep in range((time.shape[0]) - 1):
    #compute variance at time step
    var = Avg.variables['salt'][tstep, :, :, :]

    #compute depth at averg points
    dz = np.diff(dep._set_depth(AvgFile, None, 'w',\
                                Avg.variables['h'][:],\
                                Avg.variables['zeta'][tstep, :, :]), \
                 n = 1, axis = 0)

    #Time derivative
    #cell thinkness on average points
    deltaA = np.diff(dep._set_depth(AvgFile, None, 'w', \
                                             Avg.variables['h'][:], \
                                             Avg.variables['zeta'][tstep,:,:]),
                              n = 1, axis = 0)

    #diagnostic rate
    var_rate = Diag.variables['salt_rate'][tstep, :, :, :] * Masks['RhoMask']

    #change in vertical cell thickness at history points
    deltaH0 = np.diff(dep._set_depth(HistFile, None, 'w', \
예제 #6
0
time = Avg.variables['ocean_time'][:]

#load dA
dA_xy = ma.array(dff.dA_top(Avg), mask=RhoMask)

#integrate time derivative of s_prime^2
SprInt = np.empty(time.shape[0])
SprInt.fill(np.nan)
for t in range(time.shape[0]):
    #avg file variables at t
    salt = ma.array(Avg.variables['salt'][t, :, :, :], mask=RhoMask)
    s_prime = salt - salt.mean()

    #diff and mask are in opposite order
    deltaA = ma.array(ma.diff(dep._set_depth(AvgFile, None, 'w', \
                                             Avg.variables['h'][:], \
                                             Avg.variables['zeta'][t,:,:]),
                              n = 1, axis = 0), \
                      mask = RhoMask)

    #diag file variables at t
    salt_rate = ma.array(Diag.variables['salt_rate'][t, :, :, :], \
                         mask = RhoMask)

    #hist variables at t and t+1
    deltaH0 = ma.array(ma.diff(dep._set_depth(HistFile, None, 'w', \
                                             Hist.variables['h'][:], \
                                             Hist.variables['zeta'][t,:,:]),
                              n = 1, axis = 0), \
                      mask = RhoMask)