From da94f03c45ab98fffe041b96a883c0795f076f42 Mon Sep 17 00:00:00 2001 From: Keara Soloway Date: Thu, 24 Oct 2024 09:43:50 -0400 Subject: [PATCH] perf: use slices of points in results of edd.UpdateNXdataReader to improve speed when used with common.UpdateNXvalueProcessor --- CHAP/common/processor.py | 4 ++-- CHAP/edd/reader.py | 40 +++++++++++++++++++--------------------- 2 files changed, 21 insertions(+), 23 deletions(-) diff --git a/CHAP/common/processor.py b/CHAP/common/processor.py index ceaf0e7..a2c67a5 100755 --- a/CHAP/common/processor.py +++ b/CHAP/common/processor.py @@ -2809,8 +2809,8 @@ def process(self, data, nxfilename, data_points=None, inputdir=None): except Exception as exc: self.logger.error(f'Error updating {data_point["nxpath"]} for ' f'data point {data_point["index"]}: {exc}') - self.logger.info( - f'Successfully updated data_points {list_to_string(indices)}') + else: + self.logger.debug(f'Updated data point {data_point}') nxfile.close() diff --git a/CHAP/edd/reader.py b/CHAP/edd/reader.py index edd29fe..e553104 100755 --- a/CHAP/edd/reader.py +++ b/CHAP/edd/reader.py @@ -849,28 +849,26 @@ def read(self, spec_file, scan_number, detector_ids=None, inputdir='.'): detector_data = {id_: detector_data[:,i,:] for i, id_ in enumerate(detector_ids)} spec_scan_data = scanparser.spec_scan_data - motor_vals_relative = scanparser.spec_scan_motor_vals_relative - data_points = [] self.logger.info(f'Getting {scanparser.spec_scan_npts} data points') - for i in range(scanparser.spec_scan_npts): - self.logger.debug(f'Getting data point for scan step index {i}') - index = dataset_point_index_offset + i - data_points += [ - {'nxpath': f'entry/data/{k}', 'index': index, 'value': v} - for k, v in smb_par_values.items()] - data_points += [ - {'nxpath': f'entry/data/{id_}', 'index': index, - 'value': data[i]} - for id_, data in detector_data.items()] - data_points += [ - {'nxpath': f'entry/data/{c}', 'index': index, - 'value': spec_scan_data[counters[c]][i]} - for c in counters] - step = scanparser.get_scan_step(i) - data_points += [ - {'nxpath': f'entry/data/{a}', 'index': index, - 'value': round(motor_vals_relative[j][step[j]], 3)} - for j, a in enumerate(scan_axes)] + idx = slice(dataset_point_index_offset, + dataset_point_index_offset + scanparser.spec_scan_npts) + data_points = [ + {'nxpath': f'entry/data/{k}', + 'value': [v] * scanparser.spec_scan_npts, + 'index': idx} + for k, v in smb_par_values.items()] + data_points.extend([ + {'nxpath': f'entry/data/{id_}', + 'value': data, + 'index': idx} + for id_, data in detector_data.items() + ]) + data_points.extend([ + {'nxpath': f'entry/data/{c}', + 'value': spec_scan_data[counters[c]], + 'index': idx} + for c in counters + ]) return data_points