Skip to content

Commit a5f3cf0

Browse files
committed
start moving EchelleSpectrum intro Spectrum
1 parent da7585e commit a5f3cf0

File tree

3 files changed

+32
-32
lines changed

3 files changed

+32
-32
lines changed

src/EchelleSpectrum.jl

Lines changed: 0 additions & 31 deletions
This file was deleted.

src/Spectra.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ include("common.jl")
1717

1818
# Spectrum types and basic arithmetic
1919
include("spectrum.jl")
20-
include("EchelleSpectrum.jl")
2120

2221
"""
2322
spectrum(wave, flux; kwds...)

src/spectrum.jl

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,35 @@ function Base.show(io::IO, spec::Spectrum)
3131
print(io, "\n $key: $val")
3232
end
3333
end
34+
35+
struct EchelleSpectrum{W <: Number,F <: Number} <: AbstractSpectrum{W,F}
36+
wave::Matrix{W}
37+
flux::Matrix{F}
38+
meta::Dict{Symbol,Any}
39+
end
40+
41+
EchelleSpectrum(wave, flux, meta::Dict{Symbol,Any}) = EchelleSpectrum(collect(wave), collect(flux), meta)
42+
43+
function Base.show(io::IO, spec::EchelleSpectrum)
44+
println(io, "EchelleSpectrum($(eltype(spec.wave)), $(eltype(spec.flux)))")
45+
print(io, " # orders: $(size(spec, 1))")
46+
for (key, val) in spec.meta
47+
print(io, "\n $key: $val")
48+
end
49+
end
50+
51+
function Base.getindex(spec::EchelleSpectrum, i::Integer)
52+
wave = spec.wave[i, :]
53+
flux = spec.flux[i, :]
54+
meta = merge(Dict(:Order => i), spec.meta)
55+
return Spectrum(wave, flux, meta)
56+
end
57+
58+
function Base.getindex(spec::EchelleSpectrum, I::AbstractVector)
59+
waves = spec.wave[I, :]
60+
flux = spec.flux[I, :]
61+
meta = merge(Dict(:Orders => (first(I), last(I))), spec.meta)
62+
return EchelleSpectrum(waves, flux, meta)
63+
end
64+
65+
Base.lastindex(spec::EchelleSpectrum) = lastindex(spec.flux, 1)

0 commit comments

Comments
 (0)