[hdf-compass] 190/295: Add is_plottable method for Array node and disabling for string
Ghislain Vaillant
ghisvail-guest at moszumanska.debian.org
Sun May 8 10:35:43 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 f517190ab7c28a78682b80cc7ec62108d79ee228
Author: giumas <giumas at yahoo.it>
Date: Mon Oct 26 20:39:08 2015 -0400
Add is_plottable method for Array node and disabling for string
---
hdf_compass/array_model/model.py | 15 +++++++++--
hdf_compass/bag_model/model.py | 21 +++++++++++++--
hdf_compass/compass_model/model.py | 7 +++--
hdf_compass/compass_viewer/array/frame.py | 45 ++++++++++++++++++-------------
hdf_compass/compass_viewer/frame.py | 16 ++++-------
hdf_compass/compass_viewer/info.py | 39 +++++++++++++++------------
hdf_compass/hdf5_model/model.py | 9 +++++++
hdf_compass/opendap_model/model.py | 9 +++++++
8 files changed, 108 insertions(+), 53 deletions(-)
diff --git a/hdf_compass/array_model/model.py b/hdf_compass/array_model/model.py
index 8e5fd7e..fbc56ac 100644
--- a/hdf_compass/array_model/model.py
+++ b/hdf_compass/array_model/model.py
@@ -34,8 +34,10 @@ DATA = {'array://localhost/a_0d': np.array(1),
'array://localhost/cmp_2d': np.ones((10, 10), dtype=DT_CMP),
'array://localhost/cmp_3d': np.ones((10, 10, 10), dtype=DT_CMP),
'array://localhost/cmp_4d': np.ones((10, 10, 10, 10), dtype=DT_CMP),
- 'array://localhost/s_0d': np.array("Hello"),
- 'array://localhost/s_1d': np.array(("Hello",)),
+ 'array://localhost/S_0d': np.array(b"Hello"),
+ 'array://localhost/S_1d': np.array((b"Hello",)),
+ 'array://localhost/U_0d': np.array("Hello"),
+ 'array://localhost/U_1d': np.array(("Hello",)),
'array://localhost/v_0d': np.array('\x01', dtype='|V1'),
'array://localhost/non_square': np.arange(5 * 10).reshape((5, 10)),
}
@@ -178,6 +180,15 @@ class Array(compass_model.Array):
def __getitem__(self, args):
return self.data[args]
+ def is_plottable(self):
+ if self.dtype.kind == 'S':
+ log.debug("Not plottable since ASCII String (characters: %d)" % self.dtype.itemsize)
+ return False
+ if self.dtype.kind == 'U':
+ log.debug("Not plottable since Unicode String (characters: %d)" % self.dtype.itemsize)
+ return False
+ return True
+
class ArrayKV(compass_model.KeyValue):
class_kind = "Array Key/Value Attrs"
diff --git a/hdf_compass/bag_model/model.py b/hdf_compass/bag_model/model.py
index ba558e1..707c97f 100644
--- a/hdf_compass/bag_model/model.py
+++ b/hdf_compass/bag_model/model.py
@@ -264,6 +264,15 @@ class BAGDataset(compass_model.Array):
def __getitem__(self, args):
return self._dset[args]
+ def is_plottable(self):
+ if self.dtype.kind == 'S':
+ log.debug("Not plottable since ASCII String (characters: %d)" % self.dtype.itemsize)
+ return False
+ if self.dtype.kind == 'U':
+ log.debug("Not plottable since Unicode String (characters: %d)" % self.dtype.itemsize)
+ return False
+ return True
+
class BAGElevation(compass_model.Array):
""" Represents a BAG elevation. """
@@ -387,6 +396,15 @@ class BAGMetadataRaw(compass_model.Array):
def __getitem__(self, args):
return self._dset[args]
+ def is_plottable(self):
+ if self.dtype.kind == 'S':
+ log.debug("Not plottable since ASCII String (characters: %d)" % self.dtype.itemsize)
+ return False
+ if self.dtype.kind == 'U':
+ log.debug("Not plottable since Unicode String (characters: %d)" % self.dtype.itemsize)
+ return False
+ return True
+
class BAGMetadataText(compass_model.Text):
""" Represents a text BAG metadata. """
@@ -436,8 +454,7 @@ class BAGMetadataXml(compass_model.Xml):
def can_handle(store, key):
return (key == "/BAG_root/metadata") and (key in store) and (isinstance(store.f[key], h5py.Dataset))
- @staticmethod
- def has_validation():
+ def has_validation(self):
"""For BAG data there is a known validation mechanism based on XSD and Schematron"""
return True
diff --git a/hdf_compass/compass_model/model.py b/hdf_compass/compass_model/model.py
index bd50b62..c57f223 100644
--- a/hdf_compass/compass_model/model.py
+++ b/hdf_compass/compass_model/model.py
@@ -374,6 +374,10 @@ class Array(Node):
""" Retrieve data elements """
raise NotImplementedError
+ def is_plottable(self):
+ """ To be overriden in case that there are cases in which the array is not plottable """
+ return True
+
class Image(Node):
"""
@@ -426,8 +430,7 @@ class Xml(Text):
icons = {16: os.path.join(icon_folder, "xml_16.png"),
64: os.path.join(icon_folder, "xml_64.png")}
- @staticmethod
- def has_validation():
+ def has_validation(self):
"""To be overriden in case that the xml has a known mechanism to be validated"""
return False
diff --git a/hdf_compass/compass_viewer/array/frame.py b/hdf_compass/compass_viewer/array/frame.py
index 8e18765..889c17e 100644
--- a/hdf_compass/compass_viewer/array/frame.py
+++ b/hdf_compass/compass_viewer/array/frame.py
@@ -21,6 +21,8 @@ from wx.lib.newevent import NewCommandEvent
import os
import logging
+log = logging.getLogger(__name__)
+
from ..frame import NodeFrame
from .plot import LinePlotFrame, ContourPlotFrame
@@ -45,29 +47,32 @@ class ArrayFrame(NodeFrame):
"""
def __init__(self, node, pos=None):
- """ Create a new array viewer, to display *node*. """
+ """ Create a new array viewer to display the node. """
NodeFrame.__init__(self, node, size=(800, 400), title=node.display_name, pos=pos)
self.node = node
- # The Slicer is the panel with indexing controls
- self.slicer = SlicerPanel(self, node.shape, node.dtype.fields is not None)
- self.grid = ArrayGrid(self, node, self.slicer)
-
+ # Update the menu
vis_menu = wx.Menu()
- vis_menu.Append(ID_VIS_MENU_PLOT, "Plot Data\tCtrl-D")
- self.add_menu(vis_menu, "Visualize")
-
+ if self.node.is_plottable():
+ vis_menu.Append(ID_VIS_MENU_PLOT, "Plot Data\tCtrl-D")
+ self.add_menu(vis_menu, "Visualize")
+ # Initialize the toolbar
self.init_toolbar()
+ # The Slicer is the panel with indexing controls
+ self.slicer = SlicerPanel(self, node.shape, node.dtype.fields is not None)
+ # Create the grid array
+ self.grid = ArrayGrid(self, node, self.slicer)
+ # Sizer for slicer and grid
gridsizer = wx.BoxSizer(wx.VERTICAL)
gridsizer.Add(self.slicer, 0, wx.EXPAND)
gridsizer.Add(self.grid, 1, wx.EXPAND)
-
self.view = gridsizer
self.Bind(EVT_ARRAY_SLICED, self.on_sliced)
- self.Bind(wx.EVT_MENU, self.on_plot, id=ID_VIS_MENU_PLOT)
+ if self.node.is_plottable():
+ self.Bind(wx.EVT_MENU, self.on_plot, id=ID_VIS_MENU_PLOT)
# Workaround for wxPython bug (see SlicerPanel.enable_spinctrls)
ID_WORKAROUND_TIMER = wx.NewId()
@@ -75,22 +80,19 @@ 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)
+ t_size = (24, 24)
plot_bmp = wx.Bitmap(os.path.join(self.icon_folder, "viz_plot_24.png"), wx.BITMAP_TYPE_ANY)
self.toolbar = self.CreateToolBar(wx.TB_HORIZONTAL | wx.NO_BORDER | wx.TB_FLAT | wx.TB_TEXT)
- self.toolbar.SetToolBitmapSize(tsize)
+ self.toolbar.SetToolBitmapSize(t_size)
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'")
+ if self.node.is_plottable():
+ self.toolbar.AddLabelTool(ID_VIS_MENU_PLOT, "Plot Data", plot_bmp,
+ shortHelp="Plot data in a popup window",
+ longHelp="Plot the array data in a popup window")
self.toolbar.Realize()
def on_sliced(self, evt):
@@ -162,6 +164,11 @@ class ArrayFrame(NodeFrame):
f = ContourPlotFrame(data)
f.Show()
+ def on_workaround_timer(self, evt):
+ """ See slicer.enable_spinctrls docs """
+ self.timer.Destroy()
+ self.slicer.enable_spinctrls()
+
class SlicerPanel(wx.Panel):
"""
diff --git a/hdf_compass/compass_viewer/frame.py b/hdf_compass/compass_viewer/frame.py
index 8ce16de..986feb7 100644
--- a/hdf_compass/compass_viewer/frame.py
+++ b/hdf_compass/compass_viewer/frame.py
@@ -221,9 +221,7 @@ class BaseFrame(wx.Frame):
class InitFrame(BaseFrame):
-
- """
- Frame displayed when the application starts up.
+ """ Frame displayed when the application starts up.
This includes the menu bar provided by TopFrame. On the Mac, although it
still exists (to prevent the application from exiting), the frame
@@ -233,7 +231,7 @@ class InitFrame(BaseFrame):
def __init__(self):
style = wx.DEFAULT_FRAME_STYLE & (~wx.RESIZE_BORDER) & (~wx.MAXIMIZE_BOX)
- title = "HDFCompass"
+ title = "HDF Compass"
BaseFrame.__init__(self, size=(552,247), title=title, style=style)
data = wx.Bitmap(os.path.join(self.icon_folder, "logo.png"), wx.BITMAP_TYPE_ANY)
@@ -249,9 +247,7 @@ class InitFrame(BaseFrame):
class NodeFrame(BaseFrame):
-
- """
- Base class for any frame which displays a Node instance.
+ """ Base class for any frame which displays a Node instance.
Provides a "Close file" menu item and manages open data stores.
@@ -299,8 +295,7 @@ class NodeFrame(BaseFrame):
@classmethod
def _close(cls, store):
- """ Manually close the store, and broadcast a pubsub notification.
- """
+ """ Manually close the store, and broadcast a pubsub notification. """
cls._stores.pop(store, None)
store.close()
pub.sendMessage('store.close')
@@ -309,8 +304,7 @@ class NodeFrame(BaseFrame):
@property
def info(self):
- """ The InfoPanel object used for the left-hand sidebar.
- """
+ """ The InfoPanel object used for the left-hand sidebar. """
return self.__info
@property
diff --git a/hdf_compass/compass_viewer/info.py b/hdf_compass/compass_viewer/info.py
index 91a9086..72ccc37 100644
--- a/hdf_compass/compass_viewer/info.py
+++ b/hdf_compass/compass_viewer/info.py
@@ -46,18 +46,18 @@ 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.SetFont(font)
+ self.name_text = wx.StaticText(self, style=wx.ALIGN_LEFT | wx.ST_ELLIPSIZE_MIDDLE, size=(PANEL_WIDTH - 40, 30))
+ self.name_text.SetFont(font)
# Sidebar icon (see display method)
- self.staticbitmap = None
+ self.static_bitmap = None
# Descriptive text below the icon
- self.proptext = wx.StaticText(self, style=wx.ALIGN_LEFT)
+ self.prop_text = 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.name_text, 0, wx.LEFT | wx.TOP | wx.RIGHT, border=20)
+ sizer.Add(self.prop_text, 0, wx.LEFT | wx.RIGHT, border=20)
sizer.AddStretchSpacer(1)
self.SetSizer(sizer)
@@ -69,29 +69,28 @@ class InfoPanel(wx.Panel):
See the get* methods for specifics on what's displayed.
"""
- self.nametext.SetLabel(node.display_name)
- self.proptext.SetLabel(describe(node))
+ self.name_text.SetLabel(node.display_name)
+ self.prop_text.SetLabel(describe(node))
- if self.staticbitmap is not None:
- self.sizer.Remove(self.staticbitmap)
- self.staticbitmap.Destroy()
+ if self.static_bitmap is not None:
+ self.sizer.Remove(self.static_bitmap)
+ self.static_bitmap.Destroy()
# We load the PNG icon directly from the appropriate Node class
png = wx.Bitmap(type(node).icons[64], wx.BITMAP_TYPE_ANY)
- self.staticbitmap = wx.StaticBitmap(self, wx.ID_ANY, png)
- self.sizer.Insert(1, self.staticbitmap, 0, wx.ALL, border=20)
+ self.static_bitmap = wx.StaticBitmap(self, wx.ID_ANY, png)
+ self.sizer.Insert(1, self.static_bitmap, 0, wx.ALL, border=20)
self.sizer.Layout()
self.Layout()
def describe(node):
- """ Return a (possibly multi-line) text description of a node.
- """
+ """ Return a (possibly multi-line) text description of a node. """
desc = "%s\n\n" % type(node).class_kind
if isinstance(node, compass_model.Array):
desc += "Shape\n%s\n\nType\n%s" % \
- (node.shape, dtypetext(node.dtype))
+ (node.shape, dtype_text(node.dtype))
elif isinstance(node, compass_model.Container):
desc += "%d items\n" % len(node)
@@ -99,9 +98,13 @@ def describe(node):
return desc
-def dtypetext(dt):
+def dtype_text(dt):
""" String description appropriate for a NumPy dtype """
+
+ log.debug("dtype kind: %s, size: %d" % (dt.kind, dt.itemsize))
+
if dt.names is not None:
+ log.debug("dtype names: %s" % ",".join(n for n in dt.names))
return "Compound (%d fields)" % len(dt.names)
if dt.kind == 'f':
return "%d-byte floating point" % dt.itemsize
@@ -111,4 +114,6 @@ def dtypetext(dt):
return "%d-byte signed integer" % dt.itemsize
if dt.kind == 'S':
return "ASCII String (%d characters)" % dt.itemsize
+ if dt.kind == 'U':
+ return "Unicode String (%d characters)" % dt.itemsize
return "Unknown"
diff --git a/hdf_compass/hdf5_model/model.py b/hdf_compass/hdf5_model/model.py
index 6f9f73f..0e5e5c6 100644
--- a/hdf_compass/hdf5_model/model.py
+++ b/hdf_compass/hdf5_model/model.py
@@ -208,6 +208,15 @@ class HDF5Dataset(compass_model.Array):
def __getitem__(self, args):
return self._dset[args]
+ def is_plottable(self):
+ if self.dtype.kind == 'S':
+ log.debug("Not plottable since ASCII String (characters: %d)" % self.dtype.itemsize)
+ return False
+ if self.dtype.kind == 'U':
+ log.debug("Not plottable since Unicode String (characters: %d)" % self.dtype.itemsize)
+ return False
+ return True
+
class HDF5KV(compass_model.KeyValue):
"""
diff --git a/hdf_compass/opendap_model/model.py b/hdf_compass/opendap_model/model.py
index d7f7158..e169237 100644
--- a/hdf_compass/opendap_model/model.py
+++ b/hdf_compass/opendap_model/model.py
@@ -251,6 +251,15 @@ class Base(compass_model.Array):
def description(self):
return "A Pydap BaseType Object."
+ def is_plottable(self):
+ if self.dtype.kind == 'S':
+ log.debug("Not plottable since ASCII String (characters: %d)" % self.dtype.itemsize)
+ return False
+ if self.dtype.kind == 'U':
+ log.debug("Not plottable since Unicode String (characters: %d)" % self.dtype.itemsize)
+ return False
+ return True
+
class Attributes(compass_model.KeyValue):
"""
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/hdf-compass.git
More information about the debian-science-commits
mailing list