コード例 #1
0
ファイル: CESM_utils_dMOC.py プロジェクト: LABclimate/MT
def calc_dMxint_auxgrd(lat_auxgrd, z_auxgrd, vel_comp, M, PD, PD_bins, ncdat, path_vars, savevar=True):
    '''
    Input:
     > lat_auxgrd               : meridional auxillary grid | nparray
     > z_auxgrd                 : vertical auxillary grid | nparray
     > vel_comp         	: either 'W' or 'V' | string
     > M 			: volume transport (MW or MV) | nparray of shape [nz, nlat, nlon]
     > PD                       : potential density | nparray of shape [nz, nlat, nlon]
     > PD_bins                  : borders of PD-bins | nparray of shape [nPDbins+1]
     > ncdat                    : netCDFdata to load REGION_MASK
     > path_vars                : path for saving variables | string
     > savevar 		        : boolean
    Output:
     > dMxint                   : zonally integrated volume transport of shape [nPDbins, nlat] | nparray
    Steps:
     > Todo
    '''
    # a few variables to speed up subsequent loops 
    iter_lat_auxgrd = np.arange(len(lat_auxgrd))
    iter_lat_M = np.arange(M.shape[1])
    iter_dens = np.arange(len(PD_bins)-1)
    # get masks and iteration-indices to speed up subsequent loops (calculate if loading from file fails)
    try: 	mask_auxgrd = utils_misc.loadvar(path_vars+'mask_auxgrd')
    except: 	mask_auxgrd = utils_mask.gen_mask_grd_overlay_lat(lat_auxgrd, ncdat, path_vars)
    try:	iter_maskcombo = utils_misc.loadvar(path_vars+'iter_maskcombo')
    except:     iter_maskcombo = utils_mask.gen_iter_maskcombo(lat_auxgrd, ncdat, mask_auxgrd, path_vars)
    # pre-allocation with zeros
    mask_PD_bins = np.zeros(shape=(len(PD_bins)-1, PD.shape[1]), dtype=object)
    dMxint = np.zeros(shape=mask_PD_bins.shape)
    # zonal integration along auxgrid and conversion on density axis
    print('> zonal integration')
    for n in iter_lat_auxgrd:
      utils_misc.ProgBar('step', step=n, nsteps=len(iter_lat_auxgrd))
      for l in iter_dens:
        for j in iter_lat_M:
          mask_PD_bins[l,j] = np.where( (PD[:,j,:]>PD_bins[l]) and (PD[:,j,:]<PD_bins[l+1]) ) # depth and longitude
          for i in iter_maskcombo[n,j]: # limit zonal integration to Atlantic and grid-overlay
            if i in mask_PD_bins[l,j][1]: # combine both masks: for maskcombo and for densitybinning
              try: dMxint[l,n] = np.nansum([dMxint[l,n], M[mask_PD_bins[l,j][0],j,i]])
              except: pass # just for the cases where M[...] is an empty array, which is not accepted by nansum
    utils_misc.ProgBar('done')

    if vel_comp == 'W':
      if savevar == True: utils_misc.savevar(dMxint, path_vars+'dMWxint_auxgrd')  # save to file
    elif vel_comp == 'V':
      if savevar == True: utils_misc.savevar(dMxint, path_vars+'dMVxint_auxgrd')  # save to file

    return(dMxint)
コード例 #2
0
ファイル: UTILS_misc.py プロジェクト: LABclimate/MT
def LGS(fun_to_get_var, path_to_var, str_varname='__', verbose=True, noload=False, nosave=False, format='nc'):
    ''' 
    Usage:     > LGS(lambda: fun_to_get_var(args), path_to_var)
    '''
    try:
        if noload: raise ValueError()
        if verbose: print(' > trying to load {}\n    from {}...'.format(str_varname, path_to_var))
        if format=='nc':        var = utils_misc.loadxvar(path_to_var, str_varname, verbose=False)
        elif format=='pickle':  var = utils_misc.loadvar(path_to_var, verbose=False)
        if verbose: print(' > success!\n')
    except:
        if noload & verbose: print(' > no load (note that an eventually stored variable will be overwritten)\n > calculating {}...'.format(str_varname))
        elif verbose: print(' > failed to load!\n > calculating {}...'.format(str_varname))
        try: var = fun_to_get_var()
        except: var = fun_to_get_var # as "fun" might simply be any variable (which is uncallable and thus produces an error.)
        if verbose: print(' > success!\n > saving {} to file...'.format(str_varname))
        if format=='nc':        utils_misc.savexvar(var, path_to_var, str_varname, verbose=False)
        elif format=='pickle':  utils_misc.savevar(var, path_to_var, verbose=False)
        if verbose: print(' > success!\n')
    return(var)
