Esempio n. 1
0
class AbstractGridOutputForm(AbstractOutputView):
    '''
    A mid level abstract class for output of grid data.  This adds inputs for the output grid
    dimensions.  Subclasses will need to add to _createDataBox in order to provide application 
    level inputs
    '''
    FORM_TITLE = "AbstractOutputForm"

    def __init__(self, **kwargs):
        '''
        Constructor
        '''
        super(AbstractGridOutputForm, self).__init__(**kwargs)
        self.gridWriter = VTIGridWriter()
        self.outputFileName = ""

    def _createDataBox(self):
        '''
        Create Widgets to collect output info.  This class adds parameters for the size of 
        the output grid.  Subclasses will override this method (Super'ing the method) to add 
        application specific inputs.
        '''
        dataBox = super(AbstractGridOutputForm, self)._createDataBox()
        layout = dataBox.layout()

        row = layout.rowCount()
        row += 1
        self._createGridDimensionInput(layout, row)

        return dataBox

    def _createGridDimensionInput(self, layout, row):
        '''
        provide parameters for output grid size
        '''
        label = qtGui.QLabel("Grid Dimensions")
        layout.addWidget(label, row, 0)
        row += 1
        label = qtGui.QLabel(X_STR)
        layout.addWidget(label, row, 0)
        self.xDimTxt = qtGui.QLineEdit()
        self.xDimTxt.setText(str(INITIAL_DIM))
        self.xDimValidator = qtGui.QIntValidator()
        self.xDimTxt.setValidator(self.xDimValidator)
        layout.addWidget(self.xDimTxt, row, 1)

        row += 1
        label = qtGui.QLabel(Y_STR)
        layout.addWidget(label, row, 0)
        self.yDimTxt = qtGui.QLineEdit()
        self.yDimTxt.setText(str(INITIAL_DIM))
        self.yDimValidator = qtGui.QIntValidator()
        self.yDimTxt.setValidator(self.yDimValidator)
        layout.addWidget(self.yDimTxt, row, 1)

        row += 1
        label = qtGui.QLabel(Z_STR)
        layout.addWidget(label, row, 0)
        self.zDimTxt = qtGui.QLineEdit()
        self.zDimTxt.setText(str(INITIAL_DIM))
        self.zDimValidator = qtGui.QIntValidator()
        self.zDimTxt.setValidator(self.zDimValidator)
        layout.addWidget(self.zDimTxt, row, 1)

    def getOutputFileName(self):
        '''
        dummy method to return self.outputFileName.  This is used by runMapper to 
        supply a filename for output files.  If the Writer used needs a fileName, 
        then the the derived class should supply self.outputFileName before running
        the mapper.  Otherwise a filename will be constructed using the project name 
        and gridWriter supplied extension.
        '''
        return self.outputFileName

    def runMapper(self, dataSource, transform):
        '''
        Run the selected mapper.  Writer specific class should be specified
        in the application specific subclass.  A list of forms is provided in 
        dataSource classes.
        '''
        logger.debug ("Entering " + self.FORM_TITLE + " " + \
            str(self.gridWriter))
        self.dataSource = dataSource
        nx = int(self.xDimTxt.text())
        ny = int(self.yDimTxt.text())
        nz = int(self.zDimTxt.text())
        self.outputFileName = self.getOutputFileName()
        if self.outputFileName == "":
            self.outputFileName = os.path.join(dataSource.projectDir,  \
                "%s%s" %(dataSource.projectName,self.gridWriter.FILE_EXTENSION) )
            self.setFileName.emit(self.outputFileName)
        if os.access(os.path.dirname(self.outputFileName), os.W_OK):
            self.mapper = QGridMapper(dataSource, \
                                     self.outputFileName, \
                                     self.outputType,\
                                     nx=nx, ny=ny, nz=nz,
                                     transform = transform,
                                     gridWriter = self.gridWriter,
                                     appConfig=self.appConfig)
            self.mapper.setProgressUpdater(self._updateProgress)
            self.mapper.doMap()
        else:
            self.processError.emit("The specified directory \n" + \
                                   str(os.path.dirname(self.outputFileName)) + \
                                   "\nis not writable")
        logger.debug("Exit " + self.FORM_TITLE)

    def stopMapper(self):
        '''
        Halt the mapping _process
        '''
        self.mapper.stopMap()
