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)
def __init__(self, options): QtWidgets.QMainWindow.__init__(self) if options.twod: self.twodview = EMImage2DWidget() widget = Microscope(self, options, None, None, self.twodview) else: self.imgview = EMImage2DWidget() self.pltview = EMPlot2DWidget() widget = Microscope(self, options, self.imgview, self.pltview, None) #widget = Microscope(self, None, None, None, mode, cs) #widget = Microscope(self, None, None) self.closeEvent=widget.closeEvent self.setCentralWidget(widget)
def main(): usage = " " parser = EMArgumentParser(usage=usage, version=EMANVERSION) parser.add_argument("--label", type=str, help="Load previous contour segmentation.", default="tomobox") parser.add_argument("--gpuid", type=str, help="Specify the gpu to use", default="") parser.add_argument("--mult", type=float, help="multiply data by factor. useful for vpp data...", default=1) #parser.add_argument("--ppid", type=int, help="Set the PID of the parent process, used for cross platform PPID",default=-2) (options, args) = parser.parse_args() logid = E2init(sys.argv) app = EMApp() test = EMImage2DWidget() drawer = EMTomobox(app, options) drawer.show() app.execute() E2end(logid)
def __init__(self, application, options, datafile=None): QtWidgets.QWidget.__init__(self) self.imgview = EMImage2DWidget() self.setCentralWidget(QtWidgets.QWidget()) self.gbl = QtWidgets.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} self.imgview.mouseup.connect(self.on_mouseup) self.imgview.keypress.connect(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)
def __init__(self, application, options, datafile, pks, xfs, dirs): QtWidgets.QWidget.__init__(self) self.imgview = EMImage2DWidget() self.setCentralWidget(QtWidgets.QWidget()) self.gbl = QtWidgets.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)
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() self.mx_display.module_closed.connect(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()
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)
def __init__(self,application,options): self.options=options self.check_path(options.path) self.get_data(0) QtWidgets.QWidget.__init__(self) self.imgview = EMImage2DWidget() self.setCentralWidget(QtWidgets.QWidget()) self.gbl = QtWidgets.QGridLayout(self.centralWidget()) self.lb_name=QtWidgets.QLabel(self.tomoname) self.lb_name.setWordWrap(True) self.gbl.addWidget(self.lb_name, 0,0,1,2) self.iterlst=QtWidgets.QListWidget() self.iterlst.itemflags=Qt.ItemFlags(Qt.ItemIsSelectable) for i in sorted(self.losses.keys()): txt="{:d} : loss = {:.1f}".format(i, self.losses[i]) item=QtWidgets.QListWidgetItem(txt) self.iterlst.addItem(item) self.iterlst.currentRowChanged[int].connect(self.update_list) self.gbl.addWidget(self.iterlst,1,0,1,2) self.app=weakref.ref(application) self.imgview = EMImage2DWidget() self.boxes=Boxes(self.imgview, self.pks2d, self.dirs) self.shape_index = 0 self.imgview.set_data(self.datafile) self.imgview.shapes = {0:self.boxes} self.imgview.show() self.imgview.mouseup.connect(self.on_mouseup) self.boxesviewer=EMImageMXWidget() self.boxesviewer.show() self.boxesviewer.set_mouse_mode("App") self.boxesviewer.setWindowTitle("Landmarks") self.boxesviewer.rzonce=True
def __init__(self,app): # the single image display widget self.im2d = EMImage2DWidget(application=app) # get some signals from the window. self.im2d.mousedown.connect(self.down) self.im2d.mousedrag.connect(self.drag) self.im2d.mouseup.connect(self.up) #self explanatory a=test_image(size=(512,512)) self.im2d.set_data(a) self.im2d.show()
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"
def __init__(self): QtGui.QWidget.__init__(self) self.setWindowTitle("Single Particle View") self.resize(300,300) self.gbl = QtGui.QGridLayout(self) self.xyview = EMImage2DWidget() self.gbl.addWidget(self.xyview,0,1) self.xzview = EMImage2DWidget() self.gbl.addWidget(self.xzview,1,1) self.zyview = EMImage2DWidget() self.gbl.addWidget(self.zyview,0,0) self.data = None # This puts an isosurface view in the lower left corner, but was causing a lot of segfaults, so switching to 2-D slices for now #self.d3view = EMScene3D() #self.d3viewdata = EMDataItem3D(test_image_3d(3), transform=Transform()) #isosurface = EMIsosurface(self.d3viewdata, transform=Transform()) #self.d3view.insertNewNode('', self.d3viewdata, parentnode=self.d3view) #self.d3view.insertNewNode("Iso", isosurface, parentnode=self.d3viewdata ) self.d3view = EMImage2DWidget() self.gbl.addWidget(self.d3view,1,0) self.wfilt = ValSlider(rng=(0,50),label="Filter:",value=0.0) self.gbl.addWidget(self.wfilt,2,0,1,2) self.wfilt.valueChanged.connect(self.event_filter) self.gbl.setRowStretch(2,1) self.gbl.setRowStretch(0,5) self.gbl.setRowStretch(1,5)
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.connect(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()
def display_validation_plots(path, radcut, planethres, plotdatalabels=False, color='#00ff00', plotzaxiscolor=False): from eman2_gui.emimage2d import EMImage2DWidget from eman2_gui.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_()
def __init__(self, application, apix=1.0, voltage=300.0, cs=4.1, ac=10.0, samples=256, apply=None): """CTF simulation dialog """ try: from eman2_gui.emimage2d import EMImage2DWidget except: print("Cannot import EMAN image GUI objects (EMImage2DWidget)") sys.exit(1) try: from eman2_gui.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 if apply == None: self.apply = None self.applyim = None else: self.apply = EMData(apply, 0) self.df_apix = self.apply["apix_x"] print("A/pix reset to ", self.df_apix) self.applyim = EMImage2DWidget(application=self.app()) 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.guiim.mousedown.connect(self.imgmousedown) self.guiim.mousedrag.connect(self.imgmousedrag) self.guiim.mouseup.connect(self.imgmouseup) self.guiplot.mousedown.connect(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:", 100, 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.sphase = ValSlider(self, (0, 1), "Phase/pi", 0, 90) self.vbl.addWidget(self.sphase) 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() self.sdefocus.valueChanged.connect(self.newCTF) self.sbfactor.valueChanged.connect(self.newCTF) self.sdfdiff.valueChanged.connect(self.newCTF) self.sdfang.valueChanged.connect(self.newCTF) self.sapix.valueChanged.connect(self.newCTF) self.sampcont.valueChanged.connect(self.newCTFac) self.sphase.valueChanged.connect(self.newCTFpha) self.svoltage.valueChanged.connect(self.newCTF) self.scs.valueChanged.connect(self.newCTF) self.ssamples.valueChanged.connect(self.newCTF) self.setlist.currentRowChanged[int].connect(self.newSet) self.setlist.keypress.connect(self.listkey) self.splotmode.currentIndexChanged[int].connect(self.newPlotMode) self.newbut.clicked[bool].connect(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")
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)
def __init__(self, application, options, datafile=None): QtWidgets.QWidget.__init__(self) self.imgview = EMImage2DWidget() self.setCentralWidget(QtWidgets.QWidget()) self.gbl = QtWidgets.QGridLayout(self.centralWidget()) self.lb_txt0 = QtWidgets.QLabel("ClassID") self.gbl.addWidget(self.lb_txt0, 0, 0, 1, 1) self.classidbox = QtWidgets.QSpinBox() self.classidbox.setMinimum(0) self.classidbox.setMaximum(5) self.classidbox.setValue(0) self.gbl.addWidget(self.classidbox, 0, 1, 1, 1) self.lb_lines = QtWidgets.QLabel("") self.lb_lines.setWordWrap(True) self.gbl.addWidget(self.lb_lines, 1, 0, 1, 2) self.bt_showimg = QtWidgets.QPushButton("Show tomogram") self.bt_showimg.setToolTip("Show tomogram window") self.gbl.addWidget(self.bt_showimg, 2, 0, 1, 2) self.bt_savepdb = QtWidgets.QPushButton("Save PDB") self.bt_savepdb.setToolTip("Save curves as PDB") self.gbl.addWidget(self.bt_savepdb, 3, 0, 1, 2) self.bt_clear = QtWidgets.QPushButton("Clear") self.bt_clear.setToolTip("Clear all points") self.gbl.addWidget(self.bt_clear, 4, 0, 1, 2) self.bt_interp = QtWidgets.QPushButton("Interpolate") self.bt_interp.setToolTip("Interpolate points") self.gbl.addWidget(self.bt_interp, 5, 0, 1, 1) self.tx_interp = QtWidgets.QLineEdit(self) self.tx_interp.setText("20") self.gbl.addWidget(self.tx_interp, 5, 1, 1, 1) self.classidbox.valueChanged[int].connect(self.classid_change) self.bt_showimg.clicked[bool].connect(self.show_tomo) self.bt_savepdb.clicked[bool].connect(self.save_pdb) self.bt_interp.clicked[bool].connect(self.interp_points) self.bt_clear.clicked[bool].connect(self.clear_points) #self.gbl.addWidget(self.imgview,0,0) self.options = options self.app = weakref.ref(application) self.do_optimize = not options.nooptimize self.datafile = datafile self.data = EMData(datafile) self.imgview.setWindowTitle(base_name(datafile)) self.imgview.list_idx = self.data["nz"] // 2 self.imgview.set_data(self.data) self.imgview.show() self.infofile = info_name(datafile) pts = [] self.apix_scale = 1 self.tomocenter = np.zeros(3) js = js_open_dict(self.infofile) if "apix_unbin" in js: apix_cur = apix = self.data["apix_x"] apix_unbin = js["apix_unbin"] self.apix_scale = apix_cur / apix_unbin self.tomocenter = np.array( [self.data["nx"], self.data["ny"], self.data["nz"]]) / 2 if js.has_key("curves") and len(js["curves"]) > 0: pts = np.array(js["curves"]).copy() if len(pts[0]) < 5: pts = np.hstack([pts, np.zeros((len(pts), 1))]) pts[:, :3] = pts[:, :3] / self.apix_scale + self.tomocenter pts = pts.tolist() else: pts = [] js.close() self.contour = Contour(img=self.imgview, points=pts) self.shape_index = 0 self.imgview.shapes = {0: self.contour} self.imgview.mouseup.connect(self.on_mouseup) self.imgview.keypress.connect(self.key_press) self.update_label() glEnable(GL_POINT_SMOOTH) glEnable(GL_LINE_SMOOTH) glEnable(GL_POLYGON_SMOOTH) glEnable(GL_BLEND) glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
def __init__(self,application,options,datafile): QtWidgets.QWidget.__init__(self) self.initialized=False self.app=weakref.ref(application) self.options=options self.apix=options.apix self.currentset=0 self.shrink=1#options.shrink self.setWindowTitle("Main Window (e2spt_boxer.py)") if options.mode=="3D": self.boxshape="circle" else: self.boxshape="rect" self.globalxf=Transform() # Menu Bar self.mfile=self.menuBar().addMenu("File") #self.mfile_open=self.mfile.addAction("Open") self.mfile_read_boxloc=self.mfile.addAction("Read Box Coord") self.mfile_save_boxloc=self.mfile.addAction("Save Box Coord") self.mfile_save_boxpdb=self.mfile.addAction("Save Coord as PDB") self.mfile_save_boxes_stack=self.mfile.addAction("Save Boxes as Stack") #self.mfile_quit=self.mfile.addAction("Quit") self.setCentralWidget(QtWidgets.QWidget()) self.gbl = QtWidgets.QGridLayout(self.centralWidget()) # relative stretch factors self.gbl.setColumnMinimumWidth(0,200) self.gbl.setRowMinimumHeight(0,200) self.gbl.setColumnStretch(0,0) self.gbl.setColumnStretch(1,100) self.gbl.setColumnStretch(2,0) self.gbl.setRowStretch(1,0) self.gbl.setRowStretch(0,100) # 3 orthogonal restricted projection views self.xyview = EMImage2DWidget(sizehint=(1024,1024)) self.gbl.addWidget(self.xyview,0,1) self.xzview = EMImage2DWidget(sizehint=(1024,256)) self.gbl.addWidget(self.xzview,1,1) self.zyview = EMImage2DWidget(sizehint=(256,1024)) self.gbl.addWidget(self.zyview,0,0) # Select Z for xy view self.wdepth = QtWidgets.QSlider() self.gbl.addWidget(self.wdepth,1,2) ### Control panel area in upper left corner self.gbl2 = QtWidgets.QGridLayout() self.gbl.addLayout(self.gbl2,1,0) #self.wxpos = QtWidgets.QSlider(Qt.Horizontal) #self.gbl2.addWidget(self.wxpos,0,0) #self.wypos = QtWidgets.QSlider(Qt.Vertical) #self.gbl2.addWidget(self.wypos,0,3,6,1) # box size self.wboxsize=ValBox(label="Box Size:",value=0) self.gbl2.addWidget(self.wboxsize,2,0) # max or mean #self.wmaxmean=QtWidgets.QPushButton("MaxProj") #self.wmaxmean.setCheckable(True) #self.gbl2.addWidget(self.wmaxmean,3,0) # number slices label0=QtWidgets.QLabel("Thickness") self.gbl2.addWidget(label0,3,0) self.wnlayers=QtWidgets.QSpinBox() self.wnlayers.setMinimum(1) self.wnlayers.setMaximum(256) self.wnlayers.setValue(1) self.gbl2.addWidget(self.wnlayers,3,1) # Local boxes in side view self.wlocalbox=QtWidgets.QCheckBox("Limit Side Boxes") self.gbl2.addWidget(self.wlocalbox,4,0) self.wlocalbox.setChecked(True) self.button_flat = QtWidgets.QPushButton("Flatten") self.gbl2.addWidget(self.button_flat,5,0) self.button_reset = QtWidgets.QPushButton("Reset") self.gbl2.addWidget(self.button_reset,5,1) ## scale factor #self.wscale=ValSlider(rng=(.1,2),label="Sca:",value=1.0) #self.gbl2.addWidget(self.wscale,4,0,1,2) # 2-D filters self.wfilt = ValSlider(rng=(0,150),label="Filt",value=0.0) self.gbl2.addWidget(self.wfilt,6,0,1,2) self.curbox=-1 self.boxes=[] # array of box info, each is (x,y,z,...) self.boxesimgs=[] # z projection of each box self.dragging=-1 ##coordinate display self.wcoords=QtWidgets.QLabel("") self.gbl2.addWidget(self.wcoords, 1, 0, 1, 2) self.button_flat.clicked[bool].connect(self.flatten_tomo) self.button_reset.clicked[bool].connect(self.reset_flatten_tomo) # file menu #self.mfile_open.triggered[bool].connect(self.menu_file_open) self.mfile_read_boxloc.triggered[bool].connect(self.menu_file_read_boxloc) self.mfile_save_boxloc.triggered[bool].connect(self.menu_file_save_boxloc) self.mfile_save_boxpdb.triggered[bool].connect(self.menu_file_save_boxpdb) self.mfile_save_boxes_stack.triggered[bool].connect(self.save_boxes) #self.mfile_quit.triggered[bool].connect(self.menu_file_quit) # all other widgets self.wdepth.valueChanged[int].connect(self.event_depth) self.wnlayers.valueChanged[int].connect(self.event_nlayers) self.wboxsize.valueChanged.connect(self.event_boxsize) #self.wmaxmean.clicked[bool].connect(self.event_projmode) #self.wscale.valueChanged.connect(self.event_scale) self.wfilt.valueChanged.connect(self.event_filter) self.wlocalbox.stateChanged[int].connect(self.event_localbox) self.xyview.mousemove.connect(self.xy_move) self.xyview.mousedown.connect(self.xy_down) self.xyview.mousedrag.connect(self.xy_drag) self.xyview.mouseup.connect(self.mouse_up) self.xyview.mousewheel.connect(self.xy_wheel) self.xyview.signal_set_scale.connect(self.event_scale) self.xyview.origin_update.connect(self.xy_origin) self.xzview.mousedown.connect(self.xz_down) self.xzview.mousedrag.connect(self.xz_drag) self.xzview.mouseup.connect(self.mouse_up) self.xzview.mousewheel.connect(self.xz_wheel) self.xzview.signal_set_scale.connect(self.event_scale) self.xzview.origin_update.connect(self.xz_origin) self.xzview.mousemove.connect(self.xz_move) self.zyview.mousedown.connect(self.zy_down) self.zyview.mousedrag.connect(self.zy_drag) self.zyview.mouseup.connect(self.mouse_up) self.zyview.mousewheel.connect(self.zy_wheel) self.zyview.signal_set_scale.connect(self.event_scale) self.zyview.origin_update.connect(self.zy_origin) self.zyview.mousemove.connect(self.zy_move) self.xyview.keypress.connect(self.key_press) self.datafilename=datafile self.basename=base_name(datafile) p0=datafile.find('__') if p0>0: p1=datafile.rfind('.') self.filetag=datafile[p0:p1] if self.filetag[-1]!='_': self.filetag+='_' else: self.filetag="__" data=EMData(datafile) self.set_data(data) # Boxviewer subwidget (details of a single box) #self.boxviewer=EMBoxViewer() #self.app().attach_child(self.boxviewer) # Boxes Viewer (z projections of all boxes) self.boxesviewer=EMImageMXWidget() #self.app().attach_child(self.boxesviewer) self.boxesviewer.show() self.boxesviewer.set_mouse_mode("App") self.boxesviewer.setWindowTitle("Particle List") self.boxesviewer.rzonce=True self.setspanel=EMTomoSetsPanel(self) self.optionviewer=EMTomoBoxerOptions(self) self.optionviewer.add_panel(self.setspanel,"Sets") self.optionviewer.show() self.boxesviewer.mx_image_selected.connect(self.img_selected) ################## #### deal with metadata in the _info.json file... self.jsonfile=info_name(datafile) info=js_open_dict(self.jsonfile) #### read particle classes self.sets={} self.boxsize={} if "class_list" in info: clslst=info["class_list"] for k in sorted(clslst.keys()): if type(clslst[k])==dict: self.sets[int(k)]=str(clslst[k]["name"]) self.boxsize[int(k)]=int(clslst[k]["boxsize"]) else: self.sets[int(k)]=str(clslst[k]) self.boxsize[int(k)]=64 clr=QtGui.QColor self.setcolors=[QtGui.QBrush(clr("blue")),QtGui.QBrush(clr("green")),QtGui.QBrush(clr("red")),QtGui.QBrush(clr("cyan")),QtGui.QBrush(clr("purple")),QtGui.QBrush(clr("orange")), QtGui.QBrush(clr("yellow")),QtGui.QBrush(clr("hotpink")),QtGui.QBrush(clr("gold"))] self.sets_visible={} #### read boxes if "boxes_3d" in info: box=info["boxes_3d"] for i,b in enumerate(box): #### X-center,Y-center,Z-center,method,[score,[class #]] bdf=[0,0,0,"manual",0.0, 0] for j,bi in enumerate(b): bdf[j]=bi if bdf[5] not in list(self.sets.keys()): clsi=int(bdf[5]) self.sets[clsi]="particles_{:02d}".format(clsi) self.boxsize[clsi]=64 self.boxes.append(bdf) ###### this is the new (2018-09) metadata standard.. ### now we use coordinates at full size from center of tomogram so it works for different binning and clipping ### have to make it compatible with older versions though.. if "apix_unbin" in info: self.apix_unbin=info["apix_unbin"] self.apix_cur=apix=data["apix_x"] for b in self.boxes: b[0]=b[0]/apix*self.apix_unbin+data["nx"]//2 b[1]=b[1]/apix*self.apix_unbin+data["ny"]//2 b[2]=b[2]/apix*self.apix_unbin+data["nz"]//2 for k in self.boxsize.keys(): self.boxsize[k]=int(np.round(self.boxsize[k]*self.apix_unbin/apix)) else: self.apix_unbin=-1 info.close() E2loadappwin("e2sptboxer","main",self) E2loadappwin("e2sptboxer","boxes",self.boxesviewer.qt_parent) E2loadappwin("e2sptboxer","option",self.optionviewer) #### particle classes if len(self.sets)==0: self.new_set("particles_00") self.sets_visible[list(self.sets.keys())[0]]=0 self.currentset=sorted(self.sets.keys())[0] self.setspanel.update_sets() self.wboxsize.setValue(self.get_boxsize()) #print(self.sets) for i in range(len(self.boxes)): self.update_box(i) self.update_all() self.initialized=True
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 QtWidgets.QWidget.__init__(self, None) self.gbl = QtWidgets.QGridLayout(self) self.gbl.setContentsMargins(0, 0, 0, 0) self.gbl.setSpacing(6) self.gbl.setObjectName("hbl") # action buttons self.bcenalign = QtWidgets.QPushButton("Center Align") self.bprojalign = QtWidgets.QPushButton("Proj. Realign") self.btiltaxis = QtWidgets.QPushButton("Tilt Axis") self.btiltaxisval = QtWidgets.QLineEdit("90.0") self.bsavedata = QtWidgets.QPushButton("Save Data") self.breconst = QtWidgets.QPushButton("3D Normal") self.sbmode = QtWidgets.QSpinBox(self) self.sbmode.setRange(0, 2) self.sbmode.setValue(0) self.bmagict = QtWidgets.QPushButton("3D Tomofill") self.bmagics = QtWidgets.QPushButton("3D Sph") self.bmagicc = QtWidgets.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) self.bcenalign.clicked[bool].connect(self.do_cenalign) self.bprojalign.clicked[bool].connect(self.do_projalign) self.btiltaxis.clicked[bool].connect(self.do_tiltaxis) self.bsavedata.clicked[bool].connect(self.do_savedata) self.breconst.clicked[bool].connect(self.do_reconst) self.bmagict.clicked[bool].connect(self.do_magict) self.bmagics.clicked[bool].connect(self.do_magics) self.bmagicc.clicked[bool].connect(self.do_magicc) self.vslpfilt.valueChanged.connect(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 = EMImage3DWidget(application=app, winid="tomotrackbox.3d") # get some signals from the window. self.im2d.mousedown.connect(self.down) self.im2d.mousedrag.connect(self.drag) self.im2d.mouseup.connect(self.up) self.im2d.signal_increment_list_data.connect(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()
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 eman2_gui.emimage2d import EMImage2DWidget except: ERROR("Cannot import EMAN image GUI objects (EMImage2DWidget)") return try: from eman2_gui.emplot2d import EMPlot2DWidget except: ERROR( "Cannot import EMAN plot GUI objects (is matplotlib installed?)" ) return 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.mousedown.connect(self.imgmousedown) self.guiim.mousedrag.connect(self.imgmousedrag) self.guiim.mouseup.connect(self.imgmouseup) self.guiplot.mousedown.connect(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) self.sdefocus.valueChanged.connect(self.newCTF) self.sbfactor.valueChanged.connect(self.newCTF) # QtCore.QObject.connect(self.sapix, QtCore.SIGNAL("valueChanged"), self.newCTF) self.sampcont.valueChanged.connect(self.newCTF) self.svoltage.valueChanged.connect(self.newCTF) self.scs.valueChanged.connect(self.newCTF) self.setlist.currentRowChanged[int].connect(self.newSet) self.splotmode.currentIndexChanged[int].connect(self.newPlotMode) self.saveparms.clicked[bool].connect(self.on_save_params) self.recallparms.clicked[bool].connect(self.on_recall_params) self.output.clicked[bool].connect(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")
def __init__(self,images,voltage=None,apix=None,cs=None,ac=10.0,box=512,usefoldername=False,constbfactor=-1,fitastig=False,phaseplate=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 eman2_gui.emimage2d import EMImage2DWidget except: print("Cannot import EMAN image GUI objects (EMImage2DWidget)") sys.exit(1) try: from eman2_gui.emplot2d import EMPlot2DWidget except: print("Cannot import EMAN plot GUI objects (is matplotlib installed?)") sys.exit(1) QtWidgets.QWidget.__init__(self,None) self.setWindowIcon(QtGui.QIcon(get_image_directory() + "ctf.png")) 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 range(n): newimages.append(i+",%d"%j) else: h=EMData(i,0,True) # read header n=h["nz"] if n!=1: for j in range(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.mousedown.connect(self.imgmousedown) self.wimage.mousedrag.connect(self.imgmousedrag) self.wimage.mouseup.connect(self.imgmouseup) self.wfft.mousedown.connect(self.fftmousedown) self.wfft.mousedrag.connect(self.fftmousedrag) self.wfft.mouseup.connect(self.fftmouseup) self.wimage.mmode="app" self.wfft.mmode="app" # This object is itself a widget we need to set up self.gbl = QtWidgets.QGridLayout(self) self.gbl.setContentsMargins(8, 8, 8, 8) self.gbl.setSpacing(6) # plot list and plot mode combobox self.setlist=e2ctf.MyListWidget(self) self.setlist.setSizePolicy(QtWidgets.QSizePolicy.Preferred,QtWidgets.QSizePolicy.Expanding) for i in images: self.setlist.addItem(i) self.gbl.addWidget(self.setlist,0,0,8,2) self.lcalcmode=QtWidgets.QLabel("Region:",self) self.gbl.addWidget(self.lcalcmode,10,0) self.scalcmode=QtWidgets.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=QtWidgets.QLabel("2D FFT:",self) self.gbl.addWidget(self.lcalcmode,11,0) self.s2dmode=QtWidgets.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=QtWidgets.QLabel("Annotate:",self) self.gbl.addWidget(self.lcalcmode,12,0) self.s2danmode=QtWidgets.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=QtWidgets.QLabel("Plot:",self) self.gbl.addWidget(self.lcalcmode,13,0) self.splotmode=QtWidgets.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=QtWidgets.QPushButton("Refit") self.gbl.addWidget(self.brefit,7,2) self.cbgadj=CheckBox(None,"CTF BG Adj",1) self.gbl.addWidget(self.cbgadj,10,3) self.castig=CheckBox(None,"Astig:",fitastig) self.gbl.addWidget(self.castig,11,3) self.cphasep=CheckBox(None,"Phaseplate:",phaseplate) self.gbl.addWidget(self.cphasep,12,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=QtWidgets.QGroupBox("Project") self.gbl.addWidget(self.bbox,10,4,4,1) self.bvbl=QtWidgets.QVBoxLayout() self.bbox.setLayout(self.bvbl) self.bimport=QtWidgets.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) self.bimport.clicked[bool].connect(self.doImport) self.brefit.clicked[bool].connect(self.doRefit) self.cbgadj.valueChanged.connect(self.bgAdj) self.sdefocus.valueChanged.connect(self.newCTF) self.sbfactor.valueChanged.connect(self.newCTF) self.sdfdiff.valueChanged.connect(self.newCTF) self.sdfang.valueChanged.connect(self.newCTF) self.sapix.valueChanged.connect(self.newCTF) self.sampcont.valueChanged.connect(self.newCTF) self.svoltage.valueChanged.connect(self.newCTF) self.scs.valueChanged.connect(self.newCTF) self.sboxsize.valueChanged.connect(self.newBox) # QtCore.QObject.connect(self.soversamp, QtCore.SIGNAL("valueChanged"), self.newBox) self.sang45.valueChanged.connect(self.recalc_real) self.squality.valueChanged.connect(self.newQualityFactor) self.setlist.currentRowChanged[int].connect(self.newSet) self.setlist.keypress.connect(self.listkey) self.scalcmode.currentIndexChanged[int].connect(self.newCalcMode) self.s2dmode.currentIndexChanged[int].connect(self.new2DMode) self.s2danmode.currentIndexChanged[int].connect(self.new2DAnMode) self.splotmode.currentIndexChanged[int].connect(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() self.timer.timeout.connect(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)
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, list(range(0, self.nimg, old_div(self.nimg, 20))) ) # read regularly separated images from the file totalling ~20 elif self.nimg > 1: self.origdata = EMData.read_images(data, list(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(old_div(self.ny, 2), 0.0, 1.0, 1) ds = old_div(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)
def menu_add_2dwin(self): if self.viewer == None: return self.viewer.append(EMImage2DWidget()) self.viewer[-1].show() self.needupdate = 1
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()) self.proj_class_viewer.module_closed.connect( self.on_mx_view_closed) # self.proj_class_viewer.set_mouse_mode("App" ) self.proj_class_viewer.mx_image_selected.connect( self.on_mx_image_selected) get_application().show_specific(self.proj_class_viewer) self.proj_class_single = EMImage2DWidget( image=None, application=get_application()) self.proj_class_single.module_closed.connect( 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.on_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()
def __init__(self,application,options,datafile=None): QtWidgets.QWidget.__init__(self) self.setMinimumSize(700,200) #### load references first self.reffile="info/boxrefs3d.hdf" if os.path.isfile(self.reffile): self.references=EMData.read_images(self.reffile) else: self.references=[] self.path="tomograms/" self.setCentralWidget(QtWidgets.QWidget()) self.gbl = QtWidgets.QGridLayout(self.centralWidget()) self.imglst=QtWidgets.QTableWidget(1, 5, self) #self.imglst.verticalHeader().hide() for i,w in enumerate([50,200,70,70,70]): self.imglst.setColumnWidth(i,w) self.imglst.setMinimumSize(450, 100) self.gbl.addWidget(self.imglst, 0,4,10,10) self.bt_new=QtWidgets.QPushButton("New") self.bt_new.setToolTip("Build new neural network") self.gbl.addWidget(self.bt_new, 0,0,1,2) self.bt_load=QtWidgets.QPushButton("Load") self.bt_load.setToolTip("Load neural network") self.gbl.addWidget(self.bt_load, 1,0,1,2) self.bt_train=QtWidgets.QPushButton("Train") self.bt_train.setToolTip("Train neural network") self.gbl.addWidget(self.bt_train, 2,0,1,2) self.bt_save=QtWidgets.QPushButton("Save") self.bt_save.setToolTip("Save neural network") self.gbl.addWidget(self.bt_save, 3,0,1,2) self.bt_apply=QtWidgets.QPushButton("Apply") self.bt_apply.setToolTip("Apply neural network") self.gbl.addWidget(self.bt_apply, 4,0,1,2) self.bt_chgbx=QtWidgets.QPushButton("ChangeBx") self.bt_chgbx.setToolTip("Change box size") self.gbl.addWidget(self.bt_chgbx, 5,0,1,2) self.bt_applyall=QtWidgets.QPushButton("ApplyAll") self.bt_applyall.setToolTip("Apply to all tomograms") self.gbl.addWidget(self.bt_applyall, 6,0,1,2) self.box_display = QtWidgets.QComboBox() self.box_display.addItem("References") self.box_display.addItem("Particles") self.gbl.addWidget(self.box_display, 0,2,1,1) self.bt_new.clicked[bool].connect(self.new_nnet) self.bt_load.clicked[bool].connect(self.load_nnet) self.bt_train.clicked[bool].connect(self.train_nnet) self.bt_save.clicked[bool].connect(self.save_nnet) self.bt_apply.clicked[bool].connect(self.apply_nnet) self.bt_chgbx.clicked[bool].connect(self.change_boxsize) self.bt_applyall.clicked[bool].connect(self.apply_nnet_all) self.box_display.currentIndexChanged.connect(self.do_update) self.val_targetsize=TextBox("TargetSize", 1) self.gbl.addWidget(self.val_targetsize, 1,2,1,1) self.val_learnrate=TextBox("LearnRate", 1e-4) self.gbl.addWidget(self.val_learnrate, 2,2,1,1) self.val_ptclthr=TextBox("PtclThresh", 0.8) self.gbl.addWidget(self.val_ptclthr, 3,2,1,1) self.val_circlesize=TextBox("CircleSize", 24) self.gbl.addWidget(self.val_circlesize, 4,2,1,1) self.val_niter=TextBox("Niter", 20) self.gbl.addWidget(self.val_niter, 5,2,1,1) self.val_posmult=TextBox("PosMult", 1) self.gbl.addWidget(self.val_posmult, 6,2,1,1) self.val_lossfun = QtWidgets.QComboBox() self.val_lossfun.addItem("Sum") self.val_lossfun.addItem("Max") self.gbl.addWidget(self.val_lossfun, 7,2,1,1) self.options=options self.app=weakref.ref(application) self.nnet=None global tf tf=import_tensorflow(options.gpuid) self.nnetsize=96 if len(self.references)==0: self.boxsize=self.nnetsize else: self.boxsize=self.references[0]["boxsz"] self.thick=9 self.datafile="" self.data=None if not os.path.isdir("neuralnets"): os.mkdir("neuralnets") self.imgview = EMImage2DWidget() self.boxesviewer=[EMImageMXWidget(), EMImageMXWidget()] self.boxesviewer[0].setWindowTitle("Negative") self.boxesviewer[1].setWindowTitle("Positive") self.ptclviewer=EMImageMXWidget() self.ptclviewer.setWindowTitle("Particles") for boxview in (self.boxesviewer+[self.ptclviewer]): boxview.usetexture=False boxview.show() boxview.set_mouse_mode("App") boxview.rzonce=True self.boximages=[] self.ptclimages=[] for img in self.references: self.add_boximage(img) self.imgview.mouseup.connect(self.on_tomo_mouseup) self.imgview.keypress.connect(self.key_press) self.boxesviewer[0].mx_image_selected.connect(self.on_boxpos_selected) self.boxesviewer[1].mx_image_selected.connect(self.on_boxneg_selected) self.ptclviewer.mx_image_selected.connect(self.on_ptcl_selected) self.imglst.cellClicked[int, int].connect(self.on_list_selected) self.boxshapes=BoxShapes(img=self.imgview, points=[] ) self.imgview.shapes = {0:self.boxshapes} glEnable(GL_POINT_SMOOTH) glEnable(GL_LINE_SMOOTH ); glEnable(GL_POLYGON_SMOOTH ); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); self.trainset=[] self.tomoinp=[] self.segout=None self.curinfo=None self.update_list() self.do_update()
def __init__(self, options): self.path = "tomograms/" QtWidgets.QWidget.__init__(self, None) self.win_size = [1000, 680] self.setMinimumSize(self.win_size[0], self.win_size[1]) # This object is itself a widget we need to set up self.gbl = QtWidgets.QGridLayout(self) self.gbl.setContentsMargins(8, 8, 8, 8) self.gbl.setSpacing(6) self.gbl.setColumnStretch(0, 4) self.gbl.setColumnStretch(1, 1) self.gbl.setColumnStretch(2, 1) self.gbl.setRowStretch(0, 1) # Micrograph list self.imglst = QtWidgets.QTableWidget(1, 3, self) self.imglst.verticalHeader().hide() self.gbl.addWidget(self.imglst, 0, 0, 11, 1) self.imglst.setColumnWidth(0, 50) self.imglst.setColumnWidth(1, 200) self.imglst_srtby = 0 hdr = self.imglst.horizontalHeader() self.imglst.cellClicked[int, int].connect(self.selimg) hdr.sectionPressed[int].connect(self.sortlst) self.wg_thumbnail = EMImage2DWidget(parent=self) self.wg_thumbnail.set_scale(1) self.wg_thumbnail_width = old_div(self.size().width(), 3) * .9 self.wg_thumbnail.resize(self.wg_thumbnail_width, self.wg_thumbnail_width) #print self.wg_thumbnail_width self.wg_thumbnail.setMinimumHeight(330) self.gbl.addWidget(self.wg_thumbnail, 0, 1, 3, 2) self.bt_show2d = QtWidgets.QPushButton("Show2D") self.bt_show2d.setToolTip("Show 2D images") self.gbl.addWidget(self.bt_show2d, 4, 1, 1, 2) self.bt_runboxer = QtWidgets.QPushButton("Boxer") self.bt_runboxer.setToolTip("Run spt_boxer") self.gbl.addWidget(self.bt_runboxer, 5, 1) self.bt_refresh = QtWidgets.QPushButton("Refresh") self.bt_refresh.setToolTip("Refresh") self.gbl.addWidget(self.bt_refresh, 5, 2) self.bt_showtlts = QtWidgets.QPushButton("ShowTilts") self.bt_showtlts.setToolTip("Show raw tilt series") self.gbl.addWidget(self.bt_showtlts, 6, 1) self.bt_plottpm = QtWidgets.QPushButton("TiltParams") self.bt_plottpm.setToolTip("Plot tilt parameters") self.gbl.addWidget(self.bt_plottpm, 6, 2) self.bt_plotloss = QtWidgets.QPushButton("PlotLoss") self.bt_plotloss.setToolTip("Plot alignment loss") self.gbl.addWidget(self.bt_plotloss, 7, 1) self.bt_plotctf = QtWidgets.QPushButton("PlotCtf") self.bt_plotctf.setToolTip("Plot CTF estimation") self.gbl.addWidget(self.bt_plotctf, 7, 2) self.bt_show2d.clicked[bool].connect(self.show2d) self.bt_runboxer.clicked[bool].connect(self.runboxer) self.bt_plotloss.clicked[bool].connect(self.plot_loss) self.bt_plottpm.clicked[bool].connect(self.plot_tltparams) self.bt_showtlts.clicked[bool].connect(self.show_tlts) self.bt_refresh.clicked[bool].connect(self.update_files) self.bt_plotctf.clicked[bool].connect(self.plot_ctf) self.wg_2dimage = EMImage2DWidget() self.wg_2dimage.setWindowTitle("Tomo2D") self.cur_data = None self.wg_tltimage = EMImage2DWidget() self.wg_tltimage.setWindowTitle("Tiltseries") self.wg_tltimage.set_scale(.2) self.cur_tlt = None self.setspanel = TomoListWidget(self) self.gbl.addWidget(self.setspanel, 8, 1, 2, 2) self.wg_notes = QtWidgets.QLineEdit(self) self.wg_notes.setText("Comments:") #self.wg_notes.setStyleSheet("color: rgb(150, 150, 150);") self.gbl.addWidget(self.wg_notes, 10, 1, 1, 2) #self.setspanel.itemClicked[QtWidgets.QListWidgetItem].connect(self.clickset) self.wg_notes.textChanged.connect(self.noteupdate) self.wg_plot2d = EMPlot2DWidget() self.update_files()
def display_validation_plots(path, radcut, planethres, plotdatalabels=False, color='#00ff00', plotzaxiscolor=False): # In some cases it is impossible to import PyQT4, particularly on clusters try: from PyQt5 import QtCore, QtGui, QtWidgets, QtOpenGL # from eman2_gui.emshape import * from eman2_gui.valslider import ValSlider from eman2_gui.emplot2d import EMPolarPlot2DWidget except: class dummy(object): pass class QWidget(object): "A dummy class for use when Qt not installed" def __init__(self, parent): print("Qt4 has not been loaded") QtGui = dummy() QtWidgets.QWidget = QWidget from eman2_gui.emimage2d import EMImage2DWidget from eman2_gui.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_() # Compute a RGB value to represent a data range. Basically convert Hue to GSB with I=0.33 and S=1.0 def computeRGBcolor(value, minval, maxval): # Normalize from 0 to 1 normval = old_div((value - minval), (maxval - minval)) radval = normval * 2 * math.pi if radval < 2 * math.pi / 3: B = 0.0 R = 0.33 * (1 + old_div(math.cos(radval), math.cos(old_div(math.pi, 3) - radval))) G = 1.0 - R return "#%02x%02x%02x" % (255 * R, 255 * G, 255 * B) if radval > 2 * math.pi / 3 and radval < 4 * math.pi / 3: hue = radval - 2 * math.pi / 3 R = 0.0 G = 0.33 * (1 + old_div(math.cos(hue), math.cos(old_div(math.pi, 3) - hue))) B = 1.0 - G return "#%02x%02x%02x" % (255 * R, 255 * G, 255 * B) if radval > 4 * math.pi / 3: hue = radval - 4 * math.pi / 3 G = 0 B = 0.33 * (1 + old_div(math.cos(hue), math.cos(old_div(math.pi, 3) - hue))) R = 1.0 - B return "#%02x%02x%02x" % (255 * R, 255 * G, 255 * B) class EMValidationPlot(QtWidgets.QWidget): """Make a plot to display validation info""" def __init__(self): QtWidgets.QWidget.__init__(self) box = QtWidgets.QVBoxLayout() self.polarplot = EMPolarPlot2DWidget() self.polarplot.setMinimumHeight(50) self.polarplot.setMinimumWidth(50) self.resize(480, 580) meanAngLabel = QtWidgets.QLabel("Mean Tilt Angle") self.meanAngle = QtWidgets.QLineEdit("") meanAxisLabel = QtWidgets.QLabel("Mean Tilt Axis") self.meanAxis = QtWidgets.QLineEdit("") rmsdAngLabel = QtWidgets.QLabel("RMSD Tilt Angle") self.rmsdAngle = QtWidgets.QLineEdit("") rmsdAxisLabel = QtWidgets.QLabel("RMSD Tilt Axis") self.rmsdAxis = QtWidgets.QLineEdit("") pointsLabel = QtWidgets.QLabel("Num points") self.points = QtWidgets.QLineEdit("") self.pointlabel = QtWidgets.QLabel( "Right click to pick the nearest point") frame = QtWidgets.QFrame() frame.setFrameShape(QtWidgets.QFrame.StyledPanel) frame.setMaximumHeight(100) grid = QtWidgets.QGridLayout() grid.addWidget(meanAngLabel, 0, 0) grid.addWidget(self.meanAngle, 0, 1) grid.addWidget(meanAxisLabel, 0, 2) grid.addWidget(self.meanAxis, 0, 3) grid.addWidget(rmsdAngLabel, 1, 0) grid.addWidget(self.rmsdAngle, 1, 1) grid.addWidget(rmsdAxisLabel, 1, 2) grid.addWidget(self.rmsdAxis, 1, 3) grid.addWidget(self.pointlabel, 2, 0, 1, 2) grid.addWidget(pointsLabel, 2, 2) grid.addWidget(self.points, 2, 3) frame.setLayout(grid) box.addWidget(self.polarplot) box.addWidget(frame) self.setLayout(box) self.polarplot.clusterStats.connect(self._on_stats) def _on_stats(self, stats): """ Set the selected stats """ self.meanAngle.setText(str(round(stats[1], 2))) self.meanAxis.setText(str(round(stats[0], 2))) self.rmsdAngle.setText(str(round(stats[3], 2))) self.rmsdAxis.setText(str(round(stats[2], 2))) self.points.setText(str(stats[4])) def _on_point(self, point): """ Set the selected point""" self.pointlabel.setText("You selected the point: %s" % str(point)) def set_data(self, data, linewidth, radcut, datapoints): self.polarplot.set_data(data, linewidth=linewidth, radcut=radcut, datapoints=datapoints) def set_datalabelscolor(self, color): self.polarplot.setDataLabelsColor(color) def set_scattercolor(self, color): self.polarplot.setScatterColor(color)
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) if self.dataidx >= 0 and self.dataidx < self.nimg: ii = self.dataidx self.nimg = 1 else: ii = 0 hdr = EMData(data, 0, 1) self.origdata = EMData(data, ii) if self.origdata["nz"] == 1: if self.nimg > 20 and hdr["ny"] > 512: self.origdata = EMData.read_images( data, list(range(0, self.nimg, self.nimg // 20)) ) # read regularly separated images from the file totalling ~20 elif self.nimg > 100: self.origdata = EMData.read_images( data, list(range(0, 72)) + list(range(72, self.nimg, self.nimg // 100)) ) # read the first 36 then regularly separated images from the file elif self.nimg > 1: self.origdata = EMData.read_images(data, list(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(old_div(self.ny, 2), 0.0, 1.0, 1) ds = old_div(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 or (self.nx > 320 and self.safemode == False): if len(self.origdata) > 1: self.viewer = [EMImageMXWidget()] self.mfile_save_stack.setEnabled(True) else: self.viewer = [EMImage2DWidget()] self.mfile_save_stack.setEnabled(False) else: self.mfile_save_stack.setEnabled(False) 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) if self.nz > 1: self.mfile_save_map.setEnabled(True) else: self.mfile_save_map.setEnabled(False) E2loadappwin("e2filtertool", "image", self.viewer[0].qt_parent) if self.origdata[0].has_attr("source_path"): winname = str(self.origdata[0]["source_path"]) else: winname = "FilterTool" self.viewer[0].setWindowTitle(winname) self.procChange(-1)
def __init__(self, options): self.path = "tomograms/" QtGui.QWidget.__init__(self, None) self.win_size = [1000, 680] self.setMinimumSize(self.win_size[0], self.win_size[1]) # This object is itself a widget we need to set up self.gbl = QtGui.QGridLayout(self) self.gbl.setMargin(8) self.gbl.setSpacing(6) self.gbl.setColumnStretch(0, 4) self.gbl.setColumnStretch(1, 1) self.gbl.setColumnStretch(2, 1) self.gbl.setRowStretch(0, 1) # Micrograph list self.imglst = QtGui.QTableWidget(1, 3, self) self.imglst.verticalHeader().hide() self.gbl.addWidget(self.imglst, 0, 0, 11, 1) self.imglst.setColumnWidth(0, 50) self.imglst.setColumnWidth(1, 200) self.imglst_srtby = 0 hdr = self.imglst.horizontalHeader() QtCore.QObject.connect(self.imglst, QtCore.SIGNAL("cellClicked(int,int)"), self.selimg) QtCore.QObject.connect(hdr, QtCore.SIGNAL("sectionPressed(int)"), self.sortlst) self.wg_thumbnail = EMImage2DWidget(parent=self) self.wg_thumbnail.set_scale(1) self.wg_thumbnail_width = self.size().width() / 3 * .9 self.wg_thumbnail.resize(self.wg_thumbnail_width, self.wg_thumbnail_width) #print self.wg_thumbnail_width self.wg_thumbnail.setMinimumHeight(330) self.gbl.addWidget(self.wg_thumbnail, 0, 1, 3, 2) self.bt_show2d = QtGui.QPushButton("Show2D") self.bt_show2d.setToolTip("Show 2D images") self.gbl.addWidget(self.bt_show2d, 4, 1, 1, 2) self.bt_runboxer = QtGui.QPushButton("Boxer") self.bt_runboxer.setToolTip("Run spt_boxer") self.gbl.addWidget(self.bt_runboxer, 5, 1) self.bt_refresh = QtGui.QPushButton("Refresh") self.bt_refresh.setToolTip("Refresh") self.gbl.addWidget(self.bt_refresh, 5, 2) self.bt_showtlts = QtGui.QPushButton("ShowTilts") self.bt_showtlts.setToolTip("Show raw tilt series") self.gbl.addWidget(self.bt_showtlts, 6, 1) self.bt_plottpm = QtGui.QPushButton("TiltParams") self.bt_plottpm.setToolTip("Plot tilt parameters") self.gbl.addWidget(self.bt_plottpm, 6, 2) self.bt_plotloss = QtGui.QPushButton("PlotLoss") self.bt_plotloss.setToolTip("Plot alignment loss") self.gbl.addWidget(self.bt_plotloss, 7, 1) self.bt_plotctf = QtGui.QPushButton("PlotCtf") self.bt_plotctf.setToolTip("Plot CTF estimation") self.gbl.addWidget(self.bt_plotctf, 7, 2) QtCore.QObject.connect(self.bt_show2d, QtCore.SIGNAL("clicked(bool)"), self.show2d) QtCore.QObject.connect(self.bt_runboxer, QtCore.SIGNAL("clicked(bool)"), self.runboxer) QtCore.QObject.connect(self.bt_plotloss, QtCore.SIGNAL("clicked(bool)"), self.plot_loss) QtCore.QObject.connect(self.bt_plottpm, QtCore.SIGNAL("clicked(bool)"), self.plot_tltparams) QtCore.QObject.connect(self.bt_showtlts, QtCore.SIGNAL("clicked(bool)"), self.show_tlts) QtCore.QObject.connect(self.bt_refresh, QtCore.SIGNAL("clicked(bool)"), self.update_files) QtCore.QObject.connect(self.bt_plotctf, QtCore.SIGNAL("clicked(bool)"), self.plot_ctf) self.wg_2dimage = EMImage2DWidget() self.wg_2dimage.setWindowTitle("Tomo2D") self.cur_data = None self.wg_tltimage = EMImage2DWidget() self.wg_tltimage.setWindowTitle("Tiltseries") self.wg_tltimage.set_scale(.2) self.cur_tlt = None self.setspanel = QtGui.QListWidget(self) self.gbl.addWidget(self.setspanel, 8, 1, 2, 2) self.itemflags = Qt.ItemFlags(Qt.ItemIsEditable) | Qt.ItemFlags( Qt.ItemIsSelectable) | Qt.ItemFlags( Qt.ItemIsEnabled) | Qt.ItemFlags(Qt.ItemIsUserCheckable) self.wg_notes = QtGui.QTextEdit(self) self.gbl.addWidget(self.wg_notes, 10, 1, 1, 2) QtCore.QObject.connect(self.setspanel, QtCore.SIGNAL("itemChanged(QListWidgetItem*)"), self.clickset) QtCore.QObject.connect(self.wg_notes, QtCore.SIGNAL("textChanged()"), self.noteupdate) self.wg_plot2d = EMPlot2DWidget() self.update_files()