Exemplo n.º 1
0
 def choose_file(self):
     """
     Opens a file dialog and sets the file text box to the chosen path
     """
     from pyspec.spec import SpecDataFile
     filename, _ = QtGui.QFileDialog.getOpenFileName(self, 'Open file',
         os.path.expanduser('~'))
     self.filename.setText(str(filename))
     self.SPECfile = SpecDataFile(self.get_filename())
     self.spectra = self.SPECfile.findex.keys()
     self.scanmin.setText(str(self.spectra[0]))
     self.scanmax.setText(str(self.spectra[-1]))
Exemplo n.º 2
0
    def compute(self):
        spec_params = self.get_input("spec_file_params")
        spec_file_root = spec_params.spec_file_root
        data_folder_path = spec_params.data_folder_path
        scan_no = spec_params.scan_number

        print spec_file_root
        print data_folder_path
        sf = SpecDataFile(spec_file_root, ccdpath=data_folder_path)
        scan = sf[scan_no]

        fp = FileProcessor(spec=scan)

        fp.process()
        arr_2d_stack = fp.getImage()

        self.set_output("spec_img_stack", arr_2d_stack)
        self.set_output("spec_file", self)
        self.fp = fp
        self.sf = sf
        self.scan = scan
Exemplo n.º 3
0
class ImportDialog(BaseImportDialog):
    """Dialog to import SPEC Scans"""
 
    def __init__(self, parent=None):

        super(ImportDialog, self).__init__(parent)
        
        self.layout = QtGui.QVBoxLayout()
        self.layout.addLayout(self.filebox())
        self.layout.addLayout(self.scanbox())
        self.layout.addWidget(self.buttonbox())
        self.setLayout(self.layout)
  
        self.setWindowTitle("Import "+str(filetype))
 
    def scanbox(self):
        scanbox = QtGui.QHBoxLayout()
        scanminlabel = QtGui.QLabel("Min. Scan")
        self.scanmin = QtGui.QLineEdit()
        self.scanmin.setFixedWidth(100)
        self.scanmin.setAlignment(QtCore.Qt.AlignRight)
        scanmaxlabel = QtGui.QLabel("Max. Scan")
        self.scanmax = QtGui.QLineEdit()
        self.scanmax.setFixedWidth(100)
        self.scanmax.setAlignment(QtCore.Qt.AlignRight)
        scanbox.addWidget(scanminlabel)
        scanbox.addWidget(self.scanmin)
        scanbox.addWidget(scanmaxlabel)
        scanbox.addWidget(self.scanmax)
        return scanbox

    def choose_file(self):
        """
        Opens a file dialog and sets the file text box to the chosen path
        """
        from pyspec.spec import SpecDataFile
        filename, _ = QtGui.QFileDialog.getOpenFileName(self, 'Open file',
            os.path.expanduser('~'))
        self.filename.setText(str(filename))
        self.SPECfile = SpecDataFile(self.get_filename())
        self.spectra = self.SPECfile.findex.keys()
        self.scanmin.setText(str(self.spectra[0]))
        self.scanmax.setText(str(self.spectra[-1]))
    
    def get_spectra(self):
        try:
            specrange = sorted([int(self.scanmin.text()), int(self.scanmax.text())])
            specmin = self.spectra.index(specrange[0])
            specmax = self.spectra.index(specrange[1]) + 1
            return specmin, specmax
        except ValueError(error_message):
                QtGui.QMessageBox.critical(
                    self, "Invalid spectra", str(error_message),
                    QtGui.QMessageBox.Ok, QtGui.QMessageBox.NoButton)

    def get_data(self):
        root = NXroot()
        specmin, specmax = self.get_spectra()
        for i in self.spectra[0:specmax]:
            scan = self.SPECfile.getScan(i)
            if i < self.spectra[specmin]:
                continue
            title, entry, scan_type, cols, axis = self.parse_scan(scan)
            root[entry] = NXentry()
            root[entry].title = title
            root[entry].comments = scan.comments
            root[entry].data = NXdata()
            if isinstance(axis,list):
                scan_shape = (axis[1][1].size, axis[0][1].size)
                scan_size = np.prod(scan_shape)
                j = 0
                for col in cols:
                    root[entry].data[col] = NXfield(reshape_data(scan.data[:,j], 
                                                                 scan_shape))
                    j += 1
            else:
                j = 0
                for col in cols:
                    root[entry].data[col] = NXfield(scan.data[:,j])
                    j += 1
            root[entry].data.nxsignal = root[entry].data[cols[-1]]
            root[entry].data.errors = NXfield(np.sqrt(root[entry].data.nxsignal))
            if isinstance(axis,list):
                root[entry].data[axis[0][0]] = axis[0][1]
                root[entry].data[axis[1][0]] = axis[1][1]
                root[entry].data.nxaxes = [root[entry].data[axis[1][0]],
                                           root[entry].data[axis[0][0]]]
            else:
                root[entry].data.nxaxes = root[entry].data[axis]
        return root

    def parse_scan(self, scan):
        title = scan.header.splitlines()[0]
        words = title.split()
        scan_number = 's%s' % words[1]
        scan_type = words[2]
        cols = [lower(col.replace(' ', '_')) for col in scan.cols]
        axis = cols[0]
        try:
            if scan_type == "hscan":
                axis = 'H'
            elif scan_type == "kscan":
                axis = 'K'
            elif scan_type == "lscan":
                axis = 'L'
            elif scan_type == "hklscan":
                Hstart, Hend, Kstart, Kend, Lstart, Lend = words[3:8]
                if Hstart <> Hend:
                    axis = 'H'
                elif Kstart <> Kend:
                    axis = 'K'
                else:
                    axis = 'L'
            elif scan_type == "hklmesh":
                Q0, Q0start, Q0end, NQ0 = words[3], float(words[4]), float(words[5]), int(words[6])+1
                Q1, Q1start, Q1end, NQ1 = words[7], float(words[8]), float(words[9]), int(words[10])+1
                axis = [(Q0, np.linspace(Q0start, Q0end, NQ0)),
                        (Q1, np.linspace(Q1end, Q1start, NQ1))]
            else:
                if words[3] in motors.keys():
                    axis = motors[words[3]]
        finally:
            return title, scan_number, scan_type, cols, axis