stevenjgomez / nxs_analysis_tools

MIT License
0 stars 0 forks source link

Background plotting and subtraction doesn't work #1

Open wilsonlabucsb opened 1 year ago

wilsonlabucsb commented 1 year ago

The following code doesn't work because the floating point indices are indexing the data.signal rather than the whole dataset, so there is no knowledge of the axes values.

    def plot_background_subtraction(self):
        data = self.data
        fig, axes = plt.subplots(1, 3)
        # Plot the background and subtracted
        plot_slice(data[data.axes[0]], data[data.axes[1]],
                   data[data.signal][:, :, 0.0] - self.background[:, :, len(data[data.axes[2]]) // 2],
                   ax=axes[0], skew_angle=self.ga_star)
        plot_slice(data[data.axes[0]], data[data.axes[2]],
                   data[data.signal][:, 0.0, :] - self.background[:, len(data[data.axes[1]]) // 2, :],
                   ax=axes[1], skew_angle=self.be_star)
        plot_slice(data[data.axes[1]], data[data.axes[2]],
                   data[data.signal][0.0, :, :] - self.background[len(data[data.axes[0]]) // 2, :, :],
                   ax=axes[2], skew_angle=self.al_star)
        plt.show()
wilsonlabucsb commented 1 year ago

Also, there is a type error that doesn't have any help text.

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[16], line 3
      1 fig, axes = plt.subplots(1, 3)
      2 # Plot the background and subtracted
----> 3 plot_slice(data[data.axes[0]], data[data.axes[1]],
      4            data[:, :, 0.0][data.signal].nxdata - p.background[:, :, len(data[data.axes[2]]) // 2],
      5            ax=axes[0], skew_angle=p.ga_star)
      6 plot_slice(data[data.axes[0]], data[data.axes[2]],
      7            data[:, 0.0, :][data.signal] - p.background[:, len(data[data.axes[1]]) // 2, :],
      8            ax=axes[1], skew_angle=p.be_star)
      9 plot_slice(data[data.axes[1]], data[data.axes[2]],
     10            data[0.0, :, :][data.signal] - p.background[len(data[data.axes[0]]) // 2, :, :],
     11            ax=axes[2], skew_angle=p.al_star)

File ~\.conda\envs\nxsanalysis\Lib\site-packages\nxs_analysis_tools\datareduction.py:134, in plot_slice(data, X, Y, transpose, vmin, vmax, skew_angle, ax, xlim, ylim, xticks, yticks, cbar, logscale, symlogscale, cmap, linthresh, title, mdheading, cbartitle, **kwargs)
    132         data = data.transpose()
    133 else:
--> 134     raise TypeError
    136 data_arr = data[data.signal].nxdata.transpose()
    138 # Display Markdown heading

TypeError: