Ejemplo n.º 1
0
def compute_frequency(client, city, entity, k=200):
    """Splits `city` in k^2 rectangles and save the frequency of `entity` in
    each of them as a matrix."""
    assert entity in [Entity.photo, Entity.checkin]
    freq_name = FREQUENCE_FILE.format(entity.name, city, k)
    try:
        mat_count = sio.loadmat(freq_name)['c']
        return mat_count
    except IOError:
        pass
    count = (k * k + 1) * [
        0,
    ]
    get_data = {Entity.photo: get_photos, Entity.checkin: get_checkins}[entity]
    coords = get_data(client, city)
    bbox = (cities.US + cities.EU)[cities.INDEX[city]]
    rectangles, rect_to_index, _ = mq.k_split_bbox(bbox, k)
    # count[0] is for potential points that do not fall in any region (it
    # must only happens because of rounding inprecision)
    count = (len(rectangles) + 1) * [
        0,
    ]
    for loc in coords:
        count[rect_to_index(loc) + 1] += 1
    mat_count = np.array(count[1:])
    sio.savemat(freq_name, {'c': mat_count}, do_compression=True)
    return mat_count
Ejemplo n.º 2
0
def compute_frequency(client, city, entity, k=200):
    """Splits `city` in k^2 rectangles and save the frequency of `entity` in
    each of them as a matrix."""
    assert entity in [Entity.photo, Entity.checkin]
    freq_name = FREQUENCE_FILE.format(entity.name, city, k)
    try:
        mat_count = sio.loadmat(freq_name)['c']
        return mat_count
    except IOError:
        pass
    count = (k*k+1)*[0, ]
    get_data = {Entity.photo: get_photos, Entity.checkin: get_checkins}[entity]
    coords = get_data(client, city)
    bbox = (cities.US+cities.EU)[cities.INDEX[city]]
    rectangles, rect_to_index, _ = mq.k_split_bbox(bbox, k)
    # count[0] is for potential points that do not fall in any region (it
    # must only happens because of rounding inprecision)
    count = (len(rectangles)+1)*[0, ]
    for loc in coords:
        count[rect_to_index(loc)+1] += 1
    mat_count = np.array(count[1:])
    sio.savemat(freq_name, {'c': mat_count}, do_compression=True)
    return mat_count
Ejemplo n.º 3
0
        for val, poly in polys:
            if point.intersects(poly) and \
               point.intersection(poly).area > .6*size:
                res.append((tag, val))
                break
    return sorted(res, key=lambda x: x[1], reverse=True)


GRID_SIZE = 80
TOP_K = 2000
MIN_WIDTH = 1
MIN_HEIGHT = 1
MAX_SIZE = 4
MAX_SUPPORT = 250
REJECTED = 0
rectangles, dummy, index_to_rect = k_split_bbox(BBOX, GRID_SIZE)
if __name__ == '__main__':
    import sys
    # import random
    # random.seed(135)
    tag = 'museum' if len(sys.argv) <= 1 else sys.argv[1]
    tt = clock()
    # tmp = persistent.load_var('supported')
    # tags = [v[0] for v in tmp]
    # random.shuffle(tags)
    # tt = clock()
    # p = Pool(3)
    # p.map(spatial_scan, tags)
    # p.map(post_process, tags)
    # p.close()
    # consolidate(tags)
Ejemplo n.º 4
0
    for tag, polys in tags.items():
        for val, poly in polys:
            if point.intersects(poly) and \
               point.intersection(poly).area > .6*size:
                res.append((tag, val))
                break
    return sorted(res, key=lambda x: x[1], reverse=True)

GRID_SIZE = 80
TOP_K = 2000
MIN_WIDTH = 1
MIN_HEIGHT = 1
MAX_SIZE = 4
MAX_SUPPORT = 250
REJECTED = 0
rectangles, dummy, index_to_rect = k_split_bbox(BBOX, GRID_SIZE)
if __name__ == '__main__':
    import sys
    # import random
    # random.seed(135)
    tag = 'museum' if len(sys.argv) <= 1 else sys.argv[1]
    tt = clock()
    # tmp = persistent.load_var('supported')
    # tags = [v[0] for v in tmp]
    # random.shuffle(tags)
    # tt = clock()
    # p = Pool(3)
    # p.map(spatial_scan, tags)
    # p.map(post_process, tags)
    # p.close()
    # consolidate(tags)