Commit 8a69452f authored by Thomas Vincent's avatar Thomas Vincent

share bin centers -> bin range an step

parent 06eb9db7
......@@ -33,11 +33,11 @@ from collections import OrderedDict
import logging
import numpy as np
from matplotlib import cm
from silx.gui import qt as Qt
from ...io.QSpaceH5 import QSpaceH5
from ...util import bin_centers_to_range_step
from ..widgets.Containers import GroupBox
from ..widgets.RoiAxisWidget import RoiAxisWidget
......@@ -234,30 +234,18 @@ class FitWidget(Qt.QWidget):
statusLabel.setFrameStyle(Qt.QFrame.Panel | Qt.QFrame.Sunken)
layout.addWidget(statusLabel, 4, 0)
# Set sliders range and step
with qspaceH5:
qx = qspaceH5.qx
qy = qspaceH5.qy
qz = qspaceH5.qz
qxMin, qxMax = np.min(qx), np.max(qx)
qyMin, qyMax = np.min(qy), np.max(qy)
qzMin, qzMax = np.min(qz), np.max(qz)
qxScale = (qxMax - qxMin) / (len(qx) - 1)
qyScale = (qyMax - qyMin) / (len(qy) - 1)
qzScale = (qzMax - qzMin) / (len(qz) - 1)
self.roiWidget().xSlider().setNumberOfSteps(len(qx) + 1)
self.roiWidget().xSlider().setRange(qxMin - qxScale/2.,
qxMax + qxScale/2.)
self.roiWidget().ySlider().setNumberOfSteps(len(qy) + 1)
self.roiWidget().ySlider().setRange(qyMin - qyScale/2.,
qyMax + qyScale/2.)
self.roiWidget().zSlider().setNumberOfSteps(len(qz) + 1)
self.roiWidget().zSlider().setRange(qzMin - qzScale/2.,
qzMax + qzScale/2.)
for slider, binCenters in ((self.roiWidget().xSlider(), qx),
(self.roiWidget().ySlider(), qy),
(self.roiWidget().zSlider(), qz)):
slider.setNumberOfSteps(len(binCenters) + 1)
min_, max_ = bin_centers_to_range_step(binCenters)[:2]
slider.setRange(min_, max_)
self.__sigFitDone.connect(self.__slotFitDone)
......@@ -382,7 +370,7 @@ class FitWidget(Qt.QWidget):
def __lock(self, lock):
enable = not lock
self.__roiWidget.setEnabled(enable)
self.roiWidget().setEnabled(enable)
self.__fitTypeCb.setEnabled(enable)
self.__runButton.setEnabled(enable)
......
......@@ -32,8 +32,6 @@ __date__ = "15/09/2016"
import os
import numpy as np
from matplotlib import cm
from silx.utils.weakref import WeakMethodProxy
from silx.gui import qt as Qt
......@@ -44,17 +42,13 @@ from silx.gui.plot3d.ScalarFieldView import ScalarFieldView
from silx.gui.plot3d.SFViewParamTree import TreeView as SFViewParamTree
from silx.math.combo import min_max
from ..model.TreeView import TreeView
from ...util import bin_centers_to_range_step
from ..widgets.XsocsPlot2D import XsocsPlot2D
from ..process.FitWidget import FitWidget
from ..Utils import nextFileName
class QSpaceTree(TreeView):
pass
class PlotIntensityMap(XsocsPlot2D):
"""Plot intensities as a scatter plot
......@@ -461,17 +455,13 @@ class QSpaceView(Qt.QMainWindow):
# Set scale and translation
# Do it before setting data as corresponding
# nodes in the SFViewParamTree are updated on sigDataChanged
qxLen, qyLen, qzLen = qspace.shape
qxMin, qxMax = min(self.__qx), max(self.__qx)
qyMin, qyMax = min(self.__qy), max(self.__qy)
qzMin, qzMax = min(self.__qz), max(self.__qz)
qxScale = (qxMax - qxMin) / (qxLen - 1)
qyScale = (qyMax - qyMin) / (qyLen - 1)
qzScale = (qzMax - qzMin) / (qzLen - 1)
self.__view3d.setScale(qxScale, qyScale, qzScale)
self.__view3d.setTranslation(qxMin - qxScale/2.,
qyMin - qyScale/2.,
qzMin - qzScale/2.)
qxMinBinEdge, _, qxBinStep = bin_centers_to_range_step(self.__qx)
qyMinBinEdge, _, qyBinStep = bin_centers_to_range_step(self.__qy)
qzMinBinEdge, _, qzBinStep = bin_centers_to_range_step(self.__qz)
self.__view3d.setScale(qxBinStep, qyBinStep, qzBinStep)
self.__view3d.setTranslation(
qxMinBinEdge, qyMinBinEdge, qzMinBinEdge)
self.__defaultIsoLevels = None # Reset default isosurface levels
......@@ -482,9 +472,9 @@ class QSpaceView(Qt.QMainWindow):
self.__stackView.setStack(
swappedQSpace,
reset=False,
calibrations=((qzMin - qzScale/2., qzScale),
(qyMin - qyScale/2., qyScale),
(qxMin - qxScale/2., qxScale)))
calibrations=((qzMinBinEdge, qzBinStep),
(qyMinBinEdge, qyBinStep),
(qxMinBinEdge, qxBinStep)))
if not wasStack:
self.__stackView.resetZoom()
......
......@@ -23,7 +23,7 @@
#
# ###########################################################################*/
from __future__ import absolute_import
from __future__ import absolute_import, division
__authors__ = ["D. Naudet"]
__license__ = "MIT"
......@@ -41,6 +41,7 @@ import multiprocessing.sharedctypes as mp_sharedctypes
import numpy as np
import xrayutilities as xu
from ...util import bin_centers_to_range_step
from ...util.medianfilter import medfilt2d
from ...util.histogramnd_lut import histogramnd_get_lut, histogramnd_from_lut
# from silx.math import histogramnd
......@@ -777,14 +778,13 @@ class QSpaceConverter(object):
step_y = (qy_max - qy_min) / (ny - 1.)
step_z = (qz_max - qz_min) / (nz - 1.)
bins_rng_x = ([qx_min - step_x / 2., qx_max + step_x / 2.])
bins_rng_y = ([qy_min - step_y / 2., qy_max + step_y / 2.])
bins_rng_z = ([qz_min - step_z / 2., qz_max + step_z / 2.])
bins_rng = [bins_rng_x, bins_rng_y, bins_rng_z]
qx_bin_centers = qx_min + step_x * np.arange(0, nx, dtype=np.float64)
qy_bin_centers = qy_min + step_y * np.arange(0, ny, dtype=np.float64)
qz_bin_centers = qz_min + step_z * np.arange(0, nz, dtype=np.float64)
qx_idx = qx_min + step_x * np.arange(0, nx, dtype=np.float64)
qy_idx = qy_min + step_y * np.arange(0, ny, dtype=np.float64)
qz_idx = qz_min + step_z * np.arange(0, nz, dtype=np.float64)
bins_rng = [bin_centers_to_range_step(qx_bin_centers)[:2],
bin_centers_to_range_step(qy_bin_centers)[:2],
bin_centers_to_range_step(qz_bin_centers)[:2]]
# TODO : on windows we may be forced to use shared memory
# TODO : find why we use more memory when using shared arrays
......@@ -852,9 +852,9 @@ class QSpaceConverter(object):
sample_roi,
sample_x[sample_indices],
sample_y[sample_indices],
qx_idx,
qy_idx,
qz_idx,
qx_bin_centers,
qy_bin_centers,
qz_bin_centers,
histo,
selected_entries=entries,
discarded_entries=discarded_entries,
......
......@@ -22,7 +22,29 @@
# THE SOFTWARE.
#
# ###########################################################################*/
"""This module miscellaneous convenient functions"""
from __future__ import absolute_import, division
__authors__ = ["D. Naudet"]
__license__ = "MIT"
__date__ = "01/03/2016"
import numpy
def bin_centers_to_range_step(centers):
"""Convert histogram bin centers (as stored in hdf5) to bin range and step
This assumes sorted bins of the same size.
:param numpy.ndarray centers: 1D array of bin centers
:return: Bin edges min, max, step
:rtype: List[float]
"""
centers = numpy.array(centers, copy=False)
nbins = centers.shape[0] - 1
min_, max_ = numpy.min(centers), numpy.max(centers)
step = (max_ - min_) / nbins
return min_ - step/2., max_ + step/2., step
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment