miranov25 / RootInteractive

4 stars 12 forks source link

Cdsstack and multiselect variables for histograms #326

Closed pl0xz0rz closed 1 year ago

pl0xz0rz commented 1 year ago

This PR adds a convenient way of combining multiple ColumnDataSources into one on the client, letting the user toggle them on and off with a MultiSelect. This PR also adds some parametrization to templates (relating to #303) letting the user specify variables, default variables and weights (because of a technical issue that will take a lot of time to fix, not supported for variables as that would require either using multiple multiselects for varY-varYNorm or seriously refactoring the code.)

It throws a Bokeh validation warning, but it's the result of a hacky workaround for a validation bug

Example use:

parameterArray=[
    {'name':"histo1Ds", "value":["histoA"], "options":["histoA", "histoB"]}
]
widgetParams=[
    ['multiSelect', ['histo1Ds'], {"name": "histo1Ds"}],
]
histoArray = [
   # create histograms
    {"name": "histoA", "variables": ["A"]}},
    {"name": "histoB", "variables": ["B"]]},
   # create the join
    {"name": "histo1Ds", "sources": "histo1Ds"}
]

Added a short hand notation, works both for 1D and ND histograms (for ND, works so far only with one axis)

parameterArray=[
   {"name":"varXs", "value":["A","B"], "options":["A","B","C","D"]}
]
widgetParams=[
  ['multiSelect', ['varXs'], {"name":"varXs"}]
]
histoArray = [
{"name": "histoA", "variables": ["varXs"]}
]

This PR also adds a useful function mergeFigureArrays to bokehTools, which is useful for adding more figures to a figureArray from a template without breaking the global figure options Use:

figureArray = mergeFigureArrays(figureArray, [
    [["bin_center"],["bin_count"], {"name":"histo1D"}]
])

Another example in test_bokeh lientHistogram.py test_template function

As a side effect, this also improves the performance of ND histograms in the case of changing varY in the ND histograms in the use case in the default template, by a factor of up to 2.

miranov25 commented 1 year ago

Test failed:


report saved to: test6.json
============================================================================================================================= short test summary info =============================================================================================================================
FAILED test_bokehClientHistogramWeight.py::test_clientHistogramWeightCompressed - KeyError: '$IGNORE'
FAILED test_bokehClientHistogramWeight.py::test_clientHistogramWeight - KeyError: '$IGNORE'
FAILED test_bokehClientHistogram.py::testBokehClientHistogramProfileB - KeyError: '$IGNORE'
FAILED test_bokehClientHistogram.py::testBokehClientHistogramProfileA - KeyError: '$IGNORE'
FAILED test_bokehClientHistogram.py::testBokehClientHistogramRowwiseTable - KeyError: '$IGNORE'
FAILED test_bokehClientHistogram.py::testBokehClientHistogram - KeyError: '$IGNORE'
=============================================================================================================== 6 failed, 31 passed, 7 warnings in 74.11s (0:01:14) ===========================================================================================
miranov25 commented 1 year ago

Test formaly OK bot in Mac and Linux test servers

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
----------------------------------------------------------------------------------------------------------------------------------- JSON report -----------------------------------------------------------------------------------------------------------------------------------
report saved to: test6.json
==================================================================================================================== 38 passed, 7 warnings in 97.14s (0:01:37) ====================================================================================================================

real    1m38.586s
user    28m59.896s
sys 2m56.960s
miranov25 commented 1 year ago

Test formaly working with new modification RootInteractive/RootInteractive/InteractiveDrawing/bokeh/test_histogramTemplate.html

miranov25 commented 1 year ago
-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
----------------------------------------------------------------------------------------------------------------------------------- JSON report -----------------------------------------------------------------------------------------------------------------------------------
report saved to: test6.json
==================================================================================================================== 37 passed, 7 warnings in 96.98s (0:01:36) ====================================================================================================================

real    1m38.624s
user    29m14.404s
sys 3m17.276s
miranov25 commented 1 year ago

Thank you Merging.

miranov25 commented 1 year ago

Test ok

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
----------------------------------------------------------------------------------------------------------------------------------- JSON report -----------------------------------------------------------------------------------------------------------------------------------
report saved to: test6.json
==================================================================================================================== 37 passed, 7 warnings in 94.15s (0:01:34) ====================================================================================================================

real    1m35.642s
user    28m5.688s
sys 2m51.228s
miranov25 commented 1 year ago

Test were OK. Real use cases tested went OK. Merging