<commit_before>from scipy.io.wavfile import write
import numpy as np

import math
from pax import plugin


class WavOutput(plugin.OutputPlugin):
    """Convert sum waveforms of event and dataset to WAV file

    If we don't find dark matter, at least we'll have contemporary music.
    """

    def startup(self):
        self.filename = self.config['wav_file']

        # Used for building waveform for entire dataset
        self.all_data = {}

        self.n = None
        self.rate = 40000
        self.single_events = False

    def write_event(self, event):
        self.log.debug('Writing event')

        # Make sum waveform without PMT info
        data = event.pmt_waveforms.sum(0)
        self.n = len(data)

        # Note that // is an integer divide
        self.all_data[event.start_time] = event.pmt_waveforms.sum()

        if self.single_events:
            # Write a file
            write('song_%d.wav' % event.event_number,
                  self.rate, # Frequency
                  data)


    def shutdown(self):
        # Determine how long dataset music should be
        start = min(self.all_data)
        end = max(self.all_data)

        if self.n == None:
            self.log.error("Not known how many samples per event!")

        # Resample such that data plays at live speed
        R = 10**9 // self.rate

        n = math.ceil((end - start) / R)
        data = np.zeros(n, dtype=np.int16)
        for key, value in self.all_data.items():
            key -= start
            key = int(key // R)
            self.log.info(key)
            if value > 0:
                data[key] = np.min([value, 2**14])

        # Output<commit_msg>Increase amplitude range of music<commit_after>from scipy.io.wavfile import write
import numpy as np

import math
from pax import plugin


class WavOutput(plugin.OutputPlugin):
    """Convert sum waveforms of event and dataset to WAV file

    If we don't find dark matter, at least we'll have contemporary music.
    """

    def startup(self):
        self.filename = self.config['wav_file']

        # Used for building waveform for entire dataset
        self.all_data = {}

        self.n = None
        self.rate = 40000
        self.single_events = False

    def write_event(self, event):
        self.log.debug('Writing event')

        # Make sum waveform without PMT info
        data = event.pmt_waveforms.sum(0)
        self.n = len(data)

        # Note that // is an integer divide
        self.all_data[event.start_time] = event.pmt_waveforms.sum()

        if self.single_events:
            # Write a file
            write('song_%d.wav' % event.event_number,
                  self.rate, # Frequency
                  data)


    def shutdown(self):
        # Determine how long dataset music should be
        start = min(self.all_data)
        end = max(self.all_data)

        if self.n == None:
            self.log.error("Not known how many samples per event!")

        # Resample such that data plays at live speed
        R = 10**9 // self.rate

        n = math.ceil((end - start) / R)
        data = np.zeros(n, dtype=np.int16)
        for key, value in self.all_data.items():
            key -= start
            key = int(key // R)

            if value > 0:
                data[key] = np.min([value, 2**15 -1])

        # Output
{'fraction_non_alphanumeric': 0.09702613397416641, 'fraction_numerical': 0.009312105737458696, 'mean_word_length': 1.8485885372112918, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4857253', 'n_tokens_mistral': 1030, 'n_tokens_neox': 953, 'n_words': 299}