예제 #1
0
def loop(zipped):

    threshold = float(zipped[0])
    seed = int(zipped[1])

    station = NuRadioReco.framework.station.Station(station_id)
    evt = NuRadioReco.framework.event.Event(0, 0)

    channelGenericNoiseAdder = NuRadioReco.modules.channelGenericNoiseAdder.channelGenericNoiseAdder(
    )
    channelGenericNoiseAdder.begin(seed=seed)

    for channel_id in channel_ids:
        # Noise rms is amplified to greater than Vrms so that, after filtering, its the Vrms we expect
        spectrum = channelGenericNoiseAdder.bandlimited_noise(
            min_freq,
            max_freq,
            n_samples,
            sampling_rate,
            amplitude,
            type="rayleigh",
            time_domain=False)

        trace = fft.freq2time(spectrum * filt, sampling_rate)

        channel = NuRadioReco.framework.channel.Channel(channel_id)
        channel.set_trace(trace, sampling_rate)
        station.add_channel(channel)

    threshold_ = threshold * np.power(Vrms, 2.0)

    triggered = triggerSimulator.run(evt,
                                     station,
                                     det,
                                     Vrms,
                                     threshold_,
                                     triggered_channels=channels,
                                     phasing_angles=default_angles,
                                     ref_index=1.75,
                                     trigger_name='primary_phasing',
                                     trigger_adc=False,
                                     adc_output='voltage',
                                     trigger_filter=None,
                                     upsampling_factor=upsampling_factor,
                                     window=window_length,
                                     step=step_length)

    return triggered
예제 #2
0
    def _detector_simulation_trigger(self, evt, station, det):
        # Start detector simulation

        orig_traces = {}
        for channel in station.iter_channels():
            orig_traces[channel.get_id()] = channel.get_trace()

            # If there is an empty trace, leave
            if (np.sum(channel.get_trace()) == 0):
                return

        filtered_signal_traces = {}
        for channel in station.iter_channels(use_channels=channels):
            trace = np.array(channel.get_trace())
            channel.set_trace(trace, new_sampling_rate)
            filtered_signal_traces[channel.get_id()] = trace

        # Since there are often two traces within the same thing, gotta be careful
        Vpps = []
        for channel in station.iter_channels(use_channels=channels):
            trace = np.array(channel.get_trace())
            Vpps += [np.max(trace) - np.min(trace)]
        Vpps = np.array(Vpps)

        # loop over all channels (i.e. antennas) of the station
        for channel in station.iter_channels(use_channels=channels):
            trace = np.zeros(len(filtered_signal_traces[channel.get_id()][:]))
            channel.set_trace(trace, sampling_rate=new_sampling_rate)

        # Adding noise AFTER the SNR calculation
        channelGenericNoiseAdder.run(evt,
                                     station,
                                     det,
                                     amplitude=Vrms / Vrms_ratio,
                                     min_freq=min_freq,
                                     max_freq=max_freq,
                                     type='rayleigh')

        # bandpass filter trace, the upper bound is higher then the sampling rate which makes it just a highpass filter
        channelBandPassFilter.run(evt,
                                  station,
                                  det,
                                  passband=[0 * units.MHz, 220.0 * units.MHz],
                                  filter_type='cheby1',
                                  order=7,
                                  rp=.1)
        channelBandPassFilter.run(
            evt,
            station,
            det,
            passband=[96.0 * units.MHz, 100.0 * units.GHz],
            filter_type='cheby1',
            order=4,
            rp=.1)

        filtered_noise_traces = {}
        for channel in station.iter_channels(use_channels=channels):
            filtered_noise_traces[channel.get_id()] = channel.get_trace()

        factor = 1.0 / (np.mean(Vpps) / (2.0 * Vrms))
        mult_factors = factor * SNRs

        if (np.mean(Vpps) == 0.0):
            return

        for factor, iSNR in zip(mult_factors, range(len(mult_factors))):

            for channel in station.iter_channels(use_channels=channels):
                trace = copy.deepcopy(
                    filtered_signal_traces[channel.get_id()][:]) * factor
                noise = copy.deepcopy(filtered_noise_traces[channel.get_id()])
                channel.set_trace(trace + noise,
                                  sampling_rate=new_sampling_rate)

            has_triggered = triggerSimulator.run(
                evt,
                station,
                det,
                Vrms=Vrms,
                threshold=threshold,
                triggered_channels=channels,
                phasing_angles=phasing_angles,
                ref_index=1.75,
                trigger_name='primary_phasing',
                trigger_adc=False,
                adc_output='voltage',
                trigger_filter=None,
                upsampling_factor=upsampling_factor,
                window=window,
                step=step)

            if (has_triggered):
                print('Trigger for SNR', SNRs[iSNR])
                SNRtriggered[iSNR] += 1

        count_events()
        print(count_events.events)
        print(SNRtriggered)

        if (count_events.events % 10 == 0):
            output = {
                'total_events': count_events.events,
                'SNRs': list(SNRs),
                'triggered': list(SNRtriggered)
            }
            outputfile = args.outputSNR
            with open(outputfile, 'w+') as fout:
                json.dump(output, fout, sort_keys=True, indent=4)
