Closed Jacob-Barhak closed 5 years ago
The rendering code path is hitting collate
which can be avoided if the hierarchy you build conforms to nesting structure described here. It should be possible to reorganize things so you don't hit collate but still offer the same functionality.
Thanks for the comment, yet the layout you pointed to shows raster images and holomap in different paths. How can I create a few combo boxes that allow me to switch between rasterized images? I assumed my solution was to use holoviews holomap. Can I do it with panel instead and still be able to generate a static html page that does not need a server to allow changing a combo box to switch between the rasterized images?
I know I should be able to do it with panel switching between html pages generated for each rasterized image using a tab layoout object. Yet since its multidimensional data, I want to use the combo boxes. If panel should work, I will switch to it since holoviews is moving towards integrating with it, yet I want to make sure I can do it before investing the effort.
Apart from adding collate, I think all you need is dynamic=False, which isn't a problem if you're exporting to HTML anyway. The underlying problem is that rasterize creates a DynamicMap if dynamic=True, and you can't simply collate and reorganize a dynamic process like that. Instead, this code should be rewritten to create one big DynamicMap with non-dynamic components, but that's a complete reorganization, and this should work for now since you don't need the result to be dynamic anyway...
import numpy
import matplotlib
import bokeh
from matplotlib.cm import viridis, plasma, gist_ncar, gist_stern, PuBu, Blues
import holoviews
from holoviews.operation.datashader import rasterize
holoviews.extension('bokeh')
#AggregationMethods = [ 'mean','max','mode','std']
AggregationMethods = [ 'mean','max']
Hows = [ 'linear', 'bilinear' ]
# uncomment the next line to see a different error message
#Hows = [ 'nearest', 'linear' ]
OutputImageFilePattern = 'TestImage_%s_%i_%s_%s'
ImageIntensityScale = 100000
PlotHeight = 100
PlotSizes = [500]
for library in ['numpy', 'matplotlib', 'holoviews']:
print ( library + ' ' + str(eval(library + '.__version__')))
def PlotCluster(MatrixClusters, MatrixDistances, OutputFile, How, AggregationMethod, PlotSize, PlotHeight = PlotHeight):
"plot the cluster"
DistBarData = holoviews.Image(MatrixDistances)
ShadedDistBar = rasterize (DistBarData, aggregator = AggregationMethod, interpolation = How, dynamic = False).opts(cmap=PuBu, xaxis=None, yaxis=None, height=PlotHeight, width=PlotSize, tools=['hover'], axiswise=True, framewise=True)
ClusterBarData = holoviews.Image(MatrixClusters)
ShadedClusterBar = rasterize (ClusterBarData, aggregator = AggregationMethod, interpolation = How, dynamic = False).opts(cmap=PuBu, xaxis=None, yaxis=None, height=PlotHeight, width=PlotSize, tools=['hover'], axiswise=True, framewise=True)
Merged = (ShadedDistBar + ShadedClusterBar).cols(1)
return Merged
HoloMapDict = {}
numpy.random.seed(1)
UnitDistanceVec = numpy.random.rand(25000)
UnitClusterVec = (numpy.random.rand(25000)*100).astype(int)
print (UnitDistanceVec[:10])
print (UnitClusterVec[:10])
BarSize = (PlotHeight,1)
UnitClusterVecRearranged = numpy.array(UnitClusterVec)
MatrixClusters = numpy.tile( UnitClusterVecRearranged, BarSize).astype(int)
UnitDistanceVecsRarranged = numpy.array(UnitDistanceVec)
UnitDistanceVecAsInt = (numpy.array(UnitDistanceVecsRarranged)/max(UnitClusterVec)*ImageIntensityScale).astype(int)
MatrixDistances = numpy.tile( UnitDistanceVecAsInt, BarSize)
for AggregationMethod in AggregationMethods:
for How in Hows:
for PlotSize in PlotSizes:
OutputFile = OutputImageFilePattern%('',PlotSize,How,AggregationMethod)
Merged = PlotCluster(MatrixClusters,MatrixDistances, OutputFile, How, AggregationMethod, PlotSize)
HoloMapDict[(AggregationMethod, How )] = Merged
Combined = holoviews.HoloMap(HoloMapDict, kdims=['Aggregation', 'interpolation']).collate()
holoviews.save(Combined, 'combined', 'html')
You can also use Panel for this, which would be very straightforward.
Thanks James, Eliminating Dynamic does fix the code so it will work, yet for some reason the saved holomap does not work as intended - with drop down boxes . The html file generated on my machine just shows the image for one holomap bin without the drop down menus one usually sees in a holomap - is this related to the fact that those are rasterized images? Or is this related to something else - I really want to have those drop down boxes if easy.
The widgets are there in Jupyter: @jlstevens, is there anything special that needs to be done for the widgets to be in the saved html file?
Sorry James, This is very odd, the html generated also has other artifacts like not following the correct color or size. Here is an image of what I see:
code versions I am using are: numpy 1.16.3 matplotlib 3.0.3 holoviews 1.12.1 Also: python 3.7.3 bokeh 1.1.0
If this is another problem, I'll be happy to open another issue. I tried panel tabs and it works nice, yet if possible, I would like this beautiful drop down menu functionality holoviews can offer.
Oh, the loss of options is just due to a debugging bit I had in the above code; now fixed (removed "Merged = holoviews.Image(MatrixDistances) + holoviews.Image(MatrixClusters)"). And Panel can give drop-down menus as well; should be fine to use either. I'd guess there's some JS missing from the HTML export, which is why I'm hoping @jlstevens or @philippjfr can investigate.
If this helps locate the issue, note that using panel save function of the holoviews object works well and shows the drop down menu. So it seems I have a solution. Thanks for the rapid responses.
One correction, when using panel to show the holoviews object, the drop down menus are shown, yet they are populated with the Cartesian product of all dimensions and selecting a value from those drop down boxes does not change the image. It seems that there is something not working even when this holoviews object is viewed when panel is generating the html.
Hi , Is there any other way in which i keep dynamic =True and still plot using Holomap and get the dynamic data available in each plot.
Is there any other way in which i keep dynamic =True and still plot using Holomap and get the dynamic data available in each plot.
No, a plot is either dynamic or isn't.
Hi, My Holomap is working fine when i am making dynamic=False i.e :-
def plotthis(datetime):
return rasterize(gv.TriMesh((tri_sub,gv.Points(verts)) ),**dynamic=False**).options(**opts)
allplot={k:plotthis(k)for k in perdelta(strt, strt + timedelta(days=1), timedelta(hours=9))}
hmap = hv.HoloMap(allplot, kdims='date')
hmap
Then Holomap is be working fine but i lost the dynamic property of plot i.e while zoomin no update of data. so i am thinking to plot using Holomap in which dyanmic data also work . :)
There is no way a HoloMap will ever support dynamic updates, that's the whole point of a HoloMap. If you want to have the dynamic features apply rasterize to the HoloMap, i.e.:
def plotthis(datetime):
return gv.TriMesh((tri_sub,gv.Points(verts)))
allplot={k:plotthis(k)for k in perdelta(strt, strt + timedelta(days=1), timedelta(hours=9))}
hmap = hv.HoloMap(allplot, kdims='date')
rasterize(hmap).options(**opts)
@philippjfr
Thanks alot for replying so fast.
After using the suggested code:-
`
return gv.TriMesh((tri_sub,gv.Points(verts))).options(**opts)
allplot={k:plotthis(k)for k in perdelta(strt, strt + timedelta(days=1), timedelta(hours=9))}
hmap = hv.HoloMap(allplot, kdims='date')
tt=rasterize(hmap)
tt
I am getting keyError
KeyError: (numpy.datetime64('2019-07-03T00:00:00.000000000'),)
:DynamicMap [date] `
Hi , Or i should do using Panel instead of Holomap for getting dynamic data ?
This specific problem was solved by James a long time ago - I should have been closed. So I am closing it so it wont bother the developers. There was another issue there with saving the html with the widgets which is related to another issue I started (https://github.com/pyviz/holoviews/issues/3849) that deals with saving.
To close this problem I am reiterating the code that will work.
import numpy
import matplotlib
import bokeh
from matplotlib.cm import viridis, plasma, gist_ncar, gist_stern, PuBu, Blues
import holoviews
from holoviews.operation.datashader import rasterize
holoviews.extension('bokeh')
#AggregationMethods = [ 'mean','max','mode','std']
AggregationMethods = [ 'mean','max']
Hows = [ 'linear', 'bilinear' ]
# uncomment the next line to see a different error message
#Hows = [ 'nearest', 'linear' ]
OutputImageFilePattern = 'TestImage_%s_%i_%s_%s'
ImageIntensityScale = 100000
PlotHeight = 100
PlotSizes = [500]
for library in ['numpy', 'matplotlib', 'holoviews']:
print ( library + ' ' + str(eval(library + '.__version__')))
def PlotCluster(MatrixClusters, MatrixDistances, OutputFile, How, AggregationMethod, PlotSize, PlotHeight = PlotHeight):
"plot the cluster"
DistBarData = holoviews.Image(MatrixDistances)
ShadedDistBar = rasterize (DistBarData, aggregator = AggregationMethod, interpolation = How, dynamic = False).opts(cmap=PuBu, xaxis=None, yaxis=None, height=PlotHeight, width=PlotSize, tools=['hover'], axiswise=True, framewise=True)
ClusterBarData = holoviews.Image(MatrixClusters)
ShadedClusterBar = rasterize (ClusterBarData, aggregator = AggregationMethod, interpolation = How, dynamic = False).opts(cmap=PuBu, xaxis=None, yaxis=None, height=PlotHeight, width=PlotSize, tools=['hover'], axiswise=True, framewise=True)
Merged = (ShadedDistBar + ShadedClusterBar).cols(1)
return Merged
HoloMapDict = {}
numpy.random.seed(1)
UnitDistanceVec = numpy.random.rand(25000)
UnitClusterVec = (numpy.random.rand(25000)*100).astype(int)
print (UnitDistanceVec[:10])
print (UnitClusterVec[:10])
BarSize = (PlotHeight,1)
UnitClusterVecRearranged = numpy.array(UnitClusterVec)
MatrixClusters = numpy.tile( UnitClusterVecRearranged, BarSize).astype(int)
UnitDistanceVecsRarranged = numpy.array(UnitDistanceVec)
UnitDistanceVecAsInt = (numpy.array(UnitDistanceVecsRarranged)/max(UnitClusterVec)*ImageIntensityScale).astype(int)
MatrixDistances = numpy.tile( UnitDistanceVecAsInt, BarSize)
for AggregationMethod in AggregationMethods:
for How in Hows:
for PlotSize in PlotSizes:
OutputFile = OutputImageFilePattern%('',PlotSize,How,AggregationMethod)
Merged = PlotCluster(MatrixClusters,MatrixDistances, OutputFile, How, AggregationMethod, PlotSize)
HoloMapDict[(AggregationMethod, How )] = Merged
Combined = holoviews.HoloMap(HoloMapDict, kdims=['Aggregation', 'interpolation']).collate()
holoviews.save(Combined, 'combined.html')
Thanks again.
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
The code below should generate a holomap of holoviews rasterized images bunched together using + operators.
The code above does not work as expected and generates the following printout:
I tired using collate on the holomap object created after creating the holomap object and adding data directly to the object, yet I am getting the same error.
I need a solution to have combo boxes that will alow me to switch between different aggregation and interpolation method - if holoviews does not implement it, can I do it with panel? My alternative is using tab layout in panel - however, it would be nice having it with the holoviews combo boxes if possible. In any case, I want it to be a static html page without the need to run a server. Hopefully iy is possible.