def __clip_hex__(self, hex, hex_densities, return_clip=False):
        """

        :param hex: hex string to evaluate
        :param hex_densities: dictionary of all hex densities, atleast at this resolution
        :return: this hex density clipped based on neigbhors
        """
        res = h3.h3_get_resolution(hex)
        res_key = str(res)
        neighbors = h3.hex_range(hex, 1)
        at_tgt_count = 0
        for n in neighbors:
            if hex_densities.get(
                    n,
                    0) >= self.chain_vars['res_vars'][res_key]['density_tgt']:
                at_tgt_count += 1

        clip = min(
            self.chain_vars['res_vars'][res_key]['density_max'],
            self.chain_vars['res_vars'][res_key]['density_tgt'] *
            max(1, (at_tgt_count - self.chain_vars['res_vars'][res_key]['N'] +
                    1)))
        val = min(clip, hex_densities[hex])
        if return_clip:
            return val, clip
        return val
Exemplo n.º 2
0
def test_hex_range2():
    h = '8928308280fffff'
    out = h3.hex_range(h, 2)

    assert len(out) == 1 + 6 + 12

    expected = {
        '89283082813ffff',
        '89283082817ffff',
        '8928308281bffff',
        '89283082863ffff',
        '89283082823ffff',
        '89283082873ffff',
        '89283082877ffff',
        '8928308287bffff',
        '89283082833ffff',
        '8928308282bffff',
        '8928308283bffff',
        '89283082857ffff',
        '892830828abffff',
        '89283082847ffff',
        '89283082867ffff',
        '89283082803ffff',
        h,
        '89283082807ffff',
        '8928308280bffff',
    }

    assert out == expected
Exemplo n.º 3
0
def test_hex_range_pentagon():
    h = '821c07fffffffff'  # a pentagon

    # should consist of `h` and it's 5 neighbors
    out = h3.hex_range(h, 1)

    expected = {
        h,
        '821c17fffffffff',
        '821c1ffffffffff',
        '821c27fffffffff',
        '821c2ffffffffff',
        '821c37fffffffff',
    }

    assert out == expected
Exemplo n.º 4
0
def test_hex_range():
    h = '8928308280fffff'
    out = h3.hex_range(h, 1)
    assert len(out) == 1 + 6

    expected = {
        '8928308280bffff',
        '89283082807ffff',
        h,
        '89283082877ffff',
        '89283082803ffff',
        '89283082873ffff',
        '8928308283bffff',
    }

    assert out == expected
Exemplo n.º 5
0
 def neighbors(self):
     """Returns the neighbors of a given node as a list."""
     # return h3.hex_ring(self.hex_id, 1)
     return h3.hex_range(self.hex_id, 1)