예제 #3
0
    def _detector_simulation_part2(self):
        # Start detector simulation

        # Convolve efield with antenna pattern
        efieldToVoltageConverter.run(self._evt, self._station, self._det)

        # Downsample trace back to detector sampling rate
        channelResampler.run(self._evt,
                             self._station,
                             self._det,
                             sampling_rate=new_sampling_rate)

        # Filter signals
        channelBandPassFilter.run(
            self._evt,
            self._station,
            self._det,
            passband=[0.0 * units.MHz, 240.0 * units.MHz],
            filter_type='cheby1',
            order=9,
            rp=.1)
        channelBandPassFilter.run(
            self._evt,
            self._station,
            self._det,
            passband=[80.0 * units.MHz, 230.0 * units.MHz],
            filter_type='cheby1',
            order=4,
            rp=.1)

        filtered_signal_traces = {}
        for channel in self._station.iter_channels():
            trace = np.array(channel.get_trace())
            filtered_signal_traces[channel.get_id()] = trace

        # Since there are often two traces within the same thing, gotta be careful
        Vpps = np.zeros(self._station.get_number_of_channels())
        for iChan, channel in enumerate(self._station.iter_channels()):
            trace = np.array(channel.get_trace())
            Vpps[iChan] = np.max(trace) - np.min(trace)

        factor = 1.0 / (np.mean(Vpps) / 2.0)
        mult_factors = factor * SNRs

        has_triggered = True
        while (has_triggered
               ):  # search for noise traces that don't set off a trigger

            # loop over all channels (i.e. antennas) of the station
            for channel in self._station.iter_channels():
                trace = np.zeros(
                    len(filtered_signal_traces[channel.get_id()][:]))
                channel.set_trace(trace, sampling_rate=new_sampling_rate)

            # Adding noise AFTER the SNR calculation
            channelGenericNoiseAdder.run(self._evt,
                                         self._station,
                                         self._det,
                                         amplitude=1.0 / Vrms_ratio,
                                         min_freq=min_freq,
                                         max_freq=max_freq,
                                         type='rayleigh')

            # bandpass filter trace, the upper bound is higher then the sampling rate which makes it just a highpass filter
            channelBandPassFilter.run(
                self._evt,
                self._station,
                self._det,
                passband=[0 * units.MHz, 240.0 * units.MHz],
                filter_type='cheby1',
                order=9,
                rp=.1)
            channelBandPassFilter.run(
                self._evt,
                self._station,
                self._det,
                passband=[80.0 * units.MHz, 230.0 * units.MHz],
                filter_type='cheby1',
                order=4,
                rp=.1)

            if (phase):
                has_triggered = triggerSimulator.run(
                    self._evt,
                    self._station,
                    self._det,
                    Vrms=1.0,
                    threshold=threshold,
                    triggered_channels=channels,
                    phasing_angles=phasing_angles,
                    ref_index=1.75,
                    trigger_name='primary_phasing',
                    trigger_adc=
                    False,  # Don't have a seperate ADC for the trigger
                    clock_offset=np.random.uniform(0.0, 2.0),
                    adc_output='voltage',  # output in volts
                    trigger_filter=None,
                    upsampling_factor=upsampling_factor,
                    window=window,
                    step=step)
            else:
                original_traces_ = self._station.get_channel(4).get_trace()

                squared_mean, num_frames = triggerSimulator.power_sum(
                    coh_sum=original_traces_,
                    window=window,
                    step=step,
                    adc_output='voltage')

                squared_mean_threshold = np.power(threshold, 2.0)

                has_triggered = (True
                                 in (squared_mean > squared_mean_threshold))

            if (has_triggered):
                print('Trigger on noise... ')

        filtered_noise_traces = {}
        for channel in self._station.iter_channels():
            filtered_noise_traces[channel.get_id()] = channel.get_trace()

        for factor, iSNR in zip(mult_factors, range(len(mult_factors))):

            for channel in self._station.iter_channels():
                trace = copy.deepcopy(
                    filtered_signal_traces[channel.get_id()][:]) * factor
                noise = filtered_noise_traces[channel.get_id()]
                channel.set_trace(trace + noise,
                                  sampling_rate=new_sampling_rate)

            if (phase):
                has_triggered = triggerSimulator.run(
                    self._evt,
                    self._station,
                    self._det,
                    Vrms=1.0,
                    threshold=threshold,
                    triggered_channels=channels,
                    phasing_angles=phasing_angles,
                    ref_index=1.75,
                    trigger_name='primary_phasing',
                    trigger_adc=False,
                    clock_offset=np.random.uniform(0.0, 2.0),
                    adc_output='voltage',
                    trigger_filter=None,
                    upsampling_factor=upsampling_factor,
                    window=window,
                    step=step)
            else:
                original_traces_ = self._station.get_channel(4).get_trace()

                squared_mean, num_frames = triggerSimulator.power_sum(
                    coh_sum=original_traces_,
                    window=window,
                    step=step,
                    adc_output='voltage')

                squared_mean_threshold = np.power(threshold, 2.0)

                has_triggered = (True
                                 in (squared_mean > squared_mean_threshold))

            if (has_triggered):
                print('Trigger for SNR', SNRs[iSNR])
                SNRtriggered[iSNR] += 1

        count_events()
        print(count_events.events)
        print(SNRtriggered)

        if (count_events.events % 10 == 0):
            # plt.show()
            # Save every ten triggers
            output = {
                'total_events': count_events.events,
                'SNRs': list(SNRs),
                'triggered': list(SNRtriggered)
            }
            outputfile = args.outputSNR
            with open(outputfile, 'w+') as fout:
                json.dump(output, fout, sort_keys=True, indent=4)