コード例 #3
0
def LGS(fun_to_get_var,
        path_to_var,
        str_varname='__',
        verbose=True,
        noload=False,
        nosave=False,
        format='nc'):
    ''' 
    Usage:     > LGS(lambda: fun_to_get_var(args), path_to_var)
    '''
    try:
        if noload: raise ValueError()
        if verbose:
            print(' > trying to load {}\n    from {}...'.format(
                str_varname, path_to_var))
        if format == 'nc':
            var = utils_misc.loadxvar(path_to_var, str_varname, verbose=False)
        elif format == 'pickle':
            var = utils_misc.loadvar(path_to_var, verbose=False)
        if verbose: print(' > success!\n')
    except:
        if noload & verbose:
            print(
                ' > no load (note that an eventually stored variable will be overwritten)\n > calculating {}...'
                .format(str_varname))
        elif verbose:
            print(
                ' > failed to load!\n > calculating {}...'.format(str_varname))
        try:
            var = fun_to_get_var()
        except:
            var = fun_to_get_var  # as "fun" might simply be any variable (which is uncallable and thus produces an error.)
        if verbose:
            print(' > success!\n > saving {} to file...'.format(str_varname))
        if format == 'nc':
            utils_misc.savexvar(var, path_to_var, str_varname, verbose=False)
        elif format == 'pickle':
            utils_misc.savevar(var, path_to_var, verbose=False)
        if verbose: print(' > success!\n')
    return (var)
コード例 #4
0
    for t in np.arange(len(fnames)):
        print t
        try:
            # load netcdf file
            ncdat = xr.open_dataset(fpath + fnames[t], decode_times=False)
            # write streamfunctions to variables (in Sv)
            BSF_mod = utils_time.concat(
                BSF_mod, utils_mask.mask_ATLANTIC(ncdat.BSF,
                                                  ncdat.REGION_MASK))
            MOC_mod = utils_time.concat(
                MOC_mod, ncdat.MOC.isel(transport_reg=1, moc_comp=0))
        except:
            print('ERROR with file ' + fpath + fnames[t] +
                  ' (t = {:d})'.format(t))
    # save to file
    utils_misc.savevar(BSF_mod, path_corr + 'BSF_mod')
    utils_misc.savevar(MOC_mod, path_corr + 'MOC_mod')

# normalisation of AMOC
for t in np.arange(len(MOC_mod)):
    MOC_mod[t, :, :] = MOC_mod[t, :, :] - MOC_mod[t, :, -1]