Esempio n. 2
0
class ProcessScans(qtGui.QDialog):
    '''
    This class presents a form to select to start analysis.  This display
    allows switching between Grid map and pole figure.
    '''
    def __init__(self, parent=None):
        '''
        Constructor - Layout widgets on the page & link up actions.
        '''
        super(ProcessScans, self).__init__(parent)
        self.Mapper = None
        layout = qtGui.QVBoxLayout()

        self.dataBox = self._createDataBox()
        controlBox = self._createControlBox()

        layout.addWidget(self.dataBox)
        layout.addWidget(controlBox)
        self.setLayout(layout)

    def _browseForOutputFile(self):
        '''
        Launch file browser to select the output file.  Checks are done to make
        sure the selected directory exists and that the selected file is 
        writable
        '''
        if self.outFileTxt.text() == "":
            fileName = str(qtGui.QFileDialog.getSaveFileName(None, \
                                               SAVE_FILE_STR, \
                                               filter=VTI_FILTER_STR))
        else:
            inFileName = str(self.outFileTxt.text())
            fileName = str(qtGui.QFileDialog.getSaveFileName(None,
                                               SAVE_FILE_STR,
                                               filter=VTI_FILTER_STR, \
                                               directory = inFileName))
        if fileName != "":
            if os.path.exists(os.path.dirname(str(fileName))):
                self.outFileTxt.setText(fileName)
                self.outputFileName = fileName
                self.outFileTxt.emit(qtCore.SIGNAL(EDIT_FINISHED_SIGNAL))
            else:
                message = qtGui.QMessageBox()
                message.warning(self, \
                             WARNING_STR, \
                             "The specified directory does not exist")
                self.outFileTxt.setText(fileName)
                self.outputFileName = fileName
                self.outFileTxt.emit(qtCore.SIGNAL(EDIT_FINISHED_SIGNAL))
            if not os.access(os.path.dirname(fileName), os.W_OK):
                message = qtGui.QMessageBox()
                message.warning(self, \
                             WARNING_STR, \
                             "The specified file is not writable")

    def _cancelProcess(self):
        '''
        Emit a signal to trigger the cancellation of processing.
        '''
        self.emit(qtCore.SIGNAL(CANCEL_PROCESS_SIGNAL))

    def _createControlBox(self):
        '''
        Create box wih the GUI controls Run & Cancel
        '''
        controlBox = qtGui.QGroupBox()
        controlLayout = qtGui.QGridLayout()
        row = 0
        self.progressBar = qtGui.QProgressBar()
        controlLayout.addWidget(self.progressBar, row, 1)

        self.runButton = qtGui.QPushButton(RUN_STR)
        controlLayout.addWidget(self.runButton, row, 3)

        self.cancelButton = qtGui.QPushButton(CANCEL_STR)
        self.cancelButton.setDisabled(True)

        controlLayout.addWidget(self.cancelButton, row, 4)

        self.connect(self.runButton, \
                     qtCore.SIGNAL(CLICKED_SIGNAL), \
                     self._process)
        self.connect(self.cancelButton, \
                     qtCore.SIGNAL(CLICKED_SIGNAL), \
                     self._cancelProcess)
        self.connect(self, \
                     qtCore.SIGNAL(UPDATE_PROGRESS_SIGNAL), \
                     self.setProgress)
        controlBox.setLayout(controlLayout)
        return controlBox

    def _createDataBox(self):
        '''
        Create Sub Layout for data gathering widgets
        '''
        dataBox = qtGui.QGroupBox()
        dataLayout = qtGui.QGridLayout()
        row = 0

        label = qtGui.QLabel("Grid Dimensions")
        dataLayout.addWidget(label, row, 0)
        row += 1
        label = qtGui.QLabel(X_STR)
        dataLayout.addWidget(label, row, 0)
        self.xDimTxt = qtGui.QLineEdit()
        self.xDimTxt.setText("200")
        self.xDimValidator = qtGui.QIntValidator()
        self.xDimTxt.setValidator(self.xDimValidator)
        dataLayout.addWidget(self.xDimTxt, row, 1)

        row += 1
        label = qtGui.QLabel(Y_STR)
        dataLayout.addWidget(label, row, 0)
        self.yDimTxt = qtGui.QLineEdit()
        self.yDimTxt.setText("200")
        self.yDimValidator = qtGui.QIntValidator()
        self.yDimTxt.setValidator(self.yDimValidator)
        dataLayout.addWidget(self.yDimTxt, row, 1)

        row += 1
        label = qtGui.QLabel(Z_STR)
        dataLayout.addWidget(label, row, 0)
        self.zDimTxt = qtGui.QLineEdit()
        self.zDimTxt.setText("200")
        self.zDimValidator = qtGui.QIntValidator()
        self.zDimTxt.setValidator(self.zDimValidator)
        dataLayout.addWidget(self.zDimTxt, row, 1)

        row += 1
        label = qtGui.QLabel("Output File")
        dataLayout.addWidget(label, row, 0)
        self.outputFileName = ""
        self.outFileTxt = qtGui.QLineEdit()
        self.outFileTxt.setText(self.outputFileName)
        dataLayout.addWidget(self.outFileTxt, row, 1)
        self.outputFileButton = qtGui.QPushButton(BROWSE_STR)
        dataLayout.addWidget(self.outputFileButton, row, 2)

        self.connect(self.outputFileButton, \
                     qtCore.SIGNAL(CLICKED_SIGNAL),
                     self._browseForOutputFile)
        self.connect(self.outputFileButton, \
                     qtCore.SIGNAL(EDIT_FINISHED_SIGNAL),
                     self._editFinishedOutputFile)
        self.connect(self.outFileTxt, \
                     qtCore.SIGNAL(EDIT_FINISHED_SIGNAL), \
                     self._editFinishedOutputFile)
        self.connect(self, qtCore.SIGNAL(SET_FILE_NAME_SIGNAL),
                     self.outFileTxt.setText)

        dataBox.setLayout(dataLayout)
        return dataBox

    def _editFinishedOutputFile(self):
        '''
        When editing is finished the a check is done to make sure that the 
        directory exists and the file is writable
        '''
        fileName = str(self.outFileTxt.text())
        if fileName != "":
            if os.path.exists(os.path.dirname(fileName)):
                self.outputFileName = fileName
            else:
                if os.path.dirname(fileName) == "":
                    curDir = os.path.realpath(os.path.curdir)
                    fileName = str(os.path.join(curDir, fileName))
                else:
                    message = qtGui.QMessageBox()
                    message.warning(self, \
                                 WARNING_STR, \
                                 "The specified directory \n" + \
                                 str(os.path.dirname(fileName)) + \
                                 "\ndoes not exist")

