Example #1
0
    def _detector_simulation(self):
        calculateAmplitudePerRaySolution.run(self._evt, self._station, self._det)
        # save the amplitudes to output hdf5 file
        # save amplitudes per ray tracing solution to hdf5 data output
        if('max_amp_ray_solution' not in self._mout):
            self._mout['max_amp_ray_solution'] = np.zeros((self._n_events, self._n_antennas, 2)) * np.nan
#        for sim_channel in self._station.get_sim_station().iter_channels():
        for sim_channel in self._station.iter_channels():
            for iCh2, sim_channel2 in enumerate(sim_channel):
                channel_id = sim_channel2.get_id()
                self._mout['max_amp_ray_solution'][self._iE, channel_id, iCh2] = sim_channel2.get_parameter(
                    chp.maximum_amplitude_envelope)
        self._increase_signal(0, 8**0.5)
        self._increase_signal(1, 8**0.5)
        self._increase_signal(2, 8**0.5)

        # start detector simulation
#        efieldToVoltageConverterPerChannel.run(self._evt, self._station, self._det)  # convolve efield with antenna pattern
        efieldToVoltageConverter.run(self._evt, self._station, self._det)  # convolve efield with antenna pattern

        if(bool(self._cfg['signal']['zerosignal'])):
            self._increase_signal(None, 0)

        if bool(self._cfg['noise']):
            Vrms = self._Vrms / self._bandwidth * 2 * units.GHz  # normalize noise level to the bandwidth its generated for
            channelGenericNoiseAdder.run(self._evt, self._station, self._det, amplitude=Vrms, min_freq=0 * units.MHz,
                            max_freq=2 * units.GHz, type='rayleigh')

        channelBandPassFilter.run(self._evt, self._station, self._det, filter_type='NTU+cheb')

        triggerSimulator.run(self._evt, self._station, self._det,
                             threshold=4.24 * self._Vrms,
                             triggered_channels=[0, 1, 2, 3, 4, 5],  # run trigger on all channels
                             number_concidences=3,
                             trigger_name='simple_threshold')  # the name of the trigger
Example #2
0
    def _detector_simulation(self):
        # start detector simulation
        efieldToVoltageConverter.run(self._evt, self._station, self._det)  # convolve efield with antenna pattern
        # downsample trace to internal simulation sampling rate (the efieldToVoltageConverter upsamples the trace to
        # 20 GHz by default to achive a good time resolution when the two signals from the two signal paths are added)
        channelResampler.run(self._evt, self._station, self._det, sampling_rate=1. / self._dt)

        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
            Vrms = self._Vrms / (norm / (max_freq)) ** 0.5  # normalize noise level to the bandwidth its generated for
            channelGenericNoiseAdder.run(self._evt, self._station, self._det, amplitude=Vrms, min_freq=0 * units.MHz,
                                         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=[80 * units.MHz, 500 * units.MHz],
                                  filter_type='butter', order=10)
        triggerSimulator.run(self._evt, self._station, self._det,
                             threshold=1 * self._Vrms,
                             triggered_channels=[0, 1, 2, 3],
                             number_concidences=1,
                             trigger_name='pre_trigger_1sigma')

        # downsample trace back to detector sampling rate
        channelResampler.run(self._evt, self._station, self._det, sampling_rate=self._sampling_rate_detector)