# #############################################################################
#  ANALYSIS
# #############################################################################
''' check: already cut to Atlantic?'''
# -----------------------------------------------------------------------------
# choose grid representation
MOC = MOC_mod
BSF = BSF_mod
# -----------------------------------------------------------------------------
コード例 #5
0
ファイル: CESM_utils_dMOC.py プロジェクト: LABclimate/MT
def calc_dMOC_auxgrd(lat_auxgrd, dens_auxgrd, vel_comp, dMxint, ncdat, path_vars, do_norm=True, savevar=True):
    '''
    Input:
     > lat_auxgrd               : meridional auxillary grid | nparray
     > dens_auxgrd              : density auxillary grid | nparray
     > vel_comp         	: either 'W' or 'V' | string
     > dMxint                   : zonally integrated volume transport
     > ncdat                    : netCDFdata to load REGION_MASK
     > path_vars                : path for saving variables | string
     > do_norm                  : do normalisation relative to northern boundary | boolean     
     > savevar                  : boolean
    Output:
     > dMOC                     : dMOC of shape [nPDbins, nlat] | nparray
    Steps:
     > calculate dMOC by meridional of dMxint integration along aux grid
     > normalisation relative to northern boundary: at every point substract northernmost value at same depth, 
       such that streamfunction closes at NP.
    '''
    # a few variables to speed up subsequent loops 
    iter_lat_auxgrd = np.arange(len(lat_auxgrd))
    iter_dens_auxgrd = np.arange(len(dens_auxgrd))

    # preallocation of dMOC as np-array
    dMOC = np.copy(dMxint) # start with dMxint, which subsequently will be summed up

    if vel_comp == 'W':
      # meridional integration along aux grid
      print('> meridional integration')
      for n in iter_lat_auxgrd[1:]:
        utils_misc.ProgBar('step', step=n, nsteps=len(iter_lat_auxgrd), forceinit=True, minbarlen=60)
        dMOC[:,n] = np.nansum([dMOC[:,n], dMOC[:,n-1]], axis=0) 	        # meridional integration
      utils_misc.ProgBar('done')

      xrname = 'dMOC on auxillary grid calculated from WVEL'             # name of xarray
      fname = 'dMOC_auxgrd_W'                                            # name for saving

    elif vel_comp == 'V':
      # vertical integration along aux grid
      print('> vertical integration')
      for k in iter_dens_auxgrd[1:]:
        utils_misc.ProgBar('step', step=k, nsteps=len(iter_dens_auxgrd), forceinit=True, minbarlen=60)
        dMOC[k,:] = np.nansum([dMOC[k,:], dMOC[k-1,:]], axis=0) 		# meridional integration
      utils_misc.ProgBar('done')

      xrname = 'dMOC on auxillary grid calculated from VVEL'             # name of xarray
      fname = 'dMOC_auxgrd_V'                                            # name for saving

    '''
    # write to xarray
    dMOC = xr.DataArray(dMOC,
		attrs={'units':u'Sv'},
                coords=[np.arange(len(dens_auxgrd)), np.arange(len(lat_auxgrd))],
		dims=['dens', 'nlat'],
                name=xrname)
    '''
    # normalisation relative to North (shift values such that zero at northern boundary)
    if do_norm == True:
      dMOC = dMOC - dMOC[:,-1]

    # save to file
    if savevar == True:
      utils_misc.savevar(dMOC, path_vars + fname)

    return(dMOC)
コード例 #6
0
ファイル: main_CESM_controls.py プロジェクト: LABclimate/MT
'''
# ---------------------------------------------------------------------------------------
# - Volume transports (in Sv)
MV_mgrd = utils_transp.calc_MV(ncdat)  # on model grid
MV_projauxgrd = utils_conv.project_on_auxgrd(
    MV_mgrd, ncdat.ANGLE.values)  # on auxiliary grid
MW = utils_transp.calc_MW(ncdat)  # valid on both grids

try:
    MW_dens = utils_misc.loadvar(path_dens + 'MW_sig2_' +
                                 varname_binning)  # load from file
except:
    MW_dens = utils_conv.resample_dens_colwise(
        MW.values, sig2, PD_bins
    )  # resampled on density axis #! however, it's still the vertical transport!!
    utils_misc.savevar(MW_dens, path_dens + 'MW_sig2_' +
                       varname_binning)  # save to file

# ---------------------------------------------------------------------------------------
# - Streamfunctions (in Sv)...
# ... on model grid
BSF_mgrd, MVzint = utils_BSF.calc_BSF_mgrd(MV_mgrd, dump_MVzint=True)
MOC_mgrd_W, MWxint_mgrd = utils_MOC.calc_MOC_mgrd('W',
                                                  MW,
                                                  do_norm=True,
                                                  dump_Mxint=True)
#MOC_mgrd_V, MVxint_mgrd = utils_MOC.calc_MOC_mgrd('V', MV_projauxgrd, do_norm=True, dump_Mxint=True)
dMOC_mgrd_W, dMOC_mgrd_W_norm, dMWxint_mgrd = utils_MOC.calc_MOC_mgrd_nparray(
    'W', MW_dens, dump_Mxint=True)

# ... on auxiliary grid
MWxint_auxgrd = utils_MOC.calc_Mxint_auxgrd(lat_auxgrd, z_w_auxgrd, 'W',
コード例 #7
0
ファイル: main_CESM_controls.py プロジェクト: LABclimate/MT
# =======================================================================================
''' BSF: Barotropic Streamfunction
    MOC: Meridional Overturning Circulation Streamfunction
    MW:  vertical volume transport
    MV:  meridional volume transport
