[hdf-compass] 16/295: fixed loading issue. Now loads file contents only once when called with very little wait for larger files.

Ghislain Vaillant ghisvail-guest at moszumanska.debian.org
Sun May 8 10:35:20 UTC 2016


This is an automated email from the git hooks/post-receive script.

ghisvail-guest pushed a commit to branch debian/master
in repository hdf-compass.

commit f2efa806ae5dc31f60008788889a792cdcf96538
Author: Matt Comerford <matthew.comerford at colorado.edu>
Date:   Mon Jul 7 23:28:45 2014 -0600

    fixed loading issue. Now loads file contents only once when called with very little wait for larger files.
---
 asc_model/__init__.py | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/asc_model/__init__.py b/asc_model/__init__.py
index 8e076ac..bf6404e 100644
--- a/asc_model/__init__.py
+++ b/asc_model/__init__.py
@@ -127,10 +127,7 @@ class ASCFile(compass_model.Array):
 	def __init__(self, store, key):
 		self._store = store
 		self._key = key
-		# Need to load nrows and ncols
-		nrows = int(linecache.getline(self._key, 1).lstrip("ncols"))
-		ncols = int(linecache.getline(self._key, 2).lstrip("nrows"))
-		self.data = np.zeros((nrows, ncols), dtype=float)
+		self._data = np.arange(0, dtype=float)
 
 	@property
 	def key(self):
@@ -142,7 +139,7 @@ class ASCFile(compass_model.Array):
 
 	@property
 	def displayname(self):
-		return op.basename(self.key)
+		return op.basename(self._key)
 
 	@property
 	def description(self):
@@ -150,15 +147,18 @@ class ASCFile(compass_model.Array):
 
 	@property
 	def shape(self):
-		return self.data.shape
+		nrows = int(linecache.getline(self._key, 1).lstrip("ncols"))
+		ncols = int(linecache.getline(self._key, 2).lstrip("nrows"))
+		return (nrows, ncols)
 
 	@property
 	def dtype(self):
-		return self.data.dtype
+		return self._data.dtype
 
 	def __getitem__(self, args):
-		self.data = np.loadtxt(self._key, skiprows=6, unpack=True)
-		return self.data[args]
+		if self._data.size is 0:
+			self._data = np.loadtxt(self._key, skiprows=6, unpack=True, dtype=float)
+		return self._data[args]
 
 
 class Attributes(compass_model.KeyValue):

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/hdf-compass.git



More information about the debian-science-commits mailing list