コード例 #1
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)
コード例 #2
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)
コード例 #3
0
ファイル: _main_CESM_create.py プロジェクト: LABclimate/MT
    for i in np.arange(850, 1851)
]
# -----------------------------------------------------------------------------
# Dumping paths for variables
# basic path for variables - please choose correct CESMversion, CESMrun above
path_var = '../variables/CESM{}_{}/.'.format(CESMversion, CESMrun)

# ==========================================================================================================================================================
#  Gridding parameters
# ==========================================================================================================================================================
# -----------------------------------------------------------------------------
# alternative paths for local use:
ncdat = utils_misc.loadxvar(path_var + '/any_ncdat', None)  # get ncdata

folder_grid = '/grid'
utils_misc.savexvar(ncdat.REGION_MASK, path_var + folder_grid + '/REGION_MASK',
                    'REGION_MASK')
utils_misc.savexvar(ncdat.TLAT, path_var + folder_grid + '/TLAT', 'TLAT')
utils_misc.savexvar(ncdat.TLONG, path_var + folder_grid + '/TLONG', 'TLONG')
utils_misc.savexvar(ncdat.lat_aux_grid, path_var + folder_grid + '/lat_auxgrd',
                    'lat')
utils_misc.savexvar(ncdat.z_t, path_var + folder_grid + '/zT', 'zT')

# ==========================================================================================================================================================
#  Stack ncdata in time (e.g. BSF, MOC, ...)
# ==========================================================================================================================================================
''' Q: good choice of transport_reg=1 #??
'''
BSF = []
MOC = []
err = []
for idx, fname in enumerate(fnames):
コード例 #4
0
ファイル: _main_CESM_create.py プロジェクト: LABclimate/MT
fnames = ['b40.lm850-1850.1deg.001.pop.h.{:04d}.ann.4.cdf'.format(i) for i in np.arange(850, 1851)]
# -----------------------------------------------------------------------------
# Dumping paths for variables
# basic path for variables - please choose correct CESMversion, CESMrun above
path_var = '../variables/CESM{}_{}/.'.format(CESMversion, CESMrun)


# ==========================================================================================================================================================
#  Gridding parameters
# ==========================================================================================================================================================
# -----------------------------------------------------------------------------
# alternative paths for local use:
ncdat = utils_misc.loadxvar(path_var+'/any_ncdat', None)                        # get ncdata

folder_grid = '/grid'
utils_misc.savexvar(ncdat.REGION_MASK, path_var+folder_grid+'/REGION_MASK', 'REGION_MASK')
utils_misc.savexvar(ncdat.TLAT, path_var+folder_grid+'/TLAT', 'TLAT')
utils_misc.savexvar(ncdat.TLONG, path_var+folder_grid+'/TLONG', 'TLONG')
utils_misc.savexvar(ncdat.lat_aux_grid, path_var+folder_grid+'/lat_auxgrd', 'lat')
utils_misc.savexvar(ncdat.z_t, path_var+folder_grid+'/zT', 'zT')

# ==========================================================================================================================================================
#  Stack ncdata in time (e.g. BSF, MOC, ...)
# ==========================================================================================================================================================
''' Q: good choice of transport_reg=1 #??
'''
BSF = []
MOC = []
err = []
for idx, fname in enumerate(fnames):
    utils_misc.Counter(idx+1, len(fnames), 'modelyears stacked')