예제 #1
0
 def applyAndClose(self):
     paramName = self.paramTextList[self.paramNameEntry.currentIndex()]
     returnTuple = (paramName, self.lineEntry.value(),
                    safeEval(self.multEntry.text()),
                    safeEval(self.addEntry.text()),
                    self.spectrumNameEntry.currentIndex())
     self.closeEvent()
     self.returnFunc(returnTuple)
예제 #2
0
 def save(self):
     self.updatePlot()
     self.fig.set_size_inches((int(safeEval(self.widthEntry.text())) / 2.54, int(safeEval(self.heightEntry.text())) / 2.54))
     WorkspaceName = self.father.workspaceNames[self.father.workspaceNum]  # Set name of file to be saved to workspace name to start
     f = QtGui.QFileDialog.getSaveFileName(self, 'Save File', self.father.LastLocation + os.path.sep + WorkspaceName + '.' + self.fileOptions[self.filetypeEntry.currentIndex()])
     if f:
         self.father.LastLocation = os.path.dirname(f)
         self.fig.savefig(f)
         self.cancel()
예제 #3
0
 def setDimensions(self):
     diameter = safeEval(self.diameter.text())
     length = safeEval(self.length.text())
     if diameter is not None:
         self.shimSim.r = diameter/2.0
     if length is not None:
         self.shimSim.l = length
     self.shimSim.setupGrid()
     self.father.shimFrame.sim()
예제 #4
0
 def setAngles(self):
     theta = safeEval(self.theta.text())
     phi = safeEval(self.phi.text())
     if theta is not None:
         self.shimSim.theta = theta/180.0*np.pi
     if phi is not None:
         self.shimSim.phi = phi/180.0*np.pi
     self.shimSim.setupGrid()
     self.father.shimFrame.sim()
예제 #5
0
 def validate(self, string, position):
     string = str(string)
     try:
         int(safeEval(string))
         return (QtGui.QValidator.Acceptable, string, position)
     except:
         return (QtGui.QValidator.Intermediate, string, position)
예제 #6
0
    def validate(self, string, position):
        """
        Validates a given string using safeEval.

        Parameters
        ----------
        string : str
            String to be validated.
        position : int
            Position of the cursor.

        Returns
        -------
        State
            Acceptable if the string is parsable by safeEval, Intermediate otherwise.
        string : str
            The input string.
        position : int
            The input position of the cursor.
        """
        string = str(string)
        try:
            int(safeEval(string))
            return (QtGui.QValidator.Acceptable, string, position)
        except Exception:
            return (QtGui.QValidator.Intermediate, string, position)
예제 #7
0
 def validate(self, string, position):
     string = str(string)
     try:
         int(safeEval(string))
         return (QtGui.QValidator.Acceptable, string, position)
     except Exception:
         return (QtGui.QValidator.Intermediate, string, position)
예제 #8
0
def functionRun(x, freq, sw, axMult, extra, *parameters):
    """
    Simulation function used for function fitting.
    The words between @ symbols are replaced by the fit values and the resulting string is evaluated.

    Parameters
    ----------
    x : list of ndarray
        A list of axes values for the simulation.
        As this is a 1-D method only the last array in the list is used.
    freq : list of float
        The list of frequency per dimension in Hz (not used).
    sw : list of float
        The list of spectral width per dimension in Hz (not used).
    axMult : float
        The multiplier of the x-axis (not used).
    extra : list
        The extra parameters of the function [names, function].
        Where names is a list of strings with the names of the parameters and function is a string with the function for fitting.
    *parameters
        The parameters used in the fit. Should have the same length as names.

    Returns
    -------
    ndarray
        The curve resulting from the evaluation of the function.
    """
    names, function = extra
    x = x[-1]
    for i, elem in enumerate(names):
        function = function.replace('@' + elem + '@', str(parameters[i]))
    return safeEval(function, length=len(x), x=x)
