[hdf-compass] 08/295: added attributes to .asc files and fixed container class to only display directories and .asc files
Ghislain Vaillant
ghisvail-guest at moszumanska.debian.org
Sun May 8 10:35:19 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 a1508553f3c4686b1b7a2921dd28f01be9f5756b
Author: Matt Comerford <matthew.comerford at colorado.edu>
Date: Fri Jun 20 16:52:38 2014 -0600
added attributes to .asc files and fixed container class to only display directories and .asc files
---
asc_model/__init__.py | 51 ++++++++++++++++++++++++++++++++++++++++++++++++---
1 file changed, 48 insertions(+), 3 deletions(-)
diff --git a/asc_model/__init__.py b/asc_model/__init__.py
index fdfd20f..63e812e 100644
--- a/asc_model/__init__.py
+++ b/asc_model/__init__.py
@@ -8,6 +8,7 @@ directories and the ASCII grid data respectively.
import os
import os.path as op
import numpy as np
+import linecache
import compass_model
@@ -71,11 +72,13 @@ class Directory(compass_model.Container):
def canhandle(store, key):
return op.isdir(key)
+ #LIST COMPREHENSION for self._names
def __init__(self, store, key):
self._store = store
self._key = key
try:
- self._names = os.listdir(key)
+ #self._names = os.listdir(key)
+ self._names = [s for s in os.listdir(key) if s.endswith('.asc') or op.isdir(op.join(key, s))]
except OSError:
self._names = []
@@ -126,7 +129,7 @@ class ASCFile(compass_model.Array):
def __init__(self, store, key):
self._store = store
self._key = key
- self.data = np.loadtxt(self._key, skiprows=5).transpose()
+ self.data = np.loadtxt(self._key, skiprows=5, unpack=True)
@property
def key(self):
@@ -156,7 +159,49 @@ class ASCFile(compass_model.Array):
return self.data[args]
-Filesystem.push(ASCFile)
+class Attributes(compass_model.KeyValue):
+
+ classkind = "Attributes of ASC Grid File"
+
+ @staticmethod
+ def canhandle(store, key):
+ return op.isfile(key) and key.endswith('.asc')
+
+ def __init__(self, store, key):
+ self._store = store
+ self._key = key
+ self.data = {'NODATA Value': float(linecache.getline(self._key, 5).lstrip("NODATA_value")),
+ 'yllcorner': float(linecache.getline(self._key, 4).lstrip("yllcorner")),
+ 'xllcorner': float(linecache.getline(self._key, 3).lstrip("xllcorner"))}
+
+#'a': np.array((1,2)), 'b': np.array("Hello"), 'c': np.array('\x01', dtype='|V1')
+
+ @property
+ def key(self):
+ return self._key
+
+ @property
+ def store(self):
+ self._store
+
+ @property
+ def displayname(self):
+ return self.key
+
+ @property
+ def description(self):
+ return self.displayname
+
+ @property
+ def keys(self):
+ return self.data.keys()
+
+ def __getitem__(self, args):
+ return self.data[args]
+
+
+Filesystem.push(Attributes)
Filesystem.push(Directory)
+Filesystem.push(ASCFile)
compass_model.push(Filesystem)
\ No newline at end of file
--
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