Ejemplo n.º 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
Ejemplo n.º 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)
Ejemplo n.º 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
        """
Ejemplo n.º 4
0
channelResampler = NuRadioReco.modules.channelResampler.channelResampler()
channelResampler.begin()
eventWriter = NuRadioReco.modules.io.eventWriter.eventWriter()
output_filename = "MC_example_station_{}.nur".format(station_id)
eventWriter.begin(output_filename)

# 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 set, the run number and event id will be set to an increasing value.')

args = parser.parse_args()

# initialize modules
det = detector.GenericDetector(json_filename=args.detectordescription,
                               default_station=102,
                               default_channel=0)
readCoREASShower = NuRadioReco.modules.io.coreas.readCoREASShower.readCoREASShower(
)
readCoREASShower.begin(args.inputfilename,
                       det,
                       set_ascending_run_and_event_number=args.set_run_number)
efieldToVoltageConverter = NuRadioReco.modules.efieldToVoltageConverter.efieldToVoltageConverter(
)
efieldToVoltageConverter.begin()
eventTypeIdentifier = NuRadioReco.modules.eventTypeIdentifier.eventTypeIdentifier(
)
eventWriter = NuRadioReco.modules.io.eventWriter.eventWriter()
eventWriter.begin(args.output_filename)

for event, gen_det in readCoREASShower.run():
    print('Event {} {}'.format(event.get_run_number(), event.get_id()))
    for station in event.get_stations():
        eventTypeIdentifier.run(event, station, 'forced', 'cosmic_ray')
        efieldToVoltageConverter.run(event, station, gen_det)
    eventWriter.run(event, gen_det)

nevents = eventWriter.end()
print("Finished processing, {} events".format(nevents))
Ejemplo n.º 6
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)
Ejemplo n.º 7
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)
Ejemplo n.º 8
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)