예제 #4
0
    def _detector_simulation_part2(self):
        # start detector simulation
        efieldToVoltageConverter.run(
            self._evt, self._station,
            self._det)  # convolve efield with antenna pattern
        # downsample trace to 1.5 Gs/s
        new_sampling_rate = 1.5 * units.GHz
        channelResampler.run(self._evt,
                             self._station,
                             self._det,
                             sampling_rate=new_sampling_rate)

        cut_times = get_window_around_maximum(self._station)

        # Bool for checking the noise triggering rate
        check_only_noise = False

        if check_only_noise:
            for channel in self._station.iter_channels():
                trace = channel.get_trace() * 0
                channel.set_trace(trace, sampling_rate=new_sampling_rate)

        if self._is_simulate_noise():
            max_freq = 0.5 / self._dt
            norm = self._get_noise_normalization(self._station.get_id(
            ))  # assuming the same noise level for all stations
            channelGenericNoiseAdder.run(self._evt,
                                         self._station,
                                         self._det,
                                         amplitude=self._Vrms,
                                         min_freq=0 * units.MHz,
                                         max_freq=max_freq,
                                         type='rayleigh',
                                         bandwidth=norm)

        # bandpass filter trace, the upper bound is higher then the sampling rate which makes it just a highpass filter
        channelBandPassFilter.run(self._evt,
                                  self._station,
                                  self._det,
                                  passband=[130 * units.MHz, 1000 * units.GHz],
                                  filter_type='butter',
                                  order=6)
        channelBandPassFilter.run(self._evt,
                                  self._station,
                                  self._det,
                                  passband=[0, 750 * units.MHz],
                                  filter_type='butter',
                                  order=10)

        # run the phased trigger
        triggerSimulator.run(
            self._evt,
            self._station,
            self._det,
            threshold=2.5 *
            self._Vrms,  # see phased trigger module for explanation
            triggered_channels=None,  # run trigger on all channels
            secondary_channels=[0, 1, 3, 4, 6, 7],  # secondary channels
            trigger_name=
            'primary_and_secondary_phasing',  # the name of the trigger
            coupled=True,
            cut_times=cut_times)
예제 #5
0
    def _detector_simulation_trigger(self, evt, station, det):

        Vrms = self._Vrms

        simpleThreshold.run(
            evt,
            station,
            det,
            threshold=1.0 * Vrms,
            triggered_channels=[4],  # run trigger on all channels
            number_concidences=1,
            trigger_name='dipole_1.0sigma')
        simpleThreshold.run(
            evt,
            station,
            det,
            threshold=1.5 * Vrms,
            triggered_channels=[4],  # run trigger on all channels
            number_concidences=1,
            trigger_name='dipole_1.5sigma')
        simpleThreshold.run(
            evt,
            station,
            det,
            threshold=2.0 * Vrms,
            triggered_channels=[4],  # run trigger on all channels
            number_concidences=1,
            trigger_name='dipole_2.0sigma')
        simpleThreshold.run(
            evt,
            station,
            det,
            threshold=2.5 * Vrms,
            triggered_channels=[4],  # run trigger on all channels
            number_concidences=1,
            trigger_name='dipole_2.5sigma')
        simpleThreshold.run(
            evt,
            station,
            det,
            threshold=3.0 * Vrms,
            triggered_channels=[4],  # run trigger on all channels
            number_concidences=1,
            trigger_name='dipole_3.0sigma')
        simpleThreshold.run(
            evt,
            station,
            det,
            threshold=3.5 * Vrms,
            triggered_channels=[4],  # run trigger on all channels
            number_concidences=1,
            trigger_name='dipole_3.5sigma')

        triggerSimulator.run(
            evt,
            station,
            det,
            Vrms=Vrms,
            threshold=30.85 * np.power(Vrms, 2.0),
            triggered_channels=range(4),  # run trigger on all channels
            phasing_angles=phasing_angles_4ant,
            ref_index=1.75,
            trigger_name='4ant_phasing_100Hz',  # the name of the trigger
            trigger_adc=False,  # Don't have a seperate ADC for the trigger
            adc_output='voltage',  # output in volts
            trigger_filter=None,
            upsampling_factor=2,
            window=window_4ant,
            step=step_4ant)