def read(path): with open(pyfs.rext(path, "hed"), "rb") as fd: header = readHeader(fd) with open(pyfs.rext(path, "img"), "r+b") as fd: rows = int(header["ROWS"]) cols = int(header["COLS"]) count = int(header["IFOL"] + 1) data = np.memmap(fd, dtype="f4", mode="c") return data.reshape([count, cols, rows])
def topng(mrc, scale, force): png = pyfs.rext(mrc, 'png') png = mrc + '.png' if not force and pyfs.exists(png): return print(mrc, '->', png) image = imaging.load(mrc)[0] image = imaging.filters.zoom(image, scale) imaging.save(image, png)
def process(path, aligned, args, gpu): t0 = time.time() aligned_dw = unpack.label(aligned, 'dw') aligned_log = pyfs.rext(aligned, 'shifts') aligned_stk = pyfs.rext(aligned, 'mrcs') print(path, '->', aligned) print(' ' * len(path), '->', aligned_log) tmpdir = tempfile.mkdtemp() tmp_unzipped = pyfs.join(tmpdir, 'decompressed.mrc') tmp_unpacked = pyfs.join(tmpdir, 'unpacked.mrc') tmp_aligned = pyfs.join(tmpdir, 'aligned.mrc') tmp_aligned_dw = pyfs.join(tmpdir, 'aligned_DW.mrc') tmp_logfile = pyfs.join(tmpdir, 'aligned0-Full.log') tmp_stkfile = pyfs.join(tmpdir, 'aligned_Stk.mrc') tmp_unzipped = pbunzip2(path, tmp_unzipped) if args.unpack: unpack.unpack(tmp_unzipped, tmp_unpacked, args.defects, args.norm, mode='byte') motioncor2(tmp_unpacked, tmp_aligned, args, gpu=gpu) else: args.mocor2_norm = args.norm motioncor2(tmp_unzipped, tmp_aligned, args, gpu=gpu) mv(tmp_aligned, aligned) mv(tmp_aligned_dw, aligned_dw) mv(tmp_logfile, aligned_log) mv(tmp_stkfile, aligned_stk) shutil.rmtree(tmpdir, False) print('aligning: %s took: %.2f secs' % (path, time.time() - t0))
def motioncor2(src, dst, args, gpu=0): print('processing: %s' % (src)) cmd = ['motioncor2'] if src.endswith('.mrc') or src.endswith('.mrcs'): cmd += ['-InMrc', src] elif src.endswith('.tif'): cmd += ['-InTiff', src] else: raise ValueError('file: %s must be TIFF or MRC' % (src)) cmd += ['-OutMrc', dst] cmd += ['-Bft', args.bfactor] cmd += ['-Patch', args.patches, args.patches, 50] cmd += ['-Kv', args.kv] cmd += ['-PixSize', args.apix] cmd += ['-LogFile', pyfs.rext(dst, '')] if args.inframe: cmd += ['-InFmMotion', 1] if args.mag is not None: print(args.mag) cmd += ['-Mag', args.mag[0], args.mag[1], args.mag[2]] if hasattr(args, 'mocor2_norm'): cmd += ['-Gain', args.mocor2_norm] if args.binby > 1: cmd += ['-FtBin', args.binby] if args.savestack: cmd += ['-OutStack', 1] if args.throw: cmd += ['-Throw', args.throw] if args.truncate: cmd += ['-Trunc', args.truncate] if args.correction is not None: expf = calculate_dose(src, args.apix, args.correction) print('using dose rate: %f e-/A^2/frame' % (expf)) cmd += ['-FmDose', expf] group = calculate_grouping(src, args.group) cmd += ['-Group', args.group] if args.rotgain: cmd += ['-RotGain', 3, '-FlipGain', 1] cmd += ['-Gpu', gpu] print(' '.join(map(str, cmd))) call(cmd, stdout=None)
def save_stats(stats, path, **kwargs): path = pyfs.rext(path, "yaml") save(stats, path)
def load_stats(path, **kwargs): path = pyfs.rext(path, "yaml") print "load stat:", path return load(path)
def load_stats(path, **kwargs): path = pyfs.rext(path, "yaml") return load(path)