Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
A script to obtain acquisition parameters from [OME XML](http://www.openmicroscopy.org/site/support/ome-model/) files created by Prairie View. Prairie View is a microscope acquisition software for multiphoton microscopes by [Prairie Technologies](http://www.prairie-technologies.com/products/photon/Ultima.html).
#! /usr/bin/env python
#pyPrairieTiffXMLparams.py
#Created by James B. Ackman 4/1/2011
'''
A tool to obtain relevant experimental parameters from a Prairie View (microscope acquisition program from Prairie Technologies)
formatted XML file contained with folders of Prairie View acquired TIFFs. Output is to stdout as well as a log file in the users python home directory.
'''
import os, sys, wx
from xml.dom import minidom
rootdir=os.getcwd()
class MyApp(wx.App):
def OnInit(self):
# Args below are: parent, question, dialog title, default answer
dd = wx.DirDialog(None, "Select directory to open", "~/", 0, (10, 10), wx.Size(400, 300))
ret = dd.ShowModal()
if ret == wx.ID_OK:
#print('You selected: %s\n' % dd.GetPath())
selectedDir.append(dd.GetPath())
else:
print('You clicked cancel')
dd.Destroy()
return True
selectedDir = []
app = MyApp(redirect = 0)
app.MainLoop()
print selectedDir[0]
#--Parse relevant experimental parameters from OME XML file-------------------------------------
#fnm = "/Users/ackman/Desktop/TSeries-03232011-1321-003.xml"
splitpath=os.path.split(str(selectedDir[0]))
fname = splitpath[1] + '.xml'
fnm = os.path.join(str(selectedDir[0]),fname)
f = open(fnm)
xmldoc = minidom.parse(f)
seqtype = xmldoc.getElementsByTagName('Sequence')[0].getAttribute('type')
datetime = xmldoc.getElementsByTagName('PVScan').item(0).getAttribute('date')
frlist = xmldoc.getElementsByTagName('Frame')
nframes = frlist.length
if nframes > 1:
keylist = frlist[0].getElementsByTagName('Key')
nodes = len(keylist)
nchannels = len(frlist[0].getElementsByTagName('File'))
headers = ['filename']
data = [fname]
headers.append('sequencetype')
data.append(str(seqtype))
headers.append('nchannels')
data.append(nchannels)
headers.append('datetime')
data.append(str(datetime))
L = ['objectiveLens','pixelsPerLine','linesPerFrame','frameAveraging','framePeriod','scanlinePeriod','dwellTime','positionCurrent_XAxis','positionCurrent_YAxis','positionCurrent_ZAxis','opticalZoom','micronsPerPixel_XAxis','micronsPerPixel_YAxis']
for i in range(nodes):
keyname = keylist.item(i).getAttribute('key')
if keyname in L:
val = keylist.item(i).getAttribute('value')
#headers = headers + '\t' + keyname
headers.append(str(keyname))
#data = data + '\t' + val
data.append(str(val))
#print keyname + '\t' + val
if str(keyname) == 'framePeriod':
#print keyname
framerate = 1/float(val)
#print framerate
#print str(framerate)
headers.append('framerate')
data.append(framerate)
#add no.of.frames to the header and data list
headers.append('nframes')
data.append(nframes)
#add the movie length to the header and data list
ind = headers.index('framePeriod')
mov_length = float(data[ind]) * nframes
headers.append('mov_length.s')
data.append(mov_length)
#--Format for printing to stdout and to log file----------------------------------------------
pheaders = headers[0]
pdata = data[0]
for i in range(1,len(headers)):
pheaders = pheaders + '\t' + headers[i]
pdata = pdata + '\t' + str(data[i])
print pheaders
print pdata
logfile = 'log_expParams.txt'
logfilepath=os.path.join(rootdir, logfile)
if os.path.isfile(logfilepath):
log = open(logfilepath,'a')
print >> log, pdata
else:
log = open(logfilepath,'w')
print >> log, pheaders
print >> log, pdata
log.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.