Exemplo n.º 1
0
	def __init__(self, filename = ""):
		"""
		Constructor
		"""
		DataSource.__init__(self)
		# list of references to individual datasets (= timepoints) stored in 
		# vti-files
		self.polydataReader = None
		self.dataSets = []
		self.polyTimepoint = -1
		self.polyDataFiles = []
		# filename of the .du-file
		self.filename = filename
		self.baseFilename = ""
		self.setPath(filename)
		# path to the .du-file and .vti-file(s)
		self.path = ""
		self.reader = None
		# Number of datasets added to this datasource
		self.counter = 0
		self.parser = None
		self.ctf = None
		# TODO: what is this?
		# self.dataUnitSettings = {}
		self.settings = None
		self.dimensions = None
		self.spacing = None
		self.voxelsizes = None
    def __init__(self, source, component):
        """
		Initialization
		"""
        DataSource.__init__(self)
        self.source = source
        self.component = component
        self.extract = vtk.vtkImageExtractComponents()
        self.extract.SetComponents(self.component)
        self.setPath = source.setPath
        self.getPath = source.getPath
        self.setMask = source.setMask
        self.getSpacing = source.getSpacing
        self.getVoxelSize = source.getVoxelSize
        self.setResampleDimensions = source.setResampleDimensions
        self.getOriginalScalarRange = source.getOriginalScalarRange
        self.getOriginalDimensions = source.getOriginalDimensions
        self.getResampleFactors = source.getResampleFactors
        self.getResampledVoxelSize = source.getResampledVoxelSize
        self.getResampleDimensions = source.getResampleDimensions
        self.setIntensityScale = source.setIntensityScale
        self.getIntensityScaledData = source.getIntensityScaledData
        self.getResampledData = source.getResampledData
        self.getEmissionWavelength = source.getEmissionWavelength
        self.getExcitationWavelength = source.getExcitationWavelength
        self.getNumericalAperture = source.getNumericalAperture
        self.getDataSetCount = source.getDataSetCount
        self.getFileName = source.getFileName
        self.getDimensions = source.getDimensions
        self.getScalarRange = source.getScalarRange
        self.ctf = None
Exemplo n.º 3
0
	def __init__(self, filename = "", channel = -1, \
					name = ""):
		"""
		Constructor
		"""
		DataSource.__init__(self)
		self.channel = channel
		
		if not name:
			name = "Ch%d" % channel
		self.bitdepth = 12
		self.name = name

		self.timepoint = 0
		self.timepoints = 0
		self.filename = filename
		self.parser = ConfigParser.RawConfigParser()
		if filename:
			filepointer = codecs.open(self.convertFileName(filename), "r", "utf-16")
			self.parser.readfp(filepointer)
			dataName = self.parser.get("File Info","DataName")
			if dataName[0] == '"':
				dataName = dataName[1:]
			if dataName[-1] == '"':
				dataName = dataName[:-1]
			directoryName, self.lutFileName = self.getLUTPath(self.channel)
			newLut = os.path.join(directoryName, self.lutFileName)
			newLut = os.path.join(os.path.dirname(self.filename), newLut)
			if not os.path.exists(newLut):
				self.path = "%s.files"%self.filename
				print self.lutFileName
			else:
				self.path = os.path.join(os.path.dirname(filename), directoryName)
			
			# when lutFileName is e.g. bro28_par3_07-04-18_LUT1.lut, we take the 
			# bro28_par3_07-04-18 and ignore the LUT1.lut, and use that as the basis of the filenames
			# for the tiff files
			self.fileNameBase = "_".join(self.lutFileName.split("_")[:-1])
			#self.fileNameBase = dataName
			
		self.reader = None
		self.originalScalarRange = (0, 4095)
		self.scalarRange = 0, 2 ** self.bitdepth - 1
		self.dimensions = (0,0,0)
		self.voxelsize = (1,1,1)
		self.spacing = None
		self.emission = 0
		self.excitation = 0
		self.color = None
		self.shift = None
		self.noZ = 0
		self.reverseSlices = True

		if channel >= 0:
			self.ctf = self.readLUT()
		self.setPath(filename)
		
		# nm = nanometer, um = micrometer, mm = millimeter
		self.unit_coeffs = {"nm":1e-9, "um":1e-6, "mm":0.001,"ms":0.001}
		self.shortname = None
