Compute panel zone sizes.
498991
def _compute_zones_sizes(self):
        """"""
        # Left panels
        left = 0
        for panel in self.panels_for_zone(Panel.Position.LEFT):
            if not panel.isVisible():
                continue
            size_hint = panel.sizeHint()
            left += size_hint.width()
        # Right panels
        right = 0
        for panel in self.panels_for_zone(Panel.Position.RIGHT):
            if not panel.isVisible():
                continue
            size_hint = panel.sizeHint()
            right += size_hint.width()
        # Top panels
        top = 0
        for panel in self.panels_for_zone(Panel.Position.TOP):
            if not panel.isVisible():
                continue
            size_hint = panel.sizeHint()
            top += size_hint.height()
        # Bottom panels
        bottom = 0
        for panel in self.panels_for_zone(Panel.Position.BOTTOM):
            if not panel.isVisible():
                continue
            size_hint = panel.sizeHint()
            bottom += size_hint.height()
        self._top, self._left, self._right, self._bottom = (
            top, left, right, bottom)
        return bottom, left, right, top
940621
private static int[] calculateGridParam(int imagesSize) {
        int[] gridParam = new int[2];
        if (imagesSize < 3) {
            gridParam[0] = 1;
            gridParam[1] = imagesSize;
        } else if (imagesSize <= 4) {
            gridParam[0] = 2;
            gridParam[1] = 2;
        } else {
            gridParam[0] = imagesSize / 3 + (imagesSize % 3 == 0 ? 0 : 1);
            gridParam[1] = 3;
        }
        return gridParam;
    }
410740
def get_desktop_size(self):
        """"""

        _ptr = ffi.new('SDL_DisplayMode *')
        check_int_err(lib.SDL_GetDesktopDisplayMode(self._index, _ptr))
        return (_ptr.w, _ptr.h)
912356
function getWorkingSetSize(paneId) {
        var result = 0;
        _forEachPaneOrPanes(paneId, function (pane) {
            result += pane.getViewListSize();
        });
        return result;
    }
1135463
def _get_xy_scaling_parameters(self):
        """"""
        gd = self.area_definition
        bx = self.x.min()
        mx = gd.pixel_size_x
        by = self.y.min()
        my = -abs(gd.pixel_size_y)
        return mx, bx, my, by
590923
def _get_checkers(slice_shape, patch_size):
    """"""

    if patch_size is not None:
        patch_size = check_patch_size(patch_size)
    else:
        # 7 patches in each axis, min voxels/patch = 3
        # TODO make 7 a user settable parameter
        patch_size = np.round(np.array(slice_shape) / 7).astype('int16')
        patch_size = np.maximum(patch_size, np.array([3, 3]))

    black = np.zeros(patch_size)
    white = np.ones(patch_size)
    tile = np.vstack((np.hstack([black, white]), np.hstack([white, black])))

    # using ceil so we can clip the extra portions
    num_tiles = np.ceil(np.divide(slice_shape, tile.shape)).astype(int)
    checkers = np.tile(tile, num_tiles)

    # clipping any extra columns or rows
    if any(np.greater(checkers.shape, slice_shape)):
        if checkers.shape[0] > slice_shape[0]:
            checkers = np.delete(checkers, np.s_[slice_shape[0]:], axis=0)
        if checkers.shape[1] > slice_shape[1]:
            checkers = np.delete(checkers, np.s_[slice_shape[1]:], axis=1)

    return checkers
1111317
def calculateSceneWidth(self):
        
        widths = []
        
        w = self.width() / 2.0
        h = self.height() / 2.0
        
        for item in self.scene().items():
            pixmap = item.basePixmap()
            thumb = pixmap.scaled(pixmap.width(), h, Qt.KeepAspectRatio)
            widths.append(thumb.width())
            item.setPixmap(thumb)
        
        return sum(widths) + self.spacing() * (self.count() - 1) + w
1265803
def tileBounds(self, zoom, tileCol, tileRow):
        ""
        assert zoom in range(0, len(self.RESOLUTIONS))

        # 0,0 at top left: y axis down and x axis right
        tileSize = self.tileSize(zoom)
        minX = self.MINX + tileCol * tileSize
        maxX = self.MINX + (tileCol + 1) * tileSize
        if self.originCorner == 'bottom-left':
            minY = self.MINY + tileRow * tileSize
            maxY = self.MINY + (tileRow + 1) * tileSize
        elif self.originCorner == 'top-left':
            minY = self.MAXY - (tileRow + 1) * tileSize
            maxY = self.MAXY - tileRow * tileSize
        return [minX, minY, maxX, maxY]
