Commit 25ca8b31 authored by Thomas Vincent's avatar Thomas Vincent

share QSpace projection to axes code

parent ada8073e
......@@ -34,7 +34,7 @@ import logging
from silx.gui import qt as Qt
from ...io.QSpaceH5 import QSpaceH5
from ...util import bin_centers_to_range_step
from ...util import bin_centers_to_range_step, project
from ..widgets.Containers import GroupBox
from ..widgets.RoiAxisWidget import RoiAxisWidget
......@@ -196,13 +196,9 @@ class FitWidget(Qt.QWidget):
:param int index: QSpace index
"""
qspace = self.__qspaceH5.qspace_slice(index)
dim2_sum = qspace.sum(axis=0).sum(axis=0)
cube_sum_dim2 = qspace.sum(axis=2)
dim1_sum = cube_sum_dim2.sum(axis=0)
dim0_sum = cube_sum_dim2.sum(axis=1)
projections = project(self.__qspaceH5.qspace_slice(index))
for profile, slider in zip((dim0_sum, dim1_sum, dim2_sum),
for profile, slider in zip(projections,
self.roiWidget().sliders()):
slider.setGroovePixmapFromProfile(profile, colormap='jet')
......
......@@ -47,6 +47,7 @@ from .fitview.DropPlotWidget import DropPlotWidget
from .fitview.Plotter import GaussianPlotter, CentroidPlotter
from ...process.fit.peak_fit import background_estimation, BackgroundTypes
from ...util import project
_logger = logging.getLogger(__name__)
......@@ -270,17 +271,11 @@ class FitView(Qt.QMainWindow):
with self.__qspaceH5:
cube = self.__qspaceH5.qspace_slice(xIdx)
histo = self.__qspaceH5.histo
mask = np.where(histo > 0)
weights = histo[mask]
cube[mask] /= weights
xAcqQX = self.__qspaceH5.qx
xAcqQY = self.__qspaceH5.qy
xAcqQZ = self.__qspaceH5.qz
yAcqQZ = cube.sum(axis=0).sum(axis=0)
cube_sum_z = cube.sum(axis=2)
yAcqQY = cube_sum_z.sum(axis=0)
yAcqQX = cube_sum_z.sum(axis=1)
yAcqQX, yAcqQY, yAcqQZ = project(cube, histo)
# Get plotter
if entry == 'Gaussian':
......
......@@ -36,7 +36,6 @@ import ctypes
import multiprocessing
from threading import Thread
import multiprocessing.sharedctypes as mp_sharedctypes
import warnings
import numpy as np
from scipy.optimize import leastsq
......@@ -46,7 +45,7 @@ from silx.math.fit import snip1d
from ... import config
from ...io import QSpaceH5
from ...io.FitH5 import BackgroundTypes
from ...util import gaussian
from ...util import gaussian, project
from .fitresults import FitResult
......@@ -317,28 +316,6 @@ def _fit_process(index,
return result
def project(data, hits=None):
"""Sum data along each axis
:param numpy.ndarray data: 3D histogram
:param Union[numpy.ndarray,None] hits:
Number of bin count of the histogram or None to ignore
:return: Projections on each axis of the dataset
:rtype: List[numpy.ndarray]
"""
if hits is not None:
with warnings.catch_warnings():
warnings.simplefilter('ignore', RuntimeWarning)
data /= hits
data[hits <= 0] = 0
dim2_sum = data.sum(axis=0).sum(axis=0)
data_sum_dim2 = data.sum(axis=2)
dim1_sum = data_sum_dim2.sum(axis=0)
dim0_sum = data_sum_dim2.sum(axis=1)
return dim0_sum, dim1_sum, dim2_sum
# Center of mass
def centroid(axis, signal):
......
......@@ -32,6 +32,7 @@ __date__ = "01/03/2016"
import sys
import warnings
import numpy
......@@ -72,3 +73,25 @@ def gaussian(x, area, center, sigma):
"""
return (area * (1. / (_SQRT_2_PI * sigma)) *
numpy.exp(-0.5 * ((x - center) / sigma) ** 2))
def project(data, hits=None):
"""Sum data along each axis
:param numpy.ndarray data: 3D histogram
:param Union[numpy.ndarray,None] hits:
Number of bin count of the histogram or None to ignore
:return: Projections on each axis of the dataset
:rtype: List[numpy.ndarray]
"""
if hits is not None:
with warnings.catch_warnings():
warnings.simplefilter('ignore', RuntimeWarning)
data /= hits
data[hits <= 0] = 0
dim2_sum = data.sum(axis=0).sum(axis=0)
data_sum_dim2 = data.sum(axis=2)
dim1_sum = data_sum_dim2.sum(axis=0)
dim0_sum = data_sum_dim2.sum(axis=1)
return dim0_sum, dim1_sum, dim2_sum
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