本文整理汇总了Python中org.meteoinfo.data.ArrayMath.missingToNaN方法的典型用法代码示例。如果您正苦于以下问题:Python ArrayMath.missingToNaN方法的具体用法?Python ArrayMath.missingToNaN怎么用?Python ArrayMath.missingToNaN使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.meteoinfo.data.ArrayMath
的用法示例。
在下文中一共展示了ArrayMath.missingToNaN方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __getitem__
# 需要导入模块: from org.meteoinfo.data import ArrayMath [as 别名]
# 或者: from org.meteoinfo.data.ArrayMath import missingToNaN [as 别名]
#.........这里部分代码省略.........
eidx = self.dimlen(i) if k.stop is None else k.stop
if eidx < 0:
eidx = self.dimlen(i) + eidx
eidx -= 1
if isinstance(k.step, basestring):
nv = float(k.step) + self.dims[i].getDimValue()[0]
nidx = self.dims[i].getValueIndex(nv)
step = nidx - sidx
elif isinstance(k.step, datetime.timedelta):
nv = miutil.date2num(k.start + k.step)
nidx = self.dims[i].getValueIndex(nv)
step = nidx - sidx
else:
step = 1 if k.step is None else k.step
if sidx > eidx:
iidx = eidx
eidx = sidx
sidx = iidx
elif isinstance(k, list):
onlyrange = False
isrange = False
if not isinstance(k[0], datetime.datetime):
ranges.append(k)
else:
tlist = []
for tt in k:
sv = miutil.date2num(tt)
idx = self.dims[i].getValueIndex(sv)
tlist.append(idx)
ranges.append(tlist)
k = tlist
elif isinstance(k, basestring):
dim = self.variable.getDimension(i)
kvalues = k.split(':')
sv = float(kvalues[0])
sidx = dim.getValueIndex(sv)
if len(kvalues) == 1:
eidx = sidx
step = 1
else:
ev = float(kvalues[1])
eidx = dim.getValueIndex(ev)
if len(kvalues) == 2:
step = 1
else:
step = int(float(kvalues[2]) / dim.getDeltaValue())
if sidx > eidx:
iidx = eidx
eidx = sidx
sidx = iidx
else:
print k
return None
if isrange:
if eidx >= dimlen:
print 'Index out of range!'
return None
origin.append(sidx)
n = eidx - sidx + 1
size.append(n)
if n > 1:
dim = self.variable.getDimension(i)
if dim.isReverse():
step = -step
dim = dim.extract(sidx, eidx, step)
dim.setReverse(False)
dims.append(dim)
stride.append(step)
if step < 0:
step = abs(step)
flips.append(i)
rr = Range(sidx, eidx, step)
ranges.append(rr)
else:
if len(k) > 1:
dim = self.variable.getDimension(i)
dim = dim.extract(k)
dim.setReverse(False)
dims.append(dim)
#rr = self.dataset.read(self.name, origin, size, stride).reduce()
if onlyrange:
rr = self.dataset.dataset.read(self.name, ranges)
else:
rr = self.dataset.dataset.take(self.name, ranges)
if rr.getSize() == 1:
return rr.getObject(0)
else:
for i in flips:
rr = rr.flip(i)
rr = rr.reduce()
ArrayMath.missingToNaN(rr, self.fill_value)
if len(flips) > 0:
rrr = Array.factory(rr.getDataType(), rr.getShape())
MAMath.copy(rrr, rr)
array = MIArray(rrr)
else:
array = MIArray(rr)
data = DimArray(array, dims, self.fill_value, self.dataset.proj)
return data
示例2: __getitem__
# 需要导入模块: from org.meteoinfo.data import ArrayMath [as 别名]
# 或者: from org.meteoinfo.data.ArrayMath import missingToNaN [as 别名]
def __getitem__(self, indices):
if indices is None:
rr = self.dataset.read(self.name)
if rr.getDataType().isNumeric():
ArrayMath.missingToNaN(rr, self.fill_value)
array = MIArray(rr)
data = DimArray(array, self.dims, self.fill_value, self.dataset.proj)
return data
else:
return rr
if isinstance(indices, str): #metadata
rr = self.dataset.read(self.name)
m = rr.findMember(indices)
data = rr.getArray(0, m)
return MIArray(data)
if not isinstance(indices, tuple):
inds = []
inds.append(indices)
indices = inds
if len(indices) != self.ndim:
print 'indices must be ' + str(self.ndim) + ' dimensions!'
return None
origin = []
size = []
stride = []
dims = []
for i in range(0, self.ndim):
dimlen = self.dimlen(i)
k = indices[i]
if isinstance(k, int):
sidx = k
eidx = k
step = 1
elif isinstance(k, slice):
sidx = 0 if k.start is None else k.start
eidx = self.dimlen(i)-1 if k.stop is None else k.stop
step = 1 if k.step is None else k.step
elif isinstance(k, (tuple, list)):
dim = self.variable.getDimension(i)
sidx = dim.getValueIndex(k[0])
if len(k) == 1:
eidx = sidx
step = 1
else:
eidx = dim.getValueIndex(k[1])
if len(k) == 2:
step = 1
else:
step = int(k[2] / dim.getDeltaValue)
if sidx > eidx:
iidx = eidx
eidx = sidx
sidx = iidx
else:
print k
return None
if eidx >= dimlen:
print 'Index out of range!'
return None
origin.append(sidx)
n = eidx - sidx + 1
size.append(n)
if n > 1:
dim = self.variable.getDimension(i)
if dim.isReverse():
step = -step
dims.append(dim.extract(sidx, eidx, step))
stride.append(step)
rr = self.dataset.read(self.name, origin, size, stride).reduce()
if rr.getSize() == 1:
return rr.getObject(0)
ArrayMath.missingToNaN(rr, self.fill_value)
array = MIArray(rr)
data = DimArray(array, dims, self.fill_value, self.dataset.proj)
return data