Get the bonds of a bin, given its index `bin_num`.

        :returns: a `Bounds` namedtuple with properties min and max
            respectively.
544189
def get_bounds(self, bin_num):
        
        min_bound = (self.bin_size * bin_num) + self.min_value
        max_bound = min_bound + self.bin_size
        return self.Bounds(min_bound, max_bound)
103455
def bin_atoms(self):
        ''''''

        # Create the atom bins
        low_point = numpy.array([self.min_x, self.min_y, self.min_z])
        high_point = numpy.array([self.max_x, self.max_y, self.max_z])
        atom_bin_dimensions = numpy.ceil((high_point - low_point) / self.bin_size)
        self.atom_bin_dimensions = (int(atom_bin_dimensions[0]) - 1, int(atom_bin_dimensions[1]) - 1, int(atom_bin_dimensions[2]) - 1)
        atom_bins = []
        for x in range(int(atom_bin_dimensions[0])):
            atom_bins.append([])
            for y in range(int(atom_bin_dimensions[1])):
                atom_bins[x].append([])
                for z in range(int(atom_bin_dimensions[2])):
                    atom_bins[x][y].append(Bin(x, y, z))

        # Assign each Atom to a bin
        for serial_number, atom in self.atoms.iteritems():
            bin_location = numpy.trunc((atom.point - low_point) / self.bin_size)
            bin = atom_bins[int(bin_location[0])][int(bin_location[1])][int(bin_location[2])]
            bin.append(atom)
            atom.set_bin(bin)

        # Sanity_check
        if self.safe_mode:
            num_atoms = 0
            for x in range(int(atom_bin_dimensions[0])):
                for y in range(int(atom_bin_dimensions[1])):
                    for z in range(int(atom_bin_dimensions[2])):
                        num_atoms += len(atom_bins[x][y][z])
            assert(num_atoms == len(self.atoms))

        # Snip empty sections (saves a little space after garbage collection - space savings increase with the number of empty arrays in the matrix)
        blank_section = ()
        for x in range(int(atom_bin_dimensions[0])):
            for y in range(int(atom_bin_dimensions[1])):
                for z in range(int(atom_bin_dimensions[2])):
                    if not atom_bins[x][y][z]:
                        atom_bins[x][y][z] = blank_section

        self.atom_bins = atom_bins
348907
def shape(self) -> Tuple[int, ...]:
        
        return tuple(bins.bin_count for bins in self._binnings)
360772
def get_bounding_box(self, maxdist):
        
        return utils.get_bounding_box([ps.location for ps in self], maxdist)
1078217
def solveBinPacking(s,B):
    
    n = len(s)
    U = len(FFD(s,B)) # upper bound of the number of bins
    model = bpp(s,B)
    x,y = model.data

    model.optimize()

    bins = [[] for i in range(U)]
    for (i,j) in x:
        if model.getVal(x[i,j]) > .5:
            bins[j].append(s[i])
    for i in range(bins.count([])):
        bins.remove([])
    for b in bins:
        b.sort()
    bins.sort()
    return bins
190586
def numpy_bins_with_mask(self) -> Tuple[np.ndarray, np.ndarray]:
        
        bwm = to_numpy_bins_with_mask(self.bins)
        if not self.includes_right_edge:
            bwm[0].append(np.inf)
        return bwm
253409
def calc_bins(n, min_val, max_val, h=None, binwidth=None):
    
    if not h:
        h = max(10, math.log(n + 1, 2))
    if binwidth == 0:
        binwidth = 0.1
    if binwidth is None:
        binwidth = (max_val - min_val) / h
    for b in drange(min_val, max_val, step=binwidth, include_stop=True):
        if b.is_integer():
            yield int(b)
        else:
            yield b
1073274
def _get_catalogue_bin_limits(catalogue, dmag):
    
    mag_bins = np.arange(
        float(np.floor(np.min(catalogue.data['magnitude']))) - dmag,
        float(np.ceil(np.max(catalogue.data['magnitude']))) + dmag,
        dmag)
    counter = np.histogram(catalogue.data['magnitude'], mag_bins)[0]
    idx = np.where(counter > 0)[0]
    mag_bins = mag_bins[idx[0]:(idx[-1] + 2)]
    return mag_bins
417765
def extract_bbox(layers):
    
    if not hasattr(layers, '__iter__'):
        layers = [layers]
    bboxes = [
        layer.bbox for layer in layers
        if layer.is_visible() and not layer.bbox == (0, 0, 0, 0)
    ]
    if len(bboxes) == 0:  # Empty bounding box.
        return (0, 0, 0, 0)
    lefts, tops, rights, bottoms = zip(*bboxes)
    return (min(lefts), min(tops), max(rights), max(bottoms))
909998
def _get_bin_width(stdev, count):
    

    w = int(round((3.5 * stdev) / (count ** (1.0 / 3))))
    if w:
        return w
    else:
        return 1
65607
def val_to_bin(edges, x):
    """"""
    ibin = np.digitize(np.array(x, ndmin=1), edges) - 1
    return ibin
1146566
def extractTwos(m):
    """"""
    # the problem can be break down to count how many '0's are there in
    # the end of bin(m). This can be done this way: m & a stretch of '1's
    # which can be represent as (2 ** n) - 1.
    assert m >= 0
    i = 0
    while m & (2 ** i) == 0:
        i += 1
    return i, m >> i
1127378
def get_shape(bin_edges, sid):
    
    mag_bins, dist_bins, lon_bins, lat_bins, eps_bins = bin_edges
    return (len(mag_bins) - 1, len(dist_bins) - 1,
            len(lon_bins[sid]) - 1, len(lat_bins[sid]) - 1, len(eps_bins) - 1)
392557
def get_bounding_box(self):
        
        if len(self.polygons) == 0:
            return None
        return numpy.array(((min(pts[:, 0].min() for pts in self.polygons),
                             min(pts[:, 1].min() for pts in self.polygons)),
                            (max(pts[:, 0].max() for pts in self.polygons),
                             max(pts[:, 1].max() for pts in self.polygons))))
10317
def bounds(self):
        
        bounds = [np.inf,-np.inf, np.inf,-np.inf, np.inf,-np.inf]

        def update_bounds(ax, nb, bounds):
            """internal helper to update bounds while keeping track"""
            if nb[2*ax] < bounds[2*ax]:
                bounds[2*ax] = nb[2*ax]
            if nb[2*ax+1] > bounds[2*ax+1]:
                bounds[2*ax+1] = nb[2*ax+1]
            return bounds

        # get bounds for each block and update
        for i in range(self.n_blocks):
            try:
                bnds = self[i].GetBounds()
                for a in range(3):
                    bounds = update_bounds(a, bnds, bounds)
            except AttributeError:
                # Data object doesn't have bounds or is None
                pass

        return bounds
27294
def boundingbox(self):
        
        xyz = self.xyz
        return Box(mins=xyz.min(axis=0), maxs=xyz.max(axis=0))
613964
def simple_nearest_indices(xs,res):
    '''
    
    '''
    maxs = [max(a) for a in xs]
    mins = [min(a) for a in xs]
    XS = [np.linspace(mn, mx, r) for mn,mx,r in zip(mins,maxs,res)];
    XS = tuple(np.meshgrid(*XS,indexing='ij'));
    if type(xs) != tuple:
        xs = tuple(xs);
    return nearest_indices(xs,XS);