Seattle Lidar#

Visualize Lidar Scattered Point Elevation Data#

This notebook uses Datashader to visualize Lidar elevation data from the Puget Sound Lidar consortium, a source of Lidar data for the Puget Sound region of the state of Washington, U.S.A.

Lidar Elevation Data#

Example X,Y,Z scattered point elevation data from the unpacked 7zip files (unpacked as .gnd files)

! head ../data/q47122d2101.gnd

The Seattle area example below loads 25 .gnd elevation files like the one above. We’ll download, cache and read the data using intake.

import intake

cat = intake.open_catalog('./catalog.yml')
lidar = cat.seattle_lidar()
df = lidar.to_dask()
0 1293274.13 181399.80 435.79
1 1293278.38 181393.05 434.58
2 1293272.96 181401.08 435.86
3 1293271.02 181401.13 435.73
4 1293270.85 181407.80 436.15

Geographic Metadata#

Since the data are geographic, we need to know the coordinate reference system (CRS) of the X and Y. All the geographic metadata is stored in the data source entry in the intake catalog.

from pyproj.transformer import Transformer
'State Plane Coordinate System Washington North FIPS 4601'
transformer = Transformer.from_crs('epsg:2855','epsg:3857')  
# Washington State Plane North EPSG code and Mercator projection EPSG code   
FT_2_M = 0.3048  

def convert_coords(df):
    lon, lat = transformer.transform(df.X.values * FT_2_M, df.Y.values * FT_2_M)
    df['meterswest'], df['metersnorth'] = lon, lat 
    return df[['meterswest', 'metersnorth', 'Z']]

Try out the convert_coords function on a subset of the data

meterswest metersnorth Z
0 -1.360741e+07 6.022197e+06 435.79
1 -1.360741e+07 6.022194e+06 434.58
2 -1.360742e+07 6.022198e+06 435.86
3 -1.360742e+07 6.022198e+06 435.73
4 -1.360742e+07 6.022201e+06 436.15

Convert the coordinates#

Since our real dataset is large and partitioned using dask, we need to think about how to apply the convert_coords function to our data.

import dask
import dask.distributed
import dask.delayed



Connection method: Cluster object Cluster type: distributed.LocalCluster

Cluster Info

Explore the task graph to figure out a performant way to split up the coords conversion. First we’ll try with using dask.delayed.


We can see that even though we thought dask.delayed would help, in actuality we would be requiring all the processes to be done first and then the conversion would happen on the whole dataset in one go. Another approach would be to use dask.map_partitions to do the conversion on each piece of the data.

df_merc = df.map_partitions(convert_coords)

Now that we have set up the task graph, we can use df_merc directly to do the computations on the fly. However, since this dataset fits in memory on my computer, I will do the computation and keep the output in memory for quick use when plotting.

NOTE: This next cell takes about a minute to run. Take a look at the dask dashboard at the location specified above to watch the task progression.

dataset = df_merc.compute()
2023-11-03 12:12:33,731 - distributed.worker.memory - WARNING - Unmanaged memory use is high. This may indicate a memory leak or the memory may not be released to the OS; see for more information. -- Unmanaged memory: 2.34 GiB -- Worker memory limit: 3.38 GiB
CPU times: user 4.5 s, sys: 10.3 s, total: 14.8 s
Wall time: 1min 43s

If all the data doesn’t fit in memory on your machine, try downsampling the data from each file to only keep 1/100th of the total data. To avoid unnecessary computation, it is better to do the downsampling first and then convert the coordinates.

small = df.sample(frac=0.01).map_partitions(convert_coords)
small_dataset = small.compute()
CPU times: user 1.3 s, sys: 500 ms, total: 1.8 s
Wall time: 33.9 s


import geoviews as gv
import holoviews as hv
from holoviews import opts
from holoviews.operation.datashader import rasterize, rd


To simplify the exploration of the time required to display different data, define a function that accepts a regular pandas dataframe or a dask delayed dataframe.

def plot(data, **kwargs):
    """Plot point elevation data, rasterizing by mean elevation"""
    points = hv.Points(data, kdims=['meterswest', 'metersnorth'], vdims=['Z'])
    image_opts = opts.Image(tools=['hover'], cmap='blues_r', colorbar=True,
                            width=800, height=800, xaxis=None, yaxis=None)
    return rasterize(points, aggregator=rd.mean('Z'), precompute=True, **kwargs).options(image_opts)

We’ll also declare a tiler to use for background imagery.

tiles = gv.tile_sources.EsriImagery()

Then we will construct the plot out of rasterized point data and tiles.

tiles * plot(small_dataset)