'''
# ---------------------------------------------------------------------------------------
# - Volume transports (in Sv)
MV_mgrd = utils_transp.calc_MV(ncdat)                                           # on model grid
MV_projauxgrd = utils_conv.project_on_auxgrd(MV_mgrd, ncdat.ANGLE.values)       # on auxiliary grid
MW = utils_transp.calc_MW(ncdat)                                                # valid on both grids

try:    MW_dens = utils_misc.loadvar(path_dens+'MW_sig2_'+varname_binning)      # load from file
except:
    MW_dens = utils_conv.resample_dens_colwise(MW.values, sig2, PD_bins)         # resampled on density axis #! however, it's still the vertical transport!!
    utils_misc.savevar(MW_dens, path_dens+'MW_sig2_'+varname_binning)           # save to file

# ---------------------------------------------------------------------------------------
# - Streamfunctions (in Sv)...
# ... on model grid
BSF_mgrd, MVzint = utils_BSF.calc_BSF_mgrd(MV_mgrd, dump_MVzint=True)
MOC_mgrd_W, MWxint_mgrd = utils_MOC.calc_MOC_mgrd('W', MW, do_norm=True, dump_Mxint=True)
 #MOC_mgrd_V, MVxint_mgrd = utils_MOC.calc_MOC_mgrd('V', MV_projauxgrd, do_norm=True, dump_Mxint=True)
dMOC_mgrd_W, dMOC_mgrd_W_norm, dMWxint_mgrd = utils_MOC.calc_MOC_mgrd_nparray('W', MW_dens, dump_Mxint=True)

# ... on auxiliary grid
MWxint_auxgrd = utils_MOC.calc_Mxint_auxgrd(lat_auxgrd, z_w_auxgrd, 'W', MW.values, ncdat, path_auxgrd)
MOC_auxgrd_W, MOC_auxgrd_W_norm = utils_MOC.calc_MOC_auxgrd(lat_auxgrd, z_w_auxgrd, 'W', MWxint_auxgrd, 'forward', path_auxgrd)
 #MVxint_auxgrd = utils_MOC.calc_Mxint_auxgrd(lat_auxgrd, zT_auxgrd, 'V', MV_projauxgrd.values, ncdat, path_auxgrd)
 #MOC_auxgrd_V, MOC_auxgrd_V_norm = utils_MOC.calc_MOC_auxgrd(lat_auxgrd, zT_auxgrd, 'V', MVxint_auxgrd, path_auxgrd)
dMWxint_auxgrd = utils_MOC.calc_Mxint_auxgrd(lat_auxgrd, PD_bins, 'dW', MW_dens, ncdat, path_auxgrd)
コード例 #8
0
# =======================================================================================
#  Streamfunctions
# =======================================================================================
# ---------------------------------------------------------------------------------------
# - Volume transports (in Sv)
MW_mgrd = utils_transp.calc_MW(ncdat)                                           # on model grid
MV_mgrd = utils_transp.calc_MV(ncdat)                                          # on model grid
#MV_projauxgrd = utils_conv.project_on_auxgrd(MV_mgrd, ncdat.ANGLE.values)      # projected on auxiliary grid (same shape as on model grid)

# - conversion on density axis
#try:    dMW = utils_misc.loadvar(path_dens+fname_MWdens)                    # load from file
#except:
#print(' > loading failed!')
# resampled MW_mgrd on centre of T grid
MW_z_t = utils_conv.resample_colwise(MW_mgrd.values, MW_mgrd.z_w_top.values, ncdat.z_t.values, method='lin', mask = ATLboolmask, mono_method='sort')
utils_misc.savevar(MW_z_t, path_dens+fname_MWzt)                           # save to file
# resampled MW_mgrd on density axis (still pointing in vertical direction)
dMW = utils_conv.resample_colwise(MW_z_t, ncdat.z_t.values, zdb, method='dMW_zdb', fill_value=np.nan, mask = ATLboolmask, mono_method='force')
#dMW = utils_conv.resample_colwise(MW_z_t, sig2, db, method='dMW_db', fill_value=np.nan, mask = ATLboolmask, mono_method='force')

utils_misc.savevar(dMW, path_dens+fname_MWdens)                         # save to file

# ---------------------------------------------------------------------------------------
# - Streamfunctions (in Sv)...

BSF_mgrd, MVzint = utils_BSF.calc_BSF_mgrd(MV_mgrd, dump_MVzint=True)

MOC_mgrd_W, MWxint_mgrd = utils_MOC.calc_MOC_mgrd('W', MW_mgrd, do_norm=True, dump_Mxint=True)
MWxint_auxgrd = utils_MOC.calc_Mxint_auxgrd(lat_auxgrd, z_w_auxgrd, 'W', MW_mgrd.values, ncdat, path_auxgrd)
MOC_auxgrd_W, MOC_auxgrd_W_norm = utils_MOC.calc_MOC_auxgrd(lat_auxgrd, z_w_auxgrd, 'W', MWxint_auxgrd, 'forward', path_auxgrd)
コード例 #9
0
ファイル: PREP_dMOC.py プロジェクト: LABclimate/MT
    dMVfc       = utils_ana.nancumsum(dMVf*dzDBc, axis=0) #! changed dDB to dzDBc
    dMVfcp      = utils_conv.project_on_auxgrd(dMVfc, ncdat.ANGLE.values)
    dMOC        = np.nansum(dMVfcp, axis=-1)
    '''

    dMVf        = utils_conv.resample_colwise(MVf, sig2U, DBc, method='dMV', fill_value=np.nan, mask = ATLboolmask, mono_method='force')
    dDB3d       = utils_conv.exp_k_to_kji(dDB, dMVf.shape[-2], dMVf.shape[-1])
    dMVfc       = utils_ana.nancumsum(dMVf*dDB3d, axis=0)
    dMVfcp      = utils_conv.project_on_auxgrd(dMVfc, ncdat.ANGLE.values)
    dMOC        = np.nansum(dMVfcp, axis=-1)

