Skip to content

Commit

Permalink
Merge pull request #3199 from kif/3198_error_saving
Browse files Browse the repository at this point in the history
LGTM
  • Loading branch information
t20100 authored Sep 30, 2020
2 parents ffa05dd + 83b4636 commit 8e58119
Show file tree
Hide file tree
Showing 5 changed files with 188 additions and 98 deletions.
5 changes: 2 additions & 3 deletions bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
__authors__ = ["Frédéric-Emmanuel Picca", "Jérôme Kieffer"]
__contact__ = "[email protected]"
__license__ = "MIT"
__date__ = "26/07/2018"

__date__ = "30/09/2020"

import argparse
import distutils.util
Expand All @@ -21,7 +20,6 @@
import sys
import tempfile


logging.basicConfig()
logger = logging.getLogger("bootstrap")

Expand Down Expand Up @@ -69,6 +67,7 @@ def _get_available_scripts(path):


if sys.version_info[0] >= 3: # Python3

def execfile(fullpath, globals=None, locals=None):
"Python3 implementation for execfile"
with open(fullpath) as f:
Expand Down
10 changes: 2 additions & 8 deletions run_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"""

__authors__ = ["Jérôme Kieffer", "Thomas Vincent"]
__date__ = "02/03/2018"
__date__ = "30/09/2020"
__license__ = "MIT"

import distutils.util
Expand Down Expand Up @@ -87,7 +87,6 @@ def createBasicHandler():

logger.info("Python %s %s", sys.version, tuple.__itemsize__ * 8)


try:
import resource
except ImportError:
Expand All @@ -98,6 +97,7 @@ def createBasicHandler():
import importlib
importer = importlib.import_module
except ImportError:

def importer(name):
module = __import__(name)
# returns the leaf module, instead of the root module
Expand All @@ -107,7 +107,6 @@ def importer(name):
module = getattr(module, subname)
return module


try:
import numpy
except Exception as error:
Expand Down Expand Up @@ -350,11 +349,9 @@ def get_test_options(project_module):
PROJECT_VERSION = getattr(project_module, 'version', '')
PROJECT_PATH = project_module.__path__[0]


test_options = get_test_options(project_module)
"""Contains extra configuration for the tests."""


epilog = """Environment variables:
WITH_QT_TEST=False to disable graphical tests
SILX_OPENCL=False to disable OpenCL tests
Expand Down Expand Up @@ -393,7 +390,6 @@ def get_test_options(project_module):
options = parser.parse_args()
sys.argv = [sys.argv[0]]


test_verbosity = 1
use_buffer = True
if options.verbose == 1:
Expand Down Expand Up @@ -467,7 +463,6 @@ def get_test_options(project_module):
else:
logger.warning("No test options available.")


if not options.test_name:
# Do not use test loader to avoid cryptic exception
# when an error occur during import
Expand All @@ -487,7 +482,6 @@ def get_test_options(project_module):
else:
exit_status = 1


if options.coverage:
cov.stop()
cov.save()
Expand Down
71 changes: 51 additions & 20 deletions silx/gui/plot/actions/io.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# coding: utf-8
# /*##########################################################################
#
# Copyright (c) 2004-2019 European Synchrotron Radiation Facility
# Copyright (c) 2004-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
Expand Down Expand Up @@ -37,7 +37,7 @@

__authors__ = ["V.A. Sole", "T. Vincent", "P. Knobel"]
__license__ = "MIT"
__date__ = "12/07/2018"
__date__ = "25/09/2020"

from . import PlotAction
from silx.io.utils import save1D, savespec, NEXUS_HDF5_EXT
Expand Down Expand Up @@ -224,6 +224,43 @@ def _getAxesLabels(self, item):
ylabel = item.getYLabel() or self.plot.getYAxis().getLabel()
return xlabel, ylabel

