mean = (cube_a + cube_b + cube_c) / 3.def mean_cube(*cubes):
n = float(len(cubes))
return reduce(iris.analysis.maths.add, cubes) / nmean = mean_cube(cube_a, cube_b, cube_c)def mean(*args):
return sum(args) / float(len(args))It's getting late on a friday afternoon, so I may be talking nonsense, but does scipy.mean([cube_a, cube_b, cube_b]) not work? Or even scipy.mean(cubelist)?
You can't use scipy.mean (or np.mean, which is actually what scipy.mean calls under the covers), because it expects the arguments to be numpy arrays.
>>> print np.mean(cubes)
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-255-b689c50cf263> in <module>()
----> 1 print np.mean(cubes)
/Users/shoyer/dev/climatology-research/library/python/target/climatology/lib/python2.7/site-packages/numpy/core/fromnumeric.pyc in mean(a, axis, dtype, out, keepdims)
2714
2715 return _methods._mean(a, axis=axis, dtype=dtype,
-> 2716 out=out, keepdims=keepdims)
2717
2718 def std(a, axis=None, dtype=None, out=None, ddof=0, keepdims=False):
/Users/shoyer/dev/climatology-research/library/python/target/climatology/lib/python2.7/site-packages/numpy/core/_methods.pyc in _mean(a, axis, dtype, out, keepdims)
65 ret, rcount, out=ret, casting='unsafe', subok=False)
66 else:
---> 67 ret = ret.dtype.type(ret / rcount)
68
69 return ret
AttributeError: 'Cube' object has no attribute 'dtype'
> /Users/shoyer/dev/climatology-research/library/python/target/climatology/lib/python2.7/site-packages/numpy/core/_methods.py(67)_mean()
66 else:
---> 67 ret = ret.dtype.type(ret / rcount)
68
>>> print np.sum(cubes)
unknown / (Celsius) (time: 23351; station: 3)
Dimension coordinates:
time x -
station - x
Auxiliary coordinates:
latitude - x
longitude - x
station_id - ximport numpy as np
import numpy.ma as ma
import iris
a1 = ma.array([[1., 2., 3.], [4., 5., 6.]], mask=[[0, 1, 0], [0, 0, 1]])
a2 = ma.array([[8., 2., 1.], [3., 1., 4.]], mask=[[0, 1, 0], [0, 0, 1]])
print 'desired solution:'
print '-----------------'
print (a1 + a2) / 2.
print
print 'now with cubes'
print '--------------'
c1 = iris.cube.Cube(a1)
c2 = iris.cube.Cube(a2)
cs = np.mean([c1, c2])
print c1
print c2
print cs
print cs.dataWell I guess that means it isn't a good idea then! It seems like writing a wrapper around the built-in sum function might be the best choice here.
--
You received this message because you are subscribed to the Google Groups "Iris" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scitools-iri...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.