# -----------------------------------------------------------------------------
# PART III // SAVE SOME VARIABLES
# -----------------------------------------------------------------------------
    # Note: the part [:-4] removes ".cdf"

    # create folder with choice of densitybinning
    utils_misc.mkdir(dir_vars)

    utils_misc.savevar(sig2T, dir_vars+'sig2T_'+fnames[ii][:-4], 'sig2T')
    utils_misc.savevar(sig2U, dir_vars+'sig2U_'+fnames[ii][:-4])
    
    #utils_misc.savevar(zDBc, dir_vars+'zDBc_'+fnames[ii][:-4], 'zDBc')
    #utils_misc.savevar(zDBb, dir_vars+'zDBb_'+fnames[ii][:-4], 'zDBb')
    #utils_misc.savevar(zDBbc, dir_vars+'zDBbc_'+fnames[ii][:-4], 'zDBbc')
    utils_misc.savevar(dMOC, dir_vars+'dMOC_'+fnames[ii][:-4], 'dMOC')

# -----------------------------------------------------------------------------
# CLOSE NC-FILE
# -----------------------------------------------------------------------------
    ncdat.close()
コード例 #10
0
ファイル: CESM_utils_dMOC.py プロジェクト: LABclimate/MT
def calc_dMxint_auxgrd(lat_auxgrd,
                       z_auxgrd,
                       vel_comp,
                       M,
                       PD,
                       PD_bins,
                       ncdat,
                       path_vars,
                       savevar=True):
    '''
    Input:
     > lat_auxgrd               : meridional auxillary grid | nparray
     > z_auxgrd                 : vertical auxillary grid | nparray
     > vel_comp         	: either 'W' or 'V' | string
     > M 			: volume transport (MW or MV) | nparray of shape [nz, nlat, nlon]
     > PD                       : potential density | nparray of shape [nz, nlat, nlon]
     > PD_bins                  : borders of PD-bins | nparray of shape [nPDbins+1]
     > ncdat                    : netCDFdata to load REGION_MASK
     > path_vars                : path for saving variables | string
     > savevar 		        : boolean
    Output:
     > dMxint                   : zonally integrated volume transport of shape [nPDbins, nlat] | nparray
    Steps:
     > Todo
    '''
    # a few variables to speed up subsequent loops
    iter_lat_auxgrd = np.arange(len(lat_auxgrd))
    iter_lat_M = np.arange(M.shape[1])
    iter_dens = np.arange(len(PD_bins) - 1)
    # get masks and iteration-indices to speed up subsequent loops (calculate if loading from file fails)
    try:
        mask_auxgrd = utils_misc.loadvar(path_vars + 'mask_auxgrd')
    except:
        mask_auxgrd = utils_mask.gen_mask_grd_overlay_lat(
            lat_auxgrd, ncdat, path_vars)
    try:
        iter_maskcombo = utils_misc.loadvar(path_vars + 'iter_maskcombo')
    except:
        iter_maskcombo = utils_mask.gen_iter_maskcombo(lat_auxgrd, ncdat,
                                                       mask_auxgrd, path_vars)
    # pre-allocation with zeros
    mask_PD_bins = np.zeros(shape=(len(PD_bins) - 1, PD.shape[1]),
                            dtype=object)
    dMxint = np.zeros(shape=mask_PD_bins.shape)
    # zonal integration along auxgrid and conversion on density axis
    print('> zonal integration')
    for n in iter_lat_auxgrd:
        utils_misc.ProgBar('step', step=n, nsteps=len(iter_lat_auxgrd))
        for l in iter_dens:
            for j in iter_lat_M:
                mask_PD_bins[l, j] = np.where(
                    (PD[:, j, :] > PD_bins[l])
                    and (PD[:, j, :] < PD_bins[l + 1]))  # depth and longitude
                for i in iter_maskcombo[
                        n,
                        j]:  # limit zonal integration to Atlantic and grid-overlay
                    if i in mask_PD_bins[l, j][
                            1]:  # combine both masks: for maskcombo and for densitybinning
                        try:
                            dMxint[l, n] = np.nansum(
                                [dMxint[l, n], M[mask_PD_bins[l, j][0], j, i]])
                        except:
                            pass  # just for the cases where M[...] is an empty array, which is not accepted by nansum
    utils_misc.ProgBar('done')

    if vel_comp == 'W':
        if savevar == True:
            utils_misc.savevar(dMxint,
                               path_vars + 'dMWxint_auxgrd')  # save to file
    elif vel_comp == 'V':
        if savevar == True:
            utils_misc.savevar(dMxint,
                               path_vars + 'dMVxint_auxgrd')  # save to file

    return (dMxint)