Exemplo n.º 4
0
	def __init__(self, filename = "", experiment = "", channel = -1):
		"""
		Constructor
		"""    
		DataSource.__init__(self)
		self.filename = filename
		self.reader = LeicaExperiment(filename, progressCallback = self.updateProgress)
		self.shortname = os.path.basename(filename)

		self.experiment = experiment
		if experiment:
			self.originalDimensions = self.reader.GetDimensions(self.experiment)
			duration = self.reader.GetDuration(self.experiment)
			numT = self.reader.GetNumberOfTimepoints(self.experiment)
			print "Number of Timepoints = ",numT
			print "Duration=",duration
			step = duration/float(numT)
			stamps = []
			for t in range(0, numT):
				stamps.append(step*t)
			self.setTimeStamps(stamps)
			self.setAbsoluteTimeStamps(stamps)
			
		self.channel = channel
		self.dimensions = None
		self.voxelsize = None
		self.spacing = None
		self.color = None
		self.ctf = None
		self.setPath(filename)
		self.datasetCount = None
Exemplo n.º 5
0
	def __init__(self, filename = ""):
		"""
		Constructor
		"""	   
		DataSource.__init__(self)
		self.setPath(filename)
		dataSetName = os.path.basename(filename)
		dataSetName = dataSetName.split(".")
		dataSetName = ".".join(dataSetName[:-1])
		self.dataSetName = dataSetName
		self.io = itk.BioRadImageIO.New()
		self.reader = itk.ImageFileReader[itk.Image.UC3].New()
		self.reader.SetImageIO(self.io.GetPointer())
		self.ctf = None
		self.filename = filename
		self.filepattern = None
		self.dimensions = None
		self.voxelsize = None
		self.spacing = None
		self.itkToVtk = None
		self.color = None
		self.shift = None
		self.tps = -1
		if filename:
			self.path = os.path.dirname(filename)
			self.getDataSetCount()
Exemplo n.º 6
0
	def __init__(self, filename = ""):
		"""
		Constructor of MRCDataSource
		"""
		DataSource.__init__(self)
		self.filename = filename
		self.setPath(filename)

		self.bitDepth = 0
		self.spacing = None
		self.voxelSize = None

		# Create vtkMRCReader for reading MRC files
		self.reader = vtkbxd.vtkMRCReader()
		self.reader.AddObserver('ProgressEvent', lib.messenger.send)
		lib.messenger.connect(self.reader, 'ProgressEvent', self.updateProgress)

		if self.filename:
			self.reader.SetFileName(self.convertFileName(self.filename))
			if self.reader.OpenFile():
				if self.reader.ReadHeader():
					self.setOriginalScalarRange()
				else:
					Logging.error("Failed to read the header of the MRC file correctly",
					"Error in MRCDataSource.py in __init.py__, failed to read the header of the MRC file: %s" %(self.filename))
					return
			else:
				Logging.error("Failed to open file",
							  "Error in MRCDataSource.py in __init__, failed to open file: %s" %(self.filename))
				return
Exemplo n.º 7
0
	def __init__(self, filename = ""):
		"""
		Constructor
		"""    
		DataSource.__init__(self)
		
		name = os.path.basename(filename)
		name = name.split(".")
		name = ".".join(name[:-1])
		self.name = name
		self.setPath(filename)
		self.filename = filename
		self.reader = None

		self.datatype = "Float"
		
		self.dimensions = None
		self.voxelsize = (1, 1, 1)
		self.spacing = None
		self.color = None
		self.shift = None
		self.tps = -1
		self.numberOfImages = 0
		self.dataFileName = ""
		self.bytesPerPixel = 0
		self.duration = 0.0
		
		if filename:
			self.path = os.path.dirname(filename)
			self.getDataSetCount()            
			f = open(filename, "r")
			self.readInfo(f)
			f.close()
			self.createTimeStamps()
