Skip to content

Commit c05c109

Browse files
committed
add .txt format support
1 parent 8a29a04 commit c05c109

File tree

1 file changed

+19
-15
lines changed

1 file changed

+19
-15
lines changed

diffpy/srxplanar/loadimage.py

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,24 +21,28 @@
2121
from diffpy.srxplanar.srxplanarconfig import _configPropertyR
2222
import tifffile
2323
import subprocess
24+
import numpy as np
2425

2526
def openImage(im):
26-
try:
27-
code = 'import numpy; import fabio; numpy.save("temp.npy", fabio.openimage.openimage("%s").data)' % im
28-
cmd = [sys.executable, '-c', "'" + code + "'"]
29-
p = subprocess.Popen(cmd)
30-
p.wait()
31-
rv = np.load('temp.npy')
32-
try:
33-
os.remove('temp.npy')
34-
except:
35-
pass
36-
try:
37-
p.terminate()
27+
if im.endswith('.txt'):
28+
rv = np.loadtxt(im)
29+
else:
30+
try:
31+
code = 'import numpy; import fabio; numpy.save("temp.npy", fabio.openimage.openimage("%s").data)' % im
32+
cmd = [sys.executable, '-c', "'" + code + "'"]
33+
p = subprocess.Popen(cmd)
34+
p.wait()
35+
rv = np.load('temp.npy')
36+
try:
37+
os.remove('temp.npy')
38+
except:
39+
pass
40+
try:
41+
p.terminate()
42+
except:
43+
pass
3844
except:
39-
pass
40-
except:
41-
rv = tifffile.imread(im)
45+
rv = tifffile.imread(im)
4246
return rv
4347

4448
class LoadImage(object):

0 commit comments

Comments
 (0)