Skip to content

Commit

Permalink
Merge pull request #200 from rossant/pyks2
Browse files Browse the repository at this point in the history
Experimental Python port of Kilosort 2
  • Loading branch information
marius10p authored Apr 30, 2020
2 parents 9a7a1ae + 07803e5 commit 48bf2b8
Show file tree
Hide file tree
Showing 28 changed files with 6,751 additions and 0 deletions.
40 changes: 40 additions & 0 deletions pykilosort/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import logging
import os.path as op

from .utils import Bunch, memmap_binary_file, read_data, load_probe # noqa
from .main import run # noqa


__version__ = '2.0.0a0'


# Set a null handler on the root logger
logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)


_logger_fmt = '%(asctime)s.%(msecs)03d [%(levelname)s] %(caller)s %(message)s'
_logger_date_fmt = '%H:%M:%S'


class _Formatter(logging.Formatter):
def format(self, record):
# Only keep the first character in the level name.
record.levelname = record.levelname[0]
filename = op.splitext(op.basename(record.pathname))[0]
record.caller = '{:s}:{:d}'.format(filename, record.lineno).ljust(20)
message = super(_Formatter, self).format(record)
color_code = {'D': '90', 'I': '0', 'W': '33', 'E': '31'}.get(record.levelname, '7')
message = '\33[%sm%s\33[0m' % (color_code, message)
return message


def add_default_handler(level='INFO', logger=logger, filename=None):
if filename is None:
handler = logging.StreamHandler()
else:
handler = logging.FileHandler(filename)
handler.setLevel(level)
formatter = _Formatter(fmt=_logger_fmt, datefmt=_logger_date_fmt)
handler.setFormatter(formatter)
logger.addHandler(handler)
Loading

0 comments on commit 48bf2b8

Please sign in to comment.