def getObject3DInstance(config=None): #for the time being a former configuration #for serializing purposes is not implemented #I do the import here for the case PyMca is not installed #because the modules could be instanstiated without using #this method try: from PyMca5.PyMcaIO import EDFStack from PyMca5.PyMcaIO import TiffStack except ImportError: import EDFStack import TiffStack fileTypeList = [ 'EDF Z Stack (*edf *ccd)', 'EDF X Stack (*edf *ccd)', 'TIFF Stack (*tif *tiff)' ] old = PyMcaFileDialogs.PyMcaDirs.nativeFileDialogs * 1 PyMcaFileDialogs.PyMcaDirs.nativeFileDialogs = False fileList, filterUsed = PyMcaFileDialogs.getFileList( parent=None, filetypelist=fileTypeList, message="Please select the object file(s)", mode="OPEN", getfilter=True) PyMcaFileDialogs.PyMcaDirs.nativeFileDialogs = old if not len(fileList): return None if filterUsed == fileTypeList[0]: fileindex = 2 else: fileindex = 1 #file index is irrelevant in case of an actual 3D stack. filename = fileList[0] legend = os.path.basename(filename) if filterUsed == fileTypeList[2]: #TIFF stack = TiffStack.TiffStack(dtype=numpy.float32, imagestack=False) stack.loadFileList(fileList, fileindex=1) elif len(fileList) == 1: stack = EDFStack.EDFStack(dtype=numpy.float32, imagestack=False) stack.loadIndexedStack(filename, fileindex=fileindex) else: stack = EDFStack.EDFStack(dtype=numpy.float32, imagestack=False) stack.loadFileList(fileList, fileindex=fileindex) if stack is None: raise IOError("Problem reading stack.") object3D = Object3DStack(name=legend) object3D.setStack(stack) return object3D
def get4DStack(): """ Open a stack of image files in EDF or TIFF format, and return the data with metadata. :returns: legend, data, xScale, yScale, fileindex Legend and data are both ``None`` in case of failure. Scales are 2-tuples (originX, deltaX). fileindex indicates the dimension/axis in the data corresponding to the Z-axis. :raise IOError: If the data could not be read """ fileTypeList = [ 'EDF Z Stack (*edf *ccd)', 'EDF X Stack (*edf *ccd)', 'TIFF Stack (*tif *tiff)' ] old = PyMcaFileDialogs.PyMcaDirs.nativeFileDialogs * 1 PyMcaFileDialogs.PyMcaDirs.nativeFileDialogs = False fileList, filterUsed = PyMcaFileDialogs.getFileList( parent=None, filetypelist=fileTypeList, message="Please select the object file(s)", mode="OPEN", getfilter=True) PyMcaFileDialogs.PyMcaDirs.nativeFileDialogs = old if not fileList: return None, None if filterUsed.startswith('EDF Z'): fileindex = 2 else: fileindex = 1 filename = fileList[0] legend = os.path.basename(filename) if filterUsed.startswith('TIFF'): stack = TiffStack.TiffStack(dtype=numpy.float32, imagestack=False) stack.loadFileList(fileList, fileindex=1) else: stack = EDFStack.EDFStack(dtype=numpy.float32, imagestack=False) if len(fileList) == 1: stack.loadIndexedStack(filename, fileindex=fileindex) else: stack.loadFileList(fileList, fileindex=fileindex) if stack is None: raise IOError("Problem reading stack.") xScale = stack.info.get("xScale") yScale = stack.info.get("yScale") return legend, stack.data, xScale, yScale, fileindex
def __tryEdf(self, inputfile): try: ffile = EdfFileLayer.EdfFileLayer(fastedf=0) ffile.SetSource(inputfile) fileinfo = ffile.GetSourceInfo() if fileinfo['KeyList'] == []: ffile = None elif len(self._filelist) == 1: #Is it a Diamond stack? if len(fileinfo['KeyList']) > 1: info, data = ffile.LoadSource(fileinfo['KeyList'][0]) shape = data.shape if len(shape) == 2: if min(shape) == 1: #It is a Diamond Stack ffile = EDFStack.EDFStack(inputfile) return ffile except: return None
def testEdfMap(self): filename = os.path.join(self.path, 'xrfmap.edf') nDet = 2 info = XrfData.generateEdfMap(filename, nDet=nDet, same=False) nDet0, nRows0, nColumns0, nChannels = info['data'].shape from PyMca5.PyMcaIO import EDFStack files = [ os.path.join(self.path, 'xrfmap_xia{:02d}_0001_0000_{:04d}.edf'.format(k, i)) for i in range(nRows0) for k in range(nDet0) ] stack = EDFStack.EDFStack(filelist=sorted(files)).data self.assertEqual(nDet, nDet0) self.assertEqual(stack.shape, (nDet0 * nRows0, nColumns0, nChannels)) for i in range(nRows0): for j in range(nColumns0): for k in range(nDet): mca = stack[i + k * nRows0, j] numpy.testing.assert_array_equal(mca, info['data'][k, i, j])
if opt in '--begin': begin = int(arg) elif opt in '--end': end = int(arg) elif opt in '--fileindex': fileindex = int(arg) app = qt.QApplication(sys.argv) window = SceneGLWindow.SceneGLWindow() window.show() if len(sys.argv) == 1: object3D = getObject3DInstance() if object3D is not None: window.addObject(object3D) else: if len(sys.argv) > 1: stack = EDFStack.EDFStack(dtype=numpy.float32, imagestack=False) filename = args[0] else: stack = EDFStack.EDFStack(dtype=numpy.float32, imagestack=False) filename = r"..\COTTE\ch09\ch09__mca_0005_0000_0070.edf" if os.path.exists(filename): print("fileindex = ", fileindex) stack.loadIndexedStack(filename, begin=begin, end=end, fileindex=fileindex) object3D = Object3DStack() object3D.setStack(stack) stack = 0 else: print("filename %s does not exists" % filename) sys.exit(1) time.sleep(1) print("START ADDING")