summaryrefslogtreecommitdiff
path: root/silx/gui/data
diff options
context:
space:
mode:
Diffstat (limited to 'silx/gui/data')
-rw-r--r--silx/gui/data/DataViews.py2
-rw-r--r--silx/gui/data/Hdf5TableView.py68
-rw-r--r--silx/gui/data/NXdataWidgets.py1
-rw-r--r--silx/gui/data/TextFormatter.py8
-rw-r--r--silx/gui/data/test/test_dataviewer.py8
-rw-r--r--silx/gui/data/test/test_textformatter.py28
6 files changed, 88 insertions, 27 deletions
diff --git a/silx/gui/data/DataViews.py b/silx/gui/data/DataViews.py
index f3b02b9..d9958de 100644
--- a/silx/gui/data/DataViews.py
+++ b/silx/gui/data/DataViews.py
@@ -406,7 +406,7 @@ class DataView(object):
:param NamedTuple selection: Data selected
:rtype: str
"""
- if selection is None:
+ if selection is None or selection.filename is None:
return None
else:
directory, filename = os.path.split(selection.filename)
diff --git a/silx/gui/data/Hdf5TableView.py b/silx/gui/data/Hdf5TableView.py
index 57d6f7b..7749326 100644
--- a/silx/gui/data/Hdf5TableView.py
+++ b/silx/gui/data/Hdf5TableView.py
@@ -380,37 +380,87 @@ class Hdf5TableModel(HierarchicalTableView.HierarchicalTableModel):
SEPARATOR = "::"
self.__data.addHeaderRow(headerLabel="Path info")
+ showPhysicalLocation = True
if isinstance(obj, silx.gui.hdf5.H5Node):
# helpful informations if the object come from an HDF5 tree
self.__data.addHeaderValueRow("Basename", lambda x: x.local_basename)
self.__data.addHeaderValueRow("Name", lambda x: x.local_name)
local = lambda x: x.local_filename + SEPARATOR + x.local_name
self.__data.addHeaderValueRow("Local", local)
- physical = lambda x: x.physical_filename + SEPARATOR + x.physical_name
- self.__data.addHeaderValueRow("Physical", physical)
else:
# it's a real H5py object
self.__data.addHeaderValueRow("Basename", lambda x: os.path.basename(x.name))
self.__data.addHeaderValueRow("Name", lambda x: x.name)
if obj.file is not None:
self.__data.addHeaderValueRow("File", lambda x: x.file.filename)
-
if hasattr(obj, "path"):
# That's a link
if hasattr(obj, "filename"):
+ # External link
link = lambda x: x.filename + SEPARATOR + x.path
else:
+ # Soft link
link = lambda x: x.path
self.__data.addHeaderValueRow("Link", link)
- else:
- if silx.io.is_file(obj):
- physical = lambda x: x.filename + SEPARATOR + x.name
+ showPhysicalLocation = False
+
+ # External data (nothing to do with external links)
+ nExtSources = 0
+ firstExtSource = None
+ extType = None
+ if silx.io.is_dataset(hdf5obj):
+ if hasattr(hdf5obj, "is_virtual"):
+ if hdf5obj.is_virtual:
+ extSources = hdf5obj.virtual_sources()
+ if extSources:
+ firstExtSource = extSources[0].file_name + SEPARATOR + extSources[0].dset_name
+ extType = "Virtual"
+ nExtSources = len(extSources)
+ if hasattr(hdf5obj, "external"):
+ extSources = hdf5obj.external
+ if extSources:
+ firstExtSource = extSources[0][0]
+ extType = "Raw"
+ nExtSources = len(extSources)
+
+ if showPhysicalLocation:
+ def _physical_location(x):
+ if isinstance(obj, silx.gui.hdf5.H5Node):
+ return x.physical_filename + SEPARATOR + x.physical_name
+ elif silx.io.is_file(obj):
+ return x.filename + SEPARATOR + x.name
elif obj.file is not None:
- physical = lambda x: x.file.filename + SEPARATOR + x.name
+ return x.file.filename + SEPARATOR + x.name
else:
# Guess it is a virtual node
- physical = "No physical location"
- self.__data.addHeaderValueRow("Physical", physical)
+ return "No physical location"
+
+ self.__data.addHeaderValueRow("Physical", _physical_location)
+
+ if extType:
+ def _first_source(x):
+ # Absolute path
+ if os.path.isabs(firstExtSource):
+ return firstExtSource
+
+ # Relative path with respect to the file directory
+ if isinstance(obj, silx.gui.hdf5.H5Node):
+ filename = x.physical_filename
+ elif silx.io.is_file(obj):
+ filename = x.filename
+ elif obj.file is not None:
+ filename = x.file.filename
+ else:
+ return firstExtSource
+
+ if firstExtSource[0] == ".":
+ firstExtSource.pop(0)
+ return os.path.join(os.path.dirname(filename), firstExtSource)
+
+ self.__data.addHeaderRow(headerLabel="External sources")
+ self.__data.addHeaderValueRow("Type", extType)
+ self.__data.addHeaderValueRow("Count", str(nExtSources))
+ self.__data.addHeaderValueRow("First", _first_source)
if hasattr(obj, "dtype"):
diff --git a/silx/gui/data/NXdataWidgets.py b/silx/gui/data/NXdataWidgets.py
index 224f337..271b267 100644
--- a/silx/gui/data/NXdataWidgets.py
+++ b/silx/gui/data/NXdataWidgets.py
@@ -370,6 +370,7 @@ class ArrayImagePlot(qt.QWidget):
vmin=None, vmax=None,
normalization=Colormap.LINEAR))
self._plot.getIntensityHistogramAction().setVisible(True)
+ self._plot.setKeepDataAspectRatio(True)
# not closable
self._selector = NumpyAxesSelector(self)
diff --git a/silx/gui/data/TextFormatter.py b/silx/gui/data/TextFormatter.py
index 98c37d7..8fd7c7c 100644
--- a/silx/gui/data/TextFormatter.py
+++ b/silx/gui/data/TextFormatter.py
@@ -267,6 +267,12 @@ class TextFormatter(qt.QObject):
if vlen is not None:
if vlen == six.text_type:
# HDF5 UTF8
+ # With h5py>=3 reading dataset returns bytes
+ if isinstance(data, (bytes, numpy.bytes_)):
+ try:
+ data = data.decode("utf-8")
+ except UnicodeDecodeError:
+ self.__formatSafeAscii(data)
return self.__formatText(data)
elif vlen == six.binary_type:
# HDF5 ASCII
@@ -289,7 +295,7 @@ class TextFormatter(qt.QObject):
elif isinstance(data, list):
text = [self.toString(d) for d in data]
return "[" + " ".join(text) + "]"
- elif isinstance(data, (numpy.ndarray)):
+ elif isinstance(data, numpy.ndarray):
if dtype is None:
dtype = data.dtype
if data.shape == ():
diff --git a/silx/gui/data/test/test_dataviewer.py b/silx/gui/data/test/test_dataviewer.py
index 12a640e..dd01dd6 100644
--- a/silx/gui/data/test/test_dataviewer.py
+++ b/silx/gui/data/test/test_dataviewer.py
@@ -1,7 +1,7 @@
# coding: utf-8
# /*##########################################################################
#
-# Copyright (c) 2016-2019 European Synchrotron Radiation Facility
+# Copyright (c) 2016-2020 European Synchrotron Radiation Facility
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
@@ -108,7 +108,7 @@ class AbstractDataViewerTests(TestCaseQt):
self.assertIn(DataViews.IMAGE_MODE, availableModes)
def test_image_bool(self):
- data = numpy.zeros((10, 10), dtype=numpy.bool)
+ data = numpy.zeros((10, 10), dtype=bool)
data[::2, ::2] = True
widget = self.create_widget()
widget.setData(data)
@@ -117,7 +117,7 @@ class AbstractDataViewerTests(TestCaseQt):
self.assertIn(DataViews.IMAGE_MODE, availableModes)
def test_image_complex_data(self):
- data = numpy.arange(3 ** 2, dtype=numpy.complex)
+ data = numpy.arange(3 ** 2, dtype=numpy.complex64)
data.shape = [3] * 2
widget = self.create_widget()
widget.setData(data)
@@ -262,7 +262,7 @@ class TestDataView(TestCaseQt):
line = [1, 2j, 3 + 3j, 4]
image = [line, line, line, line]
cube = [image, image, image, image]
- data = numpy.array(cube, dtype=numpy.complex)
+ data = numpy.array(cube, dtype=numpy.complex64)
return data
def createDataViewWithData(self, dataViewClass, data):
diff --git a/silx/gui/data/test/test_textformatter.py b/silx/gui/data/test/test_textformatter.py
index 1a63074..d3050bf 100644
--- a/silx/gui/data/test/test_textformatter.py
+++ b/silx/gui/data/test/test_textformatter.py
@@ -36,6 +36,7 @@ import six
from silx.gui.utils.testutils import TestCaseQt
from silx.gui.utils.testutils import SignalListener
from ..TextFormatter import TextFormatter
+from silx.io.utils import h5py_read_dataset
import h5py
@@ -123,76 +124,79 @@ class TestTextFormatterWithH5py(TestCaseQt):
dataset = self.h5File.create_dataset(testName, data=data, dtype=dtype)
return dataset
+ def read_dataset(self, d):
+ return self.formatter.toString(d[()], dtype=d.dtype)
+
def testAscii(self):
d = self.create_dataset(data=b"abc")
- result = self.formatter.toString(d[()], dtype=d.dtype)
+ result = self.read_dataset(d)
self.assertEqual(result, '"abc"')
def testUnicode(self):
d = self.create_dataset(data=u"i\u2661cookies")
- result = self.formatter.toString(d[()], dtype=d.dtype)
+ result = self.read_dataset(d)
self.assertEqual(len(result), 11)
self.assertEqual(result, u'"i\u2661cookies"')
def testBadAscii(self):
d = self.create_dataset(data=b"\xF0\x9F\x92\x94")
- result = self.formatter.toString(d[()], dtype=d.dtype)
+ result = self.read_dataset(d)
self.assertEqual(result, 'b"\\xF0\\x9F\\x92\\x94"')
def testVoid(self):
d = self.create_dataset(data=numpy.void(b"abc\xF0"))
- result = self.formatter.toString(d[()], dtype=d.dtype)
+ result = self.read_dataset(d)
self.assertEqual(result, 'b"\\x61\\x62\\x63\\xF0"')
def testEnum(self):
dtype = h5py.special_dtype(enum=('i', {"RED": 0, "GREEN": 1, "BLUE": 42}))
d = numpy.array(42, dtype=dtype)
d = self.create_dataset(data=d)
- result = self.formatter.toString(d[()], dtype=d.dtype)
+ result = self.read_dataset(d)
self.assertEqual(result, 'BLUE(42)')
def testRef(self):
dtype = h5py.special_dtype(ref=h5py.Reference)
d = numpy.array(self.h5File.ref, dtype=dtype)
d = self.create_dataset(data=d)
- result = self.formatter.toString(d[()], dtype=d.dtype)
+ result = self.read_dataset(d)
self.assertEqual(result, 'REF')
def testArrayAscii(self):
d = self.create_dataset(data=[b"abc"])
- result = self.formatter.toString(d[()], dtype=d.dtype)
+ result = self.read_dataset(d)
self.assertEqual(result, '["abc"]')
def testArrayUnicode(self):
dtype = h5py.special_dtype(vlen=six.text_type)
d = numpy.array([u"i\u2661cookies"], dtype=dtype)
d = self.create_dataset(data=d)
- result = self.formatter.toString(d[()], dtype=d.dtype)
+ result = self.read_dataset(d)
self.assertEqual(len(result), 13)
self.assertEqual(result, u'["i\u2661cookies"]')
def testArrayBadAscii(self):
d = self.create_dataset(data=[b"\xF0\x9F\x92\x94"])
- result = self.formatter.toString(d[()], dtype=d.dtype)
+ result = self.read_dataset(d)
self.assertEqual(result, '[b"\\xF0\\x9F\\x92\\x94"]')
def testArrayVoid(self):
d = self.create_dataset(data=numpy.void([b"abc\xF0"]))
- result = self.formatter.toString(d[()], dtype=d.dtype)
+ result = self.read_dataset(d)
self.assertEqual(result, '[b"\\x61\\x62\\x63\\xF0"]')
def testArrayEnum(self):
dtype = h5py.special_dtype(enum=('i', {"RED": 0, "GREEN": 1, "BLUE": 42}))
d = numpy.array([42, 1, 100], dtype=dtype)
d = self.create_dataset(data=d)
- result = self.formatter.toString(d[()], dtype=d.dtype)
+ result = self.read_dataset(d)
self.assertEqual(result, '[BLUE(42) GREEN(1) 100]')
def testArrayRef(self):
dtype = h5py.special_dtype(ref=h5py.Reference)
d = numpy.array([self.h5File.ref, None], dtype=dtype)
d = self.create_dataset(data=d)
- result = self.formatter.toString(d[()], dtype=d.dtype)
+ result = self.read_dataset(d)
self.assertEqual(result, '[REF NULL_REF]')