Example #3
0
    def _detector_simulation(self):
        # start detector simulation
        if (bool(self._cfg['signal']['zerosignal'])):
            self._increase_signal(None, 0)

        efieldToVoltageConverter.run(
            self._evt, self._station,
            self._det)  # convolve efield with antenna pattern
        # downsample trace to internal simulation sampling rate (the efieldToVoltageConverter upsamples the trace to
        # 20 GHz by default to achive a good time resolution when the two signals from the two signal paths are added)
        channelResampler.run(self._evt,
                             self._station,
                             self._det,
                             sampling_rate=1. / self._dt)

        if bool(self._cfg['noise']):
            Vrms = self._Vrms / (
                self._bandwidth / (2.5 * units.GHz)
            )**0.5  # normalize noise level to the bandwidth its generated for
            channelGenericNoiseAdder.run(self._evt,
                                         self._station,
                                         self._det,
                                         amplitude=Vrms,
                                         min_freq=0 * units.MHz,
                                         max_freq=2.5 * units.GHz,
                                         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=[80 * units.MHz, 1000 * units.GHz],
                                  filter_type='butter',
                                  order=2)
        channelBandPassFilter.run(self._evt,
                                  self._station,
                                  self._det,
                                  passband=[0, 500 * units.MHz],
                                  filter_type='butter',
                                  order=10)
        # first run a simple threshold trigger
        simpleThreshold.run(
            self._evt,
            self._station,
            self._det,
            threshold=3 * self._Vrms,
            triggered_channels=None,  # run trigger on all channels
            number_concidences=1,
            trigger_name='simple_threshold')  # the name of the trigger
        """
Example #4
0
    def _detector_simulation_trigger(self, evt, station, det):

        original_traces = {}
        for channel in station.iter_channels():
            trace = np.array(channel.get_trace())
            original_traces[channel.get_id()] = trace

        # channel 8 is a noiseless channel at 100m depth
        simpleThreshold.run(
            evt,
            station,
            det,
            threshold=3 * self._Vrms_per_channel[station.get_id()][8],
            triggered_channels=[8],  # run trigger on all channels
            number_concidences=1,
            trigger_name=f'dipole_3.0sigma')
        simpleThreshold.run(
            evt,
            station,
            det,
            threshold=2.5 * self._Vrms_per_channel[station.get_id()][8],
            triggered_channels=[8],  # run trigger on all channels
            number_concidences=1,
            trigger_name=f'dipole_2.5sigma')
        simpleThreshold.run(
            evt,
            station,
            det,
            threshold=2.0 * self._Vrms_per_channel[station.get_id()][8],
            triggered_channels=[8],  # run trigger on all channels
            number_concidences=1,
            trigger_name=f'dipole_2.0sigma')
        simpleThreshold.run(
            evt,
            station,
            det,
            threshold=1.5 * self._Vrms_per_channel[station.get_id()][8],
            triggered_channels=[8],  # run trigger on all channels
            number_concidences=1,
            trigger_name=f'dipole_1.5sigma')
        simpleThreshold.run(
            evt,
            station,
            det,
            threshold=1.0 * self._Vrms_per_channel[station.get_id()][8],
            triggered_channels=[8],  # run trigger on all channels
            number_concidences=1,
            trigger_name=f'dipole_1.0sigma')

        # Trigger windows
        Vrms = self._Vrms_per_channel[station.get_id()][4]
        resample = self._cfg[
            'sampling_rate'] * units.GHz  # Old name, just the MC clock frequency

        # x2 for upsampling
        window_4ant = int(16 * units.ns * self._sampling_rate_detector * 2.0)
        step_4ant = int(8 * units.ns * self._sampling_rate_detector * 2.0)

        # x4 for upsampling
        window_8ant = int(16 * units.ns * self._sampling_rate_detector * 4.0)
        step_8ant = int(8 * units.ns * self._sampling_rate_detector * 4.0)

        # Seperately add noise, filter it, then add filtered signal back in
        filtered_signal_traces = {}
        for channel in station.iter_channels():
            trace = np.array(channel.get_trace())
            filtered_signal_traces[channel.get_id()] = trace
            channel.set_trace(np.zeros(len(trace)), sampling_rate=resample)

        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, 235.0 * units.MHz],
                                  filter_type='cheby1',
                                  order=9,
                                  rp=.1)
        channelBandPassFilter.run(
            evt,
            station,
            det,
            passband=[87.0 * units.MHz, 225.0 * units.MHz],
            filter_type='cheby1',
            order=4,
            rp=.1)

        for channel in station.iter_channels():
            trace = copy.deepcopy(filtered_signal_traces[channel.get_id()][:])
            noise = channel.get_trace()
            channel.set_trace(trace + noise, sampling_rate=resample)

            # run the 4 phased trigger
        phasedArrayTrigger.run(
            evt,
            station,
            det,
            Vrms=Vrms,
            threshold=1.95 * np.power(Vrms, 2.0) *
            window_8ant,  # see phased trigger module for explanation
            triggered_channels=range(0, 8),
            phasing_angles=phasing_angles_8ant,
            ref_index=1.75,
            trigger_name=f'PA_8channel_100Hz',  # the name of the trigger
            trigger_adc=False,  # Don't have a seperate ADC for the trigger
            adc_output=f'voltage',  # output in volts
            trigger_filter=None,
            upsampling_factor=4,
            window=window_8ant,
            step=step_8ant)

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

        for channel in station.iter_channels():
            channel.set_trace(original_traces[channel.get_id()], resample)

        # downsample trace back to detector sampling rate
        resample = self._sampling_rate_detector
        channelResampler.run(evt, station, det, sampling_rate=resample)

        # channel 8 is a noiseless channel at 100m depth
        simpleThreshold.run(
            evt,
            station,
            det,
            threshold=3 * self._Vrms_per_channel[station.get_id()][8],
            triggered_channels=[8],  # run trigger on all channels
            number_concidences=1,
            trigger_name=f'dipole_3.0sigma_500MHz')
        simpleThreshold.run(
            evt,
            station,
            det,
            threshold=2.5 * self._Vrms_per_channel[station.get_id()][8],
            triggered_channels=[8],  # run trigger on all channels
            number_concidences=1,
            trigger_name=f'dipole_2.5sigma_500Mhz')
        simpleThreshold.run(
            evt,
            station,
            det,
            threshold=2.0 * self._Vrms_per_channel[station.get_id()][8],
            triggered_channels=[8],  # run trigger on all channels
            number_concidences=1,
            trigger_name=f'dipole_2.0sigma_500Mhz')
        simpleThreshold.run(
            evt,
            station,
            det,
            threshold=1.5 * self._Vrms_per_channel[station.get_id()][8],
            triggered_channels=[8],  # run trigger on all channels
            number_concidences=1,
            trigger_name=f'dipole_1.5sigma_500Mhz')
        simpleThreshold.run(
            evt,
            station,
            det,
            threshold=1.0 * self._Vrms_per_channel[station.get_id()][8],
            triggered_channels=[8],  # run trigger on all channels
            number_concidences=1,
            trigger_name=f'dipole_1.0sigma_500Mhz')

        filtered_signal_traces = {}
        for channel in station.iter_channels():
            trace = np.array(channel.get_trace())
            filtered_signal_traces[channel.get_id()] = trace
            channel.set_trace(np.zeros(len(trace)), sampling_rate=resample)

        channelGenericNoiseAdder.run(evt,
                                     station,
                                     det,
                                     amplitude=Vrms / Vrms_ratio,
                                     min_freq=min_freq,
                                     max_freq=max_freq,
                                     type='rayleigh')

        channelBandPassFilter.run(evt,
                                  station,
                                  det,
                                  passband=[0 * units.MHz, 235.0 * units.MHz],
                                  filter_type='cheby1',
                                  order=9,
                                  rp=.1)
        channelBandPassFilter.run(
            evt,
            station,
            det,
            passband=[87.0 * units.MHz, 225.0 * units.MHz],
            filter_type='cheby1',
            order=4,
            rp=.1)

        for channel in station.iter_channels():
            trace = copy.deepcopy(filtered_signal_traces[channel.get_id()][:])
            noise = channel.get_trace()
            channel.set_trace(trace + noise, sampling_rate=resample)

        phasedArrayTrigger.run(
            evt,
            station,
            det,
            Vrms=Vrms,
            threshold=1.95 * np.power(Vrms, 2.0) *
            window_8ant,  # see phased trigger module for explanation
            triggered_channels=range(0, 8),
            phasing_angles=phasing_angles_8ant,
            ref_index=1.75,
            trigger_name=f'PA_8channel_100Hz_500MHz',  # the name of the trigger
            trigger_adc=False,  # Don't have a seperate ADC for the trigger
            adc_output=f'voltage',  # output in volts
            trigger_filter=None,
            upsampling_factor=4,
            window=window_8ant,
            step=step_8ant)

        # run the 4 phased trigger
        phasedArrayTrigger.run(
            evt,
            station,
            det,
            Vrms=Vrms,
            threshold=1.89 * np.power(Vrms, 2.0) * window_4ant,
            triggered_channels=range(2, 6),
            phasing_angles=phasing_angles_4ant,
            ref_index=1.75,
            trigger_name=f'PA_4channel_100Hz_500MHz',  # the name of the trigger
            trigger_adc=False,  # Don't have a seperate ADC for the trigger
            adc_output=f'voltage',  # output in volts
            trigger_filter=None,
            upsampling_factor=2,
            window=window_4ant,
            step=step_4ant)
Example #5
0
# Loop over all events in file as initialized in readCoRREAS and perform analysis
for iE, evt in enumerate(readCoREAS.run(detector=det)):
    logger.info("processing event {:d} with id {:d}".format(iE, evt.get_id()))
    station = evt.get_station(station_id)
    station.set_station_time(astropy.time.Time('2019-01-01T00:00:00'))
    det.update(station.get_station_time())
    if simulationSelector.run(evt, station.get_sim_station(), det):

        efieldToVoltageConverter.run(evt, station, det)

        hardwareResponseIncorporator.run(evt, station, det, sim_to_data=True)

        channelGenericNoiseAdder.run(evt,
                                     station,
                                     det,
                                     type="rayleigh",
                                     amplitude=20 * units.mV)

        triggerSimulator.run(evt,
                             station,
                             det,
                             number_concidences=2,
                             threshold=100 * units.mV)

        if station.get_trigger('default_simple_threshold').has_triggered():

            channelBandPassFilter.run(
                evt,
                station,
                det,
Example #6
0
# Loop over all events in file as initialized in readCoRREAS and perform analysis
for iE, evt in enumerate(readCoREAS.run(detector=det)):

    logger.info("processing event {:d} with id {:d}".format(iE, evt.get_id()))
    station = evt.get_station(station_id)

    if simulationSelector.run(evt, station.get_sim_station(), det):

        eventTypeIdentifier.run(evt, station, 'forced', 'cosmic_ray')

        efieldToVoltageConverter.run(evt, station, det)

        channelGenericNoiseAdder.run(evt,
                                     station,
                                     det,
                                     min_freq=25 * units.MHz,
                                     type="rayleigh",
                                     amplitude=1 * units.mV)

        channelStopFilter.run(evt, station, det)
        channelResampler.run(evt, station, det, sampling_rate=0.8 * units.GHz)

        # voltageToAnalyticEfieldConverter expect butter filter
        channelBandPassFilter.run(evt,
                                  station,
                                  det,
                                  passband=[20 * units.MHz, 90 * units.MHz],
                                  filter_type='rectangular')
        channelBandPassFilter.run(evt,
                                  station,
                                  det,
Example #7
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)
Example #8
0
                               debug=True)

# Loop over all events in file as initialized in readCoRREAS and perform analysis
for iE, evt in enumerate(readCoREAS.run(detector=det)):
    logger.info("processing event {:d} with id {:d}".format(iE, evt.get_id()))
    station = evt.get_station(args.station_id)
    station.set_station_time(astropy.time.Time('2019-01-01T00:00:00'))
    sim_station = station.get_sim_station()
    det.update(station.get_station_time())
    if simulationSelector.run(evt, station.get_sim_station(), det):
        electricFieldResampler.run(evt, station, det, sampling_rate)
        efieldToVoltageConverter.run(evt, station, det)
        hardwareResponseIncorporator.run(evt, station, det, sim_to_data=True)
        channelGenericNoiseAdder.run(evt,
                                     station,
                                     det,
                                     type="rayleigh",
                                     amplitude=args.noise_level)
        triggerSimulator.run(evt,
                             station,
                             det,
                             number_concidences=2,
                             threshold=100 * units.mV)
        if station.get_trigger('default_simple_threshold').has_triggered():
            channelBandPassFilter.run(evt,
                                      station,
                                      det,
                                      passband=passband,
                                      filter_type='butter',
                                      order=10)
            efieldBandPassFilter.run(evt,
Example #9
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)
Example #10
0
        channelBandPassFilter.run(event_ARIANNA,
                                  station_ARIANNA,
                                  det,
                                  passband=[50 * units.MHz, 1000 * units.MHz],
                                  filter_type='rectangular')
        channelBandPassFilter.run(event_ARA,
                                  station_ARA,
                                  det,
                                  passband=[50 * units.MHz, 1000 * units.MHz],
                                  filter_type='rectangular')

        channelGenericNoiseAdder.run(event_ARA,
                                     station_ARA,
                                     det,
                                     amplitude=20 * units.mV,
                                     min_freq=50 * units.MHz,
                                     max_freq=1000 * units.MHz,
                                     type='perfect_white')
        channelGenericNoiseAdder.run(event_ARIANNA,
                                     station_ARIANNA,
                                     det,
                                     amplitude=20 * units.mV,
                                     min_freq=50 * units.MHz,
                                     max_freq=1000 * units.MHz,
                                     type='perfect_white')

        channelResampler.run(event_ARA,
                             station_ARA,
                             det,
                             sampling_rate=1 * units.GHz)
Example #11
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)
            ax[2].set_title("LPDA")
            ax[0].set_xlabel("time [ns]")
            ax[1].set_xlabel("time [ns]")
            ax[2].set_xlabel("time [ns]")
            fig.tight_layout()
            fig.suptitle(r"$\theta$ = {:.0f}, dCherenkov = {:.0f}".format(
                135, (theta - cherenkov_angle) / units.deg))
            fig.subplots_adjust(top=0.9)
            fig.savefig("plots/trace_LPDA_bicone_{:d}.png".format(counter))
            plt.show()
            plt.close("all")

        channelGenericNoiseAdder.run(event,
                                     station,
                                     det,
                                     amplitude=Vrms,
                                     min_freq=100 * units.MHz,
                                     max_freq=500 * units.MHz,
                                     type='perfect_white')
        trace_LPDA = station.get_channel(3).get_trace()
        trace_bicone = station.get_channel(2).get_trace()
        Vp2p_LPDA_noise_1[counter] = get_Vp2p(trace_LPDA)
        Vp2p_bicone_noise_1[counter] = get_Vp2p(trace_bicone)

        trace_LPDA = station.get_channel(5).get_trace()
        trace_bicone = station.get_channel(4).get_trace()
        Vp2p_LPDA_noise_2[counter] = get_Vp2p(trace_LPDA)
        Vp2p_bicone_noise_2[counter] = get_Vp2p(trace_bicone)

        hardwareResponseIncorporator.run(event, station, det, sim_to_data=True)
        trace_LPDA_amp = station.get_channel(3).get_trace()
Example #13
0
    def _detector_simulation(self):
        # start detector simulation
        if (bool(self._cfg['signal']['zerosignal'])):
            self._increase_signal(None, 0)

        efieldToVoltageConverter.run(
            self._evt, self._station,
            self._det)  # convolve efield with antenna pattern
        # downsample trace to internal simulation sampling rate (the efieldToVoltageConverter upsamples the trace to
        # 20 GHz by default to achive a good time resolution when the two signals from the two signal paths are added)
        channelResampler.run(self._evt,
                             self._station,
                             self._det,
                             sampling_rate=1. / self._dt)

        if bool(self._cfg['noise']):
            Vrms = self._Vrms / (
                self._bandwidth / (2.5 * units.GHz)
            )**0.5  # normalize noise level to the bandwidth its generated for
            channelGenericNoiseAdder.run(self._evt,
                                         self._station,
                                         self._det,
                                         amplitude=Vrms,
                                         min_freq=0 * units.MHz,
                                         max_freq=2.5 * units.GHz,
                                         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=[80 * units.MHz, 1000 * units.GHz],
                                  filter_type='butter',
                                  order=2)
        channelBandPassFilter.run(self._evt,
                                  self._station,
                                  self._det,
                                  passband=[0, 500 * units.MHz],
                                  filter_type='butter',
                                  order=10)
        # first run a simple threshold trigger
        simpleThreshold.run(
            self._evt,
            self._station,
            self._det,
            threshold=3 * self._Vrms,
            triggered_channels=None,  # run trigger on all channels
            number_concidences=1,
            trigger_name='simple_threshold')  # the name of the trigger

        # run a high/low trigger on the 4 downward pointing LPDAs
        highLowThreshold.run(
            self._evt,
            self._station,
            self._det,
            threshold_high=4 * self._Vrms,
            threshold_low=-4 * self._Vrms,
            triggered_channels=[0, 1, 2, 3],  # select the LPDA channels
            number_concidences=2,  # 2/4 majority logic
            trigger_name='LPDA_2of4_4.1sigma',
            set_not_triggered=(
                not self._station.has_triggered("simple_threshold"))
        )  # calculate more time consuming ARIANNA trigger only if station passes simple trigger

        # run a high/low trigger on the 4 surface dipoles
        highLowThreshold.run(
            self._evt,
            self._station,
            self._det,
            threshold_high=3 * self._Vrms,
            threshold_low=-3 * self._Vrms,
            triggered_channels=[4, 5, 6, 7],  # select the bicone channels
            number_concidences=4,  # 4/4 majority logic
            trigger_name='surface_dipoles_4of4_3sigma',
            set_not_triggered=(
                not self._station.has_triggered("simple_threshold"))
        )  # calculate more time consuming ARIANNA trigger only if station passes simple trigger

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