예제 #9
0
 def save(self):
     self.updatePlot()
     self.fig.set_size_inches((int(safeEval(self.widthEntry.text())) / 2.54, int(safeEval(self.heightEntry.text())) / 2.54))
     WorkspaceName = self.father.workspaceNames[self.father.workspaceNum]  # Set name of file to be saved to workspace name to start
     f = QtWidgets.QFileDialog.getSaveFileName(self, 'Save File', self.father.LastLocation + os.path.sep + WorkspaceName + '.' + self.fileOptions[self.filetypeEntry.currentIndex()],filter = '(*.' + self.fileOptions[self.filetypeEntry.currentIndex()] + ')')
     if type(f) is tuple:
         f = f[0]        
     if f:
         self.father.LastLocation = os.path.dirname(f)
         dpi = safeEval(self.dpiEntry.text())
         if dpi is None:
             dpi = self.fig.dpi
         self.fig.savefig(f, format=self.fileOptions[self.filetypeEntry.currentIndex()], dpi=dpi)
         if self.fileOptions[self.filetypeEntry.currentIndex()] == 'svg':
             with open(f) as fd: #workarround for stroke miter limit
                 s = fd.read()
             with open(f, 'w') as fd:
                 fd.write(s.replace('stroke-miterlimit:100000;', ''))
예제 #10
0
 def insertVal(self, func, scaleFunc, scale):
     inp = safeEval(func.text())
     scaleFunc.blockSignals(True)
     if inp is None:
         scaleFunc.setSliderPosition(0)
     else:
         scaleFunc.setSliderPosition(int(round(inp*scale)))
     scaleFunc.blockSignals(False)
     self.sim()
예제 #11
0
파일: saveFigure.py 프로젝트: fenglb/ssnake
 def updatePlot(self, *args):
     """
     Updates the plot.
     """
     if self.fontDetailsCheck.checkState():  # If details checked
         self.fig.suptitle(self.titleEntry.text(),
                           fontsize=self.titleFontSizeEntry.value())
         self.ax.set_xlabel(self.xlabelEntry.text(),
                            fontsize=self.xlabelFontSizeEntry.value())
         self.ax.set_ylabel(self.ylabelEntry.text(),
                            fontsize=self.ylabelFontSizeEntry.value())
         self.ax.set_xlim((safeEval(self.xlimLeftEntry.text(), Type='FI'),
                           safeEval(self.xlimRightEntry.text(), Type='FI')))
         self.ax.set_ylim((safeEval(self.ylimLeftEntry.text(), Type='FI'),
                           safeEval(self.ylimRightEntry.text(), Type='FI')))
         self.ax.tick_params(axis='x',
                             labelsize=self.xtickFontSizeEntry.value())
         self.ax.xaxis.get_offset_text().set_fontsize(
             self.xtickFontSizeEntry.value())
         self.ax.tick_params(axis='y',
                             labelsize=self.ytickFontSizeEntry.value())
         self.ax.yaxis.get_offset_text().set_fontsize(
             self.ytickFontSizeEntry.value())
     else:
         self.fig.suptitle(self.titleEntry.text(),
                           fontsize=self.mainFontSizeEntry.value())
         self.ax.set_xlabel(self.xlabelEntry.text(),
                            fontsize=self.mainFontSizeEntry.value())
         self.ax.set_ylabel(self.ylabelEntry.text(),
                            fontsize=self.mainFontSizeEntry.value())
         self.ax.set_xlim((safeEval(self.xlimLeftEntry.text(), Type='FI'),
                           safeEval(self.xlimRightEntry.text(), Type='FI')))
         self.ax.set_ylim((safeEval(self.ylimLeftEntry.text(), Type='FI'),
                           safeEval(self.ylimRightEntry.text(), Type='FI')))
         self.ax.tick_params(axis='x',
                             labelsize=self.mainFontSizeEntry.value())
         self.ax.xaxis.get_offset_text().set_fontsize(
             self.mainFontSizeEntry.value())
         self.ax.tick_params(axis='y',
                             labelsize=self.mainFontSizeEntry.value())
         self.ax.yaxis.get_offset_text().set_fontsize(
             self.mainFontSizeEntry.value())
         if self.legend is not None:
             self.legend.prop = {'size': self.mainFontSizeEntry.value()}
     self.updateLegend()
     self.fig.set_size_inches(self.widthEntry.value() / 2.54,
                              self.heightEntry.value() / 2.54)
     self.canvas.draw()
     self.canvas.adjustSize()
