-
Notifications
You must be signed in to change notification settings - Fork 110
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 n-dimensional unwrap #198
Merged
Merged
Changes from 12 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
ada5cc5
add n-dimensional unwrap
4e7e5e3
Deprecate old unwrap signature
64dce79
Merge branch 'master' into unwrap
platawiec c35ecc0
Add depwarn detail
162dab0
Merge branch 'unwrap' of https://github.com/platawiec/DSP.jl into unwrap
947238c
Merge #199 into #201
32cc545
Improve docstring/interface
7a4f937
Fix typos
5b5b810
Fix type-instability
c50e824
interface updates
185faed
Fix 0.7 depwarns
de70b85
Clean docstrings
0eb073f
Fix docstring typos
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
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
Large diffs are not rendered by default.
Oops, something went wrong.
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
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,140 @@ | ||
using DSP, Compat, Compat.Test | ||
|
||
@testset "Unwrap 1D" begin | ||
@test unwrap([0.1, 0.2, 0.3, 0.4]) ≈ [0.1, 0.2, 0.3, 0.4] | ||
@test unwrap([0.1, 0.2 + 2pi, 0.3, 0.4]) ≈ [0.1, 0.2, 0.3, 0.4] | ||
@test unwrap([0.1, 0.2 - 2pi, 0.3, 0.4]) ≈ [0.1, 0.2, 0.3, 0.4] | ||
@test unwrap([0.1, 0.2 - 2pi, 0.3 - 2pi, 0.4]) ≈ [0.1, 0.2, 0.3, 0.4] | ||
@test unwrap([0.1 + 2pi, 0.2, 0.3, 0.4]) ≈ [0.1 + 2pi, 0.2 + 2pi, 0.3 + 2pi, 0.4 + 2pi] | ||
@test unwrap([0.1, 0.2 + 6pi, 0.3, 0.4]) ≈ [0.1, 0.2, 0.3, 0.4] | ||
|
||
test_v = [0.1, 0.2, 0.3 + 2pi, 0.4] | ||
res_v = unwrap(test_v) | ||
@test test_v ≈ [0.1, 0.2, 0.3 + 2pi, 0.4] | ||
res_v .= 0 | ||
unwrap!(res_v, test_v) | ||
@test res_v ≈ [0.1, 0.2, 0.3, 0.4] | ||
@test test_v ≈ [0.1, 0.2, 0.3 + 2pi, 0.4] | ||
unwrap!(test_v) | ||
@test test_v ≈ [0.1, 0.2, 0.3, 0.4] | ||
|
||
# test unwrapping within multi-dimensional array | ||
wrapped = [0.1, 0.2 + 2pi, 0.3, 0.4] | ||
unwrapped = [0.1, 0.2, 0.3, 0.4] | ||
wrapped = hcat(wrapped, wrapped) | ||
unwrapped = hcat(unwrapped, unwrapped) | ||
@test unwrap(wrapped, dims=2) ≈ wrapped | ||
@test unwrap(wrapped, dims=1) ≈ unwrapped | ||
@test unwrap!(copy(wrapped), dims=2) ≈ wrapped | ||
@test unwrap!(copy(wrapped), dims=1) ≈ unwrapped | ||
|
||
# this should eventually default to the multi-dimensional case | ||
@test_throws ArgumentError unwrap!(similar(wrapped), wrapped) | ||
|
||
# test unwrapping with other ranges | ||
unwrapped = [1.0:100;] | ||
wrapped = Float64[i % 10 for i in unwrapped] | ||
@test unwrap(wrapped, range=10) ≈ unwrapped | ||
|
||
# test generically typed unwrapping | ||
types = (Float32, Float64, BigFloat) | ||
for T in types | ||
srand(1234) | ||
A_unwrapped = collect(Compat.range(0, stop=4convert(T, π), length=10)) | ||
A_wrapped = A_unwrapped .% (2convert(T, π)) | ||
|
||
@test unwrap(A_wrapped) ≈ A_unwrapped | ||
unwrap!(A_wrapped) | ||
@test A_wrapped ≈ A_unwrapped | ||
|
||
A_unwrapped_range = collect(Compat.range(0, stop=4, length=10)) | ||
test_range = convert(T, 2) | ||
A_wrapped_range = A_unwrapped_range .% test_range | ||
@test unwrap(A_wrapped_range; range=test_range) ≈ A_unwrapped_range | ||
end | ||
end | ||
|
||
# tests for multi-dimensional unwrapping | ||
@testset "Unwrap 2D" begin | ||
types = (Float32, Float64, BigFloat) | ||
for T in types | ||
srand(1234) | ||
v_unwrapped = collect(Compat.range(0, stop=4convert(T, π), length=7)) | ||
A_unwrapped = v_unwrapped .+ v_unwrapped' | ||
A_wrapped = A_unwrapped .% (2convert(T, π)) | ||
|
||
test_unwrapped = unwrap(A_wrapped, dims=1:2) | ||
d = first(A_unwrapped) - first(test_unwrapped) | ||
@test (test_unwrapped .+ d) ≈ A_unwrapped | ||
unwrap!(A_wrapped, dims=1:2) | ||
d = first(A_unwrapped) - first(A_wrapped) | ||
@test (A_wrapped .+ d) ≈ A_unwrapped | ||
|
||
v_unwrapped_range = collect(Compat.range(0, stop=4, length=7)) | ||
A_unwrapped_range = v_unwrapped_range .+ v_unwrapped_range' | ||
test_range = convert(T, 2) | ||
A_wrapped_range = A_unwrapped_range .% test_range | ||
|
||
test_unwrapped_range = unwrap(A_wrapped_range, dims=1:2; range=test_range) | ||
d = first(A_unwrapped_range) - first(test_unwrapped_range) | ||
@test (test_unwrapped_range .+ d) ≈ A_unwrapped_range | ||
|
||
# Test circular_dims | ||
# after unwrapping, pixels at borders should be equal to corresponding pixels | ||
# on other side | ||
circular_dims = (true, true) | ||
wa_vec = Compat.range(0, stop=4convert(T, π), length=10) | ||
wa_uw = wa_vec .+ zeros(10)' | ||
# make periodic | ||
wa_uw[end, :] = wa_uw[1, :] | ||
wa_w = wa_uw .% (2π) | ||
wa_test = unwrap(wa_w, dims=1:2, circular_dims=circular_dims, rng=MersenneTwister(0)) | ||
# with wrap-around, the borders should be equal, but for this problem the | ||
# image may not be recovered exactly | ||
@test wa_test[:, 1] ≈ wa_test[:, end] | ||
@test wa_test[end, :] ≈ wa_test[1, :] | ||
# In this case, calling unwrap w/o circular_dims does not recover the borders | ||
wa_test_nowa = unwrap(wa_w, dims=1:2) | ||
@test !(wa_test_nowa[end, :] ≈ wa_test_nowa[1, :]) | ||
|
||
end | ||
end | ||
|
||
@testset "Unwrap 3D" begin | ||
types = (Float32, Float64, BigFloat) | ||
f(x, y, z) = 0.1x^2 - 2y + 2z | ||
f_wraparound2(x, y, z) = 5*sin(x) + 2*cos(y) + z | ||
f_wraparound3(x, y, z) = 5*sin(x) + 2*cos(y) - 4*cos(z) | ||
for T in types | ||
grid = Compat.range(zero(T), stop=2convert(T, π), length=11) | ||
f_uw = f.(grid, grid', reshape(grid, 1, 1, :)) | ||
f_wr = f_uw .% (2convert(T, π)) | ||
uw_test = unwrap(f_wr, dims=1:3) | ||
offset = first(f_uw) - first(uw_test) | ||
@test (uw_test.+offset) ≈ f_uw rtol=eps(T) #oop, nowrap | ||
# test in-place version | ||
unwrap!(f_wr, dims=1:3) | ||
offset = first(f_uw) - first(f_wr) | ||
@test (f_wr.+offset) ≈ f_uw rtol=eps(T) #ip, nowrap | ||
|
||
f_uw = f_wraparound2.(grid, grid', reshape(grid, 1, 1, :)) | ||
f_wr = f_uw .% (2convert(T, π)) | ||
uw_test = unwrap(f_wr, dims=1:3) | ||
offset = first(f_uw) - first(uw_test) | ||
@test (uw_test.+offset) ≈ f_uw #oop, 2wrap | ||
# test in-place version | ||
unwrap!(f_wr, dims=1:3, circular_dims=(true, true, false)) | ||
offset = first(f_uw) - first(f_wr) | ||
@test (f_wr.+offset) ≈ f_uw #ip, 2wrap | ||
|
||
f_uw = f_wraparound3.(grid, grid', reshape(grid, 1, 1, :)) | ||
f_wr = f_uw .% (2convert(T, π)) | ||
uw_test = unwrap(f_wr, dims=1:3, circular_dims=(true, true, true)) | ||
offset = first(f_uw) - first(uw_test) | ||
@test (uw_test.+offset) ≈ f_uw #oop, 3wrap | ||
# test in-place version | ||
unwrap!(f_wr, dims=1:3, circular_dims=(true, true, true)) | ||
offset = first(f_uw) - first(f_wr) | ||
@test (f_wr.+offset) ≈ f_uw #oop, 3wrap | ||
end | ||
end | ||
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
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.
IIUC,
calculate_pixel_reliability
is special-cased for 2d and 3d. So maybe even test for even more dimensions?