def test_smooth_window(): """Test smooth_window with default configuration.""" hght = [[5640., 5640., 5640., 5640., 5640.], [5684., 5676., 5666., 5659., 5651.], [5728., 5712., 5692., 5678., 5662.], [5772., 5748., 5718., 5697., 5673.], [5816., 5784., 5744., 5716., 5684.]] * units.m smoothed = smooth_window(hght, np.array([[1, 0, 1], [0, 0, 0], [1, 0, 1]])) truth = [[5640., 5640., 5640., 5640., 5640.], [5684., 5675., 5667.5, 5658.5, 5651.], [5728., 5710., 5695., 5677., 5662.], [5772., 5745., 5722.5, 5695.5, 5673.], [5816., 5784., 5744., 5716., 5684.]] * units.m assert_array_almost_equal(smoothed, truth)
def test_smooth_window_1d_dataarray(): """Test smooth_window on 1D DataArray.""" temperature = xr.DataArray( [37., 32., 34., 29., 28., 24., 26., 24., 27., 30.], dims=('time',), coords={'time': pd.date_range('2020-01-01', periods=10, freq='H')}, attrs={'units': 'degF'}) smoothed = smooth_window(temperature, window=np.ones(3) / 3, normalize_weights=False) truth = xr.DataArray( [37., 34.33333333, 31.66666667, 30.33333333, 27., 26., 24.66666667, 25.66666667, 27., 30.] * units.degF, dims=('time',), coords={'time': pd.date_range('2020-01-01', periods=10, freq='H')} ) xr.testing.assert_allclose(smoothed, truth)
def test_smooth_window(array_type): """Test smooth_window with default configuration.""" hght = np.array([[5640., 5640., 5640., 5640., 5640.], [5684., 5676., 5666., 5659., 5651.], [5728., 5712., 5692., 5678., 5662.], [5772., 5748., 5718., 5697., 5673.], [5816., 5784., 5744., 5716., 5684.]]) mask = np.zeros_like(hght) mask[::2, ::2] = 1 hght = array_type(hght, 'meter', mask=mask) smoothed = smooth_window(hght, np.array([[1, 0, 1], [0, 0, 0], [1, 0, 1]])) truth = array_type([[5640., 5640., 5640., 5640., 5640.], [5684., 5675., 5667.5, 5658.5, 5651.], [5728., 5710., 5695., 5677., 5662.], [5772., 5745., 5722.5, 5695.5, 5673.], [5816., 5784., 5744., 5716., 5684.]], 'meter') assert_array_almost_equal(smoothed, truth)
def test_smooth_window_with_bad_window(): """Test smooth_window with a bad window size.""" temperature = [37, 32, 34, 29, 28, 24, 26, 24, 27, 30] * units.degF with pytest.raises(ValueError) as exc: smooth_window(temperature, np.ones(4)) assert 'must be odd in all dimensions' in str(exc)
ax[0, 1].imshow(mpcalc.smooth_gaussian(raw_data, 8), vmin=0, vmax=1) ax[0, 1].set_title('Gaussian - High Degree') # Rectangular Smoother ax[0, 2].imshow(mpcalc.smooth_rectangular(raw_data, (3, 7), 2), vmin=0, vmax=1) ax[0, 2].set_title('Rectangular - 3x7 Window\n2 Passes') # 5-point smoother ax[1, 0].imshow(mpcalc.smooth_n_point(raw_data, 5, 1), vmin=0, vmax=1) ax[1, 0].set_title('5-Point - 1 Pass') ax[1, 1].imshow(mpcalc.smooth_n_point(raw_data, 5, 4), vmin=0, vmax=1) ax[1, 1].set_title('5-Point - 4 Passes') # Circular Smoother ax[1, 2].imshow(mpcalc.smooth_circular(raw_data, 2, 2), vmin=0, vmax=1) ax[1, 2].set_title('Circular - Radius 2\n2 Passes') # 9-point smoother ax[2, 0].imshow(mpcalc.smooth_n_point(raw_data, 9, 1), vmin=0, vmax=1) ax[2, 0].set_title('9-Point - 1 Pass') ax[2, 1].imshow(mpcalc.smooth_n_point(raw_data, 9, 4), vmin=0, vmax=1) ax[2, 1].set_title('9-Point - 4 Passes') # Arbitrary Window Smoother ax[2, 2].imshow(mpcalc.smooth_window(raw_data, np.diag(np.ones(5)), 2), vmin=0, vmax=1) ax[2, 2].set_title('Custom Window (Diagonal) \n2 Passes') plt.show()