guiwitz / napari-sediment

https://guiwitz.github.io/napari-sediment/napari_sediment.html
BSD 3-Clause "New" or "Revised" License
0 stars 1 forks source link

Error while Spectral Indices plotting #38

Closed Epta13 closed 4 months ago

Epta13 commented 5 months ago

Once I computed all the indices and I changed the colour schemes to what I wanted to be on the final plot; I couldn't generate the final plot.

This is the error:

ValueError Traceback (most recent call last) File ~/mambaforge/envs/sediment/lib/python3.9/site-packages/napari_sediment/spectral_indices_widget.py:621, in SpectralIndexWidget.create_index_plot(self=, event=False) 618 toplot = toplot.compute() 620 format_dict = asdict(self.paramsplots) --> 621 , self.ax1, self.ax2, self.ax3 = plot_spectral_profile( self.ax1 = self.ax2 = self.ax3 = self = <napari_sediment.spectral_indices_widget.SpectralIndexWidget object at 0x15bd28430> rgb_image = [<class 'numpy.ndarray'> (12271, 842) uint16, <class 'numpy.ndarray'> (12271, 842) uint16, <class 'numpy.ndarray'> (12271, 842) uint16] toplot = <class 'numpy.ndarray'> (12271, 842) float32 self.qcom_indices = <PyQt5.QtWidgets.QComboBox object at 0x16a04a820> format_dict = {'left_right_margin_fraction': 0.8999999999999999, 'bottom_top_margin_fraction': 0.17, 'plot_image_w_fraction': 0.25, 'title_font_factor': 0.01, 'label_font_factor': 0.0, 'color_plotline': [0.0, 0.0, 1.0], 'plot_thickness': 1.0, 'figure_size_factor': 10.0, 'scale_font_size': 1, 'index_colormap': {'RABD715': 'green', 'RABD670': 'I Forest', 'RABD845': 'I Purple', 'RABD620': 'I Blue'}, 'red_conrast_limits': [165.0, 1452.0], 'green_conrast_limits': [171.0, 1128.0], 'blue_conrast_limits': [206.0, 926.0], 'rgb_bands': [640, 545, 460]} self.params.scale = 1.0 self.params = Param(project_path='/Volumes/Jotunheimr/PER23_test_core/PER23_21_23_results', file_path='/Volumes/Jotunheimr/PER23_test_core/PER23_21-22_A_240219-153654/capture/PER23_21-22_A_240219-153654.hdr', white_path='/Volumes/Jotunheimr/PER23_test_core/PER23_21-22_A_WR_240219-171858/capture/WHITEREF_PER23_21-22_A_WR_240219-171858.hdr', dark_for_im_path='/Volumes/Jotunheimr/PER23_test_core/PER23_21-22_A_240219-153654/capture/DARKREF_PER23_21-22_A_240219-153654.hdr', dark_for_white_path='/Volumes/Jotunheimr/PER23_test_core/PER23_21-22_A_WR_240219-171858/capture/DARKREF_PER23_21-22_A_WR_240219-171858.hdr', main_roi=[[804.0, 222.0, 13075.0, 222.0, 13075.0, 1064.0, 804.0, 1064.0]], rois=[[804.0, 670.0, 13075.0, 670.0, 13075.0, 690.0, 804.0, 690.0]], scale=1.0, location='No location', rgb=[640, 545, 460]) self.params.location = 'No location' self.index_plot_live = <napari_matplotlib.base.NapariMPLWidget object at 0x16a0d13a0> self.viewer = Viewer(camera=Camera(center=(0.0, 6590.320473736677, -254.06125631756186), zoom=0.0760697774705801, angles=(0.0, 0.0, 90.0), perspective=0.0, mouse_pan=True, mouse_zoom=True), cursor=Cursor(position=(1.0, 13919.117723334175, 8573.360507185516), scaled=True, size=1, style=<CursorStyle.STANDARD: 'standard'>), dims=Dims(ndim=3, ndisplay=2, last_used=0, range=((0.0, 3.0, 1.0), (0.0, 12273.257103457227, 1.0), (0.0, 842.0, 1.0)), current_step=(1, 6135, 420), order=(0, 1, 2), axis_labels=('0', '1', '2')), grid=GridCanvas(stride=1, shape=(-1, -1), enabled=False), layers=[<Image layer 'imcube' at 0x159e25400>, <Image layer 'red' at 0x16a23e340>, <Image layer 'green' at 0x157bd6430>, <Image layer 'blue' at 0x16d309e50>, <Image layer 'RABD715' at 0x16a0f2220>, <Shapes layer 'rois' at 0x30cf3fcd0>, <Image layer 'RABD670' at 0x16e13bf10>, <Image layer 'RABD845' at 0x16e05d4f0>, <Image layer 'RABD620' at 0x16a0e3490>, <Labels layer 'mask' at 0x16bc4fca0>], help='use <2> for transform', status={'layer_base': 'RABD620', 'source_type': '', 'plugin': '', 'coordinates': ' [13919 8573]'}, tooltip=Tooltip(visible=False, text=''), theme='dark', title='napari', mouse_over_canvas=True, mouse_move_callbacks=[], mouse_drag_callbacks=[], mouse_double_click_callbacks=[<bound method SpectralIndexWidget._add_analysis_roi of <napari_sediment.spectral_indices_widget.SpectralIndexWidget object at 0x15bd28430>>], mouse_wheel_callbacks=[<function dims_scroll at 0x146850430>], _persisted_mouse_event={}, _mouse_drag_gen={}, _mouse_wheel_gen={}, keymap={}) 622 rgb_image=rgb_image, index_image=toplot, index_name=self.qcom_indices.currentText(), 623 format_dict=format_dict, scale=self.params.scale, 624 location=self.params.location, fig=self.index_plot_live.figure, 625 roi=self.viewer.layers['rois'].data[0]) 627 # save temporary low-res figure for display in napari 628 self.index_plot_live.figure.savefig( 629 self.export_folder.joinpath('temp.png'), 630 dpi=self.spin_preview_dpi.value())#, bbox_inches="tight")

