Repository navigation
Adapting BlackrockIO for new features of version 2.3 - #523
Conversation
- time stamps of nsx data pakets are recorded in timestamp resolution and not in sampling rate
* Tries to extract segments in nev (2.3) files via comment events * Adds additional segments if spike times are reset to 0 * Tries to match segments of nsx files with those of nev files -> to be improved
This does not create detectable segments in nev files, so these need not be checked
Enabled loading multi segment nsX files without nev
Now nev files with 'Pause' can be loaded with the nev correctly cut into segments. Only situation that is not covered are 'Reset' segments that are not shown in the nev
Not working currently
This is faster now and also segment/spiketrain t_start and t_stops are correct
This makes spikes within one period (i.e. time between two samples) of a segment belong to the corresponding segment.
Now Blackrock files with pause and/or reset should load completely fine, even nev without nsX. If something cannot be determined, a warning is shown or an error is raised, depending on how severe it is
All timestamps seemed to be before the first segment, because with the tolerance around segments, the start timestamp was negative which lead to an integer overflow causing the start timestamp to be ~2^32.
could continue until then. For example ns6 is shifted by 82 samples to ns2, so it starts recording at 82 and stops about 82 samples after ns2 (as far as one can tell from the low resolution of ns2). Then spike extraction COULD (not sure) be from 0 samples to end of ns2 + 82 samples. So whenever anything is recorded, spike extraction MIGHT happen, thus the most liberal implementation is used here, in order to get all spikes.
When no reset was detected in nev although there was one in nsX, then so far it raised an erros. But if the first segment of the relevant two can be determined to be empty, then it is clear all spikes belong to the next segment
|
Hello @bjoern1001001! Thanks for updating the PR.
Comment last updated on July 02, 2018 at 13:25 Hours UTC |
|
I just added tests that make sure segments are detected correctly and their start and stop times are correct. There are multiple tests with different files in order to check all situations:
In my opinion this PR is thus finished. |
| import os | ||
| import re | ||
| import warnings | ||
| import time |
There was a problem hiding this comment.
I don't think this import is necessary any more...
|
Sharp eye. |
I had used this for testing the performance
Those mainly contained now unused print statements I used for debugging
|
Oops, I'm sorry, I forgot this there. @samuelgarcia What you mentioned some time ago about try: ... except ... not being explicit should be fixed alreadly as well. |
These files were duplicate, so I did not upload them to gin but never removed them from the files that should be downloaded by the tests. I never noticed, because tests were not failing for me. On Python3, they are skipped, but on Python2 you would never notice anything because of how urlretrieve works. Instead of failing with Error 404, it would just download the HTML page showing an image with 'Error 404' or something. This makes the files available and thus causes the test not to be skipped. If one tried accessing them, the test would fail, because the file is an HTML file.
| else: | ||
| ts = np.math.ceil(t_start * self.__nev_basic_header['timestamp_resolution']) | ||
| ind_start = np.searchsorted(timestamp, ts) | ||
| # SearchSorted does not apply. timestamp is not sorted! |
There was a problem hiding this comment.
is this comment still up to date? I guess it's not, but it's not obvious to me.
There was a problem hiding this comment.
I don't remember who write this comment.
Is it me ?
There was a problem hiding this comment.
No, this stuff is introduced in this PR. I probably entered it in an early version of this PR.
There was a problem hiding this comment.
Yes, as far as I remember this came from you. But as it only refers to single segments, searchsorted should work anyway because spikes are sorted for each segment. So I just removed the comment.
| return waveforms | ||
|
|
||
| def _event_count(self, block_index, seg_index, event_channel_index): | ||
| # TODO: Should this only return NonNeural events or also Comment events ? |
There was a problem hiding this comment.
currently only NonNeural events are counted. Is there a reason to exclude Comment events here?
There was a problem hiding this comment.
I don't remember.
I guess here both nonneural + comments should count in different event channel.
| events_data = self.nev_data['NonNeural'] | ||
| events_data, event_segment_ids = self.nev_data['NonNeural'] | ||
| ev_dict = self.__nonneural_evtypes[self.__nev_spec](events_data)[name] | ||
| mask = ev_dict['mask'] & (event_segment_ids == seg_index) |
There was a problem hiding this comment.
mask is never used -> can be removed here
| mask = ev_dict['mask'] & (event_segment_ids == seg_index) | ||
|
|
||
| timestamp = events_data[ev_dict['mask']]['timestamp'] | ||
| labels = events_data[ev_dict['mask']][ev_dict['field']] |
There was a problem hiding this comment.
mask should be used here instead of ev_dict['mask'] for the 2 previsous lines
There was a problem hiding this comment.
Yes, you are right. I fixed this.
|
|
||
| # Only needs to be done for nev version 2.3 | ||
| if self.__nev_spec == '2.3': | ||
| # TODO: Set earlier for 'self' and find out values!!! |
There was a problem hiding this comment.
@bjoern1001001: please update these todos and comments
Until now it just returned all event timestamps instead of only the ones belonging to the correct segment
I had rearranged nev segments for events and spiketrains seperately causing the events to have a segment_id that is too low, so they were matched tothe wrong segment. This is now fixed by only rearranging if nsX segments have to be rearranged
AnalogSignal.t_start must not be set to SpikeTrain.t_start if there were spikes before the AnalogSignal recording started. This would shift all values.
| if length < 2: | ||
| nb_empty_segments += 1 | ||
| self.nsx_data.pop(data_bl) | ||
| # TODO: CHECK WHAT HAPPENS HERE AND IF -1 IS CORRECT |
There was a problem hiding this comment.
is this comment still valid?
I think subtracting 1 of data_bl is not the right solution since it is only providing the reset of the counter in the current run of the loop, but in the next run the index is continued as usual. Maybe it would be better to use while here instead of a for loop.
It was not necessary to reduce the loop index. The supposed fix did not even do this.
This makes the code a lot more manageable
| # Path to nev that has spikes that don't fit nsX segment | ||
| filename_nev_outside_seg = self.get_filename_path( | ||
| 'segment/PauseSpikesOutside/pause_spikes_outside_seg') | ||
| # Path to nsX and nev that are correct |
There was a problem hiding this comment.
what exactly is 'correct' here? non-corrupted?
Blackrock file version 2.3 enables features like a reset of the global timestamp clock or pauses during recording. This creates multiple segments in nsX data whereas in the nev files there is usually nothing that shows the beginning of a new segment. Thus, nev segments need to be mapped from the nsX or, if this is not available, segments can be distinguished, when a reset occurred and the timestamps start from 0 again. If the recording was paused and thus the timestamps were not reset, this can only be done using the nsX file.
This pull request enables the following:
If this is not possible, the segments cannot be distinguished and a ValueError is raised
I will now create test files for this and write tests.