From b664256a0d7bcd5174ba0b3d72312d121e7a8aed Mon Sep 17 00:00:00 2001 From: Mathieu Doucet Date: Thu, 26 Sep 2024 13:52:31 -0400 Subject: [PATCH] add test --- reduction/test/test_time_resolved.py | 34 ++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/reduction/test/test_time_resolved.py b/reduction/test/test_time_resolved.py index 675f47e..67cabeb 100644 --- a/reduction/test/test_time_resolved.py +++ b/reduction/test/test_time_resolved.py @@ -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)