def get_uv_at_depth(dirname, fname, dep_ind):

    filesU = general_functions.get_files(dirname, fname, 'grid_U')
    filesV = general_functions.get_files(dirname, fname, 'grid_V')

    y, x = slice(1, -1, None), slice(1, -1, None)

    with scDataset(filesU) as dsU, scDataset(filesV) as dsV:
        vozocrtx0 = dsU.variables['vozocrtx'][:, dep_ind, y, x]
        vomecrty0 = dsV.variables['vomecrty'][:, dep_ind, y, x]
        sozotaux = dsU.variables['sozotaux'][:, 0, 0]
        depthu = dsU.variables['depthu'][:]
        depthv = dsV.variables['depthv'][:]

    with nc.Dataset(os.path.join(dirname, '1_mesh_mask.nc'), 'r') as dsM:
        umask0 = dsM.variables['umask'][0, dep_ind, y, x]
        vmask0 = dsM.variables['vmask'][0, dep_ind, y, x]
        e1u = dsM.variables['e1u'][0, y, x]
        e1v = dsM.variables['e1v'][0, y, x]
        e2u = dsM.variables['e2u'][0, y, x]

    umask = np.tile(umask0, (len(sozotaux), 1, 1))
    vmask = np.tile(vmask0, (len(sozotaux), 1, 1))

    vozocrtx = np.ma.array(vozocrtx0, mask=1 - umask)
    vomecrty = np.ma.array(vomecrty0, mask=1 - vmask)

    return vozocrtx, vomecrty, umask[0, ...], vmask[
        0, ...], e1u, e1v, e2u, depthu, depthv, sozotaux
def get_vars_for_box(dirname, fname, meshmaskname, x_start, x_end, y_start,
                     y_end, flag):
    if flag == 'U':
        gridname = 'grid_U'
        velname = 'vozocrtx'
        depthname = 'depthu'
        maskname = 'umask'
        e1name = 'e1u'
        e2name = 'e2u'

    elif flag == 'V':
        gridname = 'grid_V'
        velname = 'vomecrty'
        depthname = 'depthv'
        maskname = 'vmask'
        e1name = 'e1v'
        e2name = 'e2v'

    elif flag == 'W':
        gridname = 'grid_W'
        velname = 'vovecrtz'
        depthname = 'depthw'
        maskname = 'tmask'
        e1name = 'e1t'
        e2name = 'e2t'

    filesU = general_functions.get_files(dirname, fname, 'grid_U')
    with scDataset(filesU) as dsU:
        sozotaux = dsU.variables['sozotaux'][:, 0, 0]

    x, y = slice(x_start, x_end, None), slice(y_start, y_end, None)
    files = general_functions.get_files(dirname, fname, gridname)
    with scDataset(files) as ds:
        vel0 = ds.variables[velname][:, :, y, x]
        depth = ds.variables[depthname][:]

    with nc.Dataset(os.path.join(dirname, meshmaskname), 'r') as dsM:
        mask0 = dsM.variables[maskname][0, :, y, x]
        mask_all = dsM.variables[maskname][0, :, :, :]
        e1 = dsM.variables[e1name][0, y, x]
        e2 = dsM.variables[e2name][0, y, x]

    mask = np.tile(mask0, (len(sozotaux), 1, 1, 1))
    vel = np.ma.array(vel0, mask=1 - mask)

    return vel, mask, mask_all, depth, e1, e2, sozotaux
示例#3
0
def get_variables_fluxes(dirname, filepattern, ind_plane, vmask):
    files = general_functions.get_files(dirname, filepattern, 'grid_V')
    x, y = slice(1, -1, None), int(ind_plane)
    with scDataset(files) as ds:
        vomecrty0 = ds.variables['vomecrty'][:, :, y, x]
    vmask0 = vmask[:, y, :]
    vmask = np.tile(vmask0, (vomecrty0.shape[0], 1, 1))
    vomecrty = np.ma.array(vomecrty0, mask=1 - vmask)
    return vomecrty
示例#4
0
def get_variables_fluxes(dirname, filepattern, surface_mask):

    files = general_functions.get_files(dirname, filepattern, 'grid_W')
    x, y = slice(1, -1, None), slice(1, -1, None)
    with scDataset(files) as ds:
        vovecrtz0 = ds.variables['vovecrtz'][:, :, y, x]
    surface_mask_f = np.tile(surface_mask, (vovecrtz0.shape[0], 1, 1, 1))
    vovecrtz = np.ma.array(vovecrtz0, mask=1 - surface_mask_f)

    return vovecrtz