File ~/mambaforge/envs/sediment/lib/python3.9/site-packages/napari_sediment/spectralplot.py:33, in plot_spectral_profile(rgb_image=[<class 'numpy.ndarray'> (12271, 842) uint16, <class 'numpy.ndarray'> (12271, 842) uint16, <class 'numpy.ndarray'> (12271, 842) uint16], index_image=<class 'numpy.ndarray'> (12271, 842) float32, index_name='RABD620', format_dict={'blue_conrast_limits': [206.0, 926.0], 'bottom_top_margin_fraction': 0.17, 'color_plotline': [0.0, 0.0, 1.0], 'figure_size_factor': 10.0, 'green_conrast_limits': [171.0, 1128.0], 'index_colormap': {'RABD620': 'I Blue', 'RABD670': 'I Forest', 'RABD715': 'green', 'RABD845': 'I Purple'}, 'label_font_factor': 0.0, 'left_right_margin_fraction': 0.8999999999999999, 'plot_image_w_fraction': 0.25, 'plot_thickness': 1.0, ...}, scale=1.0, location='No location', fig=<Figure size 168.424x1000 with 3 Axes>, roi=<class 'numpy.ndarray'> (4, 2) float64) 31 else: 32 newmap = Colormap(colormaps.ALL_COLORMAPS['viridis'].colors) ---> 33 mpl_map = newmap.to_matplotlib() newmap = Colormap(name='custom colormap', <2 colors>) 35 rgb_to_plot = rgb_image.copy() 36 rgb_toplot, , , = colorify.multichannel_to_rgb( 37 rgb_to_plot, 38 cmaps=['pure_red', 'pure_green', 'pure_blue'], 39 rescale_type='limits', 40 limits=[red_conrast_limits, green_conrast_limits, blue_conrast_limits], 41 proj_type='sum')

File ~/mambaforge/envs/sediment/lib/python3.9/site-packages/cmap/_colormap.py:467, in Colormap.to_matplotlib(self=Colormap(name='custom colormap', <2 colors>), N=256, gamma=1.0) 463 def to_matplotlib( 464 self, N: int = 256, gamma: float = 1.0 465 ) -> matplotlib.colors.Colormap: 466 """Return a matplotlib colormap.""" --> 467 return _external.to_mpl(self, N=N, gamma=gamma) self = Colormap(name='custom colormap', <2 colors>) _external = <module 'cmap._external' from '/Users/petrazahajska/mambaforge/envs/sediment/lib/python3.9/site-packages/cmap/_external.py'> N = 256 gamma = 1.0

