Skip to content

Commit

Permalink
make sure 2D navigation spread data are displayed using triangulation…
Browse files Browse the repository at this point in the history
… if possible
  • Loading branch information
seb5g committed Dec 2, 2024
1 parent 92e2b7e commit afdfeae
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/pymodaq_gui/plotting/data_viewers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ def activate_roi(self, activate=True):
raise NotImplementedError

def setVisible(self, show=True):
"""convenience method to show or hide the paretn widget"""
"""convenience method to show or hide the parent widget"""
self.parent.setVisible(show)

@property
Expand Down
51 changes: 46 additions & 5 deletions src/pymodaq_gui/plotting/data_viewers/viewerND.py
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,9 @@ def update_nav_data(self, x, y, width=None, height=None):
self._navigator1D.show_data(nav_data)
elif len(nav_axes) == 2:
try:
Triangulation(np.array([axis.get_data() for axis in nav_data.get_nav_axes()]))
self._navigator2D.setVisible(True)
self._navigator1D.setVisible(False)
#Triangulation(np.array([axis.get_data() for axis in nav_data.get_nav_axes()]))
self._navigator2D.show_data(nav_data)
except QhullError as e:
self.triangulation = False
Expand Down Expand Up @@ -683,9 +685,10 @@ def update_widget_visibility(self, data: DataRaw = None,
self.axes_viewer.setVisible(len(nav_indexes) > 2 or (
len(nav_indexes) == 2 and not data.check_axes_linear()))
elif data.distribution.name == DataDistribution.spread:
self.navigator2D.setVisible(len(nav_indexes) == 2 and self.data_displayer.triangulation)
self.navigator1D.setVisible(len(nav_indexes) == 1 or len(nav_indexes) > 2 or
len(nav_indexes) == 2 and
n_nav_axes = len(data.get_nav_axes())
self.navigator2D.setVisible(n_nav_axes == 2 and self.data_displayer.triangulation)
self.navigator1D.setVisible(n_nav_axes == 1 or n_nav_axes > 2 or
n_nav_axes == 2 and
not self.data_displayer.triangulation)
else:
raise ValueError(f'Unknown distribution: {data.distribution.name}')
Expand Down Expand Up @@ -801,6 +804,44 @@ def main():
sys.exit(app.exec_())


def spread_main():
from pymodaq_data.data import DataRaw, Axis
app = QtWidgets.QApplication(sys.argv)
widget = QtWidgets.QWidget()
prog = ViewerND(widget)

param = np.linspace(1, 10, 10)

# generating Npts of spread 2D data
N = 100

x_axis_array = np.random.randint(-20, 50, size=N)
y_axis_array = np.random.randint(20, 40, size=N)

x_axis = Axis('xaxis', 'm', data=x_axis_array, index=0, spread_order=0)
y_axis = Axis('yaxis', 'm', data=y_axis_array, index=0, spread_order=1)
param_axis = Axis('Param', 'eV', data=param, index=1)

data_spread_1x2 = []
for i in param:
data_list = []
for ind in range(N):
data_list.append(mutils.gauss2D(x_axis.get_data()[ind], 10 + i, 15,
y_axis.get_data()[ind], 30 - i, 5))
data_array = np.squeeze(np.array(data_list))
data_spread_1x2.append(data_array)
data_spread_1x2 = np.array(data_spread_1x2).T

data_2D_1x2_spread = DataRaw('data2DSpread', data=[data_spread_1x2],
axes=[x_axis, y_axis, param_axis],
distribution='spread',
nav_indexes=(0,))

widget.show()
prog.show_data(data_2D_1x2_spread)
sys.exit(app.exec_())


if __name__ == '__main__':
main()
spread_main()

36 changes: 36 additions & 0 deletions tests/plotting_test/data_viewers_test/viewerND_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from pymodaq_gui.plotting.data_viewers.viewerND import ViewerND

from pymodaq_data import data as data_mod
from pymodaq_utils import math_utils as mutils


@pytest.fixture
Expand Down Expand Up @@ -36,3 +37,38 @@ def test_linear_spread(self, init_viewernd):
viewer.show_data(data_spread)

pass

def test_2D_spread_1D_signal(self, init_viewernd):
viewer = init_viewernd

# Parameter
param = np.linspace(1, 10, 10)

# generating Npts of spread 2D data
N = 200

x_axis_array = np.random.randint(-20, 50, size=N)
y_axis_array = np.random.randint(20, 40, size=N)

x_axis = data_mod.Axis('xaxis', 'm', data=x_axis_array, index=0, spread_order=0)
y_axis = data_mod.Axis('yaxis', 'm', data=y_axis_array, index=0, spread_order=1)
param_axis = data_mod.Axis('Param', 'eV', data=param, index=1)

data_spread_1x2 = []
for i in param :
data_list = []
for ind in range(N):
data_list.append(mutils.gauss2D(x_axis.get_data()[ind], 10+i, 15,
y_axis.get_data()[ind], 30-i, 5))
data_array = np.squeeze(np.array(data_list))
data_spread_1x2.append(data_array)
data_spread_1x2 = np.array(data_spread_1x2).T

data_2D_1x2_spread = data_mod.DataRaw('data2DSpread', data=[data_spread_1x2],
axes=[x_axis, y_axis, param_axis],
distribution='spread',
nav_indexes=(0,))

data_2D_1x2_spread.plot('qt')
QtWidgets.QApplication.processEvents()
pass

0 comments on commit afdfeae

Please sign in to comment.