Commit f21a1d99 authored by Valentin Valls's avatar Valentin Valls
Browse files

Fix the live API

parent f61df3bd
......@@ -605,12 +605,12 @@ def get_plot(
plot_id = flint.get_live_scan_plot(channel_name, plot_type, as_axes=as_axes)
if plot_type == "curve":
return flint_plots.CurvePlot(flint=flint, plot_id=plot_id)
return flint_plots.LiveCurvePlot(flint=flint, plot_id=plot_id)
elif plot_type == "scatter":
return flint_plots.ScatterPlot(flint=flint, plot_id=plot_id)
return flint_plots.LiveScatterPlot(flint=flint, plot_id=plot_id)
elif plot_type == "mca":
return flint_plots.McaPlot(flint=flint, plot_id=plot_id)
return flint_plots.LiveMcaPlot(flint=flint, plot_id=plot_id)
elif plot_type == "image":
return flint_plots.ImagePlot(flint=flint, plot_id=plot_id)
return flint_plots.LiveImagePlot(flint=flint, plot_id=plot_id)
else:
print("Argument plot_type uses an invalid value: '%s'." % plot_type)
......@@ -453,29 +453,6 @@ class Plot1D(BasePlot):
self._plot_id, unique_name, channel_name, position, text
)
def update_user_data(
self, unique_name: str, channel_name: str, ydata: Optional[numpy.ndarray]
):
"""Add user data to a live plot.
It will define a curve in the plot using the y-data provided and the
x-data from the parent item (defined by the `channel_name`)
The key `unique_name` + `channel_name` is unique. So if it already
exists the item will be updated.
Arguments:
unique_name: Name of this item in the property tree
channel_name: Name of the channel that will be used as parent for
this item. If this parent item does not exist, it is created
but set hidden.
ydata: Y-data for this item. If `None`, if the item already exists,
it is removed from the plot
"""
if ydata is not None:
ydata = numpy.asarray(ydata)
self._flint.update_user_data(self._plot_id, unique_name, channel_name, ydata)
def add_curve(self, x, y, **kwargs):
if x is None:
x = numpy.arange(len(y))
......@@ -751,6 +728,29 @@ class LiveCurvePlot(Plot1D):
ALIASES = ["curve"]
def update_user_data(
self, unique_name: str, channel_name: str, ydata: Optional[numpy.ndarray]
):
"""Add user data to a live plot.
It will define a curve in the plot using the y-data provided and the
x-data from the parent item (defined by the `channel_name`)
The key `unique_name` + `channel_name` is unique. So if it already
exists the item will be updated.
Arguments:
unique_name: Name of this item in the property tree
channel_name: Name of the channel that will be used as parent for
this item. If this parent item does not exist, it is created
but set hidden.
ydata: Y-data for this item. If `None`, if the item already exists,
it is removed from the plot
"""
if ydata is not None:
ydata = numpy.asarray(ydata)
self._flint.update_user_data(self._plot_id, unique_name, channel_name, ydata)
class LiveImagePlot(Plot2D):
......
......@@ -140,11 +140,11 @@ def test_image_display(flint_session, lima_simulator, dummy_acq_device):
# depricated access but kept for compatibilty with older versions...
p = scan.get_plot(lima_sim.image, plot_type="image", wait=True)
assert isinstance(p, plots.ImagePlot)
assert isinstance(p, plots.LiveImagePlot)
# new access
p = plot.get_plot(lima_sim.image, scan=scan, plot_type="image", wait=True)
assert isinstance(p, plots.ImagePlot)
assert isinstance(p, plots.LiveImagePlot)
def test_restart_flint_if_stucked(
......@@ -163,11 +163,11 @@ def test_restart_flint_if_stucked(
# depricated access but kept for compatibilty with older versions...
p = scan.get_plot(lima_sim.image, plot_type="image", wait=True)
assert isinstance(p, plots.ImagePlot)
assert isinstance(p, plots.LiveImagePlot)
# new access
p = plot.get_plot(lima_sim.image, scan=scan, plot_type="image", wait=True)
assert isinstance(p, plots.ImagePlot)
assert isinstance(p, plots.LiveImagePlot)
def test_ignore_flint_if_stucked(
......
Supports Markdown
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