示例#1
0
def plot_spectrum(spectrum_dict, xrange=(370, 730), yrange=(0, 100), smoothing=None, fig=None, ax=None):
    ''' Plots the spectrum.

    Args:
        xrange (`iterable`): pair of lower and upper x bounds.

        yrange (`iterable`): pair of lower and upper y bounds.

        smoothing (`float`): number of nanometers to smooth data by.  If None,
            do no smoothing.

        fig (`matplotlib.figure.Figure`): figure to plot in.

        ax (`matplotlib.axes.Axis`): axis to plot in.

    Returns:
        `tuple` containing:

            `matplotlib.figure.Figure`: figure containign the plot.

            `matplotlib.axes.Axis`: axis containing the plot.

    '''
    wvl, values = spectrum_dict['wvl'], spectrum_dict['values']
    if smoothing is not None:
        dx = wvl[1] - wvl[0]
        window_width = int(smoothing / dx)
        values = smooth(values, window_width, window='flat')

    lc = colorline(wvl, values, wvl, cmin=400, cmax=700, lw=5)
    fig, ax = share_fig_ax(fig, ax)
    ax.add_collection(lc)
    ax.set(xlim=xrange, xlabel=r'Wavelength $\lambda$ [nm]',
           ylim=yrange, ylabel='Transmission [%]')

    return fig, ax
示例#2
0
def test_smooth_rejects_window_bigger_than_array():
    window_length = 5
    arr_len = 2
    arr = np.empty((arr_len))
    with pytest.raises(ValueError):
        util.smooth(arr, window_len=window_length)
示例#3
0
def test_smooth_rejects_2d():
    arr = np.empty((2, 2))
    with pytest.raises(ValueError):
        util.smooth(arr)
示例#4
0
def test_smooth_rejects_wrong_window():
    with pytest.raises(ValueError):
        arr = np.empty(4)
        util.smooth(arr, window='foo')
示例#5
0
def test_smooth_doesnt_change_constant_arrays(val, window):
    arr = np.ones((ARR_SIZE)) * val
    assert np.allclose(util.smooth(arr, window=window), arr)