From 5d6be5796b42f33f5ea91d7082cd51a351db4f22 Mon Sep 17 00:00:00 2001 From: Luke Campagnola Date: Wed, 13 Sep 2017 21:36:34 -0700 Subject: [PATCH 1/2] image export: add option to invert pixel values (but not hues) --- pyqtgraph/exporters/ImageExporter.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/pyqtgraph/exporters/ImageExporter.py b/pyqtgraph/exporters/ImageExporter.py index 4dc07d84..ffa59091 100644 --- a/pyqtgraph/exporters/ImageExporter.py +++ b/pyqtgraph/exporters/ImageExporter.py @@ -27,6 +27,7 @@ class ImageExporter(Exporter): {'name': 'height', 'type': 'int', 'value': int(tr.height()), 'limits': (0, None)}, {'name': 'antialias', 'type': 'bool', 'value': True}, {'name': 'background', 'type': 'color', 'value': bg}, + {'name': 'invertValue', 'type': 'bool', 'value': False} ]) self.params.param('width').sigValueChanged.connect(self.widthChanged) self.params.param('height').sigValueChanged.connect(self.heightChanged) @@ -67,13 +68,15 @@ class ImageExporter(Exporter): w, h = self.params['width'], self.params['height'] if w == 0 or h == 0: raise Exception("Cannot export image with size=0 (requested export size is %dx%d)" % (w,h)) - bg = np.empty((self.params['width'], self.params['height'], 4), dtype=np.ubyte) + bg = np.empty((self.params['height'], self.params['width'], 4), dtype=np.ubyte) color = self.params['background'] bg[:,:,0] = color.blue() bg[:,:,1] = color.green() bg[:,:,2] = color.red() bg[:,:,3] = color.alpha() - self.png = fn.makeQImage(bg, alpha=True) + + self.png = fn.makeQImage(bg, alpha=True, copy=False, transpose=False) + self.bg = bg ## set resolution of image: origTargetRect = self.getTargetRect() @@ -91,6 +94,12 @@ class ImageExporter(Exporter): self.setExportMode(False) painter.end() + if self.params['invertValue']: + mn = bg[...,:3].min(axis=2) + mx = bg[...,:3].max(axis=2) + d = (255 - mx) - mn + bg[...,:3] += d[...,np.newaxis] + if copy: QtGui.QApplication.clipboard().setImage(self.png) elif toBytes: From 6287874b5c3267d40128d637ab08a7957f687c5c Mon Sep 17 00:00:00 2001 From: Luke Campagnola Date: Wed, 13 Sep 2017 21:37:19 -0700 Subject: [PATCH 2/2] Minor fix - check for ragged array length when exporting to hdf5 --- pyqtgraph/exporters/HDF5Exporter.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/pyqtgraph/exporters/HDF5Exporter.py b/pyqtgraph/exporters/HDF5Exporter.py index cc8b5733..584a9f71 100644 --- a/pyqtgraph/exporters/HDF5Exporter.py +++ b/pyqtgraph/exporters/HDF5Exporter.py @@ -42,14 +42,20 @@ class HDF5Exporter(Exporter): dsname = self.params['Name'] fd = h5py.File(fileName, 'a') # forces append to file... 'w' doesn't seem to "delete/overwrite" data = [] - + appendAllX = self.params['columnMode'] == '(x,y) per plot' - for i,c in enumerate(self.item.curves): + #print dir(self.item.curves[0]) + tlen = 0 + for i, c in enumerate(self.item.curves): d = c.getData() + if i > 0 and len(d[0]) != tlen: + raise ValueError ("HDF5 Export requires all curves in plot to have same length") if appendAllX or i == 0: data.append(d[0]) + tlen = len(d[0]) data.append(d[1]) - + + fdata = numpy.array(data).astype('double') dset = fd.create_dataset(dsname, data=fdata) fd.close()