Skip to content

Commit

Permalink
Merge pull request #134 from fjebaker/no-xspec
Browse files Browse the repository at this point in the history
Remove LibXSPEC_jll dependency
  • Loading branch information
fjebaker authored Oct 22, 2024
2 parents 3f571de + b990844 commit 8e05e8a
Show file tree
Hide file tree
Showing 39 changed files with 252 additions and 195 deletions.
13 changes: 11 additions & 2 deletions .github/workflows/auto-register.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
julia-version: ['1.9']
julia-version: ['1.11']
os: [ubuntu-latest]
steps:
- uses: actions/checkout@v2
Expand All @@ -45,7 +45,16 @@ jobs:
Pkg.add(url="https://github.com/GunnarFarneback/LocalRegistry.jl")
using LocalRegistry
Pkg.Registry.add(Pkg.RegistrySpec(url="https://github.com/astro-group-bristol/AstroRegistry/"))
register(pwd(), registry="AstroRegistry", push=false)
try
register(pwd(), registry="AstroRegistry", push=false)
catch err
@warn err
end
try
register(joinpath(pwd(), "lib", "XSPECModels"), registry="AstroRegistry", push=false)
catch err
@warn err
end
'
- name: Create new branch
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
- uses: actions/checkout@v3
- uses: julia-actions/setup-julia@v1
with:
version: '1.10'
version: '1.11'
- uses: actions/cache@v1
env:
cache-name: cache-artifacts
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
julia-version: ['1.10']
julia-version: ['1.11']
os: [ubuntu-latest]

steps:
Expand Down Expand Up @@ -67,4 +67,4 @@ jobs:
directories: src
- uses: codecov/codecov-action@v2
with:
files: lcov.info
files: lcov.info
3 changes: 0 additions & 3 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ FileIO = "5789e2e9-d7fb-5bc7-8068-2c6fae9b9549"
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
Interpolations = "a98d9a8b-a2ab-59e6-89dd-64a1c18fca59"
JLD2 = "033835bb-8acc-5ee8-8aae-3f567f8a3819"
LibXSPEC_jll = "50917eeb-3e3c-5f3a-99bd-93e1c30e1561"
Libz = "2ec943e9-cfe8-584d-b93d-64dcb6d567b7"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
LsqFit = "2fda8390-95c7-5789-9bda-21331edee243"
Expand All @@ -34,5 +33,3 @@ Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
Surrogates = "6fc51010-71bc-11e9-0e15-a3fcc6593c49"
Unitful = "1986cc42-f94f-5a68-af5c-568840ba703d"

