-
Notifications
You must be signed in to change notification settings - Fork 3
/
checkslice.py
80 lines (62 loc) · 2.13 KB
/
checkslice.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
from __future__ import print_function, division
import h5py, sys, numpy as np, pylab as pl
from ImageD11 import columnfile
import dorecon_grain
cc = dorecon_grain.colfilecache(parfile='fit.par')
""" Check the grains do not share too many peaks
Report on which ones we like best
See what is remaining not indexed
"""
hf = h5py.File( sys.argv[1], 'r' )
grain_names = hf.keys()
masks = {}
colf = None
print("Name npks <sum_intensity> <avg_intensity> <npixels>")
ng = len(grain_names)
grain_names = ["grain_%d"%(i) for i in range(ng)]
for i,name in enumerate(grain_names):
if colf is None:
colf = cc.get( hf[name].attrs['pksfile'] )
else:
assert colf.filename == hf[name].attrs['pksfile']
ids = hf[name]["pkid"][:]
m = np.zeros( colf.nrows, np.bool )
m[ids] = True
masks[name]=m
print(name, len(ids), colf.sum_intensity[ ids ].mean(),
colf.avg_intensity[ids].mean(), colf.Number_of_pixels[ids].mean() )
cov = np.zeros( (ng,ng), np.float)
for i in range(len(grain_names)):
m = masks[grain_names[i]]
ms = m.sum()
for j in range(i):
mo = masks[ grain_names[j] ]
clashes = (m & mo).sum()
cov[i,j] = cov[j,i] = float(clashes) / ms
if cov[i,j] > 0.2:
print("i j nshare percent percent")
print("%d %d %d %.2f %.2f"%(i,j,clashes,clashes/m.sum(),clashes/mo.sum()))
print("ubi[i]")
print( hf[grain_names[i]]["ubi"][:] )
print("ubi[j]")
print( hf[grain_names[j]]["ubi"][:] )
pl.imshow(cov)
pl.title("Peak sharing between grains")
pl.show()
# Now see what is left globally
allmasks = np.array( masks.values() )
not_indexed_peaks = allmasks.sum(axis=0) == 0
r0 = dorecon_grain.recon_all_peaks( colf )
r1 = dorecon_grain.recon_all_peaks( colf, mask = not_indexed_peaks )
pl.figure(2)
pl.subplot(121)
pl.imshow(r0)
pl.title("All peaks")
pl.subplot(122)
pl.imshow(r1)
pl.title("Left over peaks")
allsinos = np.array( [ hf[name]['sinogram'][:]
for name in grain_names ] )
allrecon = np.array( [ hf[name]['recon'][:]
for name in grain_names ] )
# etc