Skip to content

Commit

Permalink
(#32) new requirement: bokeh <2.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
francoislaurent committed Apr 1, 2021
1 parent 122e461 commit daf7b78
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 49 deletions.
15 changes: 11 additions & 4 deletions scripts/tramway-browse
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,19 @@ a.env.script = '{}'
browser)
script.write(source)
script.flush()
p = subprocess.Popen([sys.executable, script.name],
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
try:
ret = subprocess.run([sys.executable, script.name], check=True)
ret = p.communicate()
except KeyboardInterrupt:
ret = 'interrupted'
ret = p.communicate()
script.close()
return ret
def tostr(s):
if isinstance(s, bytes):
s = s.decode('utf8')
return s
ret = [ tostr(r) for r in ret ]
return [ r for r in ret if r ]


def main():
Expand All @@ -46,7 +53,7 @@ def main():
parser.add_argument('files', nargs='*', help='for example: *.rwa or */*.rwa')
parser.add_argument('--browser', default='Firefox', choices=['Firefox','Chrome','Edge','Ie','Opera','Safari','WebKitGTK'])
parser.add_argument('--colormap', help="Matplotlib colormap name")
print(browse(**parser.parse_args().__dict__))
[ print(ret) for ret in browse(**parser.parse_args().__dict__) ]

if __name__ == '__main__':
main()
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
extras_require = {
'animate': ['opencv-python', 'scikit-image', 'tqdm'],
'roi': ['polytope', 'cvxopt', 'tqdm'],
'webui': ['bokeh>=2.0.2', 'selenium']}
'webui': ['bokeh >=2.0.2, <2.3.0', 'selenium']}
tests_require = ['pytest']


