def test_amplitude_annual_cycle_add_year(annual_cycle_cube): """Test amplitude of annual cycle when year is not given in cube.""" assert not annual_cycle_cube.coords('year') amplitude_cube = amplitude(annual_cycle_cube, 'year') assert amplitude_cube.shape == (3, 4) assert amplitude_cube.coords('year') np.testing.assert_allclose(amplitude_cube.data, ANNUAL_CYCLE_AMPLITUDE) assert amplitude_cube.metadata == annual_cycle_cube.metadata
def test_amplitude_diurnal_cycle_add_coords(diurnal_cycle_cube): """Test amplitude of diurnal cycle when coords are not given in cube.""" assert not diurnal_cycle_cube.coords('day_of_year') assert not diurnal_cycle_cube.coords('year') amplitude_cube = amplitude(diurnal_cycle_cube, ['day_of_year', 'year']) assert amplitude_cube.shape == (730, ) assert amplitude_cube.coords('day_of_year') assert amplitude_cube.coords('year') np.testing.assert_allclose(amplitude_cube.data, DIURNAL_CYCLE_AMPLITUDE) assert amplitude_cube.metadata == diurnal_cycle_cube.metadata
def test_amplitude_fail_wrong_coord(annual_cycle_cube): """Test amplitude calculation when wrong coordinate is given.""" with pytest.raises(iris.exceptions.CoordinateNotFoundError): amplitude(annual_cycle_cube, ['year', 'invalid_coord'])