Beispiel #1
0
	def __init__(self):
		EMImage2DWidget.__init__(self)
		# the single image display widget
		self.datatodisp=[test_image(1),test_image(2)]

		self.curdata=0
		self.set_data(self.datatodisp[0])
	
		timer = QtCore.QTimer(self)
		self.connect(timer,QtCore.SIGNAL("timeout()"),self.mytimeout)
		timer.start(1000)
Beispiel #2
0
    def object_picked(self, object_number):
        if object_number == self.current_projection: return
        self.current_projection = object_number
        resize_necessary = False
        if self.mx_display == None:
            self.mx_display = EMImage2DWidget()
            #			self.mx_display = EMImageMXWidget()
            QtCore.QObject.connect(self.mx_display,
                                   QtCore.SIGNAL("module_closed"),
                                   self.on_mx_display_closed)
            resize_necessary = True

        if self.frc_display == None:
            self.frc_display = EMPlot2DWidget()
#			QtCore.QObject.connect(self.frc_display,QtCore.SIGNAL("module_closed"),self.on_frc_display_closed)

        self.update_display(False)

        if resize_necessary:
            get_application().show_specific(self.mx_display)
            self.mx_display.optimally_resize()
            get_application().show_specific(self.frc_display)


#			self.frc_display.optimally_resize()
        else:
            self.mx_display.updateGL()
            self.frc_display.updateGL()

        if object_number != self.special_euler:
            self.special_euler = object_number
            self.regen_dl()
Beispiel #3
0
    def __init__(self, application, options, datafile=None):
        QtGui.QWidget.__init__(self)
        self.imgview = EMImage2DWidget()
        self.setCentralWidget(QtGui.QWidget())
        self.gbl = QtGui.QGridLayout(self.centralWidget())

        self.gbl.addWidget(self.imgview, 0, 0)
        self.options = options
        self.app = weakref.ref(application)

        self.datafile = datafile
        self.imgview.set_data(datafile)

        #self.all_shapes=[]
        #self.all_points=[]
        pts = []
        if options.load:
            pts = np.loadtxt(options.load).tolist()

        self.contour = Contour(img=self.imgview, points=pts)
        self.shape_index = 0
        self.imgview.shapes = {0: self.contour}

        QtCore.QObject.connect(self.imgview, QtCore.SIGNAL("mouseup"),
                               self.mouseup)
        QtCore.QObject.connect(self.imgview, QtCore.SIGNAL("keypress"),
                               self.key_press)

        glEnable(GL_POINT_SMOOTH)
        glEnable(GL_LINE_SMOOTH)
        glEnable(GL_POLYGON_SMOOTH)
        glEnable(GL_BLEND)
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
Beispiel #4
0
    def __init__(self, application, options, datafile, pks, xfs, dirs):
        QtGui.QWidget.__init__(self)
        self.imgview = EMImage2DWidget()
        self.setCentralWidget(QtGui.QWidget())
        self.gbl = QtGui.QGridLayout(self.centralWidget())

        self.gbl.addWidget(self.imgview, 0, 0)
        self.options = options
        self.app = weakref.ref(application)

        self.datafile = datafile
        self.imgview.set_data(datafile)

        #self.all_shapes=[]
        #self.all_points=[]

        self.boxes = Boxes(self.imgview, pks, xfs, dirs)
        self.shape_index = 0
        self.imgview.shapes = {0: self.boxes}

        glEnable(GL_POINT_SMOOTH)
        glEnable(GL_LINE_SMOOTH)
        glEnable(GL_POLYGON_SMOOTH)
        glEnable(GL_BLEND)
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
Beispiel #5
0
    def __init__(self, mode=0, cs=0., twod=False):
        QtGui.QMainWindow.__init__(self)

        if twod:
            self.twodview = EMImage2DWidget()
            widget = Microscope(self, None, None, self.twodview, mode, cs)
        else:
            self.imgview = EMImage2DWidget()
            self.pltview = EMPlot2DWidget()
            widget = Microscope(self, self.imgview, self.pltview, None, mode,
                                cs)
            #widget = Microscope(self, None, None, None, mode, cs)

        #widget = Microscope(self, None, None)
        self.closeEvent = widget.closeEvent
        self.setCentralWidget(widget)
Beispiel #6
0
    def __init__(self, application, options, datafile=None):
        QtGui.QWidget.__init__(self)
        self.imgview = EMImage2DWidget()
        self.setCentralWidget(QtGui.QWidget())
        self.gbl = QtGui.QGridLayout(self.centralWidget())

        self.gbl.addWidget(self.imgview, 0, 0)
        self.options = options
        self.app = weakref.ref(application)

        self.datafile = datafile
        self.imgview.set_data(datafile)

        self.shape = [0] * 6
        self.all_shapes = []
        self.state = 0
        self.shape_index = 0
        self.origin = [0, 0]
        self.imgview.shapes = {}

        print("imgnum,x,y,major,minor,angle")

        QtCore.QObject.connect(self.imgview, QtCore.SIGNAL("mouseup"),
                               self.mouseup)
        QtCore.QObject.connect(self.imgview, QtCore.SIGNAL("mousemove"),
                               self.mousemv)
Beispiel #7
0
    def __init__(self, img, app):
        EMImage2DWidget.__init__(self, img, application=app)

        self.sx = img["nx"]
        self.sy = img["ny"]
        self.set_scale(.3)

        minxy = min(self.sx, self.sy)
        self.bar_len = minxy * .1
        self.bar_ypos = -self.sy * .2
        self.bar_thick = 20
        self.bar_xpos = self.sx / 2
        self.bar = EMShape()
        self.barspeed = 0.02 * minxy

        self.score = 0
        self.score_label = EMShape()

        self.ball = EMShape()
        self.ball_rad = 20
        self.ball_pos = np.array(
            [self.bar_xpos, self.bar_ypos + self.bar_thick + self.ball_rad])
        self.ball_speed = minxy * .01
        self.set_shapes({0: self.bar, 1: self.ball, 2: self.score_label})

        self.game_started = False

        self.data.mult(-1)
        #self.data.process_inplace("filter.lowpass.gauss",{"cutoff_abs":.05})
        #self.data.process_inplace("normalize")
        #self.data.process_inplace("threshold.belowtozero",{"minval":1})
        #print self.data["mean_nonzero"],self.sx,self.sy
        self.data.div(self.data["mean_nonzero"] * self.sx * self.sy)
        self.data.mult(1000)
        self.auto_contrast()
        self.data_grad = self.data.process("math.gradient.direction")
        self.del_msk = self.data.copy()
        self.del_msk.to_one()

        self.update_bar()
        self.update_score()
        self.update_ball()
        print "break bricks.."
Beispiel #8
0
	def __init__(self,img, app):
		EMImage2DWidget.__init__(self,img,application=app)
		
		self.sx=img["nx"]
		self.sy=img["ny"]
		self.set_scale(.3)
		
		minxy=min(self.sx, self.sy)
		self.bar_len=minxy*.1
		self.bar_ypos=-self.sy*.2
		self.bar_thick=20
		self.bar_xpos=self.sx/2
		self.bar=EMShape()
		self.barspeed=0.02*minxy
		
		self.score=0
		self.score_label=EMShape()
		
		
		self.ball=EMShape()
		self.ball_rad=20
		self.ball_pos=np.array([self.bar_xpos, self.bar_ypos+self.bar_thick+self.ball_rad])
		self.ball_speed=minxy*.01		
		self.set_shapes({0:self.bar, 1:self.ball,2:self.score_label})
		
		self.game_started=False
		
		self.data.mult(-1)
		self.data.process_inplace("filter.lowpass.gauss",{"cutoff_abs":.05})
		self.data.process_inplace("normalize")
		self.data.process_inplace("threshold.belowtozero",{"minval":1})
		self.data.div(self.data["mean"]*self.sx*self.sy)
		self.data.mult(1000)
		self.auto_contrast()
		self.data_grad=self.data.process("math.gradient.direction")
		self.del_msk=self.data.copy()
		self.del_msk.to_one()
		
		self.update_bar()
		self.update_score()
		self.update_ball()
		print "break bricks.."
Beispiel #9
0
	def __init__(self,app):
		# the single image display widget
		self.im2d = EMImage2DWidget(application=app)
	
		# get some signals from the window.
		QtCore.QObject.connect(self.im2d,QtCore.SIGNAL("mousedown"),self.down)
		QtCore.QObject.connedisplaydemo.pyct(self.im2d,QtCore.SIGNAL("mousedrag"),self.drag)
		QtCore.QObject.connect(self.im2d,QtCore.SIGNAL("mouseup"),self.up)
	
		#self explanatory
		a=test_image(size=(512,512))
		self.im2d.set_data(a)
		self.im2d.show()
Beispiel #10
0
	def __init__(self, rctwidget, name):
		self.name = name
		self.filename = None
		self.rctwidget = rctwidget
		self.window = EMImage2DWidget(application=self.rctwidget.parent_window)
		self.boxes = EMBoxList()
		self.window.set_mouse_mode(0)
		self.connect_signals()
		self.moving = None
		self.data = None
		self.win_xsize = 0
		self.win_ysize = 0
		self.slow = False
		self.masktype = "None"
Beispiel #11
0
def display_validation_plots(path,
                             radcut,
                             planethres,
                             plotdatalabels=False,
                             color='#00ff00',
                             plotzaxiscolor=False):
    from emimage2d import EMImage2DWidget
    from emapplication import EMApp
    r = []
    theta = []
    datap = []
    zaxis = []

    try:
        tpdb = js_open_dict("%s/perparticletilts.json" % path)
        tplist = tpdb["particletilt_list"]
        maxcolorval = max(tplist, key=lambda x: x[3])[3]

        for tp in tplist:
            if tp[3] > planethres:  # if the out of plane threshold is too much
                continue
            if plotdatalabels: datap.append(tp[0])
            r.append(tp[1])
            theta.append(math.radians(tp[2]))
            # Color the Z axis out of planeness
            zaxis.append(computeRGBcolor(tp[3], 0, maxcolorval))
        tpdb.close()
    except:
        print "Couldn't load tp from DB, not showing polar plot"
    data = None
    try:
        data = EMData("%s/contour.hdf" % path)
    except:
        print "Couldn't open contour plot"

    if not data and not (theta and r): return
    app = EMApp()
    if theta and r:
        plot = EMValidationPlot()
        plot.set_data((theta, r), 50, radcut, datap)
        # Color by Z axis if desired
        if plotzaxiscolor: plot.set_scattercolor([zaxis])
        plot.set_datalabelscolor(color)
        plot.show()
    if data:
        image = EMImage2DWidget(data)
        image.show()
    app.exec_()
