{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# VizTool\n", "In this notebook, we show the features of the `VizTool`, an interactive tool to visualize events and main parameters." ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "ExecuteTime": { "end_time": "2021-11-23T12:11:34.505209Z", "start_time": "2021-11-23T12:11:30.633443Z" } }, "outputs": [], "source": [ "import cait as ai" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Mock data and DataHandler object\n", "The HDF5 file used in this notebook can be created using the following commands. If you already have an HDF5 file and a corresponding `DataHandler` object, you can skip this step." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "test_data = ai.data.TestData(filepath='./mock_001', duration=10000)\n", "test_data.generate()\n", "dh = ai.DataHandler(channels=[0,1])\n", "dh.convert_dataset(path_rdt='./', fname='mock_001', path_h5='./')\n", "dh.set_filepath(path_h5='./', fname='mock_001')\n", "\n", "dh.calc_mp()\n", "dh.calc_mp(type='testpulses')\n", "dh.calc_mp(type='noise')\n", "\n", "dh.calc_additional_mp(type='events', no_of=True)\n", "dh.calc_additional_mp(type='testpulses', no_of=True)\n", "dh.calc_additional_mp(type='noise', no_of=True)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# create DataHandler instance\n", "dh = ai.DataHandler(channels=[0,1])\n", "dh.set_filepath(path_h5='./', fname='mock_001', appendix=True)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Visualization\n", "We now have to decide, which data to visualize. This is handled with a `datasets` dictionary: The keys of the dictionary are the labels that will be displayed on the plot. The value is always a list of the name of the dataset, the index in the first dimension (channel index) and last dimension (feature index). If there is no channel or feature index to be set, the value in the list can be put to `None`. This might look overwhelming at first but most of the time, you will only use exactly this dictionary." ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [], "source": [ "datasets = {\n", " 'Time (h)': ['hours', None, None],\n", " 'Pulse Height Phonon (V)': ['pulse_height', 0, None],\n", " 'Pulse Height Light (V)': ['pulse_height', 1, None],\n", " 'Rise Time Phonon (ms)': ['rise_time', 0, None],\n", " 'Rise Time Light (ms)': ['rise_time', 1, None],\n", " 'Decay Time Phonon (ms)': ['decay_time', 0, None],\n", " 'Decay Time Light (ms)': ['decay_time', 1, None],\n", " 'Onset Phonon (ms)': ['onset', 0, None],\n", " 'Onset Light (ms)': ['onset', 1, None],\n", " 'Slope Phonon (V)': ['slope', 0, None],\n", " 'Slope Light (V)': ['slope', 1, None],\n", " 'Variance Phonon (V^2)': ['var', 1, None],\n", " 'Variance Light (V^2)': ['var', 0, None],\n", " 'Mean Phonon (V)': ['mean', 0, None],\n", " 'Mean Light (V)': ['mean', 1, None],\n", " 'Skewness Phonon': ['skewness', 0, None],\n", " 'Skewness Light': ['skewness', 1, None],\n", "}" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Using this dictionary, we are ready to construct the `vizTool` object. Here, we use the already existing `DataHandler` as data source. Note, however, that you could also specify the path to an `*.h5` or `*.csv` file." ] }, { "cell_type": "code", "execution_count": 19, "metadata": {}, "outputs": [], "source": [ "viz = ai.VizTool(datahandler=dh, datasets=datasets, group=\"events\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "You might not want to plot *all* the data because you might have already performed some cuts, for example. We can choose to show only certain events from the file by handing the indices of these events to the instance of the `VizTool`. Let us define some arbitrary cut to illustrate this procedure:" ] }, { "cell_type": "code", "execution_count": 20, "metadata": {}, "outputs": [], "source": [ "some_cut = ai.cuts.LogicalCut(dh.get('events', 'pulse_height')[0] < 5) # cut on the phonon channel\n", "\n", "viz.set_idx(some_cut.get_idx())" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We are now ready to display the tool. The `show` method takes one argument `template` which you can use to style the tool to your likings." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "viz.show(template='ggplot2')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "![](media/vizTool_upper.png)\n", "![](media/vizTool_lower.png)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The `VizTool`'s main component is a scatter plot surrounded by histograms for the x- and y-values that are scatter plotted. You can choose the axis using the x- and y-dropdown-menus. The `color`-dropdown lets you choose a coloring for the scatter plot, effectively giving you a third plot axis. You can choose to have a heatmap instead of a scatter plot by using the radio-buttons on top. The scale (log or linear) for the heatmap and histograms can be selected using the respective radio-button.\n", "\n", "In the scatter plot, we can select and plot events (which show up in the bottom part of the tool) and cut them away (using box or lasso select and the button `Cut Selected`). Note that they will not be deleted from the HDF5 file but only from the current `vizTool` instance.\n", "\n", "In the textbox, you can define a name for the selected events (you need to press `Enter`) and then store the cut flag (a boolean array) for the selected event in the HDF5 file (`Save Selected`) or export the index list as CSV (`Export Selected`). \n", "\n", "You can calculate a preview of a standard event of your selected events with the `Calc SEV` button. \n", "Once you choose a list of events for which you want to calculate a proper standard event, you can access the saved list from the HDF5 file with the `DataHandler.get` method. You can define the index list with a `LogicalCut` object and then use it in the `calc_sev` method:" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "ExecuteTime": { "end_time": "2021-11-07T14:00:36.422692Z", "start_time": "2021-11-07T14:00:33.763776Z" } }, "outputs": [], "source": [ "sev_cuts = ai.cuts.LogicalCut(dh.get('events', 'sev_cuts')[0])\n", "\n", "dh.calc_sev(use_idx=sev_cuts.get_idx())" ] } ], "metadata": { "kernelspec": { "display_name": "venv_cait", "language": "python", "name": "venv_cait" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.9.6" }, "varInspector": { "cols": { "lenName": 16, "lenType": 16, "lenVar": 40 }, "kernels_config": { "python": { "delete_cmd_postfix": "", "delete_cmd_prefix": "del ", "library": "var_list.py", "varRefreshCmd": "print(var_dic_list())" }, "r": { "delete_cmd_postfix": ") ", "delete_cmd_prefix": "rm(", "library": "var_list.r", "varRefreshCmd": "cat(var_dic_list()) " } }, "types_to_exclude": [ "module", "function", "builtin_function_or_method", "instance", "_Feature" ], "window_display": false } }, "nbformat": 4, "nbformat_minor": 4 }