def Export(self, data, outFile, xslice, yslice, zslice, metadata=None, events=None, origName=None, progressCallback=None): from PYME.contrib.gohlke import tifffile from PYME.IO import dataWrap def _bool_to_uint8(data): if data.dtype == 'bool': return data.astype('uint8') else: return data if data.nbytes > 2e9: warnings.warn( 'Data is larger than 2GB, generated TIFF may not read in all software' ) if data.nbytes > 4e9: raise RuntimeError( 'TIFF has a maximum file size of 4GB, crop data or save as HDF' ) dw = dataWrap.ListWrap([ numpy.atleast_3d( _bool_to_uint8(data[xslice, yslice, zslice, i].squeeze())) for i in range(data.shape[3]) ]) #xmd = None if not metadata is None: xmd = MetaDataHandler.OMEXMLMDHandler(mdToCopy=metadata) if not origName is None: xmd.setEntry('cropping.originalFile', origName) xmd.setEntry('cropping.xslice', xslice.indices(data.shape[0])) xmd.setEntry('cropping.yslice', yslice.indices(data.shape[1])) xmd.setEntry('cropping.zslice', zslice.indices(data.shape[2])) description = xmd.getXML(dw) else: description = None tifffile.imsave_f(outFile, dw, description=description) if progressCallback: try: progressCallback(100, 100) except: pass
def Export(self, data, outFile, xslice, yslice, zslice, metadata=None, events=None, origName=None, progressCallback=None): from PYME.contrib.gohlke import tifffile from PYME.IO import dataWrap def _bool_to_uint8(data): if data.dtype == 'bool': return data.astype('uint8') else: return data dw = dataWrap.ListWrap([ numpy.atleast_3d( _bool_to_uint8(data[xslice, yslice, zslice, i].squeeze())) for i in range(data.shape[3]) ]) #xmd = None if not metadata is None: xmd = MetaDataHandler.OMEXMLMDHandler(mdToCopy=metadata) if not origName is None: xmd.setEntry('cropping.originalFile', origName) xmd.setEntry('cropping.xslice', xslice.indices(data.shape[0])) xmd.setEntry('cropping.yslice', yslice.indices(data.shape[1])) xmd.setEntry('cropping.zslice', zslice.indices(data.shape[2])) description = xmd.getXML(dw) else: description = None tifffile.imsave_f(outFile, dw, description=description) if progressCallback: try: progressCallback(100, 100) except: pass
def OnMakeComposites(self, event): import numpy as np dlg = CompositeDialog(self.dsviewer, self.dsviewer.image) imageNames = dlg.imageNames #dispNames = dlg.dispNames if dlg.ShowModal() == wx.ID_OK: #others = [dispNames[n] for n in dlg.GetSelections()] others = dlg.GetSelections() #master, mchan = _getImage(dlg.GetMaster()) ignoreZ = dlg.GetIgnoreZ() interp = dlg.GetInterp() if interp: order = 3 else: order = 0 shape, origin, voxelsize = dlg.shape, dlg.origin, dlg.voxelsize print((shape, origin, voxelsize)) if len(others) > 0: newNames = [] newData = [] for otherN in others: other, chan = _getImage(otherN) try: cn = other.mdh.getEntry('ChannelNames')[chan] otherName = '%s - %s' % (os.path.split(other.filename)[1], cn) except: if other.data.shape[3] == 1: otherName = os.path.split(other.filename)[1] else: otherName = '%s - %d' % (os.path.split(other.filename)[1], chan) newNames.append(otherName) if isinstance(other.data, dataWrap.ListWrap): od = other.data.dataList[chan] else: od = other.data if ignoreZ: originsEqual = np.allclose(other.origin[:2], origin[:2], atol=1) else: originsEqual = np.allclose(other.origin, origin, atol=1) shiftField = dlg.GetShiftmap(otherN) print(shape[:3], other.data.shape[:3]) if (not np.allclose(other.pixelSize, voxelsize[0], rtol=.001)) or (not (other.data.shape[:3] == shape[:3])) or (not originsEqual) or shiftField: #need to rescale ... print(('Remapping ', otherN, originsEqual, other.origin, np.allclose(other.pixelSize, voxelsize[0], rtol=.001),(not (other.data.shape[:3] == shape[:3])), shiftField, other.pixelSize, ignoreZ)) #print origin, voxelsize od = self.RemapData(other, chan, shape, voxelsize, origin, shiftField = shiftField, ignoreZ=ignoreZ, order=order) newData += [od] pre = common_prefix(newNames) print(pre) lPre = len(pre) newNames = [n[lPre:] for n in newNames] mdh = MetaDataHandler.NestedClassMDHandler(self.image.mdh) mdh.setEntry('ChannelNames', newNames) mdh['voxelsize.x'] = voxelsize[0]/1e3 mdh['voxelsize.y'] = voxelsize[1]/1e3 mdh['voxelsize.z'] = voxelsize[2]/1e3 mdh['Origin.x'] = origin[0] mdh['Origin.y'] = origin[1] mdh['Origin.z'] = origin[2] View3D(dataWrap.ListWrap(newData, 3), 'Composite', mdh=mdh, mode = self.dsviewer.mode, parent=wx.GetTopLevelParent(self.dsviewer), glCanvas=self.dsviewer.glCanvas) dlg.Destroy()