• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python var.Var类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中pygeode.var.Var的典型用法代码示例。如果您正苦于以下问题:Python Var类的具体用法?Python Var怎么用?Python Var使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Var类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: __init__

  def __init__ (self, var, axis, n):
  # {{{
    ''' __init__()'''

    from pygeode.var import Var

    df = 'right'  # Hard-coded to match numpy behaviour.
                  # May be extended in the future?

    self.daxis = daxis = var.whichaxis(axis)
    assert var.shape[daxis] > n, "need at least %d value(s) along difference axis"%n

    self.n = n
    self.df = df
    self.var = var

    # Construct new variable

    if var.name != '':
      name = 'd' + var.name
    else:
      name = 'd(UnknownVar)'

    axes = list(var.axes)
    if df == 'left':
      axes[daxis] = axes[daxis].slice[n:]
    else:
      axes[daxis] = axes[daxis].slice[:-n]

    Var.__init__(self, axes, var.dtype, name=name, atts=var.atts, plotatts=var.plotatts)
开发者ID:neishm,项目名称:pygeode,代码行数:30,代码来源:diff.py


示例2: __init__

  def __init__ (self, var, saxis, kernel, fft):
  # {{{
    ''' __init__()'''
    import numpy as np

    assert len(kernel) <= var.shape[saxis], 'Kernel must not be longer than dimension being smoothed.'

    # Construct new variable
    self.saxis = saxis
    self.var = var
    self.kernel = kernel
    self.fft = fft
    self.klen = len(kernel)

    # Normalize and reshape kernel
    self.kernel /= np.sum(self.kernel)
    self.kernel.shape = [self.klen if i == saxis else 1 for i in range(var.naxes)]

    # Determine which convolution function to use
    from scipy import signal as sg
    tdata = np.ones(len(kernel), 'd')
    if self.fft:
      try:
        sg.fftconvolve(tdata, kernel, 'same', old_behaviour=False)
        self._convolve = lambda x, y, z: sg.fftconvolve(x, y, z, old_behaviour=False)
      except TypeError:
        self._convolve = sg.fftconvolve
    else:
      try:
        sg.convolve(tdata, kernel, 'same', old_behaviour=False)
        self._convolve = lambda x, y, z: sg.convolve(x, y, z, old_behaviour=False)
      except TypeError:
        self._convolve = sg.convolve

    Var.__init__(self, var.axes, var.dtype, name=var.name, atts=var.atts, plotatts=var.plotatts)
开发者ID:neishm,项目名称:pygeode,代码行数:35,代码来源:smooth.py


示例3: __init__

  def __init__ (self, var, daxis, dx=None, df='centre'):
  # {{{
    ''' __init__()'''

    from pygeode.var import Var

    self.daxis = daxis = var.whichaxis(daxis)
    assert var.shape[daxis] > 1, "need at least two values along differentiation axis"

    if dx is not None:
      if dx.naxes == 1:
        assert dx.shape[0] == var.shape[daxis]
        self.dx = dx.replace_axes(newaxes=(var.axes[daxis],))
      else:
        assert all([dx.hasaxis(a) for a in var.axes])
        self.dx = dx
    else:
      self.dx = var.axes[daxis]

    assert df in ['centre', 'left', 'right']
    self.df = df

    self.var = var

    # Construct new variable

    if var.name != '':
      name = 'd' + var.name
    else:
      name = 'd(UnknownVar)'

    Var.__init__(self, var.axes, var.dtype, name=name, atts=var.atts, plotatts=var.plotatts)
开发者ID:aerler,项目名称:pygeode,代码行数:32,代码来源:deriv.py


