Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can Numba or Jax be used to speedup processes #122

Open
mattijn opened this issue Apr 29, 2021 · 4 comments
Open

Can Numba or Jax be used to speedup processes #122

mattijn opened this issue Apr 29, 2021 · 4 comments

Comments

@mattijn
Copy link
Owner

mattijn commented Apr 29, 2021

As raised in #110 (comment), it might be good to study if Numba can be optionally used to speed up processes within computations.

@brotherofken
Copy link

Hi! Regarding speedups, correct me if I'm wrong.
Great speed-up might be achieved by parallelization of this loop: https://github.com/mattijn/topojson/blob/master/topojson/ops.py#L627

@mattijn
Copy link
Owner Author

mattijn commented Sep 17, 2021

Thanks for commenting! This might be one of the locations that can be parallelized if simplification is a bottleneck for you. In my experience the computation of the Topology itself is sometimes more troublesome.

The line you point to is for shapely simplification, it is also possible to use the optional package simplification, see https://mattijn.github.io/topojson/example/settings-tuning.html#simplify_algorithm.

Although that is also a for-loop: https://github.com/mattijn/topojson/blob/master/topojson/ops.py#L635.

Another option to speedup pre/topo-simplification is too see how shapely 2.0 (pygeos) will perform. If there is support for ragged-arrays than the simplification of linestrings/arcs can probably be done on array level in C.

@mattijn
Copy link
Owner Author

mattijn commented Jun 22, 2022

Comparison against https://strk.kbt.io/blog/2012/04/13/simplifying-a-map-layer-using-postgis-topology/
Simplifying a map layer using PostGIS topology
Posted on 13 April, 2012

Total seconds ~13, vertices down to 1369 (from 47036).


Python topojson timing:

Total milliseconds ~457, vertices down to 1015. ~28x faster. Maybe due to better hardware.


Used code

import topojson as tp
import geopandas as gpd
import numpy as np

gdf = gpd.read_file(r"https://www.geotests.net/cours/sigma/webmapping/donnees_pg/GEOFLADept_FR_Corse_AV_L93.zip")
gdf.head()

# building topology
topo = tp.Topology(gdf, prequantize=3000)  # 270ms

# apply simplify on arcs
topo = topo.toposimplify(10000)  # 164ms

# visualize
topo.to_alt()  # 94ms

# or as oneliner
# tp.Topology(gdf, prequantize=10000, toposimplify=10000).to_alt()  # 457ms

image

# count vertices
arcs = topo.to_dict()['arcs']
np.sum([len(arc) for arc in arcs])
1015

@mattijn
Copy link
Owner Author

mattijn commented Sep 8, 2022

Or Jax

@mattijn mattijn changed the title Can Numba be used to speedup processes Can Numba or Jax be used to speedup processes Sep 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants