Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
fcea42b
started resampler ext
icweaver Nov 1, 2025
e40a724
Another resampling idea
cgarling Nov 1, 2025
fdc9c9c
Update src/Spectra.jl
icweaver Nov 2, 2025
333c957
Update src/Spectra.jl
icweaver Nov 2, 2025
6426edb
added Interpolations ext, cleaned up interface a bit
icweaver Nov 2, 2025
248b9fe
Try `SpectrumResampler` type
cgarling Nov 2, 2025
623b446
Use the `spectrum` constructor not `Spectrum`
cgarling Nov 2, 2025
24714e6
switched to explicit interpolation + docs
icweaver Nov 3, 2025
921cbaa
update make.jl
icweaver Nov 3, 2025
7d59626
Fix doctest on local
cgarling Nov 3, 2025
8a2dbc0
Expand `SpectrumResampler` docstring
cgarling Nov 3, 2025
bf1373a
Use `Spectrum` constructor in resampler
cgarling Nov 3, 2025
32ea043
point docs to docstring
icweaver Nov 3, 2025
2768c0f
tests up
icweaver Nov 3, 2025
17bb315
added ext by mistake
icweaver Nov 3, 2025
46dfee4
updated show method + test
icweaver Nov 4, 2025
e2ceff8
drop mutation tests, using immutable structs in #35
icweaver Nov 5, 2025
c76e0c2
Merge branch 'main' into resample
icweaver Nov 5, 2025
2de9ca3
Simplify docs
cgarling Nov 5, 2025
44e236a
use getters
cgarling Nov 5, 2025
5b15e7b
just return a regular Spectrum
icweaver Nov 7, 2025
54fbc98
more test cov
icweaver Nov 7, 2025
c9a03fa
update tests
icweaver Nov 7, 2025
6f022f5
qualify interp
icweaver Nov 7, 2025
69d0906
Merge branch 'main' into resample
icweaver Nov 27, 2025
894c426
Merge branch 'main' into resample
icweaver Dec 18, 2025
68683ff
cleanup
icweaver Dec 18, 2025
fab8c54
cleanup
icweaver Dec 19, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,14 @@ RecipesBase = "3cdcf5f2-1ef4-517c-9805-6587b60abb01"
Unitful = "1986cc42-f94f-5a68-af5c-568840ba703d"
UnitfulAstro = "6112ee07-acf9-5e0f-b108-d242c714bf9f"

[weakdeps]
DataInterpolations = "82cc6244-b520-54b8-b5a6-8a565e85f1d0"

[extensions]
DataInterpolationsExt = "DataInterpolations"

[compat]
DataInterpolations = "8.6.1"
DustExtinction = ">=0.6.0"
LinearAlgebra = "1.5"
Measurements = "2"
Expand Down
11 changes: 11 additions & 0 deletions ext/DataInterpolationsExt.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module DataInterpolationsExt
using Spectra: Spectra, Spectrum, spectrum
using DataInterpolations: AbstractInterpolation

function Spectra.resample(spec::Spectrum, wave_sampled, interp::AbstractInterpolation)
p = sortperm(spec.wave) # x-scale must be monitonically increasing
flux_sampled = interp(wave_sampled)
return spectrum(wave_sampled, flux_sampled; meta = spec.meta)
end

end # module
32 changes: 32 additions & 0 deletions src/Spectra.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ export AbstractSpectrum, spectrum
export blackbody
# transforms/redden.jl
export redden, redden!, deredden, deredden!
# resampling: ../ext/DataInterpolationsExt.jl
export resample

using RecipesBase: @recipe
using Measurements: Measurements, Measurement
Expand Down Expand Up @@ -91,6 +93,36 @@ function spectrum(wave::AbstractMatrix{<:Quantity}, flux::AbstractMatrix{<:Quant
EchelleSpectrum(wave, flux, Dict{Symbol,Any}(kwds))
end

# Stub
"""
function resample(spec, wave_sampled, interp)

Resample a spectrum onto the given wavelength grid `wave_sampled` using the supplied interpolator `interp`. Currently supports interpolators from the [DataInterpolations.jl](https://github.com/SciML/DataInterpolations.jl) package.

# Examples

```julia-repl
julia> using 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];

# BYO interpolator
julia> interp = LinearInterpolation(spec.flux, spec.wave; extrapolation = ExtrapolationType.Constant);
Comment thread
icweaver marked this conversation as resolved.
Outdated

julia> spec_sampled = resample(spec, wave_sampled, interp);
```
"""
function resample(spec, wave_sampled, interp)
error("""Supported interpolation package not loaded. Please try adding one of the supported interpolation packages below:
Comment thread
icweaver marked this conversation as resolved.
Outdated

- DataInterpolations.jl

PRs to add additional interpolation packages are welcome!
""")
end

# tools
include("utils.jl")
include("transforms/transforms.jl")
Expand Down
Loading