コード例 #1
0
    def _computeCTFDiscrepancy(self, method1, method2):
        #TODO must be same micrographs
        #move to a single step, each step takes 5 sec while the function takes 0.03 sec
        #convert to md
        md1 = MetaData()
        md2 = MetaData()

        for ctf1 in method1:  #reference CTF
            ctfId = ctf1.getObjId()
            self._ctfToMd(ctf1, md1)
            ctf2 = method2[ctfId]  #.target
            self._ctfToMd(ctf2, md2)
            key = ctfId
            self._freqResol[key] = xmipp.errorMaxFreqCTFs2D(md1, md2)
コード例 #2
0
    def _plotHistogram(self, param=None):
        md = MetaData()
        md.read(self.protocol._getFileName(FN_METADATA_HISTOGRAM))
        x_axis = []
        y_axis = []

        i = 0
        for idx in md:
            x_axis_ = md.getValue(MDL_X, idx)
            if i == 0:
                x0 = x_axis_
            elif i == 1:
                x1 = x_axis_
            y_axis_ = md.getValue(MDL_COUNT, idx)

            i += 1
            x_axis.append(x_axis_)
            y_axis.append(y_axis_)
        delta = x1 - x0
        fig = plt.figure()
        plt.bar(x_axis, y_axis, width=delta)
        plt.title("Resolutions Histogram")
        plt.xlabel("Resolution (A)")
        plt.ylabel("Counts")

        return [Plotter(figure2=fig)]
コード例 #3
0
    def _plotHistogram(self, fnhist, titlename, xname):
        md = MetaData()
        md.read(self.protocol._getPath('extra/' + fnhist))
        x_axis = []
        y_axis = []

        i = 0
        for idx in md:
            x_axis_ = md.getValue(MDL_X, idx)
            if i == 0:
                x0 = x_axis_
            elif i == 1:
                x1 = x_axis_
            y_axis_ = md.getValue(MDL_COUNT, idx)

            i += 1
            x_axis.append(x_axis_)
            y_axis.append(y_axis_)
        delta = x1 - x0
        plt.figure()
        plt.bar(x_axis, y_axis, width=delta)
        plt.title(titlename + "Histogram")
        plt.xlabel(xname + "(a.u.)")
        plt.ylabel("Counts")

        return plt.show()
コード例 #4
0
ファイル: dataimport.py プロジェクト: EyeSeeTea/scipion-web
    def importCoordinates(self, fileName, addCoordinate):
        if exists(fileName):
            ext = getExt(fileName)
            
            if ext == ".json":
                jsonPosDict = loadJson(fileName)
                
                if jsonPosDict.has_key("boxes"):
                    boxes = jsonPosDict["boxes"]

                    for box in boxes:
                        x, y = box[:2]
                        coord = Coordinate()
                        coord.setPosition(x, y)
                        addCoordinate(coord)
                        
            elif ext == ".box":
                md = MetaData()
                md.readPlain(fileName, "xcoor ycoor particleSize")
                size = md.getValue(MDL_PICKING_PARTICLE_SIZE, md.firstObject())
                if size is None:
                    print ">>> WARNING: Error parsing coordinate file: %s" % fileName
                    print "             Skipping this file."
                else:
                    half = size / 2
                    for objId in md:
                        x = md.getValue(MDL_XCOOR, objId)
                        y = md.getValue(MDL_YCOOR, objId)
                        coord = Coordinate()
                        coord.setPosition(x+half, y+half)
                        addCoordinate(coord)
            else:
                raise Exception('Unknown extension "%s" to import Eman coordinates' % ext)
コード例 #5
0
    def _plotHistogram(self, param=None):
        md = MetaData()
        md.read(self.protocol._getPath('extra/hist.xmd'))
        x_axis = []
        y_axis = []

        i = 0
        for idx in md:
            x_axis_ = md.getValue(MDL_X, idx)
            if i == 0:
                x0 = x_axis_
            elif i == 1:
                x1 = x_axis_
            y_axis_ = md.getValue(MDL_COUNT, idx)

            i += 1
            x_axis.append(x_axis_)
            y_axis.append(y_axis_)
        delta = x1 - x0
        plt.figure()
        plt.bar(x_axis, y_axis, width=delta)
        plt.title("Resolutions Histogram")
        plt.xlabel("Resolution (A)")
        plt.ylabel("Counts")

        return plt.show()
