# Path: kwiklib/utils/logger.py
# def register(logger):
#     name = logger.name
#     if name not in LOGGERS:
#         LOGGERS[name] = logger
# 
# def unregister(logger):
#     name = logger.name
#     if name in LOGGERS:
#         LOGGERS[name].close()
#         del LOGGERS[name]
# 
# class FileLogger(Logger):
#     def __init__(self, filename=None, **kwargs):
#         kwargs['handler'] = logging.FileHandler(filename)
#         super(FileLogger, self).__init__(**kwargs)
#         
#     def close(self):
#         self.handler.close()
#         self._logger.removeHandler(self.handler)
#         del self.handler
#         del self._logger
# 
# def debug(self, msg):
#     self._logger.debug(self.get_message(msg))
# 
# def info(self, msg):
#     self._logger.info(self.get_message(msg))
# 
# def warn(self, msg):
#     self._logger.warn(self.get_message(msg))


import os
import os.path
import re
import xml.etree.ElementTree as ET
import numpy as np
import pandas as pd
from loader import (Loader, default_group_info, reorder, renumber_clusters,
    default_cluster_info)
from tools import (load_text, normalize,
    load_binary, load_pickle, save_text, get_array,
    first_row, load_binary_memmap)
from selection import (select, select_pairs, get_spikes_in_clusters,
    get_some_spikes_in_clusters, get_some_spikes, get_indices)
from kwiklib.utils.logger import (register, unregister, FileLogger, 
    debug, info, warn)
from kwiklib.utils.colors import COLORS_COUNT, generate_colors
                self.probe = read_probe(self.filename_probe, self.fileindex)
                info("Successfully loaded {0:s}".format(self.filename_probe))
            except Exception as e:
                info(("There was an error while loading the probe file "
                          "'{0:s}' : {1:s}").format(self.filename_probe,
                            e.message))
                self.probe = None
    
    def read_features(self):
        try:
            self.features, self.spiketimes = read_features(self.filename_fet,
                self.nchannels, self.fetdim, self.freq)
            info("Successfully loaded {0:s}".format(self.filename_fet))
        except IOError:
            raise IOError("The FET file is missing.")
        # Convert to Pandas.
        self.features = pd.DataFrame(self.features, dtype=np.float32)
        self.duration = self.spiketimes[-1]
        self.spiketimes = pd.Series(self.spiketimes, dtype=np.float32)
        
        # Count the number of spikes and save it in the metadata.
        self.nspikes = self.features.shape[0]
        self.metadata['nspikes'] = self.nspikes
        self.nextrafet = self.features.shape[1] - self.nchannels * self.fetdim
    
    def read_res(self):
        try:
            self.spiketimes_res = read_res(self.filename_res, self.freq)
            self.spiketimes_res = pd.Series(self.spiketimes_res, dtype=np.float32)
        except IOError:

# Path: kwiklib/utils/logger.py
# def register(logger):
#     name = logger.name
#     if name not in LOGGERS:
#         LOGGERS[name] = logger
# 
# def unregister(logger):
#     name = logger.name
#     if name in LOGGERS:
#         LOGGERS[name].close()
#         del LOGGERS[name]
# 
# class FileLogger(Logger):
#     def __init__(self, filename=None, **kwargs):
#         kwargs['handler'] = logging.FileHandler(filename)
#         super(FileLogger, self).__init__(**kwargs)
#         
#     def close(self):
#         self.handler.close()
#         self._logger.removeHandler(self.handler)
#         del self.handler
#         del self._logger
# 
# def debug(self, msg):
#     self._logger.debug(self.get_message(msg))
# 
# def info(self, msg):
#     self._logger.info(self.get_message(msg))
# 
# def warn(self, msg):
#     self._logger.warn(self.get_message(msg))


# Path: kwiklib/dataio/klustersloader.py
import os
import os.path
import re
import xml.etree.ElementTree as ET
import numpy as np
import pandas as pd
from loader import (Loader, default_group_info, reorder, renumber_clusters,
    default_cluster_info)
from tools import (load_text, normalize,
    load_binary, load_pickle, save_text, get_array,
    first_row, load_binary_memmap)
from selection import (select, select_pairs, get_spikes_in_clusters,
    get_some_spikes_in_clusters, get_some_spikes, get_indices)
from kwiklib.utils.logger import (register, unregister, FileLogger, 
    debug, info, warn)
from kwiklib.utils.colors import COLORS_COUNT, generate_colors

                self.probe = read_probe(self.filename_probe, self.fileindex)
                info("Successfully loaded {0:s}".format(self.filename_probe))
            except Exception as e:
                info(("There was an error while loading the probe file "
                          "'{0:s}' : {1:s}").format(self.filename_probe,
                            e.message))
                self.probe = None
    
    def read_features(self):
        try:
            self.features, self.spiketimes = read_features(self.filename_fet,
                self.nchannels, self.fetdim, self.freq)
            info("Successfully loaded {0:s}".format(self.filename_fet))
        except IOError:
            raise IOError("The FET file is missing.")
        # Convert to Pandas.
        self.features = pd.DataFrame(self.features, dtype=np.float32)
        self.duration = self.spiketimes[-1]
        self.spiketimes = pd.Series(self.spiketimes, dtype=np.float32)
        
        # Count the number of spikes and save it in the metadata.
        self.nspikes = self.features.shape[0]
        self.metadata['nspikes'] = self.nspikes
        self.nextrafet = self.features.shape[1] - self.nchannels * self.fetdim
    
    def read_res(self):
        try:
            self.spiketimes_res = read_res(self.filename_res, self.freq)
            self.spiketimes_res = pd.Series(self.spiketimes_res, dtype=np.float32)
        except IOError:

            warn("The RES file is missing.")