-
Notifications
You must be signed in to change notification settings - Fork 9
Add resampling extension #26
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
Merged
Changes from 2 commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
fcea42b
started resampler ext
icweaver e40a724
Another resampling idea
cgarling fdc9c9c
Update src/Spectra.jl
icweaver 333c957
Update src/Spectra.jl
icweaver 6426edb
added Interpolations ext, cleaned up interface a bit
icweaver 248b9fe
Try `SpectrumResampler` type
cgarling 623b446
Use the `spectrum` constructor not `Spectrum`
cgarling 24714e6
switched to explicit interpolation + docs
icweaver 921cbaa
update make.jl
icweaver 7d59626
Fix doctest on local
cgarling 8a2dbc0
Expand `SpectrumResampler` docstring
cgarling bf1373a
Use `Spectrum` constructor in resampler
cgarling 32ea043
point docs to docstring
icweaver 2768c0f
tests up
icweaver 17bb315
added ext by mistake
icweaver 46dfee4
updated show method + test
icweaver e2ceff8
drop mutation tests, using immutable structs in #35
icweaver c76e0c2
Merge branch 'main' into resample
icweaver 2de9ca3
Simplify docs
cgarling 44e236a
use getters
cgarling 5b15e7b
just return a regular Spectrum
icweaver 54fbc98
more test cov
icweaver c9a03fa
update tests
icweaver 6f022f5
qualify interp
icweaver 69d0906
Merge branch 'main' into resample
icweaver 894c426
Merge branch 'main' into resample
icweaver 68683ff
cleanup
icweaver fab8c54
cleanup
icweaver 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 hidden or 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 hidden or 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,36 @@ | ||
| module DataInterpolationsExt | ||
|
|
||
| using Spectra: Spectra, Spectrum, spectrum, wave, flux | ||
| import Spectra: resample | ||
| using DataInterpolations: AbstractInterpolation | ||
|
|
||
| function Spectra.resample(spec::Spectrum, wave_sampled, interp::AbstractInterpolation) | ||
| # p = sortperm(spec.wave) # x-scale must be monitonically increasing; not being used | ||
| flux_sampled = interp(wave_sampled) | ||
| return spectrum(wave_sampled, flux_sampled; meta = spec.meta) | ||
| end | ||
|
|
||
| """ | ||
| resample(spec::Spectrum, wave_sampled, interp::Type{<:DataInterpolations.AbstractInterpolation}; kws...) | ||
| Constructs an interpolator of type `interp` from the provided spectrum `spec` and evaluates it at `wave_sampled`, returning a `Spectrum`. The `kws...` control extrapolation and are passed through to the interpolator. | ||
|
|
||
| ```jldoctest | ||
| julia> using Spectra, DataInterpolations | ||
|
|
||
| julia> spec = spectrum([2, 4, 12, 16, 20], [1, 3, 7, 6, 20]); | ||
|
|
||
| julia> wave_sampled = [1, 5, 9, 13, 14, 17, 21, 22, 23]; | ||
|
|
||
| julia> resample(spec, wave_sampled, LinearInterpolation; extrapolation = ExtrapolationType.Constant) | ||
| Spectrum(Int64, Float64) | ||
| ``` | ||
| """ | ||
| function Spectra.resample(spec::Spectrum, wave_sampled, interp::Type{<:AbstractInterpolation}; kws...) | ||
| # Not sure if we have to check wave is monotonically increasing or if that is guaranteed by the constructor? | ||
| p = sortperm(wave(spec)) | ||
| itp = interp(flux(spec)[p], wave(spec)[p]; kws...) | ||
| flux_sampled = itp.(wave_sampled) | ||
| return spectrum(wave_sampled, flux_sampled; meta = spec.meta) | ||
| end | ||
|
|
||
| end # module |
This file contains hidden or 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
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.
Uh oh!
There was an error while loading. Please reload this page.