AxFoundation/strax

Bug in peak_merging

Closed this issue · 1 comments

Describe the bug
There is some indexing error in Merging S2s

To Reproduce
Insert the MWE of how to reproduce the error

import straxen
straxen.print_versions()
st = straxen.contexts.xenonnt('global_v5')

for _ in st.get_iter('022261', 'peak_basics', progress_bar=True):
    pass

Traceback*

Loading peak_basics:
60.15 % [05:57<03:58], #35 (10.54 s). 640.7 kB/s

Exception in thread Target Mailbox (peak_basics) killed, exception <class 'strax.mailbox.MailboxKilled'>, message (<class 'ValueError'>, ValueError('could not broadcast input array from shape (106) into shape (0)'), <traceback object at 0x7ff5e441ec00>)
build:merged_s2s:
Traceback (most recent call last):
  File "/home/angevaare/software/Miniconda3/envs/strax_dev/lib/python3.8/threading.py", line 932, in _bootstrap_inner
    self.run()
  File "/home/angevaare/software/Miniconda3/envs/strax_dev/lib/python3.8/threading.py", line 870, in run
    self._target(*self._args, **self._kwargs)
  File "/home/angevaare/software/dev_strax/strax/strax/mailbox.py", line 294, in _send_from
    self.kill_from_exception(e)
  File "/home/angevaare/software/dev_strax/strax/strax/mailbox.py", line 213, in kill_from_exception
    raise e
  File "/home/angevaare/software/dev_strax/strax/strax/mailbox.py", line 281, in _send_from
    x = next(iterable)
  File "/home/angevaare/software/dev_strax/strax/strax/plugin.py", line 616, in iter
    yield from super().iter(iters, executor=executor)
  File "/home/angevaare/software/dev_strax/strax/strax/plugin.py", line 427, in iter
    yield self.do_compute(chunk_i=chunk_i, **inputs_merged)
  File "/home/angevaare/software/dev_strax/strax/strax/plugin.py", line 633, in do_compute
    result = super().do_compute(chunk_i=chunk_i, **kwargs)
  File "/home/angevaare/software/dev_strax/strax/strax/plugin.py", line 525, in do_compute
    result = self.compute(**kwargs)
  File "/home/angevaare/software/dev_strax/straxen/straxen/plugins/peaklet_processing.py", line 673, in compute
    merged_s2s = strax.merge_peaks(
  File "/home/angevaare/software/dev_strax/strax/strax/processing/peak_merging.py", line 59, in merge_peaks
    buffer[i0: i0 + n_after] = \
ValueError: could not broadcast input array from shape (106) into shape (0)

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-3-9e3f0e7bc7d6> in <module>
----> 1 for _ in st.get_iter('022261', 'peak_basics', progress_bar=True):
      2     pass

~/software/dev_strax/strax/strax/context.py in get_iter(self, run_id, targets, save, max_workers, time_range, seconds_range, time_within, time_selection, selection_str, keep_columns, drop_columns, allow_multiple, progress_bar, _chunk_number, **kwargs)
   1142 
   1143         except Exception as e:
-> 1144             generator.throw(e)
   1145             raise ValueError(f'Failed to process chunk {n_chunks}!')
   1146 

~/software/dev_strax/strax/strax/context.py in get_iter(self, run_id, targets, save, max_workers, time_range, seconds_range, time_within, time_selection, selection_str, keep_columns, drop_columns, allow_multiple, progress_bar, _chunk_number, **kwargs)
   1114                 pbar.last_print_t = time.time()
   1115                 pbar.mbs = []
-> 1116                 for n_chunks, result in enumerate(strax.continuity_check(generator), 1):
   1117                     seen_a_chunk = True
   1118                     if not isinstance(result, strax.Chunk):

~/software/dev_strax/strax/strax/chunk.py in continuity_check(chunk_iter)
    301 
    302     last_subrun = {'run_id': None}
--> 303     for chunk in chunk_iter:
    304         if chunk.run_id != last_runid:
    305             last_end = None

~/software/dev_strax/strax/strax/processor.py in iter(self)
    300             # which is printed for the user
    301             self.log.debug("Reraising exception")
--> 302             raise exc.with_traceback(traceback)
    303 
    304         # Check the savers for any exception that occurred during saving

~/software/dev_strax/strax/strax/mailbox.py in _send_from(self, iterable)
    279 
    280                 try:
--> 281                     x = next(iterable)
    282                 except StopIteration:
    283                     # No need to send this yet, close will do that

~/software/dev_strax/strax/strax/plugin.py in iter(self, iters, executor)
    614 
    615     def iter(self, iters, executor=None):
--> 616         yield from super().iter(iters, executor=executor)
    617 
    618         # Yield final results, kept at bay in fear of a new chunk

~/software/dev_strax/strax/strax/plugin.py in iter(self, iters, executor)
    425                     yield new_future
    426                 else:
--> 427                     yield self.do_compute(chunk_i=chunk_i, **inputs_merged)
    428 
    429         except IterDone:

~/software/dev_strax/strax/strax/plugin.py in do_compute(self, chunk_i, **kwargs)
    631 
    632         # Compute new results
--> 633         result = super().do_compute(chunk_i=chunk_i, **kwargs)
    634 
    635         # Throw away results we already sent out

~/software/dev_strax/strax/strax/plugin.py in do_compute(self, chunk_i, **kwargs)
    523             kwargs['start'] = start
    524             kwargs['end'] = end
--> 525         result = self.compute(**kwargs)
    526 
    527         return self._fix_output(result, start, end)

~/software/dev_strax/straxen/straxen/plugins/peaklet_processing.py in compute(self, peaklets, lone_hits)
    671                 max_area=max_area,
    672             )
--> 673             merged_s2s = strax.merge_peaks(
    674                 peaklets,
    675                 start_merge_at, end_merge_at,

~/software/dev_strax/strax/strax/processing/peak_merging.py in merge_peaks(peaks, start_merge_at, end_merge_at, max_buffer)
     57             n_after = p['length'] * upsample
     58             i0 = (p['time'] - new_p['time']) // common_dt
---> 59             buffer[i0: i0 + n_after] = \
     60                 np.repeat(p['data'][:p['length']], upsample) / upsample
     61 

ValueError: could not broadcast input array from shape (106) into shape (0)

Versions

Working on midway2-0462.rcc.local with the following versions and installation paths:
python	v3.8.0	(default, Nov  6 2019, 21:49:08) [GCC 7.3.0]
strax	v1.1.1	/home/angevaare/software/dev_strax/strax/strax	git branch:unknown | 9262448
straxen	v1.1.2	/home/angevaare/software/dev_strax/straxen/straxen	git branch:unknown | 63a1561
cutax	v0.2.2	/home/angevaare/software/dev_strax/cutax/cutax	git branch:master | 0e9819e