Holoviews/Datashaded map overlay not displaying

392 Views Asked by At

I am using the code below to get a Panel dashboard with a dropdown select box, a histogram and a map.

import pandas as pd
import holoviews as hv
from holoviews.operation.datashader import datashade, rasterize, shade
import panel as pn
from holoviews.element.tiles import OSM
import hvplot.pandas

    
df = pd.read_parquet('cleanedFiles/AllMNO.parquet')
mno = pn.widgets.Select(options=df['mnc'].unique().tolist())

@pn.depends(mno)
def mnoStats(operator):
    return'### Operator {} has {} samples'.format(operator, len(df[df['mnc'] == operator]))

@pn.depends(mno)
def plotMap(mno):
    opts = dict(width=700, height=300, tools=['hover'])
    tiles = OSM().opts(alpha=0.4, xaxis=None, yaxis=None)
    points = hv.Points(df[df['mnc'] == mno], ['latitude', 'longitude'])
    rasterized = shade(rasterize(points, x_sampling=1, y_sampling=1)).opts(**opts)
    return tiles*rasterized


def plotHist(df):
    return df.hvplot.hist(y='rsrp', by='mnc', bins=20)

pn.Row(pn.Column(pn.WidgetBox('## Ofcom scanner data', mno, mnoStats)),
       pn.Column(plotHist(df))).servable()
pn.Row(plotMap).servable()

The dropdown selector and histogram appear as expected, however I get a 'blocky' image for the map as below. I wanted to get the locations (lat/longs) of the measurements each coloured / datashaded by the signal level denoted by the column 'rsrp'

Panel Dashboard

Please advice how this can be corrected.

1

There are 1 best solutions below

2
On

According to the holoviews docs, hv.rasterize is a high-level resampling interface and passes parameters to several internal methods:

holoviews.core.operation.Operation: group, input_ranges

holoviews.operation.datashader.LinkableOperation: link_inputs

holoviews.operation.datashader.ResamplingOperation: dynamic, streams, expand, height, width, x_range, y_range, x_sampling, y_sampling, target, element_type, precompute

holoviews.operation.datashader.AggregationOperation: vdim_prefix

Based on this, it looks like your arguments x_sampling and y_sampling are passed to ResamplingOperation, which are described:

x_sampling = param.Number(allow_None=True, inclusive_bounds=(True, True), label=’X sampling’)
Specifies the smallest allowed sampling interval along the x axis.

y_sampling = param.Number(allow_None=True, inclusive_bounds=(True, True), label=’Y sampling’)
Specifies the smallest allowed sampling interval along the y axis.

So, I'd guess that the issue is that providing the arguments x_sampling=1, y_sampling=1 to rasterize has the effect of aggregating all of your data to 1 degree, or approximately 110 km/70 mile blocks, which is causing the blockiness in your figure. Changing these parameters to a smaller value, such as 0.1 or smaller, should resolve the issue, as long as your data itself has sufficient resolution.