コード例 #11
0
ファイル: CESM_utils_dMOC.py プロジェクト: LABclimate/MT
def calc_dMOC_auxgrd(lat_auxgrd,
                     dens_auxgrd,
                     vel_comp,
                     dMxint,
                     ncdat,
                     path_vars,
                     do_norm=True,
                     savevar=True):
    '''
    Input:
     > lat_auxgrd               : meridional auxillary grid | nparray
     > dens_auxgrd              : density auxillary grid | nparray
     > vel_comp         	: either 'W' or 'V' | string
     > dMxint                   : zonally integrated volume transport
     > ncdat                    : netCDFdata to load REGION_MASK
     > path_vars                : path for saving variables | string
     > do_norm                  : do normalisation relative to northern boundary | boolean     
     > savevar                  : boolean
    Output:
     > dMOC                     : dMOC of shape [nPDbins, nlat] | nparray
    Steps:
     > calculate dMOC by meridional of dMxint integration along aux grid
     > normalisation relative to northern boundary: at every point substract northernmost value at same depth, 
       such that streamfunction closes at NP.
    '''
    # a few variables to speed up subsequent loops
    iter_lat_auxgrd = np.arange(len(lat_auxgrd))
    iter_dens_auxgrd = np.arange(len(dens_auxgrd))

    # preallocation of dMOC as np-array
    dMOC = np.copy(
        dMxint)  # start with dMxint, which subsequently will be summed up

    if vel_comp == 'W':
        # meridional integration along aux grid
        print('> meridional integration')
        for n in iter_lat_auxgrd[1:]:
            utils_misc.ProgBar('step',
                               step=n,
                               nsteps=len(iter_lat_auxgrd),
                               forceinit=True,
                               minbarlen=60)
            dMOC[:, n] = np.nansum([dMOC[:, n], dMOC[:, n - 1]],
                                   axis=0)  # meridional integration
        utils_misc.ProgBar('done')

        xrname = 'dMOC on auxillary grid calculated from WVEL'  # name of xarray
        fname = 'dMOC_auxgrd_W'  # name for saving

    elif vel_comp == 'V':
        # vertical integration along aux grid
        print('> vertical integration')
        for k in iter_dens_auxgrd[1:]:
            utils_misc.ProgBar('step',
                               step=k,
                               nsteps=len(iter_dens_auxgrd),
                               forceinit=True,
                               minbarlen=60)
            dMOC[k, :] = np.nansum([dMOC[k, :], dMOC[k - 1, :]],
                                   axis=0)  # meridional integration
        utils_misc.ProgBar('done')

        xrname = 'dMOC on auxillary grid calculated from VVEL'  # name of xarray
        fname = 'dMOC_auxgrd_V'  # name for saving
    '''
    # write to xarray
    dMOC = xr.DataArray(dMOC,
		attrs={'units':u'Sv'},
                coords=[np.arange(len(dens_auxgrd)), np.arange(len(lat_auxgrd))],
		dims=['dens', 'nlat'],
                name=xrname)
    '''
    # normalisation relative to North (shift values such that zero at northern boundary)
    if do_norm == True:
        dMOC = dMOC - dMOC[:, -1]

    # save to file
    if savevar == True:
        utils_misc.savevar(dMOC, path_vars + fname)

    return (dMOC)
