aestrivex / ielu

grids and strips electrode localization utility
GNU General Public License v3.0
10 stars 7 forks source link

intermittent IOError errno 0 in geometry.py/get_vox2rasxfm() #9

Closed cleemesser closed 8 years ago

cleemesser commented 8 years ago

Hello, Thank you for publishing your code. I have been trying it out with some of our preop/post-op MRIs and CT. I frequently got an IOError errno 0 in geometry.py with get_vox2rasxfm(). It appeared that sometimes the python code would try to read from the pipe ps.stdout before freesurfer's mri_info had completed. It did not look like a streaming read was needed so I fixed this by inserting a wait() call to assure that the command had completed before iterating through the lines of output. -Chris Lee-Messer Would you like a pull request? Here is the updated code:

def get_vox2rasxfm(volume, stem='vox2ras'): import subprocess

ps = subprocess.Popen(['mri_info','--%s'%stem,volume], 
    stdout=subprocess.PIPE)

vox2ras = np.zeros((4,4))

ps.wait() # \ here is the update ** i = 0 for ln in ps.stdout: try: loc = np.array(map(float, ln.strip('()[]\n').split())) except: continue

    vox2ras[i,:] = loc
    i+=1

return vox2ras 
aestrivex commented 8 years ago

Thanks for the report.

That's a very strange error, which I have never encountered and would never have found. I don't have any idea why you're getting it and I'm not (on several different machines). But your patch cannot hurt.

thanks!

cleemesser commented 8 years ago

Thanks. It seems to happen when my laptop is under load. I tried replicating it in isolation, but it never reproduced the error in isolation (just calling get_vox2rasxfm() on my data or on sample data) but it happened reproducibly when running the whole pipeline on my 2012 macbookpro