2

我是 Iris 库的新手,需要计算热量指数,它是温度和相对湿度的多元非线性函数,类似于 $HI = temp +rh + temp*rh + temp^2 *rh + rh^2*temp $ 。这里,temp 的单位是华氏度,rh 的单位是 1。

但是,虹膜立方体不会添加不同的单位:

In [147]: HI = temp + rh + temp*rh + temp**2*rh + rh**2*temp
---------------------------------------------------------------------------
NotYetImplementedError                    Traceback (most recent call last)
<ipython-input-147-675ea72a5d06> in <module>()
----> 1 HI = temp + rh + temp*rh + temp**2*rh + rh**2*temp

/Users/me/anaconda/lib/python2.7/site-packages/iris/cube.pyc in __add__(self, other)
  2596 
   2597     def __add__(self, other):
-> 2598         return iris.analysis.maths.add(self, other, ignore=True)
   2599     __radd__ = __add__
   2600 

/Users/me/anaconda/lib/python2.7/site-packages/iris/analysis/maths.pyc in add(cube, other, dim, ignore, in_place)
    166     op = operator.iadd if in_place else operator.add
167     return _add_subtract_common(op, 'addition', 'added', cube, other, dim=dim,
--> 168                                 ignore=ignore, in_place=in_place)
169 
170 

/Users/me/anaconda/lib/python2.7/site-packages/iris/analysis/maths.pyc     in _add_subtract_common(operation_function, operation_noun,     operation_past_tense, cube, other, dim, ignore, in_place)
    216     """
    217     _assert_is_cube(cube)
--> 218     _assert_matching_units(cube, other, operation_noun)
219 
220     if isinstance(other, iris.cube.Cube):

/Users/me/anaconda/lib/python2.7/site-packages/iris/analysis/maths.pyc in _assert_matching_units(cube, other, operation_noun)
132         raise iris.exceptions.NotYetImplementedError(
133             'Differing units (%s & %s) %s not implemented' %
--> 134             (cube.units, other.units, operation_noun))
135 
136 

NotYetImplementedError: Differing units (Fahrenheit & 1) addition not implemented

如果我将数据称为 numpy 数组,那么这是一种解决方法,例如: heatIndex = -42.379 + temp.data + rh.data + temp.data 2 + rh.data 2 但这似乎违背了使用 Iris 的目的首先,需要重写元数据。

这可能与虹膜立方体有关吗?是否有我缺少的无单位 udunit 允许这种情况发生?

注意:如果从错误中不清楚,我正在运行 Python 2.7(和 Iris 1.7)。

4

2 回答 2

0

If I call the data instead as a numpy array ... this seems to defeat the purpose of using Iris in the first place, and requires re-writing the meta-data.

Firstly, making use of numpy and all of the incredible scipy ecosystem is a powerful capability of Iris. Where functionality exists in Iris, it is better to use it rather than having to manage the metadata yourself, but if something doesn't exist then hopefully it shouldn't be too difficult to implement.

In your case, you will probably be wanting to update some of the metadata yourself (i.e. Iris wont know that this mathematical transformation produces data which represents "heat index").

It appears the heat index should be in Fahrenheit, and the addition of the Fahrenheit cube to a scalar cube is causing this error. The simplest solution might be to just add the relative humidity scalar data (i.e. not the cube) to the temperature:

rh = rh.data
heat_index = temp + rh + temp*rh + temp**2*rh + rh**2*temp
heat_index.rename('heat_index')
assert heat_index.units == 'Fahrenheit'
于 2015-02-03T09:38:09.283 回答
0

我认为当您开始使用数据数组时,您的思路是正确的,但它可以变得更简洁一些。关键是首先复制温度立方体并从那里开始工作

C1 = -42.379
C2 = 2.04901523
# etc

def get_heat_index(temp, rh):
    '''Calculate the heat index as defined by George Winterling'''

    # make sure we are using the right temperature units
    # other checks could be implemented as assertions
    temp.convert_units('Fahrenheit')

    # start by copying the temperature cube
    heat_index = temp

    # fix the name of the cube to be returned
    heat_index.rename('heat_index')

    # C2 - do this first as already have temperature data
    heat_index.data = (C1 + C2*temp.data +
                      C3*rh.data +
    # etc
                      C9*temp.data**2*rh.data**2)

    return heat_index
于 2016-01-12T18:11:32.797 回答