示例4: __init__

  def __init__(self, var, axisdict={}, ignore_mismatch=False, newaxes=None, keep_old_name=True, **kwargs):
    from pygeode.var import Var, copy_meta
    from inspect import isclass
    axisdict = dict(axisdict, **kwargs)
    if newaxes is None:
      newaxes = list(var.axes)
    else:
      assert len(newaxes) == var.naxes, "wrong number of axes provided"

    for a,newa in axisdict.items():
      if not var.hasaxis(a) and ignore_mismatch: continue
      i = var.whichaxis(a)
      olda = var.axes[i]
      # Keep the old axis name?
      name = olda.name if keep_old_name else newa.name
      # Convert axis class to axis object, using the existing values?
      if isclass(newa):
        # Cram in any 'auxiliary' attributes, in case they're needed by the new class.
        # (Needed if, say, converting from StandardTime to ModelTime365)
        # Note: even if these attributes aren't pick up by the new init,
        # they'll get stored in the 'auxatts' field and stay there as benign,
        # unused values.  Ideally, if we knew ahead of time what attributes are
        # needed, we could pass only *those* attributes to the new class...
        newa = newa(olda.values, name=name, **olda.auxatts)
      # Use this new axis
      newaxes[i] = newa
    for a1, a2 in zip(newaxes, var.axes): assert len(a1) == len(a2)
    self.var = var
    Var.__init__(self, newaxes, dtype=var.dtype)
    copy_meta (var, self)
开发者ID:neishm,项目名称:pygeode,代码行数:30,代码来源:varoperations.py


示例5: __init__

 def __init__(self, u, v, perix=True, name=None, atts=None, plotatts=None):
   '''
     relativeVorticity(u, v, perix=True, name=None, atts=None, plotatts=None)
   '''
   from pygeode.axis import Lat, Lon
   from pygeode.atmdyn.constants import Re       
   ## check axes
   # order: latitude and longitude have to be the last two
   assert u.whichaxis(Lat)==u.naxes-2 and u.whichaxis(Lon)==u.naxes-1, 'Unsupported axes order.'
   # homogeneity
   assert u.axes==v.axes, 'Axes are incompatible!'            
   # handle meta data
   if name is None: name = 'ze'
   # parameter (set defaults, if not present)
   defatts = {'name': 'zeta', 'units': r'$s^{-1}$', 'long_name': 'Relative Vorticity (vertical)', 
              'standard_name': 'Relative Vorticity', 'Re': Re, 'perix':perix}      
   if atts: defatts.update(atts)
   # plot parameter
   defplot = variablePlotatts['ze'] 
   if plotatts: defplot.update(plotatts)
   # make proper Var-instance
   Var.__init__(self, axes=u.axes, dtype=u.dtype, name=name, values=None, atts=defatts, plotatts=defplot)
   # save variables and parameters
   self.perix = perix
   self.u = u; self.v = v
   self.lon = u.getaxis(Lon); self.lat = u.getaxis(Lat)
   self.Re = self.atts['Re']
开发者ID:aerler,项目名称:GeoPy,代码行数:27,代码来源:f2pyVar.py


示例6: clim_detrend

def clim_detrend(var, yrlen, itime = -1, sig=False):
# {{{
  ''' clim_detrend() - returns detrended time series with a daily trend.'''
  from pygeode.timeaxis import Time
  from . import stats
  from numpy import arange
  if itime == -1: itime = var.whichaxis(Time) 
  tlen = var.shape[itime]
  
  vary = composite(var, itime, list(range(0, tlen, yrlen)), yrlen)
  yrs = vary.axes[itime]
  yrs.values=arange(len(yrs)).astype(yrs.dtype)

  print('Computing regression')
  from pygeode.progress import PBar
  m, b, p = stats.regress(yrs, vary, pbar=PBar())
  varz = flatten(vary - (m*yrs + b), itime + 1)

  varz.axes = var.axes

  # Since the axes have been modified after initialization, redo the init to get
  # shortcuts to the axes names
  Var.__init__(varz, varz.axes, varz.dtype)

  if var.name != '':
    varz.name = var.name+"'"

  if sig:
    return m, b, varz, p
  else:
    return m, b, varz
开发者ID:neishm,项目名称:pygeode,代码行数:31,代码来源:composite.py


