Skip to content

Commit

Permalink
Rename RDWaveform field value to signal (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
fhagemann authored Jun 17, 2022
1 parent 6651296 commit 5a5d2cb
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
18 changes: 9 additions & 9 deletions src/detector_waveforms.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Represents a radiation detector signal waveform.
Fields:
* `time`: time axis, typically a range
* `value`: sample values
* `signal`: detector signal values
Use [`ArrayOfRDWaveforms`](@ref) for arrays of `RDWaveform` that have a
compact memory layout.
Expand All @@ -27,13 +27,13 @@ struct RDWaveform{
TV<:TimeAxis{T},UV<:WaveformSamples{U},
}
time::TV
value::UV
signal::UV
end

export RDWaveform


RDWaveform{T,U,TV,UV}(wf::RDWaveform) where {T,U,TV,UV} = RDWaveform{T,U,TV,UV}(wf.time, wf.value)
RDWaveform{T,U,TV,UV}(wf::RDWaveform) where {T,U,TV,UV} = RDWaveform{T,U,TV,UV}(wf.time, wf.signal)
Base.convert(::Type{RDWaveform{T,U,TV,UV}}, wf::RDWaveform) where {T,U,TV,UV} = RDWaveform{T,U,TV,UV}(wf)


Expand All @@ -54,7 +54,7 @@ const ArrayOfRDWaveforms{
} = StructArray{
<:RDWaveform{T,U},
N,
NamedTuple{(:time, :value), Tuple{VVT,VVU}}
NamedTuple{(:time, :signal), Tuple{VVT,VVU}}
}

export ArrayOfRDWaveforms
Expand All @@ -66,17 +66,17 @@ function StructArray{RDWaveform}(
AbstractArray{<:AbstractVector{<:RealQuantity},N}
}
) where {N}
time, value = contents
time, signal = contents
VT = eltype(time)
VU = eltype(value)
VU = eltype(signal)
T = eltype(VT)
U = eltype(VU)
StructArray{RDWaveform{T,U,VT,VU}}((time, value))
StructArray{RDWaveform{T,U,VT,VU}}((time, signal))
end


StructArray{RDWaveform}(waveforms::AbstractVector{<:RDWaveform}) =
StructArray{RDWaveform}((map(w -> w.time, waveforms), VectorOfVectors(map(w -> w.value, waveforms))))
StructArray{RDWaveform}((map(w -> w.time, waveforms), VectorOfVectors(map(w -> w.signal, waveforms))))

Base.convert(::Type{ArrayOfRDWaveforms}, waveforms::AbstractVector{<:RDWaveform}) = StructArray{RDWaveform}(waveforms)
Base.convert(::Type{ArrayOfRDWaveforms}, waveforms::StructArray{<:RDWaveform}) = waveforms
Expand All @@ -88,7 +88,7 @@ Base.convert(::Type{StructArray{RDWaveform}}, waveforms::StructArray{<:RDWavefor
# Specialize getindex to properly support ArraysOfArrays, preventing
# conversion to exact element type:
@inline Base.getindex(A::StructArray{<:RDWaveform}, I::Int...) =
RDWaveform(A.time[I...], A.value[I...])
RDWaveform(A.time[I...], A.signal[I...])


@inline ArrayOfRDWaveforms(contents) = StructArray{RDWaveform}(contents)
Expand Down
4 changes: 2 additions & 2 deletions src/plots_recipes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@ end
@series begin
seriestype := seriestype
xguide --> "t"
yguide --> "sample value"
yguide --> "signal"
unitformat --> :square
wf.time, wf.value
wf.time, wf.signal
end

#=
Expand Down
8 changes: 4 additions & 4 deletions test/test_detector_waveforms.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ using ArraysOfArrays, FillArrays, StructArrays, Unitful
A = ArrayOfRDWaveforms((timedata, wfdata))

@test A.time[1] == A[1].time == 0:0.1:12.7
@test A.value isa ArrayOfSimilarArrays
@test A.value[1] == A[1].value
@test A.signal isa ArrayOfSimilarArrays
@test A.signal[1] == A[1].signal
end # testset

@testset "detector_waveforms with units" begin
Expand All @@ -28,6 +28,6 @@ end # testset
A = ArrayOfRDWaveforms((timedata, wfdata))

@test A.time[1] == A[1].time == (0:0.1:12.7) * u"ns"
@test A.value isa ArrayOfSimilarArrays
@test A.value[1] == A[1].value
@test A.signal isa ArrayOfSimilarArrays
@test A.signal[1] == A[1].signal
end # testset

0 comments on commit 5a5d2cb

Please sign in to comment.