1235268
def generateForSize(width, height, dimOrder, maxWindowSize, overlapPercent, transforms = []):
	
	
	# If the input data is smaller than the specified window size,
	# clip the window size to the input size on both dimensions
	windowSizeX = min(maxWindowSize, width)
	windowSizeY = min(maxWindowSize, height)
	
	# Compute the window overlap and step size
	windowOverlapX = int(math.floor(windowSizeX * overlapPercent))
	windowOverlapY = int(math.floor(windowSizeY * overlapPercent))
	stepSizeX = windowSizeX - windowOverlapX
	stepSizeY = windowSizeY - windowOverlapY
	
	# Determine how many windows we will need in order to cover the input data
	lastX = width - windowSizeX
	lastY = height - windowSizeY
	xOffsets = list(range(0, lastX+1, stepSizeX))
	yOffsets = list(range(0, lastY+1, stepSizeY))
	
	# Unless the input data dimensions are exact multiples of the step size,
	# we will need one additional row and column of windows to get 100% coverage
	if len(xOffsets) == 0 or xOffsets[-1] != lastX:
		xOffsets.append(lastX)
	if len(yOffsets) == 0 or yOffsets[-1] != lastY:
		yOffsets.append(lastY)
	
	# Generate the list of windows
	windows = []
	for xOffset in xOffsets:
		for yOffset in yOffsets:
			for transform in [None] + transforms:
				windows.append(SlidingWindow(
					x=xOffset,
					y=yOffset,
					w=windowSizeX,
					h=windowSizeY,
					dimOrder=dimOrder,
					transform=transform
				))
	
	return windows
1181745
def zone_calc(surf, cortex, src):
    

    cortex_vertices, cortex_triangles = surf_keep_cortex(surf, cortex)

    dist_vals = np.zeros((len(source_nodes), len(cortex_vertices)))

    for x in range(len(source_nodes)):

        translated_source_nodes = translate_src(source_nodes[x], cortex)
        dist_vals[x, :] = gdist.compute_gdist(cortex_vertices, cortex_triangles, source_indices = translated_source_nodes)

    data = np.argsort(dist_vals, axis=0)[0, :] + 1

    zone = recort(data, surf, cortex)

    del data

    return zone
375295
def bottoms(panels):
    
    bottom_lines = [(p['col'], p['row'] + p['size_y'], p['col'] + p['size_x'], p['row'] + p['size_y']) for p in panels]
    return sorted(bottom_lines, key=lambda l: l[1], reverse=True)
273313
def _get_qsize(tuning, width):
    """"""
    names = [x.to_shorthand() for x in tuning.tuning]
    basesize = len(max(names)) + 3
    barsize = ((width - basesize) - 2) - 1

    # x * 4 + 0.5x - barsize = 0 4.5x = barsize x = barsize / 4.5
    return max(0, int(barsize / 4.5))
958507
def calc_size(rect, orientation):
        
        (total_halfx, total_halfy) = rect.center
        if orientation in ["bottom", "top"]:
            (total_major_axis, total_minor_axis) = (total_halfx, total_halfy)
        else:
            (total_major_axis, total_minor_axis) = (total_halfy, total_halfx)

        major_axis = total_major_axis * (1.0 -
                                         ColorBarWidget.major_axis_padding)
        minor_axis = major_axis * ColorBarWidget.minor_axis_ratio

        # if the minor axis is "leaking" from the padding, then clamp
        minor_axis = np.minimum(minor_axis,
                                total_minor_axis *
                                (1.0 - ColorBarWidget.minor_axis_padding))

        return (major_axis, minor_axis)
92056
def get_grid_spatial_dimensions(self, variable):
        """"""

        data = self.open_dataset(self.service).variables[variable.variable]
        dimensions = list(data.dimensions)
        return data.shape[dimensions.index(variable.x_dimension)], data.shape[dimensions.index(variable.y_dimension)]
1348429
def _check_panel(self, length):
        
        n = len(self.index)
        if divmod(n, length)[1] != 0:
            raise ValueError("Panel length '%g' must evenly divide length of series '%g'"
                             % (length, n))
        if n == length:
            raise ValueError("Panel length '%g' cannot be length of series '%g'"
                             % (length, n))
366709
def getWindowBounds(self):
        """"""

        fn = self.function_table.getWindowBounds
        pnX = c_int32()
        pnY = c_int32()
        pnWidth = c_uint32()
        pnHeight = c_uint32()
        fn(byref(pnX), byref(pnY), byref(pnWidth), byref(pnHeight))
        return pnX.value, pnY.value, pnWidth.value, pnHeight.value
1016374
def calc_piece_size(total_size, max_pieces, min_piece_size, max_piece_size):
    """"""
    ps = 1 << max(0, math.ceil(math.log(total_size / max_pieces, 2)))
    if ps < min_piece_size:
        ps = min_piece_size
    if ps > max_piece_size:
        ps = max_piece_size
    return ps