#               self.outputFileName = fileName
                self.emit(qtCore.SIGNAL(SET_FILE_NAME_SIGNAL), fileName)

            if not os.access(os.path.dirname(fileName), os.W_OK):
                message = qtGui.QMessageBox()
                message.warning(self, \
                             WARNING_STR, \
                             "The specified file is not writable")

    def _process(self):
        '''
        Emit a signal to trigger the start of processing.
        '''
        self.emit(qtCore.SIGNAL(PROCESS_SIGNAL))

    def runMapper(self, dataSource, transform):
        '''
        Run the selected mapper
        '''
        self.dataSource = dataSource
        nx = int(self.xDimTxt.text())
        ny = int(self.yDimTxt.text())
        nz = int(self.zDimTxt.text())
        if self.outputFileName == "":
            self.outputFileName = os.path.join(dataSource.projectDir,  \
                                               "%s.vti" %dataSource.projectName)
            self.emit(qtCore.SIGNAL(SET_FILE_NAME_SIGNAL), self.outputFileName)
        if os.access(os.path.dirname(self.outputFileName), os.W_OK):
            self.mapper = QGridMapper(dataSource, \
                                     self.outputFileName, \
                                     nx=nx, ny=ny, nz=nz,
                                     transform = transform,
                                     appConfig=self.appConfig)
            self.mapper.setProgressUpdater(self.updateProgress)
            self.mapper.doMap()
        else:
            self.emit(qtCore.SIGNAL(PROCESS_ERROR_SIGNAL), \
                         "The specified directory \n" + \
                         str(os.path.dirname(self.outputFileName)) + \
                         "\nis not writable")

    def setCancelOK(self):
        '''
        If Cancel is OK the run button is disabled and the cancel button is 
        enabled
        '''
        self.runButton.setDisabled(True)
        self.cancelButton.setDisabled(False)
        self.dataBox.setDisabled(True)

    def setOutFileName(self, name):
        '''
        Write a filename to the text widget and to the stored output file name
        :param name: Name of output file
        '''
        self.outFileTxt.setText(name)
        self.outputFileName = name

    def setProgress(self, value):
        '''
        Set the value in the progress bar
        :param value: value to write to the progress bar
        '''
        self.progressBar.setValue(value)

    def setProgressLimits(self, progressMin, progressMax):
        '''
        Set the limits on the progress bar.
        :param progressMin: Minimum value to store in the progress bar
        :param progressMax: Maximum value to store in the progress bar
        '''
        self.progressBar.setMinimum(progressMin)
        self.progressBar.setMaximum(progressMax)

    def setRunOK(self):
        '''
        If Run is OK the load button is enabled and the cancel button is 
        disabled
        '''
        self.runButton.setDisabled(False)
        self.cancelButton.setDisabled(True)
        self.dataBox.setDisabled(False)

    def _stopMapper(self):
        '''
        Halt the mapping _process
        '''
        self.mapper.stopMap()

    def updateProgress(self, value):
        '''
        Send signal to update the progress bar.
        :param value: value to be put on the progress bar.
        '''
        self.emit(qtCore.SIGNAL(UPDATE_PROGRESS_SIGNAL), value)
