def _processMovie(self, movie): movieFolder = self._getOutputMovieFolder(movie) x, y, n = movie.getDim() s0, sN = self._getFrameRange(n, 'sum') inputMd = os.path.join(movieFolder, 'input_movie.xmd') writeMovieMd(movie, inputMd, s0, sN, useAlignment=(movie.hasAlignment() and self.useAlignment)) outputMicFn = self._getExtraPath(self._getOutputMicName(movie)) if self.cropRegion == CROP_ALIGNMENT and movie.hasAlignment(): roi = movie.getAlignment().getRoi() elif self.cropRegion == CROP_NEW: roi = [self.cropOffsetX.get(), self.cropOffsetY.get(), self.cropDimX.get(), self.cropDimY.get()] else: roi = None self.averageMovie(movie, inputMd, outputMicFn, self.binFactor.get(), roi, self.inputMovies.get().getDark(), self.inputMovies.get().getGain(), splineOrder=self.INTERP_MAP[self.splineOrder.get()]) self._storeSummary(movie)
def _processMovie(self, movie): movieFolder = self._getOutputMovieFolder(movie) x, y, n = movie.getDim() s0, sN = self._getFrameRange(n, 'sum') inputMd = os.path.join(movieFolder, 'input_movie.xmd') writeMovieMd(movie, inputMd, s0, sN, useAlignment=(movie.hasAlignment() and self.useAlignment)) outputMicFn = self._getExtraPath(self._getOutputMicName(movie)) if self.cropRegion == CROP_ALIGNMENT and movie.hasAlignment(): roi = movie.getAlignment().getRoi() elif self.cropRegion == CROP_NEW: roi = [ self.cropOffsetX.get(), self.cropOffsetY.get(), self.cropDimX.get(), self.cropDimY.get() ] else: roi = None gainFn = self.inputMovies.get().getGain() ext = pwutils.getExt( self.inputMovies.get().getFirstItem().getFileName()).lower() if self.inputMovies.get().getGain() and ext in ['.tif', '.tiff']: self.flipY = True inGainFn = self.inputMovies.get().getGain() gainFn = xmutils.flipYImage(inGainFn, outDir=self._getExtraPath()) self.averageMovie( movie, inputMd, outputMicFn, self.binFactor.get(), roi, self.inputMovies.get().getDark(), gainFn, splineOrder=self.INTERP_MAP[self.splineOrder.get()], outxmd="\"\"") # we're not interested in the metadata self._storeSummary(movie)
def _processMovie(self, movie): inputMovies = self.inputMovies.get() if self.doApplyDoseFilter: outMicFn = self._getExtraPath(self._getOutputMicWtName(movie)) else: outMicFn = self._getExtraPath(self._getOutputMicName(movie)) outMovieFn = self._getExtraPath(self._getOutputMovieName(movie)) aveMic = self._getFnInMovieFolder(movie, "uncorrected_mic.mrc") dark = inputMovies.getDark() gain = inputMovies.getGain() # Get the number of frames and the range # to be used for alignment and sum x, y, n = movie.getDim() a0, aN = self._getFrameRange(n, 'align') gpuId = self.gpuList.get() inputMd = self._getFnInMovieFolder(movie, 'input_movie.xmd') writeMovieMd(movie, inputMd, a0, aN, useAlignment=self.useAlignment) args = '-i %s ' % inputMd args += '-o "%s" ' % self._getOutputShifts(movie) args += ' --frameRange %d %d ' % (0, aN - a0) if dark: args += '--dark %s ' % dark if gain: args += '--gain %s ' % gain winSize = self.winSize.get() doSaveMovie = self.doSaveMovie.get() groupSize = self.groupSize.get() args += ' --winSize %(winSize)d --groupSize %(groupSize)d ' % locals() if self.useGpu: program = 'xmipp_movie_optical_alignment_gpu' args += '--gpu %s ' % gpuId else: program = 'xmipp_movie_optical_alignment_cpu' # We should save the movie either if the user selected it (default) # or if the PSD is going to be computed if self.doSaveAveMic or self.doComputePSD: args += '--oavg "%s" ' % outMicFn if self.doComputePSD: args += '--oavgInitial %s ' % aveMic if doSaveMovie: args += '--outMovie %s ' % outMovieFn roi = [ self.cropOffsetX.get(), self.cropOffsetY.get(), self.cropDimX.get(), self.cropDimY.get() ] args += '--cropULCorner %d %d ' % (roi[0], roi[1]) args += '--cropDRCorner %d %d ' % (roi[0] + roi[2] - 1, roi[1] + roi[3] - 1) if self.memory: args += ' --inmemory' toDelete = [] if self.doApplyDoseFilter: pxSize = movie.getSamplingRate() vol = movie.getAcquisition().getVoltage() preExp, dose = self._getCorrectedDose(inputMovies) args += ' --doseCorrection %f %f %f %f' % (dose, pxSize, vol, preExp) if self.applyDosePreAlign: args += ' pre' else: args += ' post' if self.doSaveUnweightedMic: outUnwtMicFn = self._getExtraPath( self._getOutputMicName(movie)) outUnwtMovieFn = self._getExtraPath( self._getOutputMovieUnWtName(movie)) args += ' --oUnc %s %s' % (outUnwtMicFn, outUnwtMovieFn) toDelete.append(outUnwtMovieFn) try: self.runJob(program, args) if self.doSaveAveMic: if not exists(outMicFn): raise Exception("Micrograph %s not produced after " "running %s " % (outMicFn, program)) if self.doSaveMovie: if not exists(outMovieFn): raise Exception("Movie %s not produced after running %s " % (outMovieFn, program)) if self.doComputePSD: self.computePSDImages(movie, aveMic, outMicFn, outputFnCorrected=outMicFn + 'psd.png') # If the micrograph was only saved for computing the PSD # we can remove it if not self.doSaveAveMic: pwutils.cleanPath(outMicFn) for fn in toDelete: pwutils.cleanPath(fn) self._saveAlignmentPlots(movie) except Exception as e: print("ERROR: %s failed for movie %s.\n Exception: %s" % (program, movie.getFileName(), e))
def _processMovie(self, movie): movieFolder = self._getOutputMovieFolder(movie) x, y, n = movie.getDim() a0, aN = self._getFrameRange(n, 'align') s0, sN = self._getFrameRange(n, 'sum') inputMd = os.path.join(movieFolder, 'input_movie.xmd') writeMovieMd(movie, inputMd, a0, aN, useAlignment=False) args = '-i "%s" ' % inputMd args += '-o "%s" ' % self._getShiftsFile(movie) args += '--sampling %f ' % movie.getSamplingRate() args += '--max_freq %f ' % self.maxFreq args += '--Bspline %d ' % self.INTERP_MAP[self.splineOrder.get()] if self.binFactor > 1: args += '--bin %f ' % self.binFactor # Assume that if you provide one cropDim, you provide all offsetX = self.cropOffsetX.get() offsetY = self.cropOffsetY.get() cropDimX = self.cropDimX.get() cropDimY = self.cropDimY.get() args += '--cropULCorner %d %d ' % (offsetX, offsetY) if cropDimX <= 0: dimX = x - 1 else: dimX = offsetX + cropDimX - 1 if cropDimY <= 0: dimY = y - 1 else: dimY = offsetY + cropDimY - 1 args += '--cropDRCorner %d %d ' % (dimX, dimY) if self.outsideMode == self.OUTSIDE_WRAP: args += "--outside wrap" elif self.outsideMode == self.OUTSIDE_AVG: args += "--outside avg" elif self.outsideMode == self.OUTSIDE_AVG: args += "--outside value %f" % self.outsideValue args += ' --frameRange %d %d ' % (0, aN - a0) args += ' --frameRangeSum %d %d ' % (s0 - a0, sN - a0) args += ' --max_shift %d ' % self.maxShift if self.doSaveAveMic or self.doComputePSD: fnAvg = self._getExtraPath(self._getOutputMicName(movie)) args += ' --oavg "%s"' % fnAvg if self.doComputePSD: fnInitial = os.path.join(movieFolder, "initialMic.mrc") args += ' --oavgInitial %s' % fnInitial if self.doSaveMovie: args += ' --oaligned %s' % self._getExtraPath( self._getOutputMovieName(movie)) if self.inputMovies.get().getDark(): args += ' --dark ' + self.inputMovies.get().getDark() if self.inputMovies.get().getGain(): args += ' --gain ' + self.inputMovies.get().getGain() if self.autoControlPoints.get(): self._setControlPoints() if self.useGpu.get(): args += ' --device %(GPU)s' if self.doLocalAlignment.get(): args += ' --processLocalShifts ' args += ' --storage ' + self._getExtraPath("fftBenchmark.txt") args += ' --controlPoints %d %d %d' % ( self.controlPointX, self.controlPointY, self.controlPointT) args += ' --patches %d %d' % (self.patchX, self.patchY) args += ' --locCorrDownscale 4 4' args += ' --patchesAvg %d' % self.groupNFrames self.runJob('xmipp_cuda_movie_alignment_correlation', args, numberOfMpi=1) else: self.runJob('xmipp_movie_alignment_correlation', args, numberOfMpi=1) if self.doComputePSD: self.computePSDs(movie, fnInitial, fnAvg) # If the micrograph was only saved for computing the PSD # we can remove it pwutils.cleanPath(fnInitial) if not self.doSaveAveMic: pwutils.cleanPath(fnAvg) self._saveAlignmentPlots(movie)
def tryProcessMovie(self, movie): movieFolder = self._getOutputMovieFolder(movie) x, y, n = movie.getDim() a0, aN = self._getFrameRange(n, 'align') s0, sN = self._getFrameRange(n, 'sum') inputMd = os.path.join(movieFolder, 'input_movie.xmd') writeMovieMd(movie, inputMd, a0, aN, useAlignment=False) args = '-i "%s" ' % inputMd args += ' -o "%s"' % self._getShiftsFile(movie) args += ' --sampling %f' % movie.getSamplingRate() args += ' --maxResForCorrelation %f' % self.maxResForCorrelation args += ' --Bspline %d' % self.INTERP_MAP[self.splineOrder.get()] if self.binFactor > 1: args += ' --bin %f' % self.binFactor args += self.getCropCornerArg(x, y) args += self.getOutsideModeArg() args += ' --frameRange %d %d' % (0, aN - a0) args += ' --frameRangeSum %d %d' % (s0 - a0, sN - a0) args += ' --max_shift %d' % self.maxShift if self.doSaveAveMic or self.doComputePSD: fnAvg = self._getExtraPath(self._getOutputMicName(movie)) args += ' --oavg "%s"' % fnAvg if self.doComputePSD: fnInitial = os.path.join(movieFolder, "initialMic.mrc") args += ' --oavgInitial "%s"' % fnInitial if self.doSaveMovie: args += ' --oaligned "%s"' % self._getExtraPath( self._getOutputMovieName(movie)) if self.inputMovies.get().getDark(): args += ' --dark "%s"' % self.inputMovies.get().getDark() if self.inputMovies.get().getGain(): ext = pwutils.getExt( self.inputMovies.get().getFirstItem().getFileName()).lower() if ext in ['.tif', '.tiff']: self.flipY = True inGainFn = self.inputMovies.get().getGain() gainFn = xmutils.flipYImage(inGainFn, outDir=self._getExtraPath()) else: gainFn = self.inputMovies.get().getGain() if self.gainRot.get() != 0 or self.gainFlip.get() != 0: gainFn = self.transformGain(gainFn) args += ' --gain "%s"' % gainFn if self.autoControlPoints.get(): self._setControlPoints() if self.minLocalRes.get(): args += ' --minLocalRes %f' % self.minLocalRes if self.useGpu.get(): args += self.getGPUArgs() self.runJob('xmipp_cuda_movie_alignment_correlation', args, numberOfMpi=1) else: self.runJob('xmipp_movie_alignment_correlation', args, numberOfMpi=1) if self.doComputePSD: self.computePSDImages(movie, fnInitial, fnAvg) # If the micrograph was only saved for computing the PSD # we can remove it pwutils.cleanPath(fnInitial) if not self.doSaveAveMic: pwutils.cleanPath(fnAvg) self._saveAlignmentPlots(movie)