def checkValidSampleNormalization(self, event, massSB):
    string = self.text()
    try:
        mass = calculateMolarMass(string)
        self.setStyleSheet("color: black;")
    except AttributeError as e:
        self.setStyleSheet("color: red;")
        _GUItools.dialog(
            'When parsing "{}" following error occured:\n'.format(string) +
            str(e))
        if not event is None:
            self.focusOutEvent_old2(event)
        return None

    if len(
            string
    ) != 0 and mass == 0:  # A string was provided but no mass found, typically error in input
        self.setStyleSheet("color: red;")
        _GUItools.dialog(
            'When parsing "{}" no mass was found. Please format the chemical formula correctly, e.g. MnF2'
            .format(string))
    elif len(string) == 0:
        mass = calculateMolarMass(self.placeholderText())
        massSB.setValue(mass)
    else:
        massSB.setValue(mass)
    if not event is None:
        self.focusOutEvent_old2(event)
Ejemplo n.º 2
0
def generateQELineScript(self):
    self.stateMachine.run()
    if not self.stateMachine.currentState.name in ['Raw','Converted']:
        _GUItools.dialog(text='It is not possible to generate a script without any data loaded.')
        return False

    folder = self.getCurrentDirectory()
    saveFile = QtWidgets.QFileDialog.getSaveFileName(self, 'Save File',folder,"Python (*.py)")[0]
    if len(saveFile)==0:
        return False
    if path.splitext(saveFile)[1] !='.py':
        saveFile = path.splitext(saveFile)[0]+'.py'

    ds = self.DataSetModel.getCurrentDataSet()
    dataSetName = ds.name.replace(' ','_')
    
    dataFiles = [df.original_file.fileLocation if hasattr(df,'original_file') else df.fileLocation for df in ds]
    if not ds.background is None: # Dealing with a subracted dataset
        convertBeforeSubtract = ds.convertBeforeSubtract
        backgroundFiles = ds.background
    else:
        convertBeforeSubtract = None
        backgroundFiles = None

    binning = self.ui.DataSet_binning_comboBox.currentText()
    
    HStart = self.ui.QELine_HStart_lineEdit.text()
    KStart = self.ui.QELine_KStart_lineEdit.text()
    LStart = self.ui.QELine_LStart_lineEdit.text()
    HEnd = self.ui.QELine_HEnd_lineEdit.text()
    KEnd = self.ui.QELine_KEnd_lineEdit.text()
    LEnd = self.ui.QELine_LEnd_lineEdit.text()
    width = self.ui.QELine_Width_lineEdit.text()
    minPixel = self.ui.QELine_MinPixel_lineEdit.text()
    EMin = self.ui.QELine_EMin_lineEdit.text()
    EMax = self.ui.QELine_EMax_lineEdit.text()
    NPoints = self.ui.QELine_NPoints_lineEdit.text()

    constantBins = self.ui.QELine_ConstantBins_checkBox.isChecked()

    CAxisMin = self.ui.QELine_CAxisMin_lineEdit.text()
    CAxisMax = self.ui.QELine_CAxisMax_lineEdit.text()

    log = self.ui.QELine_LogScale_checkBox.isChecked()
    grid = self.ui.QELine_Grid_checkBox.isChecked()

    title = self.ui.QELine_SetTitle_lineEdit.text()

    RLU = self.ui.QELine_SelectUnits_RLU_radioButton.isChecked()
    
    
    generatePlotQELineScript(saveFile=saveFile,dataSetName=dataSetName,dataFiles=dataFiles,binning = binning, 
                                HStart=HStart, KStart=KStart, LStart = LStart, HEnd=HEnd, KEnd=KEnd, LEnd=LEnd, 
                                width=width, minPixel=minPixel, EMin = EMin, EMax=EMax, NPoints=NPoints, RLU=RLU, 
                                CAxisMin = CAxisMin, CAxisMax = CAxisMax, log=log, grid=grid, title=title, constantBins=constantBins,
                                convertBeforeSubtract=convertBeforeSubtract,backgroundFiles=backgroundFiles)

    return True    
