本文整理汇总了Python中pygeode.var.Var.name方法的典型用法代码示例。如果您正苦于以下问题:Python Var.name方法的具体用法?Python Var.name怎么用?Python Var.name使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pygeode.var.Var
的用法示例。
在下文中一共展示了Var.name方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: finalize
# 需要导入模块: from pygeode.var import Var [as 别名]
# 或者: from pygeode.var.Var import name [as 别名]
def finalize (var, time, space, eof, eig, pc, variance, weight, out):
from pygeode.var import Var
import numpy as np
# Keep the name
name = var.name
num = eof.shape[0]
# Conform to the proper shape
eof = eof.reshape((num,)+space.shape)
pc = pc.reshape((num,)+time.shape)
# Use a consistent sign convention
# (the first element of the eof is non-negative)
sign = [-1 if eof.reshape(num,-1)[i,0] < 0 else 1 for i in range(num)]
for i,s in enumerate(sign):
eof[i,...] *= s
pc[i,...] *= s
# Copy the data into fresh array
# (that way, if these are view on much larger arrays, the rest of
# the unused data can be garbage collected)
eof = np.array(eof)
pc = np.array(pc)
eig = np.array(eig)
# EOF axis
orderaxis = order(num,name="order")
eof = Var((orderaxis,)+space.axes, values=eof)
eig = Var([orderaxis], values=eig)
pc = Var((orderaxis,)+time.axes, values = pc)
# Undo normalization by area weight?
eof = remove_weights(eof, weight=weight).load()
eof.name = name + "_EOF"
pc.name = name + "_timeseries"
eig.name = name + "_eigenvalues"
# Other things
# Fraction of total variance
frac = ((eig**2) / variance).load()
frac.name = name + "_fraction_of_variance"
# Eigenvalues of the covariance matrix
eig2 = (eig**2).load()
eig2.name = name + "_eigenvalues"
# Gather up all possible outputs
outdict = dict(eof=eof, eig=eig, eig2=eig2, pc=pc, var=variance, frac=frac)
out = whichout(out)
out = [outdict[o] for o in out]
return out
示例2: in
# 需要导入模块: from pygeode.var import Var [as 别名]
# 或者: from pygeode.var.Var import name [as 别名]
for naxes in (1,2):
print("Testing %s dimensions"%naxes)
for shape in product(*([sizes]*naxes)):
print(" Testing shape %s"%str(shape))
np.random.seed(shape)
values = np.random.randn(*shape)
# print "full values:", values
axes = [axis_classes[i](sorted(np.random.randn(n))) for i,n in enumerate(shape)]
for i,axis in enumerate(axes):
axis.name = 'axis%s'%i
# print "axis %s values: %s"%(i,axis.values)
var = Var(axes, values=values)
var.name = 'myvar'
slicelists = [slices[size] for size in shape]
print(" # tests: %d" % len(list(product(*slicelists))))
for sl in product(*slicelists):
print(" Testing slices %s"%repr(sl))
# Trap any known failures here to further diagnose
# assert (count!=4860), "shape: %s, slices: %s, values: %s, axes: %s"%(shape, str(sl), values, [a.values for a in var.axes])
# slice the var immediately (before massaging the slices for numpy)
slicedvar = var.slice[sl]
# Force integer slices to be integer index arrays
# (so numpy doesn't remove any dimensions)
sl = tuple([i] if isinstance(i,int) else i for i in sl)
示例3: SVD
# 需要导入模块: from pygeode.var import Var [as 别名]
# 或者: from pygeode.var.Var import name [as 别名]
def SVD (var1, var2, num=1, subspace=-1, iaxis=Time, weight1=True, weight2=True, matrix='cov'):
"""
Finds coupled EOFs of two fields. Note that the mean/trend/etc. is NOT
removed in this routine.
Parameters
----------
var1, var2 : :class:`Var`
The variables to analyse.
num : integer
The number of EOFs to compute (default is ``1``).
weight1, weight2 : optional
Weights to use for defining orthogonality in the var1, var2 domains,
respectively. Patterns X and Y in the var1 domain are orthogonal if the
sum over X*Y*weights1 is 0. Patterns Z and W in the var2 domain are
orthogonal if the sum over Z*W*weights2 is 0. Default is to use internal
weights defined for var1 accessed by :meth:`Var.getweights()`. If set to
``False`` no weighting is used.
matrix : string, optional ['cov']
Which matrix we are diagonalizing (default is 'cov').
* 'cov': covariance matrix of var1 & var2
* 'cov': correlation matrix of var1 & var2
iaxis : Axis identifier
The principal component / expansion coefficient axis, i.e., the 'time'
axis. Can be an integer (the axis number, leftmost = 0), the axis name
(string), or a Pygeode axis class. If not specified, will try to use
pygeode.timeaxis.Time, and if that fails, the leftmost axis.
Returns
-------
(eof1, pc1, eof2, pc2): tuple
* eof1: The coupled eof patterns for var1.
* pc1: The principal component / expansion coefficients for var1.
* eof2: The coupled eof patterns for var2.
* pc2: The principal component / expansion coefficients for var2.
Notes
-----
Multiple orders of EOFs are concatenated along an 'order' axis.
"""
import numpy as np
from pygeode.timeaxis import Time
from pygeode.var import Var
from pygeode.view import View
from pygeode import MAX_ARRAY_SIZE
from warnings import warn
from pygeode import svdcore as lib
if matrix in ('cov', 'covariance'): matrix = 'cov'
elif matrix in ('cor', 'corr', 'correlation'): matrix = 'cor'
else:
warn ("invalid matrix type '%'. Defaulting to covariance."%matrix, stacklevel=2)
matrix = 'cov'
MAX_ITER = 1000
# Iterate over more EOFs than we need
# (this helps with convergence)
# TODO: a more rigorous formula for the optimum number of EOFs to use
if subspace <= 0: subspace = 2*num + 8
if subspace < num: subspace = num # Just in case
# Remember the names
prefix1 = var1.name+'_' if var1.name != '' else ''
prefix2 = var2.name+'_' if var2.name != '' else ''
# Apply weights?
# if weight1 is not None: var1 *= weight1.sqrt()
# if weight2 is not None: var2 *= weight2.sqrt()
if weight1 is True: weight1 = var1.getweights()
if weight1 is not False:
assert not weight1.hasaxis(iaxis), "Can't handle weights along the record axis"
# Normalize the weights
W = weight1.sum() / weight1.size
weight1 /= W
# Apply the weights
var1 *= weight1.sqrt()
if weight2 is True: weight2 = var2.getweights()
if weight2 is not False:
assert not weight2.hasaxis(iaxis), "Can't handle weights along the record axis"
# Normalize the weights
W = weight2.sum() / weight2.size
weight2 /= W
# Apply the weights
var2 *= weight2.sqrt()
#TODO: allow multiple iteration axes (i.e., time and ensemble)
# if iaxis is None:
# if var1.hasaxis(Time) and var2.hasaxis(Time):
# iaxis1 = var1.whichaxis(Time)
# iaxis2 = var2.whichaxis(Time)
# else:
# iaxis1 = 0
# iaxis2 = 0
# else:
#.........这里部分代码省略.........