Skip to content

Commit

Permalink
Merge pull request #176 from jonwright/master
Browse files Browse the repository at this point in the history
ready for v2
  • Loading branch information
jonwright authored Oct 19, 2023
2 parents 1957cc0 + 18b5608 commit 66afd90
Show file tree
Hide file tree
Showing 17 changed files with 84 additions and 35 deletions.
2 changes: 1 addition & 1 deletion ImageD11/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
"""

__version__ = "1.9.9"
__version__ = "2.0.0"
__author__ = 'Jon Wright',
__author_email__ = '[email protected]'

Expand Down
2 changes: 1 addition & 1 deletion ImageD11/saintraw.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ def tocolumnfile(self):
"""
cof = columnfile.newcolumnfile( self.alltitles )
dlist = [ self.data[t] for t in self.alltitles ]
cof.bigarray = numpy.array( dlist, numpy.float )
cof.bigarray = numpy.array( dlist, float )
cof.nrows = len( self.data[ self.alltitles[0] ] )
cof.ncols = len( self.alltitles )
cof.set_attributes()
Expand Down
14 changes: 7 additions & 7 deletions ImageD11/scale.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ def __init__( self, im1, threshold = None):
im1 = a * im2 + b
returns a, b
"""
lsqmat = numpy.zeros((2, 2), numpy.float)
dyda = numpy.ravel(im1).astype(numpy.float)
lsqmat = numpy.zeros((2, 2), float)
dyda = numpy.ravel(im1).astype(float)
self.threshold = threshold
if threshold is None:
self.indices = None
Expand Down Expand Up @@ -102,14 +102,14 @@ def scale(self, im2):
...use scale image for that
"""
if self.indices is None:
rhs0 = numpy.sum(self.dyda * numpy.ravel(im2).astype(numpy.float))
rhs1 = numpy.sum(numpy.ravel(im2).astype(numpy.float))
rhs0 = numpy.sum(self.dyda * numpy.ravel(im2).astype(float))
rhs1 = numpy.sum(numpy.ravel(im2).astype(float))
ans = numpy.dot(self.inverse, [rhs0, rhs1])
return ans[0], ans[1]
else:
usedata = numpy.take(numpy.ravel(im2) , self.indices)
rhs0 = numpy.sum(self.dyda * usedata.astype(numpy.float))
rhs1 = numpy.sum(usedata.astype(numpy.float))
rhs0 = numpy.sum(self.dyda * usedata.astype(float))
rhs1 = numpy.sum(usedata.astype(float))
ans = numpy.dot(self.inverse, [rhs0, rhs1])
return ans[0], ans[1]