def get_vars_at_depth(dirname, fname, dep_ind):

    filesU = general_functions.get_files(dirname, fname, 'grid_U')
    filesV = general_functions.get_files(dirname, fname, 'grid_V')
    filesW = general_functions.get_files(dirname, fname, 'grid_W')
    filesT = general_functions.get_files(dirname, fname, 'grid_T')
    print('files')

    y, x = slice(1, -1, None), slice(1, -1, None)

    with scDataset(filesU) as dsU, scDataset(filesV) as dsV, scDataset(
            filesW) as dsW, scDataset(filesT) as dsT:
        vozocrtx0 = dsU.variables['vozocrtx'][:, dep_ind, y, x]
        print('U')
        vomecrty0 = dsV.variables['vomecrty'][:, dep_ind, y, x]
        print('V')
        vovecrtz0 = dsW.variables['vovecrtz'][:, dep_ind, y, x]
        print('W')
        vosaline0 = dsT.variables['vosaline'][:, dep_ind, y, x]
        vosaline0_orig = dsT.variables['vosaline'][0, dep_ind, y, x]
        print('S')
        sozotaux = dsU.variables['sozotaux'][:, 0, 0]
        depthu = dsU.variables['depthu'][:]

    with nc.Dataset(os.path.join(dirname, '1_mesh_mask.nc'), 'r') as dsM:
        umask0 = dsM.variables['umask'][0, dep_ind, y, x]
        vmask0 = dsM.variables['vmask'][0, dep_ind, y, x]
        tmask0 = dsM.variables['tmask'][0, dep_ind, y, x]

    umask = np.tile(umask0, (len(sozotaux), 1, 1))
    vmask = np.tile(vmask0, (len(sozotaux), 1, 1))
    tmask = np.tile(tmask0, (len(sozotaux), 1, 1))
    tmask_orig = np.tile(tmask0, (1, 1, 1))

    vozocrtx = np.ma.array(vozocrtx0, mask=1 - umask)
    vomecrty = np.ma.array(vomecrty0, mask=1 - vmask)
    vovecrtz = np.ma.array(vovecrtz0, mask=1 - tmask)
    vosaline = np.ma.array(vosaline0, mask=1 - tmask)
    vosaline_orig = np.ma.array(vosaline0_orig, mask=1 - tmask_orig)

    return vozocrtx, vomecrty, vovecrtz, vosaline, vosaline_orig, umask, vmask, tmask, depthu, sozotaux
def get_uv_at_depth_day(dirname, fname, dep_ind, day):
    ''' day 1 = 0 to 24 hrs -- time_ind 24 hrs
        day 2 = 24 to 48 hrs -- time_ind 48 hrs
        day 3 = 48 to 72 hrs -- time_ind 72 hrs
        
        enter the actual day you want (no day 0).
    '''

    filesU = general_functions.get_files(dirname, fname, 'grid_U')
    filesV = general_functions.get_files(dirname, fname, 'grid_V')

    y, x = slice(1, -1, None), slice(1, -1, None)
    time_ind = day * 24

    with scDataset(filesU) as dsU, scDataset(filesV) as dsV:
        vozocrtx0 = dsU.variables['vozocrtx'][time_ind - 24:time_ind, dep_ind,
                                              y, x]
        vomecrty0 = dsV.variables['vomecrty'][time_ind - 24:time_ind, dep_ind,
                                              y, x]
        sozotaux = dsU.variables['sozotaux'][time_ind - 24:time_ind, 0, 0]
        depthu = dsU.variables['depthu'][:]
        depthv = dsV.variables['depthv'][:]

    with nc.Dataset(os.path.join(dirname, '1_mesh_mask.nc'), 'r') as dsM:
        umask0 = dsM.variables['umask'][0, dep_ind, y, x]
        vmask0 = dsM.variables['vmask'][0, dep_ind, y, x]
        e1u = dsM.variables['e1u'][0, y, x]
        e2u = dsM.variables['e2u'][0, y, x]

    umask = np.tile(umask0, (len(sozotaux), 1, 1))
    vmask = np.tile(vmask0, (len(sozotaux), 1, 1))

    vozocrtx = np.ma.array(vozocrtx0, mask=1 - umask)
    vomecrty = np.ma.array(vomecrty0, mask=1 - vmask)

    vozocrtx_avg = np.mean(vozocrtx, axis=0)
    vomecrty_avg = np.mean(vomecrty, axis=0)

    return vozocrtx, vomecrty, vozocrtx_avg, vomecrty_avg, umask[
        0, ...], vmask[0, ...], e1u, e2u, depthu, depthv, sozotaux
