Repository navigation
Description
I plan a refactoring of some (many?) (all ?) IO classes in neo.
I have a strong need in tridesclous to acces data:
- In Raw format (very often int16)
- Fast acces
- chunk access
I also need this for writting fast viewer for dataset.
They actual neo.io API is far from that because for almost all IOs evrything is copied in memory (and sometimes twice) and converted to float32 or float64 without rules or control on that. Actual output of our IOs is a tree of neo object. We try in the past to make to lazyload API but this is difficult for users and developpers. I guess that very few of us are using it.
With the size of actual dataset in ephys expiremt we need a strong change.
Here 2 examples of 2 (anonymous) guys involved in neo team but re-coding there own readers only for themself (to bad!!):
- https://github.com/spyking-circus/spyking-circus/tree/master/circus/files
- https://github.com/samuelgarcia/tridesclous/blob/master/tridesclous/datasource.py
So, I would like to entirely refactor the io API to be able to stream and load chunk or selected channel easily and in an efficient way.
To not break everything and to have a slow transition I propose to have 2 levels for IOs:
- one, top level, that give neo objects as today.
- another, low level, that stream buffer in the original format (int16, int32, float32).
The layer 2 would something that expose something like that:
- read_header(...) and every stuff we need later one to have a fast acces.
- get_nb_block()
- get_nb_segment(block_num)
- get_nb_analogsignals(block_num, seg_num)
- get_nb_spiketrain(block_num, seg_num)
- read_analogsignal_chunk(block_num, seg_num, channel_indexes, i_start, i_stop) this give raw data (often int16)
- rescale_to_float(..)
- rescale_to_quantities(..)
- channel_name_to_index()
- channel_index_to_name()
- channel_id_to_index()
- channel_index_to_id()
- equivalent stuff for spiketrain
With this kind of level 2 API we could have one level 2 class for an IO and the level 1 would auto generated.
Example:
# low level class that accces to chunks in raw format:
class BlackrockIORaw:
pass
# Class to bridge new raw API to old neo obect API
class GenericNeoLegacy:
pass
# Class the behave as before and read neo objects.
class BlackrockIO(GenericNeoLegacy, BlackrockIORaw):
passI propose to do this only for readers at the moment. (writting is more complicated).
There are 2 possibles place to do that:
- In a sperate project (ephyreader, rawneo, ...) and some neo.io classes could depend on that.
- make this insisde neo project in neo.rawio and some classes could depend on that.
I prefer solution 2, because everything append here and we will be able to refactor slowly one by one some popular IOs.
I will push this summer a PR to propose this new structures for only one IO maybe BlackrockIO if it is not a problem (@mdenker ?).
This PR would be place for discussion of this new rawio API.
I need feedback and help.
Samuel
Activity
samuelgarcia commentedon Jun 23, 2017
Here is a very first drafty test for blackrock and for signal only.
#355
Look at this:
https://github.com/samuelgarcia/python-neo/blob/raw_io_api/neo/rawio/tests/text_blackrockrawio.py
achilleas-k commentedon Jun 23, 2017
Part of this came up recently as a requirement for the NIX IO, namely being able to get a description of the file without loading everything (number of signals, for instance). I would say it's certainly a useful feature.
A small nitpick, since feedback was requested:
get(andset) methods aren't generally considered very pythonic and I also find them needlessly verbose. I'd prefer method names similar to:reader.num_blocks()reader.num_analogsignals(block_num=0, seg_num=1)or perhaps
reader.block_count()(this one is probably the least ambiguous).I would also be curious to know if total counts would be useful. For instance:
reader.num_analogsignals()with no arguments could return the total number of AnalogSignals in a file, regardless of how they are separated into Blocks and Segments.samuelgarcia commentedon Jun 23, 2017
Thank you. Better semantic.
For reader.num_analogsignals() with argument I would prefer to avoid any amgic at the low level IO.
I think that fastiduous and unambiguous is better. So for this a loop or another method. No ?
achilleas-k commentedon Jun 23, 2017
Sure, there's no need for it to be very complicated behind the scenes. I was simply commenting on the API definition.
samuelgarcia commentedon Jul 4, 2017
This new API is still very very drafty but we can have an global overview with theses files:
Any feedback would very helpfull.
samuelgarcia commentedon Jul 12, 2017
MicromedIO have been ported very easily in neo.rawio.
So now there are 3 RawIO: ExampleRawIO, MicromedRawIO, BlackrockRawIO (still drafty).
mdenker commentedon Jul 12, 2017
In principle, the idea to access detailed info on the data file is a good one -- we had done something similar with our BlackrockIO in the beginning of its development by adding fileformat-specific functions to the IO, but since this was not really an API it was then suggested to put everything in annotations of the Block, and then use lazy/nonrecursive loading to get this information. While this works to a large extent, in practice this is somewhat cumbersome, so an API would be a really useful feature. Also, some things like loading chunks of data, or choosing between raw DAC int values vs converted voltage values, are currently performed using custom parameters of the BlackrockIO, which is of course not a good solution. This seemed a concensus with a number of people I talked to. However, the main question will be to see at which level the API is generic enough to be able to work on all file formats.
samuelgarcia commentedon Jul 12, 2017
For the raw signals data (in16 often) the APi is pretty simple:
Things are more complicated with spikes and waveforms....
samuelgarcia commentedon Aug 2, 2017
Actual list of io ported to rawio:
samuelgarcia commentedon Aug 21, 2017
Actual list of io ported to rawio:
*Axon
samuelgarcia commentedon Sep 21, 2017
Added:
So NeuralynxIO and BlackrockIO have normally the same behavior as before.
Only one thing is missing at the neo.io level: ability to select a subset of channel. It was done before in NeuralynxIO and BlackrockIO with very specific way. It will be hard to put this at neo.io for all IOs. Since this is possible to have a subset of channel at neo.rawio level. I think it is wise to not have this possibility of channel selection at neo.io level. It sounds a bit complicated to cover all cases (ex: NeuroexplorerIO with several sampling_rate problem).
samuelgarcia commentedon Sep 21, 2017
A good way for testing all RawIOs is to use the unreleased ephyviewer.
You can use ephyviewer in standalone mode:
And with that neo branch (>=0.6.0) you are able to open files supported by neo.rawio et get a fast viewer that do not load every thing in memory.
samuelgarcia commentedon Jan 22, 2018
Done