NeuralEnsemble / ephyviewer

Simple viewers for ephys signals, events, video and more
https://ephyviewer.readthedocs.io
MIT License
55 stars 14 forks source link

Test failures with Matplotlib 3.9 #184

Closed QuLogic closed 5 months ago

QuLogic commented 6 months ago

There are 3 test failures due to the use of deprecated-in-3.7/removed-in-3.9 API; see https://matplotlib.org/stable/api/prev_api_changes/api_changes_3.7.0.html#deprecation-of-top-level-cmap-registration-and-access-functions-in-mpl-cm for more information.

______________________________ test_EpochEncoder _______________________________

interactive = False

    def test_EpochEncoder(interactive=False):
        possible_labels = ['AAA', 'BBB', 'CCC', 'DDD']

        ep_times = np.arange(0, 10., .5)
        ep_durations = np.ones(ep_times.shape) * .25
        ep_labels = np.random.choice(possible_labels, ep_times.size)
        epoch = { 'time':ep_times, 'duration':ep_durations, 'label':ep_labels, 'name': 'MyFactor' }

>       source = WritableEpochSource(epoch=epoch, possible_labels=possible_labels)

ephyviewer/tests/test_epochencoder.py:14: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <ephyviewer.datasource.epochs.WritableEpochSource object at 0x7ff8e059cd40>
epoch = {'duration': array([0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25,
       0.25, 0.25, 0.25, 0.25, 0...', 'AAA', 'DDD', 'BBB', 'BBB', 'BBB', 'CCC', 'BBB', 'BBB',
       'AAA', 'DDD'], dtype='<U3'), 'name': 'MyFactor', ...}
possible_labels = ['AAA', 'BBB', 'CCC', 'DDD'], color_labels = None
channel_name = '', restrict_to_possible_labels = False

    def __init__(self, epoch=None, possible_labels=[], color_labels=None, channel_name='', restrict_to_possible_labels=False):

        self.possible_labels = possible_labels
        self.channel_name = channel_name

        if epoch is None:
            epoch = self.load()

        InMemoryEpochSource.__init__(self, all_epochs=[epoch])

        # assign each epoch a fixed, unique integer id
        self._next_id = 0
        for chan in self.all:
            chan['id'] = np.arange(self._next_id, self._next_id + len(chan['time']))
            self._next_id += len(chan['time'])

        assert self.all[0]['time'].dtype.kind=='f'
        assert self.all[0]['duration'].dtype.kind=='f'

        # add labels missing from possible_labels but found in epoch data
        new_labels_from_data = list(set(epoch['label'])-set(self.possible_labels))
        if restrict_to_possible_labels:
            assert len(new_labels_from_data)==0, f'epoch data contains labels not found in possible_labels: {new_labels_from_data}'
        self.possible_labels += new_labels_from_data

        # put the epochs into a canonical order after loading
        self._clean_and_set(self.all[0]['time'], self.all[0]['duration'], self.all[0]['label'], self.all[0]['id'])

        # TODO: colors should be managed directly by EpochEncoder
        if color_labels is None:
            n = len(self.possible_labels)
>           cmap = matplotlib.cm.get_cmap('Dark2' , n)
E           AttributeError: module 'matplotlib.cm' has no attribute 'get_cmap'

ephyviewer/datasource/epochs.py:89: AttributeError
__________________________ test_EpochEncoder_settings __________________________

interactive = False

    def test_EpochEncoder_settings(interactive=False):
        possible_labels = ['AAA', 'BBB', 'CCC', 'DDD']

        ep_times = np.arange(0, 10., .5)
        ep_durations = np.ones(ep_times.shape) * .25
        ep_labels = np.random.choice(possible_labels, ep_times.size)
        epoch = { 'time':ep_times, 'duration':ep_durations, 'label':ep_labels, 'name': 'MyFactor' }

>       source = WritableEpochSource(epoch=epoch, possible_labels=possible_labels)

ephyviewer/tests/test_epochencoder.py:38: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <ephyviewer.datasource.epochs.WritableEpochSource object at 0x7ff8e059da00>
epoch = {'duration': array([0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25,
       0.25, 0.25, 0.25, 0.25, 0...', 'DDD', 'DDD', 'AAA', 'BBB', 'DDD', 'CCC', 'DDD', 'DDD',
       'AAA', 'DDD'], dtype='<U3'), 'name': 'MyFactor', ...}