Expand All @@ -121,7 +121,7 @@ def scaleseries( target, stem, first, last,
Scale a series of [bruker] images to the target
TODO - make it work with fabio file series
"""
# d0 = numpy.ravel(target.data.astype(numpy.float))
# d0 = numpy.ravel(target.data.astype(float))
scaler = scale(target.data, thresh)
print("# Scaling with respect to:", sys.argv[1])
if thresh is not None:
Expand Down
13 changes: 10 additions & 3 deletions ImageD11/sinograms/lima_segmenter.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,11 @@ def save(self, h5name, h5group):
import numba
# pip install ImageD11 --no-deps # if you do not have it yet:
from ImageD11 import sparseframe, cImageD11
from bslz4_to_sparse import chunk2sparse

try:
from bslz4_to_sparse import chunk2sparse
except:
chunk2sparse = None

@numba.njit
def select(img, mask, row, col, val, cut):
Expand Down Expand Up @@ -217,7 +221,8 @@ def reader(frms, mask, cut):
iterator to read chunks or frames and segment them
returns sparseframes
"""
if '32008' in frms._filters and not frms.is_virtual and OPTIONS.bg is None:
if (chunk2sparse is not None) and ('32008' in frms._filters) and (
not frms.is_virtual) and (OPTIONS.bg is None):
print('# reading compressed chunks')
fun = chunk2sparse( mask, dtype = frms.dtype )
for i in range(frms.shape[0]):
Expand All @@ -228,7 +233,9 @@ def reader(frms, mask, cut):
else:
fun = frmtosparse( mask, frms.dtype )
for i in range(frms.shape[0]):
frm = frms[i].astype(np.float32) - OPTIONS.bg
frm = frms[i]
if OPTIONS.bg is not None:
frm = frm.astype(np.float32) - OPTIONS.bg
npx, row, col, val = fun( frm, cut )
spf = clean( npx, row, col, val )
yield spf
Expand Down
2 changes: 1 addition & 1 deletion ImageD11/sinograms/properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,7 @@ def pks_table_from_scan( sparsefilename, ds, row ):
This is probably not threadsafe
"""
sps = ImageD11.sparseframe.SparseScan( sparsefilename, ds.scans[row] )
sps.motors['omega'] = ds.omega[i]
sps.motors['omega'] = ds.omega[row]
peaks, pairs = ImageD11.sinograms.properties.props( sps, row )
# which frame/peak is which in the peaks array
# For the 3D merging
Expand Down
2 changes: 1 addition & 1 deletion ImageD11/sparseframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def to_dense(self, data=None, out=None):
if len(ks)==1:
data = self.pixels[ks[0]] # default for only one
else:
data = np.ones( self.nnz, np.bool ) # give a mask
data = np.ones( self.nnz, bool ) # give a mask
if out is None:
out = np.zeros( self.shape, data.dtype )
else:
Expand Down
6 changes: 3 additions & 3 deletions ImageD11/tkGui/plot3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def __init__(self,parent,data=None,lines=None,
Tk.Label(self,text="Red=[1,0,0] Green=[0,1,0] Blue=[0,0,1]").pack(
side=Tk.BOTTOM,expand=Tk.NO,fill=Tk.X)
self.ubis=ubis
self.color=numpy.ones((xyz.shape[0],3),numpy.float)
self.color=numpy.ones((xyz.shape[0],3),float)
print(self.color.shape)
self.tex=False
if ubis is not None:
Expand Down Expand Up @@ -253,10 +253,10 @@ def redraw(self,o):

if self.ubis is not None and len(self.ubis)==1:
hkl = numpy.dot(numpy.linalg.inv(self.ubis[0]),
numpy.identity(3,numpy.float)).T
numpy.identity(3,float)).T
# print hkl
else:
hkl = numpy.identity(3,numpy.float)
hkl = numpy.identity(3,float)
# print hkl

GL.glBegin(GL.GL_LINE_LOOP)
Expand Down
8 changes: 4 additions & 4 deletions sandbox/Index1DSearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

uc = unitcell.unitcell( [7.89, 8.910, 9.1011, 92, 97, 99], "P")

orient = Rotation.from_euler("XYZ",(10,20,31)).as_dcm()
orient = Rotation.from_euler("XYZ",(10,20,31)).as_matrix()
ub = np.dot( orient, uc.B )
ubi = np.linalg.inv( ub )

Expand Down Expand Up @@ -56,7 +56,7 @@
print(vec, ang)
direc = vec / np.sqrt( np.dot(vec,vec))

u0 = Rotation.from_rotvec( ang * direc).as_dcm()
u0 = Rotation.from_rotvec( ang * direc).as_matrix()
ub0 = np.dot( u0, uc.B)
gtest = np.dot( ub0, (h0,k0,l0))
print(gtest, gobs)
Expand All @@ -71,8 +71,8 @@
unitG = gtest / np.sqrt( np.dot(gtest,gtest) )
angles_to_test = np.linspace( -np.pi, np.pi, 360 )

testmats = [ np.dot( ubi0, Rotation.from_rotvec( unitG*x ).as_dcm() ) for x in angles_to_test ]
rmats = [ Rotation.from_rotvec( unitG*x ).as_dcm() for x in angles_to_test ]
testmats = [ np.dot( ubi0, Rotation.from_rotvec( unitG*x ).as_matrix() ) for x in angles_to_test ]
rmats = [ Rotation.from_rotvec( unitG*x ).as_matrix() for x in angles_to_test ]
print(np.dot(testmats[0],gtest))

gobs = gcalc.T.copy()
Expand Down
6 changes: 3 additions & 3 deletions sandbox/art.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def update_wtd( recon, proj, angle, msk, dbg=True ):
cImageD11.put_incr( calc_proj, idx_lo, r*wt_lo )
cImageD11.put_incr( calc_proj, idx_hi, r*wt_hi )
error = np.zeros( calc_proj.shape, np.float32 )
start = (len(calc_proj)- len(proj))/2
start = int((len(calc_proj)- len(proj))/2)
error[ start:start+len(proj) ] = proj
error = error - calc_proj
npcalc_proj = np.zeros( (mx-mn), np.float32 )
Expand Down Expand Up @@ -124,7 +124,7 @@ def test_u_n():
for j in range(3):
for proj, angle in zip(projections, theta):
print(j, angle, end=' ')
start = time.clock()
start = time.time()
update = update_wtd( recon, proj, angle, msk, dbg=False)
recon = recon + update*0.9
# clip to zero - constructing positive intensity
Expand All @@ -136,7 +136,7 @@ def test_u_n():
pl.imshow(recon)
pl.colorbar()
# pl.show()
end = time.clock()
end = time.time()
sumtime += end-start
ncalc +=1
# print err.sum()
Expand Down
2 changes: 1 addition & 1 deletion sandbox/bgfilter_grab.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def open_sub_dark( names, darkfilename, DARK_N=1 ):
@bench("mask")
def do_mask( imgs, maskfilename ):
""" applies a mask to the data """
msk = fabio.open(maskfilename).data.astype(np.bool)
msk = fabio.open(maskfilename).data.astype(bool)
for img in imgs:
img.data[msk] = 0
yield img
Expand Down
2 changes: 1 addition & 1 deletion sandbox/buffered_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def buffered( names, bufsize ):
buffer = []
# init
while len( buffer ) < bufsize:
name = names.next()
name = next(names)
buffer.append( name )
# print("buffer", name )
for i in range(bufsize//2+1):
Expand Down
2 changes: 1 addition & 1 deletion sandbox/collect_peak_pixels.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def to_coo( data, mask, name ):
Convert an image (2D, probably float) and mask (0 versus !0)
to a sparse array (could be more efficient...)
"""
m = mask.astype(np.bool)
m = mask.astype(bool)
j = np.outer(np.ones( data.shape[0], dtype=np.uint16),
np.arange(data.shape[1], dtype=np.uint16) )
ind0, ind1 = j.T[m], j[m]
Expand Down
4 changes: 2 additions & 2 deletions sandbox/qtcam.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ def find_offset( c ):
def register_image( im1, im2 ):
""" We take the current and place it onto reference """

ref = normalise(numpy.asarray(im1).sum(axis=2, dtype=numpy.float))
cur = normalise(numpy.asarray(im2).sum(axis=2, dtype=numpy.float))
ref = normalise(numpy.asarray(im1).sum(axis=2, dtype=float))
cur = normalise(numpy.asarray(im2).sum(axis=2, dtype=float))

fftshape = ( ref.shape[0] + cur.shape[0] ,
ref.shape[1] + cur.shape[1] )
Expand Down
2 changes: 1 addition & 1 deletion sandbox/ringselect.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
dsmax = 2*np.sin(1.03*tthmax*np.pi/360)/w
u.makerings(dsmax)

mask = np.zeros( c.nrows, dtype=np.bool )
mask = np.zeros( c.nrows, dtype=bool )
for d in u.ringds:
tthc = np.arcsin(w*d/2)*360/np.pi
M = len(u.ringhkls[d])
Expand Down
42 changes: 42 additions & 0 deletions sandbox/sigma_3_matrices.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@

import ImageD11.grain
import ImageD11.grid_index_parallel
import scipy.spatial.transform
import numpy as np


def make_sigma3_mats( ):
""" Rotations of 60 degrees on 111 """
v = 60/np.sqrt( 3 )
S3_matrices = [ scipy.spatial.transform.Rotation.from_rotvec( (x,y,z), degrees=True ).as_matrix()
for x in (-v,v)
for y in (-v,v)
for z in (-v,) ] # only need 1 z as -60 == 60
return S3_matrices


def applytwinmat( g, mat ):
""" U.B -> U.M'.B """
ubinew = np.linalg.inv( g.U.dot( mat.T ).dot( g.B ) )
return ImageD11.grain.grain( ubinew, g.translation )


def twin_check( ind, matrices, symmetry='cubic', poserr=1000, angerr=0.5 ):
gl = ImageD11.grid_index_parallel.uniq_grain_list( symmetry, poserr, angerr )
gl.add( [ ImageD11.grain.grain( ubi, np.array((0,0,0)) ) for ubi in ind.ubis ] )
for ubi in ind.ubis:
g = ImageD11.grain.grain( ubi )
sg1 = ImageD11.cImageD11.score( ubi, ind.gvflat, ind.hkl_tol )
print("%4d "%(sg1), end='')
for mat in matrices:
gnew = applytwinmat( g, mat )
s1 = ImageD11.cImageD11.score( gnew.ubi, ind.gvflat, ind.hkl_tol )
if s1 > ind.minpks: # should be accepted assuming uniq
b4 = len(gl.uniqgrains)
gl.add( [gnew,] )
if len(gl.uniqgrains) == b4:
e = 'r'
else:
e = '!'
print("%4d "%(s1), end=e)
print()
8 changes: 4 additions & 4 deletions test/testconnectedpixels/testconnectedpixels.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def setUp(self):

def test_1(self):
for t in [np.uint8, np.int8, np.uint16, np.int16,
np.int32, np.uint32, np.float32, np.float]:
np.int32, np.uint32, np.float32, float]:
data = np.array( [[ 0, 0, 0, 0, 0, 0, 0],
[ 0, 0, 0, 1, 0, 0, 0],
[ 0, 0, 0, 0, 0, 0, 0],
Expand All @@ -28,7 +28,7 @@ def test_1(self):

def test_1_shape(self):
for t in [np.uint8, np.int8, np.uint16, np.int16,
np.int32, np.uint32, np.float32, np.float]:
np.int32, np.uint32, np.float32, float]:
data = np.array( [[ 1, 0, 1, 0, 1, 0, 1],
[ 1, 0, 1, 0, 1, 0, 1],
[ 1, 0, 1, 0, 0, 1, 0],
Expand All @@ -43,7 +43,7 @@ def test_1_shape(self):

def test_2_shapes(self):
for t in [np.uint8, np.int8, np.uint16, np.int16,
np.int32, np.uint32, np.float32, np.float]:
np.int32, np.uint32, np.float32, float]:
data = np.array( [[ 1, 0, 1, 0, 2, 0, 2],
[ 1, 0, 1, 0, 2, 0, 2],
[ 1, 0, 1, 0, 0, 2, 0],
Expand Down Expand Up @@ -109,7 +109,7 @@ def test_prop_names(self):

def test_find_max(self):
for t in [np.uint8, np.int8, np.uint16, np.int16,
np.int32, np.uint32, np.float32, np.float]:
np.int32, np.uint32, np.float32, float]:
data = np.array( [[ 1, 0, 1],
[ 1, 0, 1],
[ 1, 8, 1],
Expand Down
2 changes: 1 addition & 1 deletion test/testscale.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class testscale(unittest.TestCase):
"""old testcase """
def testscaleimage(self):
"""check the object works """
im1 = numpy.ones((10, 10), numpy.float)
im1 = numpy.ones((10, 10), float)
im1[2:8, 2:8] *= 2
im1[4:6, 4:6] *= 2
im2 = im1 * 2. + 3.
Expand Down

0 comments on commit 66afd90

Please sign in to comment.