# Path: python/pipeline/exceptions.py
# class PipelineException(Exception):
#     """Base pipeline exception. Prints the message plus any specific info."""
#     def __init__(self, message, info=None):
#         info_message = '\nError info: ' + repr(info) if info else ''
#         super().__init__(message + info_message)
#         self.info = info
# 
# Path: python/pipeline/utils/eye_tracking.py
# ANALOG_PACKET_LEN = 2000


import h5py
import numpy as np
from ..exceptions import PipelineException
from .eye_tracking import ANALOG_PACKET_LEN
from .signal import mirrconv, spaced_max
            data['trialnum_ts'] = np.array(f['trialnum_ts'])
            data['eyecam_ts'] = np.array(f['videotimestamps'])
            if 'videotimestamps_posture' in f:
                data['posture_ts'] = np.array(f['videotimestamps_posture'])

            analog_signals = np.array(f['Analog Signals'])
            channel_names = f.attrs['AS_channelNames'].decode('ascii').split(',')
            channel_names = [cn.strip() for cn in channel_names]
            
            for i,channel_name in enumerate(channel_names): # only works up to 9 channels
                if ':' in channel_name:
                    colon_index = channel_name.find(':')        
                    expanded_indices = np.arange(int(channel_name[colon_index-1]),int(channel_name[colon_index+1])+1)
                    expanded_channel_names = [channel_name[:colon_index-1] + str(ex_i) for ex_i in expanded_indices]
                    channel_names[i:i+1] = expanded_channel_names
            data['syncPd'] = analog_signals[channel_names.index('Photodiode')]
            data['ts'] = analog_signals[channel_names.index('Time')]
            if 'Temperature' in channel_names:
                data['temperature'] = analog_signals[channel_names.index('Temperature')]
            
            if 'AudioStimWindow' in channel_names:
                data['auditory'] = analog_signals[channel_names.index('AudioStimWindow')]

            if str(f.attrs['AS_Version'][0]) == '2.1':
                data['scanImage'] = analog_signals[channel_names.index('ScanImageFrameSync')]
            else:
                data['scanImage'] = analog_signals[channel_names.index('FrameSync')]

        else:
            msg = 'Unknown file version {} in file {}'.format(file_version, filename)

# Path: python/pipeline/exceptions.py
# class PipelineException(Exception):
#     """Base pipeline exception. Prints the message plus any specific info."""
#     def __init__(self, message, info=None):
#         info_message = '\nError info: ' + repr(info) if info else ''
#         super().__init__(message + info_message)
#         self.info = info
# 
# Path: python/pipeline/utils/eye_tracking.py
# ANALOG_PACKET_LEN = 2000


# Path: python/pipeline/utils/h5.py
import h5py
import numpy as np
from ..exceptions import PipelineException
from .eye_tracking import ANALOG_PACKET_LEN
from .signal import mirrconv, spaced_max

            data['trialnum_ts'] = np.array(f['trialnum_ts'])
            data['eyecam_ts'] = np.array(f['videotimestamps'])
            if 'videotimestamps_posture' in f:
                data['posture_ts'] = np.array(f['videotimestamps_posture'])

            analog_signals = np.array(f['Analog Signals'])
            channel_names = f.attrs['AS_channelNames'].decode('ascii').split(',')
            channel_names = [cn.strip() for cn in channel_names]
            
            for i,channel_name in enumerate(channel_names): # only works up to 9 channels
                if ':' in channel_name:
                    colon_index = channel_name.find(':')        
                    expanded_indices = np.arange(int(channel_name[colon_index-1]),int(channel_name[colon_index+1])+1)
                    expanded_channel_names = [channel_name[:colon_index-1] + str(ex_i) for ex_i in expanded_indices]
                    channel_names[i:i+1] = expanded_channel_names
            data['syncPd'] = analog_signals[channel_names.index('Photodiode')]
            data['ts'] = analog_signals[channel_names.index('Time')]
            if 'Temperature' in channel_names:
                data['temperature'] = analog_signals[channel_names.index('Temperature')]
            
            if 'AudioStimWindow' in channel_names:
                data['auditory'] = analog_signals[channel_names.index('AudioStimWindow')]

            if str(f.attrs['AS_Version'][0]) == '2.1':
                data['scanImage'] = analog_signals[channel_names.index('ScanImageFrameSync')]
            else:
                data['scanImage'] = analog_signals[channel_names.index('FrameSync')]

        else:
            msg = 'Unknown file version {} in file {}'.format(file_version, filename)

            raise PipelineException(msg)