Beispiel #12
0
    def __init__(self, application, data):
        """Implements the CTF fitting dialog using various EMImage and EMPlot2D widgets
		'data' is a list of (filename,ctf,im_1d,bg_1d,im_2d,bg_2d)
		"""
        try:
            from emimage2d import EMImage2DWidget
        except:
            print "Cannot import EMAN image GUI objects (EMImage2DWidget)"
            sys.exit(1)
        try:
            from emplot2d import EMPlot2DWidget
        except:
            print "Cannot import EMAN plot GUI objects (is matplotlib installed?)"
            sys.exit(1)

        self.app = weakref.ref(application)

        QtGui.QWidget.__init__(self, None)
        self.setWindowIcon(QtGui.QIcon(get_image_directory() + "ctf.png"))

        self.data = data
        self.curset = 0
        self.plotmode = 0

        self.guiim = EMImage2DWidget(application=self.app())
        self.guiplot = EMPlot2DWidget(application=self.app())

        self.guiim.connect(self.guiim, QtCore.SIGNAL("mousedown"),
                           self.imgmousedown)
        self.guiim.connect(self.guiim, QtCore.SIGNAL("mousedrag"),
                           self.imgmousedrag)
        self.guiim.connect(self.guiim, QtCore.SIGNAL("mouseup"),
                           self.imgmouseup)
        self.guiplot.connect(self.guiplot, QtCore.SIGNAL("mousedown"),
                             self.plotmousedown)

        self.guiim.mmode = "app"

        # This object is itself a widget we need to set up
        self.hbl = QtGui.QHBoxLayout(self)
        self.hbl.setMargin(0)
        self.hbl.setSpacing(6)
        self.hbl.setObjectName("hbl")

        # plot list and plot mode combobox
        self.vbl2 = QtGui.QVBoxLayout()
        self.setlist = QtGui.QListWidget(self)
        self.setlist.setSizePolicy(QtGui.QSizePolicy.Preferred,
                                   QtGui.QSizePolicy.Expanding)
        self.vbl2.addWidget(self.setlist)

        self.splotmode = QtGui.QComboBox(self)
        self.splotmode.addItem("Bgsub & fit")
        self.splotmode.addItem("Ptcl & BG power")
        self.splotmode.addItem("SNR")
        self.splotmode.addItem("Smoothed SNR")
        self.splotmode.addItem("Integrated SNR")
        self.splotmode.addItem("Total CTF")
        self.vbl2.addWidget(self.splotmode)
        self.hbl.addLayout(self.vbl2)

        # ValSliders for CTF parameters
        self.vbl = QtGui.QVBoxLayout()
        self.vbl.setMargin(0)
        self.vbl.setSpacing(6)
        self.vbl.setObjectName("vbl")
        self.hbl.addLayout(self.vbl)

        #self.samp = ValSlider(self,(0,5.0),"Amp:",0)
        #self.vbl.addWidget(self.samp)

        self.sdefocus = ValSlider(self, (0, 5), "Defocus:", 0, 90)
        self.vbl.addWidget(self.sdefocus)

        self.sbfactor = ValSlider(self, (0, 1600), "B factor:", 0, 90)
        self.vbl.addWidget(self.sbfactor)

        self.sampcont = ValSlider(self, (0, 100), "% AC", 0, 90)
        self.vbl.addWidget(self.sampcont)

        #		self.sapix=ValSlider(self,(.2,10),"A/Pix:",2,90)
        #		self.vbl.addWidget(self.sapix)

        self.svoltage = ValSlider(self, (0, 500), "Voltage (kV):", 0, 90)
        self.vbl.addWidget(self.svoltage)

        self.scs = ValSlider(self, (0, 5), "Cs (mm):", 0, 90)
        self.vbl.addWidget(self.scs)
        self.hbl_buttons = QtGui.QHBoxLayout()
        self.saveparms = QtGui.QPushButton("Save parms")
        self.recallparms = QtGui.QPushButton("Recall")
        self.output = QtGui.QPushButton("Output")
        self.hbl_buttons.addWidget(self.saveparms)
        self.hbl_buttons.addWidget(self.recallparms)
        self.hbl_buttons2 = QtGui.QHBoxLayout()
        self.hbl_buttons2.addWidget(self.output)
        self.vbl.addLayout(self.hbl_buttons)
        self.vbl.addLayout(self.hbl_buttons2)

        QtCore.QObject.connect(self.sdefocus, QtCore.SIGNAL("valueChanged"),
                               self.newCTF)
        QtCore.QObject.connect(self.sbfactor, QtCore.SIGNAL("valueChanged"),
                               self.newCTF)
        #		QtCore.QObject.connect(self.sapix, QtCore.SIGNAL("valueChanged"), self.newCTF)
        QtCore.QObject.connect(self.sampcont, QtCore.SIGNAL("valueChanged"),
                               self.newCTF)
        QtCore.QObject.connect(self.svoltage, QtCore.SIGNAL("valueChanged"),
                               self.newCTF)
        QtCore.QObject.connect(self.scs, QtCore.SIGNAL("valueChanged"),
                               self.newCTF)
        QtCore.QObject.connect(self.setlist,
                               QtCore.SIGNAL("currentRowChanged(int)"),
                               self.newSet)
        QtCore.QObject.connect(self.splotmode,
                               QtCore.SIGNAL("currentIndexChanged(int)"),
                               self.newPlotMode)

        QtCore.QObject.connect(self.saveparms, QtCore.SIGNAL("clicked(bool)"),
                               self.on_save_params)
        QtCore.QObject.connect(self.recallparms,
                               QtCore.SIGNAL("clicked(bool)"),
                               self.on_recall_params)
        QtCore.QObject.connect(self.output, QtCore.SIGNAL("clicked(bool)"),
                               self.on_output)

        self.update_data()

        self.update_data()
        self.resize(
            460, 380
        )  # figured these values out by printing the width and height in resize event
        self.setWindowTitle("CTF")
Beispiel #13
0
    def __new__(cls,
                filename,
                application,
                force_plot=False,
                force_2d=False,
                old=None):

        file_type = Util.get_filename_ext(filename)
        em_file_type = EMUtil.get_image_ext_type(file_type)
        if not file_exists(filename): return None

        if force_plot and force_2d:
            # ok this sucks but it suffices for the time being
            print(
                "Error, the force_plot and force_2d options are mutually exclusive"
            )
            return None

        if force_plot:
            from emplot2d import EMPlot2DWidget
            if isinstance(old, EMPlot2DWidget): widget = old
            else: widget = EMPlot2DWidget(application=application)
            widget.set_data_from_file(filename)
            return widget

        if em_file_type != IMAGE_UNKNOWN or filename[:4] == "bdb:":
            n = EMUtil.get_image_count(filename)
            nx, ny, nz = gimme_image_dimensions3D(filename)
            if n > 1 and nz == 1:
                if force_2d:
                    a = EMData()
                    data = a.read_images(filename)
                else:
                    data = None  # This is like a flag - the ImageMXWidget only needs the file name
            elif nz == 1:
                data = [EMData(filename, 0)]
            else:
                data = EMData()
                data.read_image(
                    filename, 0, not force_2d
                )  # This should be 3-D. We read the header-only here
                data = [data]

            if data != None and len(data) == 1: data = data[0]

            if force_2d or isinstance(data, EMData) and data.get_zsize() == 1:
                if isinstance(data, list) or data.get_ysize() != 1:
                    from emimage2d import EMImage2DWidget
                    if isinstance(old, EMImage2DWidget): widget = old
                    else: widget = EMImage2DWidget(application=application)
                else:
                    from emplot2d import EMPlot2DWidget
                    if isinstance(old, EMPlot2DWidget): widget = old
                    else: widget = EMPlot2DWidget(application=application)
                    widget.set_data_from_file(filename)
                    return widget
            elif isinstance(data, EMData):
                if isinstance(old, EMScene3D): widget = old
                else: widget = EMScene3D()
                #				print n,data
                for ii in xrange(n):
                    data = EMData(filename, ii)
                    datai = EMDataItem3D(data, transform=Transform())
                    widget.insertNewNode(os.path.basename(filename),
                                         datai,
                                         parentnode=widget)
                    isosurface = EMIsosurface(datai, transform=Transform())
                    widget.insertNewNode("Iso", isosurface, parentnode=datai)
                return widget

            elif data == None or isinstance(data, list):
                from emimagemx import EMImageMXWidget
                if isinstance(old, EMImageMXWidget): widget = old
                else: widget = EMImageMXWidget(application=application)
                data = filename
            else:
                print(filename)
                raise  # weirdness, this should never happen
            widget.set_data(data, filename)
            return widget
        else:
            from emplot2d import EMPlot2DWidget
            if isinstance(old, EMPlot2DWidget): widget = old
            else: widget = EMPlot2DWidget(application=application)
            widget.set_data_from_file(filename)
            return widget
Beispiel #14
0
	def au_point_selected(self,i,event=None):
		if self.readfrom:
			return
		if i == None:
			if event != None and event.modifiers()&Qt.ShiftModifier:
				if self.special_euler != None:
					self.special_euler = None
					if not self.init_lock:self.regen_dl()
			return
#		self.arc_anim_points = None
		self.projection = None
		if self.euler_data:
#			db = db_open_dict(self.average_file)
#			a = db.get(i)
#			print a["nx"]
#			print self.average_file,i
#			self.average = EMData(self.average_file,i)
#			self.average["nx"]
			self.average = self.euler_data[i]#
			self.projection = EMData(self.projection_file,self.average.get_attr("projection_image_idx"))
			self.average.process_inplace("normalize.toimage",{"to":self.projection})
			try:
				self.class_idx = self.average.get_attr("projection_image_idx")
				print("%d (%d)"%(self.class_idx,self.average["ptcl_repr"]))
			except:
				self.class_idx = -1
		else: return

		#if self.projection  == None and self.average == None: return
		first = False
		if self.proj_class_viewer == None:
			first = True
			self.proj_class_viewer = EMImageMXWidget(data=None,application=get_application())
#			self.proj_class_viewer = EMImage2DWidget(image=None,application=get_application())
			QtCore.QObject.connect(self.proj_class_viewer,QtCore.SIGNAL("module_closed"),self.on_mx_view_closed)
#			self.proj_class_viewer.set_mouse_mode("App" )
			QtCore.QObject.connect(self.proj_class_viewer,QtCore.SIGNAL("mx_image_selected"), self.mx_image_selected)
			get_application().show_specific(self.proj_class_viewer)

			self.proj_class_single = EMImage2DWidget(image=None,application=get_application())
			QtCore.QObject.connect(self.proj_class_single,QtCore.SIGNAL("module_closed"),self.on_mx_view_closed)
