def on_exportFermiSurface(self): listOfEntries = self.table_model.listOfEntries() if len(listOfEntries) > 0: filename = QtGui.QFileDialog.getSaveFileName(self, "Save file", DATA_ROOT_FOLDER, selectedFilter='nxs') if len(filename) > 0: fermiSurfaceEntry = Arpes3DSpectrumConverter.listOfEntriesToNx( listOfEntries) if type(fermiSurfaceEntry) == tuple: QtGui.QMessageBox.critical( self, "Error", "Fermisurface could not be created.\n" + fermiSurfaceEntry[1]) return root = nx.NXroot(fermiSurfaceEntry.nxEntry) ext = os.path.splitext(str(filename))[1] if ext: filename = str(filename.replace(ext, ".nxs")) else: filename = str(filename) + ".nxs" root.save(filename=filename) print root.tree else: print "No filename"
class SpectrumFile: @classmethod def load(self,filepath): data = None filepath = str(filepath) extension = filepath.split('.')[-1] r = (0,'',data) if extension == "nxs": try: loadeddata = nx.nxload(filepath,'r') ## Check if data is ARPES, right now just load! if len(loadeddata.entries) != 1: # How many entries do we have in the nexus file data = ArpesData(loadeddata, 0) # Right now, just load the first one else: data = ArpesData(loadeddata) r = (True,str(data.title)+' loaded',data) except Exception, e: r = (False,"Error: File could not be loaded",data) elif extension == "sp2": try: arpes2DSpectrum = Arpes2DSpectrumConverter.SP2ToNx(filepath,rotation=float(0.0)) root = nx.NXroot(arpes2DSpectrum.nxEntry) data = ArpesData(root) r = (True,str(data.title)+' loaded',data) except Exception, e: r = (False,"Error: File could not be loaded",data)
def mergenexus(**kwargs): path = kwargs['path'] newfile = not os.path.isfile(path) if newfile: nxroot = nx.NXroot(nx.NXdata(kwargs['img'])) else: nxroot = nx.load(path, mode='rw') if not hasattr(nxroot.data, 'rawfile'): nxroot.data.rawfile = kwargs['rawpath'] if not hasattr(nxroot.data, 'thumb'): nxroot.data.thumbnail = kwargs['thumb'] if not hasattr(nxroot.data, 'variation'): nxroot.data.variation = kwargs['variation'].items() if newfile: writenexus(nxroot, kwargs['path'])
def handleSelectionChanged(self, selected, deselected): if len(selected.indexes()) == 0: ## deselected return index = selected.indexes()[0] if index.column() == 0: loadeddata = nx.NXroot( (self.table_model.entries[index.row()]).nxEntry) self.cData = ArpesData(loadeddata) self.DataPlot.plot2DData(self.cData.data, self.cData.axis1, self.cData.axis2, "", "", self.cData.title)
## Check if data is ARPES, right now just load! if len(loadeddata.entries) != 1: # How many entries do we have in the nexus file data = ArpesData(loadeddata, 0) # Right now, just load the first one else: data = ArpesData(loadeddata) r = (True,str(data.title)+' loaded',data) except Exception, e: r = (False,"Error: File could not be loaded",data) elif extension == "sp2": try: arpes2DSpectrum = Arpes2DSpectrumConverter.SP2ToNx(filepath,rotation=float(0.0)) root = nx.NXroot(arpes2DSpectrum.nxEntry) data = ArpesData(root) r = (True,str(data.title)+' loaded',data) except Exception, e: r = (False,"Error: File could not be loaded",data) elif extension == "ibw": try: arpes2DSpectrum = Arpes2DSpectrumConverter.ibwToNx(filepath,rotation=float(0.0)) root = nx.NXroot(arpes2DSpectrum.nxEntry) data = ArpesData(root) r = (True,str(data.title)+' loaded',data) except Exception, e: r = (False,"Error: File could not be loaded",data) else: r = (False,"Error: Not a valid file",data) return r