Ejemplo n.º 1
0
    def determine_resolution(self,
                             even,
                             odd,
                             criterion,
                             numberBands,
                             mask,
                             verbose=False):
        """For the master node, determine the resolution.
        """
        from pytom.basic.correlation import FSC, determineResolution

        if not numberBands:
            numberBands = even.sizeX() / 2

        fsc = FSC(even, odd, numberBands, mask, verbose=False)
        if verbose:
            print(self.node_name + ': FSC: ' + str(fsc))

        return determineResolution(fsc, criterion, verbose=False)
Ejemplo n.º 2
0
    def determine_resolution(self,
                             even,
                             odd,
                             criterion,
                             numberBands,
                             mask,
                             verbose=False):
        """For the master node, determine the resolution.
           @param even: particle list even
           @type even: L{pytom.basic.structures.ParticleList}
           @param odd: particle list odd
           @type odd: L{pytom.basic.structures.ParticleList}
        """
        from pytom.basic.correlation import FSC, determineResolution

        if not numberBands:
            numberBands = even.sizeX() / 2

        fsc = FSC(even, odd, numberBands, mask, verbose=False)
        if verbose:
            print(self.node_name + ': FSC: ' + str(fsc))

        return determineResolution(fsc, criterion, verbose=False)
Ejemplo n.º 3
0
def calculate_averages(pl, binning, mask, outdir='./'):
    """
    calcuate averages for particle lists
    @param pl: particle list
    @type pl: L{pytom.basic.structures.ParticleList}
    @param binning: binning factor
    @type binning: C{int}

    last change: Jan 18 2020: error message for too few processes, FF
    """
    import os
    from pytom_volume import complexDiv, vol, pasteCenter
    from pytom.basic.fourier import fft, ifft
    from pytom.basic.correlation import FSC, determineResolution
    from pytom_fftplan import fftShift
    from pytom_volume import reducedToFull

    pls = pl.copy().splitByClass()
    res = {}
    freqs = {}
    wedgeSum = {}

    for pp in pls:
        # ignore the -1 class, which is used for storing the trash class
        class_label = pp[0].getClass()
        if class_label != '-1':
            assert len(pp) > 3
            if len(pp) >= 4 * mpi.size:
                spp = mpi._split_seq(pp, mpi.size)
            else:  # not enough particle to do averaging on one node
                spp = [None] * 2
                spp[0] = pp[:len(pp) // 2]
                spp[1] = pp[len(pp) // 2:]

            args = list(
                zip(spp, [True] * len(spp), [binning] * len(spp),
                    [False] * len(spp), [outdir] * len(spp)))
            avgs = mpi.parfor(paverage, args)

            even_a, even_w, odd_a, odd_w = None, None, None, None
            even_avgs = avgs[1::2]
            odd_avgs = avgs[::2]

            for a, w in even_avgs:
                if even_a is None:
                    even_a = a.getVolume()
                    even_w = w.getVolume()
                else:
                    even_a += a.getVolume()
                    even_w += w.getVolume()
                os.remove(a.getFilename())
                os.remove(w.getFilename())

            for a, w in odd_avgs:
                if odd_a is None:
                    odd_a = a.getVolume()
                    odd_w = w.getVolume()
                else:
                    odd_a += a.getVolume()
                    odd_w += w.getVolume()
                os.remove(a.getFilename())
                os.remove(w.getFilename())

            # determine the resolution
            # raise error message in case even_a == None - only one processor used
            if even_a == None:
                from pytom.basic.exceptions import ParameterError
                raise ParameterError(
                    'cannot split odd / even. Likely you used only one processor - use: mpirun -np 2 (or higher!)?!'
                )

            if mask and mask.__class__ == str:
                from pytom_volume import read, pasteCenter, vol

                maskBin = read(mask, 0, 0, 0, 0, 0, 0, 0, 0, 0, binning,
                               binning, binning)
                if even_a.sizeX() != maskBin.sizeX() or even_a.sizeY(
                ) != maskBin.sizeY() or even_a.sizeZ() != maskBin.sizeZ():
                    mask = vol(even_a.sizeX(), even_a.sizeY(), even_a.sizeZ())
                    mask.setAll(0)
                    pasteCenter(maskBin, mask)
                else:
                    mask = maskBin

            fsc = FSC(even_a, odd_a, int(even_a.sizeX() // 2), mask)
            band = determineResolution(fsc, 0.5)[1]

            aa = even_a + odd_a
            ww = even_w + odd_w
            fa = fft(aa)
            r = complexDiv(fa, ww)
            rr = ifft(r)
            rr.shiftscale(0.0, 1. / (rr.sizeX() * rr.sizeY() * rr.sizeZ()))

            res[class_label] = rr
            freqs[class_label] = band

            ww2 = reducedToFull(ww)
            fftShift(ww2, True)
            wedgeSum[class_label] = ww2
    print('done')
    return res, freqs, wedgeSum
Ejemplo n.º 4
0
        if not numberBands:
            numberBands = int(v1.sizeX() // 2)

        f = FSC(v1, v2, numberBands, mask, verbose)
        #f = [1, 0.9999816330959427, 0.9998727543638058, 0.9986706311763134, 0.9967503089610698, 0.9945473896086455, 0.9953391452631559, 0.9926167503040506, 0.9886499997836082, 0.9846988786130074, 0.9850170987613799, 0.9849222409268831, 0.9820779872082366, 0.981161445747785, 0.978102618561267, 0.9749670311874213, 0.9710488103484851, 0.9686564997495193, 0.9643854526532541, 0.9621314730670771, 0.9568606791204185, 0.9488084842261655, 0.9416015322427522, 0.9316703960630233, 0.9106972097966776, 0.8912878863048055, 0.8795187076235272, 0.8713474813842144, 0.8508750246010772, 0.8195820950483931, 0.8065990902773463, 0.7823660922709397, 0.7521861621134768, 0.7236765089946452, 0.6967229052025852, 0.6815563485825349, 0.6606856188994277, 0.6513326589007892, 0.6340321380485363, 0.6057709663336085, 0.584793117868313, 0.5612341962238455, 0.5623548376402193, 0.5564192235463952, 0.5397585867441497, 0.5089376925831242, 0.4647300273454635, 0.4310334881504598, 0.41741429413879966, 0.4195952490948154, 0.4066609275881065, 0.37019375197265786, 0.31936001816491055, 0.275903152373691, 0.2538399661514517, 0.24197349348826183, 0.20730706794873432, 0.1823204187105925, 0.17041895753522998, 0.16153106667416953, 0.13872290716093824, 0.12428131231796732, 0.09594749780671366, 0.09281895056407187, 0.0950512406930502, 0.07845013400157819, 0.06778918720241832, 0.05699422426625805, 0.04004787096713291, 0.035285330785697615, 0.02761223114687527, 0.029854265039150632, 0.030802679570736933, 0.02855574408867763, 0.04062783248396335, 0.046982827702621556, 0.044667285930674615, 0.03327190294513204, 0.028879433147898908, 0.019113096081122542, 0.018889519864393182, 0.03363102079214279, 0.030416314115916717, 0.015045702588444513, 0.007700419599421394, 0.013662921155622407, 0.02549288977161008, 0.01648898979277964, 0.004577992397744576, 0.003687537468279412, 0.015624522796941348, 0.012150048589636583, 0.013236997547964386, 0.024818980351894827, 0.017881736272355488, 0.008875703095090339, 0.004009836930167128, 0.005169522148403328, 0.013778610598594218, 0.024255111798589142]

        if verbose: print('FSC:\n', f)

        import pytom.tompy.correlation as correlation
        from pytom_numpy import vol2npy
        import numpy as np
        from pytom.tompy.io import write
        if randomize is None:
            for (ii, fscel) in enumerate(f):
                f[ii] = 2. * fscel / (1. + fscel)
            r = determineResolution(f, fscCriterion, verbose)
        else:
            randomizationFrequency = np.floor(
                determineResolution(np.array(f), randomize, verbose)[1])
            oddVolumeRandomizedPhase = correlation.randomizePhaseBeyondFreq(
                vol2npy(v1), randomizationFrequency)
            evenVolumeRandomizedPhase = correlation.randomizePhaseBeyondFreq(
                vol2npy(v2), randomizationFrequency)
            write(os.path.join(outdir, 'randOdd.mrc'),
                  oddVolumeRandomizedPhase)
            write(os.path.join(outdir, 'randEven.mrc'),
                  evenVolumeRandomizedPhase)
            oddVolumeRandomizedPhase = read(os.path.join(
                outdir, 'randOdd.mrc'))
            evenVolumeRandomizedPhase = read(
                os.path.join(outdir, 'randEven.mrc'))