[hdf-compass] 44/295: Fixing root node issues, issues with class Dataset __canhandle__ and __len__ methods.

Ghislain Vaillant ghisvail-guest at moszumanska.debian.org
Sun May 8 10:35:24 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 34d866527666c17cabd0069dbc96d573ab08c7c8
Author: Matt Comerford <matthew.comerford at colorado.edu>
Date:   Tue Aug 26 17:05:54 2014 -0600

    Fixing root node issues, issues with class Dataset __canhandle__ and __len__ methods.
---
 opendap_model/__init__.py | 29 +++++++++++++++--------------
 1 file changed, 15 insertions(+), 14 deletions(-)

diff --git a/opendap_model/__init__.py b/opendap_model/__init__.py
index 24bb196..d93cdc5 100644
--- a/opendap_model/__init__.py
+++ b/opendap_model/__init__.py
@@ -1,7 +1,3 @@
-"""
-HDF Compass plugin for accessing an OpENDAP server.
-"""
-
 import numpy as np
 import posixpath as pp
 import pydap as dap
@@ -12,7 +8,7 @@ import compass_model
 
 
 def check_key(key, dataset):
-    if not '/' in key:
+    if '/' not in key:
         return key, dataset
     new_dataset = dataset[key.split('/')[0]]
     return key.split('/')[1], new_dataset
@@ -21,7 +17,7 @@ def check_key(key, dataset):
 class Server(compass_model.Store):
 
     """
-        Represents the remote OpENDAP derver to be accessed
+        Represents the remote OpENDAP server to be accessed
     """
     def __contains__(self, key):
         if '/' not in key:
@@ -45,8 +41,8 @@ class Server(compass_model.Store):
         self._url = url
         self._valid = True
         self._dataset = open_url(self.url)
-
-        self.dataset.setdefault('')
+        self._datalength = len(self._dataset.data)
+        self._dataset.setdefault('')
 
     def close(self):
         self._valid = False
@@ -74,6 +70,10 @@ class Server(compass_model.Store):
     def dataset(self):
         return self._dataset
 
+    @property
+    def datalength(self):
+        return self._datalength
+
 
 class Dataset(compass_model.Container):
 
@@ -84,11 +84,10 @@ class Dataset(compass_model.Container):
     classkind = "Dataset"
 
     def __len__(self):
-        return len(self._dset.data)
+        return self._store.datalength
 
     def __getitem__(self, index):
         name = self._dset.keys()[index]
-
         return self.store[pp.join(self.key, name)]
 
     def __iter__(self):
@@ -96,13 +95,15 @@ class Dataset(compass_model.Container):
 
     @staticmethod
     def canhandle(store, key):
-        return isinstance(store.dataset, dap.model.DatasetType)
+        return key == ''
 
     def __init__(self, store, key):
+        if not key == '':
+            raise ValueError("A Dataset object may only represent the root group")
         self._store = store
         self._key = key
         self._url = store.url
-        self._dset = open_url(store.url)
+        self._dset = store.dataset
 
     @property
     def key(self):
@@ -114,7 +115,7 @@ class Dataset(compass_model.Container):
 
     @property
     def displayname(self):
-        return self.dset.name
+        return self._dset.name
 
     @property
     def description(self):
@@ -179,7 +180,7 @@ class Base(compass_model.Array):
         Represents Array/BaseType Object in OpENDAP/Pydap.
     """
 
-    classkind = "NumPy Array"
+    classkind = "Array"
 
     @property
     def shape(self):

-- 
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