Skip to content

Commit

Permalink
Refs #53. several changes mostly made to deal with Charles mit1 dataset
Browse files Browse the repository at this point in the history
CT class
* commented out smooth step before tilt correction
* restore tomopy write_center step
* added "tilt" kwd arg to recon method to allow skipping tilt calc

Tilt correction
* when tilt calculation using rot centers fails, use phase corr
* allow skipping tilt calculation
  • Loading branch information
yxqd committed Jul 26, 2016
1 parent 5ea9fee commit e6d8c78
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 18 deletions.
34 changes: 24 additions & 10 deletions python/imars3d/CT.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def __init__(
return


def recon(self, workdir=None, outdir=None, **kwds):
def recon(self, workdir=None, outdir=None, tilt=None, **kwds):
workdir = workdir or self.workdir; outdir = outdir or self.outdir
# preprocess
if_corrected = self.preprocess(workdir=workdir, outdir=outdir)
Expand All @@ -64,9 +64,23 @@ def recon(self, workdir=None, outdir=None, **kwds):
if self.clean_on_the_fly:
if_corrected.removeAll()
# smoothing
pre = smoothed = self.smooth(cropped, 5)
# pre = smoothed = self.smooth(cropped, 5)
pre = cropped
if tilt is None:
tilt_corrected, tilt = self.correctTilt_loop(
pre, workdir=workdir)
else:
tilt_corrected, tilt = i3.correct_tilt(
pre, tilt=tilt,
workdir=os.path.join(workdir, 'tilt-correction' ),
max_npairs=None, parallel=self.parallel_preprocessing)
if self.clean_on_the_fly:
cropped.removeAll()
# reconstruct
self.reconstruct(tilt_corrected, workdir=workdir, outdir=outdir, **kwds)
return

def correctTilt_loop(self, pre, workdir):
# correct tilt
MAX_TILT_ALLOWED = 0.05
NROUNDS = 3
Expand All @@ -80,11 +94,11 @@ def recon(self, workdir=None, outdir=None, **kwds):
pre = tilt_corrected
continue
if abs(tilt) >= MAX_TILT_ALLOWED:
raise RuntimeError("failed to bring tilt down to less than %s degrees in %s rounds" % (MAX_TILT_ALLOWED, NROUNDS))
# reconstruct
self.reconstruct(tilt_corrected, workdir=workdir, outdir=outdir, **kwds)
return

msg = "failed to bring tilt down to less than %s degrees in %s rounds" % (MAX_TILT_ALLOWED, NROUNDS)
# raise RuntimeError(msg)
import warnings
warnings.warn(msg)
return tilt_corrected, tilt

@dec.timeit
def autoCrop(self, series):
Expand Down Expand Up @@ -189,9 +203,9 @@ def reconstruct(self, ct_series, workdir=None, outdir=None, rot_center=None):
X = proj.shape[-1]
DEVIATION = 40 # max deviation of rot center from center of image
print("* Exploring rotation center using tomopy...")
# tomopy.write_center(
# proj.copy(), theta, cen_range=[X//2-DEVIATION, X//2+DEVIATION, 1.],
# dpath=os.path.join(workdir, 'tomopy-findcenter'), emission=False)
tomopy.write_center(
proj.copy(), theta, cen_range=[X//2-DEVIATION, X//2+DEVIATION, 1.],
dpath=os.path.join(workdir, 'tomopy-findcenter'), emission=False)
if rot_center is None:
print("* Computing rotation center using 180deg pairs...")
from .tilt import find_rot_center
Expand Down
7 changes: 4 additions & 3 deletions python/imars3d/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,10 @@ def normalize(ct_series, dfs, obs, workdir='work'):
return normalized_ct

@dec.timeit
def correct_tilt(ct_series, workdir='work', max_npairs=10, parallel=True):
tiltcalc = components.TiltCalculation(workdir=workdir, max_npairs=max_npairs)
tilt = tiltcalc(ct_series)
def correct_tilt(ct_series, tilt=None, workdir='work', max_npairs=10, parallel=True):
if tilt is None:
tiltcalc = components.TiltCalculation(workdir=workdir, max_npairs=max_npairs)
tilt = tiltcalc(ct_series)

# only correct if the tilt is large
if abs(tilt)>0.002:
Expand Down
17 changes: 12 additions & 5 deletions python/imars3d/tilt/__init__.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
# imars3d.tilt

import os, numpy as np
import os, numpy as np, warnings
import logging
from . import use_centers, phasecorrelation

def compute(ct_series, workdir, max_npairs=10):
from . import use_centers
calculator = use_centers.Calculator(sigma=10, maxshift=200)
tilt = _compute(
ct_series, os.path.join(workdir, 'testrun'), max_npairs=10,
calculator=calculator)
calculator = use_centers.Calculator(sigma=9, maxshift=200)
try:
tilt = _compute(
ct_series, os.path.join(workdir, 'testrun'), max_npairs=10,
calculator=calculator)
except:
warnings.warn("Failed to use centers to determine tilt. Now try phase correlation method")
calculator = phasecorrelation.PhaseCorrelation()
return _compute(
ct_series, workdir, max_npairs=max_npairs,
calculator=calculator)
if abs(tilt) > 0.8:
calculator = phasecorrelation.PhaseCorrelation()
tilt = _compute(
Expand Down

0 comments on commit e6d8c78

Please sign in to comment.