Ejemplo n.º 3
0
def generate3DScript(self):
    # Check if data has been loaded. Abort if not
    self.stateMachine.run()
    if not self.stateMachine.currentState.name in ['Raw','Converted']:
        _GUItools.dialog(text='It is not possible to generate a script without any data loaded.')
        return False

    # Save the created script
    folder = self.getCurrentDirectory()
    saveFile = QtWidgets.QFileDialog.getSaveFileName(self, 'Save File',folder,"Python (*.py)")[0]
    if len(saveFile)==0:
        return False
    if path.splitext(saveFile)[1] !='.py':
        saveFile = path.splitext(saveFile)[0]+'.py'

    # Start loading information from the GUI
    ds = self.DataSetModel.getCurrentDataSet()
    dataSetName = ds.name.replace(' ','_')
    
    dataFiles = [df.original_file.fileLocation if hasattr(df,'original_file') else df.fileLocation for df in ds]
    if not ds.background is None: # Dealing with a subracted dataset
        convertBeforeSubtract = ds.convertBeforeSubtract
        backgroundFiles = ds.background
    else:
        convertBeforeSubtract = None
        backgroundFiles = None

    binning = self.ui.DataSet_binning_comboBox.currentText()
    qx = self.ui.View3D_QXBin_lineEdit.text()
    qy = self.ui.View3D_QYBin_lineEdit.text()
    E = self.ui.View3D_EBin_lineEdit.text()

    CAxisMin = self.ui.View3D_CAxisMin_lineEdit.text()
    CAxisMax = self.ui.View3D_CAxisMax_lineEdit.text()

    customViewer = self.ui.View3D_Mode_Custom_radioButton.isChecked()

    log = self.ui.View3D_LogScale_checkBox.isChecked()
    grid = self.ui.View3D_Grid_checkBox.isChecked()
    counts = self.ui.View3D_RawCounts_checkBox.isChecked()

    title = self.ui.View3D_SetTitle_lineEdit.text()

    RLU = self.ui.View3D_SelectUnits_RLU_radioButton.isChecked()

    radioState = [self.ui.View3D_SelectView_QxE_radioButton.isChecked(),
    self.ui.View3D_SelectView_QyE_radioButton.isChecked(),self.ui.View3D_SelectView_QxQy_radioButton.isChecked()]
    selectView = np.arange(3)[radioState]
    selectView = selectView[0]

    # And generate the script
    generateViewer3DScript(saveFile=saveFile,dataFiles=dataFiles,dataSetName=dataSetName, binning=binning, qx=qx, qy=qy, E=E, 
                                RLU=RLU, CAxisMin=CAxisMin, CAxisMax=CAxisMax, log=log, grid=grid,
                                title=title, selectView=selectView,customViewer=customViewer,counts=counts,convertBeforeSubtract=convertBeforeSubtract,
                                backgroundFiles=backgroundFiles)

    return True