#			QtCore.QObject.connect(self.proj_class_single,QtCore.SIGNAL("mx_image_selected"), self.mx_image_selected)
			get_application().show_specific(self.proj_class_single)

		disp = []
		if self.projection != None: disp.append(self.projection)
		if self.average != None and self.projection!=None:
			# ok, this really should be put into its own processor
			#dataf = self.projection.do_fft()
			#apix=self.projection["apix_x"]
			#curve = dataf.calc_radial_dist(dataf["ny"], 0, 0.5,True)
			#curve=[i/(dataf["nx"]*dataf["ny"])**2 for i in curve]
			#xcurve=[i/(apix*2.0*dataf["ny"]) for i in range(len(curve))]
			#xyd=XYData()
			#xyd.set_xy_list(xcurve,curve)
			#filt=self.average.process("filter.setstrucfac",{"apix":apix,"strucfac":xyd})
			#filt.process_inplace("normalize.toimage",{"to":self.average})
			self.projection["apix_x"]=self.average["apix_x"]
			self.projection["apix_y"]=self.average["apix_y"]
			self.projection["apix_z"]=self.average["apix_z"]
			filt=self.projection.process("threshold.notzero")
			filt.mult(self.average)
			filt.process_inplace("filter.matchto",{"to":self.projection})

			disp.append(filt)

		if self.average!=None:
			disp.append(self.average)

		self.proj_class_viewer.set_data(disp)
		self.proj_class_single.set_data(disp)

		self.proj_class_viewer.updateGL()
		self.proj_class_single.updateGL()
		if self.particle_viewer != None:
			self.mx_image_selected(None,None)
		if first: self.proj_class_viewer.optimally_resize()

		if i != self.special_euler:
			self.special_euler = i
			self.force_update = True

		if not self.init_lock: self.updateGL()
Beispiel #15
0
    def setData(self, data):
        if data == None:
            self.data = None
            return

        elif isinstance(data, str):
            self.datafile = data
            self.nimg = EMUtil.get_image_count(data)

            self.origdata = EMData(data, 0)

            if self.origdata["nz"] == 1:
                if self.nimg > 20:
                    self.origdata = EMData.read_images(
                        data, range(0, self.nimg, self.nimg / 20)
                    )  # read regularly separated images from the file totalling ~20
                elif self.nimg > 1:
                    self.origdata = EMData.read_images(data, range(self.nimg))
                else:
                    self.origdata = [self.origdata]
            else:
                self.origdata = [self.origdata]

        else:
            self.datafile = None
            if isinstance(data, EMData): self.origdata = [data]
            else: self.origdata = data

        self.nx = self.origdata[0]["nx"]
        self.ny = self.origdata[0]["ny"]
        self.nz = self.origdata[0]["nz"]
        if self.apix <= 0.0: self.apix = self.origdata[0]["apix_x"]
        EMProcessorWidget.parmdefault["apix"] = (0, (0.2, 10.0), self.apix,
                                                 None)

        origfft = self.origdata[0].do_fft()
        self.pspecorig = origfft.calc_radial_dist(self.ny / 2, 0.0, 1.0, 1)
        ds = 1.0 / (self.apix * self.ny)
        self.pspecs = [ds * i for i in range(len(self.pspecorig))]

        if self.viewer != None:
            for v in self.viewer:
                v.close()

        if self.nz == 1 or self.force2d:
            if len(self.origdata) > 1:
                self.viewer = [EMImageMXWidget()]
                self.mfile_save_stack.setEnabled(True)
                self.mfile_save_map.setEnabled(False)
            else:
                self.viewer = [EMImage2DWidget()]
                self.mfile_save_stack.setEnabled(False)
                self.mfile_save_map.setEnabled(True)
        else:
            self.mfile_save_stack.setEnabled(False)
            self.mfile_save_map.setEnabled(True)
            self.viewer = [EMScene3D()]
            self.sgdata = EMDataItem3D(test_image_3d(3), transform=Transform())
            self.viewer[0].insertNewNode('Data',
                                         self.sgdata,
                                         parentnode=self.viewer[0])
            isosurface = EMIsosurface(self.sgdata, transform=Transform())
            self.viewer[0].insertNewNode("Iso",
                                         isosurface,
                                         parentnode=self.sgdata)
            volslice = EMSliceItem3D(self.sgdata, transform=Transform())
            self.viewer[0].insertNewNode("Slice",
                                         volslice,
                                         parentnode=self.sgdata)

        E2loadappwin("e2filtertool", "image", self.viewer[0].qt_parent)

        self.procChange(-1)
Beispiel #16
0
 def menu_add_2dwin(self):
     if self.viewer == None: return
     self.viewer.append(EMImage2DWidget())
     self.viewer[-1].show()
     self.needupdate = 1
Beispiel #17
0
    def __new__(cls,
                data=None,
                old=None,
                app=None,
                force_2d=False,
                force_plot=False,
                filename="",
                replace=True):
        """This will create a new EMImage* object depending on the type of 'data'. If
		old= is provided, and of the appropriate type, it will be used rather than creating
		a new instance.
		"""

        if isinstance(data, EMData) and data.get_size() == 0:
            raise RuntimeError(
                "Can not display an EMData object that has no pixels")

        from EMAN2 import remove_directories_from_name
        if force_plot and force_2d:
            # ok this sucks but it suffices for the time being
            print(
                "Error, the force_plot and force_2d options are mutually exclusive"
            )
            return None

        if force_plot or (isinstance(data, EMData) and data.get_zsize() == 1
                          and data.get_ysize() == 1):
            from emplot2d import EMPlot2DWidget
            if old:
                if isinstance(old, EMPlot2DWidget):
                    old.set_data(data, remove_directories_from_name(filename),
                                 replace)
                    return old
            widget = EMPlot2DWidget(application=app)
            widget.set_data(data, remove_directories_from_name(filename),
                            replace)
            return widget
        elif force_2d or (isinstance(data, EMData) and data.get_zsize() == 1):
            from emimage2d import EMImage2DWidget
            if old:
                if isinstance(old, EMImage2DWidget):
                    old.set_data(data, filename)
                    return old
            widget = EMImage2DWidget(application=app)
            widget.set_data(data, filename)
            return widget
        elif isinstance(data, EMData):
            if isinstance(old, EMScene3D): widget = old
            else: widget = EMScene3D()
            data = EMDataItem3D(data, transform=Transform())
            #data.setSelectedItem(True)
            isosurface = EMIsosurface(data, transform=Transform())
            widget.insertNewNode(os.path.basename(filename),
                                 data,
                                 parentnode=widget)
            widget.insertNewNode("Iso", isosurface, parentnode=data)
            return widget

        elif isinstance(data, list) and isinstance(data[0], EMData):
            from emimagemx import EMImageMXWidget
            if old:
                if isinstance(old, EMImageMXWidget):
                    old.set_data(data, filename)
                    return old
            widget = EMImageMXWidget(application=app)
            widget.set_data(data, filename)
            return widget
        elif isinstance(data, list):
            from emplot3d import EMPlot3DWidgetNew
            if (isinstance(data[0], list)
                    or isinstance(data[0], tuple)) and len(data) > 2:
                if old:
                    if isinstance(old, EMPlot3DWidgetNew):
                        old.set_data(data,
                                     remove_directories_from_name(filename),
                                     replace)
                        return old

                widget = EMPlot3DWidgetNew()
                widget.set_data(data, remove_directories_from_name(filename),
                                replace)
                return widget
            else:
                from emplot2d import EMPlot2DWidget
                if old:
                    if isinstance(old, EMPlot2DWidget):
                        old.set_data(data,
                                     remove_directories_from_name(filename),
                                     replace)
                        return old
                widget = EMPlot2DWidget(application=app)
                widget.set_data(data, remove_directories_from_name(filename),
                                replace)
                return widget
        else:
            raise Exception(
                "data must be a single EMData object or a list of EMData objects"
            )
Beispiel #18
0
    def __init__(self,
                 app,
                 maxshift,
                 invert=False,
                 seqali=False,
                 tiltstep=2.0):
        self.app = app
        self.maxshift = maxshift
        self.seqali = seqali
        self.invert = invert
        self.tiltstep = tiltstep

        # the control panel
        QtGui.QWidget.__init__(self, None)

        self.gbl = QtGui.QGridLayout(self)
        self.gbl.setMargin(0)
        self.gbl.setSpacing(6)
        self.gbl.setObjectName("hbl")

        # action buttons
        self.bcenalign = QtGui.QPushButton("Center Align")
        self.bprojalign = QtGui.QPushButton("Proj. Realign")
        self.btiltaxis = QtGui.QPushButton("Tilt Axis")
        self.btiltaxisval = QtGui.QLineEdit("90.0")
        self.bsavedata = QtGui.QPushButton("Save Data")
        self.breconst = QtGui.QPushButton("3D Normal")
        self.sbmode = QtGui.QSpinBox(self)
        self.sbmode.setRange(0, 2)
        self.sbmode.setValue(0)
        self.bmagict = QtGui.QPushButton("3D Tomofill")
        self.bmagics = QtGui.QPushButton("3D Sph")
        self.bmagicc = QtGui.QPushButton("3D Cyl")
        self.vslpfilt = ValSlider(self, (0, .5), "Filter", 0.5, 50)

        self.gbl.addWidget(self.bcenalign, 0, 0)
        self.gbl.addWidget(self.bprojalign, 0, 1)
        self.gbl.addWidget(self.btiltaxis, 0, 2)
        self.gbl.addWidget(self.btiltaxisval, 0, 3)
        #		self.gbl.addWidget(self.bsavedata,0,3)
        self.gbl.addWidget(self.breconst, 1, 0)
        self.gbl.addWidget(self.sbmode, 2, 0, 1, 1)
        self.gbl.addWidget(self.vslpfilt, 3, 0, 1, 4)
        self.gbl.addWidget(self.bmagict, 1, 1)
        self.gbl.addWidget(self.bmagics, 1, 2)
        self.gbl.addWidget(self.bmagicc, 1, 3)

        QtCore.QObject.connect(self.bcenalign, QtCore.SIGNAL("clicked(bool)"),
                               self.do_cenalign)
        QtCore.QObject.connect(self.bprojalign, QtCore.SIGNAL("clicked(bool)"),
                               self.do_projalign)
        QtCore.QObject.connect(self.btiltaxis, QtCore.SIGNAL("clicked(bool)"),
                               self.do_tiltaxis)
        QtCore.QObject.connect(self.bsavedata, QtCore.SIGNAL("clicked(bool)"),
                               self.do_savedata)
        QtCore.QObject.connect(self.breconst, QtCore.SIGNAL("clicked(bool)"),
                               self.do_reconst)
        QtCore.QObject.connect(self.bmagict, QtCore.SIGNAL("clicked(bool)"),
                               self.do_magict)
        QtCore.QObject.connect(self.bmagics, QtCore.SIGNAL("clicked(bool)"),
                               self.do_magics)
        QtCore.QObject.connect(self.bmagicc, QtCore.SIGNAL("clicked(bool)"),
                               self.do_magicc)
        QtCore.QObject.connect(self.vslpfilt, QtCore.SIGNAL("valueChanged"),
                               self.do_filter)

        # the single image display widget
        self.im2d = EMImage2DWidget(application=app, winid="tomotrackbox.big")
        self.imboxed = EMImage2DWidget(application=app,
                                       winid="tomotrackbox.small")
        self.improj = EMImage2DWidget(application=app,
                                      winid="tomotrackbox.proj")
        self.imslice = EMImage2DWidget(application=app,
                                       winid="tomotrackbox.3dslice")
        self.imvol = EMImage3DModule(application=app, winid="tomotrackbox.3d")

        # get some signals from the window.
        QtCore.QObject.connect(self.im2d, QtCore.SIGNAL("mousedown"),
                               self.down)
        QtCore.QObject.connect(self.im2d, QtCore.SIGNAL("mousedrag"),
                               self.drag)
        QtCore.QObject.connect(self.im2d, QtCore.SIGNAL("mouseup"), self.up)
        QtCore.QObject.connect(self.im2d, QtCore.SIGNAL("increment_list_data"),
                               self.change_tilt)

        self.imagefile = None
        self.imageparm = None
        self.tiltshapes = None
        self.curtilt = 0
        self.oldtilt = self.curtilt
        self.map3d = None
        self.downloc = None
        self.downadjloc = None

        self.show()
        self.im2d.show()
