Skip to content

Proposal for new neo.rawio API. - #355

Merged
samuelgarcia merged 88 commits into
NeuralEnsemble:masterfrom
samuelgarcia:raw_io_api
Oct 10, 2017
Merged

samuelgarcia merged 88 commits into
NeuralEnsemble:masterfrom
samuelgarcia:raw_io_api

Conversation

@samuelgarcia

Copy link
Copy Markdown
Contributor

This PR is for discussion around a new neo.rawio API see issue #354.

@coveralls

coveralls commented Jun 23, 2017 •

Copy link
Copy Markdown

Coverage Status

Coverage decreased (-1.9%) to 48.057% when pulling ae9428a on samuelgarcia:raw_io_api into 8997ad2 on NeuralEnsemble:master.

@coveralls

coveralls commented Jun 23, 2017 •

Copy link
Copy Markdown

Coverage Status

Coverage decreased (-1.9%) to 47.983% when pulling 92eb9ef on samuelgarcia:raw_io_api into 8997ad2 on NeuralEnsemble:master.

@coveralls

Copy link
Copy Markdown

Coverage Status

Coverage decreased (-2.0%) to 47.979% when pulling 92eb9ef on samuelgarcia:raw_io_api into 8997ad2 on NeuralEnsemble:master.

@coveralls

coveralls commented Jun 26, 2017 •

Copy link
Copy Markdown

Coverage Status

Coverage decreased (-1.8%) to 48.12% when pulling 0635348 on samuelgarcia:raw_io_api into 8997ad2 on NeuralEnsemble:master.

@coveralls

coveralls commented Jun 26, 2017 •

Copy link
Copy Markdown

Coverage Status

Coverage decreased (-1.1%) to 48.806% when pulling 39e9008 on samuelgarcia:raw_io_api into 8997ad2 on NeuralEnsemble:master.

@coveralls

coveralls commented Jun 30, 2017 •

Copy link
Copy Markdown

Coverage Status

Coverage decreased (-1.1%) to 48.817% when pulling 391ee30 on samuelgarcia:raw_io_api into 8997ad2 on NeuralEnsemble:master.

@coveralls

coveralls commented Jul 5, 2017 •

Copy link
Copy Markdown

Coverage Status

Coverage decreased (-1.5%) to 48.419% when pulling 52d7ee8 on samuelgarcia:raw_io_api into 8997ad2 on NeuralEnsemble:master.

@coveralls

coveralls commented Sep 27, 2017 •

Copy link
Copy Markdown

Coverage Status

Coverage decreased (-1.2%) to 48.526% when pulling f2b54b2 on samuelgarcia:raw_io_api into cf18db0 on NeuralEnsemble:master.

@coveralls

coveralls commented Sep 27, 2017 •

Copy link
Copy Markdown

Coverage Status

Coverage decreased (-1.2%) to 48.603% when pulling cde007e on samuelgarcia:raw_io_api into bd36cf0 on NeuralEnsemble:master.

@samuelgarcia samuelgarcia changed the title Proposal for new neo.rawio API (Ready for review) Proposal for new neo.rawio API. Sep 28, 2017
@samuelgarcia

Copy link
Copy Markdown
Contributor Author

neo 0.5.2 have been release to gather many PR and bug fixes.
Since this present PR is big change.
I propose to merge this soon in master before arrival of other PR.

The place for improvement will be directly in the master so.

Any remark before this ?

@muellerbjoern

muellerbjoern commented Sep 29, 2017 •

Copy link
Copy Markdown
Contributor

