Skip to content

Commit f145978

Browse files
committed
python3 syntax
1 parent 6610eb6 commit f145978

File tree

3 files changed

+51
-42
lines changed

3 files changed

+51
-42
lines changed

ConvertLabels.py

+11-11
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
import nrrd
44

55
if (len(sys.argv) < 4):
6-
print 'Error: missing arguments!'
7-
print 'e.g. ConvertLabels.py [1,2,3,4,5] [5,4,3,2,1] imagefile.nrrd'
8-
print 'e.g. ConvertLabels.py [1,2,3,4,5] [255,254,253,252,251] imagefile.nrrd optionaloutputfile.nrrd'
6+
print('Error: missing arguments!')
7+
print('e.g. ConvertLabels.py [1,2,3,4,5] [5,4,3,2,1] imagefile.nrrd')
8+
print('e.g. ConvertLabels.py [1,2,3,4,5] [255,254,253,252,251] imagefile.nrrd optionaloutputfile.nrrd')
99
else:
1010

11-
print 'Changing label', str(sys.argv[1]), 'to', str(sys.argv[2]), 'for file', str(sys.argv[3])
11+
print('Changing label', str(sys.argv[1]), 'to', str(sys.argv[2]), 'for file', str(sys.argv[3]) )
1212
readdata, option = nrrd.read(str(sys.argv[3]))
1313

1414
old_list = sys.argv[1].replace('[','').replace(']','').split(',')
@@ -19,17 +19,17 @@
1919
for i in range(0,len(new_list)):
2020
dc = readdata==np.uint8(old_list[i])
2121
tempd[dc] = np.uint8(new_list[i])
22-
print old_list[i], '->', new_list[i], ' (', np.sum(dc), ')'
22+
print(old_list[i], '->', new_list[i], ' (', np.sum(dc), ')')
2323
sm = sm - np.sum(dc)
24-
print 'Voxels not changed:', sm
24+
print('Voxels not changed:', sm)
2525

2626
if (len(sys.argv) < 5):
27-
print 'saving result to', str(sys.argv[3])
27+
print('saving result to', str(sys.argv[3]) )
2828

29-
nrrd.write(str(sys.argv[3]), np.uint8(tempd), options=option)
29+
nrrd.write(str(sys.argv[3]), np.uint8(tempd), header=option)
3030
else:
31-
print 'saving result to', str(sys.argv[4])
31+
print('saving result to', str(sys.argv[4]) )
3232

33-
nrrd.write(str(sys.argv[4]), np.uint8(tempd), options=option)
33+
nrrd.write(str(sys.argv[4]), np.uint8(tempd), header=option)
3434

35-
print 'Done.'
35+
print('Done.')

Index2domain.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,26 @@
44
import nrrd
55

66
if (len(sys.argv) < 3):
7-
print 'Error: missing arguments!'
8-
print 'e.g. python Index2domain.py DomainPrefix indexfile1.nrrd indexfileN.nrrd ...'
7+
print('Error: missing arguments!')
8+
print('e.g. python Index2domain.py DomainPrefix indexfile1.nrrd indexfileN.nrrd ...')
99
else:
1010

11-
print 'Adding to domains', str(sys.argv[1]), '....'
11+
print('Adding to domains', str(sys.argv[1]), '....')
1212
for x in range(2,(len(sys.argv))):
13-
print 'adding data from file', sys.argv[x]
13+
print('adding data from file', sys.argv[x])
1414
readdata, option = nrrd.read(str(sys.argv[x]))
1515
for i in np.unique(readdata[readdata>0]):
1616
if np.uint8(i) in readdata:
17-
print 'appending index', str(i)
17+
print('appending index', str(i))
1818
domfile = str(sys.argv[1]) + str(i).zfill(4) + '.nrrd'
1919
if os.path.exists(domfile):
2020
domain, option = nrrd.read(domfile)
2121
else:
2222
domain = np.zeros(readdata.shape,np.uint8)
2323
domain[readdata==i]=np.uint8(255)
24-
nrrd.write(domfile, domain, options=option)
24+
nrrd.write(domfile, domain, header=option)
2525

2626

2727

2828

29-
print 'Done.'
29+
print('Done.')

nrrd2wlzDom.py

+33-24
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
import glob, subprocess, sys
1+
import glob
2+
import subprocess
3+
import sys
4+
25

