<jupyter_start><jupyter_text>NWB Conversion Tools - Simple Tutorial<jupyter_code>from pathlib import Path

from pynwb import NWBHDF5IO
from nwbwidgets import nwb2widget

from nwb_conversion_tools import (
    NWBConverter,
    TutorialRecordingInterface,
    TutorialSortingInterface
)<jupyter_output><empty_output><jupyter_text>Define conversion class and its internal data interface classes (*i.e.*, the name of format) For a full list of supported formats, [see this list](https://nwb-conversion-tools.readthedocs.io/en/conversion_guide/converting_data_to_nwb.html), or [make your own data interface](https://nwb-conversion-tools.readthedocs.io/en/conversion_guide/data_interface.html)<jupyter_code>class TutorialNWBConverter(NWBConverter):
    data_interface_classes = dict(
        TutorialRecording=TutorialRecordingInterface, 
        TutorialSorting=TutorialSortingInterface
    )<jupyter_output><empty_output><jupyter_text>Construct arguments for the converter class and run conversion<jupyter_code># Custom parameters for simulated toy data
duration=10.  # Seconds
num_channels=4
sampling_frequency=30000.  # Hz

stub_test = True  # Truncates data write for faster quality checking

output_file = "E:/NWBConversionToolsSimpleTutorial.nwb"

# Input arguments to each interface
# For actual data formats, these arguments are typically file or folder paths to the data
source_data = dict(
    TutorialRecording=dict(
        duration=duration,
        num_channels=num_channels,
        sampling_frequency=sampling_frequency
    ),
    TutorialSorting=dict(
        duration=duration,
        num_channels=num_channels,
        sampling_frequency=sampling_frequency
    )
)

# Initialize converter
converter = TutorialNWBConverter(source_data=source_data)

# Get metadata from source data
# For actual data formats, this generally pulls informatin from the header files for each interface
metadata = converter.get_metadata()

# User-input metadata
metadata["NWBFile"]["session_description"] = "NWB Conversion Tools tutorial."
metadata["NWBFile"]["experimenter"] = "<NAME>"
metadata["Subject"] = dict(subject_id="Name of imaginary testing subject (required for DANDI upload)")

# Conversion options for each interface
# For actual data formats, these can vary widely - read the docstring for the interface you want to use by entering
#     import nwb_conversion_tools
#     nwb_conversion_tools.NameOfDataInterface.run_conversion?
conversion_options = dict(
    TutorialRecording=dict(stub_test=stub_test),
    TutorialSorting=dict()
)

# Run conversion
converter.run_conversion(
    metadata=metadata, 
    nwbfile_path=output_file, 
    save_to_file=True,  # If False, this instead returns the NWBFile object in memory
    overwrite = True,  # If False, this appends an existing file
    conversion_options=conversion_options
)<jupyter_output><empty_output><jupyter_text>View NWBFile with widgets<jupyter_code>io = NWBHDF5IO(output_file, "r", load_namespaces=True)
nwbfile = io.read()
nwb2widget(nwbfile)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.07495069033530571, 'fraction_numerical': 0.0039447731755424065, 'mean_word_length': 5.673245614035087, 'pattern_counts': {'":': 0, '<': 18, '<?xml version=': 0, '>': 18, 'https://': 2, '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': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '284600', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 940, 'n_tokens_neox': 889, 'n_words': 231, 'path': 'tutorials/simple-tutorial.ipynb', 'repo_name': 'JuliaSprenger/nwb-conversion-tools', 'size': '3043'}