diff options
author | Onderwaater <onderwaa@esrf.fr> | 2015-08-20 16:00:59 +0200 |
---|---|---|
committer | Onderwaater <onderwaa@esrf.fr> | 2015-08-20 16:00:59 +0200 |
commit | 91d677d63bccc32bbabee5c226995108d8e6bb6d (patch) | |
tree | 8f0d2362d7be8fc780a403d984c93ea74ece345f | |
parent | 2fb48c4288b75b122dfa8e1bf03be019dd3fdb1e (diff) |
merge space.get_value into space.__getitem__
-rw-r--r-- | BINoculars/fit.py | 2 | ||||
-rw-r--r-- | BINoculars/space.py | 18 | ||||
-rw-r--r-- | gui.py | 2 |
3 files changed, 4 insertions, 18 deletions
diff --git a/BINoculars/fit.py b/BINoculars/fit.py index 2e7b8c4..647a005 100644 --- a/BINoculars/fit.py +++ b/BINoculars/fit.py @@ -91,7 +91,7 @@ class PeakFitBase(FitBase): argmax_bkg = linparams[-1] + numpy.sum(numpy.vstack(param * grid.flatten() for (param, grid) in zip(linparams[:-1], argmax))) try: - maximum = self.space.get_value(argmax) - argmax_bkg + maximum = self.space[argmax] - argmax_bkg except ValueError: maximum = self.cydata.max() diff --git a/BINoculars/space.py b/BINoculars/space.py index 3f02285..44fafb5 100644 --- a/BINoculars/space.py +++ b/BINoculars/space.py @@ -366,7 +366,7 @@ class Space(object): newkey = self.get_key(key) newaxes = tuple(ax[k] for k, ax in zip(newkey, self.axes) if isinstance(ax[k], Axis)) if not newaxes: - raise ValueError('zero-dimensional spaces are not supported') + return self.photons[newkey] / self.contributions[newkey] newspace = self.__class__(newaxes) newspace.photons = self.photons[newkey].copy() newspace.contributions = self.contributions[newkey].copy() @@ -379,24 +379,10 @@ class Space(object): raise IndexError('dimension mismatch') else: key = [key] - elif not isinstance(key, tuple) or not len(key) == len(self.axes): + elif not (isinstance(key, tuple) or isinstance(key, list)) or not len(key) == len(self.axes): raise IndexError('dimension mismatch') return tuple(ax.get_index(k) for k, ax in zip(key, self.axes)) - def get_value(self, key): - ### FIXME: should be merged into __getitem__() - if isinstance(key, numbers.Number): - if not len(self.axes) == 1: - raise IndexError('dimension mismatch') - newkey = self.axes[0].get_index(key) - return self.photons[newkey] / self.contributions[newkey] - elif isinstance(key, tuple) or isinstance(key, list): - newkey = tuple(ax.get_index(k) for k, ax in zip(key, self.axes)) - return self.photons[newkey] / self.contributions[newkey] - else: - raise ValueError('invalid key: {0}'.format(key)) - - def project(self, axis, *more_axes): """Reduce dimensionality of Space by projecting onto 'axis'. All data (photons, contributions) is summed along this axis. @@ -478,7 +478,7 @@ class ProjectWidget(QtGui.QWidget): coords = numpy.array([event.xdata, event.ydata])[order] try: rounded_coords = [ax[ax.get_index(coord)] for ax, coord in zip(plotaxes.space.axes, coords)] - intensity = '{0:.2e}'.format(plotaxes.space.get_value(list(coords))) + intensity = '{0:.2e}'.format(plotaxes.space[list(coords)]) self.parent.statusbar.showMessage('{0} = {1}, {2} = {3}, Intensity = {4}'.format(labels[0], rounded_coords[0] ,labels[1], rounded_coords[1], intensity)) except ValueError: self.parent.statusbar.showMessage('out of range') |