<jupyter_start><jupyter_text>Jaeger lab - TreadmillConverterThis tutorial follows the step-by-step guide for a [NWB Converter](https://github.com/catalystneuro/nwb-conversion-tools/blob/master/documentation/conversion_tools_structure.mdstep-by-step-operations)<jupyter_code>from jaeger_lab_to_nwb import JaegerTreadmillConverter
from pynwb import NWBHDF5IO
from nwbwidgets import nwb2widget
from pathlib import Path
import pprint<jupyter_output><empty_output><jupyter_text>Step 1 - Converter.get_source_schema()<jupyter_code># Get source_schema
source_schema = JaegerTreadmillConverter.get_source_schema()
pprint.pprint(source_schema['properties'], width=120)<jupyter_output>{'IntanDataInterface': {'additionalProperties': False,
                        'properties': {'dir_ecephys_rhd': {'description': 'path to directory containing ecephys data '
                                                                          'in rhd files',
                                                           'format': 'directory',
                                                           'type': 'string'},
                                       'file_electrodes': {'description': 'path to csv file containing electrodes data',
                                                           'format': 'file',
                                                           'type': 'string'}},
                        'required': [],
                        'type': 'object'},
 'TreadmillDataInterface': {'additionalProperties': False,
                            'properties': {'dir_behavior_treadmill': {'description': 'path to directory containing '
                                        [...]<jupyter_text>Step 2 - Get user-input source_data that complies to the returned full source_schema<jupyter_code># Source data
dir_ecephys_rhd = Path.cwd() / 'Behavioral_data_Li'
file_electrodes = Path.cwd() / 'Behavioral_data_Li/UD09_impedance_1.csv'
dir_behavior_treadmill = Path.cwd() / 'Behavioral_data_Li'

source_data = dict(
    TreadmillDataInterface=dict(
        dir_behavior_treadmill=str(dir_behavior_treadmill)
    ),
    IntanDataInterface=dict(
        dir_ecephys_rhd=str(dir_ecephys_rhd),
        file_electrodes=str(file_electrodes)
    )
)
pprint.pprint(source_data, width=120)<jupyter_output>{'IntanDataInterface': {'dir_ecephys_rhd': 'C:\\Users\\Luiz\\Google Drive '
                                           '(<EMAIL>)\\client_ben\\project_jaeger_lab\\Behavioral_data_Li',
                        'file_electrodes': 'C:\\Users\\Luiz\\Google Drive '
                                           '(<EMAIL>)\\client_ben\\project_jaeger_lab\\Behavioral_data_Li\\UD09_impedance_1.csv'},
 'TreadmillDataInterface': {'dir_behavior_treadmill': 'C:\\Users\\Luiz\\Google Drive '
                                                      '(<EMAIL>)\\client_ben\\project_jaeger_lab\\Behavioral_data_Li'}}<jupyter_text>Step 3 - Instantiate Converter<jupyter_code># Initialize converter
converter = JaegerTreadmillConverter(source_data)

print('Data interfaces for this converter:')
pprint.pprint(converter.data_interface_objects, width=120)<jupyter_output>Data interfaces for this converter:
{'IntanDataInterface': <jaeger_lab_to_nwb.treadmillconverter.intandatainterface.IntanDataInterface object at 0x0000027025E05CC8>,
 'TreadmillDataInterface': <jaeger_lab_to_nwb.treadmillconverter.treadmilldatainterface.TreadmillDataInterface object at 0x0000027025E05108>}<jupyter_text>Step 4 - Converter.get_metadata_schema()<jupyter_code># Get metadata_schema
metadata_schema = converter.get_metadata_schema()
pprint.pprint(metadata_schema, width=1000)<jupyter_output>{'$id': 'metadata.schema.json',
 '$schema': 'http://json-schema.org/draft-07/schema#',
 'additionalProperties': False,
 'description': 'Schema for the metadata',
 'properties': {'Ecephys': {'additionalProperties': False,
                            'properties': {'Device': {'additionalProperties': False, 'properties': {'description': {'description': 'Description of the device (e.g., model, firmware version, processing software version, etc.)', 'type': 'string'}, 'manufacturer': {'description': 'the name of the manufacturer of this device', 'type': 'string'}, 'name': {'default': 'Device_ecephys', 'description': 'the name of this device', 'type': 'string'}}, 'required': ['name'], 'tag': 'pynwb.device.Device', 'type': 'object'},
                                           'ElectricalSeries': {'additionalProperties': False,
                                                                'properties': {'comments': {'default': 'no comments', 'description': 'Human-readable comments about this [...]<jupyter_text>Step 5 - Automatically fetches available metadata with Converter.get_metadata()<jupyter_code># Get metadata from source data
metadata = converter.get_metadata()
pprint.pprint(metadata, width=120)<jupyter_output>{'Behavior': {'TimeSeries_actualperiod': {'description': 'ADDME', 'name': 'ActualPeriod'},
              'TimeSeries_beambreak': {'description': 'ADDME', 'name': 'BeamBreak'},
              'TimeSeries_cntrx': {'description': 'ADDME', 'name': 'Cntr_X'},
              'TimeSeries_cntry': {'description': 'ADDME', 'name': 'Cntr_Y'},
              'TimeSeries_encoder': {'description': 'ADDME', 'name': 'Encoder'},
              'TimeSeries_iteration': {'description': 'ADDME', 'name': 'Iteration'},
              'TimeSeries_nosex': {'description': 'ADDME', 'name': 'Nose_X'},
              'TimeSeries_nosey': {'description': 'ADDME', 'name': 'Nose_Y'},
              'TimeSeries_speed': {'description': 'ADDME', 'name': 'Speed'},
              'TimeSeries_variablespeed': {'description': 'ADDME', 'name': 'VariableSpeed'}},
 'Ecephys': {'Device': {'name': 'Device_ecephys'},
             'ElectricalSeries': {'conversion': 1.0,
                                  'description': 'Raw acquisition trace[...]<jupyter_text>Step 6 - Get user-input metadata<jupyter_code>metadata['NWBFile']['session_description'] = 'example conversion'
pprint.pprint(metadata, width=120)<jupyter_output>{'Behavior': {'TimeSeries_actualperiod': {'description': 'ADDME', 'name': 'ActualPeriod'},
              'TimeSeries_beambreak': {'description': 'ADDME', 'name': 'BeamBreak'},
              'TimeSeries_cntrx': {'description': 'ADDME', 'name': 'Cntr_X'},
              'TimeSeries_cntry': {'description': 'ADDME', 'name': 'Cntr_Y'},
              'TimeSeries_encoder': {'description': 'ADDME', 'name': 'Encoder'},
              'TimeSeries_iteration': {'description': 'ADDME', 'name': 'Iteration'},
              'TimeSeries_nosex': {'description': 'ADDME', 'name': 'Nose_X'},
              'TimeSeries_nosey': {'description': 'ADDME', 'name': 'Nose_Y'},
              'TimeSeries_speed': {'description': 'ADDME', 'name': 'Speed'},
              'TimeSeries_variablespeed': {'description': 'ADDME', 'name': 'VariableSpeed'}},
 'Ecephys': {'Device': {'name': 'Device_ecephys'},
             'ElectricalSeries': {'conversion': 1.0,
                                  'description': 'Raw acquisition trace[...]<jupyter_text>Step 7 - Converter.get_conversion_options_schema()<jupyter_code># Not used for this converter<jupyter_output><empty_output><jupyter_text>Step 8 - Get user-input conversion options<jupyter_code># Not used for this converter<jupyter_output><empty_output><jupyter_text>Step 9 - Run conversion user filled metadata and conversion_options<jupyter_code>output_file = 'treadmill_example.nwb'

converter.run_conversion(
    metadata=metadata, 
    nwbfile_path=output_file, 
    save_to_file=True,
    conversion_options=None
)<jupyter_output>c:\users\luiz\documents\github\pynwb\src\pynwb\file.py:758: UserWarning: Date is missing timezone information. Updating to local timezone.
  warn("Date is missing timezone information. Updating to local timezone.")<jupyter_text>Final 1 - Check NWB file<jupyter_code># load file
with NWBHDF5IO(output_file, 'r') as io:
    nwbfile = io.read()
    print(nwbfile)
    print('\n ############################################### \n')
    print('Trials: \n')
    print(nwbfile.trials)<jupyter_output>root pynwb.file.NWBFile at 0x2680696864328
Fields:
  acquisition: {
    ActualPeriod <class 'pynwb.base.TimeSeries'>,
    BeamBreak <class 'pynwb.base.TimeSeries'>,
    Cntr_X <class 'pynwb.base.TimeSeries'>,
    Cntr_Y <class 'pynwb.base.TimeSeries'>,
    ElectricalSeries <class 'pynwb.ecephys.ElectricalSeries'>,
    Encoder <class 'pynwb.base.TimeSeries'>,
    Iteration <class 'pynwb.base.TimeSeries'>,
    Nose_X <class 'pynwb.base.TimeSeries'>,
    Nose_Y <class 'pynwb.base.TimeSeries'>,
    Speed <class 'pynwb.base.TimeSeries'>,
    VariableSpeed <class 'pynwb.base.TimeSeries'>
  }
  devices: {
    Device_ecephys <class 'pynwb.device.Device'>
  }
  electrode_groups: {
    ElectrodeGroup_1 <class 'pynwb.ecephys.ElectrodeGroup'>,
    ElectrodeGroup_2 <class 'pynwb.ecephys.ElectrodeGroup'>,
    ElectrodeGroup_3 <class 'pynwb.ecephys.ElectrodeGroup'>
  }
  electrodes: electrodes <class 'hdmf.common.table.DynamicTable'>
  experimenter: ['<NAME>']
  file_create_date: [datetime.datetime(20[...]<jupyter_text>Final 2 - Check NWB file with widgets<jupyter_code>output_file = 'treadmill_example.nwb'

io = NWBHDF5IO(output_file, 'r')
nwbfile = io.read()
nwb2widget(nwbfile)
nwbfile.acquisition['ElectricalSeries']<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14218516142826598, 'fraction_numerical': 0.010583707504810776, 'mean_word_length': 3.5193236714975846, 'pattern_counts': {'":': 0, '<': 63, '<?xml version=': 0, '>': 63, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 25, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '12', 'dir': 'jupyter-structured-clean-dedup', 'id': '182475', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 2953, 'n_tokens_neox': 2791, 'n_words': 530, 'path': 'tutorials/example_conversion_treadmill.ipynb', 'repo_name': 'ben-dichter-consulting/jaeger-lab-to-nwb', 'size': '9410'}