Esempio n. 3
0
    ds.setRangeBounds(ds.getOverallRanges())
    imageToBeUsed = ds.getImageToBeUsed()
    
    print("imageToBeUsed %s" % imageToBeUsed)
#    wavelen = ENERGY_WAVELENGTH_CONVERT_FACTOR/ds.getIncidentEnergy()[scans[0]]
    imageSize = np.prod(ds.getDetectorDimensions())
    print scanRange[0]
    for imageInScan in range(1, len(imageToBeUsed[scanRange[0]])+1):
        print ("Scan Line %d" % imageInScan)
        
        outputFileName = os.path.join(projectDir, specName + \
                                      ('_N%d.vti' % imageInScan))
        gridWriter = VTIGridWriter()

        tmpImageUsed = imageToBeUsed[scanRange[0]]
        savImageUsed = imageToBeUsed[scanRange[0]]
        tmpImageUsed[imageInScan] = False
        ds.imageToBeUsed[scanRange[0]]  = [not i for i in tmpImageUsed]
        gridMapper = QGridMapper(ds,
                                 outputFileName, 
                                 outputType=BINARY_OUTPUT,
                                 transform=UnityTransform3D(),
                                 gridWriter=gridWriter,
                                 appConfig=appConfig,
                                 nx=nx, ny=ny, nz=nz)
    
        gridMapper.setProgressUpdater(updateMapperProgress)
        gridMapper.doMap()
        ds.imageToBeUsed[scanRange[0]]  = savImageUsed
    
        