36
def query_yes_no(question, default="yes"):
47
"""Ask a yes/no question via raw_input() and return their answer.
@@ -10,8 +13,8 @@ def query_yes_no(question, default="yes"):
1013
1114
The "answer" return value is one of "yes" or "no".
1215
"""
13-
valid = {"yes":False, "y":False, "ye":False,
14-
"no":True, "n":True}
16+
valid = {"yes": False, "y": False, "ye": False,
17+
"no": True, "n": True}
1518
if default == None:
1619
prompt = " [y/n] "
1720
elif default == "yes":
@@ -29,21 +32,22 @@ def query_yes_no(question, default="yes"):
2932
elif choice in valid:
3033
return valid[choice]
3134
else:
32-
sys.stdout.write("Please respond with 'yes' or 'no' "\
35+
sys.stdout.write("Please respond with 'yes' or 'no' "
3336
"(or 'y' or 'n').\n")
3437

3538

3639
if (len(sys.argv) < 4):
37-
print 'e.g. python nrrd2wlzDom.py DomainPrefix templateFile WoolzDir FijiExec Zsize XYsize'
38-
print 'Error: missing arguments - using defaults:'
39-
print 'e.g. python nrrd2wlzDom.py TAGdomain flyVNCtemplate20xDaS_th.wlz /disk/data/VFBTools/Woolz2013Full/bin/ /disk/data/VFBTools/Fiji.145/fiji-linux64'
40+
print('e.g. python nrrd2wlzDom.py DomainPrefix templateFile WoolzDir FijiExec Zsize XYsize')
41+
print('Error: missing arguments - using defaults:')
42+
print('e.g. python nrrd2wlzDom.py TAGdomain flyVNCtemplate20xDaS_th.wlz /disk/data/VFBTools/Woolz2013Full/bin/ /disk/data/VFBTools/Fiji.145/fiji-linux64')
4043
wlzdir = '/disk/data/VFBTools/Woolz2013Full/bin/'
4144
Tfile = 'flyVNCtemplate20xDaS_th.wlz'
4245
Fpre = 'TAGdomain'
4346
Lfiji = '/disk/data/VFBTools/Fiji.145/fiji-linux64'
4447
Zsize = str(1)
4548
Vsize = str(1)
46-
if query_yes_no('Do you want to run with the defaults?', default='no'): sys.exit(0)
49+
if query_yes_no('Do you want to run with the defaults?', default='no'):
50+
sys.exit(0)
4751
else:
4852
Lfiji = str(sys.argv[4])
4953
wlzdir = str(sys.argv[3])
@@ -53,32 +57,37 @@ def query_yes_no(question, default="yes"):
5357
Vsize = str(sys.argv[6])
5458

5559
for infile in glob.glob(Fpre + "0*.nrrd"):
56-
print 'Converting %s to %s...' % (infile, infile.replace('.nrrd','.tif'))
57-
subprocess.call('nice xvfb-run %s -macro nrrd2tif.ijm %s -batch' % (Lfiji, infile), shell=True)
60+
print('Converting %s to %s...' % (infile, infile.replace('.nrrd', '.tif')))
61+
subprocess.call('nice xvfb-run %s -macro nrrd2tif.ijm %s -batch' %
62+
(Lfiji, infile), shell=True)
5863

59-
for i in xrange(1,250):
64+
for i in xrange(1, 250):
6065
outfile = Fpre + str(i).zfill(4) + '_dom.wlz'
61-
print 'Creating blank %s...'% outfile
62-
subprocess.call('nice %sWlzMakeEmpty -o%s'% (wlzdir, outfile), shell=True)
66+
print('Creating blank %s...' % outfile)
67+
subprocess.call('nice %sWlzMakeEmpty -o%s' % (wlzdir, outfile), shell=True)
6368

6469

6570
for infile in glob.glob(Fpre + "0*.tif"):
66-
outfile = infile.replace('.tif','_dom.wlz')
67-
print 'Converting %s to %s...' % (infile, outfile)
68-
subprocess.call('nice %sWlzExtFFConvert -ftif -Fwlz %s | %sWlzThreshold -v1 |%sWlzDomain |%sWlzSetVoxelSize -x%s -y%s -z%s >%s' % (wlzdir, infile, wlzdir, wlzdir, wlzdir, Vsize, Vsize, Zsize, outfile), shell=True)
69-
comfile = infile.replace('.tif','.txt')
70-
print 'Calculating centre for %s and saving to %s...' % (outfile, comfile)
71-
subprocess.call('nice %sWlzCentreOfMass -o %s %s' % (wlzdir, comfile, outfile), shell=True)
71+
outfile = infile.replace('.tif', '_dom.wlz')
72+
print('Converting %s to %s...' % (infile, outfile))
73+
subprocess.call('nice %sWlzExtFFConvert -ftif -Fwlz %s | %sWlzThreshold -v1 |%sWlzDomain |%sWlzSetVoxelSize -x%s -y%s -z%s >%s' %
74+
(wlzdir, infile, wlzdir, wlzdir, wlzdir, Vsize, Vsize, Zsize, outfile), shell=True)
75+
comfile = infile.replace('.tif', '.txt')
76+
print('Calculating centre for %s and saving to %s...' % (outfile, comfile))
77+
subprocess.call('nice %sWlzCentreOfMass -o %s %s' %
78+
(wlzdir, comfile, outfile), shell=True)
7279

73-
#print '%sWlzExtFFConvert -ftif -Fwlz %s | %sWlzDomain >%s' % (wlzdir, infile, wlzdir, outfile)
80+
# print('%sWlzExtFFConvert -ftif -Fwlz %s | %sWlzDomain >%s' % (wlzdir, infile, wlzdir, outfile)
7481

7582

76-
print 'Compiling...'
83+
print('Compiling...')
7784

78-
subprocess.call('%sWlzSetVoxelSize -x%s -y%s -z%s %s >%s' % (wlzdir, Vsize, Vsize, Zsize, Tfile, Tfile.replace('.wlz','_E.wlz')), shell=True)
85+
subprocess.call('%sWlzSetVoxelSize -x%s -y%s -z%s %s >%s' % (wlzdir, Vsize,
86+
Vsize, Zsize, Tfile, Tfile.replace('.wlz', '_E.wlz')), shell=True)
7987

8088
#subprocess.call('find %s0*_dom.wlz -size -2b | xargs rm -f'% (Fpre), shell=True)
8189

82-
subprocess.call('cat %s %s0*_dom.wlz | %sWlzCompound >out.wlz'% (Tfile.replace('.wlz','_E.wlz'), Fpre, wlzdir), shell=True)
90+
subprocess.call('cat %s %s0*_dom.wlz | %sWlzCompound >out.wlz' %
91+
(Tfile.replace('.wlz', '_E.wlz'), Fpre, wlzdir), shell=True)
8392

84-
print 'Result saved to out.wlz'
93+
print('Result saved to out.wlz')

0 commit comments

Comments
 (0)