I tested the new BlackRockIO and compared the output to the old implementation, based on how @JuliaSprenger tested the NeuraLynxIO. I used the test files that are used for the UnitTests. The following is a list of the differences I found, sorted by objects. The points marked by "!" are the ones I think are most important.

  • Parameters for calling the IO

    • units ('units') and channels to load ('channels') cannot be specified any more (old parameters not accepted any more)
    • In old IO all nsX were loaded by default, now it's just the highest. This might be a problem, because sometimes not all values are in the highest nsX but rather in lower nsX, so they should be loaded by default as well
    • parameter 'scaling' is now 'voltage' by default, was 'raw' before
  • General

    • ! Unit and SpikeTrains are not linked, i.e. for every Unit object, unit.spiketrains is empty and for every SpikeTrain object, spiketrain.unit is empty as well
    • ! Times are not saved in sampling resolution but in seconds (=> keeping the native sampling resolution prevents accumulating rounding errors early on)
    • file origin and description missing most of the time
    • inconsistent values of attribute name, in ChannelIndex name is 'Channel group X', in AnalogSignal name is 'chanX'
  • AnalogSignals

    • more AnalogSignals/channels loaded by default, in old IO only channels to 128 were loaded by default, if found
    • no nsX value in annotations, so that it's difficult to understand from which nsX file the data was loaded
    • in anasig.description signals are now numbered, maybe start index at 1, like numbering for channel_id and label. It looks like this: 'AnalogSignal X from channel_id: Y label: chanY, nsx: 5', but X is always one less than Y: X=Y-1
  • Block

    • missing annotations, earlier there was more meta-information
  • ChannelIndexes

    • In old IO Units were linked to the ChannelIndex that the AnalogSignal with the same number was linked to. Why do you create extra ChannelIndexes for the Units?
    • missing annotations, earlier there was more meta-information
    • index becomes array with number instead of 0 => numbers too large, every AnalogSignal only has 1 channel
  • Events

    • additional annotations (copy and id), what are they for?
    • one new Event that is not found by old IO, has empty times and labels (called 'serial_input_port' (0,))
  • SpikeTrains

    • names look differently: 'ch1#0' was 'Unit 1000'
    • There is an additional annotation 'id', that contains the same content as SpikeTrain.name in old IO (e.g 'Unit 1000')
    • description contained 'unit: unclassified', is now 'unit_id: 0'
  • Unit

    • Annotations Channel_ID and Unit_ID don't exist any more, instead the information is combined in annotation 'ID'. So there is no possibility to access them seperately any more

Some of those differences are quite similar to what @JuliaSprenger reported for the NeuraLynxIO.

@samuelgarcia

Copy link
Copy Markdown
Contributor Author

Thank you for feed back.

The short answer is that the behavior of the old BlackrockIO will not be exactly similar that the new one. So choices we made specifically to the IO. In the new branch the same behavior should work for all IOs.

   units ('units') and channels to load ('channels') cannot be specified any more (old parameters not accepted any more)

This can be done at rawio API. For io API it is easy to add channel_indexes key. channel_ids is more ambiguous for some cases.

   In old IO all nsX were loaded by default, now it's just the highest. This might be a problem, because sometimes not all values are in the highest nsX but rather in lower nsX, so they should be loaded by default as well

You can do reader = BlackrockIO(filename='...',nsx_to_load=3) but it is not at instanciation not in read_block. This was too specific to blackrock. Specific kargs are now in init. This is easier and more consistent.

   parameter 'scaling' is now 'voltage' by default, was 'raw' before

At the moment reading raw data is only available at raw level but since the class is made by compisition. You can do reader.get_signal_chunk(...) and you get directly numpyint16.

    Unit and SpikeTrains are not linked, i.e. for every Unit object, unit.spiketrains is empty and for every SpikeTrain object, spiketrain.unit is empty as well

Oups, this is a bug in BaseFromRaw.

Times are not saved in sampling resolution but in seconds (=> keeping the native sampling resolution prevents accumulating rounding errors early on)

At the io level, yes, but you can get timestamp (original format) at the rawio level with spike_timestamps(..)

file origin and description missing most of the time

Oups. I will fix.

inconsistent values of attribute name, in ChannelIndex name is 'Channel group X', in AnalogSignal name is 'chanX'

This is due to signal_group_mode="group-by-same-units" or "split-all". I guess we need some discussion here.

   more AnalogSignals/channels loaded by default, in old IO only channels to 128 were loaded by default, if found

OK. I was not aware of that. We can clip the channel exploration to 128. Is it the case for all blackrock system ?

   no nsX value in annotations, so that it's difficult to understand from which nsX file the data was loaded