示例7: __init__

  def __init__ (self, v1, opener, files, faxis, timedict):
# {{{
    # v1 - var chunk from the first file
    # opener - method for opening a file given a filename
    # files - list of filenames
    # faxis - starting time of each file, as a time axis
    # timedict - dictionary of pre-constructed time axes
    from pygeode.var import Var
    from pygeode.timeaxis import Time

    self.opener = opener
    self.files = files
    self.faxis = faxis

    n = v1.getaxis(Time).name if v1.hasaxis(Time) else None
    taxis = timedict[n]
    T = type(taxis)

    axes = list(v1.axes)

    # Replace the existing time axis?
    # (look for either a Time axis or a generic axis with the name 'time')
    if v1.hasaxis(T): axes[v1.whichaxis(T)] = taxis
    elif v1.hasaxis('time'): axes[v1.whichaxis('time')] = taxis
    else: axes = [taxis] + axes

    Var.__init__ (self, axes, dtype=v1.dtype, name=v1.name, atts=v1.atts, plotatts=v1.plotatts)
开发者ID:aerler,项目名称:pygeode,代码行数:27,代码来源:multifile.py


示例8: __init__

  def __init__ (self, var, indices):
  # {{{
    from pygeode.var import Var
    import numpy as np
    from pygeode.tools import combine_axes, common_dtype
    # Are we given a list of variables to work on in parallel?
    if isinstance(var,(tuple,list)):
      axes = combine_axes(var)
      dtype = common_dtype(var)
    else:
      axes = var.axes
      dtype = var.dtype

#    if not isinstance(indices,(list,tuple)): indices = [indices]
    indices = np.sort([var.whichaxis(i) for i in indices])
    assert len(indices) > 0, "no reduction axes specified"

    N = [len(axes[i]) for i in indices]
    # Check for degenerate reductions (ill-defined)
    for i,n in enumerate(N):
      if n == 0:  raise ValueError("Can't do a reduction over axis '%s' - length is 0."%axes[i].name)
    N = int(np.product(N))
    self.N =  N # number of values to reduce over
    self.var = var
    self.indices = indices

    self.in_axes = axes

    # Remove the reduction axis from the output variable
    axes = [a for i,a in enumerate(axes) if i not in indices]

    Var.__init__(self, axes, dtype=dtype, name=var.name, atts=var.atts, plotatts=var.plotatts)
开发者ID:aerler,项目名称:pygeode,代码行数:32,代码来源:reduce.py


示例9: __init__

  def __init__ (self, var, inner = -1, naxis=None):
  #{{{
    from numpy import concatenate
    if inner == -1:
      if isinstance(var, CompositeVar):
         out = var.whichaxis(var.event.__class__)
         inner = var.whichaxis(var.offset.__class__)
         stride = len(var.axes[inner])
         vals = concatenate([e + var.axes[inner].values for e in var.axes[out].values])
      else:
         raise NotImplementedError("You must specify which axis to flatten")
    elif inner == 0: raise NotImplementedError("inner axis must not be the outermost")
    else:
      out = inner - 1
      stride = len(var.axes[inner])
      vals = concatenate([i*stride + var.axes[inner].values for i in range(len(var.axes[out]))])
    
    if naxis is None:
      if isinstance(var.axes[out], NamedAxis):
        naxis = var.axes[out].__class__(vals, var.axes[out].name)
      else:
        naxis = var.axes[out].__class__(vals)
    axes = var.axes[:out] + (naxis,) + var.axes[inner+1:]
    self.iout = out
    self.iin = inner
    self.stride = stride
    self.source_var = var
   
    self.name = var.name

    Var.__init__(self, axes, var.dtype)
开发者ID:neishm,项目名称:pygeode,代码行数:31,代码来源:composite.py


