def process_data(num, name=None, microns=None, outdir=None, adir=None, zdir=None, gtype=None): tic = time.time() e = cranium.embryo(name, num, outdir) e.add_channel(os.path.join(adir, 'AT_' + num + '_Probabilities.h5'), 'AT') e.add_channel(os.path.join(zdir, gtype + '_' + num + '_Probabilities.h5'), gtype) e.process_channels(0.25, 0.5, 7, [1, 1, 1], microns, 2, 'AT', [0, 2, 1], ['x', 'z']) e.save_psi() toc = time.time() print(num, toc - tic)
def process(num, expname=None, outdir=None, gtype=None, adir=None, zdir=None): tic = time.time() e = cranium.embryo(expname, num, outdir) e.add_channel(os.path.join(adir, 'AT_' + num + '_Probabilities.h5'), 'AT') e.add_channel(os.path.join(zdir, gtype + '_' + num + '_Probabilities.h5'), gtype) e.chnls['AT'].preprocess_data(genthresh, [1, 1, 1], microns) e.chnls[gtype].preprocess_data(genthresh, [1, 1, 1], microns) e.chnls['AT'].calculate_pca_median(e.chnls['AT'].raw_data, medthresh, radius, microns) pca = e.chnls['AT'].pcamed e.chnls['AT'].pca_transform_3d(e.chnls['AT'].df_thresh, pca, comporder, fitdim, deg=2) mm = e.chnls['AT'].mm vertex = e.chnls['AT'].vertex e.chnls[gtype].pca_transform_3d(e.chnls[gtype].df_thresh, pca, comporder, fitdim, deg=2, mm=mm, vertex=vertex) e.chnls['AT'].transform_coordinates() e.chnls[gtype].transform_coordinates() e.save_psi() toc = time.time() print(num, toc - tic)
import cranium expname = 'test' samplenum = '01' directory = 'data' #Create an embryo object that facilitates data processing e = cranium.embryo(expname, samplenum, directory) #For each channel in your sample, add a channel with a unique name, e.g. 'c1' or 'c2' e.add_channel('data/C1/AT_01_Probabilities.h5', 'c1') # e.add_channel('data/C2/ZRF1_01_Probabilities.h5','c2') genthresh = 0.5 scale = [1, 1, 1] microns = [0.16, 0.16, 0.21] #Threshold each channel and scale points according to voxel dimension in microns e.chnls['c1'].preprocess_data(genthresh, scale, microns) # e.chnls['c2'].preprocess_data(genthresh,scale,microns) medthresh = 0.25 radius = 20 microns = [0.16, 0.16, 0.21] #Run PCA on the structural channel, in this case, c1 e.chnls['c1'].calculate_pca_median(e.chnls['c1'].raw_data, medthresh, radius, microns) #Save the pca object that includes the transformation matrix pca = e.chnls['c1'].pcamed
def process(num, P=None): ''' Run through the processing steps for a single sample through saving psi files :param int num: Index of the file that is currently being processed :param :class:`paramClass` P: Object containing all variables from config file ''' tic = time.time() print(num, 'Starting sample') #Extract sample number from c1 filename snum = re.findall(r'\d+', P.c1_files[num].split('.')[0])[0] e = cranium.embryo(P.expname, snum, P.outdir) #Add channels and preprocess data try: e.add_channel(os.path.join(P.c1_dir, P.c1_files[num]), P.c1_key) e.chnls[P.c1_key].preprocess_data(P.genthresh, P.scale, P.microns) for i in range(len(P.Lcdir)): e.add_channel(os.path.join(P.Lcdir[i], P.Lcfiles[i][num]), P.Lckey[i]) e.chnls[P.Lckey[i]].preprocess_data(P.genthresh, P.scale, P.microns) except: print(num, 'failed on preprocess_data', time.time() - tic) #Calculate PCA transformation for structural channel, c1 try: if P.twoD == True: e.chnls[P.c1_key].calculate_pca_median_2d( e.chnls[P.c1_key].raw_data, P.medthresh, P.radius, P.microns) pca = e.chnls[P.c1_key].pcamed e.chnls[P.c1_key].pca_transform_2d(e.chnls[P.c1_key].df_thresh, pca, P.comporder, P.fitdim, deg=P.deg) #Transform additional channels for i in range(len(P.Lcdir)): e.chnls[P.Lckey[i]].pca_transform_2d( e.chnls[P.Lckey[i]].df_thresh, pca, P.comporder, P.fitdim, deg=P.deg) else: e.chnls[P.c1_key].calculate_pca_median(e.chnls[P.c1_key].raw_data, P.medthresh, P.radius, P.microns) pca = e.chnls[P.c1_key].pcamed e.chnls[P.c1_key].pca_transform_3d(e.chnls[P.c1_key].df_thresh, pca, P.comporder, P.fitdim, deg=P.deg) #Transform additional channels for i in range(len(P.Lcdir)): e.chnls[P.Lckey[i]].pca_transform_3d( e.chnls[P.Lckey[i]].df_thresh, pca, P.comporder, P.fitdim, deg=P.deg) except: print(num, 'failed on pca', time.time() - tic) print(num, 'Starting coordinate transformation') try: e.chnls[P.c1_key].transform_coordinates() for i in range(len(P.Lcdir)): e.chnls[P.Lckey[i]].transform_coordinates() except: print(num, 'failed on coordinate transform', time.time() - tic) try: e.save_psi() except: print(num, 'failed on save_psi', time.time() - tic) toc = time.time() print(num, 'Complete', toc - tic)
def first_alignment(self, p, Lc, D): tic = time.time() for i, c in enumerate(Lc): print(i, c.name, c.dir) pc = self.check_settings(p) e = cranium.embryo(pc['expname'], self.key, pc['outdir']) for i, c in enumerate(Lc): print(i, c.dir, c.key) if c.dir != None: print(i, 'data processing') e.add_channel(os.path.join(c.dir, self.fs[i]), c.key) e.chnls[c.key].preprocess_data(pc['genthresh'], [1, 1, 1], pc['microns']) #Processing for the structural channel if i == 0: if D == 3: print('comporder', pc['comporder']) e.chnls[c.key].calculate_pca_median( e.chnls[c.key].raw_data, pc['medthresh'], pc['radius'], pc['microns']) pca = e.chnls[c.key].pcamed e.chnls[c.key].pca_transform_3d( e.chnls[c.key].df_thresh, pca, pc['comporder'], pc['fitdim'], deg=pc['deg']) elif D == 2: e.chnls[c.key].calculate_pca_median_2d( e.chnls[c.key].raw_data, pc['medthresh'], pc['radius'], pc['microns']) pca = e.chnls[c.key].pcamed e.chnls[c.key].pca_transform_2d( e.chnls[c.key].df_thresh, pca, pc['comporder'], pc['fitdim'], deg=pc['deg']) mm = e.chnls[c.key].mm vertex = e.chnls[c.key].vertex #Secondary channel processing if D == 3: e.chnls[c.key].pca_transform_3d(e.chnls[c.key].df_thresh, pca, pc['comporder'], pc['fitdim'], deg=pc['deg'], mm=mm, vertex=vertex) if D == 2: e.chnls[c.key].pca_transform_2d(e.chnls[c.key].df_thresh, pca, pc['comporder'], pc['fitdim'], deg=pc['deg'], mm=mm, vertex=vertex) print('sample alignment complete', time.time() - tic) #Save data for i, c in enumerate(Lc): if c.dir != None: print(i, 'data saving') cname = c.name.get() for p in ':,./\\[]{};() ': cname = cname.replace(p, '') fpath = os.path.join( pc['outdir'], '_'.join([cname, pc['expname'], self.key]) + '.psi') cranium.write_data(fpath, e.chnls[c.key].df_align) self.outpaths[i] = fpath self.plot_projections( [e.chnls[Lc[0].key].df_thresh, e.chnls[Lc[0].key].df_align], mm)