Beispiel #19
0
    def __init__(self,
                 images,
                 voltage=None,
                 apix=None,
                 cs=None,
                 ac=10.0,
                 box=512):
        """The 'new' e2boxer interface.
		"""
        try:
            from emimage2d import EMImage2DWidget
        except:
            print "Cannot import EMAN image GUI objects (EMImage2DWidget)"
            sys.exit(1)
        try:
            from emimagemx import EMImageMXWidget
        except:
            print "Cannot import EMAN image GUI objects (EMImageMXWidget)"
            sys.exit(1)
        try:
            from emplot2d import EMPlot2DWidget
        except:
            print "Cannot import EMAN plot GUI objects (is matplotlib installed?)"
            sys.exit(1)

        QtGui.QWidget.__init__(self, None)
        self.setWindowIcon(QtGui.QIcon(get_image_directory() + "ctf.png"))

        self.data = None
        self.curfilename = None

        self.defaultvoltage = voltage
        self.defaultapix = apix
        self.defaultcs = cs
        self.defaultac = ac

        self.wimage = EMImage2DWidget()
        self.wimage.setWindowTitle("Micrograph")

        self.wparticles = EMImageMXWidget()
        self.wparticles.setWindowTitle("Particles")

        #self.wfft=EMImage2DWidget()
        #self.wfft.setWindowTitle("e2evalimage - 2D FFT")

        #self.wplot=EMPlot2DWidget()
        #self.wplot.setWindowTitle("e2evalimage - Plot")

        self.wimage.connect(QtCore.SIGNAL("mousedown"), self.imgmousedown)
        self.wimage.connect(QtCore.SIGNAL("mousedrag"), self.imgmousedrag)
        self.wimage.connect(QtCore.SIGNAL("mouseup"), self.imgmouseup)
        self.wparticles.connect(QtCore.SIGNAL("mousedown"), self.ptclmousedown)
        self.wparticles.connect(QtCore.SIGNAL("mousedrag"), self.ptclmousedrag)
        self.wparticles.connect(QtCore.SIGNAL("mouseup"), self.ptclmouseup)

        self.wimage.mmode = "app"
        self.wparticles.mmode = "app"

        # This object is itself a widget we need to set up
        self.gbl = QtGui.QGridLayout(self)
        self.gbl.setMargin(8)
        self.gbl.setSpacing(6)

        # plot list and plot mode combobox
        self.setlist = e2ctf.MyListWidget(self)
        self.setlist.setSizePolicy(QtGui.QSizePolicy.Preferred,
                                   QtGui.QSizePolicy.Expanding)
        for i in images:
            self.setlist.addItem(i)
        self.gbl.addWidget(self.setlist, 0, 0, 10, 2)

        self.lboxmode = QtGui.QLabel("Mode:", self)
        self.gbl.addWidget(self.lboxmode, 10, 0)

        self.sboxmode = QtGui.QComboBox(self)
        self.sboxmode.addItem("Manual")
        self.sboxmode.addItem("Reference")
        self.sboxmode.setCurrentIndex(1)
        self.gbl.addWidget(self.sboxmode, 10, 1)

        self.lanmode = QtGui.QLabel("Annotate:", self)
        self.gbl.addWidget(self.lanmode, 12, 0)

        self.sanmode = QtGui.QComboBox(self)
        self.sanmode.addItem("Box")
        self.sanmode.addItem("Box+dot")
        self.sanmode.addItem("Circle")
        self.sanmode.addItem("None")
        self.gbl.addWidget(self.sanmode, 12, 1)

        self.sdefocus = ValSlider(self, (0, 5), "Defocus:", 0.0, 90)
        self.gbl.addWidget(self.sdefocus, 0, 2, 1, 3)

        self.squality = ValSlider(self, (0, 9), "Quality (0-9):", 0, 90)
        self.squality.setIntonly(True)
        self.gbl.addWidget(self.squality, 6, 2, 1, 3)

        self.brefit = QtGui.QPushButton("Autobox")
        self.gbl.addWidget(self.brefit, 7, 2)

        self.bclrauto = QtGui.QPushButton("Clear Auto")
        self.gbl.addWidget(self.bclrauto, 7, 3)

        self.bclrall = QtGui.QPushButton("Clear All")
        self.gbl.addWidget(self.bclrall, 7, 4)

        self.sapix = ValBox(self, (0, 500), "A/pix:", 1.0, 90)
        if self.defaultapix != None: self.sapix.setValue(self.defaultapix)
        self.gbl.addWidget(self.sapix, 10, 2)

        self.svoltage = ValBox(self, (0, 500), "Voltage (kV):", 200, 90)
        if self.defaultvoltage != None:
            self.svoltage.setValue(self.defaultvoltage)
        self.gbl.addWidget(self.svoltage, 11, 2)

        self.scs = ValBox(self, (0, 5), "Cs (mm):", 4.1, 90)
        if self.defaultcs != None: self.scs.setValue(self.defaultcs)
        self.gbl.addWidget(self.scs, 12, 2)

        self.sboxsize = ValBox(self, (0, 500), "Box Size:", 256, 90)
        self.sboxsize.intonly = True
        self.gbl.addWidget(self.sboxsize, 13, 2)

        self.sptclsize = ValBox(self, (0, 500), "Ptcl Size:", 256, 90)
        self.sptclsize.intonly = True
        self.gbl.addWidget(self.sptclsize, 14, 2)

        QtCore.QObject.connect(self.sdefocus, QtCore.SIGNAL("valueChanged"),
                               self.newCTF)
        QtCore.QObject.connect(self.sapix, QtCore.SIGNAL("valueChanged"),
                               self.newCTF)
        QtCore.QObject.connect(self.svoltage, QtCore.SIGNAL("valueChanged"),
                               self.newCTF)
        QtCore.QObject.connect(self.scs, QtCore.SIGNAL("valueChanged"),
                               self.newCTF)
        QtCore.QObject.connect(self.sboxsize, QtCore.SIGNAL("valueChanged"),
                               self.newBox)
        #		QtCore.QObject.connect(self.soversamp, QtCore.SIGNAL("valueChanged"), self.newBox)
        QtCore.QObject.connect(self.squality, QtCore.SIGNAL("valueChanged"),
                               self.newQualityFactor)
        QtCore.QObject.connect(self.setlist,
                               QtCore.SIGNAL("currentRowChanged(int)"),
                               self.newSet)
        QtCore.QObject.connect(self.setlist, QtCore.SIGNAL("keypress"),
                               self.listkey)
        QtCore.QObject.connect(self.sboxmode,
                               QtCore.SIGNAL("currentIndexChanged(int)"),
                               self.newBoxMode)

        self.resize(
            720, 380
        )  # figured these values out by printing the width and height in resize event

        ### This section is responsible for background updates
        self.busy = False
        self.needupdate = True
        self.needredisp = False
        self.procthread = None
        self.errors = None  # used to communicate errors back from the reprocessing thread

        self.timer = QTimer()
        QtCore.QObject.connect(self.timer, QtCore.SIGNAL("timeout()"),
                               self.timeOut)
        self.timer.start(100)

        self.setWindowTitle("e2boxer21 - Control Panel")

        self.wimage.show()
        self.wfft.show()
        self.wplot.show()
        E2loadappwin("e2boxer21", "main", self)
        E2loadappwin("e2boxer21", "image", self.wimage.qt_parent)
        E2loadappwin("e2boxer21", "particles", self.wparticles.qt_parent)
