Return separation distance as a function of floc size.
761786
def sep_dist_floc(ConcAluminum, ConcClay, coag, material,
                  DIM_FRACTAL, DiamTarget):
    """"""
    return (material.Diameter
            * (np.pi/(6
                      * frac_vol_floc_initial(ConcAluminum, ConcClay,
                                              coag, material)
                      ))**(1/3)
            * (DiamTarget / material.Diameter)**(DIM_FRACTAL / 3)
            )
724013
def distance(self, other):
        
        return distance((self.separation, self.pa), (other.separation, other.pa))
428995
def _distance_matrix_generic(x, centering, exponent=1):
    """"""
    _check_valid_dcov_exponent(exponent)

    x = _transform_to_2d(x)

    # Calculate distance matrices
    a = distances.pairwise_distances(x, exponent=exponent)

    # Double centering
    a = centering(a, out=a)

    return a
653415
def distance_law(matrix, log_bins=False):
    

    D = np.array([np.average(np.diagonal(matrix, j))
                  for j in range(min(matrix.shape))])
    if not log_bins:
        return D
    else:
        n = min(matrix.shape)
        n_bins = int(np.log(n) / np.log(2) + 1)
        logD = np.array([np.average(D[int(2**(i - 1)):min(n, 2**i)])
                         for i in range(n_bins)])
        return logD
1323428
def separate(polylines, f_mx_dist=2, mn_group_len=4):
    
    s = []

    for n in range(len(polylines) - 1, -1, -1):
        c = polylines[n]
        separated = False
        start = 0

        for m in range(mn_group_len, len(c) - 1):
            if m - start < mn_group_len:
                continue
            m += 1
            group = c[m - mn_group_len:m]

            x, y = group[:, 0], group[:, 1]
            asc, offs, _, _, _ = linregress(x, y)
            yfit = asc * x + offs

            # check whether next point would fit in:
            p1 = c[m]
            l = (x[0], yfit[0], p1[-1], asc * p1[-1] + offs)
            std = np.mean([line.distance(l, g) for g in group])
            dist = line.distance(l, p1)

            if dist > 2 and dist > f_mx_dist * std:
                separated = True
                s.append(c[start:m - 1])
                start = m - 1

        if separated:
            if len(c) - start >= 2:
                s.append(c[start:])
            polylines.pop(n)

    polylines.extend(s)

    return polylines
883429
def distance_function_match(l1, l2, thresh, dist_fn, norm_funcs=[]):
    """"""
    common = []
    # We will keep track of the global index in the source list as we
    # will successively reduce their sizes.
    l1 = list(enumerate(l1))
    l2 = list(enumerate(l2))

    # Use the distance function and threshold on hints given by normalization.
    # See _match_by_norm_func for implementation details.
    # Also wrap the list element function function to ignore the global list
    # index computed above.
    for norm_fn in norm_funcs:
        new_common, l1, l2 = _match_by_norm_func(
                l1, l2,
                lambda a: norm_fn(a[1]),
                lambda a1, a2: dist_fn(a1[1], a2[1]),
                thresh)
        # Keep only the global list index in the end result.
        common.extend((c1[0], c2[0]) for c1, c2 in new_common)

    # Take any remaining umatched entries and try to match them using the
    # Munkres algorithm.
    dist_matrix = [[dist_fn(e1, e2) for i2, e2 in l2] for i1, e1 in l1]

    # Call Munkres on connected components on the remaining bipartite graph.
    # An edge links an element from l1 with an element from l2 only if
    # the distance between the elements is less (or equal) than the theshold.
    components = BipartiteConnectedComponents()
    for l1_i in range(len(l1)):
        for l2_i in range(len(l2)):
            if dist_matrix[l1_i][l2_i] > thresh:
                continue
            components.add_edge(l1_i, l2_i)

    for l1_indices, l2_indices in components.get_connected_components():
        # Build a partial distance matrix for each connected component.
        part_l1 = [l1[i] for i in l1_indices]
        part_l2 = [l2[i] for i in l2_indices]

        part_dist_matrix = [[dist_matrix[l1_i][l2_i] for l2_i in l2_indices]
                            for l1_i in l1_indices]
        part_cmn = _match_munkres(part_l1, part_l2, part_dist_matrix, thresh)

        common.extend((c1[0], c2[0]) for c1, c2 in part_cmn)

    return common
1048504
def distance(self, other):
        """"""
        return math.acos(self._pos3d.dot(other.vector))
425714
def dens_floc_init(ConcAluminum, ConcClay, coag, material):
    
    return (conc_floc(ConcAluminum, ConcClay, coag).magnitude
            / frac_vol_floc_initial(ConcAluminum, ConcClay, coag, material)
            )
684037
def _get_distance_term(self, C, rhypo, mag):
        
        h_eff = self._get_effective_distance(mag)
        r_val = np.sqrt(rhypo ** 2.0 + h_eff ** 2.0)
        return C["c3"] * np.log10(r_val)
1297154
def PaperSize(s):
    """"""
    size = s.lower()
    f = "p"
    if size.endswith("-l"):
        f = "l"
        size = size[:-2]
    if size.endswith("-p"):
        size = size[:-2]
    rc = paperSizes.get(size, (-1, -1))
    if f == "p":
        return rc
    return (rc[1], rc[0])
813875
def distance(self) -> ErrorValue:
        """"""
        if 'DistCalibrated' in self._data:
            dist = self._data['DistCalibrated']
        else:
            dist = self._data["Dist"]
        if 'DistCalibratedError' in self._data:
            disterr = self._data['DistCalibratedError']
        elif 'DistError' in self._data:
            disterr = self._data['DistError']
        else:
            disterr = 0.0
        return ErrorValue(dist, disterr)
786058
def getsize(path, recurse=False):
    """"""
    if not op.isdir(path):
        return op.getsize(path)
    size = 0
    for r,_,fs in os.walk(path):
        for f in fs:
            size += getsize(op.join(r,f))
        if not recurse:
            break
    return size
409220
def size(self):
        """"""
        initial_count = self.count()
        count_with_skip = max(0, initial_count - self._skip)
        size = min(count_with_skip, self._limit)
        return size
981486
def distance(a, b, metric="cosine"):
    
    if metric == "cosine":
        return np.dot(a, b.T)
    raise Exception("Unknown metric '{metric}'".format(metric=metric))
935929
def vector_distance(a, b):
    """"""
    a = np.array(a)
    b = np.array(b)
    return np.linalg.norm(a - b)
552227
def batch(data, batch_size, batch_size_fn=None):
    """"""
    if batch_size_fn is None:
        def batch_size_fn(new, count, sofar):
            return count
    minibatch, size_so_far = [], 0
    for ex in data:
        minibatch.append(ex)
        size_so_far = batch_size_fn(ex, len(minibatch), size_so_far)
        if size_so_far == batch_size:
            yield minibatch
            minibatch, size_so_far = [], 0
        elif size_so_far > batch_size:
            yield minibatch[:-1]
            minibatch, size_so_far = minibatch[-1:], batch_size_fn(ex, 1, 0)
    if minibatch:
        yield minibatch
1237599
def distance(self, other):
        
        return distance(self.lat, self.lon, None, other.lat, other.lon, None)