Example #1
0
    def rank_nD(self, data, axis=0):
        if not axis in [0, 1]:
            if not isinstance(axis, str):
                raise 'Ranking error, axis can only be 1 or 2 or name'
            else:
                nms = data.getAxisIds()
                for i in range(len(nms)):
                    nm = nms[i]
                    if axis in nm.split('___'):
                        axis = i
                if not axis in [0, 1]:
                    raise 'Ranking error, axis can only be 1 or 2 or name'

        if axis != 0:
            data = data(order=(str(axis) + '...'))
        a0 = MV2.argsort(data.filled(1.E20), axis=0)
        n = a0.shape[0]
        b = MV2.zeros(a0.shape, MV2.float)
        sh = a0[1].shape
        for i in range(n):
            I = MV2.ones(sh) * i
            c = MV2.array(a0[i].filled(n - 1))
            b = genutil.arrayindexing.set(b, c, I)
        m = data.mask
        if not m is None:
            b = MV2.masked_where(m, b)
        else:
            b = MV2.array(b)
        n = MV2.count(b, 0)
        n.setAxisList(b.getAxisList()[1:])
        b, n = genutil.grower(b, n)
        b = 100. * b / (n - 1)
        b.setAxisList(data.getAxisList())
        if axis != 0:
            st = ''
            for i in range(axis):
                st += str(i + 1)
            st += '0...'
            data = data(order=st)
            b = b(order=st)
        return b
Example #2
0
    def rank_nD(self, data, axis=0):
        if axis not in [0, 1]:
            if not isinstance(axis, str):
                raise 'Ranking error, axis can only be 1 or 2 or name'
            else:
                nms = data.getAxisIds()
                for i in range(len(nms)):
                    nm = nms[i]
                    if axis in nm.split('___'):
                        axis = i
                if axis not in [0, 1]:
                    raise 'Ranking error, axis can only be 1 or 2 or name'

        if axis != 0:
            data = data(order=(str(axis) + '...'))
        a0 = MV2.argsort(data.filled(1.E20), axis=0)
        n = a0.shape[0]
        b = MV2.zeros(a0.shape, MV2.float)
        sh = a0[1].shape
        for i in range(n):
            Indx = MV2.ones(sh) * i
            c = MV2.array(a0[i].filled(n - 1))
            b = genutil.arrayindexing.set(b, c, Indx)
        m = data.mask
        if m is not None:
            b = MV2.masked_where(m, b)
        else:
            b = MV2.array(b)
        n = MV2.count(b, 0)
        n.setAxisList(b.getAxisList()[1:])
        b, n = genutil.grower(b, n)
        b = 100. * b / (n - 1)
        b.setAxisList(data.getAxisList())
        if axis != 0:
            st = ''
            for i in range(axis):
                st += str(i + 1)
            st += '0...'
            data = data(order=st)
            b = b(order=st)
        return b
Example #3
0
    def rank(self, data, axis=0):
        if not axis in [0, 1]:
            if not isinstance(axis, str):
                raise 'Ranking error, axis can only be 1 or 2 or name'
            else:
                nms = data.getAxisIds()
                for i in range(len(nms)):
                    nm = nms[i]
                    if axis in nm.split('___'):
                        axis = i
                if not axis in [0, 1]:
                    raise 'Ranking error, axis can only be 1 or 2 or name'
        if data.ndim > 2:
            raise "Ranking error, array can only be 2D"

        if axis == 1:
            data = MV2.transpose(data)
        a0 = MV2.argsort(data.filled(1.E20), axis=0)
        n = a0.shape[0]
        b = MV2.zeros(a0.shape, MV2.float)
        sh = a0[1].shape
        for i in range(n):
            I = MV2.ones(sh) * i
            c = MV2.array(a0[i].filled(n - 1))
            b = genutil.arrayindexing.set(b, c, I)

        m = data.mask
        if not m is None:
            b = MV2.masked_where(m, b)
        else:
            b = MV2.array(b)
        n = MV2.count(b, 0)
        n.setAxis(0, b.getAxis(1))
        b, n = genutil.grower(b, n)
        b = 100. * b / (n - 1)
        b.setAxisList(data.getAxisList())
        if axis == 1:
            b = MV2.transpose(b)
            data = MV2.transpose(data)
        return b
Example #4
0
    def rank(self, data, axis=0):
        if axis not in [0, 1]:
            if not isinstance(axis, str):
                raise 'Ranking error, axis can only be 1 or 2 or name'
            else:
                nms = data.getAxisIds()
                for i in range(len(nms)):
                    nm = nms[i]
                    if axis in nm.split('___'):
                        axis = i
                if axis not in [0, 1]:
                    raise 'Ranking error, axis can only be 1 or 2 or name'
        if data.ndim > 2:
            raise "Ranking error, array can only be 2D"

        if axis == 1:
            data = MV2.transpose(data)
        a0 = MV2.argsort(data.filled(1.E20), axis=0)
        n = a0.shape[0]
        b = MV2.zeros(a0.shape, MV2.float)
        sh = a0[1].shape
        for i in range(n):
            Indx = MV2.ones(sh) * i
            c = MV2.array(a0[i].filled(n - 1))
            b = genutil.arrayindexing.set(b, c, Indx)

        m = data.mask
        if m is not None:
            b = MV2.masked_where(m, b)
        else:
            b = MV2.array(b)
        n = MV2.count(b, 0)
        n.setAxis(0, b.getAxis(1))
        b, n = genutil.grower(b, n)
        b = 100. * b / (n - 1)
        b.setAxisList(data.getAxisList())
        if axis == 1:
            b = MV2.transpose(b)
            data = MV2.transpose(data)
        return b