Beispiel #20
0
    def __init__(self,
                 application,
                 apix=1.0,
                 voltage=300.0,
                 cs=4.1,
                 ac=10.0,
                 samples=256):
        """CTF simulation dialog
		"""
        try:
            from emimage2d import EMImage2DWidget
        except:
            print "Cannot import EMAN image GUI objects (EMImage2DWidget)"
            sys.exit(1)
        try:
            from emplot2d import EMPlot2DWidget
        except:
            print "Cannot import EMAN plot GUI objects (is matplotlib installed?)"
            sys.exit(1)

        self.app = weakref.ref(application)

        self.df_voltage = voltage
        self.df_apix = apix
        self.df_cs = cs
        self.df_ac = ac
        self.df_samples = samples
        self.img = None

        QtGui.QWidget.__init__(self, None)
        self.setWindowIcon(QtGui.QIcon(get_image_directory() + "ctf.png"))

        self.data = []
        self.curset = 0
        self.plotmode = 0

        self.guiim = EMImage2DWidget(application=self.app())
        self.guiiminit = True  # a flag that's used to auto resize the first time the gui's set_data function is called
        self.guiplot = EMPlot2DWidget(application=self.app())
        #		self.guirealim=EMImage2DWidget(application=self.app())	# This will show the original particle images

        #		self.guirealim.connect(self.guirealim,QtCore.SIGNAL("keypress"),self.realimgkey)
        self.guiim.connect(self.guiim, QtCore.SIGNAL("mousedown"),
                           self.imgmousedown)
        self.guiim.connect(self.guiim, QtCore.SIGNAL("mousedrag"),
                           self.imgmousedrag)
        self.guiim.connect(self.guiim, QtCore.SIGNAL("mouseup"),
                           self.imgmouseup)
        self.guiplot.connect(self.guiplot, QtCore.SIGNAL("mousedown"),
                             self.plotmousedown)

        self.guiim.mmode = "app"

        # This object is itself a widget we need to set up
        self.hbl = QtGui.QHBoxLayout(self)
        self.hbl.setMargin(0)
        self.hbl.setSpacing(6)
        self.hbl.setObjectName("hbl")

        # plot list and plot mode combobox
        self.vbl2 = QtGui.QVBoxLayout()
        self.setlist = MyListWidget(self)
        self.setlist.setSizePolicy(QtGui.QSizePolicy.Preferred,
                                   QtGui.QSizePolicy.Expanding)
        self.vbl2.addWidget(self.setlist)

        self.splotmode = QtGui.QComboBox(self)
        self.splotmode.addItem("Amplitude")
        self.splotmode.addItem("Intensity")
        self.splotmode.addItem("Int w sum")
        self.splotmode.addItem("Amp w sum")
        self.vbl2.addWidget(self.splotmode)
        self.hbl.addLayout(self.vbl2)

        # ValSliders for CTF parameters
        self.vbl = QtGui.QVBoxLayout()
        self.vbl.setMargin(0)
        self.vbl.setSpacing(6)
        self.vbl.setObjectName("vbl")
        self.hbl.addLayout(self.vbl)

        #self.samp = ValSlider(self,(0,5.0),"Amp:",0)
        #self.vbl.addWidget(self.samp)

        self.imginfo = QtGui.QLabel("Info", self)
        self.vbl.addWidget(self.imginfo)

        self.sdefocus = ValSlider(self, (0, 5), "Defocus:", 0, 90)
        self.vbl.addWidget(self.sdefocus)

        self.sbfactor = ValSlider(self, (0, 1600), "B factor:", 0, 90)
        self.vbl.addWidget(self.sbfactor)

        self.sdfdiff = ValSlider(self, (0, 1), "DF Diff:", 0, 90)
        self.vbl.addWidget(self.sdfdiff)

        self.sdfang = ValSlider(self, (0, 180), "Df Angle:", 0, 90)
        self.vbl.addWidget(self.sdfang)

        self.sampcont = ValSlider(self, (0, 100), "% AC", 0, 90)
        self.vbl.addWidget(self.sampcont)

        self.sapix = ValSlider(self, (.2, 10), "A/Pix:", 2, 90)
        self.vbl.addWidget(self.sapix)

        self.svoltage = ValSlider(self, (0, 1000), "Voltage (kV):", 0, 90)
        self.vbl.addWidget(self.svoltage)

        self.scs = ValSlider(self, (0, 5), "Cs (mm):", 0, 90)
        self.vbl.addWidget(self.scs)

        self.ssamples = ValSlider(self, (32, 1024), "# Samples:", 0, 90)
        self.ssamples.setIntonly(True)
        self.vbl.addWidget(self.ssamples)

        self.hbl_buttons = QtGui.QHBoxLayout()
        self.newbut = QtGui.QPushButton("New")
        self.hbl_buttons.addWidget(self.newbut)
        self.vbl.addLayout(self.hbl_buttons)

        self.on_new_but()

        QtCore.QObject.connect(self.sdefocus, QtCore.SIGNAL("valueChanged"),
                               self.newCTF)
        QtCore.QObject.connect(self.sbfactor, QtCore.SIGNAL("valueChanged"),
                               self.newCTF)
        QtCore.QObject.connect(self.sdfdiff, QtCore.SIGNAL("valueChanged"),
                               self.newCTF)
        QtCore.QObject.connect(self.sdfang, QtCore.SIGNAL("valueChanged"),
                               self.newCTF)
        QtCore.QObject.connect(self.sapix, QtCore.SIGNAL("valueChanged"),
                               self.newCTF)
        QtCore.QObject.connect(self.sampcont, QtCore.SIGNAL("valueChanged"),
                               self.newCTF)
        QtCore.QObject.connect(self.svoltage, QtCore.SIGNAL("valueChanged"),
                               self.newCTF)
        QtCore.QObject.connect(self.scs, QtCore.SIGNAL("valueChanged"),
                               self.newCTF)
        QtCore.QObject.connect(self.ssamples, QtCore.SIGNAL("valueChanged"),
                               self.newCTF)
        QtCore.QObject.connect(self.setlist,
                               QtCore.SIGNAL("currentRowChanged(int)"),
                               self.newSet)
        QtCore.QObject.connect(self.setlist, QtCore.SIGNAL("keypress"),
                               self.listkey)
        QtCore.QObject.connect(self.splotmode,
                               QtCore.SIGNAL("currentIndexChanged(int)"),
                               self.newPlotMode)

        QtCore.QObject.connect(self.newbut, QtCore.SIGNAL("clicked(bool)"),
                               self.on_new_but)

        self.resize(
            720, 380
        )  # figured these values out by printing the width and height in resize event

        E2loadappwin("e2ctfsim", "main", self)
        E2loadappwin("e2ctfsim", "image", self.guiim.qt_parent)
        #		E2loadappwin("e2ctf","realimage",self.guirealim.qt_parent)
        E2loadappwin("e2ctfsim", "plot", self.guiplot.qt_parent)

        self.setWindowTitle("CTF")
Beispiel #21
0
	def __init__(self,images,voltage=None,apix=None,cs=None,ac=10.0,box=512,usefoldername=False,constbfactor=-1,fitastig=False):
		"""Implements the CTF fitting dialog using various EMImage and EMPlot2D widgets
		'data' is a list of (filename,ctf,im_1d,bg_1d,quality)
		'parms' is [box size,ctf,box coord,set of excluded boxnums,quality,oversampling]
		"""
		try:
			from emimage2d import EMImage2DWidget
		except:
			print "Cannot import EMAN image GUI objects (EMImage2DWidget)"
			sys.exit(1)
		try:
			from emplot2d import EMPlot2DWidget
		except:
			print "Cannot import EMAN plot GUI objects (is matplotlib installed?)"
			sys.exit(1)

		QtGui.QWidget.__init__(self,None)
		self.setWindowIcon(QtGui.QIcon(get_image_directory() + "ctf.png"))

		self.fitastig=fitastig
		self.nodir=not usefoldername
		self.data=None
		self.curset=0
		self.calcmode=1
		self.f2dmode=0
		self.f2danmode=0
		self.plotmode=0
		self.curfilename = None

		self.ringrad=1
		self.xpos1=(10,0)
		self.xpos2=(0,10)
#		self.db = db_open_dict('bdb:mgquality')

		self.defaultvoltage=voltage
		self.defaultapix=apix
		self.defaultcs=cs
		self.defaultac=ac
		self.constbfactor=constbfactor

		# Per image parameters to keep track of
		# for each image [box size,ctf,box coord,set of excluded boxnums,quality,oversampling]
		self.parms=[]
#		db_fparms=db_open_dict("bdb:e2ctf.frameparms",True)

		# This little block of code deals with Z stacks of images and multiple image files,
		# rewriting the name(s) with an enumeration including ;number or ,number
		newimages=[]
		for i in images:
			n=EMUtil.get_image_count(i)
			if n!=1:
				for j in xrange(n): newimages.append(i+",%d"%j)
			else:
				h=EMData(i,0,True)		# read header
				n=h["nz"]
				if n!=1:
					for j in xrange(n): newimages.append(i+";%d"%j)
				else : newimages.append(i)
		images=newimages

		# Now we try to restore old image information
		for i in images:
			try:
				pd=js_open_dict(info_name(i,nodir=self.nodir))
				parms=pd["ctf_frame"]
				parms[4]=pd["quality"]
				if box>=64 and parms[0]!=box:
					parms[0]=box
					parms[3]=set()
