Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plotting of NDCube and NDCubeSequence is failing #187

Closed
yashrsharma44 opened this issue Jul 17, 2019 · 0 comments · Fixed by #189
Closed

Plotting of NDCube and NDCubeSequence is failing #187

yashrsharma44 opened this issue Jul 17, 2019 · 0 comments · Fixed by #189
Labels

Comments

@yashrsharma44
Copy link
Member

yashrsharma44 commented Jul 17, 2019

Description

When we perform plotting of NDCube and NDCubeSequence object, the plotting is breaking in some weird ways.

Expected behavior

The extra keywords such as axes_coordinates and plot_axis_indices should not cause NDCube plotting to break.

Actual behavior

On initializing the NDCube objects from the docs and performing plotting using the keywords plot_axis_indices=0 or plot_axis_indices=1, it breaks up without performing the plotting.

Here is a traceback when I perform my_cube[0].plot(plot_axis_indices=0)
Traceback

---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
<ipython-input-7-a17e3408b1c5> in <module>
----> 1 my_cube[0].plot(plot_axis_indices=1)

~/nd/ndcube/ndcube/mixins/plotting.py in plot(self, axes, plot_axis_indices, axes_coordinates, axes_units, data_unit, **kwargs)
     77                 ax = self._animate_cube_1D(
     78                     plot_axis_index=plot_axis_indices[0], axes_coordinates=axes_coordinates,
---> 79                     axes_units=axes_units, data_unit=data_unit, **kwargs)
     80             else:
     81                 if naxis == 2:

~/nd/ndcube/ndcube/mixins/plotting.py in _animate_cube_1D(self, plot_axis_index, axes_coordinates, axes_units, data_unit, **kwargs)
    391         ax = LineAnimator(data, plot_axis_index=plot_axis_index, axis_ranges=axes_coordinates,
    392                           xlabel=default_xlabel,
--> 393                           ylabel="Data [{0}]".format(data_unit), **kwargs)
    394         return ax
    395 

~/nd/vnv/lib/python3.7/site-packages/sunpy/visualization/animator/line.py in __init__(self, data, plot_axis_index, axis_ranges, ylabel, xlabel, xlim, ylim, aspect, **kwargs)
    100             # supplied by the user for the plotted axis.
    101             self.xdata = edges_to_centers_nd(np.asarray(axis_ranges[self.plot_axis_index]),
--> 102                                              plot_axis_index)
    103         if ylim is None:
    104             ylim = (data.min(), data.max())