I will add this.

   in anasig.description signals are now numbered, maybe start index at 1, like numbering for channel_id and label. It looks like this: 'AnalogSignal X from channel_id: Y label: chanY, nsx: 5', but X is always one less than Y: X=Y-1

I don't get this. X is the channel_index (0 based) can't be sparse. Y is the channel_id (1 base in the case of Blackrock) can be sparse. What is the expected descr ?

   missing annotations, earlier there was more meta-information

I need to check.

   In old IO Units were linked to the ChannelIndex that the AnalogSignal with the same number was linked to. Why do you create extra ChannelIndexes for the Units?

This cannot be done here at the moment because the BaseFromRaw is generic.
If someone have a solution for this. The IOs are able to do that. Some other not....

   missing annotations, earlier there was more meta-information

I need to check.

   index becomes array with number instead of 0 => numbers too large, every AnalogSignal only has 1 channel

This behavior can be fixed with signal_group_mode="group-by-same-units" or "split-all".

   additional annotations (copy and id), what are they for?

This is something general at rawio level. All channel have an id.

   one new Event that is not found by old IO, has empty times and labels (called 'serial_input_port' (0,))

I need to check. Is it a problem ?

   names look differently: 'ch1#0' was 'Unit 1000'

This is my choice. I thin this more explicit to have both channel and unit id. No ?

   There is an additional annotation 'id', that contains the same content as SpikeTrain.name in old IO (e.g 'Unit 1000')

Same answer.

   description contained 'unit: unclassified', is now 'unit_id: 0'

I can add this but not in name or id. Maybe another key ?

   Annotations Channel_ID and Unit_ID don't exist any more, instead the information is combined in annotation 'ID'. So there is no possibility to access them seperately any more

Yes but with other key.

Some of those differences are quite similar to what @JuliaSprenger reported for the NeuraLynxIO.

Yes they are!

I will fix most of theses soon when it is easy. Then I propose to merge this branch in the master.
It will easier for other developers related to previous IO implementation to propose a PR that could enhance everybody needs.

It is now more clear were to put changes : in the RawIO directly when it is specific or in BaseFromRaw when we want a global behavior for all IO.

@JuliaSprenger

Copy link
Copy Markdown
Member

@samuelgarcia thanks for the quick relpy. We are currently looking into your comments and will come back to you soon. However, before merging this branch, we would like to test the new BlackrockIO not only on a single test data set (as done above) but also confirm that the new IO is working for real datasets containing more data and also recordings using different versions of Blackrock files. This might take a couple of days, but we will keep you informed.

@samuelgarcia

Copy link
Copy Markdown
Contributor Author

@JuliaSprenger. Yes of course we can wait a before this merge. Merging soon is nevertheless important because any incoming PR could lead to conflict with rawio.

I propose:

  • keep explicitly OldBlackockIO and OldNeuralynxIO in the master for a long overlapping time to not break everyhting in existing pipeline you have.
  • add some commit in rawio branch this week.
  • merge rawio let's say next week. (but refusing any PR that concern theses IOs in old fashion)
  • discuss this new API and specific IO stuff directly in the master with PR and reviews.

In any case the release of 0.6.0 will be in a long time.

Is it OK for you ?

@samuelgarcia

samuelgarcia commented Oct 2, 2017 •

Copy link
Copy Markdown
Contributor Author

Unit and SpikeTrains are not linked, i.e. for every Unit object, unit.spiketrains is empty and for every SpikeTrain object, spiketrain.unit is empty as well

This is strange, because the link is already done. Do you have my latest latest raw_io_api branch ?

missing annotations, earlier there was more meta-information

Could you be more specific ?

description contained 'unit: unclassified', is now 'unit_id: 0'

unit_id still is unit_id but I have added unit_tag for this = 'unclassified', 'noise' or str(unit_id)

names look differently: 'ch1#0' was 'Unit 1000'
We now have at line 252

                    name = "ch{}#{}".format(channel_id, unit_id)
                    _id = "Unit {}".format(1000 * channel_id + unit_id)

if you prefer we can swap name<-> _id.

I have push a new commit that fix some annotations problems.
For more annotations see BlackrockRawIO line 339 - 390.
Adding a new one is easy.