#				if parms==None : raise Exception
			except:
				ctf = EMAN2Ctf()
				ctf.from_dict({'defocus':0.0,'dfdiff':0.0,'dfang':0.0,'bfactor':200.0,'ampcont':self.defaultac,'voltage':200.0,'cs':4.1,'apix':1.0,'dsbg':-1})
				if self.defaultvoltage!=None : ctf.voltage=self.defaultvoltage
				if self.defaultcs!=None : ctf.cs=self.defaultcs
				if self.defaultapix!=None : ctf.apix=self.defaultapix
				parms=[int(box),ctf,(256,256),set(),5,1]
				print "Initialize new parms for: ",base_name(i)

			if self.constbfactor>0 : parms[1].bfactor=self.constbfactor

			if parms[0]<64 :
				parms[0]=512
				parms[3]=set()

			self.parms.append(parms)

		self.wimage=EMImage2DWidget()
		self.wimage.setWindowTitle("e2evalimage - Micrograph")

		self.wfft=EMImage2DWidget()
		self.wfft.setWindowTitle("e2evalimage - 2D FFT")

		self.wplot=EMPlot2DWidget()
		self.wplot.setWindowTitle("e2evalimage - Plot")


		self.wimage.connect(self.wimage,QtCore.SIGNAL("mousedown"),self.imgmousedown)
		self.wimage.connect(self.wimage,QtCore.SIGNAL("mousedrag"),self.imgmousedrag)
		self.wimage.connect(self.wimage,QtCore.SIGNAL("mouseup")  ,self.imgmouseup)
		self.wfft.connect(self.wfft,QtCore.SIGNAL("mousedown"),self.fftmousedown)
		self.wfft.connect(self.wfft,QtCore.SIGNAL("mousedrag"),self.fftmousedrag)
		self.wfft.connect(self.wfft,QtCore.SIGNAL("mouseup")  ,self.fftmouseup)
		self.wplot.connect(self.wplot,QtCore.SIGNAL("mousedown"),self.plotmousedown)

		self.wimage.mmode="app"
		self.wfft.mmode="app"

		# This object is itself a widget we need to set up
		self.gbl = QtGui.QGridLayout(self)
		self.gbl.setMargin(8)
		self.gbl.setSpacing(6)

		# plot list and plot mode combobox
		self.setlist=e2ctf.MyListWidget(self)
		self.setlist.setSizePolicy(QtGui.QSizePolicy.Preferred,QtGui.QSizePolicy.Expanding)
		for i in images:
			self.setlist.addItem(i)
		self.gbl.addWidget(self.setlist,0,0,10,2)

		self.lcalcmode=QtGui.QLabel("Region:",self)
		self.gbl.addWidget(self.lcalcmode,10,0)

		self.scalcmode=QtGui.QComboBox(self)
		self.scalcmode.addItem("Single Region")
		self.scalcmode.addItem("Tiled Boxes")
		self.scalcmode.setCurrentIndex(1)
		self.gbl.addWidget(self.scalcmode,10,1)


		self.lcalcmode=QtGui.QLabel("2D FFT:",self)
		self.gbl.addWidget(self.lcalcmode,11,0)

		self.s2dmode=QtGui.QComboBox(self)
		self.s2dmode.addItem("Power Spectrum")
		self.s2dmode.addItem("Bg Subtracted")
		self.s2dmode.addItem("Background")
		self.gbl.addWidget(self.s2dmode,11,1)

		self.lcalcmode=QtGui.QLabel("Annotate:",self)
		self.gbl.addWidget(self.lcalcmode,12,0)

		self.s2danmode=QtGui.QComboBox(self)
		self.s2danmode.addItem("Ctf Zeroes")
		self.s2danmode.addItem("Resolution Ring")
		self.s2danmode.addItem("2-D Xtal")
		self.s2danmode.addItem("None")
		self.gbl.addWidget(self.s2danmode,12,1)


		self.lcalcmode=QtGui.QLabel("Plot:",self)
		self.gbl.addWidget(self.lcalcmode,13,0)

		self.splotmode=QtGui.QComboBox(self)
		self.splotmode.addItem("Bgsub and Fit")
		self.splotmode.addItem("Fg and Bg")
		self.splotmode.addItem("Bgsub, 45 deg slices")
		self.splotmode.addItem("Fg, 45 deg slices")
		self.splotmode.addItem("SSNR (NOT BY PTCL !)")
		self.gbl.addWidget(self.splotmode,13,1)

		# ValSliders for CTF parameters

		#self.samp = ValSlider(self,(0,5.0),"Amp:",0)
		#self.vbl.addWidget(self.samp)

		self.sdefocus=ValSlider(self,(0,5),"Defocus:",0.0,90)
		self.gbl.addWidget(self.sdefocus,0,2,1,3)

		self.sbfactor=ValSlider(self,(0,1600),"B factor:",200.0,90)
		self.gbl.addWidget(self.sbfactor,1,2,1,3)

		self.sdfdiff=ValSlider(self,(0,1),"DF Diff:",0,90)
		self.gbl.addWidget(self.sdfdiff,2,2,1,3)

		self.sdfang=ValSlider(self,(0,180),"Df Angle:",0,90)
		self.gbl.addWidget(self.sdfang,3,2,1,3)

		self.sampcont=ValSlider(self,(0,100),"% AC",10.0,90)
		if self.defaultac!=None : self.sampcont.setValue(self.defaultac)
		self.gbl.addWidget(self.sampcont,4,2,1,3)

		self.sang45=ValSlider(self,(-22.5,22.5),"45 mode ang",0.0,90)
		self.gbl.addWidget(self.sang45,5,2,1,3)

		self.squality=ValSlider(self,(0,9),"Quality (0-9):",0,90)
		self.squality.setIntonly(True)
		self.gbl.addWidget(self.squality,6,2,1,3)

		self.brefit=QtGui.QPushButton("Refit")
		self.gbl.addWidget(self.brefit,7,2)

		self.cbgadj=CheckBox(None,"CTF BG Adj",1)
		self.gbl.addWidget(self.cbgadj,7,3)


#		self.sapix=ValSlider(self,(.2,10),"A/Pix:",2,90)
#		self.vbl.addWidget(self.sapix)

		self.sapix=ValBox(self,(0,500),"A/pix:",1.0,90)
		if self.defaultapix!=None : self.sapix.setValue(self.defaultapix)
		self.gbl.addWidget(self.sapix,10,2)

		self.svoltage=ValBox(self,(0,500),"Voltage (kV):",200,90)
		if self.defaultvoltage!=None : self.svoltage.setValue(self.defaultvoltage)
		self.gbl.addWidget(self.svoltage,11,2)

		self.scs=ValBox(self,(0,5),"Cs (mm):",4.1,90)
		if self.defaultcs!=None : self.scs.setValue(self.defaultcs)
		self.gbl.addWidget(self.scs,12,2)

		self.sboxsize=ValBox(self,(128,1024),"Box Size:",512,90)
		self.sboxsize.intonly=True
		self.gbl.addWidget(self.sboxsize,13,2)

#		self.soversamp=ValBox(self,(0,500),"Oversample:",1,90)
#		self.soversamp.intonly=True
#		self.gbl.addWidget(self.soversamp,14,2)					# disable oversampling for now, not properly integrated with save/recall mechanism, and not clear if it's really useful


		# this is just a spacer
		self.gbl.setColumnStretch(3,2)

		self.bbox=QtGui.QGroupBox("Project")
		self.gbl.addWidget(self.bbox,10,4,4,1)

		self.bvbl=QtGui.QVBoxLayout()
		self.bbox.setLayout(self.bvbl)

		self.bimport=QtGui.QPushButton("Import")
		self.bvbl.addWidget(self.bimport)

		self.cinvert=CheckBox(None,"Invert")
		self.bvbl.addWidget(self.cinvert)

		self.cxray=CheckBox(None,"X-ray Pixels")
		self.bvbl.addWidget(self.cxray)

		QtCore.QObject.connect(self.bimport, QtCore.SIGNAL("clicked(bool)"),self.doImport)
		QtCore.QObject.connect(self.brefit, QtCore.SIGNAL("clicked(bool)"),self.doRefit)
		QtCore.QObject.connect(self.cbgadj, QtCore.SIGNAL("valueChanged"),self.bgAdj)
		QtCore.QObject.connect(self.sdefocus, QtCore.SIGNAL("valueChanged"), self.newCTF)
		QtCore.QObject.connect(self.sbfactor, QtCore.SIGNAL("valueChanged"), self.newCTF)
		QtCore.QObject.connect(self.sdfdiff, QtCore.SIGNAL("valueChanged"), self.newCTF)
		QtCore.QObject.connect(self.sdfang, QtCore.SIGNAL("valueChanged"), self.newCTF)
		QtCore.QObject.connect(self.sapix, QtCore.SIGNAL("valueChanged"), self.newCTF)
		QtCore.QObject.connect(self.sampcont, QtCore.SIGNAL("valueChanged"), self.newCTF)
		QtCore.QObject.connect(self.svoltage, QtCore.SIGNAL("valueChanged"), self.newCTF)
		QtCore.QObject.connect(self.scs, QtCore.SIGNAL("valueChanged"), self.newCTF)
		QtCore.QObject.connect(self.sboxsize, QtCore.SIGNAL("valueChanged"), self.newBox)
#		QtCore.QObject.connect(self.soversamp, QtCore.SIGNAL("valueChanged"), self.newBox)
		QtCore.QObject.connect(self.sang45, QtCore.SIGNAL("valueChanged"), self.recalc_real)
		QtCore.QObject.connect(self.squality,QtCore.SIGNAL("valueChanged"),self.newQualityFactor)
		QtCore.QObject.connect(self.setlist,QtCore.SIGNAL("currentRowChanged(int)"),self.newSet)
		QtCore.QObject.connect(self.setlist,QtCore.SIGNAL("keypress"),self.listkey)
		QtCore.QObject.connect(self.scalcmode,QtCore.SIGNAL("currentIndexChanged(int)"),self.newCalcMode)
		QtCore.QObject.connect(self.s2dmode,QtCore.SIGNAL("currentIndexChanged(int)"),self.new2DMode)
		QtCore.QObject.connect(self.s2danmode,QtCore.SIGNAL("currentIndexChanged(int)"),self.new2DAnMode)
		QtCore.QObject.connect(self.splotmode,QtCore.SIGNAL("currentIndexChanged(int)"),self.newPlotMode)

	   	#QtCore.QObject.connect(self.saveparms,QtCore.SIGNAL("clicked(bool)"),self.on_save_params)
		#QtCore.QObject.connect(self.recallparms,QtCore.SIGNAL("clicked(bool)"),self.on_recall_params)
		#QtCore.QObject.connect(self.refit,QtCore.SIGNAL("clicked(bool)"),self.on_refit)
		#QtCore.QObject.connect(self.output,QtCore.SIGNAL("clicked(bool)"),self.on_output)


		self.resize(720,380) # figured these values out by printing the width and height in resize event

		### This section is responsible for background updates
		self.busy=False
		self.needupdate=True
		self.needredisp=False
		self.procthread=None
		self.errors=None		# used to communicate errors back from the reprocessing thread

		self.timer=QTimer()
		QtCore.QObject.connect(self.timer, QtCore.SIGNAL("timeout()"), self.timeOut)
		self.timer.start(100)

		self.setWindowTitle("e2evalimage - Control Panel")

		self.wimage.show()
		self.wfft.show()
		self.wplot.show()
		E2loadappwin("e2evalimage","main",self)
		E2loadappwin("e2evalimage","image",self.wimage.qt_parent)
		E2loadappwin("e2evalimage","fft",self.wfft.qt_parent)
		E2loadappwin("e2evalimage","plot",self.wplot.qt_parent)
