def export_avgs(avgs, out_dir): if not os.path.isdir(out_dir): os.makedirs(out_dir) for k in avgs: AIF.put_mrc( avgs[k]['v'], os.path.join(out_dir, '%03d--%s.mrc' % (avgs[k]['pass_i'], k)))
def peak__partition__single_job(v, s1, s2, base=None, find_maxima=None, partition_id=None, save_vg=False): assert find_maxima is not None # vg = FG.dog_smooth__large_map(v, s1=s1, s2=s2) 'dog_smooth' seems to perform better vg = FG.dog_smooth(v, s1=s1, s2=s2) # save the smoothed partition for inspection if save_vg: IOF.put_mrc(v, '/tmp/%d-%d-%d--v.mrc' % (partition_id[0], partition_id[1], partition_id[2]), overwrite=True) del v if find_maxima: # print 'local_maxima()' # sys.stdout.flush() x = FL.local_maxima(vg) else: # print 'local_minima()' # sys.stdout.flush() x = FL.local_minima(vg) p = vg[x] x = N.array(x).T if base is not None: assert base.shape[0] == x.shape[1] assert base.shape[1] == 2 for dim_i in range(x.shape[1]): x[:, dim_i] += base[dim_i, 0] ps = [] for i in range(len(p)): ps.append({ 'val': float(p[i]), 'x': [_ for _ in x[i, :]], 'uuid': str(uuid.uuid4()) }) if save_vg: # save the smoothed partition for inspection IOF.put_mrc(vg, '/tmp/%d-%d-%d--vg.mrc' % (partition_id[0], partition_id[1], partition_id[2]), overwrite=True) del vg GC.collect() return {'ps': ps, 'partition_id': partition_id}
def convert(op): from . import situs_pdb2vol as SP import aitom.io.file as IF r = SP.convert(op) v = r['map'] if 'out_map_size' in op: import aitom.image.vol.util as IVU v = IVU.resize_center(v=v, s=op['out_map_size'], cval=0.0) IF.put_mrc(v, op['out_file'])
def convert(op): import aitom.structure.pdb.situs_pdb2vol as SP r = SP.convert(op) v = r['map'] if 'out_map_size' in op: import tomominer.image.vol.util as IVU v = IVU.resize_center(v=v, s=op['out_map_size'], cval=0.0) import aitom.io.file as IF IF.put_mrc(v, op['out_file'])
im = IF.read_mrc(op['vol_file']) # voxel spacing in nm unit voxel_spacing = (im['header']['MRC']['xlen'] / im['header']['MRC']['nx']) * 0.1 print('voxel_spacing', voxel_spacing) v = im['value'] if 'debug' in op: se = N.array(op['debug']['start_end']) v = v[se[0, 0]:se[0, 1], se[1, 0]:se[1, 1], se[2, 0]:se[2, 1]] v = v.astype(N.float) v -= v.mean() IF.put_mrc(v, '/tmp/v.mrc', overwrite=True) if op['inverse_intensity']: v = -v print('intensity distribution of v', 'max', v.max(), 'min', v.min(), 'mean', v.mean()) print('# gaussian smoothing') vg = FG.smooth(v, sigma=float(op['sigma']) / voxel_spacing) print('intensity distribution of vg', 'max', vg.max(), 'min', vg.min(), 'mean', vg.mean()) IF.put_mrc(vg, '/tmp/vg.mrc', overwrite=True)
v = MU.generate_toy_model(dim_siz=64) # generate a pseudo density map print(v.shape) # randomly rotate and translate v loc_proportion = 0.1 loc_max = N.array(v.shape, dtype=float) * loc_proportion angle = GAL.random_rotation_angle_zyz() loc_r = (N.random.random(3) - 0.5) * loc_max vr = GR.rotate(v, angle=angle, loc_r=loc_r, default_val=0.0) # generate simulated subtomogram vb from v vb = TSRSC.do_reconstruction(vr, op, verbose=True) print('vb', 'mean', vb.mean(), 'std', vb.std(), 'var', vb.var()) # save v and vb as 3D grey scale images IF.put_mrc(vb, '/tmp/vb.mrc', overwrite=True) IF.put_mrc(v, '/tmp/v.mrc', overwrite=True) # save images of the slices of the corresponding 3D iamges for visual inspection import aitom.image.io as IIO import aitom.image.vol.util as IVU IIO.save_png(IVU.cub_img(vb)['im'], "/tmp/vb.png") IIO.save_png(IVU.cub_img(v)['im'], "/tmp/v.png") if True: # verify the correctness of SNR estimation vb_rep = TSRSC.do_reconstruction(vr, op, verbose=True) import scipy.stats as SS # calculate SNR vb_corr = SS.pearsonr(vb.flatten(), vb_rep.flatten())[0]