~/nd/vnv/lib/python3.7/site-packages/sunpy/visualization/animator/base.py in edges_to_centers_nd(axis_range, edges_axis)
    584     """
    585     upper_edge_indices = [slice(None)] * axis_range.ndim
--> 586     upper_edge_indices[edges_axis] = slice(1, axis_range.shape[edges_axis])
    587     upper_edges = axis_range[tuple(upper_edge_indices)]
    588 

IndexError: tuple index out of range

For NDCubeSequence, this is also not working properly my_sequence.plot(axes_coordinates=[None, "time", None, None]) .
Traceback

---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
<ipython-input-17-315da964f63e> in <module>
----> 1 my_sequence.plot(axes_coordinates=[None, "time", None, None])

~/nd/ndcube/ndcube/mixins/sequence_plotting.py in plot(self, axes, plot_axis_indices, axes_coordinates, axes_units, data_unit, **kwargs)
    122                     ax = ImageAnimatorNDCubeSequence(
    123                         self, plot_axis_indices=plot_axis_indices,
--> 124                         axes_coordinates=axes_coordinates, axes_units=axes_units, **kwargs)
    125 
    126         return ax

~/nd/ndcube/ndcube/mixins/sequence_plotting.py in __init__(self, seq, wcs, axes, plot_axis_indices, axes_coordinates, axes_units, data_unit, **kwargs)
    740             data_stack, wcs=new_wcs, image_axes=plot_axis_indices, axis_ranges=axes_coordinates,
    741             unit_x_axis=axes_units[plot_axis_indices[0]],
--> 742             unit_y_axis=axes_units[plot_axis_indices[1]], **kwargs)
    743 
    744 

~/nd/vnv/lib/python3.7/site-packages/sunpy/visualization/animator/image.py in __init__(self, data, wcs, image_axes, unit_x_axis, unit_y_axis, axis_ranges, **kwargs)
    171         self.unit_x_axis = unit_x_axis
    172         self.unit_y_axis = unit_y_axis
--> 173         super().__init__(data, image_axes=image_axes, axis_ranges=axis_ranges, **kwargs)
    174 
    175     def _get_main_axes(self):

~/nd/vnv/lib/python3.7/site-packages/sunpy/visualization/animator/image.py in __init__(self, data, image_axes, axis_ranges, **kwargs)
     53         self._non_regular_plot_axis = False
     54         # Run init for parent class
---> 55         super().__init__(data, image_axes=image_axes, axis_ranges=axis_ranges, **kwargs)
     56 
     57     def plot_start_image(self, ax):

~/nd/vnv/lib/python3.7/site-packages/sunpy/visualization/animator/base.py in __init__(self, data, image_axes, axis_ranges, **kwargs)
    426             raise ValueError("Number of image and slider axes do not match total number of axes.")
    427 
--> 428         self.axis_ranges, self.extent = self._sanitize_axis_ranges(axis_ranges, data.shape)
    429 
    430         # create data slice

~/nd/vnv/lib/python3.7/site-packages/sunpy/visualization/animator/base.py in _sanitize_axis_ranges(self, axis_ranges, data_shape)
    543             elif len(axis_ranges[i]) == data_shape[i]+1:
    544                 # If array of individual pixel edges supplied, convert to pixel centers.
--> 545                 axis_ranges[i] = edges_to_centers_nd(np.asarray(axis_ranges[i]), i)
    546             else:
    547                 raise ValueError(incompatible_axis_ranges_error_message(i))

~/nd/vnv/lib/python3.7/site-packages/sunpy/visualization/animator/base.py in edges_to_centers_nd(axis_range, edges_axis)
    584     """
    585     upper_edge_indices = [slice(None)] * axis_range.ndim
--> 586     upper_edge_indices[edges_axis] = slice(1, axis_range.shape[edges_axis])
    587     upper_edges = axis_range[tuple(upper_edge_indices)]
    588 

IndexError: tuple index out of range

The axes_coordinates with some str parameter doesn't seem to be working for >2D NDCubes.

my_cube[:,0].plot(axes_coordinates=["time", None])

Traceback

--------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-63-9fa8379b19d0> in <module>
----> 1 my_cube[:,0].plot(axes_coordinates=["time", None])
      2 # my_cube.data.shape

~/ndcub/ndcube/ndcube/mixins/plotting.py in plot(self, axes, plot_axis_indices, axes_coordinates, axes_units, data_unit, **kwargs)
     82                 if naxis == 2:
     83                     ax = self._plot_2D_cube(axes, plot_axis_indices, axes_coordinates,
---> 84                                             axes_units, data_unit, **kwargs)
     85                 else:
     86                     ax = self._plot_3D_cube(

~/ndcub/ndcube/ndcube/mixins/plotting.py in _plot_2D_cube(self, axes, plot_axis_indices, axes_coordinates, axes_units, data_unit, **kwargs)
    252                                 new_axes_coordinates[plot_axis_indices[1]][-1]), **kwargs)
    253                 im_ax.set_data(new_axes_coordinates[plot_axis_indices[0]],
--> 254                                new_axes_coordinates[plot_axis_indices[1]], data)
    255                 ax.add_image(im_ax)
    256                 # Set the limits, labels, etc. of the axes.

~/ndcub/vnv/lib/python3.7/site-packages/matplotlib/image.py in set_data(self, x, y, A)
    961         A = cbook.safe_masked_invalid(A, copy=True)
    962         if not (x.ndim == y.ndim == 1 and A.shape[0:2] == y.shape + x.shape):
--> 963             raise TypeError("Axes don't match array shape")
    964         if A.ndim not in [2, 3]:
    965             raise TypeError("Can only plot 2D or 3D data")

TypeError: Axes don't match array shape

Steps to Reproduce

The example code has been taken from ndcube docs

Extra information

The plotting of NDCube object seems to be breaking on giving the arguments such as plot_axis_indices and axes_coordinates

System Details

  • ndcube Version: 1.1.1
  • SunPy Version: 1.0.2
  • Python Version: 3.7
  • OS information: Ubuntu 16.04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant