Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Updated installation instructions * Player fixes from lancelot1969 * Restored apps from prior to #81 * Updated pins
- Loading branch information
Showing
7 changed files
with
67 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,40 @@ | ||
import os | ||
import holoviews as hv, geoviews as gv, param, parambokeh, dask.dataframe as dd, cartopy.crs as crs | ||
import holoviews as hv, geoviews as gv, param, dask.dataframe as dd, cartopy.crs as crs | ||
import panel as pn | ||
|
||
from colorcet import cm_n | ||
from holoviews.operation.datashader import datashade | ||
from colorcet import cm | ||
from holoviews.operation.datashader import rasterize, shade | ||
from holoviews.streams import RangeXY | ||
|
||
hv.extension('bokeh', logo=False) | ||
|
||
usecols = ['dropoff_x','dropoff_y','pickup_x','pickup_y','dropoff_hour','pickup_hour','passenger_count'] | ||
df = dd.read_parquet(os.path.join(os.path.dirname(__file__),'..','..','..','data','nyc_taxi_wide.parq'))[usecols].persist() | ||
|
||
url='https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{Z}/{Y}/{X}.jpg' | ||
tiles = gv.WMTS(url,crs=crs.GOOGLE_MERCATOR) | ||
df = dd.read_parquet('../../data/nyc_taxi_wide.parq')[usecols].persist() | ||
opts = dict(width=1000,height=600,xaxis=None,yaxis=None,bgcolor='black',show_grid=False) | ||
max_pass = int(df.passenger_count.max().compute()+1) | ||
cmaps = ['fire','bgy','bgyw','bmy','gray','kbc'] | ||
|
||
|
||
class NYCTaxiExplorer(hv.streams.Stream): | ||
class NYCTaxiExplorer(param.Parameterized): | ||
alpha = param.Magnitude(default=0.75, doc="Alpha value for the map opacity") | ||
colormap = param.ObjectSelector(default=cm_n["fire"], objects=cm_n.values()) | ||
hour = param.Integer(default=None, bounds=(0, 23), doc="All hours by default; drag to select one hour") | ||
passengers = param.Range(default=(0,max_pass), bounds=(0,max_pass)) | ||
cmap = param.ObjectSelector(cm['fire'], objects={c:cm[c] for c in cmaps}) | ||
hour = param.Range(default=(0, 24), bounds=(0, 24)) | ||
location = param.ObjectSelector(default='dropoff', objects=['dropoff', 'pickup']) | ||
|
||
def make_view(self, x_range, y_range, **kwargs): | ||
map_tiles = tiles.options(alpha=self.alpha, **opts) | ||
points = hv.Points(df, [self.location+'_x', self.location+'_y'], self.location+'_hour') | ||
selection = {self.location+"_hour":self.hour if self.hour else (0,24), "passenger_count":self.passengers} | ||
taxi_trips = datashade(points.select(**selection), x_sampling=1, y_sampling=1, cmap=self.colormap, | ||
dynamic=False, x_range=x_range, y_range=y_range, width=1000, height=600) | ||
return map_tiles * taxi_trips | ||
|
||
explorer = NYCTaxiExplorer(name="NYC Taxi Trips") | ||
dmap = hv.DynamicMap(explorer.make_view, streams=[explorer, RangeXY()]) | ||
|
||
plot = hv.renderer('bokeh').instance(mode='server').get_plot(dmap) | ||
parambokeh.Widgets(explorer, view_position='right', callback=explorer.event, plots=[plot.state], | ||
mode='server') | ||
@param.depends('location', 'hour') | ||
def points(self): | ||
points = hv.Points(df, kdims=[self.location+'_x', self.location+'_y'], vdims=['dropoff_hour']) | ||
if self.hour != (0, 24): points = points.select(dropoff_hour=self.hour) | ||
return points | ||
|
||
@param.depends('alpha') | ||
def tiles(self): | ||
return gv.tile_sources.StamenTerrain.options(alpha=self.alpha, **opts) | ||
|
||
def view(self,**kwargs): | ||
points = hv.DynamicMap(self.points) | ||
agg = rasterize(points, x_sampling=1, y_sampling=1, width=600, height=400) | ||
stream = hv.streams.Params(self, ['cmap']) | ||
tiles = hv.DynamicMap(self.tiles) | ||
return tiles * shade(agg, streams=[stream]) | ||
|
||
taxi = NYCTaxiExplorer(name="NYC Taxi Trips") | ||
pn.Row(taxi, taxi.view()).servable() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,28 @@ | ||
import os | ||
import holoviews as hv, geoviews as gv, param, parambokeh, dask.dataframe as dd, cartopy.crs as crs | ||
|
||
from holoviews.operation.datashader import datashade | ||
import holoviews as hv, geoviews as gv, param, dask.dataframe as dd, panel as pn | ||
from holoviews.operation.datashader import datashade, rasterize, shade | ||
from holoviews.streams import RangeXY | ||
from colorcet import cm_n | ||
from colorcet import cm | ||
|
||
hv.extension('bokeh', logo=False) | ||
|
||
df = dd.read_parquet(os.path.join(os.path.dirname(__file__),'..','..','data','osm-1billion.snappy.parq')).persist() | ||
|
||
url='https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{Z}/{Y}/{X}.jpg' | ||
map_tiles = gv.WMTS(url,crs=crs.GOOGLE_MERCATOR) | ||
|
||
opts1 = dict(width=1000, height=600, xaxis=None, yaxis=None, bgcolor='black', show_grid=False) | ||
opts2 = dict(width=1000, height=600, x_sampling=1, y_sampling=1, dynamic=False) | ||
df = dd.read_parquet('../../data/osm-1billion.snappy.parq').persist() | ||
|
||
class OSMExplorer(hv.streams.Stream): | ||
alpha = param.Magnitude(default=0.75, doc="Map opacity") | ||
colormap = param.ObjectSelector(default=cm_n["fire"], objects=cm_n.values()) | ||
cmaps = ['fire','bgy','bgyw','bmy','gray','kbc'] | ||
topts = dict(width=900,height=600,xaxis=None,yaxis=None,bgcolor='black',show_grid=False) | ||
|
||
def make_view(self, x_range, y_range, **kwargs): | ||
tiles = map_tiles.options(alpha=self.alpha, **opts1) | ||
points = hv.Points(df, ['x','y']) | ||
return tiles * datashade(points, cmap=self.colormap, x_range=x_range, y_range=y_range, **opts2) | ||
class OSM(param.Parameterized): | ||
alpha = param.Magnitude(default=0.75, doc="Map tile opacity") | ||
cmap = param.ObjectSelector(cm['fire'], objects={c:cm[c] for c in cmaps}) | ||
|
||
@param.depends('alpha') | ||
def tiles(self): | ||
return gv.tile_sources.EsriImagery.options(alpha=self.alpha, **topts) | ||
|
||
explorer = OSMExplorer(name="Open Street Map GPS") | ||
dmap = hv.DynamicMap(explorer.make_view, streams=[explorer, RangeXY()]) | ||
@param.depends() | ||
def view(self): | ||
points = hv.DynamicMap(hv.Points(df, kdims=['x', 'y'])) | ||
raster = rasterize(points, x_sampling=1, y_sampling=1, width=900, height=600) | ||
return hv.DynamicMap(self.tiles) * shade(raster, streams=[hv.streams.Params(self, ['cmap'])]) | ||
|
||
plot = hv.renderer('bokeh').instance(mode='server').get_plot(dmap) | ||
parambokeh.Widgets(explorer, view_position='right', callback=explorer.event, plots=[plot.state], mode='server') | ||
osm = OSM(name="Open Street Map GPS") | ||
pn.Row(osm, osm.view).servable() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters