Skip to content

Commit

Permalink
Merge pull request #261 from CJ-Wright/tomo_3D
Browse files Browse the repository at this point in the history
Support 3D pencil reconstruction
  • Loading branch information
CJ-Wright authored Mar 14, 2019
2 parents 3c30fa8 + 22232c4 commit 7621cb3
Show file tree
Hide file tree
Showing 16 changed files with 565 additions and 105 deletions.
5 changes: 3 additions & 2 deletions docs/_templates/using_servers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,11 @@ folders.
Users will need to specify which folder(s) they would like the data to be
placed in before running their experiments.',
qoi='The QOI server performs additional data processing and analysis,
extracting quantities of interest from raw and reduced data.
extracting quantities of interest from raw and reduced data.',
viz='The viz server visualizes raw and processed data as it becomes available.
This server should already be running, only beamline staff should need to
start it.'
start it.',
tomo='The tomo server runs tomographic reconstructions on all scalar data (raw and analyzed). The reconstruction algorithm can be changed via the ``algorithm`` keyword.'
) %}

{% for name, blurb in servers_dict.items() %}
Expand Down
49 changes: 49 additions & 0 deletions examples/ctPDF_example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import os
import time

import bluesky.plans as bp
import dxchange
import numpy as np
import tomopy
from bluesky.run_engine import RunEngine
from ophyd.sim import SynSignal, hw
from xpdan.vend.callbacks.zmq import Publisher
from xpdconf.conf import glbl_dict

hw = hw()
rot_center = 290
m = hw.motor1
m.kind = "hinted"
mm = hw.motor2
mm.kind = "hinted"
mmm = hw.motor3
mmm.kind = "hinted"
xrun(0,
bp.grid_scan(
[xpd_pe1c],
mmm,
0,
2,
2,
m,
0,
180,
4,
True,
mm,
200,
401,
4,
True,

md={
"tomo": {
"type": "pencil",
"rotation": "motor1",
"translation": "motor2",
"stack": "motor3",
"center": rot_center - 200,
}
},
)
)
151 changes: 151 additions & 0 deletions examples/multi_tomo_example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
import os
import time

import bluesky.plans as bp
import dxchange
import numpy as np
import tomopy
from bluesky.run_engine import RunEngine
from ophyd.sim import SynSignal, hw, SynSignalWithRegistry
from xpdan.vend.callbacks.zmq import Publisher
from xpdconf.conf import glbl_dict

hw = hw()
fname = os.path.expanduser("~/Downloads/tooth.h5")

proj, flat, dark, theta = dxchange.read_aps_32id(fname, sino=(0, 1))

proj = tomopy.normalize(proj, flat, dark)

rot_center = tomopy.find_center(proj, theta, init=290, ind=0, tol=0.5)
# proj2 = np.hstack((proj[:, :, :],) * 200)
# proj2 = np.hstack((proj[:, :, :],) * 1)
# rot_center -= 200
proj2 = proj
m = hw.motor1
m.kind = "hinted"
mm = hw.motor2
mm.kind = "hinted"
mmm = hw.motor3
mmm.kind = "hinted"


class FullField:
def __call__(self, *args, **kwargs):
v = m.get()[0]
out = proj2[int(v), :, :]
print(v)
time.sleep(.5)
return out


class Pencil:
def __call__(self, *args, **kwargs):
v = m.get()[0]
vv = mm.get()[0]
out = proj2[int(v), :, int(vv)]
print(v, vv, mmm.get()[0])
time.sleep(.5)
return np.squeeze(out)


f = FullField()
# det = SynSignal(f, name="img", labels={"detectors"})
det = SynSignalWithRegistry(f, name="img", labels={"detectors"},)
det.kind = "hinted"

#g = Pencil()
#det2 = SynSignal(g, name="img", labels={"detectors"})
#det2.kind = "hinted"

RE = RunEngine()
RE.md['analysis_stage'] = 'raw'
p = Publisher(glbl_dict["inbound_proxy_address"], prefix=b"raw")
t = RE.subscribe(p)
# RE.subscribe(print)

# Build scan
l = [0, 90]
for i in range(8):
ll = l.copy()
interval = sorted(set(ll))[1] / 2
for lll in ll:
j = lll + interval
j = round(j, 0)
if j not in l and j < 180:
l.append(j)
# Run Full Field Scans, each scan has more slices, showing how we can minimize
# the number of slices by interleaving them by half
for i in [2 ** n for n in range(2, 8)] + [180]:
RE(
bp.list_scan(
[det],
m,
l[:i],
md={
"tomo": {
"type": "full_field",
"rotation": "motor1",
"center": rot_center,
}
},
)
)
print(i)
time.sleep(3)
'''
# Run in pencil beam geometry (this takes a long time!)
RE(
bp.grid_scan(
[det2],
m,
0,
180,
181,
mm,
0,
639,
640,
True,
md={
"tomo": {
"type": "pencil",
"rotation": "motor1",
"translation": "motor2",
"center": rot_center,
}
},
)
)
# Run in 3D pencil beam geometry
RE(
bp.grid_scan(
[det2],
mmm,
0,
2,
10,
m,
0,
180,
41,
True,
mm,
200,
401,
21,
True,
md={
"tomo": {
"type": "pencil",
"rotation": "motor1",
"translation": "motor2",
"stack": "motor3",
"center": rot_center - 200,
}
},
)
)
RE.abort()
'''
53 changes: 45 additions & 8 deletions examples/tomo_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import numpy as np
import tomopy
from bluesky.run_engine import RunEngine
from ophyd.sim import SynSignal, hw
from ophyd.sim import SynSignal, hw, SynSignalWithRegistry
from xpdan.vend.callbacks.zmq import Publisher
from xpdconf.conf import glbl_dict

Expand All @@ -26,6 +26,8 @@
m.kind = "hinted"
mm = hw.motor2
mm.kind = "hinted"
mmm = hw.motor3
mmm.kind = "hinted"


class FullField:
Expand All @@ -42,23 +44,26 @@ def __call__(self, *args, **kwargs):
v = m.get()[0]
vv = mm.get()[0]
out = proj2[int(v), :, int(vv)]
print(v, vv)
time.sleep(.1)
print(v, vv, mmm.get()[0])
time.sleep(.5)
return np.squeeze(out)


f = FullField()
det = SynSignal(f, name="img", labels={"detectors"})
# det = SynSignal(f, name="img", labels={"detectors"})
det = SynSignalWithRegistry(f, name="img", labels={"detectors"},)
det.kind = "hinted"

g = Pencil()
det2 = SynSignal(g, name="img", labels={"detectors"})
det2.kind = "hinted"
#g = Pencil()
#det2 = SynSignal(g, name="img", labels={"detectors"})
#det2.kind = "hinted"

RE = RunEngine()
RE.md['analysis_stage'] = 'raw'
p = Publisher(glbl_dict["inbound_proxy_address"], prefix=b"raw")
t = RE.subscribe(p)
# RE.subscribe(print)

# Build scan
l = [0, 90]
for i in range(8):
Expand All @@ -71,7 +76,7 @@ def __call__(self, *args, **kwargs):
l.append(j)
# Run Full Field Scans, each scan has more slices, showing how we can minimize
# the number of slices by interleaving them by half
for i in [2 ** n for n in range(2, 8)] + [180]:
for i in [180]:
RE(
bp.list_scan(
[det],
Expand All @@ -88,6 +93,7 @@ def __call__(self, *args, **kwargs):
)
print(i)
time.sleep(3)
'''
# Run in pencil beam geometry (this takes a long time!)
RE(
bp.grid_scan(
Expand All @@ -111,4 +117,35 @@ def __call__(self, *args, **kwargs):
},
)
)
# Run in 3D pencil beam geometry
RE(
bp.grid_scan(
[det2],
mmm,
0,
2,
10,
m,
0,
180,
41,
True,
mm,
200,
401,
21,
True,
md={
"tomo": {
"type": "pencil",
"rotation": "motor1",
"translation": "motor2",
"stack": "motor3",
"center": rot_center - 200,
}
},
)
)
RE.abort()
'''
19 changes: 19 additions & 0 deletions news/tomo_3D
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
**Added:**

* Support for 3D pencil beam reconstructions
* Support for Registry backed full field reconstructions
* ``ctPDF_example.py`` example for pencil beam

**Changed:**

* ``tomo_example.py`` runs on a registry backed detector

**Deprecated:** None

**Removed:** None

**Fixed:**

* Pencil beam no longer tries to run independent var reconstructions

**Security:** None
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"viz_server",
"analysis_server",
"qoi_server",
"tomo_server",
]

entry_points = {
Expand Down
Loading

0 comments on commit 7621cb3

Please sign in to comment.