[compat]
LibXSPEC_jll = "0.1.9"
8 changes: 4 additions & 4 deletions docs/src/examples/xrism-simulation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ begin
erange = 10 .^ collect(range(log10(4), log10(20.0), 100))
model2 = GaussianLine() + GaussianLine(ΞΌ = FitParam(10.0))
plot(
erange[1:end-1],
erange[1:(end-1)],
@time(invokemodel(erange, model)),
marker = :o,
markersize = 4,
label = "XS",
)
plot!(
erange[1:end-1],
erange[1:(end-1)],
@time(invokemodel(erange, model2)),
marker = :o,
markersize = 4,
Expand All @@ -40,7 +40,7 @@ model = XS_PowerLaw(a = FitParam(2.0), K = FitParam(1.0))
emids = push!(copy(resp.channel_bins_low), last(resp.channel_bins_high))
evald = push!(copy(resp.bins_low), last(resp.bins_high))
out = resp.matrix * invokemodel(evald, model)
plot(emids[1:end-1], out)
plot(emids[1:(end-1)], out)


sims = @time simulate(model, resp, anc; exposure_time = 1e3, seed = 42)
Expand All @@ -58,7 +58,7 @@ begin
)
plot!(sims)
plot!(
emids[1:end-1] .+ diff(emids) ./ 2,
emids[1:(end-1)] .+ diff(emids) ./ 2,
out .* 1.4,
xscale = :log10,
label = "Hand folded",
Expand Down
13 changes: 13 additions & 0 deletions lib/XSPECModels/Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name = "XSPECModels"
uuid = "e051c099-9e89-4e1f-aad2-39a4611ecf4d"
authors = ["fjebaker <fergusbkr@gmail.com>"]
version = "0.1.0"

[deps]
DocStringExtensions = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae"
LibXSPEC_jll = "50917eeb-3e3c-5f3a-99bd-93e1c30e1561"
SpectralFitting = "f2c56810-742e-4b72-8bf4-27af3bb81a12"

[compat]
DocStringExtensions = "0.9.3"
LibXSPEC_jll = "0.1.15"
36 changes: 36 additions & 0 deletions lib/XSPECModels/src/XSPECModels.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
module XSPECModels

using DocStringExtensions
using LibXSPEC_jll
using SpectralFitting
import SpectralFitting: _check_model_directory_present, register_model_data

const LIBXSPEC_STORAGE_PATH = joinpath(LibXSPEC_jll.artifact_dir, "spectral", "modelData")

include("ccall-wrapper.jl")

# include xspec models
include("additive.jl")
include("multiplicative.jl")
include("convolutional.jl")

function register_xspec_data()
push!(SpectralFitting.ALL_STORAGE_PATHS, LIBXSPEC_STORAGE_PATH)
register_model_data(XS_KerrDisk, "kerrtable.fits"; root = LIBXSPEC_STORAGE_PATH)
register_model_data(XS_KyrLine, "KBHline01.fits"; root = LIBXSPEC_STORAGE_PATH)
register_model_data(XS_Laor, "ari.mod"; root = LIBXSPEC_STORAGE_PATH)
end


function __init__()
# init HEASOFT
if get(ENV, "SPECTRAL_FITTING_XSPEC_INIT", "") == ""
# push our storage path
register_xspec_data()
ccall((:FNINIT, libXSFunctions), Cvoid, ())
# set an environment variable so we don't accidentally init again
ENV["SPECTRAL_FITTING_XSPEC_INIT"] = "true"
end
end

end # module XSPECModels
161 changes: 79 additions & 82 deletions src/xspec-models/additive.jl β†’ lib/XSPECModels/src/additive.jl
Original file line number Diff line number Diff line change
Expand Up @@ -59,25 +59,25 @@ lineplot(energy[1:end-1],m,xscale=:log10,yscale=:log10,xlim=(1e-1,1e2),ylim=(1e-
```
```
XS_CutOffPowerLaw
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
10⁰ β”‚:.. β”‚
β”‚ '':... β”‚
β”‚ '':.. β”‚
β”‚ '''.. β”‚
β”‚ '':.. β”‚
β”‚ '':. β”‚
β”‚ ':. β”‚
Flux β”‚ '.. β”‚
β”‚ ':. β”‚
β”‚ '. β”‚
β”‚ : β”‚
β”‚ :. β”‚
β”‚ : β”‚
β”‚ : β”‚
10⁻⁢ β”‚ :β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
10⁻¹ 10²
XS_CutOffPowerLaw
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
10⁰ β”‚:.. β”‚
β”‚ '':... β”‚
β”‚ '':.. β”‚
β”‚ '''.. β”‚
β”‚ '':.. β”‚
β”‚ '':. β”‚
β”‚ ':. β”‚
Flux β”‚ '.. β”‚
β”‚ ':. β”‚
β”‚ '. β”‚
β”‚ : β”‚
β”‚ :. β”‚
β”‚ : β”‚
β”‚ : β”‚
10⁻⁢ β”‚ :β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
10⁻¹ 10²
Energy (keV)
```
"""
Expand Down Expand Up @@ -262,7 +262,6 @@ function XS_KerrDisk(;
)
XS_KerrDisk(K, lineE, index1, index2, break_r, a, ΞΈ, inner_r, outer_r, z)
end
register_model_data(XS_KerrDisk, "kerrtable.fits")


"""
Expand Down Expand Up @@ -340,7 +339,6 @@ function XS_KyrLine(;
)
XS_KyrLine(K, a, ΞΈ, inner_r, ms_flag, outer_r, lineE, Ξ±, Ξ², break_r, z, limb)
end
register_model_data(XS_KyrLine, "KBHline01.fits")


"""
Expand Down Expand Up @@ -402,7 +400,6 @@ function XS_Laor(;
)
XS_Laor(K, lineE, a, inner_r, outer_r, ΞΈ)
end
register_model_data(XS_Laor, "ari.mod")

"""
XS_DiskLine(K, lineE, Ξ², inner_r, outer_r, incl)
Expand Down Expand Up @@ -477,26 +474,26 @@ invokemodel(energy, XS_Gaussian())
```
```
XS_Gaussian
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
0.09 β”‚ β”‚
β”‚ . β”‚
β”‚ : : β”‚
β”‚ : : β”‚
β”‚ : '. β”‚
β”‚ .' : β”‚
β”‚ : : β”‚
β”‚ : : β”‚
β”‚ : '. β”‚
β”‚ : : β”‚
β”‚ : : β”‚
β”‚ : : β”‚
β”‚ .' : β”‚
β”‚ : : β”‚
0 β”‚.......: :......................β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
0 20
E (keV)
XS_Gaussian
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
0.09 β”‚ β”‚
β”‚ . β”‚
β”‚ : : β”‚
β”‚ : : β”‚
β”‚ : '. β”‚
β”‚ .' : β”‚
β”‚ : : β”‚
β”‚ : : β”‚
β”‚ : '. β”‚
β”‚ : : β”‚
β”‚ : : β”‚
β”‚ : : β”‚
β”‚ .' : β”‚
β”‚ : : β”‚
0 β”‚.......: :......................β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
0 20
E (keV)
```
"""
@xspecmodel :C_gaussian struct XS_Gaussian{T} <: AbstractSpectralModel{T,Additive}
Expand Down Expand Up @@ -530,26 +527,26 @@ lineplot(energy[1:end-1],m,xscale=:log10,yscale=:log10,xlim=(1e-8,1e8),ylim=(1e-
```
```
XS_Jet
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
10⁸ β”‚ β”‚
β”‚ β”‚
β”‚ β”‚
β”‚ β”‚
β”‚ :':.. β”‚
β”‚ .' ''. β”‚
β”‚: ':. β”‚
Flux β”‚' ': β”‚
β”‚ '. β”‚
β”‚ : β”‚
β”‚ ''..... β”‚
β”‚ '''''.. β”‚
β”‚ ':.. β”‚
β”‚ ':. β”‚
10⁻⁸ β”‚ ''. β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
10⁻⁸ 10⁸
Energy (keV)
XS_Jet
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
10⁸ β”‚ β”‚
β”‚ β”‚
β”‚ β”‚
β”‚ β”‚
β”‚ :':.. β”‚
β”‚ .' ''. β”‚
β”‚: ':. β”‚
Flux β”‚' ': β”‚
β”‚ '. β”‚
β”‚ : β”‚
β”‚ ''..... β”‚
β”‚ '''''.. β”‚
β”‚ ':.. β”‚
β”‚ ':. β”‚
10⁻⁸ β”‚ ''. β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
10⁻⁸ 10⁸
Energy (keV)
```
"""
@xspecmodel :C_jet struct XS_Jet{T} <: AbstractSpectralModel{T,Additive}
Expand Down Expand Up @@ -702,26 +699,26 @@ energy = collect(range(0.1, 20.0, 100))
invokemodel(energy, XS_Optxagnf())
```
```
XS_Optxagnf
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
0 β”‚ β”‚
β”‚: β”‚
β”‚: β”‚
β”‚: β”‚
β”‚'. β”‚
β”‚ : β”‚
β”‚ '. β”‚
Flux (log scale) β”‚ :. β”‚
β”‚ : β”‚
β”‚ '. β”‚
β”‚ ''':..... β”‚
β”‚ '''''''':............. β”‚
β”‚ ''''β”‚
β”‚ β”‚
-30 β”‚ β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
0 20
E (keV)
XS_Optxagnf
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
0 β”‚ β”‚
β”‚: β”‚
β”‚: β”‚
β”‚: β”‚
β”‚'. β”‚
β”‚ : β”‚
β”‚ '. β”‚
Flux (log scale) β”‚ :. β”‚
β”‚ : β”‚
β”‚ '. β”‚
β”‚ ''':..... β”‚
β”‚ '''''''':............. β”‚
β”‚ ''''β”‚
β”‚ β”‚
-30 β”‚ β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
0 20
E (keV)
```
"""
@xspecmodel :C_optxagnf struct XS_Optxagnf{T} <: AbstractSpectralModel{T,Additive}
Expand Down
Loading

0 comments on commit 8e05e8a

Please sign in to comment.