Expand Down
5 changes: 4 additions & 1 deletion tramway/plot/bokeh/analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,13 +268,16 @@ def make_time_view(self):
self.time_slider.on_change('value_throttled', lambda attr, old, new: self.refresh_map())
return self.time_slider
def make_space_view(self):
self.main_figure = f = figure(disabled=True, toolbar_location=None, active_drag=None,
self.main_figure = f = figure(disabled=True, toolbar_location=None,
match_aspect=True, tools='pan, wheel_zoom, reset')
self.main_figure.toolbar.active_drag = None
f.background_fill_color = f.border_fill_color = None
self.colorbar_figure = f = figure(disabled=True, toolbar_location=None,
min_border=0, outline_line_color=None, title_location='right', plot_width=112)
f.background_fill_color = f.border_fill_color = None
f.title.align = 'center'
add_colorbar(self.main_figure, colorbar_figure=f,
colormap=self.model.analyzer.browser.colormap)
#f.visible = False
self.visibility_controls = CheckboxGroup(disabled=True, labels=['Localizations','Trajectories','Hide map'], active=[])
def _update(attr, old, new):
Expand Down
120 changes: 77 additions & 43 deletions tramway/plot/bokeh/map.py
Original file line number Diff line number Diff line change
Expand Up @@ -411,54 +411,87 @@ def scalar_map_2d(cells, values, clim=None, figure=None, delaunay=False,
if colorbar:
low = clim.get('vmin', vmin)
high = clim.get('vmax', vmax)
if colormap is None:
color_map = 'Viridis256'
elif colormap.lower() in ('greys','inferno','magma','plasma','viridis','cividis','turbo'):
color_map = colormap[0].upper()+colormap[1:].lower()+'256'
if False:
add_colorbar(figure, colormap, low, high, unit, clabel, colorbar_figure)
else:
try:
import colorcet as cc
except ImportError:
color_map = colormap # let us try anyway...
else:
try:
color_map = getattr(cc, colormap)
except AttributeError:
color_map = colormap
try:
color_map = LinearColorMapper(palette=color_map, low=low, high=high)
except ValueError as e:
try:
import colorcet
except ImportError:
raise ValueError('colormap not found; try installing the colorcet package') from e
else:
raise
color_bar = ColorBar(color_mapper=color_map, ticker=BasicTicker(),
border_line_color=None, margin=0)
color_bar.background_fill_color = None
#glyph_renderers.append(color_bar)
if unit is None:
unit = clabel
if colorbar_figure is None:
if unit is not None:
color_bar.title = unit
figure.add_layout(color_bar, place='right')
else:
if unit is not None:
colorbar_figure.title.text = unit
colorbar_figure.title_location = 'right'
colorbar_figure.title.align = 'center'
color_bar.height = colorbar_figure.plot_height
if isinstance(colorbar_figure.center[-1], ColorBar):
colorbar_figure.center = colorbar_figure.center[:-1]
colorbar_figure.add_layout(color_bar, place='center')
#print(colorbar_figure.center, colorbar_figure.plot_height, color_bar.width, color_bar.height, color_bar.margin, color_bar.padding)
update_colorbar(figure, low, high, unit, clabel, colorbar_figure)

#plt.show(figure)
return glyph_renderers


def add_colorbar(figure, colormap=None, low=0, high=1, unit=None, clabel=None, colorbar_figure=None):
if colormap is None:
color_map = 'Viridis256'
elif colormap.lower() in ('greys','inferno','magma','plasma','viridis','cividis','turbo'):
color_map = colormap[0].upper()+colormap[1:].lower()+'256'
else:
try:
import colorcet as cc
except ImportError:
color_map = colormap # let us try anyway...
else:
try:
color_map = getattr(cc, colormap)
except AttributeError:
color_map = colormap
try:
color_map = LinearColorMapper(palette=color_map, low=low, high=high,
name='color_mapper')
except ValueError as e:
try:
import colorcet
except ImportError:
raise ValueError('colormap not found; try installing the colorcet package') from e
else:
raise
color_bar = ColorBar(color_mapper=color_map, ticker=BasicTicker(name='ticker'),
border_line_color=None, margin=0, name='color_bar')
color_bar.background_fill_color = None
#glyph_renderers.append(color_bar)
if unit is None:
unit = clabel
if colorbar_figure is None:
if unit is not None:
color_bar.title = unit
figure.add_layout(color_bar, place='right')
else:
if unit is not None:
colorbar_figure.title.text = unit
colorbar_figure.title_location = 'right'
colorbar_figure.title.align = 'center'
color_bar.height = colorbar_figure.plot_height
if isinstance(colorbar_figure.center[-1], ColorBar):
colorbar_figure.center = colorbar_figure.center[:-1]
colorbar_figure.add_layout(color_bar, place='center')
#print(colorbar_figure.center, colorbar_figure.plot_height, color_bar.width, color_bar.height, color_bar.margin, color_bar.padding)


def update_colorbar(figure, low=None, high=None, unit=None, clabel=None, colorbar_figure=None):
if colorbar_figure is not None:
figure = colorbar_figure
color_bar = figure.select(name='color_bar')[0]
if not (low is None and high is None):
color_map = figure.select(name='color_mapper')[0]
palette = color_map.palette
#color_map.update(low=low, high=high)
#palette = 'Greys256'
color_map = LinearColorMapper(palette=palette, low=low, high=high,
name='color_mapper')
color_bar.update(color_mapper=color_map)
if unit is None:
unit = clabel
if colorbar_figure is None:
if unit is not None:
color_bar.title = unit
else:
if unit is not None:
colorbar_figure.title.text = unit
#color_bar.height = colorbar_figure.plot_height
#if isinstance(colorbar_figure.center[-1], ColorBar):
# colorbar_figure.center = colorbar_figure.center[:-1]


def plot_delaunay(cells, labels=None, color=None, style='-',
figure=None, linewidth=1, **kwargs):
"""
Expand Down Expand Up @@ -675,5 +708,6 @@ def field_map_2d(cells, values, angular_width=30.0,



__all__ = ['plot_points', 'plot_trajectories', 'plot_delaunay', 'scalar_map_2d', 'field_map_2d']
__all__ = ['plot_points', 'plot_trajectories', 'plot_delaunay', 'scalar_map_2d', 'field_map_2d',
'add_colorbar']

0 comments on commit daf7b78

Please sign in to comment.