Esempio n. 4
0
class ProcessVTIOutputForm(AbstractOutputView):
    FORM_TITLE = "VTI Grid Output"
    
    @staticmethod
    def createInstance(parent=None, appConfig=None):
        return ProcessVTIOutputForm(parent=parent, appConfig=appConfig)
    
    def __init__(self, **kwargs):
        super(ProcessVTIOutputForm, self).__init__(**kwargs)
        logger.debug(METHOD_ENTER_STR)
        self.mapper = None
        layout = qtGui.QVBoxLayout()
        self.dataBox = self._createDataBox()
        controlBox = self._createControlBox()
        
        layout.addWidget(self.dataBox)
        layout.addWidget(controlBox)
        self.setLayout(layout)
        self.outputType = BINARY_OUTPUT
        logger.debug(METHOD_EXIT_STR)
        
    @Slot()
    def _browseForOutputFile(self):
        '''
        Launch file browser to select the output file.  Checks are done to make
        sure the selected directory exists and that the selected file is 
        writable
        '''
        logger.debug(METHOD_ENTER_STR)
        if self.outFileTxt.text() == EMPTY_STR:
            fileName = str(qtGui.QFileDialog.getSaveFileName(None, \
                                               SAVE_FILE_STR, \
                                               filter=VTI_FILTER_STR))
        else:
            inFileName = str(self.outFileTxt.text())
            fileName = str(qtGui.QFileDialog.getSaveFileName(None, 
                                               SAVE_FILE_STR, 
                                               filter=VTI_FILTER_STR, \
                                               directory = inFileName))
        if fileName != EMPTY_STR:
            if os.path.exists(os.path.dirname(str(fileName))):
                self.outFileTxt.setText(fileName)
                self.outputFileName = fileName
                self.outFileTxt.editingFinished.emit()
            else:
                message = qtGui.QMessageBox()
                message.warning(self, \
                             WARNING_STR, \
                             "The specified directory does not exist")
                self.outFileTxt.setText(fileName)
                self.outputFileName = fileName
                self.outFileTxt.editingFinished.emit()
            if not os.access(os.path.dirname(fileName), os.W_OK):
                message = qtGui.QMessageBox()
                message.warning(self, \
                             WARNING_STR, \
                             "The specified file is not writable")
        else:
            self.outputFileName = EMPTY_STR
            self.setOutFileText.emit(EMPTY_STR)
        logger.debug(METHOD_EXIT_STR)
#     @Slot()
#     def _cancelProcess(self):
#         '''
#         Emit a signal to trigger the cancellation of processing.
#         '''
#         self.cancel.emit(qtCore.SIGNAL(CANCEL_PROCESS_SIGNAL))
        

    def _createDataBox(self):
        '''
        Create Widgets to collect output info
        '''
        logger.debug(METHOD_ENTER_STR)
        dataBox = super(ProcessVTIOutputForm, self)._createDataBox()
        dataLayout = dataBox.layout()
        row = dataLayout.rowCount()
        
        label = qtGui.QLabel("Grid Dimensions")
        dataLayout.addWidget(label, row,0)
        row += 1
        label = qtGui.QLabel(X_STR)
        dataLayout.addWidget(label, row,0)
        self.xDimTxt = qtGui.QLineEdit()
        self.xDimTxt.setText("200")
        self.xDimValidator = qtGui.QIntValidator()
        self.xDimTxt.setValidator(self.xDimValidator)
        dataLayout.addWidget(self.xDimTxt, row,1)
        
        row += 1
        label = qtGui.QLabel(Y_STR)
        dataLayout.addWidget(label, row,0)
        self.yDimTxt = qtGui.QLineEdit()
        self.yDimTxt.setText("200")
        self.yDimValidator = qtGui.QIntValidator()
        self.yDimTxt.setValidator(self.yDimValidator)
        dataLayout.addWidget(self.yDimTxt, row,1)
        
        row += 1
        label = qtGui.QLabel(Z_STR)
        dataLayout.addWidget(label, row,0)
        self.zDimTxt = qtGui.QLineEdit()
        self.zDimTxt.setText("200")
        self.zDimValidator = qtGui.QIntValidator()
        self.zDimTxt.setValidator(self.zDimValidator)
        dataLayout.addWidget(self.zDimTxt, row,1)
        
        row += 1
        label = qtGui.QLabel("Output File")
        dataLayout.addWidget(label, row,0)
        self.outputFileName = ""
        self.outFileTxt = qtGui.QLineEdit()
        self.outFileTxt.setText(self.outputFileName)
        dataLayout.addWidget(self.outFileTxt, row,1)
        self.outputFileButton = qtGui.QPushButton(BROWSE_STR)
        dataLayout.addWidget(self.outputFileButton, row, 2)

        row += 1
        label = qtGui.QLabel("Output Type")
        dataLayout.addWidget(label, row, 0)
        self.outputTypeSelect = QComboBox()
        self.outputTypeSelect.addItem(BINARY_OUTPUT)
        self.outputTypeSelect.addItem(ASCII_OUTPUT)
        dataLayout.addWidget(self.outputTypeSelect, row, 2)
        
        self.outputFileButton.clicked.connect(self._browseForOutputFile)
