-
Notifications
You must be signed in to change notification settings - Fork 61
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
[ENH] Incomplete tile warning #245
Closed
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
376f7e1
incomplete tile warning
ryanhammonds 08b0158
review update
ryanhammonds 8a6de1e
move warning to note
ryanhammonds d7325fc
update note text
TomDonoghue 68f79cd
add util func to check osc_def
TomDonoghue 5f5d9db
add tests for check_osc_def
TomDonoghue File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 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,30 @@ | ||
"""Utility functions for simulations.""" | ||
|
||
################################################################################################### | ||
################################################################################################### | ||
|
||
def check_osc_def(n_seconds, fs, freq): | ||
"""Check whether a requested oscillation definition will have an integer number of cycles. | ||
|
||
Parameters | ||
---------- | ||
n_seconds : float | ||
Simulation time, in seconds. | ||
fs : float | ||
Signal sampling rate, in Hz. | ||
freq : float | ||
Oscillation frequency. | ||
|
||
Returns | ||
------- | ||
bool | ||
Whether the definition will have an integer number of cycles. | ||
""" | ||
|
||
# Sampling rate check: check if the number of samples per cycle is an integer | ||
srate_check = (fs/freq).is_integer() | ||
|
||
# Time check: check if signal length matches an integer number of cycles | ||
time_check = (n_seconds * freq).is_integer() | ||
|
||
return srate_check and time_check |
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,24 @@ | ||
"""Tests for neurodsp.sim.utils.""" | ||
|
||
from neurodsp.sim.utils import * | ||
|
||
################################################################################################### | ||
################################################################################################### | ||
|
||
def test_check_osc_def(): | ||
|
||
n_seconds = 1.0 | ||
fs = 100 | ||
freq = 10 | ||
|
||
# Check definition that should pass | ||
assert check_osc_def(n_seconds, fs, freq) | ||
|
||
# Check a definition that should fail the sampling rate check | ||
assert not check_osc_def(1.05, fs, freq) | ||
|
||
# Check a definition that should fail the time check | ||
assert not check_osc_def(n_seconds, 1111, freq) | ||
|
||
# Check a definition that should fail both checks | ||
assert not check_osc_def(1.05, 1111, freq) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 truncation always an issue? This example seems to produce an appropriate spectrum:
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.
huh, great catch!
So yeh, this time check isn't super specific. Whether the number of cycles leads to funky PSD is a bit more complex than this check - it depends on the actual spectral estimation that is done (for example, with Welchs, I think it depends on the segment size (
nperseg
), and how this relates to the signal, more than the details of the total signal. Because of this, I think we should probably just entirely drop this time check, since I otherwise don't really know how to make it more specific (we can't predict the spectral estimation people will do - and this emphasizes that the details of the resulting PSD are somewhat contextual - not fully determined by the sim'd time series).