Repository navigation
WIP: Realtime - #382
WIP: Realtime#382mluessi wants to merge 14 commits into
Conversation
|
So basically, we'd have It occurred to me that it would be useful for testing and such (for nosetests but also for people who will actually use the code ) to have a "simulation mode", where an epochs FIF file can be used to fake realtime inputs to |
|
Both proposals seem reasonable to me. BaseEpochs seems nicer than 'ugly hack'! On 14.01.2013, at 22:14, Eric89GXL [email protected] wrote:
|
|
On 01/14/13 16:14, Eric89GXL wrote:
Yes, that's the idea. It is not strictly necessary to have a common base
Yes, we will need a simulator for testing. Right now I use mne_rt_server |
|
Sounds good -- I'd much prefer one more layer of abstraction ( |
|
+1 For a BaseEpochs object. I would call RtEpochs just Epochs as the import name makes it obvious |
|
I don't think renaming RtEpochs to Epochs is a good idea. I know it is redundant but don't you think it will be confusing to the user when there are two classes that have the same name but behave differently? |
|
ok fair enough |
|
@mluessi fixed the calibration issue: simulator isn't anymore de-calibrating before sending. Ouptut should be now the same as reading raw data directly. |
|
@chdinh there was never a problem with the calibration (the strange output in #213 was due to a wrong reshape). Does the mne_rt_server apply the calibration when reading from the neuromag system, or is this done before by the "neuromag collector"? We should either always have calibrated data coming from the server or always assume the client applies the calibration. |
|
Good point - right now calibration isn't applied to the neuromag data within the mne_rt_server. I'll change this, that it will be consistent with the fiff simulator. |
|
Is it possible that we lose precision if we apply calibration but keep the data 32bit float? In mne-python we use 64 bit floats when we apply calibration, but if you do so and send the data over the network it would double the amount of data. So if precision is a problem we should apply the calibration at the client side. |
|
Actually within mne-cpp internally everything is treaded as doubles. But for storing, data are casted back to float and so in the case of broadcasting data over TCP/IP. We can also broadcast data using double - we have enough resources to do that. |
|
If 32 bit floats after calibration cause potential precision problems, I think we should do the calibration on the client side. While it is true that we right now have the resources to send doubles over the network, we can reduce the amount of data by a factor of two without any negative consequences. Only the calibration has to be done on the client side, but this is very easy to do (and computationally cheap). Maybe @agramfort and @mshamalainen can weigh on this issue as well. |
|
+1 for transfering float32 and do calibration on client side after a cast |
|
I think ideally, the mne_rt_server should be able to receive both float32 and float64 data from the plugin and then transparently (=without doing any processing) forward the data as raw buffers to the client. For current systems, we use float32 and apply the calibration at the client side, but if for some reason the plugin or "collector program" wants to do processing and it is better to send float64 data, this is supported as well and doesn't require any changes to mne_rt_server. WDYT? |
|
sounds reasonable to me |
|
Added This will probably stay WIP for a while as we are currently implementing some of the communication with the mne_rt_server plugins using JSON, see mne-tools/mne-cpp#5. |
|
Okay - we can transparently forward the data buffers. What we should keep in mind is: that mne_rt_server runs mostly on this powerfull Linux neuromag workstations by basically doing nothing computational intensive - so this neuromag workstation is kind of bored. Also mne_rt_server is highly threaded that we can do computational intensive parts in different parallel jobs. I see that you wanna have the full control about what's going on within the python side - but for stuff like calibration... WDYT? |
|
I think we should keep mne_rt_server as transparent as possible. Given that applying the calibration on the client side is simple to do and computationally very cheap (just one multiplication per sample), it IMHO just does not make sense to increase the the code complexity on the server side and double the amount of data that needs to be transmitted by moving the calibration to the server. What do you think about supporting both float32 and float64 raw buffers at the same time*? This will give people the freedom to do processing in the mne_rt_server plugin if they want to and the transmit the data as float64. *Of course a plugin would either use float32 or float64, but the server wouldn't need to be recompiled. |
|
okay than we should do that - but we still should have in mind that one of the fastest matrix multiplication algorithms (coppersmith) implementation still needs a computational effort of O(n^2.376) and even if that operation only needs 2% of the processor capabilities we have 2% less to do some fancy stuff. Especially when I think of compiling a real-time display for a tablet device... battery life and so on... |
|
@mainakjas I rebased this old PR using the newest master. It is till WIP, i.e., unit tests need to be added and I have to double check that the changes don't break anything else that was recently introduced. Have a look at the example, let me know if you have comments / questions. |
There was a problem hiding this comment.
When does this happen? Is this something that the RT server does? It would be better to update this comment if that's the case.
There was a problem hiding this comment.
Yeah.. I agree it's a dirty temporary fix. For some reason the data coming from the RT server is transposed. I will update the comment.
There was a problem hiding this comment.
Oh let me know if there is something wired - I also had a transposing issue. Can be the fault of mne_rt_server.
|
@mluessi Thanks a lot! Looking into it ... will let you know soon if/when On Tue, Apr 23, 2013 at 10:07 PM, Martin Luessi [email protected]:
|
|
fixed it -> rows = length(names) |
|
@mluessi I get an error which goes something like this: [1] run realtime/compute_rt_moving_average.py
========================================================
Compute real-time evoked responses using moving averages
========================================================
This example demonstrates how to connect to an MNE Real-time server
using the RtClient and use it together with RtEpochs to compute
evoked responses using moving averages.
Note: The MNE Real-time server (mne_rt_server), which is part of mne-cpp,
has to be running on the same computer.
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/ipython-0.13.2-py2.7.egg/IPython/utils/py3compat.py", line 178, in execfile
__builtin__.execfile(filename, *where)
File "/home/mainakjas/github/mne-python/examples/realtime/compute_rt_moving_average.py", line 24, in <module>
from mne.realtime import RtClient, RtEpochs
ImportError: No module named realtimeThe realtime folder is present and other folders examples appear to be running right. |
|
@mainakjas the realtime module was missing from |
|
@mluessi thanks! it works now (or at least it doesn't give any error) and I see that a plot is updated in real-time :-) Exploring further now ... |
|
another quick question @chdinh. I have to cd to mne-cpp/bin to run mainakjas@Mainak:~/github/mne-cpp$ echo $PATH
/home/mainakjas/github/mne-cpp/bin:/opt/MNE-2.7.0-3106-Linux-i686/bin:/data/freesurfer/bin:/data/freesurfer/fsfast/bin:/data/freesurfer/tktools:/data/freesurfer/mni/bin:/opt/Qt/qt-creator-2.6.2-src/bin:/opt/Qt/Qt5.0.1/bin:/usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/gamesSo, it does have the mainakjas@Mainak:~/github$ ./mne_rt_server
bash: ./mne_rt_server: No such file or directoryIt's not a big thing as I can |
|
@mainakjas glad it works now :). To run |
|
Oh, that was it! Yes, leaving out the ./ solved the problem. |
|
well, the sample data problem is there too -- leaving out the ./ starts the server alright but then I get: Opening raw data ../../mne-cpp/bin/MNE-sample-data/MEG/sample/sample_audvis_raw.fif...
Cannot open ../../mne-cpp/bin/MNE-sample-data/MEG/sample/sample_audvis_raw.fif
Error: Not able to read raw info!
send measurement info to FiffStreamClient (ID: 0)We should probably specify the absolute path (by using the environment variable) rather than relative path: i.e. |
|
thx good hint - I'll look into it. Meanwhile one have to run mne_rt_server from inside the bin directory - sorry for that inconvinience |
|
If you want to change it - you're welcome :-) |
|
ok, I'll try to look at it over the weekend - I am not sure if the environment variables would work within C. Depends on how you have implemented it, but I don't mind prying into the code :-) |
|
What is the relationship between this PR and the one @mainakjas has open? In other words, can we close this one in favor of his, or do they implement different functionality? |
|
I just checked, and it looks like we should be able to just have @mainakjas's PR to work from. I'm going to close this to move discussion to that PR. @mluessi if you think that's counterproductive, feel free to reopen. |
|
My idea was to merge this soon after the 0.6 release, after a bit more polishing and after the mock server and unit tests have been added. @mainakjas decoding PR (#382) can then be recreated on top of the new master. So I'm reopening it.. |
|
By the way, should I keep rebasing from master in the meanwhile? Or is On Fri, Jun 7, 2013 at 4:29 PM, Martin Luessi [email protected]:
|
|
I think for now it is best to just keep working on your branch, no rebasing required. Once this PR has been merged, you can make a new decoding branch that just includes your commits. |
|
ok good, that's simple. Thanks! On Fri, Jun 7, 2013 at 6:09 PM, Martin Luessi [email protected]:
|
|
closing this as it's now in #615 |
This is a rework of #213. My idea is to have a real time epochs class
RtEpochsthat behaves similarly toEpochs, but the data is received continuously from an mne_rt_server via anRtClientinstance which pushes the received raw buffers to theRtEpochsinstance(s). You can e.g. doThis code will receive 5 (good) epochs, compute an evoked response, and plot it. Then the next 5 epochs are received (5 because the
n_epochsparameter in the constructor is 5). The idea is that it will be possible to pass an instance ofRtEpochsto most functions that acceptEpochsas input, e.g.,apply_inverse_epochs,spectral_connectivity(for the latter, then_epochsargument is useful, as onlyn_epochswill be used for the connectivity computation).The code works but one problem is that
RtEpochsis derived fromEpochs, which has many methods which don't work when real time processing is used. Right now, those methods are disabled using an ugly hack. The proper solution would be create a new classBaseEpochsand derive bothEpochsandRtEpochsfrom that class. Is anyone opposed to this solution?