def save(self, baseFn=None): """save Mosaic size/pos/scale info in baseFn.txt save all images into baseFn_xx.mrc """ from Priithon.all import Mrc, U if baseFn is None: from .usefulX import FN baseFn = FN(1) if not baseFn: return a = N.concatenate((self.m_imgPosArr, self.m_imgSizeArr, N.array(self.m_imgRotArr,)[:,N.newaxis], self.m_imgScaleMM), 1) U.writeArray(a, baseFn + '.txt') n = len(self.m_imgSizeArr) for i in range( n ): # Mrc.save(self.m_imgArrL[i], "%s_%02d.mrc" % (baseFn, i)) #20070126 m = Mrc.Mrc("%s_%02d.mrc" % (baseFn, i), "w+", self.m_imgArrL[i] ) #20070126 m.calcMMM() #20070126 m.hdr('d')[:] = tuple(self.m_imgSizeArr[i] / N.array((self.m_imgArrL[i].shape))[::1]) + (1,) #20070126 m.hdr('zxy0')[:] = (0,) + tuple(self.m_imgPosArr[i]) #20070126 m.hdr('mmm1')[:] = tuple(self.m_imgScaleMM[i]) + (1,) #20070126 m.flush() #20070126 m.close() d = tuple(self.m_imgSizeArr[i] / N.array((self.m_imgArrL[i].shape), dtype=N.float32)[::1]) + (1,) zxy0 = (0,) + tuple(self.m_imgPosArr[i]) Mrc.save(self.m_imgArrL[i], "%s_%02d.mrc" % (baseFn, i), hdrEval='''hdr.d = d; hdr.zxy0 = zxy0''' )
def _cutoutForAlign2(fn, py, outFn=''): """ if not outFn, default with 'cut' extention resulting array is imgSequence=0 (t,w,z,y,x) return outFn """ h = imgManager.ImageManager(fn) slc, shiftZYX, ZYX = makeSlice(h, py) # input arr = N.empty((h.nt, h.nw, h.nz, h.ny, h.nx), h.dtype) for t in range(h.nt): for w in range(h.nw): arr[t, w] = h.get3DArr(w=w, t=t) canvas = N.squeeze(arr[slc].astype(arr.dtype.type)) newNum = (canvas.shape[-1], canvas.shape[-2], N.prod(canvas.shape[:-3])) if not outFn: outFn = '_'.join((h.filePath, EXT_CUTOUT)) #arr.Mrc.path, EXT_CUTOUT)) hdr = Mrc.makeHdrArray() Mrc.initHdrArrayFrom(hdr, h.hdr) #arr.Mrc.hdr) hdr.ImgSequence = 2 hdr.Num[:] = newNum mstart = [sl.start for sl in slc[::-1][:3] if isinstance(sl, slice)] hdr.mst[:len(mstart)] += mstart Mrc.save(canvas, outFn, ifExists='overwrite', hdr=hdr) return outFn
def OnSave(self, event=None): from Priithon.all import Mrc, U, Y fn = Y.FN(1)#, verbose=0) if not fn: return if fn[-4:] in [ ".mrc", ".dat" ]: Mrc.save(self.m_imgArr, fn) elif fn[-5:] in [ ".fits" ]: U.saveFits(self.m_imgArr, fn) else: U.saveImg8(self.m_imgArr, fn) Y.shellMessage("### section saved to '%s'\n"%fn)
def OnSave(self, event=None): from Priithon.all import Mrc, U, Y fn = Y.FN(1) #, verbose=0) if not fn: return if fn[-4:] in [".mrc", ".dat"]: Mrc.save(self.m_imgArr, fn) elif fn[-5:] in [".fits"]: U.saveFits(self.m_imgArr, fn) else: U.saveImg8(self.m_imgArr, fn) Y.shellMessage("### section saved to '%s'\n" % fn)
def OnMenuSaveND(self, ev=None): if self.data.dtype.type in (N.complex64, N.complex128): dat = self.dataCplx datX = abs(self.data) #CHECK else: dat = datX = self.data from Priithon.all import Mrc, U, FN, Y fn = FN(1,0) if not fn: return if fn[-4:] in [ ".mrc", ".dat" ]: Mrc.save(dat, fn) elif fn[-5:] in [ ".fits" ]: U.saveFits(dat, fn) else: # save as sequence of image files # if fn does contain something like '%0d' auto-insert '_%0NNd' # with NN to just fit the needed number of digits datX = datX.view() datX.shape = (-1,)+datX.shape[-2:] U.saveImg8_seq(datX, fn) Y.shellMessage("### Y.vd(%d) saved to '%s'\n"%(self.id, fn))
def OnMenuSaveND(self, ev=None): if self.data.dtype.type in (N.complex64, N.complex128): dat = self.dataCplx datX = abs(self.data) #CHECK else: dat = datX = self.data from Priithon.all import Mrc, U, FN, Y fn = FN(1, 0) if not fn: return if fn[-4:] in [".mrc", ".dat"]: Mrc.save(dat, fn) elif fn[-5:] in [".fits"]: U.saveFits(dat, fn) else: # save as sequence of image files # if fn does contain something like '%0d' auto-insert '_%0NNd' # with NN to just fit the needed number of digits datX = datX.view() datX.shape = (-1, ) + datX.shape[-2:] U.saveImg8_seq(datX, fn) Y.shellMessage("### Y.vd(%d) saved to '%s'\n" % (self.id, fn))
def makeFiles(fns, std=10, div_step=50, div_max=800): #1000): """ makes a series of images added Gaussain and Poisson noise std: standard deviation for Gaussian, and mean=std*10 for Poisson div_step: the step that the original image is divided while noise is added div_max: the maximum value that the original image is divided return output filenames """ outs = [] for fn in fns: a = Mrc.bindFile(fn) for ns in NOISE_STATS: hdr = mrcIO.makeHdr_like(a.Mrc.hdr) if ns == NOISE_STATS[0]: noise = F.noiseArr(a.shape, stddev=std, mean=0) else: noise = F.poissonArr(a.shape, mean=std * 10) steps = range(div_step, div_max + div_step, div_step) ag = [a / c + noise for c in steps] for i, arr in enumerate(ag): val = steps[i] if hasattr(arr, "Mrc"): del arr.Mrc if arr.dtype == N.float64: arr = arr.astype(N.float32) hdr.PixelType = 2 out = a.Mrc.path + ns + '%04d' % val Mrc.save(arr, out, ifExists='overwrite', hdr=hdr) outs.append(out) return outs