Skip to content

Commit

Permalink
Fix load_nxs with recent JLD2 (#338)
Browse files Browse the repository at this point in the history
  • Loading branch information
kbarros authored Dec 5, 2024
1 parent 29d570f commit b3aaa27
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 3 deletions.
1 change: 1 addition & 0 deletions docs/src/versions.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
[SeeK-path](http://www.materialscloud.org/tools/seekpath/).
* Add prototype function [`view_qspace`](@ref) for visualizing reciprocal-space
objects in the context of the first Brillouin zone.
* Fix `load_nxs` for compatibility with recent JLD2.

## v0.7.3
(Nov 12, 2024)
Expand Down
6 changes: 3 additions & 3 deletions src/Binning/ExperimentData.jl
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ function load_nxs(filename; field="signal")
transform_from_orig = file["MDHistoWorkspace"]["transform_from_orig"]
transform_from_orig = reshape(transform_from_orig, 5, 5)
transform_from_orig = transform_from_orig'

# U: Orthogonal rotation matrix
# B: inv(lattice_vectors(...)) matrix, as in Sunny
# The matrix stored in the file is transpose of U * B
Expand Down Expand Up @@ -105,7 +105,7 @@ function load_nxs(filename; field="signal")

signal = file["MDHistoWorkspace"]["data"][field]

axes = Dict(JLD2.load_attributes(file, "MDHistoWorkspace/data/signal"))[:axes]
axes = JLD2.load_attributes(file, "MDHistoWorkspace/data/signal")["axes"]

# Axes are just stored backwards in Mantid .nxs for some reason
axes_names = reverse(split(axes,":"))
Expand All @@ -118,7 +118,7 @@ function load_nxs(filename; field="signal")
spatial_covector_ixs = [0,0,0]
std = x -> sqrt(sum((x .- sum(x) ./ length(x)).^2))
for (i, name) in enumerate(axes_names)
long_name = Dict(JLD2.load_attributes(file, "MDHistoWorkspace/data/$name"))[:long_name]
long_name = JLD2.load_attributes(file, "MDHistoWorkspace/data/$name")["long_name"]

if long_name == "DeltaE"
covectors[i,:] .= [0,0,0,1] # energy covector
Expand Down
1 change: 1 addition & 0 deletions test/Project.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[deps]
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
CodecZlib = "944b1d66-785c-5afd-91f1-9de20f533193"
Ewalder = "2efd4204-53b6-4d30-8cf4-11a055f037eb"
ExplicitImports = "7d51a73a-1435-4ff3-83d9-f097790105c7"
FiniteDifferences = "26cc04aa-876d-5657-8c51-4c34ba976000"
Expand Down
Binary file added test/nxs/1Dcut_sym_0p00T_K.nxs
Binary file not shown.
17 changes: 17 additions & 0 deletions test/test_nxs.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
@testitem "load_nxs" begin
import CodecZlib, IOCapture

filename = joinpath(@__DIR__, "nxs", "1Dcut_sym_0p00T_K.nxs")

# Discard warnings
capt = IOCapture.capture() do
load_nxs(filename)
end
params, signal = capt.value

@test isapprox(params.binstart, [-0.05, 0.617, -0.25, -0.1]; atol=1e-7)
@test isapprox(params.binend, [0.0, 0.667, 0.0, 0.6]; atol=1e-7)
@test isapprox(params.binwidth, [0.1, 0.1, 0.5, 0.008]; atol=1e-7)
@test params.covectors == [ 1.0 0.5 0.0 0.0; 0.0 1.0 0.0 0.0; 0.0 0.0 1.0 0.0; 0.0 0.0 0.0 1.0]
@test signal[5:10] [0.0002707771, 0.0001276792, 0.0002237122, 0.0015903557, 0.0177874433, 0.0950909946]
end

0 comments on commit b3aaa27

Please sign in to comment.