-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Loading status checks…
make dow configurable for input data and weekly aggregated data
Showing
3 changed files
with
148 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
# numpydoc ignore=GL08 | ||
|
||
import jax.numpy as jnp | ||
import pytest | ||
|
||
from pyrenew.convolve import daily_to_weekly, daily_to_mmwr_epiweekly | ||
|
||
|
||
def test_daily_to_weekly_no_offset(): | ||
""" | ||
Tests that the function correctly aggregates | ||
daily values into weekly totals when there | ||
is no offset both input and output start dow on Monday. | ||
""" | ||
daily_values = jnp.arange(1, 15) | ||
result = daily_to_weekly(daily_values) | ||
expected = jnp.array([28, 77]) | ||
assert jnp.array_equal(result, expected) | ||
|
||
|
||
def test_daily_to_weekly_with_input_data_offset(): | ||
""" | ||
Tests that the function correctly aggregates | ||
daily values into weekly totals with dow | ||
offset in the input data. | ||
""" | ||
daily_values = jnp.arange(1, 15) | ||
result = daily_to_weekly(daily_values, input_data_first_dow=2) | ||
expected = jnp.array([63]) | ||
assert jnp.array_equal(result, expected) | ||
|
||
|
||
def test_daily_to_weekly_with_different_week_start(): | ||
""" | ||
Tests aggregation when the desired week start | ||
differs from the input data start. | ||
""" | ||
daily_values = jnp.arange(1, 15) | ||
result = daily_to_weekly(daily_values, input_data_first_dow=2, week_start_dow=5) | ||
expected = jnp.array([49]) | ||
assert jnp.array_equal(result, expected) | ||
|
||
|
||
def test_daily_to_weekly_incomplete_week(): | ||
""" | ||
Tests that the function raises a | ||
ValueError when there are | ||
insufficient daily values to | ||
form a complete week. | ||
""" | ||
daily_values = jnp.arange(1, 5) | ||
with pytest.raises(ValueError, match="No complete weekly values available"): | ||
daily_to_weekly(daily_values, input_data_first_dow=0) | ||
|
||
|
||
def test_daily_to_weekly_missing_daily_values(): | ||
""" | ||
Tests that the function correctly | ||
aggregates the available daily values | ||
into weekly values when there are | ||
fewer daily values than required for | ||
complete weekly totals. | ||
""" | ||
daily_values = jnp.arange(1, 10) | ||
result = daily_to_weekly(daily_values, input_data_first_dow=0) | ||
expected = jnp.array([28]) | ||
assert jnp.array_equal(result, expected) | ||
|
||
|
||
def test_daily_to_weekly_invalid_offset(): | ||
""" | ||
Tests that the function raises a | ||
ValueError when the offset is | ||
outside the valid range (0-6). | ||
""" | ||
daily_values = jnp.arange(1, 15) | ||
with pytest.raises( | ||
ValueError, match="First day of the week must be between 0 and 6." | ||
): | ||
daily_to_weekly(daily_values, input_data_first_dow=-1) | ||
|
||
with pytest.raises( | ||
ValueError, match="First day of aggregated data must be between 0 and 6." | ||
): | ||
daily_to_weekly(daily_values, week_start_dow=7) | ||
|
||
|
||
def test_daily_to_mmwr_epiweekly(): | ||
""" | ||
Tests aggregation for MMWR epidemiological week. | ||
""" | ||
daily_values = jnp.arange(1, 15) | ||
result = daily_to_mmwr_epiweekly(daily_values) | ||
expected = jnp.array([70]) | ||
assert jnp.array_equal(result, expected) |