Exemplo n.º 1
0
Arquivo: line.py Projeto: zimmaz/sunpy
    def __init__(self,
                 data,
                 plot_axis_index=-1,
                 axis_ranges=None,
                 ylabel=None,
                 xlabel=None,
                 xlim=None,
                 ylim=None,
                 aspect='auto',
                 **kwargs):
        # Check inputs.
        self.plot_axis_index = int(plot_axis_index)
        if self.plot_axis_index not in range(-data.ndim, data.ndim):
            raise ValueError(
                "plot_axis_index must be within range of number of data dimensions"
                " (or equivalent negative indices).")
        if data.ndim < 2:
            raise ValueError(
                "data must have at least two dimensions. One for data "
                "for each single plot and at least one for time/iteration.")
        # Define number of slider axes.
        self.naxis = data.ndim
        self.num_sliders = self.naxis - 1
        # Attach data to class.
        if axis_ranges is not None and all(axis_range is None
                                           for axis_range in axis_ranges):
            axis_ranges = None
        if axis_ranges is None or axis_ranges[self.plot_axis_index] is None:
            self.xdata = np.arange(data.shape[self.plot_axis_index])
        # Else derive the xdata as pixel centers from the pixel edges supplied by
        # the user in axis_ranges[plot_axis_index]
        else:
            # If the shape of the array is a 1D array, get the centers about axis=0
            if np.asarray(axis_ranges[self.plot_axis_index]).ndim == 1:
                self.xdata = edges_to_centers_nd(
                    np.asarray(axis_ranges[self.plot_axis_index]), 0)

            # Else derive the xdata as pixel centers from the pixel edges supplied by
            # the user in axis_ranges[plot_axis_index] along axis=plot_axis_index
            else:
                self.xdata = edges_to_centers_nd(
                    np.asarray(axis_ranges[self.plot_axis_index]),
                    plot_axis_index)
        if ylim is None:
            ylim = (data.min(), data.max())
        if xlim is None:
            xlim = (self.xdata.min(), self.xdata.max())
        self.ylim = ylim
        self.xlim = xlim
        self.xlabel = xlabel
        self.ylabel = ylabel
        self.aspect = aspect
        # Run init for base class
        super().__init__(data,
                         image_axes=[self.plot_axis_index],
                         axis_ranges=axis_ranges,
                         **kwargs)
Exemplo n.º 2
0
 def __init__(self, data, plot_axis_index=-1, axis_ranges=None, ylabel=None, xlabel=None,
              xlim=None, ylim=None, aspect='auto', **kwargs):
     # Check inputs.
     self.plot_axis_index = int(plot_axis_index)
     if self.plot_axis_index not in range(-data.ndim, data.ndim):
         raise ValueError("plot_axis_index must be within range of number of data dimensions"
                          " (or equivalent negative indices).")
     if data.ndim < 2:
         raise ValueError("data must have at least two dimensions. One for data "
                          "for each single plot and at least one for time/iteration.")
     # Define number of slider axes.
     self.naxis = data.ndim
     self.num_sliders = self.naxis-1
     # Attach data to class.
     if axis_ranges is not None and all(axis_range is None for axis_range in axis_ranges):
         axis_ranges = None
     if axis_ranges is None or axis_ranges[self.plot_axis_index] is None:
         self.xdata = np.arange(data.shape[self.plot_axis_index])
     else:
         # Else derive the xdata as the centers of the pixel/bin edges
         # supplied by the user for the plotted axis.
         self.xdata = edges_to_centers_nd(np.asarray(axis_ranges[self.plot_axis_index]),
                                          plot_axis_index)
     if ylim is None:
         ylim = (data.min(), data.max())
     if xlim is None:
         xlim = (self.xdata.min(), self.xdata.max())
     self.ylim = ylim
     self.xlim = xlim
     self.xlabel = xlabel
     self.ylabel = ylabel
     self.aspect = aspect
     # Run init for base class
     super().__init__(data, image_axes=[self.plot_axis_index], axis_ranges=axis_ranges,
                      **kwargs)
Exemplo n.º 3
0
def test_edges_to_centers_nd():
    edges_axis = 0
    axis_range = np.zeros((10, 2))
    axis_range[:, 0] = np.arange(10, 20)
    expected = np.zeros((9, 2))
    expected[:, edges_axis] = np.arange(10.5, 19)
    output = base.edges_to_centers_nd(axis_range, edges_axis)
    assert np.array_equal(output, expected)
Exemplo n.º 4
0
def test_edges_to_centers_nd():
    edges_axis = 0
    axis_range = np.zeros((10, 2))
    axis_range[:, 0] = np.arange(10, 20)
    expected = np.zeros((9,2))
    expected[:, edges_axis] = np.arange(10.5, 19)
    output = base.edges_to_centers_nd(axis_range, edges_axis)
    assert np.array_equal(output, expected)