コード例 #12
0
    CT = gsw.CT_from_pt(SA, PT)                 # conservative temperature
    sig2 = gsw.sigma2(SA, CT)                   # potential density anomaly referenced to 2000dbar
    
    # - conversion T-->U
    densU = np.zeros_like(sig2)
    foo1 = utils_ana.canonical_cumsum(sig2, 2, axis=-1)
    densU[:,:-1,:-1] = .25*utils_ana.canonical_cumsum(foo1, 2, axis=-2)
    densU[:,-1,:-1] = .5*utils_ana.canonical_cumsum(sig2, 2, axis=-1)[:,-1,:]
    densU[:,:-1,-1] = .5*utils_ana.canonical_cumsum(sig2, 2, axis=-2)[:,:,-1]
    densU[:,-1,-1] = sig2[:,-1,-1]
    
    # density bins:  border-values (=dbb), center-values (=dbc) and thickness (=ddb)
    dbb = np.concatenate((np.linspace(dbsetup[0,0],dbsetup[0,1],dbsetup[0,2]), np.linspace(dbsetup[1,0],dbsetup[1,1],dbsetup[1,2]), np.linspace(dbsetup[2,0],dbsetup[2,1],dbsetup[2,2]), np.linspace(dbsetup[3,0],dbsetup[3,1],dbsetup[3,2]), np.linspace(dbsetup[4,0],dbsetup[4,1],dbsetup[4,2])))
    dbc = np.convolve(dbb, np.array([.5,.5]))[1:-1]
    
    # depth of isopycnals (zdbbc) calculated as z(dbc) (=zdbc) and as c(zdbb) (=zdbbc)
    z_t_3d = utils_conv.exp_k_to_kji(ncdat.z_t, densU.shape[-2], densU.shape[-1])
    zdbc = utils_conv.resample_colwise(z_t_3d, densU, dbc, 'lin', fill_value=np.nan, mask = ATLboolmask, mono_method='sort')
    zdbb = utils_conv.resample_colwise(z_t_3d, densU, dbb, 'lin', fill_value=np.nan, mask = ATLboolmask, mono_method='sort')
    zdbbc = np.ones_like(zdbc) * np.nan
    for j in np.arange(zdbb.shape[-2]):
        for i in np.arange(zdbb.shape[-1]):
            zdbbc[:,j,i] = np.convolve(zdbb[:,j,i], np.array([.5,.5]))[1:-1] # centre-values
    
    # save variables
    utils_misc.savevar(sig2, path_sig2)
    utils_misc.savevar(densU, path_densU)
    utils_misc.savevar(zdbc, path_zdbc)
    utils_misc.savevar(zdbb, path_zdbb)
    utils_misc.savevar(zdbbc, path_zdbbc)
