Пример #1
0
def test_array_animator_wcs_2d_colorbar_buttons(wcs_4d):
    data = np.arange(120).reshape((5, 4, 3, 2))
    bf = [lambda x: x] * 10
    bl = ['h'] * 10
    a = ArrayAnimatorWCS(data, wcs_4d, [0, 0, 'y', 'x'],
                         colorbar=True, button_func=bf, button_labels=bl)
    a.update_plot(1, a.im, a.sliders[0]._slider)
    return a.fig
Пример #2
0
def test_array_animator_wcs_2d_extra_sliders(wcs_4d):
    def vmin_slider(val, im, slider):
        im.set_clim(vmin=val)

    def vmax_slider(val, im, slider):
        im.set_clim(vmax=val)

    data = np.arange(120).reshape((5, 4, 3, 2))
    a = ArrayAnimatorWCS(data, wcs_4d, [0, 0, 'y', 'x'], colorbar=True,
                         slider_functions=[vmin_slider, vmax_slider],
                         slider_ranges=[[0, 100], [0, 100]])
    a.update_plot(1, a.im, a.sliders[0]._slider)
    return a.fig
Пример #3
0
def test_construct_array_animator(wcs_4d, data, slices, dim):
    if dim == 1:
        pytest.importorskip("astropy", minversion="4.0dev26173")

    array_animator = ArrayAnimatorWCS(data, wcs_4d, slices)

    assert isinstance(array_animator, ArrayAnimatorWCS)
    assert array_animator.plot_dimensionality == dim
    assert array_animator.num_sliders == data.ndim - dim
    for i, (wslice,
            arange) in enumerate(zip(slices,
                                     array_animator.axis_ranges[::-1])):
        if wslice not in ['x', 'y']:
            assert callable(arange)
            a = arange(0)
            if "pos" in wcs_4d.world_axis_physical_types[i]:
                assert isinstance(a, u.Quantity)
                assert u.allclose(a, 0 * u.pix)
            else:
                assert isinstance(a, u.Quantity)
                assert a.value == wcs_4d.pixel_to_world_values(
                    *[0] * wcs_4d.world_n_dim)[i]
                assert a.unit == wcs_4d.world_axis_units[i]
        else:
            assert arange is None
Пример #4
0
def test_constructor_errors(wcs_4d):
    # WCS is not BaseLowLevelWCS
    with pytest.raises(ValueError, match="provided that implements the astropy WCS API."):
        ArrayAnimatorWCS(np.arange(25).reshape((5, 5)), {}, ['x', 'y'])

    # Data has wrong number of dimensions
    with pytest.raises(ValueError, match="Dimensionality of the data and WCS object do not match."):
        ArrayAnimatorWCS(np.arange(25).reshape((5, 5)), wcs_4d, ['x', 'y'])

    # Slices is wrong length
    with pytest.raises(ValueError, match="slices should be the same length"):
        ArrayAnimatorWCS(np.arange(16).reshape((2, 2, 2, 2)), wcs_4d, ['x', 'y'])

    # x not in slices
    with pytest.raises(ValueError, match="slices should contain at least"):
        ArrayAnimatorWCS(np.arange(16).reshape((2, 2, 2, 2)), wcs_4d, [0, 0, 0, 'y'])
Пример #5
0
def test_array_animator_wcs_coord_params_no_ticks(wcs_4d):

    coord_params = {
        'hpln': {
            'format_unit': u.deg,
            'major_formatter': 'hh:mm:ss',
            'axislabel': 'Longitude',
            'ticks': False
        }
    }

    data = np.arange(120).reshape((5, 4, 3, 2))
    a = ArrayAnimatorWCS(data, wcs_4d, [0, 0, 'x', 'y'], coord_params=coord_params)
    return a.fig
Пример #6
0
def test_array_animator_wcs_coord_params_grid(wcs_4d):
    pytest.importorskip("astropy", minversion="4.0dev26173")

    coord_params = {
        'hpln': {
            'format_unit': u.deg,
            'major_formatter': 'hh:mm:ss',
            'axislabel': 'Longitude',
            'grid': True
        }
    }

    data = np.arange(120).reshape((5, 4, 3, 2))
    a = ArrayAnimatorWCS(data, wcs_4d, [0, 0, 'x', 'y'], coord_params=coord_params)
    return a.fig