예제 #12
0
    def valueFromText(self, text):
        """
        Parses a string to a slice number.

        Parameters
        ----------
        text : str
            String to be parsed.

        Returns
        -------
        int
            The slice number.
        """
        inp = int(safeEval(str(text)))
        if inp < 0:
            inp = inp + self.maximum() + 1
        return inp
예제 #13
0
 def setFreq(self, n):
     if MASTERISOTOPELIST[n] is not None and MASTERISOTOPELIST[n]['mass'] is not None:
         val = safeEval(self.freqEditList[n].text())
         if val is not None:
             self.freqConst = val / MASTERISOTOPELIST[n]['freqRatio'][int(self.isoSelect[n])] 
             self.upd()
예제 #14
0
 def setElectron(self):
     val = safeEval(self.electronEntry.text())
     if val is not None:
         self.freqConst = val / ELECTRONSCALE
         self.upd()
예제 #15
0
 def valueFromText(self, text):
     inp = int(safeEval(str(text)))
     if inp < 0:
         inp = inp + self.maximum() + 1
     return inp
예제 #16
0
 def setFreq(self, i):
     val = safeEval(self.freqEntries[i].text())
     if val is not None:
         self.father.freqConst = val / MASTERISOTOPELIST[self.n]['freqRatio'][i]
         self.father.upd()
         self.atomSelect(self.n+1)
예제 #17
0
 def setSw(self):
     sw = safeEval(self.sw.text())
     if sw is not None:
         self.shimSim.sw = int(round(sw))
     self.shimSim.setupGrid()
     self.father.shimFrame.sim()
예제 #18
0
def functionRun(x, freq, sw, axMult, extra, *parameters):
    names, function = extra
    x = x[-1]
    for i, elem in enumerate(names):
        function = function.replace('@' + elem + '@', str(parameters[i]))
    return safeEval(function, length=len(x), x=x)
예제 #19
0
 def setPoints(self):
     nsamples = safeEval(self.nsamples.text())
     if nsamples is not None:
         self.shimSim.N = int(round(nsamples))
     self.shimSim.setupGrid()
     self.father.shimFrame.sim()
예제 #20
0
 def minimize(self, num):
     lineedits = [self.z1, self.x1, self.y1, self.z2,
                  self.xz, self.yz, self.x2_y2, self.xy,
                  self.z3, self.xz2, self.yz2, self.zx2_zy2,
                  self.xyz, self.x3, self.y3]
     y1 = safeEval(self.y1.text())
     z1 = safeEval(self.z1.text())
     x1 = safeEval(self.x1.text())
     xy = safeEval(self.xy.text())
     yz = safeEval(self.yz.text())
     z2 = safeEval(self.z2.text())
     xz = safeEval(self.xz.text())
     x2_y2 = safeEval(self.x2_y2.text())
     y3 = safeEval(self.y3.text())
     xyz = safeEval(self.xyz.text())
     yz2 = safeEval(self.yz2.text())
     z3 = safeEval(self.z3.text())
     xz2 = safeEval(self.xz2.text())
     zx2_zy2 = safeEval(self.zx2_zy2.text())
     x3 = safeEval(self.x3.text())
     val = self.father.minimize(num, [z1, x1, y1, z2, xz, yz, x2_y2, xy, z3, xz2, yz2, zx2_zy2, xyz, x3, y3])
     lineedits[num].setText(str(val))
     lineedits[num].returnPressed.emit()
예제 #21
0
 def valueFromText(self, text):
     inp = int(safeEval(str(text)))
     if inp < 0:
         inp = inp + self.maximum() + 1
     return inp
