Example #1
0
(nz, ny, nx) = libOPT.getminc_dimlengths(infile)
if (libOPT.verbose):
    print "Minc dimensions are", nz, ny, nx

if (int(options.slice) >= ny):
    parser.error(
        "The specified slice %d is outside of the maximum number of slices" %
        int(options.slice))

## Everything verified, now let's begin
tf = libOPT.get_tempfile()
tdir = libOPT.make_tempdir()

libOPT.execute_command(
    "mincreshape -clobber -float -start 0,%d,0 -count %d,1,%d %s %s" %
    (int(options.slice), nz, nx, infile, tf))

maxdets = int(ceil(nx + 2 * max(abs(first), abs(last))))
j = 0
for i in arange(first, last, inc):
    libOPT.reconstruct(tf,
                       "%s/offset_%04d.mnc" % (tdir, j),
                       offset=i,
                       reconsize=(maxdets, maxdets),
                       antialias=int(options.antialias))
    j += 1
#	libOPT.execute_command("python /micehome/jwalls/workspace/tomography_recon/individrecon.py "\
#							  "-o %d -r %d,%d %s %s/offset%04d" %
#							  (i, nx+2*max(abs(first),abs(last)),nx+2*max(abs(first),abs(last)),
#							   tf, tdir, i+abs(first)))
scan_info = libOPT.parse_bioptonics_log(logfile)

if(scan_info is False):
  parser.error("Could not parse the log file $s" % logfile)

first_slice = int(scan_info["First Section"])
last_slice = int(scan_info["Last Section"])

if(last_slice < first_slice):
  parser.error("Could not parse sections in log file.  1st: %d, last: %d" % (first_slice, last_slice))

infls = []
for i in range(first_slice, last_slice+1):
  fname = "%s/%s%04d.tif" % (indir, opts.prefix, i)
  if(not os.path.exists(fname)):
     parser.error("Could not find the file %s, aborting ..." % fname)
  infls.append(fname)

if(scan_info["Depth (bits)"] == "16"):
  stype = "short"
  ssigned = False
else:
  stype = "byte"
  ssigned = False

libOPT.manytiffs_to_minc(infls, outfile, datatype=stype, signed=ssigned, rang=(lower,upper))
libOPT.execute_command("minc_modify_header -dinsert zspace:step=%s %s" % (str(float(scan_info["Pixel Size (um)"])/1000.), outfile))
libOPT.execute_command("minc_modify_header -dinsert yspace:step=%s %s" % (str(float(scan_info["Pixel Size (um)"])/1000.), outfile))
libOPT.execute_command("minc_modify_header -dinsert xspace:step=%s %s" % (str(float(scan_info["Pixel Size (um)"])/1000.), outfile))

if (not opts.background):
    background_str = "--bg_output none"
else:
    background_str = ""

## OPT Prototype mode
if (opts.bioptonics):
    for a in args:
        a1 = os.path.realpath(a)
        if (not os.path.exists(a1)):
            print("The directory %s does not exist, skipping ..." % a1)
            continue
        cmd = "sge_batch -J autorecon python %s/process_bioptonics_data.py %s %s %s %s" % (
            libOPT.WORKDIR, fdr_str, verbose_str, clobber_str, a1)
        libOPT.execute_command(cmd)
## OPT Prototype mode
else:
    for a in args:
        a1 = os.path.realpath(a)
        if (not os.path.exists(a1)):
            print("The directory %s does not exist, skipping ..." % a1)
            continue
        if (os.path.exists("%s/ANNOTATION_A.txt" % a1)):
            cmd = "sge_batch -J autorecon python %s/process_prototype_data.py %s %s %s %s %s" % (
                libOPT.WORKDIR, background_str, fdr_str, verbose_str,
                clobber_str, a1)
        else:
            parser.error("Could not find ANNOTATION_A.txt")

        libOPT.execute_command(cmd)
Example #4
0
infile = args[0]

if (not os.path.exists(infile)):
    parser.error("The input file %s does not exist" % infile)

if (options.outfile):
    if (os.path.exists(options.outfile) and not options.clobber):
        parser.error("The specified output file %s already exists." %
                     options.outfile)
    out = os.path.realpath(options.outfile)
else:
    out = os.path.realpath(infile)

a = libOPT.openmincfile(infile)

sz = shape(a.array)
if (len(sz) != 2):
    parser.error(
        "This minc file is improperly formatted -- does not have only 2 dims")

b = libOPT.newmincfile((1, sz[0], sz[1]))
b.array[0, :, :] = squeeze(a.array)
b.set_range(min(ravel(a.array)), max(ravel(a.array)))

tf = libOPT.get_tempfile()

b.output(tf)

libOPT.execute_command("mv %s %s" % (tf, out))
infile = args[0]
outfile = args[1]

if (not os.path.exists(infile)):
    parser.error("The input file %s does not exist." % infile)
if (not opts.clobber and os.path.exists(outfile)):
    parser.error("The output file %s already exists." % outfile)
if (not opts.clobber and opts.plotfile and os.path.exists(opts.plotfile)):
    parser.error("The plot file %s already exists." % opts.plotfile)