Exemplo n.º 8
0
    def __init__(self, filename=""):
        """
		Constructor of MRCDataSource
		"""
        DataSource.__init__(self)
        self.filename = filename
        self.setPath(filename)

        self.bitDepth = 0
        self.spacing = None
        self.voxelSize = None

        # Create vtkMRCReader for reading MRC files
        self.reader = vtkbxd.vtkMRCReader()
        self.reader.AddObserver('ProgressEvent', lib.messenger.send)
        lib.messenger.connect(self.reader, 'ProgressEvent',
                              self.updateProgress)

        if self.filename:
            self.reader.SetFileName(self.convertFileName(self.filename))
            if self.reader.OpenFile():
                if self.reader.ReadHeader():
                    self.setOriginalScalarRange()
                else:
                    Logging.error(
                        "Failed to read the header of the MRC file correctly",
                        "Error in MRCDataSource.py in __init.py__, failed to read the header of the MRC file: %s"
                        % (self.filename))
                    return
            else:
                Logging.error(
                    "Failed to open file",
                    "Error in MRCDataSource.py in __init__, failed to open file: %s"
                    % (self.filename))
                return
Exemplo n.º 9
0
	def __init__(self, source, component):
		"""
		Initialization
		"""
		DataSource.__init__(self)
		self.source = source
		self.component = component
		self.extract = vtk.vtkImageExtractComponents()
		self.extract.SetComponents(self.component)
		self.setPath = source.setPath
		self.getPath = source.getPath
		self.setMask = source.setMask
		self.getSpacing = source.getSpacing
		self.getVoxelSize = source.getVoxelSize
		self.setResampleDimensions = source.setResampleDimensions
		self.getOriginalScalarRange = source.getOriginalScalarRange
		self.getOriginalDimensions = source.getOriginalDimensions
		self.getResampleFactors = source.getResampleFactors
		self.getResampledVoxelSize = source.getResampledVoxelSize
		self.getResampleDimensions = source.getResampleDimensions
		self.setIntensityScale = source.setIntensityScale
		self.getIntensityScaledData = source.getIntensityScaledData
		self.getResampledData = source.getResampledData
		self.getEmissionWavelength = source.getEmissionWavelength
		self.getExcitationWavelength = source.getExcitationWavelength
		self.getNumericalAperture = source.getNumericalAperture
		self.getDataSetCount = source.getDataSetCount
		self.getFileName = source.getFileName
		self.getDimensions = source.getDimensions
		self.getScalarRange = source.getScalarRange
		self.ctf = None
Exemplo n.º 10
0
	def testGetCacheKey(self):
		winFileName = "Data\\DataFile"
		unixFileName = "Data/DataFile"
#		macFileName = "Data:DataFile"
		channelName = "DataChannel"
		purpose = "Purpose"
		resultKey = "Data_DataFile_DataChannel_Purpose"
		self.assertEquals(DataSource.getCacheKey(winFileName, channelName, purpose), resultKey)
		self.assertEquals(DataSource.getCacheKey(unixFileName, channelName, purpose), resultKey)
		self.assertEquals(DataSource.getCacheKey(winFileName, channelName, purpose), resultKey)
	def __init__(self, filenames = [], callback = None):
		"""
		Constructor
		"""
		DataSource.__init__(self)
		self.name = "Import"
		self.extMapping = {"tif": "TIFF", "tiff": "TIFF", "png": "PNG", "jpg": "JPEG", "jpeg": "JPEG", \
							"pnm": "PNM", "vti": "XMLImageData", "vtk": "DataSet", "bmp": "BMP"}
		self.dimMapping = {"bmp":2, "tif":2, "tiff":2, "png":2, "jpg":2, "jpeg":2, "pnm":2, "vti":3, "vtk":3}
		self.callback = callback
		self.initialize()