File ~/mambaforge/envs/sediment/lib/python3.9/site-packages/cmap/_external.py:30, in to_mpl(cm=Colormap(name='custom colormap', <2 colors>), N=256, gamma=1.0) 28 if cm.interpolation == "nearest": 29 return mplc.ListedColormap(colors=cm.color_stops.color_array, name=cm.name) ---> 30 return mplc.LinearSegmentedColormap.from_list( mplc = <module 'matplotlib.colors' from '/Users/petrazahajska/mambaforge/envs/sediment/lib/python3.9/site-packages/matplotlib/colors.py'> cm.name = 'custom colormap' cm.color_stops = ColorStops( (0.0, Color('white')), (1.0, Color((0.0, 0.2, 0.8))) ) cm = Colormap(name='custom colormap', <2 colors>) N = 256 gamma = 1.0 31 cm.name, cm.color_stops, N=N, gamma=gamma 32 )

File ~/mambaforge/envs/sediment/lib/python3.9/site-packages/matplotlib/colors.py:1067, in LinearSegmentedColormap.from_list(name='custom colormap', colors=(Color('white'), Color((0.0, 0.2, 0.8))), N=256, gamma=1.0) 1063 vals = np.linspace(0, 1, len(colors)) 1065 r, g, b, a = to_rgba_array(colors).T 1066 cdict = { -> 1067 "red": np.column_stack([vals, r, r]), vals = (0.0, 1.0) r = <class 'numpy.ndarray'> (4,) float64 np.column_stack = <function column_stack at 0x102e4b330> [vals, r, r] = [(0.0, 1.0), <class 'numpy.ndarray'> (4,) float64, <class 'numpy.ndarray'> (4,) float64] np = <module 'numpy' from '/Users/petrazahajska/mambaforge/envs/sediment/lib/python3.9/site-packages/numpy/init.py'> g = <class 'numpy.ndarray'> (4,) float64 [vals, g, g] = [(0.0, 1.0), <class 'numpy.ndarray'> (4,) float64, <class 'numpy.ndarray'> (4,) float64] b = <class 'numpy.ndarray'> (4,) float64 [vals, b, b] = [(0.0, 1.0), <class 'numpy.ndarray'> (4,) float64, <class 'numpy.ndarray'> (4,) float64] a = <class 'numpy.ndarray'> (4,) float64 [vals, a, a] = [(0.0, 1.0), <class 'numpy.ndarray'> (4,) float64, <class 'numpy.ndarray'> (4,) float64] 1068 "green": np.column_stack([vals, g, g]), 1069 "blue": np.column_stack([vals, b, b]), 1070 "alpha": np.column_stack([vals, a, a]), 1071 } 1073 return LinearSegmentedColormap(name, cdict, N, gamma)

File ~/mambaforge/envs/sediment/lib/python3.9/site-packages/numpy/lib/shape_base.py:652, in column_stack(tup=[(0.0, 1.0), <class 'numpy.ndarray'> (4,) float64, <class 'numpy.ndarray'> (4,) float64]) 650 arr = array(arr, copy=False, subok=True, ndmin=2).T 651 arrays.append(arr) --> 652 return _nx.concatenate(arrays, 1) arrays = [<class 'numpy.ndarray'> (2, 1) float64, <class 'numpy.ndarray'> (4, 1) float64, <class 'numpy.ndarray'> (4, 1) float64] _nx.concatenate = <function concatenate at 0x101be8af0> _nx = <module 'numpy.core.numeric' from '/Users/petrazahajska/mambaforge/envs/sediment/lib/python3.9/site-packages/numpy/core/numeric.py'>

ValueError: all the input array dimensions except for the concatenation axis must match exactly, but along dimension 0, the array at index 0 has size 2 and the array at index 1 has size 4

Epta13 commented 5 months ago
guiwitz commented 5 months ago

Not only do the plots work a bit, but saving always rewrites the previously saved plot. We need an option where the name of the plot can be selected.

Plots should be saved with the name of the index. Should we still add an option to rename?

Also, the A4 format needs to be added, as we discussed.

This should be taken care of by 45d45a9. The defaults should be much better now. Font sizes correspond now to the expected definitions.

The colour scale of the map is somehow weird. Is the range of the RABD somehow scaled to the range of the colour palette?

This can now be adjusted by first adding the map to the viewer, adjusting the contrast and then generating the plot. Via 26fd8c2

Additionally, the colour of the RABD map cannot be saved for each index and selected for the plotting. It takes viridis by default for every plot.

Similarly to the contrast, the colormap can be adjusted via the viewer. The same colormap should be then used in the plot.