예제 #22
0
 def sim(self, *args):
     y1 = safeEval(self.y1.text())
     z1 = safeEval(self.z1.text())
     x1 = safeEval(self.x1.text())
     xy = safeEval(self.xy.text())
     yz = safeEval(self.yz.text())
     z2 = safeEval(self.z2.text())
     xz = safeEval(self.xz.text())
     x2_y2 = safeEval(self.x2_y2.text())
     y3 = safeEval(self.y3.text())
     xyz = safeEval(self.xyz.text())
     yz2 = safeEval(self.yz2.text())
     z3 = safeEval(self.z3.text())
     xz2 = safeEval(self.xz2.text())
     zx2_zy2 = safeEval(self.zx2_zy2.text())
     x3 = safeEval(self.x3.text())
     self.father.sim(z1=z1, x1=x1, y1=y1, xy=xy, yz=yz, z2=z2, xz=xz, x2_y2=x2_y2, y3=y3, xyz=xyz, yz2=yz2, z3=z3, xz2=xz2, zx2_zy2=zx2_zy2, x3=x3)
예제 #23
0
 def setB0(self):
     val = safeEval(self.b0Entry.text())
     if val is not None:
         self.freqConst = val / GAMMASCALE
         self.upd()
예제 #24
0
 def updatePlot(self, *args):
     self.fig.suptitle(self.titleEntry.text(), fontsize=safeEval(self.titleFontSizeEntry.text()))
     self.ax.set_xlabel(self.xlabelEntry.text(), fontsize=safeEval(self.xlabelFontSizeEntry.text()))
     self.ax.set_ylabel(self.ylabelEntry.text(), fontsize=safeEval(self.ylabelFontSizeEntry.text()))
     self.ax.set_xlim((safeEval(self.xlimLeftEntry.text()), safeEval(self.xlimRightEntry.text())))
     self.ax.set_ylim((safeEval(self.ylimLeftEntry.text()), safeEval(self.ylimRightEntry.text())))
     self.ax.tick_params(axis='x', labelsize=safeEval(self.xtickFontSizeEntry.text()))
     self.ax.xaxis.get_offset_text().set_fontsize(safeEval(self.xtickFontSizeEntry.text()))
     self.ax.tick_params(axis='y', labelsize=safeEval(self.ytickFontSizeEntry.text()))
     self.ax.yaxis.get_offset_text().set_fontsize(safeEval(self.ytickFontSizeEntry.text()))
     self.fig.set_size_inches((int(safeEval(self.widthEntry.text())) / 2.54, int(safeEval(self.heightEntry.text())) / 2.54))
     self.canvas.draw()
     self.canvas.adjustSize()
예제 #25
0
 def updatePlot(self, *args):
     self.fig.suptitle(self.titleEntry.text(), fontsize=safeEval(self.titleFontSizeEntry.text()))
     self.ax.set_xlabel(self.xlabelEntry.text(), fontsize=safeEval(self.xlabelFontSizeEntry.text()))
     self.ax.set_ylabel(self.ylabelEntry.text(), fontsize=safeEval(self.ylabelFontSizeEntry.text()))
     self.ax.set_xlim((safeEval(self.xlimLeftEntry.text()), safeEval(self.xlimRightEntry.text())))
     self.ax.set_ylim((safeEval(self.ylimLeftEntry.text()), safeEval(self.ylimRightEntry.text())))
     self.ax.tick_params(axis='x', labelsize=safeEval(self.xtickFontSizeEntry.text()))
     self.ax.xaxis.get_offset_text().set_fontsize(safeEval(self.xtickFontSizeEntry.text()))
     self.ax.tick_params(axis='y', labelsize=safeEval(self.ytickFontSizeEntry.text()))
     self.ax.yaxis.get_offset_text().set_fontsize(safeEval(self.ytickFontSizeEntry.text()))
     self.fig.set_size_inches((int(safeEval(self.widthEntry.text())) / 2.54, int(safeEval(self.heightEntry.text())) / 2.54))
     self.canvas.draw()
     self.canvas.adjustSize()