示例#7
0
def get_vars_salt(dirname, fname, meshmaskname, dep_ind_slice, time_s, time_f,
                  y_end):

    if y_end == None:
        y_end = -1
    else:
        y_end = y_end

    y, x = slice(1, y_end, None), slice(1, -1, None)

    filesT = general_functions.get_files(dirname, fname, 'grid_T')
    filesU = general_functions.get_files(dirname, fname, 'grid_U')

    with scDataset(filesT) as dsT, scDataset(filesU) as dsU:
        deptht = dsT.variables['deptht'][:]
        if dep_ind_slice == None:
            vosaline0 = dsT.variables['vosaline'][time_s:time_f, :, y, x]
        else:
            vosaline0 = dsT.variables['vosaline'][time_s:time_f, dep_ind_slice,
                                                  y, x]
        sozotaux = dsU.variables['sozotaux'][time_s:time_f, 0, 0]

    with nc.Dataset(os.path.join(dirname, meshmaskname), 'r') as dsM:
        if dep_ind_slice == None:
            tmask0 = dsM.variables['tmask'][0, :, y, x]
        else:
            tmask0 = dsM.variables['tmask'][0, dep_ind_slice, y, x]

    tmask = np.tile(tmask0, (len(sozotaux), 1, 1, 1))
    vosaline = np.ma.array(vosaline0, mask=1 - tmask)

    if dep_ind_slice == None:
        tmask_return = tmask
    else:
        tmask_return = tmask[0, 0, ...]

    return vosaline, sozotaux, deptht, tmask_return
def get_sal_cross_zon(dirname, fname, y_ind, time_ind, z_cut):

    filesT = general_functions.get_files(dirname, fname, 'grid_T')

    x = slice(1, -1, None)

    with scDataset(filesT) as dsT:
        vosaline0 = dsT.variables['vosaline'][time_ind, :z_cut, y_ind, x]
        deptht_cz = dsT.variables['deptht'][:z_cut]

    with nc.Dataset(os.path.join(dirname, '1_mesh_mask.nc'), 'r') as dsM:
        tmask0 = dsM.variables['tmask'][0, :z_cut, y_ind, x]

    tmask_cz = np.tile(tmask0, (1, 1, 1))
    vosaline_cz = np.ma.array(vosaline0, mask=1 - tmask_cz)

    return vosaline_cz, tmask_cz, deptht_cz
def get_sozotaux(dirname, fname):
    filesU = general_functions.get_files(dirname, fname, 'grid_U')
    with scDataset(filesU) as dsU:
        sozotaux = dsU.variables['sozotaux'][:, 0, 0]
    return sozotaux
示例#10
0
        y_start =  164
        y_end =  204
    elif kind == 'real':
        x_start =  180
        x_end =  185
        y_start =  157
        y_end =  197

    # ------------------------------------------------
    
    dirname = '/ocean/imachuca/Canyons/results_mackenzie/extended_domain/'+kind+'_'+case+'/'
    fname = '1_MCKNZ_1h_20170101_201701*'
    meshmaskname = '1_mesh_mask.nc'
    time_end = 6*24
        
    filesW = general_functions.get_files(dirname, fname, 'grid_W')
    
    y,x = slice(y_start, y_end,None), slice(x_start, x_end,None)
    
    with scDataset(filesW) as dsW:
        vovecrtz = dsW.variables['vovecrtz'][:time_end, dep_ind, y, x] * 1000
        
    with nc.Dataset(os.path.join(dirname, meshmaskname), 'r') as dsM:
        gdepw = dsM.variables['gdepw_1d'][0, dep_ind]
        
    return vovecrtz, gdepw

# ---------------------------------------------------------------

def get_varbs_nitrate(kind, case, dep_ind):