Ejemplo n.º 4
0
def generateQPlaneScript(self):
    self.stateMachine.run()
    if not self.stateMachine.currentState.name in ['Raw','Converted']:
        _GUItools.dialog(text='It is not possible to generate a script without any data loaded.')
        return False

    folder = self.getCurrentDirectory()
    saveFile = QtWidgets.QFileDialog.getSaveFileName(self, 'Save File',folder,"Python (*.py)")[0]
    if len(saveFile)==0:
        return False
    if path.splitext(saveFile)[1] !='.py':
        saveFile = path.splitext(saveFile)[0]+'.py'

    ds = self.DataSetModel.getCurrentDataSet()
    dataSetName = ds.name.replace(' ','_')
    
    dataFiles = [df.original_file.fileLocation if hasattr(df,'original_file') else df.fileLocation for df in ds]
    if not ds.background is None: # Dealing with a subracted dataset
        convertBeforeSubtract = ds.convertBeforeSubtract
        backgroundFiles = ds.background
    else:
        convertBeforeSubtract = None
        backgroundFiles = None

    binning = self.ui.DataSet_binning_comboBox.currentText()
    
    
    
    EMin = self.ui.QPlane_EMin_lineEdit.text()
    EMax = self.ui.QPlane_EMax_lineEdit.text()

    xBinTolerance = self.ui.QPlane_xBinTolerance_lineEdit.text()
    yBinTolerance = self.ui.QPlane_yBinTolerance_lineEdit.text()

    CAxisMin = self.ui.QPlane_CAxisMin_lineEdit.text()
    CAxisMax = self.ui.QPlane_CAxisMax_lineEdit.text()

    log = self.ui.QPlane_LogScale_checkBox.isChecked()
    grid = self.ui.QPlane_Grid_checkBox.isChecked()

    title = self.ui.QPlane_SetTitle_lineEdit.text()

    RLU = self.ui.QPlane_SelectUnits_RLU_radioButton.isChecked()
    
    
    generatePlotQPlaneScript(saveFile,dataSetName,dataFiles,binning = binning, 
                             xBinTolerance=xBinTolerance, yBinTolerance=yBinTolerance,
                             EMin = EMin,EMax=EMax, RLU=RLU, 
                             CAxisMin = CAxisMin, CAxisMax = CAxisMax, log=log, grid=grid, title=title,
                             convertBeforeSubtract=convertBeforeSubtract,backgroundFiles=backgroundFiles)

    return True    
Ejemplo n.º 5
0
def checker(q1, q2, width, minPixel, EMax, EMin, cutQ):
    """Checker for 1DCuts. Returns False is an error is detected."""
    success = True
    if EMax < EMin:
        _GUItools.dialog(
            text='1D Cut could not be made. EMax ({}) < EMin ({})!'.format(
                EMax, EMin))
        success = False
    if width < 0:
        _GUItools.dialog(
            text='1D Cut could not be made. Q width ({}) is negative!'.format(
                width))
        success = False
    if minPixel < 0:
        _GUItools.dialog(
            text='1D Cut could not be made. Min Pixel ({}) is negative!'.
            format(minPixel))
        success = False
    if not cutQ:  # Cut along E
        if not np.all(np.isclose(q1, q2)):
            _GUItools.dialog(
                text=
                '1D Cut could not be made. Start ({}) is not equal to End ({}) is negative!'
                .format(q1, q2))
            success = False
    return success
Ejemplo n.º 6
0
def generateCut1DScript(self):
    self.stateMachine.run()
    if not self.stateMachine.currentState.name in ['Raw','Converted']:
        _GUItools.dialog(text='It is not possible to generate a script without any data loaded.')
        return False

    if self.Cut1DModel.rowCount() == 0:
        _GUItools.dialog(text='It is not possible to generate a script without any cuts performed. Please make a cut using the "Generate 1D cut" or Plot 1D cut" buttons.')
        return False

    folder = self.getCurrentDirectory()
    saveFile = QtWidgets.QFileDialog.getSaveFileName(self, 'Save File',folder,"Python (*.py)")[0]
    if len(saveFile)==0:
        return False
    if path.splitext(saveFile)[1] !='.py':
        saveFile = path.splitext(saveFile)[0]+'.py'

    ds = self.DataSetModel.getCurrentDataSet()
    dataSetName = ds.name
    
    dataFiles = [df.original_file.fileLocation if hasattr(df,'original_file') else df.fileLocation for df in ds]

    binning = self.ui.DataSet_binning_comboBox.currentText()
    
    saveString = []
    saveString.append(startString())
    saveString.append('\n\n')
    saveString.append(loadDataSet(dataSetName=dataSetName,DataFiles=dataFiles))
    saveString.append(binDataSet(dataSetName=dataSetName,binning=binning))

    if self.Cut1DModel.rowCount() == 1:
        cut = self.Cut1DModel.dataCuts1D[0]
        saveString.append(plotCut1DTextSingle(dataSetName,cut))
    else:
        
        for cut in self.Cut1DModel.dataCuts1D:
            method = cut.method
            params = {}
            for param in cut.parameters:
                if param == 'method':
                    continue
                val = getattr(cut,param)
                if isinstance(val,(list,np.ndarray)):
                    val = '['+','.join([str(x) for x in val])+']'
                params[param] = val
            
            name = cut.name.replace(' ','_').replace('.','_').replace(',','_')

            if method.find('plot')>-1:
                returnValues = ','.join([name+'_'+x for x in ['ax','data','bins']])
            else:
                returnValues = ','.join([name+'_'+x for x in ['data','bins']])
            line = returnValues+' = '+dataSetName+'.'+method+'('
            line += ', '.join([param+' = ' + str(value) for param,value in params.items()])+')\n'
            saveString.append(line)
            
        
    saveString.append('\n\n#If a ufit object is needed, add "ufit=True" to the above method calls and change "_data" and "_bins" to "_ufit".')
    with open(saveFile,'w') as file:
        file.write(''.join(saveString))
    return True    
