-
Notifications
You must be signed in to change notification settings - Fork 18
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
Dev small checks in merging #171
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
d72f652
Perform simple time checks before merging 2 single ended to double ended
bdestombe 884b4fd
Ensure times are align during merge of two channels
bdestombe 023f6d3
More documentation
bdestombe 39a3d9e
Better docs
bdestombe a55b0bc
Bug in merge_double_ended_times
bdestombe 219b7f4
Added test to merge_double_ended_times
bdestombe 0525b61
test_merge_double_ended_times() now makes use of pytest pameterize
bdestombe 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 |
---|---|---|
|
@@ -637,3 +637,65 @@ def test_merge_double_ended(): | |
result = (ds.isel(time=0).st - ds.isel(time=0).rst).sum().values | ||
|
||
np.testing.assert_approx_equal(result, -3712866.0382, significant=10) | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"inotinfw, inotinbw, inotinout", | ||
[ | ||
([], [], []), | ||
([1], [], [1]), | ||
([], [1], [1]), | ||
([1], [1], [1]), | ||
([1, 2], [], [1, 2]), | ||
([], [1, 2], [1, 2]), | ||
([1], [2], [1, 2]), | ||
pytest.param([2], [1], [1, 2], marks=pytest.mark.xfail) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice :D |
||
]) | ||
def test_merge_double_ended_times(inotinfw, inotinbw, inotinout): | ||
""" | ||
Arguments are the indices not included in resp fw measurements, bw measurements, | ||
and merged output. | ||
|
||
If all measurements are recorded: fw_t0, bw_t0, fw_t1, bw_t1, fw_t2, bw_t2, .. | ||
> all are passed | ||
|
||
If some are missing the accompanying measurement is skipped: | ||
- fw_t0, bw_t0, bw_t1, fw_t2, bw_t2, .. > fw_t0, bw_t0, fw_t2, bw_t2, .. | ||
- fw_t0, bw_t0, fw_t1, fw_t2, bw_t2, .. > fw_t0, bw_t0, fw_t2, bw_t2, .. | ||
- fw_t0, bw_t0, bw_t1, fw_t2, fw_t3, bw_t3, .. > fw_t0, bw_t0, fw_t3, bw_t3, | ||
|
||
Mixing forward and backward channels can be problematic when there is a pause | ||
after measuring all channels. This function is not perfect as the following | ||
situation is not caught: | ||
- fw_t0, bw_t0, fw_t1, bw_t2, fw_t3, bw_t3, .. | ||
> fw_t0, bw_t0, fw_t1, bw_t2, fw_t3, bw_t3, .. | ||
|
||
This routine checks that the lowest channel | ||
number is measured first (aka the forward channel), but it doesn't catch the | ||
last case as it doesn't know that fw_t1 and bw_t2 belong to different cycles. | ||
Any ideas are welcome. | ||
""" | ||
filepath_fw = data_dir_double_single_ch1 | ||
filepath_bw = data_dir_double_single_ch2 | ||
cable_length = 2017.7 | ||
|
||
ds_fw = read_silixa_files(directory=filepath_fw) | ||
ds_bw = read_silixa_files(directory=filepath_bw) | ||
|
||
# set stokes to varify proper time alignment | ||
ds_fw.st.values = np.tile(np.arange(ds_fw.time.size)[None], (ds_fw.x.size, 1)) | ||
ds_bw.st.values = np.tile(np.arange(ds_bw.time.size)[None], (ds_bw.x.size, 1)) | ||
|
||
# transform time index that is not included in: fw, bw, merged, to the ones included | ||
ifw = list(i for i in range(6) if i not in inotinfw) | ||
ibw = list(i for i in range(6) if i not in inotinbw) | ||
iout = list(i for i in range(6) if i not in inotinout) | ||
|
||
ds = merge_double_ended( | ||
ds_fw.isel(time=ifw), | ||
ds_bw.isel(time=ibw), | ||
cable_length=cable_length, | ||
plot_result=False, | ||
verbose=False) | ||
assert ds.time.size == len(iout) and np.all(ds.st.isel(x=0) == iout), \ | ||
f"FW:{ifw} & BW:{ibw} should lead to {iout} but instead leads to {ds.st.isel(x=0).values}" |
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.
Could you add a test for this?
You can then also add an xfail for the uncaught situation :)
Pytest's parameterize might come in useful for this to keep the test short.
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.
Great idea! Just implemented it.