<jupyter_start><jupyter_text>H5 explorerThe h5explorer module provides a jupyter widget implementation for looking at 3 dimensional volumes in HDF5 files in a folder.It allows the user to insert "filters" for modifying the volumesand supports saving volumes in existing or new files.<jupyter_code>from feedWebGL2 import h5explorer
E = h5explorer.Explorer()<jupyter_output><empty_output><jupyter_text>Adding custom filtersThe explorer implementation allows the user to define customarray transformation filters which define how to change a 3d volume arrayusing parameters which can be specified interactively.The following example adds a simple (but not very useful) filter implementationto an explorer object.  See the h5explorer.py source code for more examplesof filter implementations.<jupyter_code># Make a custom filter as a subclass of h5explorer.LogFilter
from feedWebGL2 import h5explorer

# Use standard Jupyter widget implementations to construct the interactive controls.
import ipywidgets as widgets

class FlipFilter(h5explorer.LogFilter):
    
    "Flip axes -- a simple filter example."

    # title is required
    title = "Flip"

    def widget(self):
        "The widget method defines the parameters for the filter."
        html1 = widgets.HTML("<H1>Flip one of the dimensions.</H1>")
        # self.info is required
        self.info = widgets.HTML("<div>Parameters</div>")
        # other parameters
        self.axis_name_dropdown = widgets.Dropdown(description="Axis to flip", options=["I", "J", "K"])
        # apply button is required
        self.button = widgets.Button(
            description="Flip it!",
        )
        self.button.on_click(self.apply)
        # Construct a widget container including all sub-widgets
        return widgets.VBox([html1, self.info, self.axis_name_dropdown, self.button])

    def apply(self, button):
        """
        The apply method defines how to execute the filter using the parameters.
        It must test that the image is defined.
        """
        # make sure an image has been loaded:
        ex = self.in_explorer
        image_array = ex.current_image
        if image_array is None:
            # no image: abort...
            self.update()
            return
        # Get parameters
        axis_name = self.axis_name_dropdown.value
        # apply the filter to the image
        if axis_name == "I":
            flipped = image_array[::-1, :, :]
        elif axis_name == "J":
            flipped = image_array[:, ::-1, :]
        elif axis_name == "K":
            flipped = image_array[:, :, ::-1]
        else:
            self.info.value = "??? Unknown axis name: " + repr(axis_name)
            return
        # store the modified array
        ex.current_image = flipped
        # redisplay all widgets
        ex.update_all()

# Configure an explorer with some the standard filters and also the FlipFilter

filter_classes = [
    h5explorer.LogFilter,
    h5explorer.BlurFilter,
    h5explorer.SubsampleFilter,
    FlipFilter,
]

CustomExplorer = h5explorer.Explorer(
    filters = filter_classes,
)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.0784, 'fraction_numerical': 0.00768, 'mean_word_length': 2.8784119106699753, 'pattern_counts': {'":': 3, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '338668', 'license': 'BSD-2-Clause', 'n_tokens_mistral': 872, 'n_tokens_neox': 854, 'n_words': 296, 'path': 'notebooks/h5 explorer demo.ipynb', 'repo_name': 'flatironinstitute/feedWebGL2', 'size': '3125'}