Example #1
0
 def on_actionImportSpecFile_triggered(self, force=False):
     f = '%s'% QtGui.QFileDialog.getOpenFileName(self, 'Open File', '.',
                 "Spec datafiles (*.dat *.mca);;All files (*)")
     if f:
         while 1:
             h5_filename = str(
                 QtGui.QFileDialog.getSaveFileName(
                     self,
                     'Save HDF5 File',
                     './'+f+'.h5',
                     'HDF5 files (*.h5 *.hdf5 *.hdf *.nxs)'
                 )
             )
             if h5_filename and os.path.isfile(h5_filename):
                 res = QtGui.QMessageBox.question(
                     self,
                     'overwrite?',
                     'Do you want to overwrite the existing file?',
                     QtGui.QMessageBox.Yes,
                     QtGui.QMessageBox.No
                 )
                 if res == QtGui.QMessageBox.Yes:
                     os.remove(h5_filename)
                 else:
                     continue
             break
         if h5_filename:
             self.statusBar.showMessage('Converting spec data...')
             #QtGui.qApp.processEvents()
             from xpaxs.io.spec import convert_to_phynx
             f = convert_to_phynx(f, h5_filename=h5_filename, force=True)
             f.close()
             del f
             self.statusBar.clearMessage()
             self.openFile(h5_filename)
Example #2
0
def convert_to_phynx(
        spec_filename, h5_filename=None, oldh5_filename=None, force=False
    ):
    """convert a spec data file to phynx and return the phynx file object"""

    from xpaxs.io import spec
    f = spec.convert_to_phynx(spec_filename, h5_filename, force)

    if oldh5_filename is None:
        oldh5_filename = spec_filename + '.h5.old'
    if os.path.exists(oldh5_filename):
        oldf = tables.openFile(oldh5_filename, 'r')
        edict = dict(
            [(entry._v_attrs.scanNumber, entry)
                for entry in oldf.root]
        )

        for k, oldentry in edict.iteritems():
            try:
                newentry = f['entry_%d'%(int(k))]
                convert_entry(oldentry, newentry)
            except:
                pass

    return f
Example #3
0
def convert_to_phynx(
        spec_filename, h5_filename=None, oldh5_filename=None, force=False
    ):
    """convert a spec data file to phynx and return the phynx file object"""

    from xpaxs.io import spec
    f = spec.convert_to_phynx(spec_filename, h5_filename, force)

    if oldh5_filename is None:
        oldh5_filename = spec_filename + '.h5.old'
    if os.path.exists(oldh5_filename):
        oldf = h5py.File(oldh5_filename, 'r')
        try:
            edict = dict(
                [(entry.attrs['scan number'], entry)
                    for entry in oldf.itervalues()]
            )
        except h5py.H5Error:
            edict = dict(
                [(entry.attrs['scanNumber'], entry)
                    for entry in oldf.itervalues()]
            )

        for k, oldentry in edict.iteritems():
            try:
                newentry = f['entry_%d'%(int(k))]
                convert_entry(oldentry, newentry)
            except:
                pass

    return f