Exemplo n.º 12
0
    def __init__(self, filename="", channelNum=-1):
        """
		Constructor
		"""
        DataSource.__init__(self)
        # Name and path of the lsm-file:
        self.filename = filename
        if len(os.path.basename(self.filename)) > 4:
            self.imageName = os.path.basename(self.filename)[:-4]
        self.numericalAperture = 0
        self.excitationWavelength = 0
        self.timepoint = -1
        self.shortname = os.path.basename(filename)
        self.path = ""
        # An lsm-file may contain multiple channels. However, LsmDataSource only
        # handles one channel. The following attribute indicates, which channel
        # within the lsm-file is hadled by this LsmDataSource instance.
        self.channelNum = channelNum
        self.setPath(filename)
        self.dataUnitSettings = {}

        self.spacing = None
        self.origin = None
        self.voxelsize = None
        # vtkLSMReader is used to do the actual reading:
        self.reader = vtkbxd.vtkLSMReader()
        #self.reader.DebugOn()
        self.reader.AddObserver("ProgressEvent", lib.messenger.send)
        lib.messenger.connect(self.reader, 'ProgressEvent',
                              self.updateProgress)
        # If a filename was specified, the file is loaded
        if self.filename:
            self.path = os.path.dirname(filename)
            Logging.info("LsmDataSource created with file %s and channelNum=%d"%\
            (self.filename, channelNum), kw = "lsmreader")
            try:
                f = open(self.convertFileName(filename))
                f.close()
            except IOError, ex:
                Logging.error(
                    "Failed to open LSM file",
                    "Failed to open file %s for reading: %s" %
                    (filename, str(ex)))
                return

            self.reader.SetFileName(self.convertFileName(self.filename))
            self.reader.SetUpdateChannel(channelNum)
            self.reader.UpdateInformation()
            self.originalScalarRange = None
            self.getBitDepth()
            self.originalDimensions = self.reader.GetDimensions()[0:3]
            self.readTimeStamps()
	def __init__(self, filename = "", channelNum = -1):
		"""
		Constructor
		"""
		DataSource.__init__(self)
		# Name and path of the lsm-file:
		self.filename = filename
		if len(os.path.basename(self.filename)) > 4:
			self.imageName = os.path.basename(self.filename)[:-4]
		self.numericalAperture = 0
		self.excitationWavelength = 0
		self.timepoint = -1
		self.shortname = os.path.basename(filename)
		self.path = ""
		# An lsm-file may contain multiple channels. However, LsmDataSource only
		# handles one channel. The following attribute indicates, which channel
		# within the lsm-file is hadled by this LsmDataSource instance.
		self.channelNum = channelNum
		self.setPath(filename)
		self.dataUnitSettings = {}

		self.spacing = None
		self.origin = None
		self.voxelsize = None
		# vtkLSMReader is used to do the actual reading:
		self.reader = vtkbxd.vtkLSMReader()
		#self.reader.DebugOn()
		self.reader.AddObserver("ProgressEvent", lib.messenger.send)
		lib.messenger.connect(self.reader, 'ProgressEvent', self.updateProgress)
		# If a filename was specified, the file is loaded
		if self.filename:
			self.path = os.path.dirname(filename)
			Logging.info("LsmDataSource created with file %s and channelNum=%d"%\
			(self.filename, channelNum), kw = "lsmreader")
			try:
				f = open(self.convertFileName(filename))
				f.close()
			except IOError, ex:
				Logging.error("Failed to open LSM file",
				"Failed to open file %s for reading: %s" % (filename, str(ex)))
				return
				
			self.reader.SetFileName(self.convertFileName(self.filename))
			self.reader.SetUpdateChannel(channelNum)
			self.reader.UpdateInformation()
			self.originalScalarRange = None
			self.getBitDepth()
			self.originalDimensions = self.reader.GetDimensions()[0:3]
			self.readTimeStamps()