コード例 #6
0
    def getBoxSize(self, coordFile):
        """ Try to infer the box size from the given coordinate file.
        In the case of .box files, the size is the 3rd column
        In the case of .json files, we will look for file
        e2boxercache/base.json
        """
        if coordFile.endswith('.box'):
            md = MetaData()
            md.readPlain(coordFile, "xcoor ycoor particleSize")
            return md.getValue(MDL_PICKING_PARTICLE_SIZE, md.firstObject())

        elif coordFile.endswith('.json'):
            infoDir = pwutils.dirname(coordFile)
            # Still go one level up of info dir
            jsonBase = pwutils.join(pwutils.dirname(infoDir), 'e2boxercache',
                                    'base.json')
            jsonBase2 = pwutils.join(infoDir, 'project.json')
            if pwutils.exists(jsonBase):
                jsonDict = loadJson(jsonBase)
                if jsonDict.has_key('box_size'):
                    return int(jsonDict["box_size"])
            elif pwutils.exists(jsonBase2):
                jsonDict = loadJson(jsonBase2)
                if jsonDict.has_key('global.boxsize'):
                    return int(jsonDict["global.boxsize"])

        return None
コード例 #7
0
    def _computeCTFDiscrepancyStep(self, ctfId, method1, method2):
        #TODO must be same micrographs
        #convert to md
        mdList = [MetaData(), MetaData()]
        ctfList = [
            self.inputCTFs[method1].get()[ctfId],
            self.inputCTFs[method2].get()[ctfId]
        ]
        ctfRow = Row()

        for md, ctf in izip(mdList, ctfList):
            objId = md.addObject()
            convert.ctfModelToRow(ctf, ctfRow)
            convert.micrographToRow(ctf.getMicrograph(),
                                    ctfRow,
                                    alignType=convert.ALIGN_NONE)
            ctfRow.writeToMd(md, objId)
        self._freqResol[(method1, method2,
                         ctfId)] = xmipp.errorMaxFreqCTFs2D(*mdList)
コード例 #8
0
def readCoordinates(mic, fileName, coordsSet):
    if exists(fileName):
        md = MetaData()
        md.readPlain(fileName, 'xcoor ycoor')
        for objId in md:
            x = md.getValue(MDL_XCOOR, objId)
            y = md.getValue(MDL_YCOOR, objId)
            coord = Coordinate()
            coord.setPosition(x, y)
            coord.setMicrograph(mic)
            coordsSet.append(coord)
コード例 #9
0
 def importCoordinates(self, fileName, addCoordinate):
     print "In importCoordinates Appion with filename=%s" % fileName
     if exists(fileName):
         md = MetaData()
         md.readPlain(fileName, 'xcoor ycoor')
         for objId in md:
             x = md.getValue(MDL_XCOOR, objId)
             y = md.getValue(MDL_YCOOR, objId)
             coord = Coordinate()
             coord.setPosition(x, y)
             addCoordinate(coord)
コード例 #10
0
    def _computeCTFDiscrepancy(self, method1, method2):
        # TODO must be same micrographs
        # move to a single step, each step takes 5 sec while the function
        # takes 0.03 sec
        # convert to md
        md1 = MetaData()
        md2 = MetaData()

        for ctf1 in method1:  # reference CTF
            ctfId = ctf1.getObjId()
            if ctfId in self.processedDict:
                continue
            for ctf2 in method2:
                ctfId2 = ctf2.getObjId()
                if ctfId2 != ctfId:
                    continue
                self.processedDict.append(ctfId)
                self._ctfToMd(ctf1, md1)
                self._ctfToMd(ctf2, md2)
                self._freqResol[ctfId] = xmippLib.errorMaxFreqCTFs2D(md1, md2)