@JuliaSprenger

Copy link
Copy Markdown
Member

@samuelgarcia: I agree to your proposed plan. Keeping both versions of the IO would help a lot. Maybe we can do the same for the NeuralynxIO for some time?

@samuelgarcia

samuelgarcia commented Oct 4, 2017 •

Copy link
Copy Markdown
Contributor Author

OldNeuralynxIO is now in neo.io.neuralynxio_v1

The __init__ look like this

from neo.io.neuralynxio import NeuralynxIO #the new based on rawio
from neo.io.neuralynxio_v1 import NeuralynxIO as OldNeuralynxIO #the old one with all annotations
...
from neo.io.blackrockio import BlackrockIO
from neo.io.blackrockio_v4 import BlackrockIO as OldBlackrockIO

If there is another IO you want to keep in double version teel me.

@coveralls

coveralls commented Oct 4, 2017 •

Copy link
Copy Markdown

Coverage Status

Coverage decreased (-0.9%) to 49.035% when pulling e10fe7a on samuelgarcia:raw_io_api into e43ed54 on NeuralEnsemble:master.

@muellerbjoern

Copy link
Copy Markdown
Contributor

I worked through your comments and will write a detailed answer to them soon. In addition, I just investigated whether it is possible to load different real Blackrock datasets. I noticed that it seems that some version checks are missing. blackrockrawio.py fails for file version 2.1 in _parse_header at line 244, because 'NEUEVFLT' cannot always be read as a key from the header (i.e., this Block is not existent in version 2.1). In the old IO 'NEUEVFLT' is only referenced in a function that would be run for file versions 2.2 and 2.3, whereas _parse_header in the new IO is called in any case.

As a somewhat related issue, could you please explain a bit more in detail how to load only specific channels in your new IO? I don't quite understand what you meant and don't want to crash everything by loading a complete ns5 dataset.

@coveralls

coveralls commented Oct 9, 2017 •

Copy link
Copy Markdown

Coverage Status

Coverage decreased (-0.9%) to 49.033% when pulling 34f6a60 on samuelgarcia:raw_io_api into e43ed54 on NeuralEnsemble:master.

@samuelgarcia

Copy link
Copy Markdown
Contributor Author

Thank you Björn for this investigation across the code.

I have done a fast patch for NEUEVFLT changed NEUEVWAV. Could you test it ?

For channel you have several possibilities for selecting (only at rawio level for the moment):

reader = BlackrockRawIO(filename='FileSpec2.3001')
reader.parse_hedaer()

#read all signals channels
raw_sigs = reader.get_analogsignal_chunk(channel_indexes=None)

#select by channel_indexes
raw_sigs = reader.get_analogsignal_chunk(channel_indexes=[0,  2, 4])

#select by channel_ids (note tha in Blackrock id is one based and this is specific to blackrock and some other
raw_sigs = reader.get_analogsignal_chunk(channel_ids=[1, 3, 5])

#select by channel_names
raw_sigs = reader.get_analogsignal_chunk(channel_names=['chan1', 'chan3', 'chan5'])

The file for testing is 2.3. If you have the small dataset <10Mo for 2.1 and 2.2, we could put them at gnode portal and use them in the test suite.

Since the neo.io Blackrock is done by inheritance with BlackrockRawIO get_analogsignal_chunk() is also available.

Have you seen the doc doc/source/rawio.rst ?

I will add in doc the channel selection stuff.

@coveralls

coveralls commented Oct 9, 2017 •

Copy link
Copy Markdown

Coverage Status

Coverage decreased (-0.9%) to 49.035% when pulling 15f26fd on samuelgarcia:raw_io_api into e43ed54 on NeuralEnsemble:master.

@samuelgarcia

Copy link
Copy Markdown
Contributor Author

I guess it is time to merge this rawio.
Lets improve rawio directly in master.

@samuelgarcia
samuelgarcia merged commit c9cdfbb into NeuralEnsemble:master Oct 10, 2017
@samuelgarcia
samuelgarcia deleted the raw_io_api branch April 10, 2019 10:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants