-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat!: add Tag parameter to SpectralData
This enormously simplifies derived datatypes, and removed the API forwarding macro that was unreliable to maintain. Follows from the Tagging idea introduced with BinnedData, and allows derived types to be implemented more easily. Updated OGIP, XMM and NuSTAR datatypes to use this tagging system instead of adding new types. Modified test cases to sync with changes.
- Loading branch information
Showing
6 changed files
with
67 additions
and
186 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,87 +1,24 @@ | ||
struct NuSTAR <: AbstractInstrument end | ||
struct XmmEPIC <: AbstractInstrument end | ||
|
||
struct NuStarData{T,H} <: AbstractDataset | ||
data::SpectralData{T} | ||
paths::SpectralDataPaths | ||
observation_id::String | ||
exposure_id::String | ||
object::String | ||
header::H | ||
end | ||
|
||
NuStarData(spec_path; rmf_matrix_index = 3, rmf_energy_index = 2, kwargs...) = NuStarData( | ||
load_ogip_dataset( | ||
function NuStarData(spec_path; rmf_matrix_index = 3, rmf_energy_index = 2, kwargs...) | ||
OGIPDataset( | ||
spec_path; | ||
rmf_matrix_index = rmf_matrix_index, | ||
tag = NuSTAR(), | ||
rmf_energy_index = rmf_energy_index, | ||
rmf_matrix_index = rmf_matrix_index, | ||
kwargs..., | ||
)..., | ||
) | ||
|
||
make_label(data::NuStarData) = data.observation_id | ||
|
||
@_forward_SpectralData_api NuStarData.data | ||
|
||
function Base.show(io::IO, @nospecialize(data::NuStarData{T})) where {T} | ||
print(io, "NuStarData[obs_id=$(data.observation_id)]") | ||
end | ||
|
||
function _printinfo(io, data::NuStarData{T}) where {T} | ||
descr = """NuStarData: | ||
. Object : $(data.object) | ||
. Observation ID : $(data.observation_id) | ||
. Exposure ID : $(data.exposure_id) | ||
""" | ||
print(io, descr) | ||
_printinfo(io, data.data) | ||
) | ||
end | ||
|
||
|
||
abstract type AbstractXmmNewtonDevice end | ||
struct XmmEPIC <: AbstractXmmNewtonDevice end | ||
|
||
struct XmmData{T,H,D} <: AbstractDataset | ||
device::D | ||
data::SpectralData{T} | ||
paths::SpectralDataPaths | ||
observation_id::String | ||
exposure_id::String | ||
object::String | ||
header::H | ||
end | ||
|
||
XmmData( | ||
device::AbstractXmmNewtonDevice, | ||
spec_path; | ||
rmf_matrix_index = 2, | ||
rmf_energy_index = 3, | ||
kwargs..., | ||
) = XmmData( | ||
device, | ||
load_ogip_dataset( | ||
function XmmData(spec_path; rmf_matrix_index = 2, rmf_energy_index = 3, kwargs...) | ||
OGIPDataset( | ||
spec_path; | ||
rmf_matrix_index = rmf_matrix_index, | ||
tag = XmmEPIC(), | ||
rmf_energy_index = rmf_energy_index, | ||
rmf_matrix_index = rmf_matrix_index, | ||
kwargs..., | ||
)..., | ||
) | ||
|
||
make_label(data::XmmData) = data.observation_id | ||
|
||
@_forward_SpectralData_api XmmData.data | ||
|
||
function Base.show(io::IO, @nospecialize(data::XmmData{T})) where {T} | ||
print(io, "XmmData[dev=$(data.device),obs_id=$(data.observation_id)]") | ||
) | ||
end | ||
|
||
function _printinfo(io, data::XmmData{T}) where {T} | ||
descr = """XmmData for $(Base.typename(typeof(data.device)).name): | ||
. Object : $(data.object) | ||
. Observation ID : $(data.observation_id) | ||
. Exposure ID : $(data.exposure_id) | ||
""" | ||
print(io, descr) | ||
_printinfo(io, data.data) | ||
end | ||
|
||
|
||
export NuStarData, XmmData, XmmEPIC |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,12 @@ | ||
using Test, SpectralFitting | ||
|
||
# path to the data directory | ||
data1 = SpectralFitting.XmmData( | ||
SpectralFitting.XmmEPIC(), | ||
joinpath(testdir, "xmm/pn_spec_grp.fits"), | ||
) | ||
data1 = SpectralFitting.XmmData(joinpath(testdir, "xmm/pn_spec_grp.fits")) | ||
|
||
|
||
# smoke test | ||
model = GaussianLine() + PowerLaw(a = FitParam(0.2)) | ||
sim = simulate( | ||
model, | ||
data1.data.response, | ||
data1.data.ancillary; | ||
seed = 8, | ||
exposure_time = 1e1, | ||
) | ||
sim = simulate(model, data1.response, data1.ancillary; seed = 8, exposure_time = 1e1) | ||
|
||
# TODO: add a fit. can't do it at the moment as the simulated datasets don't | ||
# support masking the model domain, so we have singular values at high energies |