コード例 #13
0
                                       sig2U,
                                       DBc,
                                       method='dMV',
                                       fill_value=np.nan,
                                       mask=ATLboolmask,
                                       mono_method='force')
    dDB3d = utils_conv.exp_k_to_kji(dDB, dMVf.shape[-2], dMVf.shape[-1])
    dMVfc = utils_ana.nancumsum(dMVf * dDB3d, axis=0)
    dMVfcp = utils_conv.project_on_auxgrd(dMVfc, ncdat.ANGLE.values)
    dMOC = np.nansum(dMVfcp, axis=-1)

    # -----------------------------------------------------------------------------
    # PART III // SAVE SOME VARIABLES
    # -----------------------------------------------------------------------------
    # Note: the part [:-4] removes ".cdf"

    # create folder with choice of densitybinning
    utils_misc.mkdir(dir_vars)

    utils_misc.savevar(sig2T, dir_vars + 'sig2T_' + fnames[ii][:-4], 'sig2T')
    utils_misc.savevar(sig2U, dir_vars + 'sig2U_' + fnames[ii][:-4])

    #utils_misc.savevar(zDBc, dir_vars+'zDBc_'+fnames[ii][:-4], 'zDBc')
    #utils_misc.savevar(zDBb, dir_vars+'zDBb_'+fnames[ii][:-4], 'zDBb')
    #utils_misc.savevar(zDBbc, dir_vars+'zDBbc_'+fnames[ii][:-4], 'zDBbc')
    utils_misc.savevar(dMOC, dir_vars + 'dMOC_' + fnames[ii][:-4], 'dMOC')

    # -----------------------------------------------------------------------------
    # CLOSE NC-FILE
    # -----------------------------------------------------------------------------
    ncdat.close()
コード例 #14
0
    MOC_mod = utils_misc.loadvar(path_corr+'MOC_mod') 
except:
    BSF_mod = []
    MOC_mod = []
    for t in np.arange(len(fnames)):
        print t
        try:
            # load netcdf file
            ncdat = xr.open_dataset(fpath+fnames[t], decode_times=False)
            # write streamfunctions to variables (in Sv)
            BSF_mod = utils_time.concat(BSF_mod, utils_mask.mask_ATLANTIC(ncdat.BSF, ncdat.REGION_MASK))
            MOC_mod = utils_time.concat(MOC_mod, ncdat.MOC.isel(transport_reg=1, moc_comp=0))
        except:
            print('ERROR with file ' + fpath+fnames[t] + ' (t = {:d})'.format(t))
    # save to file
    utils_misc.savevar(BSF_mod, path_corr+'BSF_mod')
    utils_misc.savevar(MOC_mod, path_corr+'MOC_mod')
    
# normalisation of AMOC
for t in np.arange(len(MOC_mod)):
    MOC_mod[t,:,:] = MOC_mod[t,:,:] - MOC_mod[t,:,-1]