Exemplo n.º 1
0
    def compute(self, peaklets, merged_s2s):
        # Remove fake merged S2s from dirty hack, see above
        merged_s2s = merged_s2s[merged_s2s['type'] != FAKE_MERGED_S2_TYPE]

        peaks = strax.replace_merged(peaklets, merged_s2s)

        if self.config['diagnose_sorting']:
            assert np.all(np.diff(peaks['time']) >= 0), "Peaks not sorted"
            assert np.all(peaks['time'][1:] >= strax.endtime(peaks)[:-1]
                          ), "Peaks not disjoint"
        return peaks
Exemplo n.º 2
0
    def compute(self, peaklets, merged_s2s):
        # Remove fake merged S2s from dirty hack, see above
        merged_s2s = merged_s2s[merged_s2s['type'] != FAKE_MERGED_S2_TYPE]

        if self.config['merge_without_s1']:
            is_s1 = peaklets['type'] == 1
            peaks = strax.replace_merged(peaklets[~is_s1], merged_s2s)
            peaks = strax.sort_by_time(np.concatenate([peaklets[is_s1],
                                                       peaks]))
        else:
            peaks = strax.replace_merged(peaklets, merged_s2s)

        if self.config['diagnose_sorting']:
            assert np.all(np.diff(peaks['time']) >= 0), "Peaks not sorted"
            if self.config['merge_without_s1']:
                to_check = peaks['type'] != 1
            else:
                to_check = peaks['type'] != FAKE_MERGED_S2_TYPE

            assert np.all(peaks['time'][to_check][1:] >= strax.endtime(peaks)
                          [to_check][:-1]), "Peaks not disjoint"
        return peaks
Exemplo n.º 3
0
def test_replace_merged(intervals, merge_instructions):
    # First we have to create some merged intervals.
    # We abuse the interval generation mechanism to create 'merge_instructions'
    # i.e. something to tell us which indices of intervals must be merged
    # together.

    merged_itvs = []
    to_remove = []
    for x in merge_instructions:
        start, end_inclusive = x['time'], x['time'] + x['length'] - 1
        if end_inclusive == start or end_inclusive >= len(intervals):
            # Pointless / invalid merge instruction
            continue
        to_remove.extend(list(range(start, end_inclusive + 1)))
        new = np.zeros(1, strax.interval_dtype)[0]
        new['time'] = intervals[start]['time']
        new['length'] = strax.endtime(intervals[end_inclusive]) - new['time']
        new['dt'] = 1
        merged_itvs.append(new)
    removed_itvs = []
    kept_itvs = []
    for i, itv in enumerate(intervals):
        if i in to_remove:
            removed_itvs.append(itv)
        else:
            kept_itvs.append(itv)

    kept_itvs = np.array(kept_itvs)
    merged_itvs = np.array(merged_itvs)

    result = strax.replace_merged(intervals, merged_itvs)
    assert len(result) == len(merged_itvs) + len(kept_itvs)
    assert np.all(np.diff(result['time']) > 0), "Not sorted"
    assert np.all(
        result['time'][1:] - strax.endtime(result)[:-1] >= 0), "Overlap"
    for x in kept_itvs:
        assert x in result, "Removed too many"
    for x in merged_itvs:
        assert x in result, "Didn't put in merged"
    for x in result:
        assert np.isin(x, merged_itvs) or np.isin(x, kept_itvs), "Invented itv"