Пример #7
0
def test_array_animator_wcs_1d_update_plot_masked(wcs_3d):
    """
    This test ensures the x axis of the line plot is correct even if the whole
    of the initial line plotted at construction of the animator is masked out.
    """

    nelem = np.prod(wcs_3d.array_shape)
    data = np.arange(nelem, dtype=np.float64).reshape(wcs_3d.array_shape)
    data = np.ma.MaskedArray(data, data < nelem / 2)

    # Check that the generated data satisfies the test condition
    assert data.mask[0, 0].all()

    a = ArrayAnimatorWCS(data, wcs_3d, ['x', 0, 0], ylabel="Y axis!")
    a.sliders[0]._slider.set_val(wcs_3d.array_shape[0] / 2)

    return a.fig
Пример #8
0
def test_array_animator_wcs_2d_clip_interval_change(wcs_4d):
    data = np.arange(120).reshape((5, 4, 3, 2))
    pclims = [5, 95]
    a = ArrayAnimatorWCS(data,
                         wcs_4d, [0, 0, 'x', 'y'],
                         clip_interval=pclims * u.percent)
    lims0 = a._get_2d_plot_limits()
    a.update_plot(1, a.im, a.sliders[0]._slider)
    lims1 = a._get_2d_plot_limits()
    assert np.all(lims0 != lims1)
    assert np.all(lims0 == np.percentile(data[..., 0, 0], pclims))
    assert np.all(lims1 == np.percentile(data[..., 1, 0], pclims))
Пример #9
0
def test_array_animator_wcs_1d_update_plot(wcs_4d):
    data = np.arange(120).reshape((5, 4, 3, 2))
    a = ArrayAnimatorWCS(data, wcs_4d, [0, 0, 'x', 0], ylabel="Y axis!")
    a.sliders[0]._slider.set_val(1)
    return a.fig
Пример #10
0
def test_array_animator_wcs_2d_transpose_update_plot(wcs_4d):
    data = np.arange(120).reshape((5, 4, 3, 2))
    a = ArrayAnimatorWCS(data, wcs_4d, [0, 0, 'y', 'x'], colorbar=True)
    a.update_plot(1, a.im, a.sliders[0]._slider)
    return a.fig
Пример #11
0
def test_to_axes(wcs_4d):
    data = np.arange(120).reshape((5, 4, 3, 2))
    a = ArrayAnimatorWCS(data, wcs_4d, ['x', 'y', 0, 0])
    assert isinstance(a.axes, WCSAxes)
Пример #12
0
def test_array_animator_wcs_2d_celestial_sliders(wcs_4d):
    data = np.arange(120).reshape((5, 4, 3, 2))
    a = ArrayAnimatorWCS(data, wcs_4d, ['x', 'y', 0, 0])
    return a.fig
Пример #13
0
def test_array_animator_wcs_2d_clip_interval(wcs_4d):
    data = np.arange(120).reshape((5, 4, 3, 2))
    a = ArrayAnimatorWCS(data,
                         wcs_4d, [0, 0, 'x', 'y'],
                         clip_interval=(1, 99) * u.percent)
    return a.fig
Пример #14
0
def test_array_animator_wcs_2d_simple_plot(wcs_4d):
    data = np.arange(120).reshape((5, 4, 3, 2))
    a = ArrayAnimatorWCS(data, wcs_4d, [0, 0, 'x', 'y'])
    return a.fig
Пример #15
0
def test_array_animator_wcs_1d_update_plot(wcs_4d):
    pytest.importorskip("astropy", minversion="4.0dev26173")
    data = np.arange(120).reshape((5, 4, 3, 2))
    a = ArrayAnimatorWCS(data, wcs_4d, [0, 0, 'x', 0], ylabel="Y axis!")
    a.sliders[0]._slider.set_val(1)
    return a.fig