-
Notifications
You must be signed in to change notification settings - Fork 11
Add time series duration check and corresponding tests #627
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Conversation
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added my review, could you also add a CHANGELOG entry?
| return None | ||
|
|
||
|
|
||
| @register_check(importance=Importance.CRITICAL, neurodata_type=TimeSeries) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be critical or a best practice violation?
tests/unit_tests/test_time_series.py
Outdated
| def test_check_rate_not_below_threshold_fail_period_like_value(): | ||
| """Test detection when period was likely used instead of rate.""" | ||
| # If someone uses 2.0 thinking it's a 2 second period, the rate should be 0.5 Hz | ||
| period_value = 2.0 | ||
| time_series = pynwb.TimeSeries( | ||
| name="test_time_series", | ||
| unit="test_units", | ||
| data=np.zeros(shape=100), | ||
| starting_time=0.0, | ||
| rate=period_value, | ||
| ) | ||
| result = check_rate_not_below_threshold(time_series) | ||
| # Should pass with default threshold since 2.0 > 0.01 | ||
| assert result is None | ||
|
|
||
| # But should fail with a custom threshold | ||
| result = check_rate_not_below_threshold(time_series, low_rate_threshold=5.0) | ||
| assert result is not None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| def test_check_rate_not_below_threshold_fail_period_like_value(): | |
| """Test detection when period was likely used instead of rate.""" | |
| # If someone uses 2.0 thinking it's a 2 second period, the rate should be 0.5 Hz | |
| period_value = 2.0 | |
| time_series = pynwb.TimeSeries( | |
| name="test_time_series", | |
| unit="test_units", | |
| data=np.zeros(shape=100), | |
| starting_time=0.0, | |
| rate=period_value, | |
| ) | |
| result = check_rate_not_below_threshold(time_series) | |
| # Should pass with default threshold since 2.0 > 0.01 | |
| assert result is None | |
| # But should fail with a custom threshold | |
| result = check_rate_not_below_threshold(time_series, low_rate_threshold=5.0) | |
| assert result is not None |
I think this test covers the same behavior as the test above and below?
tests/unit_tests/test_time_series.py
Outdated
| result = check_time_series_duration(time_series) | ||
| assert result is not None | ||
| assert "long_time_series" in result.message | ||
| assert "exceeds the threshold" in result.message | ||
| assert result.importance == Importance.BEST_PRACTICE_SUGGESTION |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you update these to be checked against the full inspector message? Similarly in the other tests.
e.g. check_time_series_duration(time_series) == InspectorMessage(...
| one_year = 31557600.0 | ||
| rate = 1.0 # 1 Hz | ||
| num_samples = int(one_year + 1000) # More than 1 year worth of samples | ||
| time_series = pynwb.TimeSeries( | ||
| name="long_time_series", | ||
| unit="test_units", | ||
| data=np.zeros(shape=num_samples), | ||
| starting_time=0.0, | ||
| rate=rate, | ||
| ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We might want to avoid creating a large array here just for tests, could lower the rate instead to minimize the number of samples
| """ | ||
| Check if the TimeSeries duration is longer than the specified threshold. | ||
| The default threshold is 1 year (31,557,600 seconds = 365.25 days). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason for the year long threshold? I imagine anything longer than a month or two could be worth flagging since it is a best practice suggestion.
Co-authored-by: Steph Prince <[email protected]>
Co-authored-by: Steph Prince <[email protected]>
Co-authored-by: Steph Prince <[email protected]>
Co-authored-by: Steph Prince <[email protected]>
for more information, see https://pre-commit.ci
Co-authored-by: Steph Prince <[email protected]>
for more information, see https://pre-commit.ci
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## dev #627 +/- ##
==========================================
+ Coverage 73.03% 76.91% +3.88%
==========================================
Files 47 47
Lines 1587 1616 +29
==========================================
+ Hits 1159 1243 +84
+ Misses 428 373 -55
🚀 New features to boost your workflow:
|
related to #626