Exemplo n.º 5
0
        super().update_plot(val, artist, slider)


axis_ranges1 = np.tile(np.linspace(0, 100, 21), (10, 1))


@pytest.mark.parametrize(
    'axis_ranges, exp_extent, exp_axis_ranges',
    [([None, None], [-0.5, 19.5], [np.arange(10),
                                   np.array([-0.5, 19.5])]),
     ([[0, 10], [0, 20]], [0, 20], [np.arange(0.5, 10.5),
                                    np.asarray([0, 20])]),
     ([np.arange(0, 11), np.arange(0, 21)], [0, 20],
      [np.arange(0.5, 10.5), np.arange(0.5, 20.5)]),
     ([None, axis_ranges1], [0.0, 100.0],
      [np.arange(10), base.edges_to_centers_nd(axis_ranges1, 1)])])
def test_sanitize_axis_ranges(axis_ranges, exp_extent, exp_axis_ranges):
    data_shape = (10, 20)
    data = np.random.rand(*data_shape)
    aanim = ArrayAnimatorTest(data=data)
    out_axis_ranges, out_extent = aanim._sanitize_axis_ranges(
        axis_ranges=axis_ranges, data_shape=data_shape)
    assert exp_extent == out_extent
    assert np.array_equal(exp_axis_ranges[1], out_axis_ranges[1])
    assert callable(out_axis_ranges[0])
    assert np.array_equal(exp_axis_ranges[0],
                          out_axis_ranges[0](np.arange(10)))


XDATA = np.tile(np.linspace(0, 100, 11), (5, 5, 1))
                                      unit=u.pix).value.astype(int)
new_x_axis_coords3_shape[-1] = 1
none_axis_ranges_axis3 = [
    np.arange(0, len(seq.data)),
    np.array([0., 1.]),
    np.arange(0, 3),
    np.tile(np.array(x_axis_coords3), new_x_axis_coords3_shape)
]
none_axis_ranges_axis0 = [
    np.arange(len(seq.data)),
    np.array([0., 1.]),
    np.arange(0, 3),
    np.arange(0, int(seq.dimensions[-1].value))
]
distance0_none_axis_ranges_axis0 = \
    [edges_to_centers_nd(_get_extra_coord_edges(seq.sequence_axis_extra_coords["distance"].value), 0),
     np.array([0., 1.]), np.arange(0, 3),
     np.arange(0, int(seq.dimensions[-1].value))]
distance0_none_axis_ranges_axis0_mm = \
    [edges_to_centers_nd(_get_extra_coord_edges(seq.sequence_axis_extra_coords["distance"].to(
        "mm").value), 0), np.array([0., 1.]), np.arange(0, 3), np.arange(0, int(seq.dimensions[-1].value))]
userrangequantity_none_axis_ranges_axis0 = [
    np.arange(int(seq.dimensions[0].value)),
    np.array([0., 1.]),
    np.arange(0, 3),
    np.arange(0, int(seq.dimensions[-1].value))
]

userrangequantity_none_axis_ranges_axis0_1e7 = [
    (np.arange(int(seq.dimensions[0].value)) * u.J).to(u.erg).value,
    np.array([0., 1.]),
Exemplo n.º 7
0
axis_ranges1 = np.tile(np.linspace(0, 100, 21), (10, 1))


@pytest.mark.parametrize('axis_ranges, exp_extent, exp_axis_ranges',
                         [([None, None], [-0.5, 19.5],
                          [np.arange(10), np.array([-0.5, 19.5])]),

                          ([[0, 10], [0, 20]], [0, 20],
                          [np.arange(0.5, 10.5), np.asarray([0, 20])]),

                          ([np.arange(0, 11), np.arange(0, 21)], [0, 20],
                          [np.arange(0.5, 10.5), np.arange(0.5, 20.5)]),

                          ([None, axis_ranges1], [0.0, 100.0],
                          [np.arange(10), base.edges_to_centers_nd(axis_ranges1, 1)])])
def test_sanitize_axis_ranges(axis_ranges, exp_extent, exp_axis_ranges):
    data_shape = (10, 20)
    data = np.random.rand(*data_shape)
    aanim = ArrayAnimatorTest(data=data)
    out_axis_ranges, out_extent = aanim._sanitize_axis_ranges(axis_ranges=axis_ranges,
                                                              data_shape=data_shape)
    assert exp_extent == out_extent
    assert np.array_equal(exp_axis_ranges[0], out_axis_ranges[0])
    assert np.array_equal(exp_axis_ranges[1], out_axis_ranges[1])


xdata = np.tile(np.linspace(0, 100, 11), (5, 5, 1))


@pytest.mark.parametrize('plot_axis_index, axis_ranges, xlabel, xlim',