def onClickIndirectPlot(self): overplot = self.indirect_plotover.isChecked() createws = self.indirect_createws.isChecked() inst = str(self.indirect_inst_box.currentText()) ana = str(self.indirect_ef_input.currentText()) ef = self.indirect_analysers[inst][ana] try: self.indirect_input_check(ana) Emax = float(self.indirect_emax_input.text()) except ValueError: Emax = abs(ef) qe = calcQE([-ef], self.tthlims, emax=Emax) if not overplot: self.xlim = 0 self.axes.clear() self.axes.axhline(color='k') else: if matplotlib.compare_versions('2.1.0',matplotlib.__version__): self.axes.hold(True) # hold is deprecated since 2.1.0, true by default line, = self.axes.plot(qe[0][0], qe[0][1]) line.set_label(inst + '_' + ana) if max(qe[0][0]) > self.xlim: self.xlim = max(qe[0][0]) if createws: mantid.simpleapi.CreateWorkspace(DataX=qe[0][0], DataY=qe[0][1], NSpec=1, OutputWorkspace=str('QECoverage_' + inst + '_' + ana)) self.axes.set_xlim([0, self.xlim]) self.axes.set_xlabel(r'$|Q|$ ($\AA^{-1}$)') self.axes.set_ylabel('Energy Transfer (meV)') self.axes.legend() self.canvas.draw()
def plot_res(self): """ Plots the resolution in the resolution tab """ overplot = self.widgets['HoldCheck'].isChecked() multiplot = self.widgets['MultiRepCheck'].isChecked() self._set_overplot(overplot, 'resaxes') self._set_overplot(overplot, 'qeaxes') inst = self.engine.instname freq = self.engine.getFrequency() if hasattr(freq, '__len__'): freq = freq[0] if multiplot: if matplotlib.compare_versions('2.1.0', matplotlib.__version__): self.resaxes.hold(True) for ie, Ei in enumerate(self.eis): en = np.linspace(0, 0.95 * Ei, 200) if any(self.res[ie]): if not self.flux[ie]: continue line, = self.resaxes.plot(en, self.res[ie]) label_text = '%s_%3.2fmeV_%dHz_Flux=%fn/cm2/s' % ( inst, Ei, freq, self.flux[ie]) line.set_label(label_text) if self.tabs.isTabEnabled(self.qetabID): self.plot_qe(Ei, label_text, hold=True) self.resaxes_xlim = max(Ei, self.resaxes_xlim) if matplotlib.compare_versions('2.1.0', matplotlib.__version__): self.resaxes.hold(False) else: ei = self.engine.getEi() en = np.linspace(0, 0.95 * ei, 200) line, = self.resaxes.plot(en, self.res) chopper = self.engine.getChopper() label_text = '%s_%s_%3.2fmeV_%dHz_Flux=%fn/cm2/s' % ( inst, chopper, ei, freq, self.flux) line.set_label(label_text) if self.tabs.isTabEnabled(self.qetabID): self.plot_qe(ei, label_text, overplot) self.resaxes_xlim = max(ei, self.resaxes_xlim) self.resaxes.set_xlim([0, self.resaxes_xlim]) self.resaxes.legend().draggable() self.resaxes.set_xlabel('Energy Transfer (meV)') self.resaxes.set_ylabel(r'$\Delta$E (meV FWHM)') self.rescanvas.draw()
def _set_overplot(self, overplot, axisname): axis = getattr(self, axisname) if overplot: if matplotlib.compare_versions('2.1.0', matplotlib.__version__): axis.hold(True) else: setattr(self, axisname + '_xlim', 0) axis.clear() axis.axhline(color='k')
def _set_overplot(self, overplot, axisname): axis = getattr(self, axisname) if overplot: if matplotlib.compare_versions('2.1.0',matplotlib.__version__): axis.hold(True) else: setattr(self, axisname+'_xlim', 0) axis.clear() axis.axhline(color='k')
def onClickDirectPlot(self): overplot = self.direct_plotover.isChecked() createws = self.direct_createws.isChecked() ei_str = self.direct_ei_input.text() eierr = '-----------------------------------------------------------------------------------\n' eierr += 'Error: Invalid input Ei. This must be a number or a comma-separated list of numbers\n' eierr += '-----------------------------------------------------------------------------------\n' ei_vec = [] if ',' not in ei_str: try: ei_vec.append(float(ei_str)) ei_vec = self.direct_input_check(ei_vec) except ValueError: self.emptyfield_msgbox.show() raise ValueError(eierr) else: try: ei_vec = [float(val) for val in ei_str.split(',')] ei_vec = self.direct_input_check(ei_vec) except ValueError: self.emptyfield_msgbox.show() raise ValueError(eierr) try: Emin = float(self.direct_emin_input.text()) except ValueError: Emin = -max(ei_vec) qe = calcQE(ei_vec, self.tthlims, emin=Emin) if not overplot: self.xlim = 0 self.axes.clear() self.axes.axhline(color='k') if matplotlib.compare_versions('2.1.0', matplotlib.__version__): self.axes.hold( True) # hold is deprecated since 2.1.0, true by default Inst = self.direct_inst_box.currentText() for n in range(len(qe)): name = Inst + '_Ei=' + str(ei_vec[n]) line, = self.axes.plot(qe[n][0], qe[n][1]) line.set_label(name) if max(qe[n][0]) > self.xlim: self.xlim = max(qe[n][0]) if createws: mantid.simpleapi.CreateWorkspace( DataX=qe[n][0], DataY=qe[n][1], NSpec=1, OutputWorkspace=str('QECoverage_' + name)) self.axes.set_xlim([0, self.xlim]) self.axes.set_xlabel(r'$|Q|$ ($\AA^{-1}$)') self.axes.set_ylabel('Energy Transfer (meV)') self.axes.legend() self.canvas.draw()
def plot_res(self): """ Plots the resolution in the resolution tab """ overplot = self.widgets['HoldCheck'].isChecked() multiplot = self.widgets['MultiRepCheck'].isChecked() self._set_overplot(overplot, 'resaxes') self._set_overplot(overplot, 'qeaxes') inst = self.engine.instname freq = self.engine.getFrequency() if hasattr(freq, '__len__'): freq = freq[0] if multiplot: if matplotlib.compare_versions('2.1.0',matplotlib.__version__): self.resaxes.hold(True) for ie, Ei in enumerate(self.eis): en = np.linspace(0, 0.95*Ei, 200) if any(self.res[ie]): if not self.flux[ie]: continue line, = self.resaxes.plot(en, self.res[ie]) label_text = '%s_%3.2fmeV_%dHz_Flux=%fn/cm2/s' % (inst, Ei, freq, self.flux[ie]) line.set_label(label_text) if self.tabs.isTabEnabled(self.qetabID): self.plot_qe(Ei, label_text, hold=True) self.resaxes_xlim = max(Ei, self.resaxes_xlim) if matplotlib.compare_versions('2.1.0',matplotlib.__version__): self.resaxes.hold(False) else: ei = self.engine.getEi() en = np.linspace(0, 0.95*ei, 200) line, = self.resaxes.plot(en, self.res) chopper = self.engine.getChopper() label_text = '%s_%s_%3.2fmeV_%dHz_Flux=%fn/cm2/s' % (inst, chopper, ei, freq, self.flux) line.set_label(label_text) if self.tabs.isTabEnabled(self.qetabID): self.plot_qe(ei, label_text, overplot) self.resaxes_xlim = max(ei, self.resaxes_xlim) self.resaxes.set_xlim([0, self.resaxes_xlim]) self.resaxes.legend().draggable() self.resaxes.set_xlabel('Energy Transfer (meV)') self.resaxes.set_ylabel(r'$\Delta$E (meV FWHM)') self.rescanvas.draw()
def __init__(self, parent, main, contact=None): super(Statistics, self).__init__(parent) self.parent = parent self.main = main self.log = main.log self.connection = main.connection self.database = main.database self.settings = main.settings self.helper = main.helper self.setupUi(self) main.setupButtonBox(self.buttonBox) self.graphLayout = StatisticGraphLayout.Stacked self.lastRequest = None self.connect(self.statisticTab, SIGNAL("currentChanged(int)"), lambda x: self.refreshStatistic()) self.connect(self.infoBrowser, SIGNAL("anchorClicked(const QUrl &)"), self.refreshStatistic) self.connect(self.filterBox, SIGNAL("currentIndexChanged(int)"), lambda x: self.refreshStatistic(reset=False)) self.connect(self.contactBox, SIGNAL("currentIndexChanged(int)"), lambda x: self.refreshStatistic(reset=False)) self.connect(self.viewBox, SIGNAL("currentIndexChanged(int)"), lambda x: self.refreshStatistic()) self.connect(self.stackedAction, SIGNAL("triggered()"), self.stackedGraph) self.connect(self.separateAction, SIGNAL("triggered()"), self.separateGraph) self.show() if USE_MATPLOTLIB: self.log.info(QString("Matplotlib found - generating statistics")) else: self.log.info(QString("Matplotlib not found :-(")) # On older versions of matplotlib the default size of the matplotlib widget is incorrect if USE_MATPLOTLIB: self.log.info( QString("Using matplotlib version %1").arg( matplotlib.__version__)) if not matplotlib.compare_versions(matplotlib.__version__, '0.98.6svn'): self.log.warning( QString( "too old version of matplotlib - faking widget size")) self.resize(self.size().width() + 1, self.size().height() + 1) self.resize(self.size().width() - 1, self.size().height() - 1) self.insertContacts(contact) self.refreshStatistic()
def plot_flux_hz(self): """ Plots the flux vs freq in the middle tab """ inst = self.engine.instname chop = self.engine.getChopper() ei = float(self.widgets['EiEdit']['Edit'].text()) overplot = self.widgets['HoldCheck'].isChecked() # Do not recalculate if one of the plots has the same parametersc _, labels = self.frqaxes2.get_legend_handles_labels() searchStr = '([A-Z]+) "(.+)" Ei = ([0-9.-]+) meV' if labels and (overplot or len(labels) == 1): for prevtitle in labels: prevInst, prevChop, prevEi = re.search(searchStr, prevtitle).groups() if inst == prevInst and chop == prevChop and abs( ei - float(prevEi)) < 0.01: return freq0 = self.engine.getFrequency() rep = self.engine.moderator.source_rep maxfreq = self.engine.chopper_system.max_frequencies freqs = range( rep, (maxfreq[0] if hasattr(maxfreq, '__len__') else maxfreq) + 1, rep) flux = np.zeros(len(freqs)) elres = np.zeros(len(freqs)) for ie, freq in enumerate(freqs): if hasattr(freq0, '__len__'): self.setFreq(manual_freq=[freq] + freq0[1:]) else: self.setFreq(manual_freq=freq) with warnings.catch_warnings(record=True): warnings.simplefilter('always', UserWarning) flux[ie] = self.engine.getFlux(ei) elres[ie] = self.engine.getResolution(0., ei)[0] if overplot: if matplotlib.compare_versions('2.1.0', matplotlib.__version__): self.frqaxes1.hold(True) self.frqaxes2.hold(True) else: self.frqaxes1.clear() self.frqaxes2.clear() self.setFreq(manual_freq=freq0) self.frqaxes1.set_xlabel('Chopper Frequency (Hz)') self.frqaxes1.set_ylabel('Flux (n/cm$^2$/s)') line, = self.frqaxes1.plot(freqs, flux, 'o-') self.frqaxes1.set_xlim([0, np.max(freqs)]) self.frqaxes2.set_xlabel('Chopper Frequency (Hz)') self.frqaxes2.set_ylabel('Elastic Resolution FWHM (meV)') line, = self.frqaxes2.plot(freqs, elres, 'o-') line.set_label('%s "%s" Ei = %5.3f meV' % (inst, chop, ei)) lg = self.frqaxes2.legend() lg.draggable() self.frqaxes2.set_xlim([0, np.max(freqs)]) self.frqcanvas.draw()
def onClickDirectPlot(self): overplot = self.direct_plotover.isChecked() createws = self.direct_createws.isChecked() ei_str = self.direct_ei_input.text() eierr = '-----------------------------------------------------------------------------------\n' eierr += 'Error: Invalid input Ei. This must be a number or a comma-separated list of numbers\n' eierr += '-----------------------------------------------------------------------------------\n' ei_vec = [] if ',' not in ei_str: try: ei_vec.append(float(ei_str)) ei_vec = self.direct_input_check(ei_vec) except ValueError: self.emptyfield_msgbox.show() raise ValueError(eierr) else: try: ei_vec = [float(val) for val in ei_str.split(',')] ei_vec = self.direct_input_check(ei_vec) except ValueError: self.emptyfield_msgbox.show() raise ValueError(eierr) try: Emin = float(self.direct_emin_input.text()) except ValueError: Emin = -max(ei_vec) qe = calcQE(ei_vec, self.tthlims, emin=Emin) if not overplot: self.xlim = 0 self.axes.clear() self.axes.axhline(color='k') if matplotlib.compare_versions('2.1.0',matplotlib.__version__): self.axes.hold(True) # hold is deprecated since 2.1.0, true by default Inst = self.direct_inst_box.currentText() for n in range(len(qe)): name = Inst + '_Ei=' + str(ei_vec[n]) line, = self.axes.plot(qe[n][0], qe[n][1]) line.set_label(name) if max(qe[n][0]) > self.xlim: self.xlim = max(qe[n][0]) if createws: mantid.simpleapi.CreateWorkspace(DataX=qe[n][0], DataY=qe[n][1], NSpec=1, OutputWorkspace=str('QECoverage_' + name)) self.axes.set_xlim([0, self.xlim]) self.axes.set_xlabel(r'$|Q|$ ($\AA^{-1}$)') self.axes.set_ylabel('Energy Transfer (meV)') self.axes.legend() self.canvas.draw()
def plot_flux_hz(self): """ Plots the flux vs freq in the middle tab """ inst = self.engine.instname chop = self.engine.getChopper() ei = float(self.widgets['EiEdit']['Edit'].text()) overplot = self.widgets['HoldCheck'].isChecked() # Do not recalculate if one of the plots has the same parametersc _, labels = self.frqaxes2.get_legend_handles_labels() searchStr = '([A-Z]+) "(.+)" Ei = ([0-9.-]+) meV' if labels and (overplot or len(labels) == 1): for prevtitle in labels: prevInst, prevChop, prevEi = re.search(searchStr, prevtitle).groups() if inst == prevInst and chop == prevChop and abs(ei-float(prevEi)) < 0.01: return freq0 = self.engine.getFrequency() rep = self.engine.moderator.source_rep maxfreq = self.engine.chopper_system.max_frequencies freqs = range(rep, (maxfreq[0] if hasattr(maxfreq, '__len__') else maxfreq) + 1, rep) flux = np.zeros(len(freqs)) elres = np.zeros(len(freqs)) for ie, freq in enumerate(freqs): if hasattr(freq0, '__len__'): self.setFreq(manual_freq=[freq] + freq0[1:]) else: self.setFreq(manual_freq=freq) with warnings.catch_warnings(record=True): warnings.simplefilter('always', UserWarning) flux[ie] = self.engine.getFlux(ei) elres[ie] = self.engine.getResolution(0., ei)[0] if overplot: if matplotlib.compare_versions('2.1.0',matplotlib.__version__): self.frqaxes1.hold(True) self.frqaxes2.hold(True) else: self.frqaxes1.clear() self.frqaxes2.clear() self.setFreq(manual_freq=freq0) self.frqaxes1.set_xlabel('Chopper Frequency (Hz)') self.frqaxes1.set_ylabel('Flux (n/cm$^2$/s)') line, = self.frqaxes1.plot(freqs, flux, 'o-') self.frqaxes1.set_xlim([0, np.max(freqs)]) self.frqaxes2.set_xlabel('Chopper Frequency (Hz)') self.frqaxes2.set_ylabel('Elastic Resolution FWHM (meV)') line, = self.frqaxes2.plot(freqs, elres, 'o-') line.set_label('%s "%s" Ei = %5.3f meV' % (inst, chop, ei)) lg = self.frqaxes2.legend() lg.draggable() self.frqaxes2.set_xlim([0, np.max(freqs)]) self.frqcanvas.draw()
def __init__(self, parent, main, contact=None): super(Statistics, self).__init__(parent) self.parent = parent self.main = main self.log = main.log self.connection = main.connection self.database = main.database self.settings = main.settings self.helper = main.helper self.setupUi(self) main.setupButtonBox(self.buttonBox) self.graphLayout = StatisticGraphLayout.Stacked self.lastRequest = None self.connect(self.statisticTab, SIGNAL("currentChanged(int)"), lambda x : self.refreshStatistic()) self.connect(self.infoBrowser, SIGNAL("anchorClicked(const QUrl &)"), self.refreshStatistic) self.connect(self.filterBox, SIGNAL("currentIndexChanged(int)"), lambda x : self.refreshStatistic(reset=False)) self.connect(self.contactBox, SIGNAL("currentIndexChanged(int)"), lambda x : self.refreshStatistic(reset=False)) self.connect(self.viewBox, SIGNAL("currentIndexChanged(int)"), lambda x : self.refreshStatistic()) self.connect(self.stackedAction, SIGNAL("triggered()"), self.stackedGraph) self.connect(self.separateAction, SIGNAL("triggered()"), self.separateGraph) self.show() if USE_MATPLOTLIB: self.log.info(QString("Matplotlib found - generating statistics")) else: self.log.info(QString("Matplotlib not found :-(")) # On older versions of matplotlib the default size of the matplotlib widget is incorrect if USE_MATPLOTLIB: self.log.info(QString("Using matplotlib version %1").arg(matplotlib.__version__)) if not matplotlib.compare_versions(matplotlib.__version__, '0.98.6svn'): self.log.warning(QString("too old version of matplotlib - faking widget size")) self.resize(self.size().width()+1, self.size().height()+1) self.resize(self.size().width()-1, self.size().height()-1) self.insertContacts(contact) self.refreshStatistic()
def _mpl_le_2_0_0(): try: import matplotlib return matplotlib.compare_versions('2.0.0', matplotlib.__version__) except ImportError: return False
def __init__(self, parent=None, window_flags=None, ol=None): # pylint: disable=unused-argument,super-on-old-class super(DGSPlannerGUI, self).__init__(parent) if window_flags: self.setWindowFlags(window_flags) # OrientedLattice if ValidateOL(ol): self.ol = ol else: self.ol = mantid.geometry.OrientedLattice() self.masterDict = dict() # holds info about instrument and ranges self.updatedInstrument = False self.instrumentWAND = False self.updatedOL = False self.wg = None # workspace group self.instrumentWidget = InstrumentSetupWidget.InstrumentSetupWidget( self) self.setLayout(QtWidgets.QHBoxLayout()) controlLayout = QtWidgets.QVBoxLayout() geometryBox = QtWidgets.QGroupBox("Instrument Geometry") plotBox = QtWidgets.QGroupBox("Plot Axes") geometryBoxLayout = QtWidgets.QVBoxLayout() geometryBoxLayout.addWidget(self.instrumentWidget) geometryBox.setLayout(geometryBoxLayout) controlLayout.addWidget(geometryBox) self.ublayout = QtWidgets.QHBoxLayout() self.classic = ClassicUBInputWidget.ClassicUBInputWidget(self.ol) self.ublayout.addWidget(self.classic, alignment=QtCore.Qt.AlignTop, stretch=1) self.matrix = MatrixUBInputWidget.MatrixUBInputWidget(self.ol) self.ublayout.addWidget(self.matrix, alignment=QtCore.Qt.AlignTop, stretch=1) sampleBox = QtWidgets.QGroupBox("Sample") sampleBox.setLayout(self.ublayout) controlLayout.addWidget(sampleBox) self.dimensionWidget = DimensionSelectorWidget.DimensionSelectorWidget( self) plotBoxLayout = QtWidgets.QVBoxLayout() plotBoxLayout.addWidget(self.dimensionWidget) plotControlLayout = QtWidgets.QGridLayout() self.plotButton = QtWidgets.QPushButton("Plot", self) self.oplotButton = QtWidgets.QPushButton("Overplot", self) self.helpButton = QtWidgets.QPushButton("?", self) self.colorLabel = QtWidgets.QLabel('Color by angle', self) self.colorButton = QtWidgets.QCheckBox(self) self.colorButton.toggle() self.aspectLabel = QtWidgets.QLabel('Aspect ratio 1:1', self) self.aspectButton = QtWidgets.QCheckBox(self) self.saveButton = QtWidgets.QPushButton("Save Figure", self) plotControlLayout.addWidget(self.plotButton, 0, 0) plotControlLayout.addWidget(self.oplotButton, 0, 1) plotControlLayout.addWidget(self.colorLabel, 0, 2, QtCore.Qt.AlignRight) plotControlLayout.addWidget(self.colorButton, 0, 3) plotControlLayout.addWidget(self.aspectLabel, 0, 4, QtCore.Qt.AlignRight) plotControlLayout.addWidget(self.aspectButton, 0, 5) plotControlLayout.addWidget(self.helpButton, 0, 6) plotControlLayout.addWidget(self.saveButton, 0, 7) plotBoxLayout.addLayout(plotControlLayout) plotBox = QtWidgets.QGroupBox("Plot Axes") plotBox.setLayout(plotBoxLayout) controlLayout.addWidget(plotBox) self.layout().addLayout(controlLayout) # figure self.figure = Figure() self.figure.patch.set_facecolor('white') self.canvas = FigureCanvas(self.figure) self.grid_helper = GridHelperCurveLinear((self.tr, self.inv_tr)) self.trajfig = Subplot(self.figure, 1, 1, 1, grid_helper=self.grid_helper) if matplotlib.compare_versions('2.1.0', matplotlib.__version__): self.trajfig.hold( True) # hold is deprecated since 2.1.0, true by default self.figure.add_subplot(self.trajfig) self.toolbar = MantidNavigationToolbar(self.canvas, self) figureLayout = QtWidgets.QVBoxLayout() figureLayout.addWidget(self.toolbar, 0) figureLayout.addWidget(self.canvas, 1) self.layout().addLayout(figureLayout) self.needToClear = False self.saveDir = '' # connections self.matrix.UBmodel.changed.connect(self.updateUB) self.matrix.UBmodel.changed.connect(self.classic.updateOL) self.classic.changed.connect(self.matrix.UBmodel.updateOL) self.classic.changed.connect(self.updateUB) self.instrumentWidget.changed.connect(self.updateParams) self.instrumentWidget.getInstrumentComboBox().activated[str].connect( self.instrumentUpdateEvent) self.instrumentWidget.getEditEi().textChanged.connect( self.eiWavelengthUpdateEvent) self.dimensionWidget.changed.connect(self.updateParams) self.plotButton.clicked.connect(self.updateFigure) self.oplotButton.clicked.connect(self.updateFigure) self.helpButton.clicked.connect(self.help) self.saveButton.clicked.connect(self.save) # force an update of values self.instrumentWidget.updateAll() self.dimensionWidget.updateChanges() # help self.assistant_process = QtCore.QProcess(self) # pylint: disable=protected-access self.mantidplot_name = 'DGS Planner' # control for cancel button self.iterations = 0 self.progress_canceled = False # register startup mantid.UsageService.registerFeatureUsage( mantid.kernel.FeatureType.Interface, "DGSPlanner", False)
def __init__(self, ol=None, parent=None): # pylint: disable=unused-argument,super-on-old-class super(DGSPlannerGUI, self).__init__(parent) # OrientedLattice if ValidateOL(ol): self.ol = ol else: self.ol = mantid.geometry.OrientedLattice() self.masterDict = dict() # holds info about instrument and ranges self.updatedInstrument = False self.updatedOL = False self.wg = None # workspace group self.instrumentWidget = InstrumentSetupWidget.InstrumentSetupWidget(self) self.setLayout(QtWidgets.QHBoxLayout()) controlLayout = QtWidgets.QVBoxLayout() controlLayout.addWidget(self.instrumentWidget) self.ublayout = QtWidgets.QHBoxLayout() self.classic = ClassicUBInputWidget.ClassicUBInputWidget(self.ol) self.ublayout.addWidget(self.classic, alignment=QtCore.Qt.AlignTop, stretch=1) self.matrix = MatrixUBInputWidget.MatrixUBInputWidget(self.ol) self.ublayout.addWidget(self.matrix, alignment=QtCore.Qt.AlignTop, stretch=1) controlLayout.addLayout(self.ublayout) self.dimensionWidget = DimensionSelectorWidget.DimensionSelectorWidget(self) controlLayout.addWidget(self.dimensionWidget) plotControlLayout = QtWidgets.QGridLayout() self.plotButton = QtWidgets.QPushButton("Plot", self) self.oplotButton = QtWidgets.QPushButton("Overplot", self) self.helpButton = QtWidgets.QPushButton("?", self) self.colorLabel = QtWidgets.QLabel('Color by angle', self) self.colorButton = QtWidgets.QCheckBox(self) self.colorButton.toggle() self.aspectLabel = QtWidgets.QLabel('Aspect ratio 1:1', self) self.aspectButton = QtWidgets.QCheckBox(self) self.saveButton = QtWidgets.QPushButton("Save Figure", self) plotControlLayout.addWidget(self.plotButton, 0, 0) plotControlLayout.addWidget(self.oplotButton, 0, 1) plotControlLayout.addWidget(self.colorLabel, 0, 2, QtCore.Qt.AlignRight) plotControlLayout.addWidget(self.colorButton, 0, 3) plotControlLayout.addWidget(self.aspectLabel, 0, 4, QtCore.Qt.AlignRight) plotControlLayout.addWidget(self.aspectButton, 0, 5) plotControlLayout.addWidget(self.helpButton, 0, 6) plotControlLayout.addWidget(self.saveButton, 0, 7) controlLayout.addLayout(plotControlLayout) self.layout().addLayout(controlLayout) # figure self.figure = Figure() self.figure.patch.set_facecolor('white') self.canvas = FigureCanvas(self.figure) self.grid_helper = GridHelperCurveLinear((self.tr, self.inv_tr)) self.trajfig = Subplot(self.figure, 1, 1, 1, grid_helper=self.grid_helper) if matplotlib.compare_versions('2.1.0',matplotlib.__version__): self.trajfig.hold(True) # hold is deprecated since 2.1.0, true by default self.figure.add_subplot(self.trajfig) self.toolbar = CustomNavigationToolbar(self.canvas, self) figureLayout = QtWidgets.QVBoxLayout() figureLayout.addWidget(self.toolbar,0) figureLayout.addWidget(self.canvas,1) self.layout().addLayout(figureLayout) self.needToClear = False self.saveDir = '' # connections self.matrix.UBmodel.changed.connect(self.updateUB) self.matrix.UBmodel.changed.connect(self.classic.updateOL) self.classic.changed.connect(self.matrix.UBmodel.updateOL) self.classic.changed.connect(self.updateUB) self.instrumentWidget.changed.connect(self.updateParams) self.dimensionWidget.changed.connect(self.updateParams) self.plotButton.clicked.connect(self.updateFigure) self.oplotButton.clicked.connect(self.updateFigure) self.helpButton.clicked.connect(self.help) self.saveButton.clicked.connect(self.save) # force an update of values self.instrumentWidget.updateAll() self.dimensionWidget.updateChanges() # help self.assistant_process = QtCore.QProcess(self) # pylint: disable=protected-access self.mantidplot_name='DGS Planner' self.collection_file = os.path.join(mantid._bindir, '../docs/qthelp/MantidProject.qhc') version = ".".join(mantid.__version__.split(".")[:2]) self.qt_url = 'qthelp://org.sphinx.mantidproject.' + version + '/doc/interfaces/DGS Planner.html' self.external_url = 'http://docs.mantidproject.org/nightly/interfaces/DGS Planner.html' # control for cancel button self.iterations = 0 self.progress_canceled = False # register startup mantid.UsageService.registerFeatureUsage("Interface", "DGSPlanner", False)
def plot_flux_ei(self, **kwargs): """ Plots the flux vs Ei in the middle tab """ inst = self.engine.instname chop = self.engine.getChopper() freq = self.engine.getFrequency() overplot = self.widgets['HoldCheck'].isChecked() if hasattr(freq, '__len__'): freq = freq[0] update = kwargs['update'] if 'update' in kwargs.keys() else False # Do not recalculate if all relevant parameters still the same. _, labels = self.flxaxes2.get_legend_handles_labels() searchStr = '([A-Z]+) "(.+)" ([0-9]+) Hz' tmpinst = [] if (labels and (overplot or len(labels) == 1)) or update: for prevtitle in labels: prevInst, prevChop, prevFreq = re.search(searchStr, prevtitle).groups() if update: tmpinst.append( copy.deepcopy( Instrument(self.instruments[prevInst], prevChop, float(prevFreq)))) else: if inst == prevInst and chop == prevChop and freq == float( prevFreq): return ne = 25 mn = self.minE[inst] mx = (self.flxslder.val / 100) * self.maxE[inst] eis = np.linspace(mn, mx, ne) flux = eis * 0 elres = eis * 0 if update: self.flxaxes1.clear() self.flxaxes2.clear() if matplotlib.compare_versions('2.1.0', matplotlib.__version__): self.flxaxes1.hold(True) self.flxaxes2.hold(True) for ii, instrument in enumerate(tmpinst): for ie, ei in enumerate(eis): with warnings.catch_warnings(record=True): warnings.simplefilter('always', UserWarning) flux[ie] = instrument.getFlux(ei) elres[ie] = instrument.getResolution(0., ei)[0] self.flxaxes1.plot(eis, flux) line, = self.flxaxes2.plot(eis, elres) line.set_label(labels[ii]) else: for ie, ei in enumerate(eis): with warnings.catch_warnings(record=True): warnings.simplefilter('always', UserWarning) flux[ie] = self.engine.getFlux(ei) elres[ie] = self.engine.getResolution(0., ei)[0] if overplot: if matplotlib.compare_versions('2.1.0', matplotlib.__version__): self.flxaxes1.hold(True) self.flxaxes2.hold(True) else: self.flxaxes1.clear() self.flxaxes2.clear() self.flxaxes1.plot(eis, flux) line, = self.flxaxes2.plot(eis, elres) line.set_label('%s "%s" %d Hz' % (inst, chop, freq)) self.flxaxes1.set_xlim([mn, mx]) self.flxaxes2.set_xlim([mn, mx]) self.flxaxes1.set_xlabel('Incident Energy (meV)') self.flxaxes1.set_ylabel('Flux (n/cm$^2$/s)') self.flxaxes1.set_xlabel('Incident Energy (meV)') self.flxaxes2.set_ylabel('Elastic Resolution FWHM (meV)') lg = self.flxaxes2.legend() lg.draggable() self.flxcanvas.draw()
def plot_flux_ei(self, **kwargs): """ Plots the flux vs Ei in the middle tab """ inst = self.engine.instname chop = self.engine.getChopper() freq = self.engine.getFrequency() overplot = self.widgets['HoldCheck'].isChecked() if hasattr(freq, '__len__'): freq = freq[0] update = kwargs['update'] if 'update' in kwargs.keys() else False # Do not recalculate if all relevant parameters still the same. _, labels = self.flxaxes2.get_legend_handles_labels() searchStr = '([A-Z]+) "(.+)" ([0-9]+) Hz' tmpinst = [] if (labels and (overplot or len(labels) == 1)) or update: for prevtitle in labels: prevInst, prevChop, prevFreq = re.search(searchStr, prevtitle).groups() if update: tmpinst.append(copy.deepcopy(Instrument(self.instruments[prevInst], prevChop, float(prevFreq)))) else: if inst == prevInst and chop == prevChop and freq == float(prevFreq): return ne = 25 mn = self.minE[inst] mx = (self.flxslder.val/100)*self.maxE[inst] eis = np.linspace(mn, mx, ne) flux = eis*0 elres = eis*0 if update: self.flxaxes1.clear() self.flxaxes2.clear() if matplotlib.compare_versions('2.1.0',matplotlib.__version__): self.flxaxes1.hold(True) self.flxaxes2.hold(True) for ii, instrument in enumerate(tmpinst): for ie, ei in enumerate(eis): with warnings.catch_warnings(record=True): warnings.simplefilter('always', UserWarning) flux[ie] = instrument.getFlux(ei) elres[ie] = instrument.getResolution(0., ei)[0] self.flxaxes1.plot(eis, flux) line, = self.flxaxes2.plot(eis, elres) line.set_label(labels[ii]) else: for ie, ei in enumerate(eis): with warnings.catch_warnings(record=True): warnings.simplefilter('always', UserWarning) flux[ie] = self.engine.getFlux(ei) elres[ie] = self.engine.getResolution(0., ei)[0] if overplot: if matplotlib.compare_versions('2.1.0',matplotlib.__version__): self.flxaxes1.hold(True) self.flxaxes2.hold(True) else: self.flxaxes1.clear() self.flxaxes2.clear() self.flxaxes1.plot(eis, flux) line, = self.flxaxes2.plot(eis, elres) line.set_label('%s "%s" %d Hz' % (inst, chop, freq)) self.flxaxes1.set_xlim([mn, mx]) self.flxaxes2.set_xlim([mn, mx]) self.flxaxes1.set_xlabel('Incident Energy (meV)') self.flxaxes1.set_ylabel('Flux (n/cm$^2$/s)') self.flxaxes1.set_xlabel('Incident Energy (meV)') self.flxaxes2.set_ylabel('Elastic Resolution FWHM (meV)') lg = self.flxaxes2.legend() lg.draggable() self.flxcanvas.draw()