#         self.connect(self.outputFileButton, \
#                      qtCore.SIGNAL(EDIT_FINISHED_SIGNAL), 
#                      self._editFinishedOutputFile)
        self.outFileTxt.editingFinished.connect(self._editFinishedOutputFile)
        self.setFileName[str].connect( self.setOutFileText)
        self.outputTypeSelect.currentIndexChanged[str]. \
            connect(self._selectedTypeChanged)
        logger.debug(METHOD_EXIT_STR)
        return dataBox
        
    @Slot()
    def _editFinishedOutputFile(self):
        '''
        When editing is finished the a check is done to make sure that the 
        directory exists and the file is writable
        '''
        logger.debug(METHOD_ENTER_STR)
        fileName = str(self.outFileTxt.text())
        if fileName != EMPTY_STR:
            if os.path.exists(os.path.dirname(fileName)):
                self.outputFileName = fileName
            else:
                if os.path.dirname(fileName) == EMPTY_STR:
                    curDir = os.path.realpath(os.path.curdir)
                    fileName = str(os.path.join(curDir, fileName))
                else:
                    message = qtGui.QMessageBox()
                    message.warning(self, \
                                 WARNING_STR, \
                                 "The specified directory \n" + \
                                 str(os.path.dirname(fileName)) + \
                                 "\ndoes not exist")
                
#               self.outputFileName = fileName
                self.setFileName.emit(fileName)
                
            if not os.access(os.path.dirname(fileName), os.W_OK):
                message = qtGui.QMessageBox()
                message.warning(self, \
                             WARNING_STR, \
                             "The specified file is not writable")
        else:
            self.outputFileName = EMPTY_STR
            self.setOutFileText.emit(EMPTY_STR)
        logger.debug(METHOD_EXIT_STR)
#     @Slot()
#     def _process(self):
#         '''
#         Emit a signal to trigger the start of processing.
#         '''
#         self.emit(qtCore.SIGNAL(PROCESS_SIGNAL))
        
    def runMapper(self, dataSource, transform, gridWriter=None):
        '''
        Run the selected mapper
        '''
        logger.debug(METHOD_ENTER_STR)
        self.dataSource = dataSource
        nx = int(self.xDimTxt.text())
        ny = int(self.yDimTxt.text())
        nz = int(self.zDimTxt.text())
        logger.debug( "nx,ny,nz %d,%d,%d" % (nx, ny, nz))
        outType = self.outputType
        if self.outputFileName == "":
            self.outputFileName = os.path.join(dataSource.projectDir,  \
                                               "%s.vti" %dataSource.projectName)
            self.setFileName[str].emit(self.outputFileName)
        if os.access(os.path.dirname(self.outputFileName), os.W_OK):
            self.mapper = QGridMapper(dataSource, \
                                     self.outputFileName, \
                                     outType, \
                                     nx=nx, ny=ny, nz=nz, \
                                     transform = transform, \
                                     gridWriter = gridWriter,
                                     appConfig=self.appConfig)
            self.mapper.setGridWriter(VTIGridWriter())
            self.mapper.setProgressUpdater(self._updateProgress)
            self.mapper.doMap()
        else:
            self.processError.emit("The specified directory \n" + \
                                   str(os.path.dirname(self.outputFileName)) + \
                                   "\nis not writable")
        logger.debug(METHOD_EXIT_STR)
        
    @Slot(str)
    def _selectedTypeChanged(self, typeStr):
        logger.debug(METHOD_ENTER_STR)
        self.outputType = str(typeStr)
        logger.debug(METHOD_EXIT_STR)
        
    @Slot(str)
    def setOutFileText(self, outFile):
        logger.debug(METHOD_ENTER_STR)
        self.outFileTxt.setText(outFile)
        self.outFileTxt.editingFinished.emit()
        
    def _stopMapper(self):
        '''
        Halt the mapping _process
        '''
        logger.debug(METHOD_ENTER_STR)
        self.mapper.stopMap()
        logger.debug(METHOD_EXIT_STR)