paulscherrerinstitute / photodiag

GNU General Public License v3.0
2 stars 2 forks source link

Indexing error in process_eco #9

Closed arrellc closed 5 years ago

arrellc commented 5 years ago

Running res = se.process_eco('/sf/alvra/data/p17589/res/PhotoDiag/scan_info/STT_calib_2002_scan_info.json')

returns an indexing error: TypeError Traceback (most recent call last) /sf/photo/miniconda/lib/python3.6/site-packages/h5py/_hl/selections.py in select(shape, args, dsid) 84 try: ---> 85 int(a) 86 if isinstance(a, np.ndarray) and a.shape == (1,):

TypeError: only size-1 arrays can be converted to Python scalars

During handling of the above exception, another exception occurred:

ValueError Traceback (most recent call last)

in ----> 1 res = se.process_eco('/sf/alvra/data/p17589/res/PhotoDiag/scan_info/STT_calib_2002_scan_info.json') /sf/photo/miniconda/lib/python3.6/site-packages/photodiag/spatial_encoder.py in process_eco(self, filepath, debug) 195 output = [] 196 for i, bsread_file in enumerate(bsread_files): --> 197 step_output = self.process_hdf5(bsread_file, debug=debug) 198 step_output['scan_pos_fs'] = scan_pos_fs[i] 199 output.append(step_output) /sf/photo/miniconda/lib/python3.6/site-packages/photodiag/spatial_encoder.py in process_hdf5(self, filepath, debug) 160 """ 161 if self.events_channel: --> 162 self.calibrate_background(filepath) 163 else: 164 if self._background is None: /sf/photo/miniconda/lib/python3.6/site-packages/photodiag/spatial_encoder.py in calibrate_background(self, filepath) 37 filepath: hdf5 file to be processed with background signal data 38 """ ---> 39 background_data, _, is_dark = self._read_bsread_file(filepath) 40 41 # average over all dark images /sf/photo/miniconda/lib/python3.6/site-packages/photodiag/spatial_encoder.py in _read_bsread_file(self, filepath) 229 if self.events_channel: 230 index = pulse_id - events_channel_group["pulse_id"][0] --> 231 is_dark = events_channel_group["data"][index, 21].astype(bool) 232 else: 233 is_dark = None h5py/_objects.pyx in h5py._objects.with_phil.wrapper() h5py/_objects.pyx in h5py._objects.with_phil.wrapper() /sf/photo/miniconda/lib/python3.6/site-packages/h5py/_hl/dataset.py in __getitem__(self, args) 551 552 # Perform the dataspace selection. --> 553 selection = sel.select(self.shape, args, dsid=self.id) 554 555 if selection.nselect == 0: /sf/photo/miniconda/lib/python3.6/site-packages/h5py/_hl/selections.py in select(shape, args, dsid) 88 except Exception: 89 sel = FancySelection(shape) ---> 90 sel[args] 91 return sel 92 /sf/photo/miniconda/lib/python3.6/site-packages/h5py/_hl/selections.py in __getitem__(self, args) 390 self._id.select_none() 391 for idx, vector in enumerate(argvector): --> 392 start, count, step, scalar = _handle_simple(self.shape, vector) 393 self._id.select_hyperslab(start, count, step, op=h5s.SELECT_OR) 394 /sf/photo/miniconda/lib/python3.6/site-packages/h5py/_hl/selections.py in _handle_simple(shape, args) 455 else: 456 try: --> 457 x,y,z = _translate_int(int(arg), length) 458 s = True 459 except TypeError: /sf/photo/miniconda/lib/python3.6/site-packages/h5py/_hl/selections.py in _translate_int(exp, length) 475 476 if not 0<=exp 477 raise ValueError("Index (%s) out of range (0-%s)" % (exp, length-1)) 478 479 return exp, 1, 1 ValueError: Index (3530) out of range (0-2999)
ivan-usov commented 5 years ago

OK, in the files of that run pulse_ids are not consecutive and have large gaps. I need to implement a more robust correlation for event_codes and data then.