Ejemplo n.º 7
0
def QELine_plot_button_function(self):
    # First check if we have data, otherwise convert data
    if not self.stateMachine.requireStateByName('Converted'):
        return False

    ds = self.DataSetModel.getCurrentDataSet()
    if len(ds.convertedFiles) == 0:
        self.DataSet_convertData_button_function()

    # Get the Q points
    HStart = float(self.ui.QELine_HStart_lineEdit.text())
    KStart = float(self.ui.QELine_KStart_lineEdit.text())
    LStart = float(self.ui.QELine_LStart_lineEdit.text())

    HEnd = float(self.ui.QELine_HEnd_lineEdit.text())
    KEnd = float(self.ui.QELine_KEnd_lineEdit.text())
    LEnd = float(self.ui.QELine_LEnd_lineEdit.text())

    if self.ui.QELine_SelectUnits_RLU_radioButton.isChecked():
        rlu = True
        Q1 = np.array([HStart, KStart, LStart])
        Q2 = np.array([HEnd, KEnd, LEnd])
    else:
        rlu = False
        Q1 = np.array([HStart, KStart])
        Q2 = np.array([HEnd, KEnd])

    # Collect them into one array
    QPoints = np.array([Q1, Q2])

    # Define orthogonal width and minimum pixel size along Q-cut
    width = float(self.ui.QELine_Width_lineEdit.text())
    minPixel = float(self.ui.QELine_MinPixel_lineEdit.text())

    # Define energy bins
    EMin = float(self.ui.QELine_EMin_lineEdit.text())
    EMax = float(self.ui.QELine_EMax_lineEdit.text())
    NPoints = int(self.ui.QELine_NPoints_lineEdit.text())
    EnergyBins = np.linspace(EMin, EMax, NPoints)

    # Check various plot settings

    if self.ui.QELine_LogScale_checkBox.isChecked():
        log = True
    else:
        log = False

    if self.ui.QELine_ConstantBins_checkBox.isChecked():
        constantBins = True
    else:
        constantBins = False

    try:
        # Make plot
        ax,DataLists,Bins,BinCenters,Offsets = \
        ds.plotCutQELine(QPoints=QPoints, width=width, \
                                        minPixel=minPixel, EnergyBins=EnergyBins,\
                                            rlu=rlu,log=log,constantBins=constantBins)

        # Make some final changes to the plot
        self.QELine = ax
        fig = self.QELine.get_figure()
        fig.set_size_inches(8, 6)

        if self.ui.QELine_Grid_checkBox.isChecked():
            ax.grid(True)
        else:
            ax.grid(False)

        self.QELine_setCAxis_button_function()

        self.windows.append(self.QELine.get_figure())
        self.QELine_SetTitle_button_function()

        return True
    except:
        _GUItools.dialog(
            text=
            'QELine cut could not be made. Check the limits for the cut and try again!'
        )
        return False