예제 #26
0
 def updatePlot(self, *args):
     """
     Updates the plot.
     """
     if not self.xlimLeftEntry.text():
         self.xlimLeftEntry.setText(str(self.xlimBackup[0]))
     if not self.xlimRightEntry.text():
         self.xlimRightEntry.setText(str(self.xlimBackup[1]))
     if not self.ylimLeftEntry.text():
         self.ylimLeftEntry.setText(str(self.ylimBackup[0]))
     if not self.ylimRightEntry.text():
         self.ylimRightEntry.setText(str(self.ylimBackup[1]))
     if self.fontDetailsCheck.checkState():  # If details checked
         self.fig.suptitle(self.titleEntry.text(),
                           fontsize=self.titleFontSizeEntry.value())
         self.ax.set_xlabel(self.xlabelEntry.text(),
                            fontsize=self.xlabelFontSizeEntry.value())
         self.ax.set_ylabel(self.ylabelEntry.text(),
                            fontsize=self.ylabelFontSizeEntry.value())
         self.ax.set_xlim((safeEval(self.xlimLeftEntry.text(), Type='FI'),
                           safeEval(self.xlimRightEntry.text(), Type='FI')))
         self.ax.set_ylim((safeEval(self.ylimLeftEntry.text(), Type='FI'),
                           safeEval(self.ylimRightEntry.text(), Type='FI')))
         self.ax.tick_params(axis='x',
                             labelsize=self.xtickFontSizeEntry.value())
         self.ax.xaxis.get_offset_text().set_fontsize(
             self.xtickFontSizeEntry.value())
         self.ax.tick_params(axis='y',
                             labelsize=self.ytickFontSizeEntry.value())
         self.ax.yaxis.get_offset_text().set_fontsize(
             self.ytickFontSizeEntry.value())
     else:
         self.fig.suptitle(self.titleEntry.text(),
                           fontsize=self.mainFontSizeEntry.value())
         self.ax.set_xlabel(self.xlabelEntry.text(),
                            fontsize=self.mainFontSizeEntry.value())
         self.ax.set_ylabel(self.ylabelEntry.text(),
                            fontsize=self.mainFontSizeEntry.value())
         self.ax.set_xlim((safeEval(self.xlimLeftEntry.text(), Type='FI'),
                           safeEval(self.xlimRightEntry.text(), Type='FI')))
         self.ax.set_ylim((safeEval(self.ylimLeftEntry.text(), Type='FI'),
                           safeEval(self.ylimRightEntry.text(), Type='FI')))
         self.ax.tick_params(axis='x',
                             labelsize=self.mainFontSizeEntry.value())
         self.ax.xaxis.get_offset_text().set_fontsize(
             self.mainFontSizeEntry.value())
         self.ax.tick_params(axis='y',
                             labelsize=self.mainFontSizeEntry.value())
         self.ax.yaxis.get_offset_text().set_fontsize(
             self.mainFontSizeEntry.value())
         if self.legend is not None:
             self.legend.prop = {'size': self.mainFontSizeEntry.value()}
     xticksbool = self.xticksToggle.isChecked()
     yticksbool = self.yticksToggle.isChecked()
     if self.frameToggle.isChecked():
         self.ax.spines['top'].set_visible(True)
         self.ax.spines['right'].set_visible(True)
         self.ax.spines['bottom'].set_visible(True)
         self.ax.spines['left'].set_visible(True)
     else:
         self.ax.spines['top'].set_visible(False)
         self.ax.spines['right'].set_visible(False)
         if xticksbool:
             self.ax.spines['bottom'].set_visible(True)
         else:
             self.ax.spines['bottom'].set_visible(False)
         if yticksbool:
             self.ax.spines['left'].set_visible(True)
         else:
             self.ax.spines['left'].set_visible(False)
     self.ax.tick_params(bottom=xticksbool,
                         labelbottom=xticksbool,
                         left=yticksbool,
                         labelleft=yticksbool)
     if not xticksbool:
         self.ax.xaxis.get_offset_text().set_visible(False)
     else:
         self.ax.xaxis.get_offset_text().set_visible(True)
     if not yticksbool:
         self.ax.yaxis.get_offset_text().set_visible(False)
     else:
         self.ax.yaxis.get_offset_text().set_visible(True)
     self.updateLegend()
     self.fig.set_size_inches(self.widthEntry.value() / 2.54,
                              self.heightEntry.value() / 2.54)
     self.canvas.draw()
     self.canvas.adjustSize()