Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test for time-resolved reduction #47

Merged
merged 1 commit into from
Sep 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions reduction/test/test_time_resolved.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,37 @@ def test_reduce_workflow(nexus_dir):
# Plot data
time_resolved.plot_slices(reduced, 'Test', 300,
os.path.join(output_dir, 'reduced.png'), show=False)


def test_reduce_template_workflow(nexus_dir):
"""
Test the time-resolved reduction that uses a template.
"""
template_path = 'data/template.xml'
output_dir = 'data/'
reduced_path = 'data/reference_rq_avg_overlap.txt'
ref_data = np.loadtxt(reduced_path).T
with amend_config(data_dir=nexus_dir):
reduced = time_resolved.reduce_slices(198413,
template_file=template_path,
time_interval=300,
output_dir=output_dir,
scan_index=5,
create_plot=False)

q_long = len(ref_data[0])
q_short = len(reduced[0][0])
n_match = 0
n_pts = 0
for i in range(q_long):
if ref_data[0][i] > 0.03 and ref_data[0][i] < 0.045:
n_pts += 1
for k in range(q_short):
if np.fabs(reduced[0][0][k] - ref_data[0][i]) < 0.0001:
assert(np.fabs(reduced[0][1][k] - ref_data[1][i]) < 1e-10)
n_match += 1
assert(n_pts == n_match)

# Plot data
time_resolved.plot_slices(reduced, 'Test', 300,
os.path.join(output_dir, 'reduced_template.png'), show=False)
Loading