[hdf-compass] 33/295: prototype for OpENDAP server plugin

Ghislain Vaillant ghisvail-guest at moszumanska.debian.org
Sun May 8 10:35:22 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 c65a8740d7d71191c907fd88f621a7b7f7be2307
Author: Matt Comerford <matthew.comerford at colorado.edu>
Date:   Tue Aug 5 10:46:11 2014 -0600

    prototype for OpENDAP server plugin
---
 opendap_model/Outline.py          | 246 +++++++++++++++++++++++++++++++
 opendap_model/__init__.py         | 299 ++++++++++++++++++++++++++++++++++++++
 opendap_model/datasetFunction.txt |  34 +++++
 opendap_model/server_test.py      |   7 +
 opendap_model/testscript.py       |  28 ++++
 5 files changed, 614 insertions(+)

diff --git a/opendap_model/Outline.py b/opendap_model/Outline.py
new file mode 100644
index 0000000..d341df2
--- /dev/null
+++ b/opendap_model/Outline.py
@@ -0,0 +1,246 @@
+"""
+HDF Compass plugin for accessing an OpENDAP server. 
+"""
+import numpy as np
+import pydap as dap
+
+import compass_model
+
+class Server(compass_model.Store):
+
+	"""
+		Represents the remote OpENDAP derver to be accessed
+	"""
+
+	# Methods related to the plugin system
+	def __getitem__(self, key):
+        # Open an object in the store, using the last registered class which reports it can open the key.
+		pass
+
+	def gethandlers(self, key=None):
+        # Retrieve all registered Node subclasses, optionally filtering by those which report they can handle "key"
+		pass
+
+	def __contains__(self, key):
+        # True if "key" exists in the store. False otherwise.
+		pass
+
+	# Other methods & properties
+	@staticmethod
+	def canhandle(url):
+        # Return True if this class can make sense of "url". False otherwise.
+		pass
+
+	def __init__(self, url):
+        #Create a new store instance from the data at "url". False otherwise.
+		pass
+
+	def close(self):
+        # Discontinue access to the data store
+        self._valid = False
+		#pass
+
+	def getparent(self, key):
+        # Return the object which contains "key", or None if no object exists
+		pass
+
+	@property
+	def url(self):
+        # The "URL" used to open the store
+        return self._url
+		#pass
+
+	@property
+	def displayname(self):
+        # A short name used for the store
+		pass
+
+	@property
+	def root(self):
+        # A node instance representing the starting point in the file
+        # For hierarchiacal formats, this would be the root container.
+		pass
+
+	@property
+	def valid(self):
+        return self._valid
+		#pass
+
+class Structure(compass_model.Container):
+
+	"""
+		Represents Structure/StructureType Object in OpENDAP/Pydap
+	"""
+
+	# Unique to the Container class
+	@property
+	def __len__(self):
+        # Get the number of ojects directly attached to the Container
+		pass
+
+	def __getitem__(self, index):
+        # Retrieve the node at index.
+        # Returns a NODE INSTANCE, not a key
+		pass
+
+    def __iter__(self):
+        pass
+
+	# General Node class implementations
+
+	classkind = "Structure"
+
+	@staticmethod
+	def canhandle(store, key):
+        # Determine whether this class can usefully represent the object.
+        # Keys are not technically required to be strings
+		pass
+
+	def __init__(self, store, key):
+        # Create a new instance representing the object pointed to by "key" in "store"
+		pass
+
+	@property
+	def key(self):
+        # Unique key which identifies this object in the store
+        # Keys may be any hashable object, although strings are the most common
+		pass
+
+	@property
+	def store(self):
+        # The data store to which the object belongs
+		pass
+
+	@property
+	def displayname(self):
+        # A short name for display purposes 
+		pass
+
+	@property
+	def description(self):
+        # Descriptive string
+		pass
+
+class Array(compass_model.Array):
+
+	"""
+		Represents Array/BaseType Object in OpENDAP/Pydap
+	"""
+
+	# Implementations unique to Array class
+
+	@property
+	def shape(self):
+        # Shape of the array, as a Python tuple
+        return self.shape
+		#pass
+
+	@property
+	def dtype(self):
+        # NumPy data type object representing the type of the array
+		return self.type
+        #pass
+
+	def __getitem__(self, indices):
+        # Retrieve data from the array, using the standard array-slicing syntax.
+        # "indices" are slicing arguments
+		pass
+
+    # General Node class implementations
+
+    classkind = "Array"
+
+    @staticmethod
+    def canhandle(store, key):
+        # Determine whether this class can usefully represent the object
+        # Keys are not technically required to be strings.
+        pass
+
+    def __init__(self, store, key):
+        # Create a new instance representing the object pointed to by "key" in "store"
+        pass
+
+    @property
+    def key(self):
+        # Unique key which identifies this object in the store.
+        # Keys may be any hashable object
+        self._key
+        #pass
+
+    @property
+    def store(self):
+        # The data store to which the object belongs
+        return self._store
+        #pass
+
+    @property
+    def displayname(self):
+        #  A short name for display purposes
+        return self.name
+        #pass
+
+    @property
+    def description(self):
+        # A descriptive string
+        return self.id
+        #pass
+
+class Grid(compass_model.Array):
+
+    """
+        Represents Grid/GridType Object in OpENDAP/Pydap
+    """
+
+    # Implementations unique to Array class
+
+    @property
+    def shape(self):
+        # Shape of the array, as a Python tuple
+        return self.shape
+        #pass
+
+    @property
+    def dtype(self):
+        # NumPy data type object representing the type of the array
+        return self.type
+        #pass
+
+    def __getitem__(self, indices):
+        # Retrieve data from the array, using the standard array-slicing syntax
+        # "Indices" are slicing arguments
+        pass
+
+    # General Node class implementations
+
+    classkind = "Grid"
+
+    @staticmethod
+    def canhandle(store, key):
+        # Determine whether this class can usefully represent the object
+        pass
+
+    def __init__(self, store, key):
+        # Create a new instance representing the object pointed to by "key" in "store"
+        pass
+
+    @property
+    def key(self):
+        # Unique key which identifies this object in the store
+        # Keys may be any hashable object, although strings are the most common
+        pass
+
+    @property
+    def store(self):
+        # The data store to which the object belongs
+        pass
+
+    @property
+    def displayname(self):
+        # A short name for display purposes
+        pass
+
+    @property
+    def description(self):
+        # Descriptive string
+        pass
+
diff --git a/opendap_model/__init__.py b/opendap_model/__init__.py
new file mode 100644
index 0000000..85c8b7a
--- /dev/null
+++ b/opendap_model/__init__.py
@@ -0,0 +1,299 @@
+"""
+HDF Compass plugin for accessing an OpENDAP server. 
+"""
+import numpy as np
+from pydap.client import open_url
+import pydap as dap
+from pydap.model import *
+
+import compass_model
+
+class Server(compass_model.Store):
+
+    """
+        Represents the remote OpENDAP derver to be accessed
+    """
+    # For practice I will implement using the OpENDAP Test Server, found at:
+    # http://test.opendap.org/dap/data/nc/coads_climatology.nc
+
+    # Methods related to the plugin system
+    '''
+    def __getitem__(self, key):
+        # Open an object in the store, using the last registered class which reports it can open the key.
+        print 1
+        #return open_url(self._url)
+        #return self._dset
+        pass
+    '''
+    '''
+    def gethandlers(self, key=None):
+        # Retrieve all registered Node subclasses, optionally filtering by those which report they can handle "key"
+        print 2
+        pass
+    '''
+
+    def __contains__(self, key):
+        # True if "key" exists in the store. False otherwise.
+        print 3
+        #return key in self._dset.keys()
+        if key == '/':
+            return True
+        return False
+        #pass
+
+    # Other methods & properties
+    @staticmethod
+    def canhandle(url):
+        print 'canhandle'
+        if not url.startswith('http://'):
+            return False
+        #if not url.endswith('.nc'):
+        #    return False
+        return True
+        # Return True if this class can make sense of "url". False otherwise.
+        #pass
+
+    def __init__(self, url):
+        #Create a new store instance from the data at "url". False otherwise.
+        print 4
+        if not self.canhandle(url):
+            raise ValueError(url)
+        self._url = url
+        self._valid = True
+        self._dataset = open_url(self._url)
+
+    def close(self):
+        # Discontinue access to the data store
+        self._valid = False
+        print 5
+        #pass
+
+    def getparent(self, key):
+        # Return the object which contains "key", or None if no object exists
+        print 6
+        return None
+        #pass
+
+    @property
+    def url(self):
+        # The "URL" used to open the store
+        print 7
+        return self._url
+        #pass
+
+    @property
+    def displayname(self):
+        # A short name used for the store
+        print 8
+        return "OpENDAP Test Dataset"
+        #pass
+
+    @property
+    def root(self):
+        # A node instance representing the starting point in the file
+        # For hierarchiacal formats, this would be the root container.
+        print 9
+        return self['/']
+        #pass
+
+    @property
+    def valid(self):
+        print 10
+        return self._valid
+        #pass
+
+
+class Structure(compass_model.Container):
+
+    """
+        Represents Structure/StructureType Object in OpENDAP/Pydap
+    """
+
+    classkind = "Structure"
+
+    # Unique to the Container class
+    
+    def __len__(self):
+        # Get the number of ojects directly attached to the Container
+        print 11
+        #print "the length is ", len(self._dset.data)
+        return len(self._dset.data)
+        #pass
+    
+
+    def __getitem__(self, index):
+        # Retrieve the node at index.
+        # Returns a NODE INSTANCE, not a key
+        item = self._dset.get(self._dset.keys()[index])
+        print 12
+        return item
+        #return self._dset.get(self._dset.keys()[index])
+        #return open_url(self._url)
+        #pass
+
+    def __iter__(self):
+        print 13
+        for name in self._names:
+            yield self.store[pp.join(self.key, name)]
+        #pass
+
+    # General Node class implementations
+
+    @staticmethod
+    def canhandle(store, key):
+        # Determine whether this class can usefully represent the object.
+        # Keys are not technically required to be strings
+        print 14
+        print "key is", key, " store is ", store
+        return key in store
+        if type(store._dataset) == DatasetType or type(store._dataset) == StructureType:
+        #if type(self._dest) == DatasetType or type(self._dset) == StructureType:
+            return True
+        return False
+
+    def __init__(self, store, key):
+        # Create a new instance representing the object pointed to by "key" in "store"
+        print 15
+        self._store = store
+        self._key = key 
+        self._url = store.url
+        self._dset = open_url(self._url)
+
+        print "self._dset.name is ", self._dset.name
+        #pass
+
+    @property
+    def key(self):
+        # Unique key which identifies this object in the store
+        # Keys may be any hashable object, although strings are the most common
+        print 16
+        print "self._key is ", self._key
+        return self._key
+        #pass
+
+    @property
+    def store(self):
+        # The data store to which the object belongs
+        print 17
+        print "self._store is ", self._store
+        return self._store
+        #pass
+
+    @property
+    def displayname(self):
+        # A short name for display purposes 
+        print 18
+        return "test"
+        #return self._dset.name
+        #pass
+
+    @property
+    def description(self):
+        # Descriptive string
+        print 19
+        return "Testing Structure Implementation"
+        #pass
+
+
+class BaseType(compass_model.Array):
+
+    """
+    Represents Array/BaseType Object in OpENDAP/Pydap
+    """
+
+    classkind = "Base"
+
+    # Imports only used within this class
+    from pydap.proxy import ArrayProxy
+
+    # Implementations unique to Array class
+
+    @property
+    def shape(self):
+        # Shape of the array, as a Python tuple
+        print 20
+        return self._dset.shape
+        #pass
+
+    @property
+    def dtype(self):
+        # NumPy data type object representing the type of the array
+        print 21
+        return self._dset.dtype
+        #pass
+
+    def __getitem__(self, indices):
+        # Retrieve data from the array, using the standard array-slicing syntax.
+        # "indices" are slicing arguments
+        print 22
+        return self._dset[indices]
+        #pass
+
+    # General Node class implementations
+
+    @staticmethod
+    def canhandle(store, key):
+        # Determine whether this class can usefully represent the object
+        # Keys are not technically required to be strings.
+
+        # If the type of the key stored in store is not 'pydap.model.BaseType' then false
+        #return key in store and type(key)
+        print 23
+        if type(store._dataset) == BaseType:
+            return True
+        return False
+        #pass
+
+    def __init__(self, store, key):
+        # Create a new instance representing the object pointed to by "key" in "store"
+        print 24
+        self._store = store
+        self._key = key
+        self._id = self.id
+        self._url = store.url
+        self._shape = self.shape
+        self._dset = ArrayProxy(self._id, self._url, self._shape)#[:]
+        #pass
+
+    @property
+    def key(self):
+        # Unique key which identifies this object in the store.
+        # Keys may be any hashable object
+        print 25
+        return self._key
+        #pass
+
+    @property
+    def store(self):
+        # The data store to which the object belongs
+        print 26
+        return self._store
+        #pass
+
+    @property
+    def displayname(self):
+        #  A short name for display purposes
+        print 27
+        return "test"
+        #return self._dset.name
+        #pass
+
+    @property
+    def description(self):
+        # A descriptive string
+        print 28
+        return "A Descriptive String"
+        #pass
+
+    @property
+    def id(self):
+        print 29
+        return self._id
+        #pass
+
+
+# Register Handlers
+Server.push(Structure)
+Server.push(BaseType)
+
+compass_model.push(Server)
\ No newline at end of file
diff --git a/opendap_model/datasetFunction.txt b/opendap_model/datasetFunction.txt
new file mode 100644
index 0000000..3939cb4
--- /dev/null
+++ b/opendap_model/datasetFunction.txt
@@ -0,0 +1,34 @@
+PyDap Dataset Methods
+
+dataset.
+
+*attributes
+
+clear()
+copy()
+data
+fromkeys(keys, d=None)
+
+*functions
+
+get(key, d=None)
+has_key(key)
+
+*id
+
+items()
+iteritems()
+iterkeys()
+itervalues()
+
+keys()
+name
+pop(key, d=None)
+popitem()
+setdefault(key, d=None)
+update(odict)
+values()
+viewitems() -> a set-like object providing a view on the dataset's items
+viewkeys() -> a set-like object providing a view on the dataset's keys
+viewvalues -> an object providing view on the dataset's values
+walk()
\ No newline at end of file
diff --git a/opendap_model/server_test.py b/opendap_model/server_test.py
new file mode 100644
index 0000000..4fa9699
--- /dev/null
+++ b/opendap_model/server_test.py
@@ -0,0 +1,7 @@
+from pydap.client import open_url
+from pydap.model import *
+from pydap.proxy import ArrayProxy
+
+dataset = open_url('http://test.opendap.org/dap/data/nc/coads_climatology.nc')
+
+print dataset.values()
diff --git a/opendap_model/testscript.py b/opendap_model/testscript.py
new file mode 100644
index 0000000..39ddde4
--- /dev/null
+++ b/opendap_model/testscript.py
@@ -0,0 +1,28 @@
+from pydap.model import *
+from pydap.client import open_url
+from pydap.proxy import ArrayProxy
+# url - http://test.opendap.org/dap/data/nc/coads_climatology.nc
+
+
+
+a = BaseType(name='a', data=1, shape=(), dimensions=(), type=Int32, attributes={'long_name':'variable a'})
+a.history = 'Created by me'
+a.attributes['history'] = 'Created by me'
+
+b = a 
+
+c = BaseType(name='long & complicated')
+
+s = StructureType(name='s')
+s['a'] = a
+s[c.name] = c
+
+dataset = DatasetType(name='example')
+dataset['s'] = s
+
+print 'a, b, c, s, dataset are variables'
+
+if type(dataset) == DatasetType:
+	print "heck yea"
+	
+test_dataset = open_url('http://test.opendap.org/dap/data/nc/coads_climatology.nc')
\ 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