Skip to content
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

added filtering #83

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open

added filtering #83

wants to merge 6 commits into from

Conversation

lylyhan
Copy link

@lylyhan lylyhan commented Jul 28, 2020

added lowpass, highpass, bandpass, randomized filtering functionalities, and their corresponding testing functions

@jatinkhilnani jatinkhilnani mentioned this pull request Jul 28, 2020
@bmcfee
Copy link
Owner

bmcfee commented Jul 30, 2020

Thanks @lylyhan ! Can you fix the merge conflicts before we start a code review? Either way of doing it is fine (web editor or command line). Let me know if you need assistance getting it sorted out.

tests/test_deformers.py Outdated Show resolved Hide resolved
tests/test_deformers.py Outdated Show resolved Hide resolved
tests/test_deformers.py Outdated Show resolved Hide resolved
tests/test_deformers.py Outdated Show resolved Hide resolved
muda/deformers/filter.py Outdated Show resolved Hide resolved
tests/test_deformers.py Outdated Show resolved Hide resolved
@lylyhan
Copy link
Author

lylyhan commented Aug 3, 2020

OK! i revised all suggestions above (replaced already implemented functions, revised __test_xx_filter series, corrected the messed up merge), pytest now pass on all functions.
please review :)

__all__ = ["Filter", "RandomLPFilter", "RandomHPFilter","RandomBPFilter"]


def checkfreqinband(freq,state,datatype):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a docstring for this function, explaining what its inputs should be and what it returns? See _get_rng for an example of how that sort of thing should look.

)

@staticmethod
def filter_class(annotation, state):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should leave pitch_class annotations unchanged. Pitch classes don't have octave information, so it's impossible to tell what frequency they actually correspond to, and whether or not they lie in the passband of the filter.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I checked https://jams.readthedocs.io/en/stable/namespace.html#pitch-class again and seems like the "tonic" and "pitch" keys together did specify octave information?(for example C7 is convertible to a specific frequency in hz)


Examples
--------
>>> # Shift down by a quarter-tone
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comment seems incorrect / copypasta here

self.order = order
self.attenuation = attenuation
if self.btype == "bandpass":
if type(cutoff) == tuple:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

checking type(x) == y is an anti-pattern.

Instead, say isinstance(cutoff, tuple). (Similarly for following lines)

if all(len(i) == 2 for i in cutoff): # [[a,b],[c,d]]
self.cutoff = [tuple(c) for c in cutoff]
else:
raise ValueError("bandpass filter cutoff must be tuple or list of tuples")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not check this first (outside of checking btype) so you don't have multiple copies of this exception?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i designed the cutoff variable format to be btype-specific (when btype == bandpass, take list of tuples, tuple or list of length-2 lists; when btype==others, take list of floats or one float), so i can't really check its format outside of knowing what btype it is.. The repetitive exception is each corresponding to a different case: first one is when input is a list of lists of not necessarily length 2, second one is when input is a list of neither tuples nor lists, third one is when input is neither a list nor a tuple. Maybe i should change the name of the exception accordingly to avoid appearing to be repetitive?


Examples
--------
>>> # Shift down by a quarter-tone
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

another copypasta


Examples
--------
>>> # Shift down by a quarter-tone
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

copypasta

raise ValueError("n_samples must be None or positive")

if order <= 0 or attenuation <= 0:
raise ValueError("order and attenuation must be None or positive")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if None is a valid value, checking order <= 0 will raise a type error. You need to handle Nones separately:

if order is not None and order <= 0:
    ...

It's also not good style to combine two tests and then raise a single exception, because a user then has to figure out which of the two tests failed. Better to factor these out into separate conditional statements.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants