Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
11 changes: 8 additions & 3 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 @@ -18,7 +21,7 @@ makedocs(sitename = "Spectra.jl",
"spectrum.md",
"transforms.md",
"fitting.md",
"analysis.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
)
12 changes: 8 additions & 4 deletions docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ 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}})
wave (3827,): 3815.0483f0 Å .. 9206.613f0 Å
flux (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);
```
Expand All @@ -50,9 +53,10 @@ julia> plot(spec);

```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
SingleSpectrum(Quantity{Float32, 𝐋, Unitful.FreeUnits{(Å,), 𝐋, nothing}}, Quantity{Float64, 𝐌 𝐋^-1 𝐓^-3, Unitful.FreeUnits{(Å^-1, erg, cm^-2, s^-1), 𝐌 𝐋^-1 𝐓^-3, nothing}})
wave (3827,): 3815.0483f0 Å .. 9206.613f0 Å
flux (3827,): 1.0808438837160355 erg Å^-1 cm^-2 s^-1 .. 1.0098373106940344 erg Å^-1 cm^-2 s^-1
meta: Dict{Symbol, Any}(: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));
```
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.wave(::AbstractSpectrum)
Spectra.flux(::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
```
39 changes: 15 additions & 24 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,10 +22,16 @@ 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}})
wave (5,): 1.0 μm .. 3.0 μm
flux (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}})
wave (5,): 1.0 μm .. 3.0 μm
flux (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
5-element Vector{Quantity{Measurement{Float64}, 𝐌 𝐋^-1 𝐓^-3, Unitful.FreeUnits{(μm^-1, m^-2, W), 𝐌 𝐋^-1 𝐓^-3, nothing}}}:
Expand All @@ -50,7 +42,10 @@ 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}})
wave (5,): 1.0 μm .. 3.0 μm
flux (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
true
Expand All @@ -64,7 +59,3 @@ redden!
deredden
deredden!
```

```@meta
DocTestSetup = nothing
```
5 changes: 3 additions & 2 deletions docs/src/analysis.md → docs/src/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
```
```
31 changes: 0 additions & 31 deletions src/EchelleSpectrum.jl

This file was deleted.

Loading
Loading