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

Add more tests to strax #359

Merged
merged 9 commits into from Dec 2, 2020
Merged

Add more tests to strax #359

merged 9 commits into from Dec 2, 2020

Conversation

JoranAngevaare
Copy link
Member

@JoranAngevaare JoranAngevaare commented Nov 30, 2020

What is the problem / what does the code in this PR do
Fix a slight mistake in #357 concerning the testing.

Further I've added some other tests while I was waiting on some computations to finish.

@JoranAngevaare JoranAngevaare changed the title fix loop plugin test Add more tests to strax Nov 30, 2020
@JoranAngevaare
Copy link
Member Author

afbeelding
This is what we like to see

Copy link
Collaborator

@WenzDaniel WenzDaniel left a comment

Choose a reason for hiding this comment

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

Looks mostly fine just some minor comments and suggestions. Took me a while to understand test_loop_plugin, but looks fine too.

@@ -3,7 +3,6 @@
import tempfile
import os
import os.path as osp

Copy link
Collaborator

Choose a reason for hiding this comment

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

?

Copy link
Member Author

Choose a reason for hiding this comment

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

there probably was an import statement during some point of the live time of this PR

:param chunks: list op numpy arrays to modify. Here we will drop some of the fields randomly
:return: list of chunks
Drop some of the data in the chunk
:param chunk: list op numpy arrays to modify. Here we will drop some
Copy link
Collaborator

Choose a reason for hiding this comment

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

typo op -> of?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Just to be sure, "chunk" refers here to chunk.data or must I convert a chunk object first into an array?

Copy link
Member Author

Choose a reason for hiding this comment

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

yeah, it's the chunk.data, also see the type specification in the function definition

Copy link
Member Author

Choose a reason for hiding this comment

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

let me smooth out the docstring a little


# Fill the peaks with random length data
for p in peaks:
length = np.random.randint(0, data_length)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I am wondering if it would not be nicer to have this already in the hypothesis itself for tracking reasons. You can also create a list of integers.

Copy link
Member Author

Choose a reason for hiding this comment

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

Can do but as I don't see the how this would affect thinks I consider it unlikely that we ever have to replicate on this specific point. Therefore, I will keep it as it is.

Copy link
Member Author

Choose a reason for hiding this comment

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

Turns out that this was a good comment though. See #363. Someday will rewrite this test in a similar way!

Comment on lines 33 to 37
p['data'] = wf

for i in range(length, len(wf)):
# Set all the out of length data to zero
wf[i] = 0.
Copy link
Collaborator

Choose a reason for hiding this comment

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

p['data'][:data_length] = wf does not work?

Copy link
Member Author

Choose a reason for hiding this comment

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

nope, I also found that strange. Perhaps my syntax was off or its because it's unjitted but yeah

Copy link
Collaborator

@WenzDaniel WenzDaniel Dec 1, 2020

Choose a reason for hiding this comment

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

Hmm okay this odd, because I was not sure and so I tried the following in a notebook before I made the comment

peaks = np.zeros(2, dtype=strax.peak_dtype())
for p in peaks:
    length = int(np.random.uniform(0, 20))
    data = np.random.uniform(0, 20, length)
    p['data'][:length] = data

Copy link
Member Author

Choose a reason for hiding this comment

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

Ok, so the Perhaps my syntax was off seems quite likely. Will change, thanks Daniel!

tests/test_peak_properties.py Show resolved Hide resolved
peaks = np.zeros(peak_length, dtype=dtype)
dt = 1
peaks['time'] = np.arange(peak_length)*dt
peaks['dt'][:] = dt
Copy link
Collaborator

Choose a reason for hiding this comment

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

peaks['dt'] = dt should work

Copy link
Member Author

Choose a reason for hiding this comment

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

sure

Comment on lines 80 to 84
p['data'] = wf

for i in range(length, len(wf)):
# Set all the out of length data to zero
wf[i] = 0.
Copy link
Collaborator

Choose a reason for hiding this comment

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

See comment above. In general I am wondering if it would not be easier to simply merge this test with the previous one. A lot of duplication in here.

Copy link
Member Author

Choose a reason for hiding this comment

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

Not impossible but I like the fact that the first test does test something whereon the second test is build.

Copy link
Collaborator

Choose a reason for hiding this comment

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

But this would be also the case if you join them no? But you would just initialize everything once and have less copy-paste code.

Copy link
Member Author

Choose a reason for hiding this comment

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

OK, will change the setup of the random peaks to a different function, you are right that there is some unnecessary duplication. My reasoning is that I don't mind that much if the tests are sometimes a little rough/slightly duplicate, it's already tedious enough to write them while being quite unrewarding ;).

But this would be also the case if you join them no

So the failure would be a little clearer because you split it over multiple functions with the name of what is being tested.

Copy link
Collaborator

Choose a reason for hiding this comment

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

it's already tedious enough to write them while being quite unrewarding ;).

Yes I know :D I feel with you. But it is our task to gently bully one another for a cleaner code.

OK, will change the setup of the random peaks to a different function,
So the failure would be a little clearer because you split it over multiple functions with the name of what is being tested.

Okay nice, in this way we get both.

Comment on lines +95 to +98
if np.sum(peaks['area'] > 0) > 10:
mess = ("Highly unlikely that from at least 10 positive area peaks "
"none were able to compute the width")
assert np.any(peaks['width'] != pre_peaks['width']), mess
Copy link
Collaborator

Choose a reason for hiding this comment

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

The test is very vague, but I can see the difficulty. Maybe we should add a simple unity test like:

data = np.ones(100)

*compute widths in 10% steps*

*check widths*

Copy link
Member Author

Choose a reason for hiding this comment

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

It's quite simple right? You just check that the widths were computed at all and not all 0.

@@ -39,3 +52,7 @@ def test_LocalMinimumSplitter():
assert len(my_splits) <= int(len(w) / 2) + 1
assert min(my_splits[:, 0]) == NO_MORE_SPLITS
assert my_splits[-1, 0] == NO_MORE_SPLITS

Copy link
Collaborator

Choose a reason for hiding this comment

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

L49, L50 would not >= work?

Copy link
Member Author

Choose a reason for hiding this comment

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

there has to be at least one NO_MORE_SPLITS right. You can also not split on the last entry.

EDIT: Oh wait the lines you are mentioning are different from the ones I'm seeing. But yeah, I tend to agree (although not really part of this PR but originally written by Tim: https://github.com/AxFoundation/strax/pull/267/files).

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes, sorry there was no other way to comment on this and it just stroke my eye.

@@ -112,12 +55,8 @@ def _loop_test_inner(big_data, nchunks, target='added_thing', force_value_error=

_dtype = big_data.dtype

# TODO smarter test. I want to drop some random data from the
Copy link
Collaborator

Choose a reason for hiding this comment

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

L39 typo to -> two

Copy link
Member Author

Choose a reason for hiding this comment

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

thanks

@JoranAngevaare JoranAngevaare marked this pull request as draft December 1, 2020 10:32
@JoranAngevaare JoranAngevaare marked this pull request as ready for review December 2, 2020 09:00
Copy link
Collaborator

@WenzDaniel WenzDaniel left a comment

Choose a reason for hiding this comment

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

Okay looks good.

@JoranAngevaare JoranAngevaare merged commit faf309c into master Dec 2, 2020
@JoranAngevaare JoranAngevaare deleted the loop_plugin_multioutput branch December 2, 2020 11:52
@JoranAngevaare JoranAngevaare linked an issue Dec 7, 2020 that may be closed by this pull request
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.

NB breaks test should be reproducible
2 participants