Create inscribed circlesΒΆ
This notebook creates a center and a radius of a maximum inscribed circle of each enclosed tessellation cell. We will need it to generate distance-based weights used to measure contextual characters.
It requires custom piece of code within pygeos. Therefore, we use a custom docker container based on docker/Dockerfile
.
from dask.distributed import Client, LocalCluster, as_completed
from tqdm.notebook import tqdm
from time import time
client = Client(LocalCluster())
client
Client
|
Cluster
|
pygeos.constructive.maximum_inscribed_circle
is custom function implemented in https://github.com/martinfleis/pygeos/tree/circle branch. It is likely that it will, in some form, be part of the future release of pygeos.
def _circle(chunk):
import geopandas as gpd
import pygeos
gpd._compat.USE_PYGEOS = True
s = time()
df = gpd.read_parquet(f'../../urbangrammar_samba/spatial_signatures/tessellation/tess_{chunk}.pq', columns=['hindex', 'tessellation'])
geoms = df.tessellation.values.data
insc = pygeos.constructive.maximum_inscribed_circle(geoms, 0.1)
lenghts = pygeos.length(insc)
points = pygeos.points(pygeos.get_coordinates(insc)[::2])
res = gpd.GeoDataFrame({'hindex': df.hindex, 'radius': lenghts}, geometry=points, crs=27700, index=df.index)
res.to_parquet(f'../../urbangrammar_samba/spatial_signatures/inscribed_circle/circle_{chunk}.pq')
return f"Chunk {chunk} processed sucessfully in {time() - s} seconds."
%%time
workers=16
inputs = iter(range(103))
futures = [client.submit(_circle, next(inputs)) for i in range(workers)]
ac = as_completed(futures)
for finished_future in ac:
# submit new future
try:
new_future = client.submit(_circle, next(inputs))
ac.add(new_future)
except StopIteration:
pass
print(finished_future.result())
Chunk 11 processed sucessfully in 75.18252611160278 seconds.
Chunk 3 processed sucessfully in 79.87826347351074 seconds.
Chunk 0 processed sucessfully in 86.3075304031372 seconds.
Chunk 2 processed sucessfully in 89.55268573760986 seconds.
Chunk 10 processed sucessfully in 90.74024438858032 seconds.
Chunk 1 processed sucessfully in 97.34478044509888 seconds.
Chunk 9 processed sucessfully in 100.90103268623352 seconds.
Chunk 15 processed sucessfully in 108.83816909790039 seconds.
Chunk 13 processed sucessfully in 111.28670144081116 seconds.
Chunk 7 processed sucessfully in 112.3213279247284 seconds.
Chunk 8 processed sucessfully in 115.32112979888916 seconds.
Chunk 14 processed sucessfully in 122.33609461784363 seconds.
Chunk 4 processed sucessfully in 127.47185468673706 seconds.
Chunk 17 processed sucessfully in 79.50266242027283 seconds.
Chunk 18 processed sucessfully in 74.23960661888123 seconds.
Chunk 16 processed sucessfully in 86.40599298477173 seconds.
Chunk 12 processed sucessfully in 167.05304145812988 seconds.
Chunk 20 processed sucessfully in 79.75736093521118 seconds.
Chunk 21 processed sucessfully in 80.58741903305054 seconds.
Chunk 22 processed sucessfully in 80.6435329914093 seconds.
Chunk 25 processed sucessfully in 72.32591104507446 seconds.
Chunk 23 processed sucessfully in 79.83560848236084 seconds.
Chunk 19 processed sucessfully in 105.1453025341034 seconds.
Chunk 5 processed sucessfully in 195.1716525554657 seconds.
Chunk 28 processed sucessfully in 73.44700741767883 seconds.
Chunk 6 processed sucessfully in 207.29619550704956 seconds.
Chunk 24 processed sucessfully in 106.48440980911255 seconds.
Chunk 27 processed sucessfully in 102.46933102607727 seconds.
Chunk 26 processed sucessfully in 128.02418613433838 seconds.
Chunk 29 processed sucessfully in 88.51605463027954 seconds.
Chunk 30 processed sucessfully in 88.9432635307312 seconds.
Chunk 31 processed sucessfully in 94.05712509155273 seconds.
Chunk 36 processed sucessfully in 76.88225984573364 seconds.
Chunk 34 processed sucessfully in 85.03011465072632 seconds.
Chunk 33 processed sucessfully in 93.47328281402588 seconds.
Chunk 35 processed sucessfully in 93.31725096702576 seconds.
Chunk 39 processed sucessfully in 84.95077896118164 seconds.
Chunk 37 processed sucessfully in 103.69995832443237 seconds.
Chunk 43 processed sucessfully in 78.75121450424194 seconds.
Chunk 41 processed sucessfully in 98.14898085594177 seconds.
Chunk 32 processed sucessfully in 151.09507703781128 seconds.
Chunk 44 processed sucessfully in 82.31604027748108 seconds.
Chunk 42 processed sucessfully in 114.99541783332825 seconds.
Chunk 47 processed sucessfully in 82.50904440879822 seconds.
Chunk 46 processed sucessfully in 99.27299094200134 seconds.
Chunk 45 processed sucessfully in 102.41146564483643 seconds.
Chunk 52 processed sucessfully in 73.63012290000916 seconds.
Chunk 49 processed sucessfully in 94.9011583328247 seconds.
Chunk 40 processed sucessfully in 158.7320909500122 seconds.
Chunk 50 processed sucessfully in 96.84051871299744 seconds.
Chunk 48 processed sucessfully in 101.36079668998718 seconds.
Chunk 38 processed sucessfully in 171.39834427833557 seconds.
Chunk 51 processed sucessfully in 94.71584892272949 seconds.
Chunk 55 processed sucessfully in 71.53085708618164 seconds.
Chunk 53 processed sucessfully in 93.04612755775452 seconds.
Chunk 54 processed sucessfully in 96.173100233078 seconds.
Chunk 56 processed sucessfully in 99.22452998161316 seconds.
Chunk 57 processed sucessfully in 92.65790843963623 seconds.
Chunk 58 processed sucessfully in 91.41398882865906 seconds.
Chunk 59 processed sucessfully in 91.25998950004578 seconds.
Chunk 60 processed sucessfully in 86.61306047439575 seconds.
Chunk 63 processed sucessfully in 89.7208001613617 seconds.
Chunk 62 processed sucessfully in 107.36594891548157 seconds.
Chunk 69 processed sucessfully in 96.30247735977173 seconds.
Chunk 65 processed sucessfully in 112.9035873413086 seconds.
Chunk 68 processed sucessfully in 113.88563823699951 seconds.
Chunk 66 processed sucessfully in 120.90739822387695 seconds.
Chunk 70 processed sucessfully in 105.3549063205719 seconds.
Chunk 72 processed sucessfully in 85.64587545394897 seconds.
Chunk 71 processed sucessfully in 107.28501224517822 seconds.
Chunk 74 processed sucessfully in 88.7121856212616 seconds.
Chunk 61 processed sucessfully in 163.17906045913696 seconds.
Chunk 67 processed sucessfully in 147.67236065864563 seconds.
Chunk 64 processed sucessfully in 162.09181380271912 seconds.
Chunk 73 processed sucessfully in 117.76950526237488 seconds.
Chunk 76 processed sucessfully in 105.27343320846558 seconds.
Chunk 78 processed sucessfully in 80.98367524147034 seconds.
Chunk 75 processed sucessfully in 114.53599977493286 seconds.
Chunk 77 processed sucessfully in 101.85784840583801 seconds.
Chunk 79 processed sucessfully in 78.74561047554016 seconds.
Chunk 81 processed sucessfully in 81.6527853012085 seconds.
Chunk 82 processed sucessfully in 88.69246315956116 seconds.
Chunk 80 processed sucessfully in 102.27177405357361 seconds.
Chunk 84 processed sucessfully in 86.50438046455383 seconds.
Chunk 83 processed sucessfully in 112.60691523551941 seconds.
Chunk 90 processed sucessfully in 72.91517686843872 seconds.
Chunk 86 processed sucessfully in 100.6086437702179 seconds.
Chunk 93 processed sucessfully in 74.9451117515564 seconds.
Chunk 91 processed sucessfully in 82.35606026649475 seconds.
Chunk 88 processed sucessfully in 110.23749661445618 seconds.
Chunk 94 processed sucessfully in 75.01656985282898 seconds.
Chunk 87 processed sucessfully in 120.26353168487549 seconds.
Chunk 96 processed sucessfully in 73.48248147964478 seconds.
Chunk 85 processed sucessfully in 132.50018501281738 seconds.
Chunk 95 processed sucessfully in 89.38614797592163 seconds.
Chunk 92 processed sucessfully in 109.92542171478271 seconds.
Chunk 97 processed sucessfully in 79.90889811515808 seconds.
Chunk 99 processed sucessfully in 72.52620553970337 seconds.
Chunk 89 processed sucessfully in 143.69170308113098 seconds.
Chunk 102 processed sucessfully in 58.38040852546692 seconds.
Chunk 100 processed sucessfully in 68.74128866195679 seconds.
Chunk 98 processed sucessfully in 98.71787142753601 seconds.
Chunk 101 processed sucessfully in 97.21494770050049 seconds.
CPU times: user 19.2 s, sys: 2.08 s, total: 21.2 s
Wall time: 11min 48s