-
Notifications
You must be signed in to change notification settings - Fork 8
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
Api rework #34
Merged
halleysfifthinc
merged 64 commits into
halleysfifthinc:master
from
KronosTheLate:api_rework
Feb 28, 2024
Merged
Api rework #34
Changes from all commits
Commits
Show all changes
64 commits
Select commit
Hold shift + click to select a range
baa439e
Ignore autogenerated .vscode folder
KronosTheLate d235238
Make parent file for rework, define "findpeaks"
KronosTheLate ccb918e
implement api_rework as discussed
KronosTheLate 5cb66c3
Remove test code from Peaks.jl
KronosTheLate 80b8280
Update readme to temp state
KronosTheLate 7609635
Add sentence about mutation to todo section
KronosTheLate 24e3892
add sentence about minima finding
KronosTheLate aac8d5a
Remove temporary content from readme
KronosTheLate 9ccd30a
make `findpeaks` a oneliner
KronosTheLate 4a0d9dc
Don't discard initially calculated heights
KronosTheLate 0e20f16
Export filterpeaks, improve internals in new API
KronosTheLate 369c072
Change linebreaks in "filterpeaks!"
KronosTheLate 080e970
Make use of "strict" in all functions
KronosTheLate 37839c8
Fix some bugs
KronosTheLate 6edefcf
export old functions
KronosTheLate 169e5dd
improvements, polish docstrings
KronosTheLate 67cea1b
tag breaking version
KronosTheLate 310fbfe
misc changes
KronosTheLate 82c5b8e
comment out bad test
KronosTheLate 639f212
minor changes
KronosTheLate 8690fe2
fix docstrung for peakheights
KronosTheLate 40ad1a7
un-commented failing test
KronosTheLate cf0d8c3
revert exports
KronosTheLate 3c17d0c
move export of filterpeaks!
KronosTheLate 21312b9
remove extra exports
KronosTheLate 7f005f6
explicit about copying data in docstring
KronosTheLate 11eb80d
Turn --> info ->
KronosTheLate df8537b
add sentence about not copying data
KronosTheLate 5c82230
minheight -> min, same for proms,widths, and max
KronosTheLate 779081e
some changes + better length check in filterpeaks!
KronosTheLate c19d483
add new method for filterpeaks!
KronosTheLate 26cdb9d
Distribute contents of rework, structure exports
KronosTheLate c1d553d
Do not include api_work, which does not exist
KronosTheLate 676a0b5
fixed a couple copy-paste errors
KronosTheLate b70804b
Revert function reordering (clarify changes in docstrings)
halleysfifthinc f9ab0f2
Example compromise docstrings and ordering
halleysfifthinc 75a588e
Revert random change (fixes tests)
halleysfifthinc 32b16e3
Separate docstring examples for APIs
KronosTheLate e98362d
Improve curried docstring
KronosTheLate aaf8b51
make known_fields a const
KronosTheLate 613d0f0
explain what a named tuple slice is
KronosTheLate 8ac658d
Make filterpeaks signature match
KronosTheLate 9848205
swap check order filterpeaks!
KronosTheLate 42aba3c
Swap check order filterpeaks!
KronosTheLate 83c53cb
Merge branch 'master' into api_rework
halleysfifthinc 36b71c7
[nfc] whitespace changes
halleysfifthinc df11d3a
Update/rewrite docstrings and doctests
halleysfifthinc bd468cc
Don't need to depwarn old kwargs for new functions
halleysfifthinc 40ea9a3
Rename `up` => `hi`
halleysfifthinc 9b7da88
Update `peakproms!`/`peakwidths!` to use `ismaxima`/`isminima` for ar…
halleysfifthinc 5493b52
Rewrite error for bad min/max order
halleysfifthinc 598477c
Fix unnecessary Missing union when input array doesn't have missings
halleysfifthinc d5b4281
Update doctest outputs
halleysfifthinc d805b04
Update deprecated kwargs in tests
halleysfifthinc 5c98dab
Test doctests when running tests
halleysfifthinc e791292
Test depwarns
halleysfifthinc 1c7180d
Test error for when first peak is not an extrema
halleysfifthinc 66df7ad
Confirm error when namedtuple has widths OR edges
halleysfifthinc 4939c3d
Confirm error in plotpeaks when first peak isnt an extrema
halleysfifthinc 862ad61
Update docstrings/doctests for utils functions
halleysfifthinc adc1439
Add `filterpeaks!` to the docs
halleysfifthinc 925c9af
Add julia cache to CI docs build
halleysfifthinc b2ec0a6
Dont try linking to Base docs (for the moment)
halleysfifthinc f8b6f0e
fix errant ref
halleysfifthinc 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 |
---|---|---|
|
@@ -4,4 +4,4 @@ | |
Manifest.toml | ||
docs/build/ | ||
docs/site/ | ||
|
||
.vscode/ |
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 |
---|---|---|
|
@@ -13,6 +13,7 @@ peakwidths | |
peakwidths! | ||
peakheights | ||
peakheights! | ||
filterpeaks! | ||
findnextmaxima | ||
findnextminima | ||
ismaxima | ||
|
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 |
---|---|---|
@@ -1,73 +1,134 @@ | ||
""" | ||
peakheights(peaks, heights; | ||
minheight=nothing, | ||
maxheight=nothing | ||
) -> (peaks, heights) | ||
peakheights(indices, heights; [min, max]) -> (indices, heights) | ||
peakheights(pks::NamedTuple; [min, max]) -> NamedTuple | ||
|
||
Return a copy of `peaks` and `heights` where peak heights are removed if less than | ||
`minheight` and/or greater than `maxheight`. | ||
|
||
Return a copy of `indices` and `heights` where peaks are removed if their height is less than | ||
`min` and/or greater than `max`. | ||
|
||
If a NamedTuple `pks` is given, a new NamedTuple is returned with filtered copies of fields | ||
from `pks`. `pks` must have `:indices` and `:heights` fields. The fields `:proms`, | ||
`:widths`, and `:edges` will be filtered if present, and any remaining fields will be | ||
copied unmodified. | ||
|
||
See also: [`peakproms`](@ref), [`peakwidths`](@ref), [`findmaxima`](@ref) | ||
|
||
# Examples | ||
```jldoctest | ||
julia> x = [0,5,2,3,3,1,4,0]; | ||
|
||
julia> xpks, vals = findmaxima(x) | ||
([2, 4, 7], [5, 3, 4]) | ||
julia> pks = findmaxima(x) | ||
(indices = [2, 4, 7], heights = [5, 3, 4], data = [0, 5, 2, 3, 3, 1, 4, 0]) | ||
|
||
julia> peakheights(xpks, vals; maxheight=4) | ||
([4, 7], [3, 4]) | ||
julia> peakheights(pks; max=4) | ||
(indices = [4, 7], heights = [3, 4], data = [0, 5, 2, 3, 3, 1, 4, 0]) | ||
|
||
julia> peakheights(xpks, vals; minheight=4.5) | ||
([2], [5]) | ||
julia> inds, heights = peakheights(pks.indices, pks.heights; max=4) | ||
([4, 7], [3, 4]) | ||
``` | ||
""" | ||
function peakheights( | ||
peaks::AbstractVector{Int}, heights::AbstractVector; | ||
minheight=nothing, maxheight=nothing | ||
indices::AbstractVector{Int}, heights::AbstractVector; | ||
minheight=nothing, maxheight=nothing, | ||
min=minheight, max=maxheight | ||
) | ||
peakheights!(copy(peaks), copy(heights); minheight=minheight, maxheight=maxheight) | ||
if !isnothing(minheight) | ||
Base.depwarn("Keyword `minheight` has been renamed to `min`", :peakheights!) | ||
end | ||
if !isnothing(maxheight) | ||
Base.depwarn("Keyword `maxheight` has been renamed to `max`", :peakheights!) | ||
end | ||
peakheights!(copy(indices), copy(heights); min=min, max=max) | ||
end | ||
|
||
peakheights(pks::NamedTuple; kwargs...) = peakheights!(deepcopy(pks); kwargs...) | ||
|
||
""" | ||
peakheights(; [min, max]) -> Function | ||
|
||
Create a function, `f(pks::NamedTuple)`, that copies and filters the peak heights of its | ||
argument, `pks`, using any given keyword arguments. | ||
|
||
# Examples | ||
```jldoctest | ||
julia> findmaxima([0, 5, 2, 3, 3, 1, 4, 0]) |> peakheights(; max=4) | ||
(indices = [4, 7], heights = [3, 4], data = [0, 5, 2, 3, 3, 1, 4, 0]) | ||
``` | ||
""" | ||
peakheights(; kwargs...) = function _curried_peakheights(pks) | ||
return peakheights(deepcopy(pks); kwargs...) | ||
end | ||
|
||
""" | ||
peakheights!(peaks, heights; | ||
minheight=nothing, | ||
maxheight=nothing | ||
) -> (peaks, heights) | ||
peakheights!(indices, heights; [min, max]) -> (indices, heights) | ||
peakheights!(pks::NamedTuple; [min, max]) -> NamedTuple | ||
|
||
Filter (mutate) and return `indices` and `heights` by removing peaks that are less than `min` | ||
and/or greater than `max`. | ||
|
||
Modify and return `peaks` and `heights` by removing peaks that are less than `minheight` or greater | ||
than `maxheight`. | ||
If a NamedTuple `pks` is given, a new NamedTuple is returned with the same fields | ||
(references) from `pks`. `pks` must have `:indices` and `:heights` fields. The fields | ||
`:proms`, `:widths`, and `:edges` will be filtered (mutated) if present, and any remaining | ||
fields will be referenced unmodified. | ||
|
||
See also: [`peakproms`](@ref), [`peakwidths`](@ref), [`findmaxima`](@ref) | ||
[`filterpeaks!`](@ref) | ||
|
||
# Examples | ||
```jldoctest | ||
julia> x = [0,5,2,3,3,1,4,0]; | ||
|
||
julia> xpks, vals = findmaxima(x) | ||
([2, 4, 7], [5, 3, 4]) | ||
julia> pks = findmaxima(x) | ||
(indices = [2, 4, 7], heights = [5, 3, 4], data = [0, 5, 2, 3, 3, 1, 4, 0]) | ||
|
||
julia> peakheights!(xpks, vals; maxheight=4); | ||
julia> peakheights!(pks; max=4) | ||
(indices = [4, 7], heights = [3, 4], data = [0, 5, 2, 3, 3, 1, 4, 0]) | ||
|
||
julia> xpks, vals | ||
([4, 7], [3, 4]) | ||
julia> inds, heights = peakheights!(pks.indices, pks.heights; min=3.5) | ||
([7], [4]) | ||
``` | ||
""" | ||
function peakheights!( | ||
peaks::Vector{Int}, heights::AbstractVector{T}; | ||
minheight=nothing, maxheight=nothing | ||
minheight=nothing, maxheight=nothing, | ||
min=minheight, max=maxheight | ||
) where {T} | ||
if !isnothing(minheight) | ||
Base.depwarn("Keyword `minheight` has been renamed to `min`", :peakheights!) | ||
end | ||
if !isnothing(maxheight) | ||
Base.depwarn("Keyword `maxheight` has been renamed to `max`", :peakheights!) | ||
end | ||
length(peaks) == length(heights) || throw(DimensionMismatch("length of `peaks`, $(length(peaks)), does not match the length of `heights`, $(length(heights))")) | ||
if !isnothing(minheight) || !isnothing(maxheight) | ||
lo = something(minheight, typemin(Base.nonmissingtype(T))) | ||
up = something(maxheight, typemax(Base.nonmissingtype(T))) | ||
matched = findall(x -> !(lo ≤ x ≤ up), heights) | ||
if !isnothing(min) || !isnothing(max) | ||
lo = something(min, typemin(Base.nonmissingtype(T))) | ||
hi = something(max, typemax(Base.nonmissingtype(T))) | ||
matched = findall(x -> !(lo ≤ x ≤ hi), heights) | ||
deleteat!(peaks, matched) | ||
deleteat!(heights, matched) | ||
end | ||
|
||
return peaks, heights | ||
end | ||
|
||
function peakheights!(pks::NamedTuple; min=nothing, max=nothing) | ||
filterpeaks!(pks, :heights; min, max) | ||
return pks | ||
end | ||
|
||
""" | ||
peakheights!(; [min, max]) -> Function | ||
|
||
Create a function, `f(pks::NamedTuple)`, that calculates peak heights and then filters | ||
(mutates) the fields of its argument, `pks`, using any given keyword arguments. | ||
|
||
# Examples | ||
```jldoctest | ||
julia> findmaxima([0, 5, 2, 3, 3, 1, 4, 0]) |> peakheights!(; max=4) | ||
(indices = [4, 7], heights = [3, 4], data = [0, 5, 2, 3, 3, 1, 4, 0]) | ||
``` | ||
""" | ||
peakheights!(; kwargs...) = function _curried_peakheights!(pks) | ||
return peakheights!(pks; kwargs...) | ||
end | ||
|
Oops, something went wrong.
Oops, something went wrong.
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.
Need to deprecate the
minheight
/maxheight
tomin
/max
here and elsewhere too.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.
This is in the docstring, which is up for discussion in another comment of yours. We can revisit the docstrings after that has been resolved.