[hdf-compass] 104/295: Creation of hdf_compass namespace
Ghislain Vaillant
ghisvail-guest at moszumanska.debian.org
Sun May 8 10:35:31 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 70bf2a6e2d98dc761de46ac0d8798d25544320bf
Author: giumas <giumas at yahoo.it>
Date: Fri Oct 2 20:17:53 2015 -0400
Creation of hdf_compass namespace
---
HDFCompass.py | 4 +-
HDFCompass.spec | 2 +-
filesystem_model/test.py | 8 --
hdf5_model/test.py | 8 --
hdf_compass/__init__.py | 9 +++
.../array_model}/__init__.py | 35 ++++----
{asc_model => hdf_compass/asc_model}/__init__.py | 26 +++---
.../compass_model}/__init__.py | 77 +++++-------------
.../compass_model}/icons/array_16.png | Bin
.../compass_model}/icons/array_64.png | Bin
.../compass_model}/icons/folder_16.png | Bin
.../compass_model}/icons/folder_64.png | Bin
.../compass_model}/icons/image_16.png | Bin
.../compass_model}/icons/image_64.png | Bin
.../compass_model}/icons/kv_16.png | Bin
.../compass_model}/icons/kv_64.png | Bin
.../compass_model}/icons/license.txt | 0
.../compass_model}/icons/readme.txt | 0
.../compass_model}/icons/unknown_16.png | Bin
.../compass_model}/icons/unknown_64.png | Bin
.../compass_model}/images.py | 0
.../compass_model}/test.py | 35 +++-----
.../compass_viewer}/__init__.py | 59 ++++++++++----
.../compass_viewer}/array/__init__.py | 88 +++++++++------------
.../compass_viewer}/array/plot.py | 19 ++---
.../compass_viewer}/container/__init__.py | 36 +++------
.../compass_viewer}/container/list.py | 30 +++----
.../compass_viewer}/events.py | 0
.../compass_viewer}/frame.py | 42 +++-------
.../compass_viewer}/icons/compass_32.png | Bin
.../compass_viewer}/icons/compass_48.png | Bin
.../compass_viewer}/icons/go_back_24.png | Bin
.../compass_viewer}/icons/go_back_32.png | Bin
.../compass_viewer}/icons/go_next_24.png | Bin
.../compass_viewer}/icons/go_next_32.png | Bin
.../compass_viewer}/icons/go_up_24.png | Bin
.../compass_viewer}/icons/go_up_32.png | Bin
.../compass_viewer}/icons/license.txt | 0
.../compass_viewer}/icons/logo.png | Bin
.../compass_viewer}/icons/logo.xcf | Bin
.../compass_viewer}/icons/readme.txt | 0
.../compass_viewer}/icons/view_icon_24.png | Bin
.../compass_viewer}/icons/view_icon_32.png | Bin
.../compass_viewer}/icons/view_list_24.png | Bin
.../compass_viewer}/icons/view_list_32.png | Bin
.../compass_viewer}/icons/view_tree_32.png | Bin
.../compass_viewer}/icons/viz_plot_24.png | Bin
.../compass_viewer}/icons/viz_plot_32.png | Bin
.../compass_viewer}/image/__init__.py | 9 ++-
.../compass_viewer}/images.py | 0
.../compass_viewer}/imagesupport.py | 8 +-
.../compass_viewer}/info.py | 14 ++--
.../compass_viewer}/keyvalue/__init__.py | 21 ++---
.../compass_viewer}/platform.py | 2 +-
{data => hdf_compass/data}/asc/sample.asc | 0
{data => hdf_compass/data}/hdf5/tall.h5 | Bin
.../filesystem_model}/__init__.py | 10 +--
hdf_compass/filesystem_model/test.py | 7 ++
{hdf5_model => hdf_compass/hdf5_model}/__init__.py | 66 ++--------------
hdf_compass/hdf5_model/test.py | 23 ++++++
.../opendap_model}/__init__.py | 10 +--
61 files changed, 260 insertions(+), 388 deletions(-)
diff --git a/HDFCompass.py b/HDFCompass.py
index 401c518..894a114 100644
--- a/HDFCompass.py
+++ b/HDFCompass.py
@@ -10,5 +10,5 @@
# request a copy from help at hdfgroup.org. #
##############################################################################
-import compass_viewer
-compass_viewer.run()
\ No newline at end of file
+from hdf_compass import compass_viewer
+compass_viewer.run()
diff --git a/HDFCompass.spec b/HDFCompass.spec
index 36c4a93..40824b0 100644
--- a/HDFCompass.spec
+++ b/HDFCompass.spec
@@ -43,4 +43,4 @@ exe = EXE(pyz,
debug=False,
strip=None,
upx=False,
- console=False , icon='compass.ico')
+ console=False, icon='compass.ico')
diff --git a/filesystem_model/test.py b/filesystem_model/test.py
deleted file mode 100644
index e4712c7..0000000
--- a/filesystem_model/test.py
+++ /dev/null
@@ -1,8 +0,0 @@
-from compass_model.test import container, store
-from . import Filesystem, Directory, File
-
-url = "file://localhost"
-
-s = store(Filesystem, url)
-c = container(Filesystem, url, Directory, "/")
-
diff --git a/hdf5_model/test.py b/hdf5_model/test.py
deleted file mode 100644
index c4e3028..0000000
--- a/hdf5_model/test.py
+++ /dev/null
@@ -1,8 +0,0 @@
-from compass_model.test import container, store
-from . import HDF5Group, HDF5Store
-
-url = "file:///Users/andrew/Documents/Compass/Demo files/2_5.hdf5"
-
-s = store(HDF5Store, url)
-c = container(HDF5Store, url, HDF5Group, "/")
-
diff --git a/hdf_compass/__init__.py b/hdf_compass/__init__.py
new file mode 100644
index 0000000..6b325b2
--- /dev/null
+++ b/hdf_compass/__init__.py
@@ -0,0 +1,9 @@
+"""
+HDFCompass Namespace
+"""
+try:
+ import pkg_resources
+ pkg_resources.declare_namespace(__name__)
+except ImportError:
+ import pkgutil
+ __path__ = pkgutil.extend_path(__path__, __name__)
diff --git a/array_model/__init__.py b/hdf_compass/array_model/__init__.py
similarity index 86%
rename from array_model/__init__.py
rename to hdf_compass/array_model/__init__.py
index 3d0de3b..2d48b18 100644
--- a/array_model/__init__.py
+++ b/hdf_compass/array_model/__init__.py
@@ -14,34 +14,30 @@
Testing model for array types.
"""
-import os
-import os.path as op
import numpy as np
-import compass_model
+from hdf_compass import compass_model
-import numpy as np
-
-DT_CMP = np.dtype([('a','i'),('b','f')])
+DT_CMP = np.dtype([('a', 'i'), ('b', 'f')])
DATA = {'a_0d': np.array(1),
'a_1d': np.arange(10),
- 'a_2d': np.arange(10*10).reshape((10,10)),
- 'a_3d': np.arange(10*10*10).reshape((10,10,10)),
- 'a_4d': np.arange(10*10*10*10).reshape((10,10,10,10)),
- 'cmp_0d': np.array((1,2), dtype=DT_CMP),
+ 'a_2d': np.arange(10 * 10).reshape((10, 10)),
+ 'a_3d': np.arange(10 * 10 * 10).reshape((10, 10, 10)),
+ 'a_4d': np.arange(10 * 10 * 10 * 10).reshape((10, 10, 10, 10)),
+ 'cmp_0d': np.array((1, 2), dtype=DT_CMP),
'cmp_1d': np.ones((10,), dtype=DT_CMP),
- 'cmp_2d': np.ones((10,10), dtype=DT_CMP),
- 'cmp_3d': np.ones((10,10,10),dtype=DT_CMP),
- 'cmp_4d': np.ones((10,10,10,10),dtype=DT_CMP),
+ 'cmp_2d': np.ones((10, 10), dtype=DT_CMP),
+ 'cmp_3d': np.ones((10, 10, 10), dtype=DT_CMP),
+ 'cmp_4d': np.ones((10, 10, 10, 10), dtype=DT_CMP),
's_0d': np.array("Hello"),
's_1d': np.array(("Hello",)),
'v_0d': np.array('\x01', dtype='|V1'),
- 'nonsquare': np.arange(5*10).reshape((5,10)),
+ 'nonsquare': np.arange(5 * 10).reshape((5, 10)),
}
-class ArrayStore(compass_model.Store):
+class ArrayStore(compass_model.Store):
"""
A "data store" represented by the file system.
@@ -66,7 +62,7 @@ class ArrayStore(compass_model.Store):
@property
def valid(self):
return True
-
+
@staticmethod
def canhandle(url):
if url == "array://localhost":
@@ -86,7 +82,6 @@ class ArrayStore(compass_model.Store):
class ArrayContainer(compass_model.Container):
-
"""
Represents a directory in the filesystem.
"""
@@ -131,7 +126,6 @@ class ArrayContainer(compass_model.Container):
class Array(compass_model.Array):
-
"""
An N-D array
"""
@@ -176,7 +170,6 @@ class Array(compass_model.Array):
class ArrayKV(compass_model.KeyValue):
-
classkind = "Array Key/Value Attrs"
@staticmethod
@@ -186,7 +179,7 @@ class ArrayKV(compass_model.KeyValue):
def __init__(self, store, key):
self._store = store
self._key = key
- self.data = {'a': np.array((1,2)), 'b': np.array("Hello"), 'c': np.array('\x01', dtype='|V1')}
+ self.data = {'a': np.array((1, 2)), 'b': np.array("Hello"), 'c': np.array('\x01', dtype='|V1')}
@property
def key(self):
@@ -216,4 +209,4 @@ ArrayStore.push(ArrayKV)
ArrayStore.push(ArrayContainer)
ArrayStore.push(Array)
-compass_model.push(ArrayStore)
\ No newline at end of file
+compass_model.push(ArrayStore)
diff --git a/asc_model/__init__.py b/hdf_compass/asc_model/__init__.py
similarity index 90%
rename from asc_model/__init__.py
rename to hdf_compass/asc_model/__init__.py
index 8262efd..eee5992 100644
--- a/asc_model/__init__.py
+++ b/hdf_compass/asc_model/__init__.py
@@ -20,14 +20,14 @@ the file format
import sys
import os.path as op
-import numpy as np
import linecache
-import compass_model
+import numpy as np
+from hdf_compass import compass_model
-class AsciiGrid(compass_model.Store):
+class AsciiGrid(compass_model.Store):
"""
A "data store" represented by an ascii grid file.
"""
@@ -82,8 +82,8 @@ class AsciiGrid(compass_model.Store):
prefixLen = len('file://')
return self._url[prefixLen:]
-class ASCFile(compass_model.Array):
+class ASCFile(compass_model.Array):
"""
Represents a .asc grid file.
"""
@@ -122,7 +122,7 @@ class ASCFile(compass_model.Array):
@property
def shape(self):
- return (self._nrows, self._ncols)
+ return self._nrows, self._ncols
@property
def dtype(self):
@@ -135,7 +135,6 @@ class ASCFile(compass_model.Array):
class Attributes(compass_model.KeyValue):
-
classkind = "Attributes of ASC Grid File"
@staticmethod
@@ -149,9 +148,9 @@ class Attributes(compass_model.KeyValue):
self._key = key
filePath = self._store.getFilePath()
self.data = {'NODATA Value': float(linecache.getline(filePath, 6).lstrip("NODATA_value")),
- 'cellsize': float(linecache.getline(filePath, 5).lstrip("cellsize")),
- 'yllcorner': float(linecache.getline(filePath, 4).lstrip("yllcorner")),
- 'xllcorner': float(linecache.getline(filePath, 3).lstrip("xllcorner"))}
+ 'cellsize': float(linecache.getline(filePath, 5).lstrip("cellsize")),
+ 'yllcorner': float(linecache.getline(filePath, 4).lstrip("yllcorner")),
+ 'xllcorner': float(linecache.getline(filePath, 3).lstrip("xllcorner"))}
@property
def key(self):
@@ -159,7 +158,7 @@ class Attributes(compass_model.KeyValue):
@property
def store(self):
- self._store
+ return self._store
@property
def displayname(self):
@@ -168,7 +167,7 @@ class Attributes(compass_model.KeyValue):
@property
def description(self):
return self.displayname
-
+
def close(self):
self._valid = False
@@ -179,7 +178,8 @@ class Attributes(compass_model.KeyValue):
def __getitem__(self, args):
return self.data[args]
-AsciiGrid.push(Attributes) # attribute data
-AsciiGrid.push(ASCFile) # array
+
+AsciiGrid.push(Attributes) # attribute data
+AsciiGrid.push(ASCFile) # array
compass_model.push(AsciiGrid)
diff --git a/compass_model/__init__.py b/hdf_compass/compass_model/__init__.py
similarity index 96%
rename from compass_model/__init__.py
rename to hdf_compass/compass_model/__init__.py
index 1c35966..f257747 100644
--- a/compass_model/__init__.py
+++ b/hdf_compass/compass_model/__init__.py
@@ -73,17 +73,18 @@ from . import images
_stores = []
+
def push(store):
""" Register a new data store class """
_stores.insert(0, store)
+
def getstores():
""" Get a list containing known data store classes """
return _stores[:]
class Store(object):
-
"""
Represents a data store (i.e. a file or remote resource).
"""
@@ -104,12 +105,10 @@ class Store(object):
cls.__nodeclasses = [Unknown]
cls.__nodeclasses.insert(0, nodeclass)
-
def __contains__(self, key):
""" Check if a key is valid. """
raise NotImplementedError
-
def __getitem__(self, key):
""" Return a Node instance for *key*.
@@ -118,7 +117,6 @@ class Store(object):
"""
return self.gethandlers(key)[0](self, key)
-
def gethandlers(self, key=None):
""" Rather than picking a handler and returning the Node, return a
list of all handlers which can do something useful with *key*.
@@ -134,7 +132,7 @@ class Store(object):
raise KeyError(key)
return [nc for nc in self.__nodeclasses if nc.canhandle(self, key)]
-
+
# End plugin support
# -------------------------------------------------------------------------
@@ -142,8 +140,7 @@ class Store(object):
# For plugins which support local files, this is a dictionary mapping
# file kinds to lists of extensions, e.g. {'HDF5 File': ['*.hdf5', '*.h5']}
file_extensions = {}
-
-
+
@property
def url(self):
""" Identifies the file or Web resource (string).
@@ -153,7 +150,6 @@ class Store(object):
"""
raise NotImplementedError
-
@property
def displayname(self):
""" Short name for display purposes.
@@ -163,7 +159,6 @@ class Store(object):
"""
raise NotImplementedError
-
@property
def root(self):
""" The root node.
@@ -173,7 +168,6 @@ class Store(object):
"""
raise NotImplementedError
-
@staticmethod
def canhandle(url):
""" Test if this class can open the resource.
@@ -183,20 +177,17 @@ class Store(object):
"""
raise NotImplementedError
-
@property
def valid(self):
""" True if the store is open and ready for use, False otherwise.
"""
raise NotImplementedError
-
def __init__(self, url):
""" Open the resource.
"""
raise NotImplementedError
-
def close(self):
""" Discontinue access to the resource.
@@ -204,7 +195,6 @@ class Store(object):
"""
pass
-
def getparent(self, key):
""" Return the parent node of the object identified by *key*.
@@ -216,7 +206,6 @@ class Store(object):
class Node(object):
-
"""
Base class for all objects which live in a data store.
@@ -224,22 +213,21 @@ class Node(object):
more useful Node subclasses in this file. Direct Node subclasses can't
do anything interesting in the GUI; all they do is show up in the browser.
"""
-
+
# Class attribute containing a dict for icon support.
# Keys should be integers giving icon size; values are a callable returning
# a byte string with PNG image data.
# Example: icons = {16: get_png_16, 32: get_png_32}
- icons = NotImplemented
+ icons = NotImplemented
+
-
# A short string (2 or 3 words) describing what the class represents.
# This will show up in e.g. the "Open As" context menu.
# Example: "HDF5 Image" or "Swath"
classkind = NotImplemented
-
@staticmethod
def canhandle(store, key):
""" Determine whether this class can usefully represent the object.
@@ -248,7 +236,6 @@ class Node(object):
"""
raise NotImplementedError
-
def __init__(self, store, key):
""" Create an instance of this class.
@@ -256,7 +243,6 @@ class Node(object):
"""
raise NotImplementedError
-
@property
def key(self):
""" Unique key which identifies this object in the store.
@@ -265,19 +251,16 @@ class Node(object):
"""
raise NotImplementedError
-
@property
def store(self):
""" The data store to which the object belongs. """
raise NotImplementedError
-
@property
def displayname(self):
""" A short name for display purposes """
raise NotImplementedError
-
@property
def displaytitle(self):
""" A longer name appropriate for display in a window title.
@@ -286,34 +269,30 @@ class Node(object):
"""
return self.displayname
-
@property
def description(self):
""" Descriptive string (possibly multi-line) """
raise NotImplementedError
-
def preview(self, w, h):
""" [Optional] PNG image preview """
return None
class Container(Node):
-
"""
Represents an object which holds other objects (like an HDF5 group).
Subclasses will be displayed using the browser view.
"""
- icons = {16: images.folder_16,
- 64: images.folder_64 }
+ icons = {16: images.folder_16,
+ 64: images.folder_64}
def __len__(self):
""" Number of child objects """
raise NotImplementedError
-
def __iter__(self):
""" Iterator over child objects.
@@ -321,7 +300,6 @@ class Container(Node):
"""
raise NotImplementedError
-
def __getitem__(self, idx):
""" Open an item by index (necessary to support ListCtrl).
@@ -331,7 +309,6 @@ class Container(Node):
class KeyValue(Node):
-
"""
Represents an object which contains a sequence of key: value attributes.
@@ -340,82 +317,73 @@ class KeyValue(Node):
Subclasses will be displayed using a list-like control.
"""
- icons = {16: images.kv_16,
- 64: images.kv_64 }
+ icons = {16: images.kv_16,
+ 64: images.kv_64}
@property
def keys(self):
""" Return a list of attribute keys. """
raise NotImplementedError
-
def __getitem__(self, name):
""" Return the raw attribute value """
raise NotImplementedError
class Array(Node):
-
"""
Represents a NumPy-style regular, rectangular array.
Subclasses will be displayed in a spreadsheet-style viewer.
"""
- icons = {16: images.array_16,
- 64: images.array_64}
+ icons = {16: images.array_16,
+ 64: images.array_64}
@property
def shape(self):
""" Shape tuple """
raise NotImplementedError
-
@property
def dtype(self):
""" Data type """
raise NotImplementedError
-
def __getitem__(self, args):
""" Retrieve data elements """
raise NotImplementedError
class Image(Node):
-
"""
A single raster image.
"""
- icons = {16: images.image_16,
- 64: images.image_64 }
+ icons = {16: images.image_16,
+ 64: images.image_64}
@property
def width(self):
""" Image width in pixels """
pass
-
@property
def height(self):
""" Image height in pixels """
pass
-
@property
def palette(self):
""" Palette array, or None. """
raise NotImplementedError
-
@property
def data(self):
""" Image data """
class Plottable(Node):
-
"""
Represents anything that can be plotted to a 2D canvas using Matplotlib.
@@ -430,7 +398,6 @@ class Plottable(Node):
""" Pop up a Matplotlib display window """
raise NotImplementedError
-
def render(self, width, height):
""" Render the image as PNG.
@@ -440,15 +407,14 @@ class Plottable(Node):
class Unknown(Node):
-
"""
"Last resort" node (and the only concrete class in this module).
These can always be created, but do nothing useful.
"""
- icons = { 16: images.unknown_16,
- 64: images.unknown_64 }
-
+ icons = {16: images.unknown_16,
+ 64: images.unknown_64}
+
classkind = "Unknown"
@staticmethod
@@ -478,10 +444,3 @@ class Unknown(Node):
@property
def description(self):
return "Unknown object"
-
-
-
-
-
-
-
diff --git a/compass_model/icons/array_16.png b/hdf_compass/compass_model/icons/array_16.png
similarity index 100%
rename from compass_model/icons/array_16.png
rename to hdf_compass/compass_model/icons/array_16.png
diff --git a/compass_model/icons/array_64.png b/hdf_compass/compass_model/icons/array_64.png
similarity index 100%
rename from compass_model/icons/array_64.png
rename to hdf_compass/compass_model/icons/array_64.png
diff --git a/compass_model/icons/folder_16.png b/hdf_compass/compass_model/icons/folder_16.png
similarity index 100%
rename from compass_model/icons/folder_16.png
rename to hdf_compass/compass_model/icons/folder_16.png
diff --git a/compass_model/icons/folder_64.png b/hdf_compass/compass_model/icons/folder_64.png
similarity index 100%
rename from compass_model/icons/folder_64.png
rename to hdf_compass/compass_model/icons/folder_64.png
diff --git a/compass_model/icons/image_16.png b/hdf_compass/compass_model/icons/image_16.png
similarity index 100%
rename from compass_model/icons/image_16.png
rename to hdf_compass/compass_model/icons/image_16.png
diff --git a/compass_model/icons/image_64.png b/hdf_compass/compass_model/icons/image_64.png
similarity index 100%
rename from compass_model/icons/image_64.png
rename to hdf_compass/compass_model/icons/image_64.png
diff --git a/compass_model/icons/kv_16.png b/hdf_compass/compass_model/icons/kv_16.png
similarity index 100%
rename from compass_model/icons/kv_16.png
rename to hdf_compass/compass_model/icons/kv_16.png
diff --git a/compass_model/icons/kv_64.png b/hdf_compass/compass_model/icons/kv_64.png
similarity index 100%
rename from compass_model/icons/kv_64.png
rename to hdf_compass/compass_model/icons/kv_64.png
diff --git a/compass_model/icons/license.txt b/hdf_compass/compass_model/icons/license.txt
similarity index 100%
rename from compass_model/icons/license.txt
rename to hdf_compass/compass_model/icons/license.txt
diff --git a/compass_model/icons/readme.txt b/hdf_compass/compass_model/icons/readme.txt
similarity index 100%
rename from compass_model/icons/readme.txt
rename to hdf_compass/compass_model/icons/readme.txt
diff --git a/compass_model/icons/unknown_16.png b/hdf_compass/compass_model/icons/unknown_16.png
similarity index 100%
rename from compass_model/icons/unknown_16.png
rename to hdf_compass/compass_model/icons/unknown_16.png
diff --git a/compass_model/icons/unknown_64.png b/hdf_compass/compass_model/icons/unknown_64.png
similarity index 100%
rename from compass_model/icons/unknown_64.png
rename to hdf_compass/compass_model/icons/unknown_64.png
diff --git a/compass_model/images.py b/hdf_compass/compass_model/images.py
similarity index 100%
rename from compass_model/images.py
rename to hdf_compass/compass_model/images.py
diff --git a/compass_model/test.py b/hdf_compass/compass_model/test.py
similarity index 99%
rename from compass_model/test.py
rename to hdf_compass/compass_model/test.py
index a24c241..db15ad0 100644
--- a/compass_model/test.py
+++ b/hdf_compass/compass_model/test.py
@@ -41,9 +41,10 @@ To run unittest, which discovers classes "store_tests" and "container_tests":
"""
-from . import Node, Store
import unittest as ut
+from . import Node, Store
+
# --- Public API --------------------------------------------------------------
@@ -53,9 +54,11 @@ def store(storecls_, url_):
storecls: Your compass_model.Store implementation.
url: A URL representing a valid datastore to test against.
"""
+
class TestStore(_TestStore):
storecls = storecls_
url = url_
+
return TestStore
@@ -67,18 +70,20 @@ def container(storecls_, url_, nodecls_, key_):
nodecls: Your compass_model.Container implementation.
key: A valid key which points to a container.
"""
+
class TestContainer(_TestContainer):
storecls = storecls_
url = url_
nodecls = nodecls_
key = key_
+
return TestContainer
+
# --- End public API ----------------------------------------------------------
class _TestStore(ut.TestCase):
-
"""
Base class for testing Stores.
"""
@@ -86,59 +91,49 @@ class _TestStore(ut.TestCase):
storecls = None
url = None
-
def setUp(self):
self.store = self.storecls(self.url)
-
def tearDown(self):
if self.store.valid:
self.store.close()
-
def test_class(self):
""" Verify the thing we get from storecls is actually a Store """
self.assertIsInstance(self.store, Store)
-
def test_url(self):
""" Verify store.url produces a string """
self.assertIsInstance(self.store.url, basestring)
-
def test_displayname(self):
""" Verify store.displayname produces a string. """
self.assertIsInstance(self.store.displayname, basestring)
-
def test_root(self):
""" Verify store.root exists and has no parent """
self.assertIsInstance(self.store.root, Node)
self.assertIs(self.store.getparent(self.store.root.key), None)
-
def test_close_valid(self):
""" Verify that store.close() works and is reflected by store.valid """
self.assertTrue(self.store.valid)
self.store.close()
self.assertFalse(self.store.valid)
-
def test_canhandle(self):
""" Verify canhandle() works properly """
self.assertTrue(self.storecls.canhandle(self.url))
self.assertFalse(self.storecls.canhandle("file:///no/such/path"))
-
def test_handlers(self):
""" The implementation has at least one Node handler registered """
h = self.store.gethandlers()
# Test for N > 1 because compass_model.Unknown is always present
- self.assertGreater(len(h), 1)
+ self.assertGreater(len(h), 1)
class _TestNode(ut.TestCase):
-
"""
Base class for testing Node objects.
"""
@@ -148,23 +143,19 @@ class _TestNode(ut.TestCase):
url = None
key = None
-
def setUp(self):
self.store = self.storecls(self.url)
self.node = self.nodecls(self.store, self.key)
-
def tearDown(self):
if self.store.valid:
self.store.close()
-
def test_contains(self):
""" Consistency check for store __contains___ """
self.assertTrue(self.key in self.store)
self.assertFalse("keynotinstore" in self.store)
-
def test_icons(self):
""" Icon dict is present and contains valid items:
@@ -178,23 +169,20 @@ class _TestNode(ut.TestCase):
data = val()
self.assertIsInstance(data, bytes)
self.assertEqual(data[0:8], b"\x89\x50\x4E\x47\x0D\x0A\x1A\x0A")
-
+
# required resolutions
self.assertIn(16, self.nodecls.icons)
self.assertIn(64, self.nodecls.icons)
-
def test_classkind(self):
""" classkind is present, and a string """
self.assertIsInstance(self.nodecls.classkind, basestring)
-
def test_canhandle(self):
""" canhandle() consistency check """
self.assertTrue(self.nodecls.canhandle(self.store, self.key))
self.assertFalse(self.nodecls.canhandle(self.store, "/some/random/key"))
-
def test_key(self):
""" Node.key returns a hashable object.
@@ -204,20 +192,17 @@ class _TestNode(ut.TestCase):
hash(out)
self.assertEqual(self.node.key, self.key)
-
def test_store(self):
""" Node.store returns a data store of the same class and URL. """
self.assertIsInstance(self.node.store, self.storecls)
self.assertEqual(self.node.store.url, self.store.url)
-
def test_displayname(self):
""" displayname exists and is a string """
self.assertIsInstance(self.node.displayname, basestring)
class _TestContainer(_TestNode):
-
"""
Class for testing compass_model.Container implementations.
"""
@@ -227,14 +212,12 @@ class _TestContainer(_TestNode):
self.assertGreaterEqual(len(self.node), 0)
self.assertEqual(len(self.node), len(list(self.node)))
-
def test_getitem(self):
""" __getitem__ works properly """
for idx in xrange(len(self.node)):
out = self.node[idx]
self.assertIsInstance(out, Node)
-
def test_getitem_exception(self):
""" out-of range indices raise IndexError """
with self.assertRaises(IndexError):
diff --git a/compass_viewer/__init__.py b/hdf_compass/compass_viewer/__init__.py
similarity index 83%
rename from compass_viewer/__init__.py
rename to hdf_compass/compass_viewer/__init__.py
index 7f1d143..b8d29ee 100644
--- a/compass_viewer/__init__.py
+++ b/hdf_compass/compass_viewer/__init__.py
@@ -22,7 +22,7 @@ matplotlib.use('WXAgg')
import wx
-import compass_model
+from hdf_compass import compass_model
from .imagesupport import png_to_bitmap
from . import platform
@@ -52,7 +52,6 @@ class CompassImageList(wx.ImageList):
self._indices = {}
self._size = size
-
def get_index(self, nodeclass):
""" Retrieve an index appropriate for the given Node subclass. """
@@ -147,33 +146,63 @@ def open_store(url):
return False
+def load_plugins():
+ """ Helper function that attempts to load all the plugins """
+
+ from hdf_compass import compass_model
+
+ try:
+ from hdf_compass import filesystem_model
+ except ImportError:
+ print("Filesystem plugin not loaded")
+
+ try:
+ from hdf_compass import array_model
+ except ImportError:
+ print("Array plugin not loaded")
+
+ try:
+ from hdf_compass import hdf5_model
+ except ImportError:
+ print("HDF plugin not loaded")
+
+ # Coming soon!
+ # try:
+ # from hdf_compass import bag_model
+ # except ImportError:
+ # print("BAG plugin not loaded")
+
+ try:
+ from hdf_compass import asc_model
+ except ImportError:
+ print("Ascii grid plugin not loaded")
+
+ try:
+ from hdf_compass import opendap_model
+ except ImportError:
+ print("Opendap plugin not loaded")
+
+
def run():
""" Run HDFCompass. Handles all command-line arguments, etc.
"""
- # These are imported to register their classes with
- # compass_model. We don't use them directly.
- import filesystem_model
- import array_model
- import hdf5_model
- import asc_model
- # todo - disabling opendap module for now due to installer issues
- # import opendap_model
-
import sys
import os.path as op
app = CompassApp(False)
+ load_plugins()
+
urls = sys.argv[1:]
- for url in sys.argv[1:]:
+ for url in urls:
if "://" not in url:
# assumed to be file path
if sys.platform == 'win32':
- url = 'file:///'+op.abspath(url)
+ url = 'file:///' + op.abspath(url)
else:
- url = 'file://'+op.abspath(url)
+ url = 'file://' + op.abspath(url)
if not open_store(url):
print 'Failed to open "%s"; no handlers'%url
@@ -184,4 +213,4 @@ def run():
else:
f.Show()
- app.MainLoop()
\ No newline at end of file
+ app.MainLoop()
diff --git a/compass_viewer/array/__init__.py b/hdf_compass/compass_viewer/array/__init__.py
similarity index 90%
rename from compass_viewer/array/__init__.py
rename to hdf_compass/compass_viewer/array/__init__.py
index bfd52dd..ee09d09 100644
--- a/compass_viewer/array/__init__.py
+++ b/hdf_compass/compass_viewer/array/__init__.py
@@ -18,10 +18,10 @@ import wx.grid
from wx.lib.newevent import NewCommandEvent
from .. import imagesupport
-
from ..frame import NodeFrame
from .plot import LinePlotFrame, ContourPlotFrame
+
# Indicates that the slicing selection may have changed.
# These events are emitted by the SlicerPanel.
ArraySlicedEvent, EVT_ARRAY_SLICED = NewCommandEvent()
@@ -31,7 +31,6 @@ ID_VIS_MENU_PLOT = wx.NewId()
class ArrayFrame(NodeFrame):
-
"""
Top-level frame displaying objects of type compass_model.Array.
@@ -44,7 +43,7 @@ class ArrayFrame(NodeFrame):
def __init__(self, node, pos=None):
""" Create a new array viewer, to display *node*. """
- NodeFrame.__init__(self, node, size=(800,400), title=node.displayname, pos=pos)
+ NodeFrame.__init__(self, node, size=(800, 400), title=node.displayname, pos=pos)
self.node = node
@@ -73,31 +72,28 @@ class ArrayFrame(NodeFrame):
self.timer = wx.Timer(self, ID_WORKAROUND_TIMER)
self.timer.Start(100)
-
def on_workaround_timer(self, evt):
""" See slicer.enable_spinctrls docs """
self.timer.Destroy()
self.slicer.enable_spinctrls()
-
def init_toolbar(self):
""" Set up the toolbar at the top of the window. """
- tsize = (24,24)
+ tsize = (24, 24)
plot_bmp = imagesupport.getbitmap('viz_plot_24')
- self.toolbar = self.CreateToolBar(wx.TB_HORIZONTAL|wx.NO_BORDER|wx.TB_FLAT|wx.TB_TEXT)
+ self.toolbar = self.CreateToolBar(wx.TB_HORIZONTAL | wx.NO_BORDER | wx.TB_FLAT | wx.TB_TEXT)
self.toolbar.SetToolBitmapSize(tsize)
self.toolbar.AddStretchableSpace()
- self.toolbar.AddLabelTool(ID_VIS_MENU_PLOT, "Plot Data", plot_bmp, shortHelp="Plot data in a popup window", longHelp="Long help for 'New'")
+ self.toolbar.AddLabelTool(ID_VIS_MENU_PLOT, "Plot Data", plot_bmp, shortHelp="Plot data in a popup window",
+ longHelp="Long help for 'New'")
self.toolbar.Realize()
-
def on_sliced(self, evt):
""" User has chosen to display a different part of the dataset. """
self.grid.Refresh()
-
def on_plot(self, evt):
""" User has chosen to plot the current selection """
cols = self.grid.GetSelectedCols()
@@ -123,9 +119,9 @@ class ArrayFrame(NodeFrame):
if len(self.node.shape) == 1:
data = [self.node[self.slicer.indices]]
else:
- data = [self.node[self.slicer.indices+(c,)] for c in cols]
+ data = [self.node[self.slicer.indices + (c,)] for c in cols]
- names = ["Col %d"%c for c in cols] if len(data) > 1 else None
+ names = ["Col %d" % c for c in cols] if len(data) > 1 else None
f = LinePlotFrame(data, names)
f.Show()
@@ -133,9 +129,9 @@ class ArrayFrame(NodeFrame):
# Rows in view are selected
elif len(rows) != 0:
-
- data = [self.node[self.slicer.indices+(slice(None,None,None),r)] for r in rows]
- names = ["Row %d"%r for r in rows] if len(data) > 1 else None
+
+ data = [self.node[self.slicer.indices + (slice(None, None, None), r)] for r in rows]
+ names = ["Row %d" % r for r in rows] if len(data) > 1 else None
f = LinePlotFrame(data, names)
f.Show()
@@ -165,7 +161,6 @@ class ArrayFrame(NodeFrame):
class SlicerPanel(wx.Panel):
-
"""
Holds controls for data access.
@@ -183,7 +178,6 @@ class SlicerPanel(wx.Panel):
"""
return tuple([x.GetValue() for x in self.spincontrols])
-
def __init__(self, parent, shape, hasfields):
""" Create a new slicer panel.
@@ -209,11 +203,11 @@ class SlicerPanel(wx.Panel):
if rank > visible_rank:
infotext = wx.StaticText(self, wx.ID_ANY, "Array Indexing: ")
- sizer.Add(infotext, 0, flag=wx.EXPAND|wx.ALL, border=10)
+ sizer.Add(infotext, 0, flag=wx.EXPAND | wx.ALL, border=10)
- for idx in xrange(rank-visible_rank):
- sc = wx.SpinCtrl(self, max=shape[idx]-1, value="0", min=0)
- sizer.Add(sc, 0, flag=wx.EXPAND|wx.ALL, border=10)
+ for idx in xrange(rank - visible_rank):
+ sc = wx.SpinCtrl(self, max=shape[idx] - 1, value="0", min=0)
+ sizer.Add(sc, 0, flag=wx.EXPAND | wx.ALL, border=10)
sc.Disable()
self.spincontrols.append(sc)
@@ -221,7 +215,6 @@ class SlicerPanel(wx.Panel):
self.Bind(wx.EVT_SPINCTRL, self.on_spin)
-
def enable_spinctrls(self):
""" Unlock the spin controls.
@@ -232,15 +225,12 @@ class SlicerPanel(wx.Panel):
for sc in self.spincontrols:
sc.Enable()
-
def on_spin(self, evt):
""" Spinbox value changed; notify parent to refresh the grid. """
wx.PostEvent(self, ArraySlicedEvent(self.GetId()))
-
class ArrayGrid(wx.grid.Grid):
-
"""
Grid class to display the Array.
@@ -264,7 +254,6 @@ class ArrayGrid(wx.grid.Grid):
class LRUTileCache(object):
-
"""
Simple tile-based LRU cache which goes between the Grid and
the Array object. Caches tiles along the last 1 or 2 dimensions
@@ -274,44 +263,44 @@ class LRUTileCache(object):
to support point-based callbacks for the Grid, arguments may
only be indices, not slices.
"""
-
+
TILESIZE = 100 # Tiles will have shape (100,) or (100, 100)
- MAXTILES = 50 # Max number of tiles to retain in the cache
-
+ MAXTILES = 50 # Max number of tiles to retain in the cache
+
def __init__(self, arr):
""" *arr* is anything implementing compass_model.Array """
import collections
self.cache = collections.OrderedDict()
self.arr = arr
-
+
def __getitem__(self, args):
""" Restricted to an index or tuple of indices. """
-
+
if not isinstance(args, tuple):
args = (args,)
-
+
# Split off the last 1 or 2 dimensions
coarse_position, fine_position = args[0:-2], args[-2:]
-
+
def clip(x):
""" Round down to nearest TILESIZE; takes e.g. 181 -> 100 """
- return (x//self.TILESIZE)*self.TILESIZE
-
+ return (x // self.TILESIZE) * self.TILESIZE
+
# Tuple with index of tile corner
tile_key = coarse_position + tuple(clip(x) for x in fine_position)
-
+
# Slice which will be applied to dataset to retrieve tile
- tile_slice = coarse_position + tuple(slice(clip(x), clip(x)+self.TILESIZE) for x in fine_position)
-
+ tile_slice = coarse_position + tuple(slice(clip(x), clip(x) + self.TILESIZE) for x in fine_position)
+
# Index applied to tile to retrieve the desired data point
- tile_data_index = tuple(x%self.TILESIZE for x in fine_position)
-
+ tile_data_index = tuple(x % self.TILESIZE for x in fine_position)
+
# Case 1: Add tile to cache, ejecting oldest tile if needed
if not tile_key in self.cache:
-
+
if len(self.cache) >= self.MAXTILES:
self.cache.popitem(last=False)
-
+
tile = self.arr[tile_slice]
self.cache[tile_key] = tile
@@ -319,12 +308,11 @@ class LRUTileCache(object):
else:
tile = self.cache.pop(tile_key)
self.cache[tile_key] = tile
-
+
return tile[tile_data_index]
-
-class ArrayTable(wx.grid.PyGridTableBase):
+class ArrayTable(wx.grid.PyGridTableBase):
"""
"Table" class which provides data and metadata for the grid to display.
@@ -348,14 +336,13 @@ class ArrayTable(wx.grid.PyGridTableBase):
self.names = node.dtype.names
self.cache = LRUTileCache(self.node)
-
+
def GetNumberRows(self):
""" Callback for number of rows displayed by the grid control """
if self.rank == 0:
return 1
return self.node.shape[-1]
-
def GetNumberCols(self):
""" Callback for number of columns displayed by the grid control.
@@ -367,14 +354,13 @@ class ArrayTable(wx.grid.PyGridTableBase):
return 1
return self.node.shape[-2]
-
def GetValue(self, row, col):
""" Callback which provides data to the Grid.
row, col: Integers giving row and column position (0-based).
"""
# Scalar case
- if self.rank == 0:
+ if self.rank == 0:
data = self.node[()]
if self.names is None:
return data
@@ -389,7 +375,7 @@ class ArrayTable(wx.grid.PyGridTableBase):
# ND case. Watch out for compound mode!
if self.names is None:
- args = self.slicer.indices + (col,row)
+ args = self.slicer.indices + (col, row)
else:
args = self.slicer.indices + (row,)
@@ -398,7 +384,6 @@ class ArrayTable(wx.grid.PyGridTableBase):
return data
return data[self.names[col]]
-
def GetRowLabelValue(self, row):
""" Callback for row labels.
@@ -408,7 +393,6 @@ class ArrayTable(wx.grid.PyGridTableBase):
return "Value"
return str(row)
-
def GetColLabelValue(self, col):
""" Callback for column labels.
diff --git a/compass_viewer/array/plot.py b/hdf_compass/compass_viewer/array/plot.py
similarity index 95%
rename from compass_viewer/array/plot.py
rename to hdf_compass/compass_viewer/array/plot.py
index 91ef567..17c060d 100644
--- a/compass_viewer/array/plot.py
+++ b/hdf_compass/compass_viewer/array/plot.py
@@ -16,7 +16,6 @@ Matplotlib window with toolbar.
import numpy as np
import wx
-
import matplotlib.pyplot as plt
from matplotlib.figure import Figure
from matplotlib.backends.backend_wxagg import \
@@ -27,7 +26,6 @@ from ..frame import BaseFrame
class PlotFrame(BaseFrame):
-
"""
Base class for Matplotlib plot windows.
@@ -39,12 +37,12 @@ class PlotFrame(BaseFrame):
"""
print self.__class__.__name__
- BaseFrame.__init__(self, id=wx.ID_ANY, title=title, size=(800,400))
-
+ BaseFrame.__init__(self, id=wx.ID_ANY, title=title, size=(800, 400))
+
self.data = data
self.panel = wx.Panel(self)
-
+
self.dpi = 100
self.fig = Figure((6.0, 4.0), dpi=self.dpi)
self.canvas = FigCanvas(self.panel, -1, self.fig)
@@ -66,31 +64,28 @@ class PlotFrame(BaseFrame):
class LinePlotFrame(PlotFrame):
-
def __init__(self, data, names=None, title="Line Plot"):
self.names = names
PlotFrame.__init__(self, data, title)
-
def draw_figure(self):
lines = [self.axes.plot(d)[0] for d in self.data]
if self.names is not None:
for n in self.names:
self.axes.legend(tuple(lines), tuple(self.names))
-
-class ContourPlotFrame(PlotFrame):
+class ContourPlotFrame(PlotFrame):
def __init__(self, data, names=None, title="Contour Plot"):
PlotFrame.__init__(self, data, title)
-
+
def draw_figure(self):
maxElements = 500 # don't attempt plot more than 500x500 elements
rows = self.data.shape[0]
cols = self.data.shape[1]
- row_stride = rows/maxElements + 1
- col_stride = cols/maxElements + 1
+ row_stride = rows / maxElements + 1
+ col_stride = cols / maxElements + 1
data = self.data[::row_stride, ::col_stride]
xx = np.arange(0, self.data.shape[1], col_stride)
yy = np.arange(0, self.data.shape[0], row_stride)
diff --git a/compass_viewer/container/__init__.py b/hdf_compass/compass_viewer/container/__init__.py
similarity index 91%
rename from compass_viewer/container/__init__.py
rename to hdf_compass/compass_viewer/container/__init__.py
index f25ba24..1df393c 100644
--- a/compass_viewer/container/__init__.py
+++ b/hdf_compass/compass_viewer/container/__init__.py
@@ -19,12 +19,12 @@ Currently list and icon views are supported.
"""
import wx
-import compass_model
+from hdf_compass import compass_model
from .. import imagesupport
from ..frame import NodeFrame
-from ..events import ID_COMPASS_OPEN, CompassOpenEvent
-from ..events import ContainerSelectionEvent, EVT_CONTAINER_SELECTION
+from ..events import ID_COMPASS_OPEN
+from ..events import EVT_CONTAINER_SELECTION
from .list import ContainerReportList, ContainerIconList
ID_GO_MENU_BACK = wx.NewId()
@@ -36,7 +36,6 @@ ID_VIEW_MENU_ICON = wx.NewId()
class ContainerFrame(NodeFrame):
-
"""
A frame to display a Container class, and browse its contents.
"""
@@ -71,10 +70,10 @@ class ContainerFrame(NodeFrame):
self.Bind(wx.EVT_MENU, lambda evt: self.list_view(), id=ID_VIEW_MENU_LIST)
self.Bind(wx.EVT_MENU, lambda evt: self.icon_view(), id=ID_VIEW_MENU_ICON)
- self.toolbar = self.CreateToolBar(wx.TB_HORIZONTAL|wx.NO_BORDER|wx.TB_FLAT|wx.TB_TEXT)
+ self.toolbar = self.CreateToolBar(wx.TB_HORIZONTAL | wx.NO_BORDER | wx.TB_FLAT | wx.TB_TEXT)
- tsize = (24,24)
- back_bmp = imagesupport.getbitmap('go_back_24')
+ tsize = (24, 24)
+ back_bmp = imagesupport.getbitmap('go_back_24')
next_bmp = imagesupport.getbitmap('go_next_24')
up_bmp = imagesupport.getbitmap('go_up_24')
icon_bmp = imagesupport.getbitmap('view_icon_24')
@@ -86,8 +85,10 @@ class ContainerFrame(NodeFrame):
self.toolbar.AddSeparator()
self.toolbar.AddLabelTool(ID_GO_MENU_UP, "Up", up_bmp, shortHelp="New", longHelp="Long help for 'New'")
self.toolbar.AddStretchableSpace()
- self.toolbar.AddLabelTool(ID_VIEW_MENU_LIST, "List View", list_bmp, shortHelp="New", longHelp="Long help for 'New'")
- self.toolbar.AddLabelTool(ID_VIEW_MENU_ICON, "Icon View", icon_bmp, shortHelp="New", longHelp="Long help for 'New'")
+ self.toolbar.AddLabelTool(ID_VIEW_MENU_LIST, "List View", list_bmp, shortHelp="New",
+ longHelp="Long help for 'New'")
+ self.toolbar.AddLabelTool(ID_VIEW_MENU_ICON, "Icon View", icon_bmp, shortHelp="New",
+ longHelp="Long help for 'New'")
self.toolbar.Realize()
@@ -97,19 +98,16 @@ class ContainerFrame(NodeFrame):
self.history_ptr = 0
self.update_view()
-
def list_view(self):
""" Switch to list view """
if not isinstance(self.view, ContainerReportList):
self.view = ContainerReportList(self, self.history[self.history_ptr])
-
def icon_view(self):
""" Switch to icon view """
if not isinstance(self.view, ContainerIconList):
self.view = ContainerIconList(self, self.history[self.history_ptr])
-
# --- Begin history support functions -------------------------------------
@property
@@ -122,14 +120,12 @@ class ContainerFrame(NodeFrame):
self.history_ptr -= 1
self.update_view()
-
def go_next(self):
""" Go to the next displayed item """
- if self.history_ptr < (len(self.history)-1):
+ if self.history_ptr < (len(self.history) - 1):
self.history_ptr += 1
self.update_view()
-
def go_up(self):
""" Go to the enclosing container """
node = self.history[self.history_ptr]
@@ -137,13 +133,12 @@ class ContainerFrame(NodeFrame):
if parent.key != node.key: # at the root item
self.go(parent)
-
def go(self, newnode):
""" Go to a particular node.
Adds the node to the history.
"""
- del self.history[self.history_ptr+1:]
+ del self.history[self.history_ptr + 1:]
self.history.append(newnode)
self.history_ptr += 1
self.update_view()
@@ -159,7 +154,7 @@ class ContainerFrame(NodeFrame):
self.update_info()
can_go_back = self.history_ptr > 0
- can_go_next = self.history_ptr < (len(self.history)-1)
+ can_go_next = self.history_ptr < (len(self.history) - 1)
can_go_up = self.node.store.getparent(self.node.key) is not None
self.go_menu.Enable(ID_GO_MENU_BACK, can_go_back)
self.go_menu.Enable(ID_GO_MENU_NEXT, can_go_next)
@@ -172,7 +167,6 @@ class ContainerFrame(NodeFrame):
self.view_menu.Enable(ID_VIEW_MENU_ICON, icon_view_allowed)
self.toolbar.EnableTool(ID_VIEW_MENU_ICON, icon_view_allowed)
-
def update_info(self):
""" Refresh the left-hand side information panel, according to the
current selection in the view.
@@ -182,7 +176,6 @@ class ContainerFrame(NodeFrame):
node = self.node # Nothing selected; show this node's info
self.info.display(node)
-
def on_open(self, evt):
""" Trap Container open events, so we can browse instead of launching
new windows.
@@ -193,6 +186,3 @@ class ContainerFrame(NodeFrame):
self.go(newnode)
else:
evt.Skip()
-
-
-
\ No newline at end of file
diff --git a/compass_viewer/container/list.py b/hdf_compass/compass_viewer/container/list.py
similarity index 93%
rename from compass_viewer/container/list.py
rename to hdf_compass/compass_viewer/container/list.py
index 1e1cd3e..dc29eee 100644
--- a/compass_viewer/container/list.py
+++ b/hdf_compass/compass_viewer/container/list.py
@@ -14,17 +14,16 @@ Handles list and icon view for Container display.
"""
import wx
-import compass_model
-from ..events import ID_COMPASS_OPEN, CompassOpenEvent
-from ..events import ContainerSelectionEvent, EVT_CONTAINER_SELECTION
+from hdf_compass import compass_model
+from ..events import CompassOpenEvent
+from ..events import ContainerSelectionEvent
ID_CONTEXT_MENU_OPEN = wx.NewId()
ID_CONTEXT_MENU_OPENWINDOW = wx.NewId()
class ContainerList(wx.ListCtrl):
-
"""
Base class for list and icons views, both of which use wx.ListCtrl.
@@ -61,7 +60,7 @@ class ContainerList(wx.ListCtrl):
def on_activate(self, evt):
""" Emit a CompassOpenEvent when an item is double-clicked.
- """
+ """
# wxPython Mac incorrectly treats a rapid left-right click as activate
ms = wx.GetMouseState()
@@ -127,7 +126,6 @@ class ContainerList(wx.ListCtrl):
menu.Destroy()
-
def on_context_open(self, evt):
""" Called in response to a plain "Open" in the context menu.
@@ -136,7 +134,6 @@ class ContainerList(wx.ListCtrl):
pos = wx.GetTopLevelParent(self).GetPosition()
wx.PostEvent(self, CompassOpenEvent(self._menu_node, pos=pos))
-
def on_context_openwindow(self, evt):
""" Called in response to a plain "Open in New Window" in the context
menu.
@@ -146,15 +143,14 @@ class ContainerList(wx.ListCtrl):
pos = wx.GetTopLevelParent(self).GetPosition()
wx.PostEvent(wx.GetApp(), CompassOpenEvent(self._menu_node, pos=pos))
-
def on_context_openas(self, evt):
""" Called in response to one of the "Open As" context menu items.
"""
# The "Open As" submenu ID
- id_ = evt.GetId()
+ id_ = evt.GetId()
# Node which was right-clicked in the view
- node_being_opened = self._menu_node
+ node_being_opened = self._menu_node
# The requested Node subclass to instantiate
h = self._menu_handlers[id_]
@@ -166,13 +162,11 @@ class ContainerList(wx.ListCtrl):
pos = wx.GetTopLevelParent(self).GetPosition()
wx.PostEvent(self, CompassOpenEvent(node_new, pos=pos))
-
- # End context menu support
- # -------------------------------------------------------------------
+ # End context menu support
+ # -------------------------------------------------------------------
class ContainerIconList(ContainerList):
-
"""
Icon view of nodes in a Container.
"""
@@ -184,7 +178,7 @@ class ContainerIconList(ContainerList):
self.node = node
self.il = wx.GetApp().imagelists[64]
- self.SetImageList(self.il, wx.IMAGE_LIST_NORMAL)
+ self.SetImageList(self.il, wx.IMAGE_LIST_NORMAL)
for item in xrange(len(self.node)):
subnode = self.node[item]
@@ -193,7 +187,6 @@ class ContainerIconList(ContainerList):
class ContainerReportList(ContainerList):
-
"""
List view of the container's contents.
@@ -208,7 +201,8 @@ class ContainerReportList(ContainerList):
node: Container instance to be displayed
"""
- ContainerList.__init__(self, parent, node, style=wx.LC_REPORT|wx.LC_VIRTUAL|wx.LC_SINGLE_SEL|wx.BORDER_NONE)
+ ContainerList.__init__(self, parent, node,
+ style=wx.LC_REPORT | wx.LC_VIRTUAL | wx.LC_SINGLE_SEL | wx.BORDER_NONE)
self.node = node
@@ -223,7 +217,6 @@ class ContainerReportList(ContainerList):
self.SetItemCount(len(node))
self.Refresh()
-
def OnGetItemText(self, item, col):
""" Callback method to support virtual list ctrl """
if col == 0:
@@ -232,7 +225,6 @@ class ContainerReportList(ContainerList):
return type(self.node[item]).classkind
return ""
-
def OnGetItemImage(self, item):
""" Callback method to support virtual list ctrl """
subnode = self.node[item]
diff --git a/compass_viewer/events.py b/hdf_compass/compass_viewer/events.py
similarity index 100%
rename from compass_viewer/events.py
rename to hdf_compass/compass_viewer/events.py
diff --git a/compass_viewer/frame.py b/hdf_compass/compass_viewer/frame.py
similarity index 96%
rename from compass_viewer/frame.py
rename to hdf_compass/compass_viewer/frame.py
index 37b62aa..4f2279e 100644
--- a/compass_viewer/frame.py
+++ b/hdf_compass/compass_viewer/frame.py
@@ -21,6 +21,7 @@ here.
import os
import sys
+from datetime import date
import wx
from wx.lib.pubsub import pub
@@ -31,9 +32,10 @@ from . import platform
ID_OPEN_RESOURCE = wx.NewId()
ID_CLOSE_FILE = wx.NewId()
-import compass_model
+from hdf_compass import compass_model
from .events import CompassOpenEvent
+
class BaseFrame(wx.Frame):
"""
@@ -100,28 +102,24 @@ class BaseFrame(wx.Frame):
self.Bind(wx.EVT_MENU, self.on_about, id=wx.ID_ABOUT)
self.Bind(wx.EVT_MENU, self.on_exit, id=wx.ID_EXIT)
-
def on_exit(self, evt):
""" Called on "exit" event from the menu """
wx.GetApp().Exit()
-
-
+
def on_about(self, evt):
""" Display an "About" dialog """
info = wx.AboutDialogInfo()
info.Name = "HDFCompass"
info.Version = platform.VERSION
- info.Copyright = "(c) 2014-2015 The HDF Group"
+ info.Copyright = "(c) 2014-%d The HDF Group" % date.today().year
icon_48 = wx.EmptyIcon()
icon_48.CopyFromBitmap(imagesupport.getbitmap('compass_48'))
info.SetIcon(icon_48)
wx.AboutBox(info)
-
def on_file_open(self, evt):
""" Request to open a file via the Open entry in the File menu """
- import compass_model
-
+
def make_filter_string():
""" Make a wxPython dialog filter string segment from dict """
filter_string = []
@@ -137,9 +135,9 @@ class BaseFrame(wx.Frame):
if s.startswith("HDF"):
hdf_filter_string.append(s)
else:
- filter_string.append(s)
+ filter_string.append(s)
filter_string = hdf_filter_string + filter_string
- filter_string.append('All Files (*.*)|*.*');
+ filter_string.append('All Files (*.*)|*.*')
pipe = "|"
return pipe.join(filter_string)
@@ -163,16 +161,14 @@ class BaseFrame(wx.Frame):
url = 'file://' + path
if not open_store(url):
dlg = wx.MessageDialog(self, 'The following file could not be opened:\n\n%s' % path,
- 'No handler for file', wx.OK | wx.ICON_INFORMATION)
+ 'No handler for file', wx.OK | wx.ICON_INFORMATION)
dlg.ShowModal()
dlg.Destroy()
-
def on_window_close(self, evt):
""" Close Window file event, or cmd-W """
self.Destroy()
-
-
+
def on_resource_open(self, evt):
""" Request to open a URL via the File menu """
from . import open_store
@@ -183,16 +179,15 @@ class BaseFrame(wx.Frame):
return
url = dlg.GetValue()
- url = url.strip() #remove any new lines
+ url = url.strip() # remove any new lines
dlg.Destroy()
if not open_store(url):
dlg = wx.MessageDialog(self, 'The following URL could not be opened:\n\n%s' % url,
- 'No handler for URL', wx.OK | wx.ICON_INFORMATION)
+ 'No handler for URL', wx.OK | wx.ICON_INFORMATION)
dlg.ShowModal()
dlg.Destroy()
-
def add_menu(self, menu, title):
""" Add a menu at the appropriate place in the menubar """
mb = self.GetMenuBar()
@@ -251,12 +246,10 @@ class NodeFrame(BaseFrame):
if not, close themselves.
"""
-
# --- Store reference-counting methods ------------------------------------
_stores = {}
-
@classmethod
def _incref(cls, store):
""" Record that a client is using the specified store. """
@@ -265,7 +258,6 @@ class NodeFrame(BaseFrame):
except KeyError:
cls._stores[store] = 1
-
@classmethod
def _decref(cls, store):
""" Record that a client is finished using the specified store. """
@@ -279,7 +271,6 @@ class NodeFrame(BaseFrame):
except KeyError:
pass
-
@classmethod
def _close(cls, store):
""" Manually close the store, and broadcast a pubsub notification.
@@ -290,31 +281,26 @@ class NodeFrame(BaseFrame):
# --- End store reference-counting ----------------------------------------
-
@property
def info(self):
""" The InfoPanel object used for the left-hand sidebar.
"""
return self.__info
-
@property
def node(self):
""" Node instance displayed by the frame. """
return self.__node
-
@node.setter
def node(self, newnode):
self.__node = newnode
-
@property
def view(self):
""" Right-hand view """
return self.__view
-
@view.setter
def view(self, window):
if self.__view is None:
@@ -326,7 +312,6 @@ class NodeFrame(BaseFrame):
self.__view = window
self.Layout()
-
def __init__(self, node, **kwds):
""" Constructor. Keywords are passed on to wx.Frame.
@@ -376,19 +361,16 @@ class NodeFrame(BaseFrame):
self._incref(node.store)
pub.subscribe(self.on_notification_closefile, 'store.close')
-
def on_notification_closefile(self):
""" Pubsub notification that a file (any file) has been closed """
if not self.node.store.valid:
self.Destroy()
-
def on_close_evt(self, evt):
""" Window is about to be closed """
self._decref(self.node.store)
evt.Skip()
-
def on_menu_closefile(self, evt):
""" "Close File" menu item activated.
diff --git a/compass_viewer/icons/compass_32.png b/hdf_compass/compass_viewer/icons/compass_32.png
similarity index 100%
rename from compass_viewer/icons/compass_32.png
rename to hdf_compass/compass_viewer/icons/compass_32.png
diff --git a/compass_viewer/icons/compass_48.png b/hdf_compass/compass_viewer/icons/compass_48.png
similarity index 100%
rename from compass_viewer/icons/compass_48.png
rename to hdf_compass/compass_viewer/icons/compass_48.png
diff --git a/compass_viewer/icons/go_back_24.png b/hdf_compass/compass_viewer/icons/go_back_24.png
similarity index 100%
rename from compass_viewer/icons/go_back_24.png
rename to hdf_compass/compass_viewer/icons/go_back_24.png
diff --git a/compass_viewer/icons/go_back_32.png b/hdf_compass/compass_viewer/icons/go_back_32.png
similarity index 100%
rename from compass_viewer/icons/go_back_32.png
rename to hdf_compass/compass_viewer/icons/go_back_32.png
diff --git a/compass_viewer/icons/go_next_24.png b/hdf_compass/compass_viewer/icons/go_next_24.png
similarity index 100%
rename from compass_viewer/icons/go_next_24.png
rename to hdf_compass/compass_viewer/icons/go_next_24.png
diff --git a/compass_viewer/icons/go_next_32.png b/hdf_compass/compass_viewer/icons/go_next_32.png
similarity index 100%
rename from compass_viewer/icons/go_next_32.png
rename to hdf_compass/compass_viewer/icons/go_next_32.png
diff --git a/compass_viewer/icons/go_up_24.png b/hdf_compass/compass_viewer/icons/go_up_24.png
similarity index 100%
rename from compass_viewer/icons/go_up_24.png
rename to hdf_compass/compass_viewer/icons/go_up_24.png
diff --git a/compass_viewer/icons/go_up_32.png b/hdf_compass/compass_viewer/icons/go_up_32.png
similarity index 100%
rename from compass_viewer/icons/go_up_32.png
rename to hdf_compass/compass_viewer/icons/go_up_32.png
diff --git a/compass_viewer/icons/license.txt b/hdf_compass/compass_viewer/icons/license.txt
similarity index 100%
rename from compass_viewer/icons/license.txt
rename to hdf_compass/compass_viewer/icons/license.txt
diff --git a/compass_viewer/icons/logo.png b/hdf_compass/compass_viewer/icons/logo.png
similarity index 100%
rename from compass_viewer/icons/logo.png
rename to hdf_compass/compass_viewer/icons/logo.png
diff --git a/compass_viewer/icons/logo.xcf b/hdf_compass/compass_viewer/icons/logo.xcf
similarity index 100%
rename from compass_viewer/icons/logo.xcf
rename to hdf_compass/compass_viewer/icons/logo.xcf
diff --git a/compass_viewer/icons/readme.txt b/hdf_compass/compass_viewer/icons/readme.txt
similarity index 100%
rename from compass_viewer/icons/readme.txt
rename to hdf_compass/compass_viewer/icons/readme.txt
diff --git a/compass_viewer/icons/view_icon_24.png b/hdf_compass/compass_viewer/icons/view_icon_24.png
similarity index 100%
rename from compass_viewer/icons/view_icon_24.png
rename to hdf_compass/compass_viewer/icons/view_icon_24.png
diff --git a/compass_viewer/icons/view_icon_32.png b/hdf_compass/compass_viewer/icons/view_icon_32.png
similarity index 100%
rename from compass_viewer/icons/view_icon_32.png
rename to hdf_compass/compass_viewer/icons/view_icon_32.png
diff --git a/compass_viewer/icons/view_list_24.png b/hdf_compass/compass_viewer/icons/view_list_24.png
similarity index 100%
rename from compass_viewer/icons/view_list_24.png
rename to hdf_compass/compass_viewer/icons/view_list_24.png
diff --git a/compass_viewer/icons/view_list_32.png b/hdf_compass/compass_viewer/icons/view_list_32.png
similarity index 100%
rename from compass_viewer/icons/view_list_32.png
rename to hdf_compass/compass_viewer/icons/view_list_32.png
diff --git a/compass_viewer/icons/view_tree_32.png b/hdf_compass/compass_viewer/icons/view_tree_32.png
similarity index 100%
rename from compass_viewer/icons/view_tree_32.png
rename to hdf_compass/compass_viewer/icons/view_tree_32.png
diff --git a/compass_viewer/icons/viz_plot_24.png b/hdf_compass/compass_viewer/icons/viz_plot_24.png
similarity index 100%
rename from compass_viewer/icons/viz_plot_24.png
rename to hdf_compass/compass_viewer/icons/viz_plot_24.png
diff --git a/compass_viewer/icons/viz_plot_32.png b/hdf_compass/compass_viewer/icons/viz_plot_32.png
similarity index 100%
rename from compass_viewer/icons/viz_plot_32.png
rename to hdf_compass/compass_viewer/icons/viz_plot_32.png
diff --git a/compass_viewer/image/__init__.py b/hdf_compass/compass_viewer/image/__init__.py
similarity index 91%
rename from compass_viewer/image/__init__.py
rename to hdf_compass/compass_viewer/image/__init__.py
index 5c2db1c..f2c422b 100644
--- a/compass_viewer/image/__init__.py
+++ b/hdf_compass/compass_viewer/image/__init__.py
@@ -16,10 +16,11 @@ Implements a simple true-color image viewer.
import wx
import wx.grid
-from wx.lib.newevent import NewCommandEvent
+from wx.lib.newevent import NewCommandEvent # FIXME: Unused?
from ..frame import NodeFrame
+
class ImageFrame(NodeFrame):
"""
@@ -28,7 +29,7 @@ class ImageFrame(NodeFrame):
def __init__(self, node, **kwds):
""" Create a new array viewer, to display *node*. """
- NodeFrame.__init__(self, node, title=node.displayname, size=(800,400), **kwds)
+ NodeFrame.__init__(self, node, title=node.displayname, size=(800, 400), **kwds)
self.node = node
p = ImagePanel(self, node)
@@ -52,7 +53,7 @@ class ImagePanel(wx.Panel):
sb = wx.StaticBitmap(self, wx.ID_ANY, b)
sizer.AddStretchSpacer()
- sizer.Add(sb, 1, wx.EXPAND|wx.ALIGN_CENTER|wx.ALIGN_CENTER_VERTICAL)
+ sizer.Add(sb, 1, wx.EXPAND | wx.ALIGN_CENTER | wx.ALIGN_CENTER_VERTICAL)
sizer.AddStretchSpacer()
sizer2 = wx.BoxSizer(wx.VERTICAL)
@@ -60,4 +61,4 @@ class ImagePanel(wx.Panel):
sizer2.Add(sizer, 1)
sizer2.AddStretchSpacer()
- self.SetSizer(sizer2)
\ No newline at end of file
+ self.SetSizer(sizer2)
diff --git a/compass_viewer/images.py b/hdf_compass/compass_viewer/images.py
similarity index 100%
rename from compass_viewer/images.py
rename to hdf_compass/compass_viewer/images.py
diff --git a/compass_viewer/imagesupport.py b/hdf_compass/compass_viewer/imagesupport.py
similarity index 97%
rename from compass_viewer/imagesupport.py
rename to hdf_compass/compass_viewer/imagesupport.py
index d801cf6..8fe6f9f 100644
--- a/compass_viewer/imagesupport.py
+++ b/hdf_compass/compass_viewer/imagesupport.py
@@ -16,17 +16,21 @@ Small module to handle common image operations.
Images themselves come from the auto-generated "images.py" module.
"""
-import wx
import cStringIO
+
+import wx
+
from . import images
+
def getbitmap(name):
""" Return a wx.Bitmap of the given icon """
png = getattr(images, name)()
return png_to_bitmap(png)
+
def png_to_bitmap(png):
""" Convert a string with raw PNG data to a wx.Bitmap """
stream = cStringIO.StringIO(png)
img = wx.ImageFromStream(stream, wx.BITMAP_TYPE_PNG)
- return img.ConvertToBitmap()
\ No newline at end of file
+ return img.ConvertToBitmap()
diff --git a/compass_viewer/info.py b/hdf_compass/compass_viewer/info.py
similarity index 89%
rename from compass_viewer/info.py
rename to hdf_compass/compass_viewer/info.py
index 1c049ab..9632f46 100644
--- a/compass_viewer/info.py
+++ b/hdf_compass/compass_viewer/info.py
@@ -15,8 +15,8 @@ Defines the left-hand side information panel used to display context info.
"""
import wx
-import compass_model
+from hdf_compass import compass_model
from .imagesupport import png_to_bitmap
from . import platform
@@ -28,7 +28,6 @@ FONTSIZE = 16 if platform.WINDOWS else 18
class InfoPanel(wx.Panel):
-
"""
Panel displaying general information about the selected object.
@@ -43,7 +42,7 @@ class InfoPanel(wx.Panel):
font = wx.Font(FONTSIZE, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL)
# Sidebar title text
- self.nametext = wx.StaticText(self, style=wx.ALIGN_LEFT|wx.ST_ELLIPSIZE_MIDDLE, size=(PANEL_WIDTH-40,30))
+ self.nametext = wx.StaticText(self, style=wx.ALIGN_LEFT | wx.ST_ELLIPSIZE_MIDDLE, size=(PANEL_WIDTH - 40, 30))
self.nametext.SetFont(font)
# Sidebar icon (see display method)
@@ -53,13 +52,12 @@ class InfoPanel(wx.Panel):
self.proptext = wx.StaticText(self, style=wx.ALIGN_LEFT)
self.sizer = sizer = wx.BoxSizer(wx.VERTICAL)
- sizer.Add(self.nametext, 0, wx.LEFT|wx.TOP|wx.RIGHT, border=20)
- sizer.Add(self.proptext, 0, wx.LEFT|wx.RIGHT, border=20)
+ sizer.Add(self.nametext, 0, wx.LEFT | wx.TOP | wx.RIGHT, border=20)
+ sizer.Add(self.proptext, 0, wx.LEFT | wx.RIGHT, border=20)
sizer.AddStretchSpacer(1)
self.SetSizer(sizer)
- self.SetBackgroundColour(wx.Colour(255,255,255))
-
+ self.SetBackgroundColour(wx.Colour(255, 255, 255))
def display(self, node):
""" Update displayed information on the node.
@@ -91,7 +89,7 @@ def describe(node):
if isinstance(node, compass_model.Array):
desc += "Shape\n%s\n\nType\n%s" % \
- (node.shape, dtypetext(node.dtype))
+ (node.shape, dtypetext(node.dtype))
elif isinstance(node, compass_model.Container):
desc += "%d items\n" % len(node)
diff --git a/compass_viewer/keyvalue/__init__.py b/hdf_compass/compass_viewer/keyvalue/__init__.py
similarity index 88%
rename from compass_viewer/keyvalue/__init__.py
rename to hdf_compass/compass_viewer/keyvalue/__init__.py
index 3f50869..6964256 100644
--- a/compass_viewer/keyvalue/__init__.py
+++ b/hdf_compass/compass_viewer/keyvalue/__init__.py
@@ -18,7 +18,6 @@ Presently this means all NumPy types, plus Python str/unicode.
"""
import wx
-import compass_model
from ..frame import NodeFrame
@@ -54,7 +53,7 @@ class KeyValueList(wx.ListCtrl):
node: compass_model.KeyValue instance
"""
- wx.ListCtrl.__init__(self, parent, style=wx.LC_REPORT|wx.LC_SINGLE_SEL|wx.BORDER_NONE|wx.LC_HRULES)
+ wx.ListCtrl.__init__(self, parent, style=wx.LC_REPORT | wx.LC_SINGLE_SEL | wx.BORDER_NONE | wx.LC_HRULES)
self.node = node
@@ -66,36 +65,32 @@ class KeyValueList(wx.ListCtrl):
names = node.keys
values = [self.node[n] for n in names]
- def itemtext(item, col):
+ def itemtext(item, col_id):
name = names[item]
data = values[item]
text = ""
- if col == 0:
+ if col_id == 0:
text = name
- elif col == 1:
+ elif col_id == 1:
text = str(data)
- elif col == 2:
+ elif col_id == 2:
if hasattr(data, 'dtype'):
text = str(data.dtype)
else:
text = str(type(data))
- elif col == 3:
+ elif col_id == 3:
if hasattr(data, 'shape'):
- text = str(data.shape)
+ text = str(data.shape)
else:
text = "()"
return text
for n in names:
row = self.InsertStringItem(9999, n)
- for col in xrange(1,4):
+ for col in xrange(1, 4):
self.SetStringItem(row, col, itemtext(row, col))
self.SetColumnWidth(0, 200)
self.SetColumnWidth(1, wx.LIST_AUTOSIZE)
self.SetColumnWidth(2, wx.LIST_AUTOSIZE)
self.SetColumnWidth(3, wx.LIST_AUTOSIZE)
-
-
-
-
\ No newline at end of file
diff --git a/compass_viewer/platform.py b/hdf_compass/compass_viewer/platform.py
similarity index 98%
rename from compass_viewer/platform.py
rename to hdf_compass/compass_viewer/platform.py
index e815bbc..1411ba8 100644
--- a/compass_viewer/platform.py
+++ b/hdf_compass/compass_viewer/platform.py
@@ -22,4 +22,4 @@ LINUX = sys.platform == 'linux2'
if not any((MAC, WINDOWS, LINUX)):
raise ValueError('Unknown platform "%s"' % sys.platform)
-VERSION = "0.5"
\ No newline at end of file
+VERSION = "0.5"
diff --git a/data/asc/sample.asc b/hdf_compass/data/asc/sample.asc
similarity index 100%
rename from data/asc/sample.asc
rename to hdf_compass/data/asc/sample.asc
diff --git a/data/hdf5/tall.h5 b/hdf_compass/data/hdf5/tall.h5
similarity index 100%
rename from data/hdf5/tall.h5
rename to hdf_compass/data/hdf5/tall.h5
diff --git a/filesystem_model/__init__.py b/hdf_compass/filesystem_model/__init__.py
similarity index 98%
rename from filesystem_model/__init__.py
rename to hdf_compass/filesystem_model/__init__.py
index 8ff5a31..279815b 100644
--- a/filesystem_model/__init__.py
+++ b/hdf_compass/filesystem_model/__init__.py
@@ -19,12 +19,13 @@ directories and files respectively.
import os
import os.path as op
+
import numpy as np
-import compass_model
+from hdf_compass import compass_model
-class Filesystem(compass_model.Store):
+class Filesystem(compass_model.Store):
"""
A "data store" represented by the file system.
@@ -72,7 +73,6 @@ class Filesystem(compass_model.Store):
class Directory(compass_model.Container):
-
"""
Represents a directory in the filesystem.
"""
@@ -124,7 +124,6 @@ class Directory(compass_model.Container):
class File(compass_model.Array):
-
"""
Represents a file (all loaded as an array of bytes)
"""
@@ -172,7 +171,8 @@ class File(compass_model.Array):
return data[args]
+
Filesystem.push(File)
Filesystem.push(Directory)
-compass_model.push(Filesystem)
\ No newline at end of file
+compass_model.push(Filesystem)
diff --git a/hdf_compass/filesystem_model/test.py b/hdf_compass/filesystem_model/test.py
new file mode 100644
index 0000000..abf582c
--- /dev/null
+++ b/hdf_compass/filesystem_model/test.py
@@ -0,0 +1,7 @@
+from hdf_compass.compass_model.test import container, store
+from hdf_compass.filesystem_model import Filesystem, Directory
+
+url = "file://localhost"
+
+s = store(Filesystem, url)
+c = container(Filesystem, url, Directory, "/")
diff --git a/hdf5_model/__init__.py b/hdf_compass/hdf5_model/__init__.py
similarity index 96%
rename from hdf5_model/__init__.py
rename to hdf_compass/hdf5_model/__init__.py
index ead23a4..6963e49 100644
--- a/hdf5_model/__init__.py
+++ b/hdf_compass/hdf5_model/__init__.py
@@ -18,13 +18,11 @@ from itertools import groupby
import sys
import os.path as op
import posixpath as pp
-import numpy as np
+
import h5py
# Py2App can't successfully import otherwise
-from h5py import defs, utils, h5ac, _proxy, _conv
-
-import compass_model
+from hdf_compass import compass_model
def sort_key(name):
@@ -36,7 +34,6 @@ def sort_key(name):
class HDF5Store(compass_model.Store):
-
"""
Data store implementation using an HDF5 file.
@@ -45,31 +42,25 @@ class HDF5Store(compass_model.Store):
file_extensions = {'HDF5 File': ['*.hdf5', '*.h5']}
-
def __contains__(self, key):
return key in self.f
-
@property
def url(self):
return self._url
-
@property
def displayname(self):
return op.basename(self.f.filename)
-
@property
def root(self):
return self['/']
-
@property
def valid(self):
return bool(self.f)
-
@staticmethod
def canhandle(url):
if not url.startswith('file://'):
@@ -82,7 +73,6 @@ class HDF5Store(compass_model.Store):
return False
return True
-
def __init__(self, url):
if not self.canhandle(url):
raise ValueError(url)
@@ -92,14 +82,13 @@ class HDF5Store(compass_model.Store):
else:
path = url.replace('file://', '')
self.f = h5py.File(path, 'r')
-
+
def close(self):
self.f.close()
-
def getparent(self, key):
# HDFCompass requires the parent of the root container be None
- if key == "" or key == "/":
+ if key == "" or key == "/":
return None
pkey = pp.dirname(key)
if pkey == "":
@@ -107,21 +96,17 @@ class HDF5Store(compass_model.Store):
return self[pkey]
-
class HDF5Group(compass_model.Container):
-
"""
Represents an HDF5 group, to be displayed in the browser view.
"""
classkind = "HDF5 Group"
-
@staticmethod
def canhandle(store, key):
return key in store and isinstance(store.f[key], h5py.Group)
-
@property
def _names(self):
@@ -136,24 +121,20 @@ class HDF5Group(compass_model.Container):
return self._xnames
-
def __init__(self, store, key):
self._store = store
self._key = key
self._group = store.f[key]
self._xnames = None
-
@property
def key(self):
return self._key
-
@property
def store(self):
return self._store
-
@property
def displayname(self):
name = pp.basename(self.key)
@@ -161,25 +142,20 @@ class HDF5Group(compass_model.Container):
name = '/'
return name
-
@property
def displaytitle(self):
return "%s %s" % (self.store.displayname, self.key)
-
@property
def description(self):
return 'Group "%s" (%d members)' % (self.displayname, len(self))
-
def __len__(self):
return len(self._group)
-
def __iter__(self):
for name in self._names:
- yield self.store[pp.join(self.key,name)]
-
+ yield self.store[pp.join(self.key, name)]
def __getitem__(self, idx):
name = self._names[idx]
@@ -187,119 +163,98 @@ class HDF5Group(compass_model.Container):
class HDF5Dataset(compass_model.Array):
-
"""
Represents an HDF5 dataset.
"""
classkind = "HDF5 Dataset"
-
@staticmethod
def canhandle(store, key):
return key in store and isinstance(store.f[key], h5py.Dataset)
-
def __init__(self, store, key):
self._store = store
self._key = key
self._dset = store.f[key]
-
@property
def key(self):
return self._key
-
@property
def store(self):
return self._store
-
@property
def displayname(self):
return pp.basename(self.key)
-
@property
def description(self):
return 'Dataset "%s"' % (self.displayname,)
-
@property
def shape(self):
return self._dset.shape
-
@property
def dtype(self):
return self._dset.dtype
-
def __getitem__(self, args):
return self._dset[args]
class HDF5KV(compass_model.KeyValue):
-
"""
A KeyValue node used for HDF5 attributes.
"""
classkind = "HDF5 Attributes"
-
@staticmethod
def canhandle(store, key):
return key in store.f
-
def __init__(self, store, key):
self._store = store
self._key = key
self._obj = store.f[key]
self._names = self._obj.attrs.keys()
-
@property
def key(self):
return self._key
-
@property
def store(self):
return self._store
-
@property
def displayname(self):
n = pp.basename(self.key)
return n if n != '' else '/'
-
@property
def description(self):
return self.displayname
-
@property
def keys(self):
return self._names[:]
-
def __getitem__(self, name):
return self._obj.attrs[name]
class HDF5Image(compass_model.Image):
-
"""
True-color images.
"""
classkind = "HDF5 Truecolor Image"
-
@staticmethod
def canhandle(store, key):
if key not in store:
@@ -313,49 +268,40 @@ class HDF5Image(compass_model.Image):
return False
return True
-
def __init__(self, store, key):
self._store = store
self._key = key
self._obj = store.f[key]
-
@property
def key(self):
return self._key
-
@property
def store(self):
return self._store
-
@property
def displayname(self):
n = pp.basename(self.key)
return n if n != '' else '/'
-
@property
def description(self):
return self.displayname
-
@property
def width(self):
return self._obj.shape[1]
-
@property
def height(self):
return self._obj.shape[0]
-
@property
def palette(self):
return None
-
@property
def data(self):
return self._obj[:]
@@ -367,4 +313,4 @@ HDF5Store.push(HDF5Dataset)
HDF5Store.push(HDF5Group)
HDF5Store.push(HDF5Image)
-compass_model.push(HDF5Store)
\ No newline at end of file
+compass_model.push(HDF5Store)
diff --git a/hdf_compass/hdf5_model/test.py b/hdf_compass/hdf5_model/test.py
new file mode 100644
index 0000000..a6af0eb
--- /dev/null
+++ b/hdf_compass/hdf5_model/test.py
@@ -0,0 +1,23 @@
+from hdf_compass.compass_model.test import container, store
+from hdf_compass.hdf5_model import HDF5Group, HDF5Store
+
+import os
+import sys
+
+import hdf_compass
+
+# locate test file
+data_folder = os.path.abspath(os.path.join(os.path.dirname(hdf_compass.__file__), 'data'))
+test_file = os.path.join(data_folder, 'hdf5', 'tall.h5')
+if not os.path.exists(test_file):
+ raise RuntimeError("Unable to locate test file: %s" % test_file)
+
+# create url
+if sys.platform == 'win32':
+ url = 'file:///' + os.path.abspath(test_file)
+else:
+ url = 'file://' + os.path.abspath(test_file)
+
+s = store(HDF5Store, url)
+c = container(HDF5Store, url, HDF5Group, "/")
+
diff --git a/opendap_model/__init__.py b/hdf_compass/opendap_model/__init__.py
similarity index 99%
rename from opendap_model/__init__.py
rename to hdf_compass/opendap_model/__init__.py
index b9a47b8..f32a814 100644
--- a/opendap_model/__init__.py
+++ b/hdf_compass/opendap_model/__init__.py
@@ -9,13 +9,14 @@
# distribution tree. If you do not have access to this file, you may #
# request a copy from help at hdfgroup.org. #
##############################################################################
-import numpy as np
import posixpath as pp
+
+import numpy as np
import pydap as dap
from pydap.client import open_url
from pydap.proxy import ArrayProxy
-import compass_model
+from hdf_compass import compass_model
def check_key(key, dataset):
@@ -26,10 +27,10 @@ def check_key(key, dataset):
class Server(compass_model.Store):
-
"""
Represents the remote OpENDAP server to be accessed
"""
+
def __contains__(self, key):
if '/' not in key:
return key in self.dataset
@@ -87,7 +88,6 @@ class Server(compass_model.Store):
class Dataset(compass_model.Container):
-
"""
Represents Dataset/DatasetType Object in OpENDAP/Pydap.
"""
@@ -138,7 +138,6 @@ class Dataset(compass_model.Container):
class Structure(compass_model.Container):
-
"""
Represents Structure/StructureType Object in OpENDAP/Pydap.
"""
@@ -189,7 +188,6 @@ class Structure(compass_model.Container):
class Base(compass_model.Array):
-
"""
Represents Array/BaseType Object in OpENDAP/Pydap.
"""
--
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