Python crashes/videos don't show
Hello,
I am currently trying to conduct an EEG experiment, where participants' brainwaves are measured in reaction to a certain kind of video-content. Therefore, I use videos (six 4-7-minute videos, .flv, 120 Mb total) as stimuli in OpenSesame. In order to set the time trackers needed for spotting significant reaction intervals, triggers were installed. System and program versions: Win7 64bit with 32Gb RAM, OpenSesame 3.3.10, Python 3.7.6.
The problem is, that when I am trying to use Legacy or Psycho-legacy libraries, Python crashes, every time - after a few minutes of loading, when the first video is launched.
When I use PsychoPy, the videos are stuck loading for several minutes, then the program either proceeds to the next video, or the sound is suddenly launched, without video. After around three repetitions (three videos), Python crashes. Also, the "Oops, I did it again..." message shows.
When I use the Xpyriment library, videos are launched with a 5-20 min delay and the video format (height/width) settings are off.
The script was overchecked several times (by my thesis' lead, I myself am not competent in programming), I am completely clueless as for what the error could be and how to fix it.
May I ask for any insight? I will provide any specific info needed.
Comments
Hi Volchi,
What video plugin are you using? If you like you can share your experiment and the videos (maybe via wetransfer or something), then I can try to have a look and see whether there is anything weird going on.
Eduard
Hello Eduard,
I think it is media_player_mpy plugin, since I changed no plugin settings after the installation of the program. It's also something I haven't paid attention to lately, so I will, as soon as I get to the lab.
Very kind of you to do so, thank you! This download link should work https://jucb-my.sharepoint.com/personal/volchi00_jcu_cz/Documents/P%C5%99%C3%ADlohy/Final_hetero_ads%20(posledn%C3%AD%20aktu%C3%A1ln%C3%AD%20verze).osexp
Best regards,
Volchi00
Hi Volchi00,
I can't download it, it seems I have to log in to microsoft before I could?
Hello Eduard,
it may be, but I'm not sure, so try this one, please:
https://drive.google.com/file/d/1HXSSXZMG76FYKMsHA_EZGqft8beZBDGP/view?usp=sharing
Thanks!
Yeah, this one worked. I had also issues running it. What solved it was using Expyriment as backend, and converting all the video to ".mp4" format (avi should also do). Can you try that?
Aside of that, it might be better to not store the videos within the file pool, but just in the same folder as the experiment itself. A file pool of >100 Mb could cause some performance issues.
To specify which file to run, you can put in the entire path as the source for the video:
path/to/osexp_directory/1het2.mp4
Hope it helps,
Eduard
I saw this as the problem (the file pool - well, the notification was simply appearing all the time) from the very start, located the videos in the experimental folder, but couldn't find a way to specify the running path. Just to be precise, could you tell me, where exactly I must enter the path to the videos for it all to work as needed?
I will try it all out ASAP. Thank You very much, Eduard.
G'day Eduard,
I've changed video format to .mp4, entered the path for every video (located in the experimental folder) in " set video src "" " line in the script, and used Expyriment as backend, but the problem remains... What could possibly be wrong, if it worked for you?
Thanks again,
Volchi00
Just to be precise, could you tell me, where exactly I must enter the path to the videos for it all to work as needed?
at the top of the video plugin, there is a field for the input that should be played.
I attach an experiment that works.
Hello Eduard,
On the input field: right, thank you, I noticed the silly mistake - failing to enter the path through 'Browse' before got me confused (it all just went to the pool).
I tried it out, everything is functional. I can't thank you enough, Eduard.
One question though: did removing the clock.sleep statements kill the time triggers? And if so, could you lastly advise, how to input the time triggers for EEG recording correctly, so that they wouldn't stall the whole experiment?
Big thanks again,
Volchi00
Hello Eduard,
to be more precise, could you please tell me, which function I should use to enter the specific time for the trigger (for the dlportio.dll variant, which is currently used in the script)? Couldn't find this information on the Parallel port instructions page (https://osdoc.cogsci.nl/3.3/manual/devices/parallel/), neither here https://osdoc.cogsci.nl/2.8.3/devices/triggers/. There is one specific instruction for it in this blog https://neurosciencemike.wordpress.com/2016/07/20/send-eeg-triggers-from-opensesame-by-parallel-port/, where the author advises to formulate it like this:
global
io
trigger =
1
port =
0xCFF8
io.DlPortWritePortUchar(port, trigger) # Send you trigger (int 1)
self.sleep(50) # Uses trigger pulse for 50 ms
io.DlPortWritePortUchar(port, 0) # Get back to zero after 50 ms
This is kind of strange as well, since the "sleep" function is used here too... Dammit, I regret not taking a programming course yet.
Functional triggers are the last thing I need to successfully run the experiment (hopefully). I am kindly asking you for this piece of advice.
Thank you,
Volchi00
To be very accurate and make sure not to hinder your experiments, you should look into parallel processes. However, there are many things that can go wrong there, so I wouldn't recommend it, unless you really really know what you are doing.
clock.sleep(time) # time in milliseconds
Is the way to go. However, keep in mind that your experiment is essentially on hold for that amount of time. So if you need a stimulus duration of 400 ms, you should keep in mind that 50 ms are always present (if you have a trigger sleep of that duration). In that case, it would make sense to set the duration to 350 ms, to take the extra time into account. Generally. A sleep of at least 10-20 ms is recommended (based on my intuition and previous experience). Also you need to set the trigger back to 0 (with a similar sleep afterwards).
That all being said, the only way to be sure is piloting your experiment, and measure:
Once you have that, you are good to go!
Good luck,
Eduard
Hello again,
wouldn't like to trouble you too much, but there's a novel question...
What could be the reason for the trigger not appearing in Biosemi EEG signal viewing program (ActiView), if the parallel port is functional?
I've tried changing the address of the parallel port in the script, changing trigger timing to 10, 20 and 50 ms (don't know how exactly it could help with the trigger sending...), checking dlportio.dll (the file is present in both opensesame root folder and SysWOW64, should be installed correctly).
I am adding the current script for the triggers down below (this is the one sent back to me by the tech lead od the thesis. I can see that there are no sleep.clock statements included, but toying around with them in the earlier experiment versions (which I mentioned in the what-I-tried list) didn't work either. Maybe editing them into this version correctly would change something?(failed at doing it myself, the experiment stopped working after my "corrections")).
Also, is there no way to input several triggers for one stimulus? Last time the attempt to do so led to the first problem, which you helped solve by basically killing the triggers.
Then you said, that the method used for the trigger input - clock.sleep(time in ms) is generally correct. Does that mean, that it is impossible to input more than one trigger per video-stimulus and that sleep time fitting the actual-stimulus-to-track appearance inside the long video-stimulus would just stall the experiment and/or crash Python? And therefore the only way to set a trigger in OpenSesame would be at the start of the video-stimulus, and then entering the locations of the actual-stimuli-to-track during post-processing?
Thank you,
Volchi00
When trying to enter the code like it is prosented below, this error appears (photo). Since 'io' is defined in the script, it doesn't makes sense. What could be wrong?
global io
trigger = 1
port = 0x378
try:
io.DlPortWritePortUchar(port, trigger)
except:
print('Failed to send trigger one!')
self.sleep(50)
io.DlPortWritePortUchar(port, 0)
//or this:
global io
trigger = 1
port = 0x378
try:
io.DlPortWritePortUchar(port, trigger)
except:
print('Failed to send trigger one!')
clock.sleep(50)
io.DlPortWritePortUchar(port, 0)
Thank you,
Volchi00
Hi Volchi00,
Sorry for the late reply, this last weeks were very busy.
Also, is there no way to input several triggers for one stimulus?
you can't send multiple triggers at once. If you don't care about the exact timing information, you can send a sequence of triggers, every 50 ms or so. All of them should show up in the file and can be worked with to analyse the conditions you want. That requires of course that you can have control over the experiment every 50 ms. If you sleep for the entire time (e.g. stimulus presentation), you can't send intermediate triggers. A workaround could be that you split the full presentation time into segments, each of which starts with a trigger.
However, if all you want is extensive condition information in the eeg file, you should consider complex triggers that codes certain conditions by using the full range of the possible trigger value spectrum
What could be the reason for the trigger not appearing in Biosemi EEG signal viewing program (ActiView), if the parallel port is functional?
If the port is functioning (how do you know?), and you set a trigger for at least a few tens of ms, I don't know what could be the reason the triggers don't show up in Actiview. The last time I used EEG, I used the same code (it has been 4-5 years, though), So, no idea, I am afraid.
Does that mean, that it is impossible to input more than one trigger per video-stimulus and that sleep time fitting the actual-stimulus-to-track appearance inside the long video-stimulus would just stall the experiment and/or crash Python?
Python shouldn't crash normally, so this has probably something to do with the video presentation, but generally yes. Like I said above, whenever you can control the experiment (no event in the experiment blocks all the resources), you can send triggers. I am not super familiar with the video playback. It might be possible to playback a video, while returning the controls to opensesame, so that code can be executed without killing the video, but I am not sure about it.
Then you said, that the method used for the trigger input - clock.sleep(time in ms) is generally correct.
Yeah, generally correct, but the point is primarily that you have triggers active for at least a few tens of ms (not sure what the minimal robust value would be, I tend to use 3 frames). If it is shorter, you might not see it in the data. If it is too long, there might be problems with other triggers (response, etc.), so the optimal procedure would be to set a triggers for a short amount of time, and then reset it to 0. Obviously, this is easiest done with clock.sleep()s, but you could also think of other ways to make sure enough time has passed.
When trying to enter the code like it is presented below, this error appears (photo). Since 'io' is defined in the script, it doesn't makes sense. What could be wrong?
Once in the beginning you have to import the things:
If that's not it, then I also don't know.
Hope this is still useful to you!
Good luck,
Eduard