Skip to content

Commit

Permalink
Merge pull request #226 from scipion-em/oddevenfixes
Browse files Browse the repository at this point in the history
Oddevenfixes
  • Loading branch information
fede-pe authored Nov 29, 2023
2 parents fb9429f + 0a3e0a0 commit 4c004a6
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 39 deletions.
9 changes: 8 additions & 1 deletion CHANGES.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
- add missing taper arg for newstack
22 changes: 17 additions & 5 deletions imod/protocols/protocol_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def wrapper(self, tsId, *args):
return wrapper

def convertInputStep(self, tsObjId, generateAngleFile=True,
imodInterpolation=True, doSwap=False):
imodInterpolation=True, doSwap=False, oddEven=False):
"""
:param tsObjId: Tilt series identifier
Expand Down Expand Up @@ -140,18 +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:
fnOdd = ts.getOddFileName()
fnEven = ts.getEvenFileName()

outputOddTsFileName = os.path.join(tmpPrefix, tsId+EXT_MRCS_TS_EVEN_NAME)
outputEvenTsFileName = os.path.join(tmpPrefix, tsId+EXT_MRCS_TS_ODD_NAME)
applyNewStack(outputOddTsFileName, fnOdd)
applyNewStack(outputEvenTsFileName, fnEven)

else:
self.info("Linking tilt series %s" % tsId)
Expand Down
13 changes: 8 additions & 5 deletions imod/protocols/protocol_tomoReconstruction.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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)
oddEvenFlag = False
if self.inputSetOfTiltSeries.get().hasOddEven():
oddEvenFlag = True
super().convertInputStep(tsObjId, doSwap=True, oddEven=oddEvenFlag)

@ProtImodBase.tryExceptDecorator
def computeReconstructionStep(self, tsObjId):
Expand Down Expand Up @@ -244,13 +247,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]
Expand Down
56 changes: 28 additions & 28 deletions imod/protocols/protocol_xCorrPrealignment.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class ProtImodXcorrPrealignment(ProtImodBase):

_label = 'Coarse prealignment'
_devStatus = BETA
_possibleOutputs = {"TiltSeries": tomoObj.SetOfTiltSeries}

# -------------------------- DEFINE param functions -----------------------
def _defineParams(self, form):
Expand Down Expand Up @@ -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 '
Expand All @@ -91,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,
Expand All @@ -104,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)
Expand Down Expand Up @@ -243,8 +245,6 @@ def computeXcorrStep(self, tsObjId):
'filterRadius2': self.filterRadius2.get()
}



argsXcorr = "-input %(input)s " \
"-output %(output)s " \
"-tiltfile %(tiltfile)s " \
Expand All @@ -267,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)
Expand Down

0 comments on commit 4c004a6

Please sign in to comment.