mapbox / make-surface

Vector surfaces creation routines
MIT License
89 stars 18 forks source link

Speed up sampling of raster values #59

Closed dnomadb closed 9 years ago

dnomadb commented 9 years ago

Most time for grabbing raster values for facet geometry is spent here: https://github.com/mapbox/make-surface/blob/triangle-indexing/makesurface/scripts/fill_facets.py#L57

To help with https://github.com/mapbox/weather-data/issues/71:

cc: @ian29 @andreasviglakis @rclark @sgillies

dnomadb commented 9 years ago

Centroid extraction (pulling data values from a single pixel within the finest triangles) is looking to be a good bet. image

Speed Improvements

As this would allow us to skip rasterization, all np.where, and np.mean calculations, it is much faster - on the order of ~100x (anecdotal observation)

Accuracy

Testing for this over the weekend. Based on the amount of upsampling we are doing before sampling, I would think that the difference will be negligible, but this is yet to be determined.

dnomadb commented 9 years ago

This method is much faster than (rasterio.features.rasterize --> np.where --> np.mean), and preliminary results look ok. Going to use it and punt on accuracy testing for now, as the speed increase is significant.