コード例 #11
0
    def plotAnisotropyResolution(self, path):
        md = MetaData(path)
        y = md.getColumnValues(MDL_COST)
        x = md.getColumnValues(MDL_RESOLUTION_SSNR)

        xmax = np.amax(x)
        xmin = np.amin(x)

        ymax = np.amax(y)
        ymin = np.amin(y)
        resstep = 0.5
        anistep = 0.1

        from math import floor, ceil
        xbin = floor((xmax - xmin) / resstep)
        ybin = ceil((ymax - ymin) / 0.05)

        print xbin, ybin

        from matplotlib.pyplot import contour, contourf
        plt.figure()
        #         plt.plot(x, y,'x')
        plt.title('resolution vs anisotropy')
        plt.xlabel("Resolution")
        plt.ylabel("Anisotropy")

        #         counts,ybins,xbins,image = plt.hist2d(x,y,bins=100)#)[xbin, ybin])
        img, xedges, yedges, imageAx = plt.hist2d(x,
                                                  y, (50, 50),
                                                  cmap=plt.cm.jet)
        plt.colorbar()
        plt.show()

        xplotter = XmippPlotter(x=1,
                                y=1,
                                mainTitle="aaaaa "
                                "along %s-axis." % self._getAxis())
        a = xplotter.createSubPlot("Slice ", '', '')
        matrix = img
        print matrix
        plot = xplotter.plotMatrix(a,
                                   matrix,
                                   0,
                                   200,
                                   cmap=self.getColorMap(),
                                   interpolation="nearest")
        xplotter.getColorBar(plot)
        print matrix

        return [xplotter]
コード例 #12
0
    def _plotCurve(self, a, fnDir, labelmd):
        print labelmd
        md = MetaData(fnDir)
        resolution = []
        radius = []
        for objId in md:
            resolution.append(md.getValue(labelmd, objId))
            radius.append(md.getValue(MDL_IDX, objId))
#         resolution_inv = [md.getValue(labelmd, objId) for objId in md]
#         frc = [md.getValue(MDL_IDX, objId) for objId in md]
        self.maxFrc = max(radius)
        self.minInv = min(resolution)
        self.maxInv = max(resolution)
        a.plot(radius, resolution, 'x')
コード例 #13
0
    def _plotHistogram(self, param=None):
        md = MetaData()
        md.read(self.protocol._getFileName(FN_METADATA_HISTOGRAM))
        x_axis = []
        y_axis = []

        for idx in md:
            x_axis_ = md.getValue(MDL_X, idx)
            y_axis_ = md.getValue(MDL_COUNT, idx)

            x_axis.append(x_axis_)
            y_axis.append(y_axis_)

        plotter = EmPlotter()
        plotter.createSubPlot("Resolutions Histogram", "Resolution (A)",
                              "# of Counts")
        barwidth = (x_axis[-1] - x_axis[0]) / len(x_axis)

        plotter.plotDataBar(x_axis, y_axis, barwidth)

        return [plotter]
コード例 #14
0
    def _showColorSlices(self, fileName, setrangelimits, titleFigure, lowlim,
                         highlim):
        imageFile = self.protocol._getExtraPath(fileName)
        img = ImageHandler().read(imageFile)
        imgData = img.getData()
        imgData2 = np.ma.masked_where(imgData < 0.001, imgData, copy=True)
        if setrangelimits is True:
            fig, im = self._plotVolumeSlices(titleFigure,
                                             imgData2,
                                             lowlim,
                                             highlim,
                                             self.getColorMap(),
                                             dataAxis=self._getAxis())
        else:
            md = MetaData()
            md.read(self.protocol._getExtraPath(OUTPUT_THRESHOLDS_FILE))
            idx = 1
            val1 = md.getValue(MDL_RESOLUTION_FREQ, idx)
            val2 = md.getValue(MDL_RESOLUTION_FREQ2, idx)

            if val1 >= val2:
                max_Res = val1 + 0.01
            else:
                max_Res = val2

#             max_Res = np.nanmax(imgData2)
            min_Res = np.nanmin(imgData2)
            fig, im = self._plotVolumeSlices(titleFigure,
                                             imgData2,
                                             min_Res,
                                             max_Res,
                                             self.getColorMap(),
                                             dataAxis=self._getAxis())
        cax = fig.add_axes([0.9, 0.1, 0.03, 0.8])
        cbar = fig.colorbar(im, cax=cax)
        cbar.ax.invert_yaxis()

        return plt.show(fig)