if (not opts.clobber and opts.histfile and os.path.exists(opts.histfile)):
    parser.error("The histogram file %s already exists." % opts.histfile)

tf = libOPT.get_tempfile()

cmd = "mincstats -min -max %s > %s" % (infile, tf)
libOPT.execute_command(cmd)
a = open(tf)
lines = a.readlines()
a.close()
libOPT.cleanup(tf)
for line in lines:
    if (line[0:3] == "Min"):
        x = line.strip().split()
        mmin = x[-1]
    elif (line[0:3] == "Max"):
        x = line.strip().split()
        mmax = x[-1]

if (opts.minimum is not False):
    min_str = "-hist_floor %s" % opts.minimum
else:
Example #6
0
infile = args[0]
bgfile = args[1]
outfile = args[2]

if (not os.path.exists(infile)):
    parser.error("The input file %s does not exist." % infile)

if (not os.path.exists(bgfile)):
    parser.error("The background file %s does not exist." % bgfile)

if (os.path.exists(outfile) and not options.clobber):
    parser.error(
        "The output file %s already exists and no clobber is active." %
        outfile)

if (options.mode == "emission"):
    libOPT.execute_command(
        "python %s/slicewisemincmath.py -c -t float -d zspace -m sub -c %s %s %s"
        % (libOPT.WORKDIR, infile, bgfile, outfile))
elif (options.mode == "transmission"):
    libOPT.execute_command(
        "python %s/slicewiselogtransform.py -c -t float -d zspace -c %s %s %s"
        % (libOPT.WORKDIR, infile, bgfile, outfile))
else:
    parser.error(
        "The listed mode %s is not a valid mode <transmission or emission>" %
        options.mode)

print "Done!"
## 2. Convert the TIFF to minc
## 3. Average all slices in the minc file
## 4. Ensure that it is properly formatted for further processing

options, args = parser.parse_args()

if (len(args) != 2):
    parser.error("Incorrect number of arguments")

libOPT.verbose = options.verbose

infile = args[0]
outfile = args[1]

if (not os.path.exists(infile)):
    parser.error("The input file %s does not exist." % infile)

if (os.path.exists(outfile) and not options.clobber):
    parser.error(
        "The output file %s already exists and no clobber is active." %
        outfile)

t1 = libOPT.get_tempfile()
libOPT.execute_command("python %s/tifftominc.py -c -r 0,4095 %s %s" %
                       (libOPT.WORKDIR, infile, t1))
libOPT.execute_command("mincaverage -clobber -float -avgdim zspace %s %s" %
                       (t1, outfile))
libOPT.execute_command("python %s/addzdim.py %s" % (libOPT.WORKDIR, outfile))

print "Done!"
def do(s):
  commands_we_ran.append(s)
  return libOPT.execute_command(s)
Example #9
0
    libOPT.verbose = options.verbose

(slices, y, x) = libOPT.getminc_dimlengths(infile)

if (options.slicerange):
    start_slice = int(options.slicerange.split(',')[0])
    end_slice = int(options.slicerange.split(',')[1])
else:
    start_slice = 0
    end_slice = slices

if (y % binning or x % binning):
    parser.error("The number of elements is not divisible by the binning of ",
                 binning)

td = libOPT.make_tempdir()

for i in range(start_slice, end_slice):

    libOPT.execute_command(
        "mincreshape %s -clobber -start %d,0,0 -count 1,%d,%d %s %s/slice%04d.mnc"
        % (libOPT.get_verbose_minc_option(
            libOPT.verbose), i, y, x, infile, td, i))
    libOPT.execute_command(
        "python %s/rebindata.py -b %d %s/slice%04d.mnc %s/bslice%04d.mnc" %
        (libOPT.WORKDIR, binning, td, i, td, i))
    #libOPT.rebin_mincfile(tf, outfile, binning)

libOPT.execute_command("mincconcat -concat_dimension zspace %s/bs* %s" %
                       (td, outfile))
Example #10
0
(options, args) = parser.parse_args()

if (len(args) != 1):
    parser.error("Incorrect arguments")

d = args[0]

if (not os.path.exists(d)):
    parser.error("The directory %s does not exist" % d)

if (not os.path.isdir(d)):
    parser.error("The argument is not a directory")

if (not os.path.exists("%s/views" % d)):
    os.mkdir("%s/views" % d)
libOPT.execute_command("mv %s/image_* %s/views" % (d, d))
if (not os.path.exists("%s/binned" % d)):
    os.mkdir("%s/binned" % d)

for i in range(0, 400):
    libOPT.tifftominc("%s/views/image_%04d" % (d, i),
                      "%s/views/v%04d.mnc" % (d, i))
    libOPT.execute_command(
        "python %s/rebindata.py -b 2 %s/views/v%04d.mnc %s/views/b_%04d.mnc" %
        (libOPT.WORKDIR, d, i, d, i))

libOPT.execute_command(
    "mincconcat -sequential -valid_range 0 4095 -float -concat_dimension zspace %s/views/v* %s/data_1.mnc"
    % (d, d))
libOPT.execute_command("mincconvert -2 %s/data_1.mnc %s/data.mnc" % (d, d))
libOPT.execute_command(