diff options
author | Thomas White <taw@physics.org> | 2023-11-13 08:56:03 +0100 |
---|---|---|
committer | Thomas White <taw@physics.org> | 2024-02-06 16:59:34 +0100 |
commit | b22775e1e512a28c6918a3f77cc91e55ef8a1750 (patch) | |
tree | 3e482c136ad9b324f7780e702a31b472372c244d | |
parent | 8ad62271e568c6e80a7b69dccfd575007dca7946 (diff) |
Julia: Implement PeakList
-rw-r--r-- | julia/CrystFEL/src/CrystFEL.jl | 4 | ||||
-rw-r--r-- | julia/CrystFEL/src/image.jl | 3 | ||||
-rw-r--r-- | julia/CrystFEL/src/peaklist.jl | 82 |
3 files changed, 88 insertions, 1 deletions
diff --git a/julia/CrystFEL/src/CrystFEL.jl b/julia/CrystFEL/src/CrystFEL.jl index 590b8973..76305e24 100644 --- a/julia/CrystFEL/src/CrystFEL.jl +++ b/julia/CrystFEL/src/CrystFEL.jl @@ -34,6 +34,10 @@ include("datatemplates.jl") using .DataTemplates export DataTemplate, loaddatatemplate +include("peaklist.jl") +using .PeakLists +export PeakList + include("image.jl") using .Images export Image diff --git a/julia/CrystFEL/src/image.jl b/julia/CrystFEL/src/image.jl index 0f2d91d7..ca0a3da0 100644 --- a/julia/CrystFEL/src/image.jl +++ b/julia/CrystFEL/src/image.jl @@ -3,6 +3,7 @@ module Images import ..CrystFEL: libcrystfel import ..CrystFEL.DataTemplates: DataTemplate, InternalDataTemplate import ..CrystFEL.DetGeoms: DetGeom +import ..CrystFEL.PeakLists: PeakList, InternalPeakList export Image const HEADER_CACHE_SIZE = 128 @@ -32,7 +33,7 @@ mutable struct InternalImage div::Cdouble bw::Cdouble peak_resolution::Cdouble - features::Ptr{Cvoid} + peaks::Ptr{InternalPeakList} ida::Ptr{Cvoid} end diff --git a/julia/CrystFEL/src/peaklist.jl b/julia/CrystFEL/src/peaklist.jl new file mode 100644 index 00000000..4814437f --- /dev/null +++ b/julia/CrystFEL/src/peaklist.jl @@ -0,0 +1,82 @@ +module PeakLists + +import ..CrystFEL: libcrystfel +export PeakList, InternalPeakList + +mutable struct InternalPeak + fs::Cdouble + ss::Cdouble + panelnumber::Cint + intensity::Cdouble + name::Cstring +end + +mutable struct InternalPeakList end + +struct PeakList + internalptr::Ptr{InternalPeakList} +end + + +function PeakList() + out = @ccall libcrystfel.image_feature_list_new()::Ptr{InternalPeakList} + if out == C_NULL + throw(ArgumentError("Failed to create peak list")) + end + PeakList(out) +end + + +function Base.length(peaklist::PeakList) + @ccall libcrystfel.image_feature_count(peaklist.internalptr::Ptr{InternalPeakList})::Cint +end + +Base.firstindex(peaklist::PeakList) = 1 +Base.lastindex(peaklist::PeakList) = length(peaklist) + + +function Base.push!(peaklist::PeakList, fs, ss, panelnumber, intensity, name=nothing) + + rname = isnothing(name) ? C_NULL : @ccall strdup(name::Cstring)::Cstring + + @ccall libcrystfel.image_add_feature(peaklist.internalptr::Ptr{InternalPeakList}, + fs::Cdouble, ss::Cdouble, panelnumber::Cint, + intensity::Cdouble, rname::Cstring)::Cvoid +end + + +function Base.getindex(peaklist::PeakList, n) + out = @ccall(libcrystfel.image_get_feature(peaklist.internalptr::Ptr{InternalPeakList}, + (n-1)::Cint)::Ptr{InternalPeak}) + if out == C_NULL + throw(BoundsError(peaklist, n)) + end + pdata = unsafe_load(out) + if pdata.name == C_NULL + nname = nothing + else + nname = unsafe_string(pdata.name) + end + return (fs=pdata.fs, ss=pdata.ss, panelnumber=pdata.panelnumber, + intensity=pdata.intensity, name=nname) +end + + +function Base.iterate(peaklist::PeakList) + return peaklist[1],(1,length(peaklist)) +end + + +function Base.iterate(peaklist::PeakList, state) + let nxt = state[1]+1 + len = state[2] + if nxt == len+1 + return nothing + else + return peaklist[nxt],(nxt,state[2]) + end + end +end + + +end # of module |