Beispiel #22
0
    def __init__(self, application, path=None, piter=None, threads=4):
        """application is an QApplication instance. ptclstack is the path to the file containing the particles to analyze. path is the path for ouput files"""
        QtGui.QWidget.__init__(self)

        self.aliimg = None  # This is the unmasked alignment reference image
        self.alisig = None  # This is the standard deviation of the alignment reference
        self.alimask = None  # This is the drawn-upon version of aliimg used to generate the mask
        self.alimasked = None  # This is the masked alignment reference used for the actual alignments
        self.roidrawmask = None  # Region of interest mask drawing image
        self.roimask = None  # Region of interest actual mask
        self.roimasked = None  # Region of interest display widget

        self.particles = None

        self.app = weakref.ref(application)
        self.path = path
        self.iter = piter

        self.setWindowTitle("Main Window (e2motion.py)")

        #		self.setWindowTitle("e2motion.py")

        # Menu Bar
        self.mfile = self.menuBar().addMenu("File")
        self.mfileopen = self.mfile.addAction("Select Particles")
        self.mfileopencls = self.mfile.addAction("Particles from Classes")
        self.mfileopencls.setEnabled(False)
        self.mfilequit = self.mfile.addAction("Quit")

        #self.mwin=self.menuBar().addMenu("Window")
        #self.mwin_boxes=self.mwin.addAction("Particles")
        #self.mwin_single=self.mwin.addAction("Single Particle")
        #self.mwin_average=self.mwin.addAction("Averaging")

        self.setCentralWidget(QtGui.QWidget())
        self.gbl = QtGui.QGridLayout(self.centralWidget())
        cen = self.centralWidget()

        ######
        # Folder parameters
        self.vgb0 = QtGui.QGroupBox("Particle Data")
        self.gbl.addWidget(self.vgb0, 0, 0, 1, 4)

        self.gbl2 = QtGui.QGridLayout(self.vgb0)
        self.wlpath = QtGui.QLabel("Path: {}".format(self.path))
        self.gbl2.addWidget(self.wlpath, 0, 0)
        self.gbl2.setColumnStretch(0, 1)

        self.wvbiter = ValBox(label="Iter:", value=self.iter)
        self.wvbiter.setIntonly(True)
        self.gbl2.addWidget(self.wvbiter, 0, 2)
        self.gbl2.setColumnStretch(2, 0)

        self.wvsnum = ValSlider(rng=(-.2, 0), label="Nptcl:", value=250)
        self.wvsnum.setIntonly(True)
        self.gbl2.addWidget(self.wvsnum, 0, 3)
        self.gbl2.setColumnStretch(3, 4)

        self.wlnptcl = QtGui.QLabel(" ")
        self.gbl2.addWidget(self.wlnptcl, 0, 5)
        self.gbl2.setColumnStretch(5, 2)

        self.wbdoavg = QtGui.QPushButton("Make Avg")
        self.gbl2.addWidget(self.wbdoavg, 0, 8)

        ###### Alignment Mask
        # widget for editing the alignment mask
        self.wlalimaskdraw = QtGui.QLabel("<big><pre>Edit</pre></big>")
        self.wlalimaskdraw.setAlignment(Qt.AlignHCenter)
        self.gbl.addWidget(self.wlalimaskdraw, 2, 1)

        self.wlalimaskdraw2 = QtGui.QLabel(
            "<big><pre>A\nl\ni\ng\nn</pre></big>")
        self.gbl.addWidget(self.wlalimaskdraw2, 3, 0)

        self.w2dalimaskdraw = EMImage2DWidget()
        self.gbl.addWidget(self.w2dalimaskdraw, 3, 1)

        # Buttons for controlling mask
        self.hbl1 = QtGui.QHBoxLayout()
        self.gbl.addLayout(self.hbl1, 4, 1)
        self.hbl1.addStretch(5)

        self.wbdrawali = QtGui.QPushButton("Draw")
        self.hbl1.addWidget(self.wbdrawali)
        self.wbdrawali.hide(
        )  # this functionality won't work with the current widget

        self.wbautoali = QtGui.QPushButton("Auto")
        self.hbl1.addWidget(self.wbautoali)

        self.wbresetali = QtGui.QPushButton("Reset")
        self.hbl1.addWidget(self.wbresetali)

        self.hbl1.addStretch(5)

        # Widget for setting alignment mask blur and base level
        self.vbl1 = QtGui.QVBoxLayout()
        self.gbl.addLayout(self.vbl1, 3, 2)
        self.vbl1.addStretch(5)

        self.wlalimaskblur = QtGui.QLabel("Blur")
        self.vbl1.addWidget(self.wlalimaskblur)

        self.wsbalimaskblur = QtGui.QSpinBox()
        self.wsbalimaskblur.setRange(0, 25)
        self.vbl1.addWidget(self.wsbalimaskblur)

        self.vbl1.addSpacing(16)

        self.wlalimaskbase = QtGui.QLabel("Base")
        self.vbl1.addWidget(self.wlalimaskbase)

        self.wsbalimaskbase = QtGui.QSpinBox()
        self.wsbalimaskbase.setRange(0, 100)
        self.wsbalimaskbase.setValue(10)
        self.vbl1.addWidget(self.wsbalimaskbase)

        self.vbl1.addSpacing(16)

        self.wlalimaskrot = QtGui.QLabel("Rot")
        self.vbl1.addWidget(self.wlalimaskrot)

        self.wsbalimaskrot = QtGui.QSpinBox()
        self.wsbalimaskrot.setRange(0, 360)
        self.wsbalimaskrot.setValue(0)
        self.vbl1.addWidget(self.wsbalimaskrot)

        self.vbl1.addSpacing(16)

        self.wbaligo = QtGui.QPushButton(QtCore.QChar(0x2192))
        self.vbl1.addWidget(self.wbaligo)

        self.vbl1.addStretch(5)

        # widget for displaying the masked alignment reference
        self.wlalimask = QtGui.QLabel("<big><pre>Reference</pre></big>")
        self.wlalimask.setAlignment(Qt.AlignHCenter)
        self.gbl.addWidget(self.wlalimask, 2, 3)

        self.w2dalimask = EMImage2DWidget()
        self.gbl.addWidget(self.w2dalimask, 3, 3)

        self.hbl1a = QtGui.QHBoxLayout()
        self.gbl.addLayout(self.hbl1a, 4, 3)
        self.hbl1a.addStretch(5)

        self.wbrecalcref = QtGui.QPushButton("Realign")
        self.hbl1a.addWidget(self.wbrecalcref)

        self.wbrrecalcref = QtGui.QPushButton("Rerefine")
        self.hbl1a.addWidget(self.wbrrecalcref)

        self.hbl1a.addStretch(5)

        ###### ROI Mask
        # widget for editing the ROI mask
        self.wlroimaskdraw = QtGui.QLabel("<big><pre>R\nO\nI</pre></big>")
        self.gbl.addWidget(self.wlroimaskdraw, 6, 0)

        self.w2droimaskdraw = EMImage2DWidget()
        self.gbl.addWidget(self.w2droimaskdraw, 6, 1)

        # Buttons for controlling mask
        self.hbl2 = QtGui.QHBoxLayout()
        self.gbl.addLayout(self.hbl2, 5, 1)
        self.hbl2.addStretch(5)

        self.wbdrawroi = QtGui.QPushButton("Draw")
        self.hbl1.addWidget(self.wbdrawroi)
        self.wbdrawroi.hide()  # this button won't work right for now

        self.wbautoroi = QtGui.QPushButton("Auto")
        self.hbl2.addWidget(self.wbautoroi)

        self.wbresetroi = QtGui.QPushButton("Reset")
        self.hbl2.addWidget(self.wbresetroi)

        self.hbl2.addStretch(5)

        # Widget for setting alignment mask blur and base level
        self.vbl2 = QtGui.QVBoxLayout()
        self.gbl.addLayout(self.vbl2, 6, 2)
        self.vbl2.addStretch(5)

        self.wlroimaskblur = QtGui.QLabel("Blur")
        self.vbl2.addWidget(self.wlroimaskblur)

        self.wsbroimaskblur = QtGui.QSpinBox()
        self.wsbroimaskblur.setRange(0, 25)
        self.vbl2.addWidget(self.wsbroimaskblur)

        self.vbl2.addSpacing(16)

        self.wbroigo = QtGui.QPushButton(QtCore.QChar(0x2192))
        self.vbl2.addWidget(self.wbroigo)

        # widget for displaying the masked ROI
        self.w2droimask = EMImage2DWidget()
        self.gbl.addWidget(self.w2droimask, 6, 3)

        self.vbl2.addStretch(5)

        self.wlarrow1 = QtGui.QLabel(QtCore.QChar(0x2192))
        self.gbl.addWidget(self.wlarrow1, 4, 4)

        ###### Results
        # Widget showing lists of different result sets
        self.vbl3 = QtGui.QVBoxLayout()
        self.gbl.addLayout(self.vbl3, 3, 6, 5, 1)

        self.wllistresult = QtGui.QLabel("Results")
        #		self.wllistresult.setAlignment(Qt.AlignHCenter)
        self.vbl3.addWidget(self.wllistresult)

        self.wlistresult = QtGui.QListWidget()
        self.vbl3.addWidget(self.wlistresult)

        ###### Parameters for processing
        self.vgb1 = QtGui.QGroupBox("Launch Job")
        self.vbl3.addWidget(self.vgb1)

        self.vbl3a = QtGui.QVBoxLayout()
        self.vgb1.setLayout(self.vbl3a)

        self.wvbclasses = ValBox(None, (0, 256), "# Classes", 32)
        self.wvbclasses.setIntonly(True)
        self.vbl3a.addWidget(self.wvbclasses)

        self.wvbnbasis = ValBox(None, (0, 64), "# PCA Vec", 8)
        self.wvbnbasis.setIntonly(True)
        self.vbl3a.addWidget(self.wvbnbasis)

        #self.wvbptclpct=ValBox(None,(0,100),"% Ptcl Incl",60)
        #self.wvbptclpct.setIntonly(True)
        #self.vbl3a.addWidget(self.wvbptclpct)

        ## fill in a default value for number of threads
        #try :
        #cores=num_cpus()
        #except:
        #cores=2
        #if cores==1 : cores=2
        cores = threads + 1  # one thread for GUI

        self.wvbcores = ValBox(None, (0, 256), "# Threads", cores)
        self.wvbcores.setIntonly(True)
        self.vbl3a.addWidget(self.wvbcores)

        self.wcbprocmode = QtGui.QComboBox()
        self.wcbprocmode.addItem("PCA / k-means")
        self.wcbprocmode.addItem("Average Density")
        self.vbl3a.addWidget(self.wcbprocmode)

        self.wpbprogress = QtGui.QProgressBar()
        self.wpbprogress.setEnabled(False)
        self.wpbprogress.setMinimum(0)
        self.wpbprogress.setMaximum(100)
        self.wpbprogress.reset()
        self.vbl3a.addWidget(self.wpbprogress)

        # doubles as a cancel button
        self.wbcompute = QtGui.QPushButton("Compute")
        self.vbl3a.addWidget(self.wbcompute)

        self.wlarrow2 = QtGui.QLabel(QtCore.QChar(0x2192))
        self.gbl.addWidget(self.wlarrow2, 4, 7)

        ###### Output widgets
        # Class-averages
        self.wlclasses = QtGui.QLabel("<big><pre>Classes</pre></big>")
        self.wlclasses.setAlignment(Qt.AlignHCenter)
        self.gbl.addWidget(self.wlclasses, 2, 9)

        self.w2dclasses = EMImage2DWidget()
        self.gbl.addWidget(self.w2dclasses, 3, 9)

        self.wbshowptcl = QtGui.QPushButton(QtCore.QChar(0x2193))
        self.gbl.addWidget(self.wbshowptcl, 4, 9)

        self.w2dptcl = EMImage2DWidget()
        self.gbl.addWidget(self.w2dptcl, 6, 9)

        ## Buttons for controlling mask
        #self.hbl1=QtGui.QHBoxLayout()
        #self.gbl.addLayout(self.hbl1,2,1)
        #self.hbl1.addStretch(5)

        #self.wbautoali=QtGui.QPushButton("Auto")
        #self.hbl1.addWidget(self.wbautoali)

        #self.wbresetali=QtGui.QPushButton("Reset")
        #self.hbl1.addWidget(self.wbresetali)"bdb:%s"

        #self.hbl1.addStretch(5)

        QtCore.QObject.connect(self.wbdrawali, QtCore.SIGNAL("clicked(bool)"),
                               self.aliDrawMode)
        QtCore.QObject.connect(self.wbautoali, QtCore.SIGNAL("clicked(bool)"),
                               self.aliAutoPress)
        QtCore.QObject.connect(self.wbresetali, QtCore.SIGNAL("clicked(bool)"),
                               self.aliResetPress)
        QtCore.QObject.connect(self.wbaligo, QtCore.SIGNAL("clicked(bool)"),
                               self.aliGoPress)
        QtCore.QObject.connect(self.wbrecalcref,
                               QtCore.SIGNAL("clicked(bool)"),
                               self.aliRecalcRefPress)
        QtCore.QObject.connect(self.wbrrecalcref,
                               QtCore.SIGNAL("clicked(bool)"),
                               self.aliRRecalcRefPress)
        QtCore.QObject.connect(self.wbdrawroi, QtCore.SIGNAL("clicked(bool)"),
                               self.roiDrawMode)
        QtCore.QObject.connect(self.wbautoroi, QtCore.SIGNAL("clicked(bool)"),
                               self.roiAutoPress)
        QtCore.QObject.connect(self.wbresetroi, QtCore.SIGNAL("clicked(bool)"),
                               self.roiResetPress)
        QtCore.QObject.connect(self.wbroigo, QtCore.SIGNAL("clicked(bool)"),
                               self.roiGoPress)
        QtCore.QObject.connect(self.wbcompute, QtCore.SIGNAL("clicked(bool)"),
                               self.doCompute)
        QtCore.QObject.connect(self.wbshowptcl, QtCore.SIGNAL("clicked(bool)"),
                               self.showParticles)
        QtCore.QObject.connect(self.wvbiter, QtCore.SIGNAL("valueChanged"),
                               self.newIter)
        QtCore.QObject.connect(self.wvsnum, QtCore.SIGNAL("valueChanged"),
                               self.newThresh)
        QtCore.QObject.connect(self.wbdoavg, QtCore.SIGNAL("clicked(bool)"),
                               self.avgPress)

        QtCore.QObject.connect(self.mfileopen,
                               QtCore.SIGNAL("triggered(bool)"),
                               self.menuFileOpen)

        # set up draw mode
        insp = self.w2dalimaskdraw.get_inspector()
        insp.hide()
        insp.mmtab.setCurrentIndex(5)
        insp.dtpenv.setText("0.0")

        insp = self.w2droimaskdraw.get_inspector()
        insp.hide()
        insp.mmtab.setCurrentIndex(5)
        insp.dtpenv.setText("0.0")

        self.path = path
        QtCore.QTimer.singleShot(500, self.afterStart)