Exemplo n.º 14
0
    def __init__(self, filename="", imageNum=-1, channelNum=-1, reader=None):
        """
		Constructor of LIF DataSource
		"""
        DataSource.__init__(self)
        self.filename = filename
        self.imageName = ""
        self.setPath(filename)
        # LIF file can contain multiple images with multiple channels.
        # Define which image and channel is associated to this DataSource
        self.imageNum = imageNum
        self.channelNum = channelNum
        self.bitDepth = 0

        self.spacing = None
        self.voxelSize = None
        self.ctf = None

        # Use vtkLIFReader
        self.reader = vtkbxd.vtkLIFReader()
        self.reader.AddObserver('ProgressEvent', lib.messenger.send)
        lib.messenger.connect(self.reader, 'ProgressEvent',
                              self.updateProgress)

        # Open file if defined
        if self.filename:
            self.reader.SetFileName(self.convertFileName(self.filename))
            if self.reader.OpenFile():
                if reader:
                    self.reader.CopyHeaderInfo(reader)
                if self.reader.ReadLIFHeader():
                    self.reader.SetCurrentImage(self.imageNum)
                    self.reader.SetCurrentChannel(self.channelNum)
                    self.imageName = self.reader.GetImageName(self.imageNum)
                    self.createTimeStamps()
                    self.originalDimensions = self.internalGetDimensions()[0:3]
                else:
                    Logging.error(
                        "Failed to read the header of the LIF file correctly",
                        "Error in LIFDataSource.py in __init__, failed to read the header of the LIF file: %s"
                        % (self.filename))
                    return
            else:
                Logging.error(
                    "Failed to open file",
                    "Error in LIFDataSource.py in __init__, failed to open file: %s"
                    % (self.filename))
                return
Exemplo n.º 15
0
    def __init__(self, filenames=[], callback=None):
        """
		Constructor
		"""
        DataSource.__init__(self)
        self.name = "Import"
        self.extMapping = {"tif": "TIFF", "tiff": "TIFF", "png": "PNG", "jpg": "JPEG", "jpeg": "JPEG", \
             "pnm": "PNM", "vti": "XMLImageData", "vtk": "DataSet", "bmp": "BMP"}
        self.dimMapping = {
            "bmp": 2,
            "tif": 2,
            "tiff": 2,
            "png": 2,
            "jpg": 2,
            "jpeg": 2,
            "pnm": 2,
            "vti": 3,
            "vtk": 3
        }
        self.callback = callback
        self.initialize()
Exemplo n.º 16
0
	def __init__(self, filename = "", imageNum = 0, channelNum = 0):
		"""
		Constructor
		"""
		DataSource.__init__(self)
		self.filename = filename
		self.numImages = 1
		self.numChannels = 1
		self.numTimePoints = 1
		self.currentImage = imageNum
		self.currentChannel = channelNum
		self.currentTimepoint = 0
		self.imageName = ""
		self.reader = vtkbxd.vtkOMETIFFReader()
		self.reader.AddObserver('ProgressEvent', lib.messenger.send)
		lib.messenger.connect(self.reader, 'ProgressEvent', self.updateProgress)

		self.ctf = None
		
		if self.filename:
			self.reader.SetFileName(self.convertFileName(self.filename))
			if not self.reader.ReadOMEHeader():
				Logging.error("Failed to open OME-TIFF file",
							"Failed to open file %s for reading: %s"%(filename, str(ex)))
				return
			
			self.numImages = self.reader.GetNumberOfImages()
			if self.currentImage < self.numImages:
				self.reader.SetCurrentImage(self.currentImage)
			self.numChannels = self.reader.GetNumberOfChannels()
			if self.currentChannel < self.numChannels:
				self.reader.SetCurrentChannel(self.currentChannel)
			self.imageName = self.reader.GetImageName()
			if self.imageName == "":
				self.imageName = "Image-%d"%(self.currentImage+1)
			self.numTimePoints = self.reader.GetNumberOfTimePoints()
			self.createTimeStamps()
	def __init__(self, filename = ""):
		"""
		Constructor
		"""
		DataSource.__init__(self)
		self.sourceUnits = []  
Exemplo n.º 18
0
    def __init__(self, filename=""):
        """
		Constructor
		"""
        DataSource.__init__(self)
        self.sourceUnits = []
	def __init__(self, filename = ""):
		DataSource.__init__(self)
Exemplo n.º 20
0
 def __init__(self, filename=""):
     DataSource.__init__(self)