From 20816161ec4edaa05f73a99fda9e3232034e9fd3 Mon Sep 17 00:00:00 2001 From: Eric Denovellis Date: Mon, 27 Nov 2017 11:04:00 -0500 Subject: [PATCH 1/4] Add Animal data structure for convenience --- loren_frank_data_processing/__init__.py | 1 + loren_frank_data_processing/core.py | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/loren_frank_data_processing/__init__.py b/loren_frank_data_processing/__init__.py index a102041..05a368b 100644 --- a/loren_frank_data_processing/__init__.py +++ b/loren_frank_data_processing/__init__.py @@ -1,4 +1,5 @@ # flake8: noqa +from .core import Animal from .multiunit import (get_multiunit_dataframe, get_multiunit_indicator_dataframe) from .neurons import (get_spike_indicator_dataframe, get_spikes_dataframe, diff --git a/loren_frank_data_processing/core.py b/loren_frank_data_processing/core.py index 7a9b871..2575adb 100644 --- a/loren_frank_data_processing/core.py +++ b/loren_frank_data_processing/core.py @@ -1,7 +1,7 @@ '''Functions for accessing data in the Frank lab format and saving ''' - +from collections import namedtuple from logging import getLogger from os.path import join from sys import exit @@ -12,6 +12,8 @@ logger = getLogger(__name__) +Animal = namedtuple('Animal', {'directory', 'short_name'}) + def get_data_filename(animal, day, file_type): '''Returns the Matlab file name assuming it is in the Raw Data From cc5a050648a40e552d6013f2e90f83e548c0cca4 Mon Sep 17 00:00:00 2001 From: Eric Denovellis Date: Mon, 27 Nov 2017 12:05:40 -0500 Subject: [PATCH 2/4] Catch type error Scipy 1.0 throws TypeError instead of FileNotFoundError or IOError. Until this is fixed, catch the type error --- loren_frank_data_processing/core.py | 4 ++-- loren_frank_data_processing/tetrodes.py | 7 ++++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/loren_frank_data_processing/core.py b/loren_frank_data_processing/core.py index 2575adb..4e671bd 100644 --- a/loren_frank_data_processing/core.py +++ b/loren_frank_data_processing/core.py @@ -74,7 +74,7 @@ def get_epochs(animal, day): get_data_filename(animal, day, 'task')) return [(animal, day, ind + 1) for ind, epoch in enumerate(task_file['task'][0, -1][0])] - except IOError as err: + except (IOError, TypeError) as err: logger.error('Failed to load file {0}'.format( get_data_filename(animal, day, 'task'))) exit() @@ -104,7 +104,7 @@ def get_data_structure(animal, day, file_type, variable): ''' try: file = loadmat(get_data_filename(animal, day, file_type)) - except IOError: + except (IOError, TypeError): logger.error('Failed to load file: {0}'.format( get_data_filename(animal, day, file_type))) exit() diff --git a/loren_frank_data_processing/tetrodes.py b/loren_frank_data_processing/tetrodes.py index ff21265..7b0e354 100644 --- a/loren_frank_data_processing/tetrodes.py +++ b/loren_frank_data_processing/tetrodes.py @@ -3,7 +3,7 @@ import pandas as pd from scipy.io import loadmat -from .core import _convert_to_dict, reconstruct_time +from .core import _convert_to_dict, reconstruct_time, logger def get_tetrode_info_path(animal): @@ -53,8 +53,9 @@ def get_LFP_dataframe(tetrode_key, animals): data=lfp_data['data'][0, 0].squeeze(), index=lfp_time, name='electric_potential') - except FileNotFoundError: - pass + except (FileNotFoundError, TypeError): + logger.error('Failed to load file: {0}'.format( + get_LFP_filename(tetrode_key, animals))) def make_tetrode_dataframe(animals): From c5877241111d03ae0dd3e9c306da7b406a433bb7 Mon Sep 17 00:00:00 2001 From: Eric Denovellis Date: Mon, 27 Nov 2017 12:05:51 -0500 Subject: [PATCH 3/4] Don't need exit here --- loren_frank_data_processing/core.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/loren_frank_data_processing/core.py b/loren_frank_data_processing/core.py index 4e671bd..7280326 100644 --- a/loren_frank_data_processing/core.py +++ b/loren_frank_data_processing/core.py @@ -4,7 +4,6 @@ from collections import namedtuple from logging import getLogger from os.path import join -from sys import exit import numpy as np import pandas as pd @@ -107,7 +106,6 @@ def get_data_structure(animal, day, file_type, variable): except (IOError, TypeError): logger.error('Failed to load file: {0}'.format( get_data_filename(animal, day, file_type))) - exit() n_epochs = file[variable][0, -1].size return [file[variable][0, -1][0, ind] for ind in np.arange(n_epochs)] From 8ff770526565ec0cde918eb9d254c7554901faec Mon Sep 17 00:00:00 2001 From: Eric Denovellis Date: Mon, 27 Nov 2017 12:09:09 -0500 Subject: [PATCH 4/4] bump version number --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index a433633..df96687 100644 --- a/setup.py +++ b/setup.py @@ -8,7 +8,7 @@ setup( name='loren_frank_data_processing', - version='0.2.2.dev0', + version='0.2.3.dev0', license='GPL-3.0', description=('Import data from Loren Frank lab'), author='Eric Denovellis',