possible_labels = ['AAA', 'BBB', 'CCC', 'DDD'], color_labels = None
channel_name = '', restrict_to_possible_labels = False

    def __init__(self, epoch=None, possible_labels=[], color_labels=None, channel_name='', restrict_to_possible_labels=False):

        self.possible_labels = possible_labels
        self.channel_name = channel_name

        if epoch is None:
            epoch = self.load()

        InMemoryEpochSource.__init__(self, all_epochs=[epoch])

        # assign each epoch a fixed, unique integer id
        self._next_id = 0
        for chan in self.all:
            chan['id'] = np.arange(self._next_id, self._next_id + len(chan['time']))
            self._next_id += len(chan['time'])

        assert self.all[0]['time'].dtype.kind=='f'
        assert self.all[0]['duration'].dtype.kind=='f'

        # add labels missing from possible_labels but found in epoch data
        new_labels_from_data = list(set(epoch['label'])-set(self.possible_labels))
        if restrict_to_possible_labels:
            assert len(new_labels_from_data)==0, f'epoch data contains labels not found in possible_labels: {new_labels_from_data}'
        self.possible_labels += new_labels_from_data

        # put the epochs into a canonical order after loading
        self._clean_and_set(self.all[0]['time'], self.all[0]['duration'], self.all[0]['label'], self.all[0]['id'])

        # TODO: colors should be managed directly by EpochEncoder
        if color_labels is None:
            n = len(self.possible_labels)
>           cmap = matplotlib.cm.get_cmap('Dark2' , n)
E           AttributeError: module 'matplotlib.cm' has no attribute 'get_cmap'

ephyviewer/datasource/epochs.py:89: AttributeError
___________________________ test_EpochEncoder_empty ____________________________

interactive = False

    def test_EpochEncoder_empty(interactive=False):
        possible_labels = ['AAA', 'BBB', 'CCC', 'DDD']

>       source = WritableEpochSource(epoch=None, possible_labels=possible_labels)

ephyviewer/tests/test_epochencoder.py:57: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <ephyviewer.datasource.epochs.WritableEpochSource object at 0x7ff8e059d640>
epoch = {'duration': array([], dtype=float64), 'id': array([], dtype=int64), 'label': array([], dtype='<U3'), 'name': '', ...}
possible_labels = ['AAA', 'BBB', 'CCC', 'DDD'], color_labels = None
channel_name = '', restrict_to_possible_labels = False

    def __init__(self, epoch=None, possible_labels=[], color_labels=None, channel_name='', restrict_to_possible_labels=False):

        self.possible_labels = possible_labels
        self.channel_name = channel_name

        if epoch is None:
            epoch = self.load()

        InMemoryEpochSource.__init__(self, all_epochs=[epoch])

        # assign each epoch a fixed, unique integer id
        self._next_id = 0
        for chan in self.all:
            chan['id'] = np.arange(self._next_id, self._next_id + len(chan['time']))
            self._next_id += len(chan['time'])

        assert self.all[0]['time'].dtype.kind=='f'
        assert self.all[0]['duration'].dtype.kind=='f'

        # add labels missing from possible_labels but found in epoch data
        new_labels_from_data = list(set(epoch['label'])-set(self.possible_labels))
        if restrict_to_possible_labels:
            assert len(new_labels_from_data)==0, f'epoch data contains labels not found in possible_labels: {new_labels_from_data}'
        self.possible_labels += new_labels_from_data

        # put the epochs into a canonical order after loading
        self._clean_and_set(self.all[0]['time'], self.all[0]['duration'], self.all[0]['label'], self.all[0]['id'])

        # TODO: colors should be managed directly by EpochEncoder
        if color_labels is None:
            n = len(self.possible_labels)
>           cmap = matplotlib.cm.get_cmap('Dark2' , n)
E           AttributeError: module 'matplotlib.cm' has no attribute 'get_cmap'

ephyviewer/datasource/epochs.py:89: AttributeError