Skip to content

Commit

Permalink
Refs #55. support tiff input image files;
Browse files Browse the repository at this point in the history
support new CT() options "ob_identifier", "df_identifier";
support new CT().recon() option "crop_window"
  • Loading branch information
yxqd committed Aug 24, 2016
1 parent 511bab5 commit 2865418
Showing 1 changed file with 30 additions and 12 deletions.
42 changes: 30 additions & 12 deletions python/imars3d/CT.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ def __init__(
workdir='work', outdir='out',
parallel_preprocessing=True, parallel_nodes=None,
clean_on_the_fly=False,
vertical_range=None):
vertical_range=None,
ob_identifier=None, df_identifier=None):
self.path = path
if CT_subdir is not None:
# if ct is in a subdir, its name most likely the
Expand All @@ -27,6 +28,8 @@ def __init__(
# the CT files are identified by string "CT"
self.CT_subdir = '.'
self.CT_identifier = CT_identifier or 'CT'
self.ob_identifier = ob_identifier
self.df_identifier = df_identifier
# workdir
if not os.path.exists(workdir):
os.makedirs(workdir)
Expand Down Expand Up @@ -55,12 +58,19 @@ def __init__(
return


def recon(self, workdir=None, outdir=None, tilt=None, **kwds):
def recon(self, workdir=None, outdir=None, tilt=None, crop_window=None,
**kwds):
workdir = workdir or self.workdir; outdir = outdir or self.outdir
# preprocess
if_corrected = self.preprocess(workdir=workdir, outdir=outdir)
# auto-cropping
cropped = self.autoCrop(if_corrected)
if crop_window is None:
# auto-cropping
cropped = self.autoCrop(if_corrected)
else:
xmin, ymin, xmax, ymax = crop_window
cropped = self.crop(
if_corrected,
left=xmin, right=xmax, top=ymin, bottom=ymax)
if self.clean_on_the_fly:
if_corrected.removeAll()
# smoothing
Expand Down Expand Up @@ -251,8 +261,8 @@ def find_CT(self):
CT_identifier = self.CT_identifier
subdir = os.path.join(self.path, self.CT_subdir)
patterns = [
'*%s*_*_*.fits' % CT_identifier,
'*_*_*.fits',
'*%s*_*_*.*' % CT_identifier,
'*_*_*.*',
]
found = None
for pattern in patterns:
Expand All @@ -266,7 +276,7 @@ def find_CT(self):
"failed to find CT images. directory: %s, patterns tried: %s"%(
subdir, patterns)
)
re_pattern = '(\S+)_(\d+)_(\d+)_(\d+).fits'
re_pattern = '(\S+)_(\d+)_(\d+)_(\d+).(\S+)'
def fn2angle(fn):
import re
m = re.match(re_pattern, fn)
Expand Down Expand Up @@ -294,8 +304,8 @@ def fn2angle(fn):
assert condition, "angles not spaced correctly: %s" % (angles,)
self.angles = np.array(angles) # in degrees
printf_pattern_candidates = [
"*%s" % CT_identifier + "*_%07.3f_*.fits",
"*%s" % CT_identifier + "*_%.3f_*.fits",
"*%s" % CT_identifier + "*_%07.3f_*.*",
"*%s" % CT_identifier + "*_%.3f_*.*",
]
found = None
for c in printf_pattern_candidates:
Expand Down Expand Up @@ -337,17 +347,25 @@ def fn2angle(fn):


def find_OB(self):
if self.ob_identifier:
fnp = ['*%s*' % self.ob_identifier]
else:
fnp = ['*ob*', '*OB*']
return self._find_pattern(
'OB',
subdir_candidates = ['ob', 'OB'],
filenamepattern_candidates = ['*ob*', '*OB*'],
filenamepattern_candidates = fnp,
)

def find_DF(self):
if self.df_identifier:
fnp = ['*%s*' % self.df_identifier]
else:
fnp = ['*df*', '*DF*']
return self._find_pattern(
'DF',
subdir_candidates = ['df', 'DF'],
filenamepattern_candidates = ['*df*', '*DF*'],
filenamepattern_candidates = fnp,
)


Expand Down Expand Up @@ -382,7 +400,7 @@ def _find_pattern(self, kind, subdir_candidates, filenamepattern_candidates):


def get_ct_scan_info(files):
re_pattern = '(\S+)_(\S+)_(\d+)_(\d+)_(\d+).fits'
re_pattern = '(\S+)_(\S+)_(\d+)_(\d+)_(\d+).(\S+)'
def _(fn):
import re
m = re.match(re_pattern, fn)
Expand Down

0 comments on commit 2865418

Please sign in to comment.