예제 #1
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 praxes.io.phynx.migration 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
예제 #2
0
 def on_actionImportSpecFile_triggered(self, force=False):
     f = '%s' % QtGui.QFileDialog.getOpenFileName(
         self, 'Open File', os.getcwd(),
         "Spec datafiles (*.dat *.mca);;All files (*)")
     if f:
         while 1:
             h5_filename = str(
                 QtGui.QFileDialog.getSaveFileName(
                     self, 'Save HDF5 File',
                     os.path.join(os.getcwd(), 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 praxes.io.phynx.migration.spec import convert_to_phynx
             h5file = convert_to_phynx(f,
                                       h5_filename=h5_filename,
                                       force=True,
                                       report=True)
             h5file.close()
             self.statusBar.clearMessage()
             self.openFile(h5_filename)
예제 #3
0
파일: transitional.py 프로젝트: rh66/praxes
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 praxes.io.phynx.migration 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
예제 #4
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 praxes.io.phynx.migration 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
예제 #5
0
파일: mainwindow.py 프로젝트: rmbaur/praxes
 def on_actionImportSpecFile_triggered(self, force=False):
     f = '%s'% QtGui.QFileDialog.getOpenFileName(
         self,
         'Open File',
         os.getcwd(),
         "Spec datafiles (*.dat *.mca);;All files (*)"
         )
     if f:
         while 1:
             h5_filename = str(
                 QtGui.QFileDialog.getSaveFileName(
                     self,
                     'Save HDF5 File',
                     os.path.join(os.getcwd(), 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 praxes.io.phynx.migration.spec import convert_to_phynx
             f = convert_to_phynx(
                 f, h5_filename=h5_filename, force=True, report=True
                 )
             f.close()
             del f
             self.statusBar.clearMessage()
             self.openFile(h5_filename)