Skip to content

Commit

Permalink
Refs #92. implemented
Browse files Browse the repository at this point in the history
  • Loading branch information
yxqd committed Jan 10, 2018
1 parent df8d70a commit e8a46b8
Showing 1 changed file with 29 additions and 8 deletions.
37 changes: 29 additions & 8 deletions python/imars3d/CT.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,27 @@ class CT:
>>> ct.normalizer = ... # similarly for normalizer
>>> ct.preprocess()
>>> ct.recon()
By default, intermediate results will be moved over to the disk where the outputs are (outdir) after CT reconstruction is all done:
clean_intermediate_files='archive'
or they can be cleaned on the fly to save disk usage:
clean_intermediate_files='on_the_fly"
or they can be kept where it is:
clean_intermediate_files=None
and you will need to clean them up yourself.
"""

def __init__(
self, path, CT_subdir=None, CT_identifier=None,
workdir='work', outdir='out',
parallel_preprocessing=True, parallel_nodes=None,
clean_on_the_fly=False,
clean_intermediate_files='archive',
vertical_range=None,
ob_identifier=None, df_identifier=None,
ob_files=None, df_files=None,
Expand Down Expand Up @@ -92,7 +106,8 @@ def __init__(

self.parallel_preprocessing = parallel_preprocessing
self.parallel_nodes = parallel_nodes
self.clean_on_the_fly = clean_on_the_fly
assert clean_intermediate_files in ['on_the_fly', 'archive', None]
self.clean_intermediate_files = clean_intermediate_files
self.vertical_range = vertical_range
self.r = results()
return
Expand Down Expand Up @@ -132,7 +147,7 @@ def preprocess(self, workdir=None, outdir=None):
normalized = normalizer(gamma_filtered, dfs, obs, workdir=os.path.join(workdir, 'normalization'))
else:
normalized = gamma_filtered
if self.clean_on_the_fly and gamma_filtered is not ct_series:
if self.clean_intermediate_files=='on_the_fly' and gamma_filtered is not ct_series:
gamma_filtered.removeAll()
# save references
self.r.gamma_filtered = gamma_filtered
Expand All @@ -144,7 +159,7 @@ def recon(self, workdir=None, outdir=None, tilt=None, crop_window=None,
smooth_projection=None, remove_rings_at_sinograms=None,
smooth_recon=None, remove_rings=None,
**kwds):
"""Run CT reconstruction
"""Run CT reconstruction workflow
Parameters:
* workdir: fast work dir
Expand Down Expand Up @@ -193,7 +208,7 @@ def recon(self, workdir=None, outdir=None, tilt=None, crop_window=None,
cropped = self.crop(
pre,
left=xmin, right=xmax, top=ymin, bottom=ymax)
if self.clean_on_the_fly:
if self.clean_intermediate_files == 'on_the_fly':
pre.removeAll()
# median filter
self.r.median_filtered = median_filtered = self.smooth(
Expand All @@ -209,7 +224,7 @@ def recon(self, workdir=None, outdir=None, tilt=None, crop_window=None,
# correct intensity fluctuation
if_corrected = i3.correct_intensity_fluctuation(
pre, workdir=os.path.join(workdir, 'intensity-fluctuation-correction'))
if self.clean_on_the_fly:
if self.clean_intermediate_files == 'on_the_fly':
pre.removeAll()
# correct tilt
pre = if_corrected
Expand All @@ -221,7 +236,7 @@ def recon(self, workdir=None, outdir=None, tilt=None, crop_window=None,
pre, tilt=tilt,
workdir=os.path.join(workdir, 'tilt-correction' ),
max_npairs=None, parallel=self.parallel_preprocessing)
if self.clean_on_the_fly:
if self.clean_intermediate_files == 'on_the_fly':
pre.removeAll()
#
self.r.cropped = cropped
Expand All @@ -244,6 +259,12 @@ def recon(self, workdir=None, outdir=None, tilt=None, crop_window=None,
**smooth_recon)
if remove_rings:
self.removeRings(recon)
# clean up
if self.clean_intermediate_files == 'archive':
import shutil
import datetime
now = datetime.datetime.now().strftime("%Y-%m-%d_%H-%M-%S")
shutil.move(workdir, os.path.join(outdir, 'work-%s' % now))
return


Expand Down Expand Up @@ -309,7 +330,7 @@ def correctTilt_loop(self, pre, workdir):
tilt_corrected, tilt = i3.correct_tilt(
pre, workdir=os.path.join(workdir, 'tilt-correction-%s' % i),
max_npairs=None, parallel=self.parallel_preprocessing)
if self.clean_on_the_fly:
if self.clean_intermediate_files == 'on_the_fly':
pre.removeAll()
if abs(tilt) < MAX_TILT_ALLOWED: break
pre = tilt_corrected
Expand Down

0 comments on commit e8a46b8

Please sign in to comment.