示例10: __init__

  def __init__(self, f, varid):
  # {{{
    from pygeode.var import Var
    from ctypes import c_int, byref, create_string_buffer
    from warnings import warn

    self._f = f
    self._varid = varid

    assert f.fileid.value != -1

    name = create_string_buffer(NC_MAX_NAME+1)
    vtype = c_int()
    ndims = c_int()
    dimids = (c_int * NC_MAX_VAR_DIMS)()
    natts = c_int()
    ier = lib.nc_inq_var (f.fileid, varid, name, byref(vtype), byref(ndims), dimids, byref(natts))
    assert ier == 0

    self._vtype  = vtype = vtype.value
    dtype = numpy_type[vtype]
    self._dimids = dimids = [dimids[j] for j in range(ndims.value)]
    name = str(name.value.decode())

    # Load attributes
    atts = get_attributes (f.fileid, varid)

    # Axes (just generic dimensions right now, until some filter is applied)
    axes = [makedim(f,d) for d in dimids]

    Var.__init__(self, axes, name=name, dtype=dtype, atts=atts)
开发者ID:neishm,项目名称:pygeode,代码行数:31,代码来源:netcdf.py


示例11: __init__

  def __init__(self, sd, axes):
    self.sd = sd
    self.name = sd.name
    #  attributes
    atts = get_attributes (sd.sds_id, sd.natts)
#    if len(atts) > 0: self.atts = atts
#    else: atts = None
    Var.__init__(self, axes, numpy_type[sd.type], atts=atts)
开发者ID:neishm,项目名称:pygeode,代码行数:8,代码来源:hdf4.py


示例12: __init__

 def __init__(self, var, saxis, maxharm):
 # {{{
   ''' __init__()'''
   # Construct new variable
   self.saxis = saxis
   self.var = var
   self.maxharm = maxharm
   Var.__init__(self, var.axes, var.dtype, name=var.name, atts=var.atts, plotatts=var.plotatts)
开发者ID:aerler,项目名称:pygeode,代码行数:8,代码来源:fft_smooth.py


示例13: __init__

 def __init__ (self, invar, iaxis, reverse=False):
   from pygeode.var import Var
   self.var = invar
   iaxis = invar.whichaxis(iaxis)
   axes = list(invar.axes)
   oldaxis = axes[iaxis]
   newaxis = oldaxis.sorted(reverse=reverse)
   axes[iaxis] = newaxis
   Var.__init__(self, axes, dtype=invar.dtype, name=invar.name, atts=invar.atts, plotatts=invar.plotatts)
开发者ID:neishm,项目名称:pygeode,代码行数:9,代码来源:interp.py


示例14: __init__

 def __init__ (self, name, arr):
   from pygeode.var import Var
   from pygeode.axis import NamedAxis
   self._arr = arr
   # Extract axes and metadata.
   # Convert unicode strings to str for compatibility with PyGeode.
   axes = [NamedAxis(n,str(d)) for n,d in zip(arr.shape,arr.dims)]
   atts = _fix_atts(arr.attrs)
   Var.__init__(self, axes, name=str(name), dtype=arr.dtype, atts=atts)
开发者ID:neishm,项目名称:pygeode,代码行数:9,代码来源:ext_xarray.py


示例15: __init__

 def __init__ (self, *coefs):
   from pygeode.axis import Coef
   from pygeode.var import Var
   assert len(set(c.shape for c in coefs)) == 1
   #TODO: more checks?
   axes = list(coefs[0].axes)
   axes.append(Coef(len(coefs)))
   self.coefs = coefs
   Var.__init__(self, axes, coefs[0].dtype)
开发者ID:neishm,项目名称:pygeode,代码行数:9,代码来源:tools.py


示例16: __init__

  def __init__(self, varlist):
    from pygeode.var import Var, combine_meta
    self.varlist = varlist
    # assume the vars have already been checked for consistency
    var0 = varlist[0]
    axes = list(var0.axes)
#    axes = [Ensemble(len(varlist))] + axes
    axes = [make_ensemble(len(varlist))] + axes
    Var.__init__(self, axes, dtype=var0.dtype)
