From: <zk...@us...> - 2009-06-24 14:53:25
|
Revision: 648 http://pyphant.svn.sourceforge.net/pyphant/?rev=648&view=rev Author: zklaus Date: 2009-06-24 13:56:20 +0000 (Wed, 24 Jun 2009) Log Message: ----------- Merge branch 'master' into svn-trunk * master: Fix: Started repairing the histogram worker. Cosm: Code improvements in the spirit of PEP8. Cosm: Code improvements in the spirit of PEP8. Modified Paths: -------------- trunk/src/pyphant/pyphant/core/KnowledgeManager.py trunk/src/workers/Statistics/Statistics/Histogram.py trunk/src/workers/Statistics/Statistics/tests/TestHistogram.py Modified: trunk/src/pyphant/pyphant/core/KnowledgeManager.py =================================================================== --- trunk/src/pyphant/pyphant/core/KnowledgeManager.py 2009-06-24 12:43:25 UTC (rev 647) +++ trunk/src/pyphant/pyphant/core/KnowledgeManager.py 2009-06-24 13:56:20 UTC (rev 648) @@ -212,8 +212,8 @@ registerContents -- whether to register contents of the file as well. """ if self.H5FileHandlers.has_key(filename): - raise KnowledgeManagerException("'%s' has already been registered."\ - % (filename, )) + raise KnowledgeManagerException("'%s' has already been registered." + % filename) self.H5FileHandlers[filename] = H5FileHandler(filename, mode) if registerContents: self.refreshH5(filename) @@ -312,8 +312,8 @@ """ logger = self._logger if self.isServerRunning(): - logger.warn("Server is running at host %s, port %d already. \ -Stopping server...", self._http_host, self._http_port) + logger.warn("Server is running at host %s, port %d already. " + "Stopping server...", self._http_host, self._http_port) self.stopServer() self._http_host = host self._http_port = port @@ -324,8 +324,8 @@ self._server.start() self._http_server_thread = _HTTPServerThread() self._http_server_thread.start() - self._logger.debug("Started HTTP server. Host: %s, port: %d, \ -temp dir: %s", host, port, self._http_dir) + self._logger.debug("Started HTTP server. Host: %s, port: %d, " + "temp dir: %s", host, port, self._http_dir) self.web_interface.disabled = not provide_web_frontend def stopServer(self): @@ -340,8 +340,8 @@ try: urllib.urlopen(self._getServerURL()) except: - logger.warn("Fake HTTP request failed when stopping HTTP \ -server.") + logger.warn("Fake HTTP request failed when stopping HTTP " + "server.") logger.info("Waiting for HTTP server thread to die...") self._http_server_thread.join(WAITING_SECONDS_HTTP_SERVER_STOP) if self._http_server_thread.isAlive(): @@ -360,8 +360,8 @@ self._http_dir) self._http_dir = None else: - self._logger.warn("HTTP server should be stopped but isn't \ -running.") + self._logger.warn("HTTP server should be stopped but isn't " + "running.") def isServerRunning(self): """ @@ -405,8 +405,8 @@ logger.debug("KM ID read from HTTP answer: %s", km_id) except Exception, excep: raise KnowledgeManagerException( - "Couldn't get ID for knowledge manager under URL %s."\ - % (km_url, ), excep) + "Couldn't get ID for knowledge manager under URL %s." + % (km_url, ), excep) self._remoteKMs[km_id] = km_url def registerURL(self, url): @@ -419,8 +419,8 @@ url -- URL of the HDF5 or FMF file """ parsed = urlparse(url) - filename = KM_PATH + 'registered/' + parsed[1] + '/'\ - + os.path.basename(parsed[2]) + filename = KM_PATH + 'registered/' + parsed[1] + '/' + filename += os.path.basename(parsed[2]) directory = os.path.dirname(filename) filename = getPyphantPath(directory) + os.path.basename(filename) if os.path.exists(filename): @@ -492,10 +492,9 @@ logger = self._logger # add this KM to query query_dict['lastkmidindex'] += 1 - query_dict['kmid%d' % (query_dict['lastkmidindex'], )] =\ - self.getServerId() + query_dict['kmid%d' % query_dict['lastkmidindex']] = self.getServerId() # ask every remote KnowledgeManager for id - logger.debug("Requesting knowledge managers for DC id '%s'..."\ + logger.debug("Requesting knowledge managers for DC id '%s'..." % (query_dict['dcid'], )) dc_url = None for km_id, km_url in self._remoteKMs.iteritems(): @@ -610,8 +609,11 @@ try: dc = dcinfo['filehandler'].loadDataContainer(dc_id) except Exception, excep: - raise KnowledgeManagerException("DC ID '%s' known, but \ -cannot be read from file '%s'." % (dc_id, localfilename), excep) + raise KnowledgeManagerException("DC ID '%s' known, but " + "cannot be read from file " + "'%s'." % (dc_id, + localfilename), + excep) if use_cache and dcinfo['hitcount'] >= CACHE_THRESHHOLD: docache = False if len(self._cache) >= CACHE_SIZE: @@ -636,8 +638,8 @@ dc_url = self._getDCURLFromRemoteKMs({'dcid':dc_id, 'lastkmidindex':-1}) if dc_url == None: - raise KnowledgeManagerException("DC ID '%s' is unknown."\ - %(dc_id,)) + raise KnowledgeManagerException("DC ID '%s' is unknown." + % (dc_id,)) filename = getFilenameFromDcId(dc_id) urllib.urlretrieve(dc_url, filename) self.registerH5(filename) Modified: trunk/src/workers/Statistics/Statistics/Histogram.py =================================================================== --- trunk/src/workers/Statistics/Statistics/Histogram.py 2009-06-24 12:43:25 UTC (rev 647) +++ trunk/src/workers/Statistics/Statistics/Histogram.py 2009-06-24 13:56:20 UTC (rev 648) @@ -56,15 +56,23 @@ @Worker.plug(Connectors.TYPE_IMAGE) def calculateHistogram(self, vector, subscriber=0): - bins=self.paramBins.value - histo= numpy.histogram(vector.data, bins, range=(numpy.floor(vector.data.min()), - numpy.ceil(vector.data.max()))) - binCenters = histo[1][:-1]+((histo[1][1:]-histo[1][:-1])/2.0) + bins = self.paramBins.value + try: + histo = numpy.histogram(vector.data.flat, bins, new=True, + range=(numpy.floor(vector.data.min()), + numpy.ceil(vector.data.max()))) + binCenters = histo[1][:-1]+(numpy.diff(histo[1])/2.0) + except TypeError: + histo = numpy.histogram(vector.data.flat, bins, + range=(numpy.floor(vector.data.min()), + numpy.ceil(vector.data.max()))) + binCenters = histo[1]+((histo[1][1]-histo[1][0])/2.0) xdim = DataContainer.FieldContainer(binCenters, vector.unit, longname=vector.longname, shortname=vector.shortname) result = DataContainer.FieldContainer(histo[0], dimensions=[xdim], - longname=u"Histogram of %s"%vector.longname, + longname=u"Histogram of %s" + % vector.longname, shortname=u"h") result.seal() return result Modified: trunk/src/workers/Statistics/Statistics/tests/TestHistogram.py =================================================================== --- trunk/src/workers/Statistics/Statistics/tests/TestHistogram.py 2009-06-24 12:43:25 UTC (rev 647) +++ trunk/src/workers/Statistics/Statistics/tests/TestHistogram.py 2009-06-24 13:56:20 UTC (rev 648) @@ -63,14 +63,16 @@ self.dim = dim self.worker = S.Histogram(None) self.accuracyLevel = -3 - self.uniform = DataContainer.FieldContainer( uniformSample, - unit = '1 V', - longname='Uniform noise', - shortname='g') - self.norm = DataContainer.FieldContainer( normalSample, - unit = '1 V', - longname='Gaussian white noise', - shortname='w') + self.uniform = DataContainer.FieldContainer( + uniformSample, + unit = '1 V', + longname='Uniform noise', + shortname='g' ) + self.norm = DataContainer.FieldContainer( + normalSample, + unit = '1 V', + longname='Gaussian white noise', + shortname='w' ) self.uniform.seal() def testUniform(self): @@ -85,7 +87,9 @@ result.data, decimal=self.accuracyLevel) self.failUnless(result.dimensions[0].unit == self.uniform.unit, - "Unit of result's dimension [%s] has to match the unit of the input data [%s]." % (result.dimensions[0].unit, self.uniform.unit)) + "Unit of result's dimension [%s] has to match " + "the unit of the input data [%s]." + % (result.dimensions[0].unit, self.uniform.unit)) def testNormal(self): """Tests the correct evaluation of a Gaussian white noise sample.""" @@ -107,7 +111,9 @@ result.data, decimal=self.accuracyLevel) self.failUnless(result.dimensions[0].unit == self.norm.unit, - "Unit of result's dimension [%s] has to match the unit of the input data [%s]." % (result.dimensions[0].unit, self.norm.unit)) + "Unit of result's dimension [%s] has to match " + "the unit of the input data [%s]." + % (result.dimensions[0].unit, self.norm.unit)) if __name__ == '__main__': unittest.main() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |