PyMoDAQ / pymodaq_femto

PyMoDAQ extension for femtosecond laser pulse characterization
MIT License
3 stars 3 forks source link

Trouble getting axes from Viewer2D #3

Closed rgeneaux closed 1 year ago

rgeneaux commented 1 year ago

Hi! When launched from a dashboard, the retriever has a function to "load last scan". It looks for the current "scan2D_graph" associated with the last scan performed by daq_scan, gets axis and data from it, and loads it into the retriever directly.

It now seems to be broken:

    def load_last_scan(self):
        try:
            viewer = self.dashboard.scan_module.ui.scan2D_graph
            parameter_axis = utils.Axis(
                data=viewer.x_axis_scaled.copy(),
                label=viewer.scaling_options["scaled_xaxis"]["label"],
                units=viewer.scaling_options["scaled_xaxis"]["units"],
            )
            wl = utils.Axis(
                data=viewer.y_axis_scaled.copy(),
                label=viewer.scaling_options["scaled_yaxis"]["label"],
                units=viewer.scaling_options["scaled_yaxis"]["units"],
            )
            data = self.dashboard.scan_module.scan_data_2D[0].T.copy()

            self.set_data_in_exp(data, wl, parameter_axis)
        except Exception as e:
            pass

The issue is that in data=viewer.x_axis_scaled.copy(), the viewer doesn't have a x_axis_scaled anymore.

I was able to get the label and units using viewer.x_axis.axis_units() and viewer.x_axis.axis_label() but I can't figure out how to get the data. Thanks for any help!

seb5g commented 1 year ago

Well indeed I refactored some time ago the viewer2D (and it will also be modified with version 4...as I'm working on a broad and general way to treat data and axes in pymodaq) Anyway in your case if you look at the x_axis property of the Viewer2D (so viewer in your case: viewer = self.dashboard.scan_module.ui.scan2D_graph)

This property returns an AxisItem_Scaled scaled image

then this object has a number of properties and methods to be used for your purpose:

that should do it!

rgeneaux commented 1 year ago

Indeed this should work, thanks! the last thing I'm missing: how do you get the number of points of an axis?

seb5g commented 1 year ago

the axis does not have this info but your data does via its shape! if data is the ndarray you want to plot:

Nyaxis = data.shape[0] Nxaxis = data.shape[1]

Seb

rgeneaux commented 1 year ago

Got it, thanks!