#    copy_meta (var0, self)
#    self.atts = common_dict(var.atts for var in varlist)
#    self.plotatts = common_dict(var.plotatts for var in varlist)
    combine_meta (varlist, self)
    self.name = varlist[0].name
开发者ID:aerler,项目名称:pygeode,代码行数:14,代码来源:ensemble.py


示例17: __init__

  def __init__ (self, var):
    from pygeode.var import Var
    from pygeode.timeaxis import CalendarTime
    self.ti  = ti = var.whichaxis(CalendarTime)
    intime = var.axes[ti]
    outtime = self.get_outtime(intime)
    # Fudge the input axis?  (endow it with extra information that it normally wouldn't have?)
    new_intime = self.get_intime(intime)
    if new_intime is not intime: var = var.replace_axes({CalendarTime:new_intime})

    if var.name != '': self.name = var.name + self.name_suffix1 + self.name_suffix2

    self.var = var

    axes = list(var.axes)
    axes[ti] = outtime
    Var.__init__ (self, axes+list(self.extra_dims), dtype = var.dtype)
开发者ID:aerler,项目名称:pygeode,代码行数:17,代码来源:climat.py


示例18: clim_anoms

def clim_anoms(var, yrlen, itime = -1):
# {{{
  ''' clim_anoms() - quick and dirty implementation; 
        returns climatology and anomalies of given variable.'''
  from pygeode.timeaxis import Time
  if itime == -1: itime = var.whichaxis(Time) 
  tlen = (var.shape[itime] // yrlen) * yrlen
  vary = composite(var, itime, list(range(0, tlen, yrlen)), yrlen)
  varc = vary.mean(itime).load()
  varz = flatten(vary - varc, itime + 1)
  varz.axes = var.axes
  # Since the axes have been modified after initialization, redo the init to get
  # shortcuts to the axes names
  Var.__init__(varz, varz.axes, varz.dtype)
  if var.name != '':
    varz.name = var.name+'_anom'
  return varc, varz
开发者ID:neishm,项目名称:pygeode,代码行数:17,代码来源:composite.py


示例19: __init__

 def __init__(self, var, newaxes, name=None, fillvalue=None, scale=None, offset=None, atts={}, plotatts={}):
   from pygeode.var import Var, copy_meta 
   atts = atts.copy()
   plotatts = plotatts.copy()
   assert len(newaxes) == len(var.axes)
   for a1, a2 in zip(newaxes, var.axes): assert len(a1) == len(a2)
   self.var = var
   dtype = var.dtype
   if fillvalue is not None or scale is not None or offset is not None: dtype = 'float32'
   self.fillvalue = fillvalue
   self.scale = scale
   self.offset = offset
   Var.__init__(self, newaxes, dtype=dtype)
   copy_meta(var, self)
   self.atts = atts
   self.plotatts = plotatts
   if name is not None: self.name = name
开发者ID:aerler,项目名称:pygeode,代码行数:17,代码来源:cfmeta.py


示例20: __init__

  def __init__ (self, var, saxis, kernel):
  # {{{
    ''' __init__()'''
    import numpy as np

    assert len(kernel) <= var.shape[saxis], 'Kernel must not be longer than dimension being smoothed.'

    # Construct new variable
    self.saxis = saxis
    self.var = var
    self.kernel = kernel
    self.klen = len(kernel)

    # Normalize and reshape kernel
    self.kernel /= np.sum(self.kernel)
    self.kernel.shape = [self.klen if i == saxis else 1 for i in range(var.naxes)]

    Var.__init__(self, var.axes, var.dtype, name=var.name, atts=var.atts, plotatts=var.plotatts)
开发者ID:aerler,项目名称:pygeode,代码行数:18,代码来源:smooth.py



注:本文中的pygeode.var.Var类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python geometry.as_shape函数代码示例发布时间:2022-05-25
下一篇:
Python pygeocoder.Geocoder类代码示例发布时间:2022-05-25
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap