From 27930ff136a3ba0029e8c4688c30003be42862ab Mon Sep 17 00:00:00 2001 From: fede-pe Date: Tue, 21 Nov 2023 13:40:47 +0100 Subject: [PATCH 01/12] make apply transform error tolerant --- .../protocol_applyTransformationMatrix.py | 99 ++++++++++--------- 1 file changed, 54 insertions(+), 45 deletions(-) diff --git a/imod/protocols/protocol_applyTransformationMatrix.py b/imod/protocols/protocol_applyTransformationMatrix.py index 241816f9..6857737e 100644 --- a/imod/protocols/protocol_applyTransformationMatrix.py +++ b/imod/protocols/protocol_applyTransformationMatrix.py @@ -74,10 +74,13 @@ def _defineParams(self, form): # -------------------------- INSERT steps functions ----------------------- def _insertAllSteps(self): + self._failedTs = [] + for ts in self.inputSetOfTiltSeries.get(): self._insertFunctionStep(self.generateTransformFileStep, ts.getObjId()) self._insertFunctionStep(self.computeAlignmentStep, ts.getObjId()) self._insertFunctionStep(self.generateOutputStackStep, ts.getObjId()) + self._insertFunctionStep(self.createOutputFailedSet, ts.getObjId()) self._insertFunctionStep(self.closeOutputSetsStep) # --------------------------- STEPS functions ------------------------------ @@ -90,6 +93,7 @@ def generateTransformFileStep(self, tsObjId): os.path.join(extraPrefix, ts.getFirstItem().parseFileName(extension=".xf"))) + @ProtImodBase.tryExceptDecorator def computeAlignmentStep(self, tsObjId): ts = self.inputSetOfTiltSeries.get()[tsObjId] tsId = ts.getTsId() @@ -147,54 +151,59 @@ def generateOutputStackStep(self, tsObjId): ts = self.inputSetOfTiltSeries.get()[tsObjId] tsId = ts.getTsId() extraPrefix = self._getExtraPath(tsId) - binning = self.binning.get() - newTs = TiltSeries(tsId=tsId) - newTs.copyInfo(ts) - newTs.setInterpolated(True) - acq = newTs.getAcquisition() - acq.setTiltAxisAngle(0.) # 0 because TS is aligned - newTs.setAcquisition(acq) - output.append(newTs) - - if binning > 1: - newTs.setSamplingRate(ts.getSamplingRate() * binning) - - ih = ImageHandler() - - index = 1 - for tiltImage in ts: - if tiltImage.isEnabled(): - newTi = TiltImage() - newTi.copyInfo(tiltImage, copyId=False, copyTM=False) - acq = tiltImage.getAcquisition() - acq.setTiltAxisAngle(0.) - newTi.setAcquisition(acq) - newTi.setLocation(index, (os.path.join(extraPrefix, tiltImage.parseFileName()))) - if self.applyToOddEven(ts): - locationOdd = index, (os.path.join(extraPrefix, tsId + EXT_MRCS_TS_ODD_NAME)) - locationEven = index, (os.path.join(extraPrefix, tsId + EXT_MRCS_TS_EVEN_NAME)) - newTi.setOddEven([ih.locationToXmipp(locationOdd), ih.locationToXmipp(locationEven)]) - else: - newTi.setOddEven([]) - - index += 1 - if binning > 1: - newTi.setSamplingRate(tiltImage.getSamplingRate() * binning) - newTs.append(newTi) - - ih = ImageHandler() - x, y, z, _ = ih.getDimensions(newTs.getFirstItem().getFileName()) - newTs.setDim((x, y, z)) - - newTs.write(properties=False) - output.update(newTs) - output.write() - self._store() + outputLocation = os.path.join(extraPrefix, tiltImage.parseFileName()) + + if os.path.exists(outputLocation): + binning = self.binning.get() + + newTs = TiltSeries(tsId=tsId) + newTs.copyInfo(ts) + newTs.setInterpolated(True) + acq = newTs.getAcquisition() + acq.setTiltAxisAngle(0.) # 0 because TS is aligned + newTs.setAcquisition(acq) + output.append(newTs) + + if binning > 1: + newTs.setSamplingRate(ts.getSamplingRate() * binning) + + ih = ImageHandler() + + index = 1 + for tiltImage in ts: + if tiltImage.isEnabled(): + newTi = TiltImage() + newTi.copyInfo(tiltImage, copyId=False, copyTM=False) + acq = tiltImage.getAcquisition() + acq.setTiltAxisAngle(0.) + newTi.setAcquisition(acq) + newTi.setLocation(index, outputLocation) + if self.applyToOddEven(ts): + locationOdd = index, (os.path.join(extraPrefix, tsId + EXT_MRCS_TS_ODD_NAME)) + locationEven = index, (os.path.join(extraPrefix, tsId + EXT_MRCS_TS_EVEN_NAME)) + newTi.setOddEven([ih.locationToXmipp(locationOdd), ih.locationToXmipp(locationEven)]) + else: + newTi.setOddEven([]) + + index += 1 + if binning > 1: + newTi.setSamplingRate(tiltImage.getSamplingRate() * binning) + newTs.append(newTi) + + ih = ImageHandler() + x, y, z, _ = ih.getDimensions(newTs.getFirstItem().getFileName()) + newTs.setDim((x, y, z)) + + newTs.write(properties=False) + output.update(newTs) + output.write() + self._store() def closeOutputSetsStep(self): - self.InterpolatedTiltSeries.setStreamState(Set.STREAM_CLOSED) - self.InterpolatedTiltSeries.write() + for _, output in self.iterOutputAttributes(): + output.setStreamState(Set.STREAM_CLOSED) + output.write() self._store() # --------------------------- INFO functions ------------------------------ From a88df1799da4c39abd68f44843da71bdba7e4b28 Mon Sep 17 00:00:00 2001 From: fede-pe Date: Tue, 21 Nov 2023 13:41:49 +0100 Subject: [PATCH 02/12] make TS normalization error tolerant --- imod/protocols/protocol_tsNormalization.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/imod/protocols/protocol_tsNormalization.py b/imod/protocols/protocol_tsNormalization.py index e16a84ab..b1924676 100644 --- a/imod/protocols/protocol_tsNormalization.py +++ b/imod/protocols/protocol_tsNormalization.py @@ -199,6 +199,8 @@ def _defineParams(self, form): # -------------------------- INSERT steps functions ----------------------- def _insertAllSteps(self): + self._failedTs = [] + for ts in self.inputSetOfTiltSeries.get(): self._insertFunctionStep(self.convertInputStep, ts.getObjId()) self._insertFunctionStep(self.generateOutputStackStep, ts.getObjId()) @@ -210,6 +212,7 @@ def convertInputStep(self, tsObjId, **kwargs): super().convertInputStep(tsObjId, imodInterpolation=None, generateAngleFile=False) + @ProtImodBase.tryExceptDecorator def generateOutputStackStep(self, tsObjId): output = self.getOutputSetOfTiltSeries(self.inputSetOfTiltSeries.get(), self.binning.get()) @@ -320,10 +323,10 @@ def generateOutputStackStep(self, tsObjId): self._store() def closeOutputSetsStep(self): - self.TiltSeries.setStreamState(Set.STREAM_CLOSED) - self.TiltSeries.write() + for _, output in self.iterOutputAttributes(): + output.setStreamState(Set.STREAM_CLOSED) + output.write() self._store() - # --------------------------- UTILS functions ----------------------------- def getModeToOutput(self): parseParamsOutputMode = { From d17f7113245abd10a4971d236992d067bfbcc8e5 Mon Sep 17 00:00:00 2001 From: fede-pe Date: Tue, 21 Nov 2023 15:02:17 +0100 Subject: [PATCH 03/12] fixes --- .../protocol_applyTransformationMatrix.py | 2 +- imod/protocols/protocol_tsNormalization.py | 16 +++++++++------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/imod/protocols/protocol_applyTransformationMatrix.py b/imod/protocols/protocol_applyTransformationMatrix.py index 6857737e..4b343f0f 100644 --- a/imod/protocols/protocol_applyTransformationMatrix.py +++ b/imod/protocols/protocol_applyTransformationMatrix.py @@ -152,7 +152,7 @@ def generateOutputStackStep(self, tsObjId): tsId = ts.getTsId() extraPrefix = self._getExtraPath(tsId) - outputLocation = os.path.join(extraPrefix, tiltImage.parseFileName()) + outputLocation = os.path.join(extraPrefix, ts.getFirstItem().parseFileName()) if os.path.exists(outputLocation): binning = self.binning.get() diff --git a/imod/protocols/protocol_tsNormalization.py b/imod/protocols/protocol_tsNormalization.py index b1924676..5ff70ed8 100644 --- a/imod/protocols/protocol_tsNormalization.py +++ b/imod/protocols/protocol_tsNormalization.py @@ -234,7 +234,8 @@ def generateOutputStackStep(self, tsObjId): argsNewstack, paramsNewstack = self.getBasicNewstackParams(ts, os.path.join(extraPrefix, firstItem.parseFileName()), - inputTsFileName=os.path.join(tmpPrefix, firstItem.parseFileName()), + inputTsFileName=os.path.join(tmpPrefix, + firstItem.parseFileName()), xfFile=xfFile, firstItem=firstItem, binning=binning, @@ -272,12 +273,12 @@ def generateOutputStackStep(self, tsObjId): if self.applyToOddEven(ts): oddFn = firstItem.getOdd().split('@')[1] - evenFn= firstItem.getEven().split('@')[1] + evenFn = firstItem.getEven().split('@')[1] paramsNewstack['input'] = oddFn - paramsNewstack['output'] = os.path.join(extraPrefix, tsId+EXT_MRCS_TS_ODD_NAME) + paramsNewstack['output'] = os.path.join(extraPrefix, tsId + EXT_MRCS_TS_ODD_NAME) Plugin.runImod(self, 'newstack', argsNewstack % paramsNewstack) paramsNewstack['input'] = evenFn - paramsNewstack['output'] = os.path.join(extraPrefix, tsId+EXT_MRCS_TS_EVEN_NAME) + paramsNewstack['output'] = os.path.join(extraPrefix, tsId + EXT_MRCS_TS_EVEN_NAME) Plugin.runImod(self, 'newstack', argsNewstack % paramsNewstack) newTs = tomoObj.TiltSeries(tsId=tsId) @@ -301,8 +302,8 @@ def generateOutputStackStep(self, tsObjId): newTi.setAcquisition(tiltImage.getAcquisition()) if self.applyToOddEven(ts): - locationOdd = index + 1, (os.path.join(extraPrefix, tsId+EXT_MRCS_TS_ODD_NAME)) - locationEven = index + 1, (os.path.join(extraPrefix, tsId+EXT_MRCS_TS_EVEN_NAME)) + locationOdd = index + 1, (os.path.join(extraPrefix, tsId + EXT_MRCS_TS_ODD_NAME)) + locationEven = index + 1, (os.path.join(extraPrefix, tsId + EXT_MRCS_TS_EVEN_NAME)) newTi.setOddEven([ih.locationToXmipp(locationOdd), ih.locationToXmipp(locationEven)]) else: newTi.setOddEven([]) @@ -327,6 +328,7 @@ def closeOutputSetsStep(self): output.setStreamState(Set.STREAM_CLOSED) output.write() self._store() + # --------------------------- UTILS functions ----------------------------- def getModeToOutput(self): parseParamsOutputMode = { @@ -348,7 +350,7 @@ def updateTM(self, newTi): transform.setMatrix(matrix) newTi.setTransform(transform) - + return newTi # --------------------------- INFO functions ------------------------------ From dcc14c440a54fee458447a8576c346f33f48605b Mon Sep 17 00:00:00 2001 From: fede-pe Date: Tue, 21 Nov 2023 15:07:38 +0100 Subject: [PATCH 04/12] fixes apply transformW --- imod/protocols/protocol_applyTransformationMatrix.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/imod/protocols/protocol_applyTransformationMatrix.py b/imod/protocols/protocol_applyTransformationMatrix.py index 4b343f0f..bacbe4b6 100644 --- a/imod/protocols/protocol_applyTransformationMatrix.py +++ b/imod/protocols/protocol_applyTransformationMatrix.py @@ -146,7 +146,6 @@ def computeAlignmentStep(self, tsObjId): Plugin.runImod(self, 'newstack', argsAlignment % paramsAlignment) def generateOutputStackStep(self, tsObjId): - output = self.getOutputInterpolatedSetOfTiltSeries(self.inputSetOfTiltSeries.get()) ts = self.inputSetOfTiltSeries.get()[tsObjId] tsId = ts.getTsId() @@ -155,6 +154,8 @@ def generateOutputStackStep(self, tsObjId): outputLocation = os.path.join(extraPrefix, ts.getFirstItem().parseFileName()) if os.path.exists(outputLocation): + output = self.getOutputInterpolatedSetOfTiltSeries(self.inputSetOfTiltSeries.get()) + binning = self.binning.get() newTs = TiltSeries(tsId=tsId) From a10fa8c9de11b632c97adf224ba7aed49592bed6 Mon Sep 17 00:00:00 2001 From: fede-pe Date: Tue, 21 Nov 2023 15:10:11 +0100 Subject: [PATCH 05/12] fixes ts normalization --- imod/protocols/protocol_tsNormalization.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/imod/protocols/protocol_tsNormalization.py b/imod/protocols/protocol_tsNormalization.py index 5ff70ed8..8c91016c 100644 --- a/imod/protocols/protocol_tsNormalization.py +++ b/imod/protocols/protocol_tsNormalization.py @@ -204,6 +204,7 @@ def _insertAllSteps(self): for ts in self.inputSetOfTiltSeries.get(): self._insertFunctionStep(self.convertInputStep, ts.getObjId()) self._insertFunctionStep(self.generateOutputStackStep, ts.getObjId()) + self._insertFunctionStep(self.createOutputFailedSet, ts.getObjId()) self._insertFunctionStep(self.closeOutputSetsStep) # --------------------------- STEPS functions ----------------------------- @@ -214,9 +215,6 @@ def convertInputStep(self, tsObjId, **kwargs): @ProtImodBase.tryExceptDecorator def generateOutputStackStep(self, tsObjId): - output = self.getOutputSetOfTiltSeries(self.inputSetOfTiltSeries.get(), - self.binning.get()) - ts = self.inputSetOfTiltSeries.get()[tsObjId] tsId = ts.getTsId() @@ -281,6 +279,8 @@ def generateOutputStackStep(self, tsObjId): paramsNewstack['output'] = os.path.join(extraPrefix, tsId + EXT_MRCS_TS_EVEN_NAME) Plugin.runImod(self, 'newstack', argsNewstack % paramsNewstack) + output = self.getOutputSetOfTiltSeries(self.inputSetOfTiltSeries.get(), self.binning.get()) + newTs = tomoObj.TiltSeries(tsId=tsId) newTs.copyInfo(ts) output.append(newTs) From 1298b27a5e19d6c1abae89405b2242d13d710956 Mon Sep 17 00:00:00 2001 From: Vilax Date: Thu, 23 Nov 2023 09:12:20 +0100 Subject: [PATCH 06/12] fixing reconstruction issue --- imod/protocols/protocol_base.py | 26 ++++++++++++++++++- imod/protocols/protocol_tomoReconstruction.py | 10 +++---- imod/protocols/protocol_xCorrPrealignment.py | 2 ++ imod/protocols/protocol_xRaysEraser.py | 1 + 4 files changed, 33 insertions(+), 6 deletions(-) diff --git a/imod/protocols/protocol_base.py b/imod/protocols/protocol_base.py index 3793350e..731bf86a 100644 --- a/imod/protocols/protocol_base.py +++ b/imod/protocols/protocol_base.py @@ -87,7 +87,7 @@ def _defineImportParams(self, form): # --------------------------- CACULUS functions --------------------------- def convertInputStep(self, tsObjId, generateAngleFile=True, - imodInterpolation=True, doSwap=False): + imodInterpolation=True, doSwap=False, oddEven=False): """ :param tsObjId: Tilt series identifier @@ -138,6 +138,30 @@ def convertInputStep(self, tsObjId, generateAngleFile=True, self.info("Interpolating tilt series %s with imod" % tsId) Plugin.runImod(self, 'newstack', argsAlignment % paramsAlignment) + if oddEven: + + firstItem = ts.getFirstItem() + fnOdd = firstItem.getOdd().split('@')[1] + fnEven = firstItem.getEven().split('@')[1] + + outputOddTsFileName = os.path.join(tmpPrefix, tsId+EXT_MRCS_TS_EVEN_NAME) + argsAlignment, paramsAlignment = self.getBasicNewstackParams(ts, + outputOddTsFileName, + inputTsFileName=fnOdd, + xfFile=outputTmFileName, + firstItem=firstItem, + doSwap=doSwap) + Plugin.runImod(self, 'newstack', argsAlignment % paramsAlignment) + + outputEvenTsFileName = os.path.join(tmpPrefix, tsId+EXT_MRCS_TS_ODD_NAME) + argsAlignment, paramsAlignment = self.getBasicNewstackParams(ts, + outputEvenTsFileName, + inputTsFileName=fnEven, + xfFile=outputTmFileName, + firstItem=firstItem, + doSwap=doSwap) + Plugin.runImod(self, 'newstack', argsAlignment % paramsAlignment) + else: self.info("Linking tilt series %s" % tsId) path.createLink(firstItem.getFileName(), outputTsFileName) diff --git a/imod/protocols/protocol_tomoReconstruction.py b/imod/protocols/protocol_tomoReconstruction.py index d01ae2ad..b5334cbd 100644 --- a/imod/protocols/protocol_tomoReconstruction.py +++ b/imod/protocols/protocol_tomoReconstruction.py @@ -32,7 +32,7 @@ from tomo.objects import Tomogram from .. import Plugin -from .protocol_base import ProtImodBase, EXT_MRC_ODD_NAME, EXT_MRC_EVEN_NAME +from .protocol_base import ProtImodBase, EXT_MRC_ODD_NAME, EXT_MRC_EVEN_NAME, EXT_MRCS_TS_EVEN_NAME, EXT_MRCS_TS_ODD_NAME class ProtImodTomoReconstruction(ProtImodBase): @@ -178,7 +178,7 @@ def _insertAllSteps(self): # --------------------------- STEPS functions ----------------------------- def convertInputStep(self, tsObjId): # Considering swapXY is required to make tilt axis vertical - super().convertInputStep(tsObjId, doSwap=True) + super().convertInputStep(tsObjId, doSwap=True, oddEven=True) def computeReconstructionStep(self, tsObjId): ts = self.inputSetOfTiltSeries.get()[tsObjId] @@ -240,13 +240,13 @@ def getArgs(): oddEvenTmp = [[], []] if self.applyToOddEven(ts): - oddFn = firstItem.getOdd().split('@')[1] + oddFn = os.path.join(tmpPrefix, tsId+EXT_MRCS_TS_ODD_NAME) paramsTilt['InputProjections'] = oddFn oddEvenTmp[0] = os.path.join(tmpPrefix, firstItem.parseFileName(extension="_odd.rec")) paramsTilt['OutputFile'] = oddEvenTmp[0] - Plugin.runImod(self, 'tilt', argsTilt % paramsTilt) - evenFn = firstItem.getEven().split('@')[1] + + evenFn = os.path.join(tmpPrefix, tsId+EXT_MRCS_TS_EVEN_NAME) paramsTilt['InputProjections'] = evenFn oddEvenTmp[1] = os.path.join(tmpPrefix, firstItem.parseFileName(extension="_even.rec")) paramsTilt['OutputFile'] = oddEvenTmp[1] diff --git a/imod/protocols/protocol_xCorrPrealignment.py b/imod/protocols/protocol_xCorrPrealignment.py index cc0bc5b0..b9bf4b0a 100644 --- a/imod/protocols/protocol_xCorrPrealignment.py +++ b/imod/protocols/protocol_xCorrPrealignment.py @@ -47,6 +47,7 @@ class ProtImodXcorrPrealignment(ProtImodBase): _label = 'Coarse prealignment' _devStatus = BETA + _possibleOutputs = {"outputSetOfTiltSeries": tomoObj.SetOfTiltSeries} # -------------------------- DEFINE param functions ----------------------- def _defineParams(self, form): @@ -83,6 +84,7 @@ def _defineParams(self, form): form.addParam('binning', params.IntParam, + condition='computeAlignment==0', default=1, label='Binning for the interpolated', help='Binning to be applied to the interpolated ' diff --git a/imod/protocols/protocol_xRaysEraser.py b/imod/protocols/protocol_xRaysEraser.py index 031e16a4..f19d9fef 100644 --- a/imod/protocols/protocol_xRaysEraser.py +++ b/imod/protocols/protocol_xRaysEraser.py @@ -45,6 +45,7 @@ class ProtImodXraysEraser(ProtImodBase): _label = 'X-rays eraser' _devStatus = BETA + _possibleOutputs = {"outputSetOfTiltSeries": tomoObj.SetOfTiltSeries} # def __init__(self, **kwargs): # EMProtocol.__init__(self, **kwargs) From 66a1345f3aa3d41dfad21e611d65c9b473404e66 Mon Sep 17 00:00:00 2001 From: Vilax Date: Thu, 23 Nov 2023 09:24:26 +0100 Subject: [PATCH 07/12] final validation oddEven --- imod/protocols/protocol_tomoReconstruction.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/imod/protocols/protocol_tomoReconstruction.py b/imod/protocols/protocol_tomoReconstruction.py index a5fba746..9f1b0906 100644 --- a/imod/protocols/protocol_tomoReconstruction.py +++ b/imod/protocols/protocol_tomoReconstruction.py @@ -181,7 +181,10 @@ def _insertAllSteps(self): # --------------------------- STEPS functions ----------------------------- def convertInputStep(self, tsObjId, **kwargs): # Considering swapXY is required to make tilt axis vertical - super().convertInputStep(tsObjId, doSwap=True, oddEven=True) + oddEvenFlag = False + if self.inputSetOfTiltSeries.get().hasOddEven(): + oddEvenFlag = True + super().convertInputStep(tsObjId, doSwap=True, oddEven=oddEvenFlag) @ProtImodBase.tryExceptDecorator def computeReconstructionStep(self, tsObjId): From cc17859edca14534e376197b9eb9d3696e1e9cb3 Mon Sep 17 00:00:00 2001 From: Vilax Date: Thu, 23 Nov 2023 12:30:28 +0100 Subject: [PATCH 08/12] refactor base --- imod/protocols/protocol_base.py | 34 +++++++++++---------------------- 1 file changed, 11 insertions(+), 23 deletions(-) diff --git a/imod/protocols/protocol_base.py b/imod/protocols/protocol_base.py index 364d0d44..f0d07dd9 100644 --- a/imod/protocols/protocol_base.py +++ b/imod/protocols/protocol_base.py @@ -140,42 +140,30 @@ def convertInputStep(self, tsObjId, generateAngleFile=True, # Use IMOD newstack interpolation if firstItem.hasTransform(): # Generate transformation matrices file - outputTmFileName = os.path.join(tmpPrefix, - firstItem.parseFileName(extension=".xf")) + outputTmFileName = os.path.join(tmpPrefix, firstItem.parseFileName(extension=".xf")) utils.formatTransformFile(ts, outputTmFileName) - argsAlignment, paramsAlignment = self.getBasicNewstackParams(ts, + def applyNewStack(outputTsFileName, fnIn): + + argsAlignment, paramsAlignment = self.getBasicNewstackParams(ts, outputTsFileName, + inputTsFileName=fnIn, xfFile=outputTmFileName, firstItem=firstItem, doSwap=doSwap) + Plugin.runImod(self, 'newstack', argsAlignment % paramsAlignment) self.info("Interpolating tilt series %s with imod" % tsId) - Plugin.runImod(self, 'newstack', argsAlignment % paramsAlignment) + applyNewStack(outputTsFileName, None) if oddEven: - - firstItem = ts.getFirstItem() - fnOdd = firstItem.getOdd().split('@')[1] - fnEven = firstItem.getEven().split('@')[1] + fnOdd = ts.getOddFileName() + fnEven = ts.getEvenFileName() outputOddTsFileName = os.path.join(tmpPrefix, tsId+EXT_MRCS_TS_EVEN_NAME) - argsAlignment, paramsAlignment = self.getBasicNewstackParams(ts, - outputOddTsFileName, - inputTsFileName=fnOdd, - xfFile=outputTmFileName, - firstItem=firstItem, - doSwap=doSwap) - Plugin.runImod(self, 'newstack', argsAlignment % paramsAlignment) - outputEvenTsFileName = os.path.join(tmpPrefix, tsId+EXT_MRCS_TS_ODD_NAME) - argsAlignment, paramsAlignment = self.getBasicNewstackParams(ts, - outputEvenTsFileName, - inputTsFileName=fnEven, - xfFile=outputTmFileName, - firstItem=firstItem, - doSwap=doSwap) - Plugin.runImod(self, 'newstack', argsAlignment % paramsAlignment) + applyNewStack(outputOddTsFileName, fnOdd) + applyNewStack(outputEvenTsFileName, fnEven) else: self.info("Linking tilt series %s" % tsId) From 7207b54fcb61469c8b1ac1315e94277d253dc5f9 Mon Sep 17 00:00:00 2001 From: Vilax Date: Thu, 23 Nov 2023 12:35:44 +0100 Subject: [PATCH 09/12] addign changes --- CHANGES.txt | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGES.txt b/CHANGES.txt index e74d8e73..d70188fd 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,3 +1,10 @@ +3.3.0: + - Fixing a bug with odd even in tomogram reconstruction + - Tolerating errors in alignment + - Making tomogram reconstruction error tolerant + - Making tilt series alignment error tolerant + - Adding possible outputs in xray eraser + - Removing visible parameters with the intepolation is not applied 3.2.0: - add more possible outputs - fixing ctf after aretomo @@ -79,4 +86,4 @@ - fix betterradius param in gold eraser tab of the fid alignment - add missing pix size in fid align - fix minpacing in gold picker - - add missing taper arg for newstack \ No newline at end of file + - add missing taper arg for newstack From 0c84021f04ebe9deafcd7b6f30fb6867d9e7f9c0 Mon Sep 17 00:00:00 2001 From: Vilax Date: Tue, 28 Nov 2023 18:52:06 +0100 Subject: [PATCH 10/12] fixing CTF issue --- imod/protocols/protocol_ctfCorrection.py | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/imod/protocols/protocol_ctfCorrection.py b/imod/protocols/protocol_ctfCorrection.py index 7a660c68..6dd1d65d 100644 --- a/imod/protocols/protocol_ctfCorrection.py +++ b/imod/protocols/protocol_ctfCorrection.py @@ -137,7 +137,8 @@ def _defineParams(self, form): def _insertAllSteps(self): self._failedTs = [] - for ts in self.inputSetOfTiltSeries.get(): + for ts in self.inputSetOfTiltSeries.get().iterItems(): + print('cccccccccccccccccccccccccccccc') self._insertFunctionStep(self.convertInputStep, ts.getObjId()) self._insertFunctionStep(self.generateDefocusFile, ts.getObjId()) self._insertFunctionStep(self.ctfCorrection, ts.getObjId()) @@ -150,7 +151,14 @@ def convertInputStep(self, tsObjId, **kwargs): # Considering swapXY is required to make tilt axis vertical super().convertInputStep(tsObjId, doSwap=True) + def tsToProcess(self, tsObjId) -> bool: + tsId = self.inputSetOfTiltSeries.get()[tsObjId].getTsId() + ctfTomoSeries = self.getCtfTomoSeriesFromTsId(tsId) + return ctfTomoSeries + def generateDefocusFile(self, tsObjId): + if self.tsToProcess(tsObjId) is None: + return ts = self.inputSetOfTiltSeries.get()[tsObjId] tsId = ts.getTsId() @@ -160,7 +168,6 @@ def generateDefocusFile(self, tsObjId): defocusFilePath = self.getDefocusFileName(ts) """Generate defocus file""" - ctfTomoSeries = self.getCtfTomoSeriesFromTsId(tsId) utils.generateDefocusIMODFileFromObject(ctfTomoSeries, defocusFilePath, inputTiltSeries=ts) @@ -176,6 +183,8 @@ def getDefocusFileName(self, ts): @ProtImodBase.tryExceptDecorator def ctfCorrection(self, tsObjId): + if self.tsToProcess(tsObjId) is None: + return ts = self.inputSetOfTiltSeries.get()[tsObjId] tsId = ts.getTsId() extraPrefix = self._getExtraPath(tsId) @@ -228,6 +237,8 @@ def ctfCorrection(self, tsObjId): Plugin.runImod(self, 'ctfphaseflip', argsCtfPhaseFlip % paramsCtfPhaseFlip) def createOutputStep(self, tsObjId): + if self.tsToProcess(tsObjId) is None: + return if tsObjId not in self._failedTs: inputTs = self.inputSetOfTiltSeries.get() output = self.getOutputSetOfTiltSeries(inputTs) @@ -274,6 +285,11 @@ def createOutputStep(self, tsObjId): output.write() self._store() + def createOutputFailedSet(self, tsObjId): + if self.tsToProcess(tsObjId) is None: + return + super().createOutputFailedSet(tsObjId) + def closeOutputSetsStep(self): for _, output in self.iterOutputAttributes(): output.setStreamState(Set.STREAM_CLOSED) @@ -285,6 +301,7 @@ def getCtfTomoSeriesFromTsId(self, tsId): for ctfTomoSeries in self.inputSetOfCtfTomoSeries.get(): if tsId == ctfTomoSeries.getTsId(): return ctfTomoSeries + return None # --------------------------- INFO functions ------------------------------ def _warnings(self): From 5ce221f27f028f788d8f037b8ebd1433bfc0018d Mon Sep 17 00:00:00 2001 From: Vilax Date: Wed, 29 Nov 2023 10:24:40 +0100 Subject: [PATCH 11/12] removing silly comment --- imod/protocols/protocol_ctfCorrection.py | 1 - 1 file changed, 1 deletion(-) diff --git a/imod/protocols/protocol_ctfCorrection.py b/imod/protocols/protocol_ctfCorrection.py index 6dd1d65d..5a8dd435 100644 --- a/imod/protocols/protocol_ctfCorrection.py +++ b/imod/protocols/protocol_ctfCorrection.py @@ -138,7 +138,6 @@ def _insertAllSteps(self): self._failedTs = [] for ts in self.inputSetOfTiltSeries.get().iterItems(): - print('cccccccccccccccccccccccccccccc') self._insertFunctionStep(self.convertInputStep, ts.getObjId()) self._insertFunctionStep(self.generateDefocusFile, ts.getObjId()) self._insertFunctionStep(self.ctfCorrection, ts.getObjId()) From 0a3e0a0b7a91e0e33f69522b7fdc2e8527c4c784 Mon Sep 17 00:00:00 2001 From: fede-pe Date: Wed, 29 Nov 2023 11:27:24 +0100 Subject: [PATCH 12/12] change possible ouptut name --- imod/protocols/protocol_xCorrPrealignment.py | 56 ++++++++++---------- 1 file changed, 27 insertions(+), 29 deletions(-) diff --git a/imod/protocols/protocol_xCorrPrealignment.py b/imod/protocols/protocol_xCorrPrealignment.py index b9bf4b0a..5c29b065 100644 --- a/imod/protocols/protocol_xCorrPrealignment.py +++ b/imod/protocols/protocol_xCorrPrealignment.py @@ -47,7 +47,7 @@ class ProtImodXcorrPrealignment(ProtImodBase): _label = 'Coarse prealignment' _devStatus = BETA - _possibleOutputs = {"outputSetOfTiltSeries": tomoObj.SetOfTiltSeries} + _possibleOutputs = {"TiltSeries": tomoObj.SetOfTiltSeries} # -------------------------- DEFINE param functions ----------------------- def _defineParams(self, form): @@ -93,7 +93,8 @@ def _defineParams(self, form): 'bigger than 1') form.addParam('Trimming parameters', params.LabelParam, - label='Tilt axis angle detected from import. In case another value is desired please adjust the number below') + label='Tilt axis angle detected from import. In case another value is desired please adjust the ' + 'number below') form.addParam('tiltAxisAngle', params.FloatParam, @@ -106,41 +107,40 @@ def _defineParams(self, form): 'system with no axis inversions') trimming = form.addGroup('Trimming parameters', - expertLevel=params.LEVEL_ADVANCED) + expertLevel=params.LEVEL_ADVANCED) xtrimming = trimming.addLine('Horizontal: Number of pixels to avoid from the', - expertLevel=params.LEVEL_ADVANCED, - help="Starting and ending X coordinates of a region to correlate, " - "based on the position of the region at zero tilt.") + expertLevel=params.LEVEL_ADVANCED, + help="Starting and ending X coordinates of a region to correlate, " + "based on the position of the region at zero tilt.") xtrimming.addParam('xmin', - params.IntParam, - label='left', - allowsNull=True, - expertLevel=params.LEVEL_ADVANCED) + params.IntParam, + label='left', + allowsNull=True, + expertLevel=params.LEVEL_ADVANCED) xtrimming.addParam('xmax', - params.IntParam, - label='right', - allowsNull=True, - expertLevel=params.LEVEL_ADVANCED) + params.IntParam, + label='right', + allowsNull=True, + expertLevel=params.LEVEL_ADVANCED) ytrimming = trimming.addLine('Vertical: Number of pixels to avoid from the', - expertLevel=params.LEVEL_ADVANCED, - help="Starting and ending Y coordinates of a region to correlate.") + expertLevel=params.LEVEL_ADVANCED, + help="Starting and ending Y coordinates of a region to correlate.") ytrimming.addParam('ymin', - params.IntParam, - label='top', - allowsNull=True, - expertLevel=params.LEVEL_ADVANCED) + params.IntParam, + label='top', + allowsNull=True, + expertLevel=params.LEVEL_ADVANCED) ytrimming.addParam('ymax', - params.IntParam, - label='botton', - allowsNull=True, - expertLevel=params.LEVEL_ADVANCED) - + params.IntParam, + label='botton', + allowsNull=True, + expertLevel=params.LEVEL_ADVANCED) filtering = form.addGroup('Filtering parameters', expertLevel=params.LEVEL_ADVANCED) @@ -245,8 +245,6 @@ def computeXcorrStep(self, tsObjId): 'filterRadius2': self.filterRadius2.get() } - - argsXcorr = "-input %(input)s " \ "-output %(output)s " \ "-tiltfile %(tiltfile)s " \ @@ -269,11 +267,11 @@ def computeXcorrStep(self, tsObjId): if xmin is None: xmin = 0 if xmax is None: - xmax = xdim-1 + xmax = xdim - 1 if ymin is None: ymin = 0 if ymax is None: - ymax = ydim-1 + ymax = ydim - 1 argsXcorr += " -xminmax %i,%i " % (xmin, xmax) argsXcorr += " -yminmax %i,%i " % (ymin, ymax)