Get the index of the unique magnitude tuple for each pixel in the ROI.
320114
def mask_roi_digi(self):
        
        # http://stackoverflow.com/q/24205045/#24206440
        A = np.vstack([self.mask_1.mask_roi_sparse,self.mask_2.mask_roi_sparse]).T
        B = self.mask_roi_unique

        AA = np.ascontiguousarray(A)
        BB = np.ascontiguousarray(B)
         
        dt = np.dtype((np.void, AA.dtype.itemsize * AA.shape[1]))
        a = AA.view(dt).ravel()
        b = BB.view(dt).ravel()
         
        idx = np.argsort(b)
        indices = np.searchsorted(b[idx],a)
        return idx[indices]
1304888
public final int getIndex( int coordinate[] ) {
		int index = coordinate[0]*strides[0];
		for (int i = 1; i < coordinate.length; i++) {
			index += strides[i]*coordinate[i];
		}

		return index;
	}
178216
def rgba_floats_tuple(self, x):
        
        if x <= self.index[0]:
            return self.colors[0]
        if x >= self.index[-1]:
            return self.colors[-1]

        i = len([u for u in self.index if u < x])  # 0 < i < n.
        if self.index[i-1] < self.index[i]:
            p = (x - self.index[i-1])*1./(self.index[i]-self.index[i-1])
        elif self.index[i-1] == self.index[i]:
            p = 1.
        else:
            raise ValueError('Thresholds are not sorted.')

        return tuple((1.-p) * self.colors[i-1][j] + p*self.colors[i][j] for j
                     in range(4))
1310800
def uniq2orderipix_lut(uniq):
    
    order = log2_lut(uniq >> 2) >> 1
    ipix = uniq - (1 << (2 * (order + 1)))
    return order, ipix
509355
def _make_index(df, cols=META_IDX):
    """"""
    return pd.MultiIndex.from_tuples(
        pd.unique(list(zip(*[df[col] for col in cols]))), names=tuple(cols))
1001812
def xrify_tuples(self, tup):
        """"""
        return xr.DataArray(tup,
                            dims=['bands'],
                            coords={'bands': self.data['bands']})
845747
def get_image(roi_rec, short, max_size, mean, std):
    
    im = imdecode(roi_rec['image'])
    if roi_rec["flipped"]:
        im = im[:, ::-1, :]
    im, im_scale = resize(im, short, max_size)
    height, width = im.shape[:2]
    im_info = np.array([height, width, im_scale], dtype=np.float32)
    im_tensor = transform(im, mean, std)

    # gt boxes: (x1, y1, x2, y2, cls)
    if roi_rec['gt_classes'].size > 0:
        gt_inds = np.where(roi_rec['gt_classes'] != 0)[0]
        gt_boxes = np.empty((len(gt_inds), 5), dtype=np.float32)
        gt_boxes[:, 0:4] = roi_rec['boxes'][gt_inds, :]
        gt_boxes[:, 4] = roi_rec['gt_classes'][gt_inds]
        # scale gt_boxes
        gt_boxes[:, 0:4] *= im_scale
    else:
        gt_boxes = np.empty((0, 5), dtype=np.float32)

    return im_tensor, im_info, gt_boxes
651755
def _determine_dimensions(num_of_pixels):
    
    for x in xrange(int(math.sqrt(num_of_pixels)) + 1, 1, -1):
        if num_of_pixels % x == 0:
            return num_of_pixels // x, x
    return 1, num_of_pixels
335316
def get_upscaled_value_tuple(self):
        
        # Scale up to 0-255 values.
        rgb_r = int(math.floor(0.5 + self.rgb_r * 255))
        rgb_g = int(math.floor(0.5 + self.rgb_g * 255))
        rgb_b = int(math.floor(0.5 + self.rgb_b * 255))

        return rgb_r, rgb_g, rgb_b
295057
def each_pixel
      get_pixels(0, 0, columns, rows).each_with_index do |p, n|
        yield(p, n % columns, n / columns)
      end
      self
    end
638127
def _get_index(self):
        
        contour = self.contour
        value = contour.segments.index(self)
        return value
208879
def get_ridx(self, iloc):
        """"""
        with h5py.File(self.source_file, "r") as hdf5:
            return hdf5[self.idx_set["geol"] + "/RuptureIndex"][iloc]
547600
def edge_index(self):
        """"""
        return dict((edge, index) for index, edge in enumerate(self.edges))
442090
def _get_single_depth(self, multi_index):
        '''
        
        '''
        single_depth = 0
        for subind in multi_index:
            if is_slice_or_dim_range(subind):
                break
            single_depth += 1
        return single_depth
975510
def mask_roi_unique(self):
        
        # There is no good inherent way in numpy to do this...
        # http://stackoverflow.com/q/16970982/

        # Also possible and simple:
        #return np.unique(zip(self.mask_1.mask_roi_sparse,self.mask_2.mask_roi_sparse))

        A = np.vstack([self.mask_1.mask_roi_sparse,self.mask_2.mask_roi_sparse]).T
        B = A[np.lexsort(A.T[::-1])]
        return B[np.concatenate(([True],np.any(B[1:]!=B[:-1],axis=1)))]
378780
def get_maximum_index(indices):
    """"""
    def _maximum_idx_single(idx):
        if isinstance(idx, slice):
            start = -1
            stop = 0
            if idx.start is not None:
                start = idx.start.__index__()
            if idx.stop is not None:
                stop = idx.stop.__index__()
            return max(start, stop - 1)
        else:
            return idx.__index__()
    if isinstance(indices, tuple):
        return max((_maximum_idx_single(i) for i in indices), default=-1)
    else:
        return _maximum_idx_single(indices)
250833
def _extract_median(image, mask = slice(None), size = 1, voxelspacing = None):
    
    # set voxel spacing
    if voxelspacing is None:
        voxelspacing = [1.] * image.ndim
        
    # determine structure element size in voxel units
    size = _create_structure_array(size, voxelspacing)
        
    return _extract_intensities(median_filter(image, size), mask)