Esempio n. 1
0
def getSettingsFromCache(key):
    """
	Return the settings stored under a given key in the cache
	"""
    global settingsCache
    data = settingsCache.get(tuple(key), None)
    value = None
    parser = None
    if data:
        value = []
        for (n, configParser) in data:
            if not configParser.sections():
                continue
            print "n=", n, "configParser=", configParser
            print configParser.sections()
            settings = DataUnitSettings(n)
            settings.set("Type", None)
            settings = settings.readFrom(configParser)
            value.append(settings)
            parser = configParser
    return value, parser
Esempio n. 2
0
	def loadFromFile(self, filename):
		"""
		Loads the specified .bxc-file and imports data from it.
					 Also returns a DataUnit of the type stored in the loaded
					 .bxc-file or None if something goes wrong. The dataunit is
					 returned in a list with one item for interoperability with
					 LSM data source
		"""
		if not self.baseFilename:
			self.baseFilename = filename
		self.shortname = os.path.basename(filename)
		dataUnitFormat = self.loadBxdFile(filename)
		Logging.info("format of unit = ", dataUnitFormat, kw = "datasource")

		if (not dataUnitFormat) or (not self.parser):
			Logging.info("No dataUnitFormat or parser: %s and %s"%(dataUnitFormat, self.parser), kw = "datasource")
			return None

		# Then, the number of datasets/timepoints that belong to this dataset
		# series
		try:
			count = self.parser.get("ImageData", "numberOfFiles")
		except ConfigParser.NoOptionError:
			count = self.parser.get("ImageData", "numberoffiles")
		Logging.info("format = ", dataUnitFormat, "count = ", count, kw = "datasource")

		# Then read the .vti-filenames and store them in the dataSets-list:
		filedir = os.path.dirname(filename)
		
		hasPolydata = self.parser.has_section("PolyData")
		for i in range(int(count)):
			currentFile = "file_%d"%i
			filename = self.parser.get("ImageData", currentFile)
			
			if hasPolydata:
				print "GOT polydata"
				polyFileName = self.parser.get("PolyData", currentFile)
				self.polyDataFiles.append(polyFileName)
				
			reader = vtk.vtkXMLImageDataReader()
			filepath = os.path.join(filedir, filename)
			if not reader.CanReadFile(filepath):
				Logging.error("Cannot read file",
				"Cannot read source XML Image Data File %s"%filename)
				return

			self.dataSets.append(filename)

		# If everything went well, we create a new DataUnit-instance of the
		# correct subclass, so that the DataUnit-instance can take over and
		# resume data processing. First, we return the DataUnit to the caller,
		# so it can set a reference to it:
		dataunit = DataUnit()
		settings = DataUnitSettings()
		settings.setType("")
		settings = settings.readFrom(self.parser)
		self.originalDimensions = eval(settings.get("Dimensions"))
		self.settings = settings
		dataunit.setDataSource(self)
		dataunit.setSettings(settings)
		data = dataunit.getTimepoint(0)
		dataunits = [dataunit]
	   
		if data.GetNumberOfScalarComponents() == 3:
			for i in range(0, 3) :
				dataSource = RGBComponentDataSource(self, i)
				dataunit = DataUnit()
				dataunit.setDataSource(dataSource)
				settings = DataUnitSettings()
				settings = settings.readFrom(self.parser)
				dataunit.setSettings(settings)
				dataunits.append(dataunit)

		return dataunits