-
Notifications
You must be signed in to change notification settings - Fork 28
notch for Patch #448
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
notch for Patch #448
Conversation
|
Hey @d-chambers, please review and let me know what you think at your convenience. Also, I wonder how I can adjust the |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #448 +/- ##
=======================================
Coverage 99.84% 99.84%
=======================================
Files 114 114
Lines 9184 9203 +19
=======================================
+ Hits 9170 9189 +19
Misses 14 14
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
d-chambers
left a comment
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.
Looks ok, just a few things to tweak on the docstring stuff.
dascore/proc/filter.py
Outdated
| patch | ||
| The patch to filter | ||
| samples | ||
| {sample_explination} |
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.
Where is sample_explination coming from? You would have to use the compose_docstring in utils.docs to make this work. Also, I don't really see how samples is to be used in this function. Could you maybe add an example?
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.
Since this is a filter, we actually do not need the samples argument. So, I deleted this from docs.
Probably the easiest thing to do for the units is to pull from dascore.units import get_inverted_quant
from dascore.utils.time import to_float
size, axes = _create_size_fw_and_axes(patch, kwargs)
data = patch.data
for coord_name, info in get_multiple_dim_value_from_kwargs(patch, kwargs).items():
dim, ax, value = info['dim'], info['axis'], info['value']
coord = patch.get_coord(coord_name, required_evenly_sampled=True) # will also raise if not evenly sampled.
# Invert units if needed
inverted_units = False
if isinstance(value, dc.units.Quantity) and coord.units is not None:
value, inverted_units = get_inverted_quant(value, coord.units)
# Check valid parameters
sr, value = to_float(coord), to_float(value)
nyquist = 0.5 * sr
if w0 > nyquist:
msg = f"possible filter values are in [0, {nyquist}] you passed {w0}"
raise FilterValueError(msg)
b, a = iirnotch(value, Q=q, fs=sr)
data = filtfilt(b, a, data, axis=ax)note: the imports should be at the top of the module, just put them here for reference. |
Thanks for this explanation, Derrick! I'm unsure why the |
So the function returns the correctly inverted quantity but just the boolean is wrong? Yes, I suppose we should fix it, hopefully it hasn't caused issues elsewhere. Sorry about the linter failing. It has to do with newer versions of to pip I think. I will push a fix in a few minutes. |
Actually, looking closer I think it is correct, just a bit confusing. With filtering we do expect the dimensionality of inputs to the be inverse of the coordinate units. For example, for the time dimension (seconds) we expect the filter parameters to be the multiplicative inverse dimensionality (1/seconds, Hz). So the second parameter returned from this function just indicates if the dimensionality of the filter argument were already the inverse dimensionality. Its probably safe to just ignore the second output parameter. |
d-chambers
left a comment
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.
Looks good @ahmadtourei, just double check the unit inversion stuff is right then merge when you are happy with it.
dascore/proc/filter.py
Outdated
| # Check valid parameters | ||
| if inverted_units: | ||
| w0 = to_float(value) | ||
| else: | ||
| w0 = to_float(1 / value) |
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.
hmmm... its a bit odd this is required. Doesn't get_inverted_quant already do this?
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.
Specifically here.
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.
Thanks for looking into this more closely. I did not initially understand the behavior of the get_inverted_quant function well. We actually don't need this. Please see my last commit (changed examples and a test) for further details.
|
closes #443. |
Description
This PR adds notch filtering functionality for
Patchas discussed in #443.Checklist
I have (if applicable):