Skip to content

Commit

Permalink
readying release
Browse files Browse the repository at this point in the history
  • Loading branch information
jonwright committed Oct 19, 2023
1 parent 21ba1aa commit 2a457f7
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 15 deletions.
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/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
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
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

0 comments on commit 2a457f7

Please sign in to comment.