Skip to content

Commit

Permalink
Merge pull request #407 from vasole/warnings
Browse files Browse the repository at this point in the history
Reduce the amount of warnings
  • Loading branch information
vasole authored Jan 7, 2019
2 parents ed55266 + a9b7bbd commit cdaebcd
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 36 deletions.
16 changes: 8 additions & 8 deletions PyMca5/PyMcaCore/NexusDataSource.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#
# The PyMca X-Ray Fluorescence Toolkit
#
# Copyright (c) 2004-2018 European Synchrotron Radiation Facility
# Copyright (c) 2004-2019 European Synchrotron Radiation Facility
#
# This file is part of the PyMca X-ray Fluorescence Toolkit developed at
# the ESRF by the Software group.
Expand Down Expand Up @@ -77,7 +77,7 @@ def h5py_sorting(object_list):

try:
if sorting_key != 'name':
sorting_list = [(o[sorting_key].value, o)
sorting_list = [(o[sorting_key][()], o)
for o in object_list]
sorted_list = sorted(sorting_list, key=itemgetter(0))
return [x[1] for x in sorted_list]
Expand Down Expand Up @@ -323,13 +323,13 @@ def getDataObject(self, key, selection=None):
mcaDatasetObjectPath = mcaObjectPaths[key]
dataset = None
if mcaDatasetObjectPath in h5File:
dataset = h5File[mcaDatasetObjectPath].value
dataset = h5File[mcaDatasetObjectPath][()]
elif "::" in mcaDatasetObjectPath:
fileName, path = mcaDatasetObjectPath.split()
if os.path.exists(fileName):
with h5py.File(fileName, "r") as h5:
if path in h5:
dataset = h5[path].value
dataset = h5[path][()]
if dataset is None:
_logger.debug("Broken link? Ignoring key %s = %s",
key, mcaDatasetObjectPath)
Expand Down Expand Up @@ -368,7 +368,7 @@ def getDataObject(self, key, selection=None):
if selection['mcaselectiontype'].lower() != "sum":
mcaData /= divider
else:
mcaData = mcaData.value
mcaData = mcaData[()]
divider = 1.0
if "McaLiveTime" in output.info:
if numpy.isscalar(output.info["McaLiveTime"]):
Expand Down Expand Up @@ -415,7 +415,7 @@ def getDataObject(self, key, selection=None):
_logger.info("Skipping object key %s" % key)
continue
output.info['MotorNames'].append(key)
value = positioners[key].value
value = positioners[key][()]
if hasattr(value, "size"):
if value.size > 1:
if hasattr(value, "flat"):
Expand All @@ -436,7 +436,7 @@ def getDataObject(self, key, selection=None):
totalElements *= dim
if totalElements < 2.0E7:
try:
data = phynxFile[path].value
data = phynxFile[path][()]
except MemoryError:
data = phynxFile[path]
pass
Expand Down Expand Up @@ -481,7 +481,7 @@ def getDataObject(self, key, selection=None):
if len(selection[cnt]) > 1:
for xidx in range(1, len(selection[cnt])):
path = entry + selection['cntlist'][selection[cnt][xidx]]
data = phynxFile[path].value
data = phynxFile[path][()]
output.x.append(data)
elif cnt == 'm':
#only one monitor
Expand Down
8 changes: 4 additions & 4 deletions PyMca5/PyMcaCore/NexusTools.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#
# The PyMca X-Ray Fluorescence Toolkit
#
# Copyright (c) 2018 European Synchrotron Radiation Facility
# Copyright (c) 2018-2019 European Synchrotron Radiation Facility
#
# This file is part of the PyMca X-ray Fluorescence Toolkit developed at
# the ESRF by the Software group.
Expand Down Expand Up @@ -78,7 +78,7 @@ def h5py_sorting(object_list):

try:
if sorting_key != 'name':
sorting_list = [(o[1][sorting_key].value, o)
sorting_list = [(o[1][sorting_key][()], o)
for o in object_list]
sorted_list = sorted(sorting_list, key=itemgetter(0))
return [x[1] for x in sorted_list]
Expand Down Expand Up @@ -500,7 +500,7 @@ def getScannedPositioners(h5file, path):
if not len(scanned):
entry = h5file[entry_name]
if "title" in entry:
title = entry["title"].value
title = entry["title"][()]
if hasattr(title, "dtype"):
_logger.warning("entry title should be a string not an array")
if hasattr(title, "__len__"):
Expand Down Expand Up @@ -537,7 +537,7 @@ def getScannedPositioners(h5file, path):
for entry in entries:
print("Entry name = %s" % entry.name)
if "title" in entry:
print("Entry title = %s" % entry["title"].value)
print("Entry title = %s" % entry["title"][()])
measurement = getMeasurementGroup(h5, entry.name)
if measurement is None:
print("No measurement")
Expand Down
31 changes: 16 additions & 15 deletions PyMca5/PyMcaGui/io/hdf5/HDF5Info.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#/*##########################################################################
# Copyright (C) 2004-2017 V.A. Sole, European Synchrotron Radiation Facility
# Copyright (C) 2004-2019 V.A. Sole, European Synchrotron Radiation Facility
#
# This file is part of the PyMca X-ray Fluorescence Toolkit developed at
# the ESRF by the Software group.
Expand Down Expand Up @@ -390,19 +390,19 @@ def getInfo(hdf5File, node):
if hasattr(data, 'shape'):
shape = data.shape
if not len(shape):
ddict['general']['Value'] = "%s" % data.value
ddict['general']['Value'] = "%s" % data[()]
elif shape[0] == 1:
ddict['general']['Value'] = "%s" % data.value[0]
ddict['general']['Value'] = "%s" % data[0]
else:
print("Warning: Node %s not fully understood" % node)
ddict['general']['Value'] = "%s" % data.value
ddict['general']['Value'] = "%s" % data[()]
elif hasattr(data, 'shape'):
shape = data.shape
if len(shape) == 1:
if shape[0] == 1:
ddict['general']['Value'] = "%s" % data.value[0]
ddict['general']['Value'] = "%s" % data[0]
elif len(shape) == 0:
ddict['general']['Value'] = "%s" % data.value
ddict['general']['Value'] = "%s" % data[()]
if hasattr(data, "keys"):
ddict['general']['members'] = list(data.keys())
elif hasattr(data, "listnames"):
Expand All @@ -425,27 +425,28 @@ def getInfo(hdf5File, node):
("%s" % dtype).startswith("|O"):
if not len(shape):
ddict['general'][member]['Shape'] = ""
ddict['general'][member]['Value'] = "%s" % memberObject.value
ddict['general'][member]['Value'] = "%s" % memberObject[()]
else:
ddict['general'][member]['Shape'] = shape[0]
ddict['general'][member]['Value'] = "%s" % memberObject.value[0]
if shape[0] > 0:
ddict['general'][member]['Value'] = "%s" % memberObject[0]
continue
if not len(shape):
ddict['general'][member]['Shape'] = ""
ddict['general'][member]['Value'] = "%s" % memberObject.value
ddict['general'][member]['Value'] = "%s" % memberObject[()]
continue
ddict['general'][member]['Shape'] = "%d" % shape[0]
for i in range(1, len(shape)):
ddict['general'][member]['Shape'] += " x %d" % shape[i]
if len(shape) == 1:
if shape[0] == 1:
ddict['general'][member]['Value'] = "%s" % memberObject.value[0]
else:
ddict['general'][member]['Value'] = "%s, ..., %s" % (memberObject.value[0],
memberObject.value[-1])
ddict['general'][member]['Value'] = "%s" % memberObject[0]
elif shape[0] > 1:
ddict['general'][member]['Value'] = "%s, ..., %s" % (memberObject[0],
memberObject[-1])
elif len(shape) == 2:
ddict['general'][member]['Value'] = "%s, ..., %s" % (memberObject.value[0],
memberObject.value[-1])
ddict['general'][member]['Value'] = "%s, ..., %s" % (memberObject[0],
memberObject[-1])
else:
pass
else:
Expand Down
8 changes: 4 additions & 4 deletions PyMca5/PyMcaGui/io/hdf5/HDF5Widget.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#/*##########################################################################
# Copyright (C) 2004-2018 V.A. Sole, ESRF - D. Dale CHESS
# Copyright (C) 2004-2019 V.A. Sole, ESRF - D. Dale CHESS
#
# This file is part of the PyMca X-ray Fluorescence Toolkit developed at
# the ESRF by the Software group.
Expand Down Expand Up @@ -105,7 +105,7 @@ def h5py_sorting(object_list):

try:
if sorting_key != 'name':
sorting_list = [(o[1][sorting_key].value, o)
sorting_list = [(o[1][sorting_key][()], o)
for o in object_list]
sorted_list = sorted(sorting_list, key=itemgetter(0))
return [x[1] for x in sorted_list]
Expand Down Expand Up @@ -429,10 +429,10 @@ def data(self, index, role):
if len(children[idx].getNode().shape):
#stored as an array of strings!!!
#return just the first item
return MyQVariant("%s" % children[idx].getNode().value[0])
return MyQVariant("%s" % children[idx].getNode()[()][0])
else:
#stored as a string
return MyQVariant("%s" % children[idx].getNode().value)
return MyQVariant("%s" % children[idx].getNode()[()])
return MyQVariant(item.type)
if column == 2:
return MyQVariant(item.shape)
Expand Down
10 changes: 8 additions & 2 deletions PyMca5/PyMcaGui/pymca/PyMcaMain.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python
#/*##########################################################################
# Copyright (C) 2004-2018 V.A. Sole, European Synchrotron Radiation Facility
# Copyright (C) 2004-2019 V.A. Sole, European Synchrotron Radiation Facility
#
# This file is part of the PyMca X-ray Fluorescence Toolkit developed at
# the ESRF by the Software group.
Expand Down Expand Up @@ -135,7 +135,13 @@
if hasattr(qt, 'QOpenGLWidget'):
print("Warning: OpenGL backend not fully supported")
try:
# try to import silx prior to import matplotlib
if (sys.version_info < (3,)) and ("PyQt4.QtCore" in sys.modules):
# PyQt4 is the most reliable binding at the ESRF for python 2
import silx
silxLogger = logging.getLogger("silx.DEPRECATION")
silxLogger.setLevel(logging.CRITICAL)
# try to import silx prior to importing matplotlib to prevent
# unnecessary warning
import silx.gui.plot
except:
pass
Expand Down
11 changes: 8 additions & 3 deletions PyMca5/PyMcaGui/pymca/QStackWidget.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python
#/*##########################################################################
# Copyright (C) 2004-2018 V.A. Sole, European Synchrotron Radiation Facility
# Copyright (C) 2004-2019 V.A. Sole, European Synchrotron Radiation Facility
#
# This file is part of the PyMca X-ray Fluorescence Toolkit developed at
# the ESRF by the Software group.
Expand Down Expand Up @@ -88,8 +88,13 @@
else:
QString = qt.safe_str
try:
# try to import silx prior to importing matplotlib
# to prevent unnecessary warning
if (sys.version_info < (3,)) and ("PyQt4.QtCore" in sys.modules):
# PyQt4 is the most reliable binding at the ESRF for python 2
import silx
silxLogger = logging.getLogger("silx.DEPRECATION")
silxLogger.setLevel(logging.CRITICAL)
# try to import silx prior to importing matplotlib to prevent
# unnecessary warning
import silx.gui.plot
except:
pass
Expand Down

0 comments on commit cdaebcd

Please sign in to comment.