Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
602e4ac
Spectrum: added indexing
icweaver Nov 1, 2025
aa7ef48
quick index test
icweaver Nov 1, 2025
da7585e
begin, end
icweaver Nov 1, 2025
a5f3cf0
start moving EchelleSpectrum intro Spectrum
icweaver Nov 2, 2025
36ea6b6
not totally hating this
icweaver Nov 2, 2025
337c793
current tests up
icweaver Nov 2, 2025
8b9bf4d
reorg utils, add more array interface + tests
icweaver Nov 2, 2025
03c3f34
more docs + prettyurl
icweaver Nov 2, 2025
dd61475
update make.jl
icweaver Nov 3, 2025
314d6c2
add IFUSpectrum
icweaver Nov 3, 2025
76b6d0d
merge common.jl into Spectra.jl
icweaver Nov 4, 2025
aef38db
use 3D flux for IFUSpectrum
icweaver Nov 4, 2025
dbf3989
Merge branch 'main' into indexing
icweaver Nov 5, 2025
6ec0bf1
get some color in there
icweaver Nov 5, 2025
c5b3e1f
typo
icweaver Nov 5, 2025
4fc12ba
nvm
icweaver Nov 5, 2025
1f0d9b3
update docstrings
icweaver Nov 5, 2025
0174dd4
update sprints
icweaver Nov 6, 2025
9327cb4
reduce number of parentheses used for display
icweaver Nov 6, 2025
d355ea4
moar tests
icweaver Nov 7, 2025
3fc80e9
more test coverage
icweaver Nov 7, 2025
0a93d83
add size and monotonicity checks, switch from row --> col major repre…
icweaver Nov 7, 2025
86ec55e
remove old asserts, finish updating tests
icweaver Nov 7, 2025
cb50530
add some dev docs
icweaver Nov 7, 2025
f8dc7b9
docs cleanup + more examples
icweaver Nov 7, 2025
765e750
Merge branch 'main' into indexing
icweaver Nov 27, 2025
216a40e
mention XSpecs in quickstart
icweaver Nov 27, 2025
7d8ec3b
generalized terms, shelved extra functionality
icweaver Dec 16, 2025
5daab57
finish shelving old functionality
icweaver Dec 16, 2025
0e4d3ce
finish spectral axis rename
icweaver Dec 16, 2025
6ae3a80
update docs
icweaver Dec 16, 2025
c9b31f7
use accessor methods more
icweaver Dec 17, 2025
d147e6a
typo
icweaver Dec 17, 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
30 changes: 30 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,33 @@ Currently this package can only be installed from github. To do so, either clone
pkg> add https://github.com/JuliaAstro/Spectra.jl

from the `pkg` command line (Press `]` from Julia REPL)

## Developer documentation

Below we show the commands to run from the package root level to develop the tests and documentation.

### Tests

```julia-repl
julia --proj

julia> import Pkg

# List tests
julia> Pkg.test("Spectra"; test_args = `--list`)

# Run specific testsets by name. Will match with `startswith`
julia> Pkg.test("Spectra"; test_args = `--verbose <testset name>`)
```

### Docs

Assuming `LiveServer.jl` is in your global environment:

```julia-repl
julia --proj=docs/

julia> using LiveServer

julia> servedocs(; include_dirs = ["src/"])
```
1 change: 1 addition & 0 deletions docs/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
FITSIO = "525bcba6-941b-5504-bd06-fd0dc1a4d2eb"
Measurements = "eff96d63-e80a-5855-80a2-b1b0885c5ab7"
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
Revise = "295af30f-e4ad-537b-8983-00126c2a3abe"
Spectra = "391af1a9-06f1-59d3-8d21-0be089654739"
Unitful = "1986cc42-f94f-5a68-af5c-568840ba703d"
UnitfulAstro = "6112ee07-acf9-5e0f-b108-d242c714bf9f"
Expand Down
13 changes: 9 additions & 4 deletions docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@ using Documenter
using Spectra
using Unitful
using Measurements
using Revise

Revise.revise()

DocMeta.setdocmeta!(Spectra, :DocTestSetup, :(using Spectra); recursive = true)