Beispiel #23
0
    def __init__(self,
                 imagenames,
                 voltage=None,
                 apix=None,
                 cs=None,
                 ac=10.0,
                 box=256,
                 ptcl=200):
        """The 'new' e2boxer interface.
		"""

        QtGui.QWidget.__init__(self, None)
        #		self.setWindowIcon(QtGui.QIcon(get_image_directory() + "ctf.png"))

        self.data = None
        self.curfilename = None  # current selected file for boxing
        self.filenames = imagenames  # list of available filenames
        self.micrograph = None
        self.boxes = None

        self.defaultvoltage = voltage
        self.defaultapix = apix
        self.defaultcs = cs
        self.defaultac = ac

        self.db = None  # open JSON file for current image

        self.wimage = EMImage2DWidget()
        self.wimage.setWindowTitle("Micrograph")

        self.wparticles = EMImageMXWidget()
        self.wparticles.setWindowTitle("Particles")

        self.wrefs = EMImageMXWidget()
        self.wrefs.setWindowTitle("Box Refs")

        self.wbadrefs = EMImageMXWidget()
        self.wbadrefs.setWindowTitle("Bad Box Refs")

        #self.wfft=EMImage2DWidget()
        #self.wfft.setWindowTitle("e2evalimage - 2D FFT")

        #self.wplot=EMPlot2DWidget()
        #self.wplot.setWindowTitle("e2evalimage - Plot")

        self.wimage.connect(self.wimage, QtCore.SIGNAL("mousedown"),
                            self.imgmousedown)
        self.wimage.connect(self.wimage, QtCore.SIGNAL("mousedrag"),
                            self.imgmousedrag)
        self.wimage.connect(self.wimage, QtCore.SIGNAL("mouseup"),
                            self.imgmouseup)
        self.wparticles.connect(self.wparticles, QtCore.SIGNAL("mousedown"),
                                self.ptclmousedown)
        self.wparticles.connect(self.wparticles, QtCore.SIGNAL("mousedrag"),
                                self.ptclmousedrag)
        self.wparticles.connect(self.wparticles, QtCore.SIGNAL("mouseup"),
                                self.ptclmouseup)
        self.wrefs.connect(self.wparticles, QtCore.SIGNAL("mousedown"),
                           self.refmousedown)
        self.wrefs.connect(self.wparticles, QtCore.SIGNAL("mousedrag"),
                           self.refmousedrag)
        self.wrefs.connect(self.wparticles, QtCore.SIGNAL("mouseup"),
                           self.refmouseup)

        self.wimage.mmode = "app"
        self.wparticles.mmode = "app"

        # This object is itself a widget we need to set up
        self.gbl = QtGui.QGridLayout(self)
        self.gbl.setMargin(8)
        self.gbl.setSpacing(6)

        # Micrograph list
        self.setlist = QtGui.QListWidget(self)
        self.setlist.setSizePolicy(QtGui.QSizePolicy.Preferred,
                                   QtGui.QSizePolicy.Expanding)
        for i in imagenames:
            self.setlist.addItem(i)
        self.gbl.addWidget(self.setlist, 0, 0, 12, 2)

        self.setlist.connect(self.setlist,
                             QtCore.SIGNAL("currentRowChanged(int)"),
                             self.newSet)
        self.setlist.connect(self.setlist, QtCore.SIGNAL("keypress"),
                             self.listKey)

        # Mouse Modes
        self.mmode = "manual"
        self.boxmm = QtGui.QGroupBox("Mouse Mode", self)
        self.boxmm.setFlat(False)
        self.gbl.addWidget(self.boxmm, 0, 2, 3, 2)

        self.hbl0 = QtGui.QHBoxLayout(self.boxmm)

        self.bmmanual = QtGui.QPushButton("Manual")
        self.bmmanual.setToolTip(
            "Manual selection of particles. No impact on autoselection.")
        self.bmmanual.setAutoExclusive(True)
        self.bmmanual.setCheckable(True)
        self.bmmanual.setChecked(True)
        self.hbl0.addWidget(self.bmmanual)

        self.bmdel = QtGui.QPushButton("Delete")
        self.bmdel.setToolTip(
            "Delete particles from any mode. Can also shift-click in other mouse modes."
        )
        self.bmdel.setAutoExclusive(True)
        self.bmdel.setCheckable(True)
        self.hbl0.addWidget(self.bmdel)

        self.bmgref = QtGui.QPushButton("Good Refs")
        self.bmgref.setToolTip(
            "Identify some good particles. Available to all autoboxers.")
        self.bmgref.setAutoExclusive(True)
        self.bmgref.setCheckable(True)
        self.hbl0.addWidget(self.bmgref)

        self.bmbref = QtGui.QPushButton("Bad Refs")
        self.bmbref.setToolTip(
            "Identify regions which should not be selected as particles.")
        self.bmbref.setAutoExclusive(True)
        self.bmbref.setCheckable(True)
        self.hbl0.addWidget(self.bmbref)

        QtCore.QObject.connect(self.bmmanual, QtCore.SIGNAL("clicked(bool)"),
                               self.setMouseManual)
        QtCore.QObject.connect(self.bmdel, QtCore.SIGNAL("clicked(bool)"),
                               self.setMouseDel)
        QtCore.QObject.connect(self.bmgref, QtCore.SIGNAL("clicked(bool)"),
                               self.setMouseGoodRef)
        QtCore.QObject.connect(self.bmbref, QtCore.SIGNAL("clicked(bool)"),
                               self.setMouseBadRef)

        # Global parameters
        self.boxparm = QtGui.QGroupBox("Parameters", self)
        self.boxparm.setFlat(False)
        self.gbl.addWidget(self.boxparm, 3, 2, 3, 3)

        self.gbl1 = QtGui.QGridLayout(self.boxparm)
        self.gbl1.setMargin(8)
        self.gbl1.setSpacing(6)

        self.vbbsize = ValBox(label="Box Size:", value=box)
        self.gbl1.addWidget(self.vbbsize, 0, 0)

        self.vbbpsize = ValBox(label="Ptcl Size:", value=ptcl)
        self.gbl1.addWidget(self.vbbpsize, 0, 1)

        self.vbbapix = ValBox(label="A/pix:", value=apix)
        self.gbl1.addWidget(self.vbbapix, 0, 2)

        self.vbvoltage = ValBox(label="Voltage:", value=voltage)
        self.gbl1.addWidget(self.vbvoltage, 1, 0)

        self.vbbac = ValBox(label="% AC:", value=ac)
        self.gbl1.addWidget(self.vbbac, 1, 1)

        self.vbcs = ValBox(label="Cs:", value=cs)
        self.gbl1.addWidget(self.vbcs, 1, 2)

        # Autoboxing Tabs
        self.autolbl = QtGui.QLabel("Autoboxing Methods:")
        self.gbl.addWidget(self.autolbl, 7, 2)
        self.autotab = QtGui.QTabWidget()
        self.gbl.addWidget(self.autotab, 8, 2, 6, 3)

        self.bautobox = QtGui.QPushButton("Autobox")
        self.gbl.addWidget(self.bautobox, 7, 4)

        QtCore.QObject.connect(self.bautobox, QtCore.SIGNAL("clicked(bool)"),
                               self.doAutoBox)

        # Individual tabs from Dictionary
        self.abwid = []
        for name, bname, cls in GUIBoxer.aboxmodes:
            w = QtGui.QWidget()
            gl = QtGui.QGridLayout(w)
            self.abwid.append((w, gl))
            cls.setup_gui(gl)
            self.autotab.addTab(w, name)

        self.setWindowTitle("e2boxer21 - Control Panel")

        self.wimage.show()
        #		self.wfft.show()
        #		self.wplot.show()
        E2loadappwin("e2boxer21", "main", self)
        E2loadappwin("e2boxer21", "image", self.wimage.qt_parent)
        E2loadappwin("e2boxer21", "particles", self.wparticles.qt_parent)
        E2loadappwin("e2boxer21", "refs", self.wrefs.qt_parent)
        E2loadappwin("e2boxer21", "badrefs", self.wbadrefs.qt_parent)

        self.newSet(0)