def _get1dData(self, item):
"provide xdata, [ydata], xlabel, [ylabel] and manages error bars"
xlabel, ylabel = self._getAxesLabels(item)
x_data = item.getXData(copy=False)
y_data = item.getYData(copy=False)
x_err = item.getXErrorData(copy=False)
y_err = item.getYErrorData(copy=False)
labels = [ylabel]
data = [y_data]

if x_err is not None:
if numpy.isscalar(x_err):
data.append(numpy.zeros_like(y_data) + x_err)
labels.append(xlabel + "_errors")
elif x_err.ndim == 1:
data.append(x_err)
labels.append(xlabel + "_errors")
elif x_err.ndim == 2:
data.append(x_err[0])
labels.append(xlabel + "_errors_below")
data.append(x_err[1])
labels.append(xlabel + "_errors_above")

if y_err is not None:
if numpy.isscalar(y_err):
data.append(numpy.zeros_like(y_data) + y_err)
labels.append(ylabel + "_errors")
elif y_err.ndim == 1:
data.append(y_err)
labels.append(ylabel + "_errors")
elif y_err.ndim == 2:
data.append(y_err[0])
labels.append(ylabel + "_errors_below")
data.append(y_err[1])
labels.append(ylabel + "_errors_above")
return x_data, data, xlabel, labels

@staticmethod
def _selectWriteableOutputGroup(filename, parent):
if os.path.exists(filename) and os.path.isfile(filename) \
Expand Down Expand Up @@ -291,16 +328,15 @@ def _saveCurve(self, plot, filename, nameFilter):
# .npy or nxdata
fmt, csvdelim, autoheader = ("", "", False)

xlabel, ylabel = self._getAxesLabels(curve)

if nameFilter == self.CURVE_FILTER_NXDATA:
return self._saveCurveAsNXdata(curve, filename)

xdata, data, xlabel, labels = self._get1dData(curve)

try:
save1D(filename,
curve.getXData(copy=False),
curve.getYData(copy=False),
xlabel, [ylabel],
xdata, data,
xlabel, labels,
fmt=fmt, csvdelim=csvdelim,
autoheader=autoheader)
except IOError:
Expand Down Expand Up @@ -328,13 +364,11 @@ def _saveCurves(self, plot, filename, nameFilter):
curve = curves[0]
scanno = 1
try:
xlabel = curve.getXLabel() or plot.getGraphXLabel()
ylabel = curve.getYLabel() or plot.getGraphYLabel(curve.getYAxis())
xdata, data, xlabel, labels = self._get1dData(curve)

specfile = savespec(filename,
curve.getXData(copy=False),
curve.getYData(copy=False),
xlabel,
ylabel,
xdata, data,
xlabel, labels,
fmt="%.7g", scan_number=1, mode="w",
write_file_header=True,
close_file=False)
Expand All @@ -345,13 +379,10 @@ def _saveCurves(self, plot, filename, nameFilter):
for curve in curves[1:]:
try:
scanno += 1
xlabel = curve.getXLabel() or plot.getGraphXLabel()
ylabel = curve.getYLabel() or plot.getGraphYLabel(curve.getYAxis())
xdata, data, xlabel, labels = self._get1dData(curve)
specfile = savespec(specfile,
curve.getXData(copy=False),
curve.getYData(copy=False),
xlabel,
ylabel,
xdata, data,
xlabel, labels,
fmt="%.7g", scan_number=scanno,
write_file_header=False,
close_file=False)
Expand Down Expand Up @@ -629,7 +660,7 @@ def onFilterSelection(filt_):
# Check for correct file extension
# Extract file extensions as .something
extensions = [ext[ext.find('.'):] for ext in
nameFilter[nameFilter.find('(')+1:-1].split()]
nameFilter[nameFilter.find('(') + 1:-1].split()]
for ext in extensions:
if (len(filename) > len(ext) and
filename[-len(ext):].lower() == ext.lower()):
Expand Down
Loading

0 comments on commit 8e58119

Please sign in to comment.