makedocs(sitename = "Spectra.jl",
format = Documenter.HTML(;
prettyurls = get(ENV, "CI", nothing) == "true",
prettyurls = true,
canonical = "https://juliaastro.org/Spectra/stable/",
),
authors = "Miles Lucas and contributors.",
Expand All @@ -17,8 +20,8 @@ makedocs(sitename = "Spectra.jl",
"Home" => "index.md",
"spectrum.md",
"transforms.md",
"fitting.md",
"analysis.md",
#"fitting.md",
#"utils.md",
"contrib.md",
],
warnonly = [:missing_docs],
Expand All @@ -27,5 +30,7 @@ makedocs(sitename = "Spectra.jl",

deploydocs(;
repo = "github.com/JuliaAstro/Spectra.jl.git",
versions = ["stable" => "v^", "v#.#"] # Restrict to minor releases
devbranch = "main",
push_preview = true,
versions = ["stable" => "v^", "v#.#"], # Restrict to minor releases
)
File renamed without changes.
5 changes: 3 additions & 2 deletions docs/src/analysis.md → docs/old_docs/utils.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Analysis
# Utilities

```@docs
Spectra.blackbody
Spectra.equivalent_width
Spectra.line_flux
```
```
20 changes: 8 additions & 12 deletions docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ julia> using Spectra

## Quick Start

Here is a quick demo of some of our features
Here is a quick demo of some of our features.

### Spectrum construction

```jldoctest guide
julia> using Spectra, FITSIO, Unitful, UnitfulAstro, Plots
Expand All @@ -41,23 +43,17 @@ julia> wave = (10 .^ read(f[2], "loglam"))u"angstrom";
julia> flux = (read(f[2], "flux") .* 1e-17)u"erg/s/cm^2/angstrom";

julia> spec = spectrum(wave, flux)
Spectrum(Quantity{Float32, 𝐋, Unitful.FreeUnits{(Å,), 𝐋, nothing}}, Quantity{Float64, 𝐌 𝐋^-1 𝐓^-3, Unitful.FreeUnits{(Å^-1, erg, cm^-2, s^-1), 𝐌 𝐋^-1 𝐓^-3, nothing}})
SingleSpectrum(Quantity{Float32, 𝐋, Unitful.FreeUnits{(Å,), 𝐋, nothing}}, Quantity{Float64, 𝐌 𝐋^-1 𝐓^-3, Unitful.FreeUnits{(Å^-1, erg, cm^-2, s^-1), 𝐌 𝐋^-1 𝐓^-3, nothing}})
spectral axis (3827,): 3815.0483f0 Å .. 9206.613f0 Å
flux axis (3827,): 2.182261505126953e-15 erg Å^-1 cm^-2 s^-1 .. 1.7559197998046877e-15 erg Å^-1 cm^-2 s^-1
meta: Dict{Symbol, Any}()

julia> plot(spec);
```

![](assets/sdss.svg)

```jldoctest guide
julia> cont_fit = continuum(spec)
Spectrum(Quantity{Float32, 𝐋, Unitful.FreeUnits{(Å,), 𝐋, nothing}}, Quantity{Float64, 𝐌 𝐋^-1 𝐓^-3, Unitful.FreeUnits{(Å^-1, erg, cm^-2, s^-1), 𝐌 𝐋^-1 𝐓^-3, nothing}})
coeffs: Quantity{Float64, 𝐌 𝐋^-1 𝐓^-3, Unitful.FreeUnits{(Å^-1, erg, cm^-2, s^-1), 𝐌 𝐋^-1 𝐓^-3, nothing}}[1.983152216046405e-15 erg Å^-1 cm^-2 s^-1, -1.8822245369267038e-16 erg Å^-1 cm^-2 s^-1, -1.0422750370065006e-16 erg Å^-1 cm^-2 s^-1, 4.8112282273206135e-17 erg Å^-1 cm^-2 s^-1]
normalized: true

julia> plot(cont_fit, xlims=(6545, 6600));
```

![](assets/sdss_cont.svg)
For constructing higher dimensional spectra, e.g., for echelle or IFU spectra, see the docstrings for [EchelleSpectrum](@ref) and [IFUSpectrum](@ref), respectively.

## Citation

Expand Down
49 changes: 27 additions & 22 deletions docs/src/spectrum.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
```@meta
DocTestSetup = quote
using Spectra, Random
Random.seed!(11894)
end
```

# Spectrum

Here we will go over the different spectral types and how we use them.
Expand All @@ -14,7 +7,11 @@ Here we will go over the different spectral types and how we use them.
Spectra are defined as possible subtypes of `AbstractSpectrum`. You can use these directly for construction, or use the catch-all [`spectrum`](@ref) function, which is preferred.

```@docs
Spectra.AbstractSpectrum
Spectra.Spectrum
Spectra.SingleSpectrum
Spectra.EchelleSpectrum
Spectra.IFUSpectrum
```

## Constructors
Expand All @@ -28,25 +25,37 @@ Spectra.spectrum

For more advanced transformations, see [Transformations](@ref)

### Getters
```@docs
Spectra.spectral_axis(::AbstractSpectrum)
Spectra.flux_axis(::AbstractSpectrum)
Spectra.meta(::AbstractSpectrum)
```

### Array interface

| Function |
|:-----------------------------------|
| `Base.argmax(::AbstractSpectrum)` |
| `Base.argmin(::AbstractSpectrum)` |
| `Base.eltype(::AbstractSpectrum)` |
| `Base.findmax(::AbstractSpectrum)` |
| `Base.findmin(::AbstractSpectrum)` |
| `Base.iterate(::AbstractSpectrum)` |
| `Base.length(::AbstractSpectrum)` |
| `Base.size(::AbstractSpectrum)` |
| `Base.maximum(::AbstractSpectrum)` |
| `Base.minimum(::AbstractSpectrum)` |
| `Base.argmax(::AbstractSpectrum)` |
| `Base.argmin(::AbstractSpectrum)` |
| `Base.findmax(::AbstractSpectrum)` |
| `Base.findmin(::AbstractSpectrum)` |
| `Base.size(::AbstractSpectrum)` |

### Arithmetic

| Function |
|:-----------------------------------|
| `+(::AbstractSpectrum, A)` |
| `-(::AbstractSpectrum, A)` |
| `*(::AbstractSpectrum, A)` |
| `/(::AbstractSpectrum, A)` |
| Function |
|:----------------------------------------------------|
| `+(::AbstractSpectrum, A)` |
| `-(::AbstractSpectrum, A)` |
| `*(::AbstractSpectrum, A)` |
| `/(::AbstractSpectrum, A)` |
| `Base.(==)(::AbstractSpectrum, ::AbstractSpectrum)` |

## Unitful helpers

Expand Down Expand Up @@ -76,7 +85,3 @@ savefig("spec-plot.svg"); nothing # hide
```@index
Pages = ["spectrum.md"]
```

```@meta
DocTestSetup = nothing
```
43 changes: 17 additions & 26 deletions docs/src/transforms.md
Original file line number Diff line number Diff line change
@@ -1,31 +1,17 @@
```@meta
DocTestSetup = quote
using Spectra, Random
Random.seed!(11894)
end
```

# Transformations

## Extinction

By levaraging [DustExtinction.jl](https://github.com/juliaastro/dustextinction.jl) we can apply common reddening laws to our spectra.

```jldoctest
julia> using Unitful, Measurements, Random
julia> using Spectra, Unitful, Measurements, Random

julia> rng = Random.seed!(0);

julia> wave = (1:0.5:3)u"μm"
(1.0:0.5:3.0) μm
julia> wave = (1:0.5:3)u"μm";

julia> sigma = randn(rng, size(wave))
5-element Vector{Float64}:
0.942970533446119
0.13392275765318448
1.5250689085124804
0.12390123120559722
-1.205772284259936
julia> sigma = randn(rng, size(wave));

julia> flux = (100 .± sigma)u"W/m^2/μm"
5-element Vector{Quantity{Measurement{Float64}, 𝐌 𝐋^-1 𝐓^-3, Unitful.FreeUnits{(μm^-1, m^-2, W), 𝐌 𝐋^-1 𝐓^-3, nothing}}}:
Expand All @@ -36,12 +22,18 @@ julia> flux = (100 .± sigma)u"W/m^2/μm"
100.0 ± -1.2 W μm^-1 m^-2

julia> spec = spectrum(wave, flux)
Spectrum(Quantity{Float64, 𝐋, Unitful.FreeUnits{(μm,), 𝐋, nothing}}, Quantity{Measurement{Float64}, 𝐌 𝐋^-1 𝐓^-3, Unitful.FreeUnits{(μm^-1, m^-2, W), 𝐌 𝐋^-1 𝐓^-3, nothing}})
SingleSpectrum(Quantity{Float64, 𝐋, Unitful.FreeUnits{(μm,), 𝐋, nothing}}, Quantity{Measurement{Float64}, 𝐌 𝐋^-1 𝐓^-3, Unitful.FreeUnits{(μm^-1, m^-2, W), 𝐌 𝐋^-1 𝐓^-3, nothing}})
spectral axis (5,): 1.0 μm .. 3.0 μm
flux axis (5,): 100.0 ± 0.94 W μm^-1 m^-2 .. 100.0 ± -1.2 W μm^-1 m^-2
meta: Dict{Symbol, Any}()

julia> red = redden(spec, 0.3)
Spectrum(Quantity{Float64, 𝐋, Unitful.FreeUnits{(μm,), 𝐋, nothing}}, Quantity{Measurement{Float64}, 𝐌 𝐋^-1 𝐓^-3, Unitful.FreeUnits{(μm^-1, m^-2, W), 𝐌 𝐋^-1 𝐓^-3, nothing}})
SingleSpectrum(Quantity{Float64, 𝐋, Unitful.FreeUnits{(μm,), 𝐋, nothing}}, Quantity{Measurement{Float64}, 𝐌 𝐋^-1 𝐓^-3, Unitful.FreeUnits{(μm^-1, m^-2, W), 𝐌 𝐋^-1 𝐓^-3, nothing}})
spectral axis (5,): 1.0 μm .. 3.0 μm
flux axis (5,): 89.44 ± 0.84 W μm^-1 m^-2 .. 98.1 ± 1.2 W μm^-1 m^-2
meta: Dict{Symbol, Any}()

julia> red.flux
julia> flux_axis(red)
5-element Vector{Quantity{Measurement{Float64}, 𝐌 𝐋^-1 𝐓^-3, Unitful.FreeUnits{(μm^-1, m^-2, W), 𝐌 𝐋^-1 𝐓^-3, nothing}}}:
89.44 ± 0.84 W μm^-1 m^-2
94.35 ± 0.13 W μm^-1 m^-2
Expand All @@ -50,9 +42,12 @@ julia> red.flux
98.1 ± 1.2 W μm^-1 m^-2

julia> deredden!(red, 0.3)
Spectrum(Quantity{Float64, 𝐋, Unitful.FreeUnits{(μm,), 𝐋, nothing}}, Quantity{Measurement{Float64}, 𝐌 𝐋^-1 𝐓^-3, Unitful.FreeUnits{(μm^-1, m^-2, W), 𝐌 𝐋^-1 𝐓^-3, nothing}})
SingleSpectrum(Quantity{Float64, 𝐋, Unitful.FreeUnits{(μm,), 𝐋, nothing}}, Quantity{Measurement{Float64}, 𝐌 𝐋^-1 𝐓^-3, Unitful.FreeUnits{(μm^-1, m^-2, W), 𝐌 𝐋^-1 𝐓^-3, nothing}})
spectral axis (5,): 1.0 μm .. 3.0 μm
flux axis (5,): 100.0 ± 0.94 W μm^-1 m^-2 .. 100.0 ± 1.2 W μm^-1 m^-2
meta: Dict{Symbol, Any}()

julia> red.flux ≈ spec.flux
julia> flux_axis(red)flux_axis(spec)
true
```

Expand All @@ -64,7 +59,3 @@ redden!
deredden
deredden!
```

```@meta
DocTestSetup = nothing
```
31 changes: 0 additions & 31 deletions src/EchelleSpectrum.jl

This file was deleted.

Loading
Loading