#Add attributes for future replicability. 
                    
                    raw_freqs = prep.rfftWrapper(prep.t(), numpy.ones_like(prep.t()))[0]
                    df = raw_freqs[1] - raw_freqs[0]
                    freq_bins = (numpy.append(raw_freqs,raw_freqs[-1]+df) - df/2)/1e6 #MHz

                    freq_hz = file['cw']['freq_hz'][...][trigger_type_cut]
                    linear_magnitude = file['cw']['linear_magnitude'][...][trigger_type_cut]
                    binary_cw_cut = file['cw']['has_cw'][...][trigger_type_cut]
                    if not numpy.isin('dbish',cw_dsets):
                        dbish = 10.0*numpy.log10( linear_magnitude[binary_cw_cut]**2 / len(prep.t()))
                    else:
                        dbish = file['cw']['dbish'][...][trigger_type_cut][binary_cw_cut]
                    if plot_maps:
                        cor = Correlator(reader,  upsample=2**16, n_phi=720, n_theta=720, waveform_index_range=(None,None),crit_freq_low_pass_MHz=float(file['cw'].attrs['crit_freq_low_pass_MHz']), crit_freq_high_pass_MHz=float(file['cw'].attrs['crit_freq_high_pass_MHz']), low_pass_filter_order=float(file['cw'].attrs['low_pass_filter_order']), high_pass_filter_order=float(file['cw'].attrs['high_pass_filter_order']), plot_filter=False,apply_phase_response=True, tukey=False, sine_subtract=True)
                        cor.prep.addSineSubtract(file['cw'].attrs['sine_subtract_min_freq_GHz'], file['cw'].attrs['sine_subtract_max_freq_GHz'], file['cw'].attrs['sine_subtract_percent'], max_failed_iterations=3, verbose=False, plot=False)

                    sine_subtract_min_freq_MHz = 1000*float(file['cw'].attrs['sine_subtract_min_freq_GHz'])
                    sine_subtract_max_freq_MHz = 1000*float(file['cw'].attrs['sine_subtract_max_freq_GHz'])

                file.close()
            
            
            ds = dataSlicerSingleRun(reader, impulsivity_dset_key, time_delays_dset_key, map_direction_dset_key,\
                    curve_choice=0, trigger_types=trigger_types,included_antennas=[0,1,2,3,4,5,6,7],include_test_roi=False,\
                    cr_template_n_bins_h=200,cr_template_n_bins_v=200,\
                    impulsivity_n_bins_h=200,impulsivity_n_bins_v=200,\
                    time_delays_n_bins_h=150,time_delays_n_bins_v=150,min_time_delays_val=-200,max_time_delays_val=200,\
                    std_n_bins_h=200,std_n_bins_v=200,max_std_val=9,\
                    p2p_n_bins_h=128,p2p_n_bins_v=128,max_p2p_val=128,\
Example #2
0
    subset_cm = plt.cm.get_cmap('autumn', 10)

    origin = info.loadAntennaZeroLocation(deploy_index=deploy_index)
    latlonel_khsv = numpy.array([36.008611, -115.005556, 3316*0.3048 + 10]) #Height on google maps is ~ 3316 feet, which I convert to meters and add additional height for the tower it is on.
    enu_khsv = numpy.array(pm.geodetic2enu(latlonel_khsv[0],latlonel_khsv[1],latlonel_khsv[2],origin[0],origin[1],origin[2]))
    distance_m = numpy.linalg.norm(enu_khsv)
    zenith_deg = numpy.rad2deg(numpy.arccos(enu_khsv[2]/distance_m))
    elevation_deg = 90.0 - numpy.rad2deg(numpy.arccos(enu_khsv[2]/distance_m))
    azimuth_deg = numpy.rad2deg(numpy.arctan2(enu_khsv[1],enu_khsv[0]))

    try:
        if True:
            center_dir = 'E'
            apply_phase_response = True
            reader = Reader(datapath,run)
            cor = Correlator(reader,  upsample=2**16, n_phi=720, n_theta=720, waveform_index_range=(None,None),crit_freq_low_pass_MHz=crit_freq_low_pass_MHz, crit_freq_high_pass_MHz=crit_freq_high_pass_MHz, low_pass_filter_order=low_pass_filter_order, high_pass_filter_order=high_pass_filter_order, plot_filter=False,apply_phase_response=apply_phase_response, tukey=False, sine_subtract=True)
            # mean_corr_values, fig, ax = cor.map(eventid, 'hpol', include_baselines=numpy.array([0,1,2,3,4,5]), plot_map=True, plot_corr=False, hilbert=False, interactive=False, max_method=None, waveforms=None, verbose=True, mollweide=True, center_dir=center_dir, circle_zenith=None, circle_az=None, radius=1.0, time_delay_dict={},window_title=None,add_airplanes=False)
            ds = dataSlicerSingleRun(reader, impulsivity_dset_key, time_delays_dset_key, map_direction_dset_key,\
                                    curve_choice=0, trigger_types=trigger_types,included_antennas=[0,1,2,3,4,5,6,7],include_test_roi=False,\
                                    cr_template_n_bins_h=200,cr_template_n_bins_v=200,\
                                    impulsivity_n_bins_h=200,impulsivity_n_bins_v=200,\
                                    time_delays_n_bins_h=150,time_delays_n_bins_v=150,min_time_delays_val=-200,max_time_delays_val=200,\
                                    std_n_bins_h=200,std_n_bins_v=200,max_std_val=9,\
                                    p2p_n_bins_h=128,p2p_n_bins_v=128,max_p2p_val=128,\
                                    snr_n_bins_h=200,snr_n_bins_v=200,max_snr_val=35)
            
            #ds.addROI('A',{'std_h':[2,3],'std_v':[5.5,7]}) #Trig types 1 and 3 # 48 Mhz strong
            #ds.addROI('B',{'std_h':[1,2],'std_v':[2.6,3.2]}) #Trig types 1 and 3 # 42 Mhz with strong vpol component
            #ds.addROI('C',{'std_h':[1.8,2.4],'std_v':[2,2.5]}) #Trig types 1 and 3 # 48 Mhz with TV in hpol band
            #ds.addROI('D',{'std_h':[1.8,2.4],'std_v':[1.7,1.9]}) #Trig types 1 and 3 # 42 MHz crosspol with TV in hpol
            #ds.addROI('E',{'std_h':[0.9,1.5],'std_v':[1.05,1.3],'snr_v':[6,6.8]}) #Trig types 1 and 3 #Only Hpol TV signals with strong 53 MHz voik
Example #3
0
                    if plot_averaged == True:                    
                        plt.figure()
                        for channel in range(8):
                            print('Channel %i'%channel)
                            wfs = averaged_waveforms[channel]
                            ffts = numpy.fft.rfft(wfs)
                            freqs = numpy.fft.rfftfreq(len(times),times[1]*1e-9)/1e6
                            plt.plot(freqs,10*numpy.log10(abs(ffts)),label='Ch%i'%channel)

                        plt.xlabel('MHz')
                        plt.ylabel('dBish')
                        plt.title('Event Classification Type == %i'%event_type)
                        plt.legend()

                    if plot_maps == True:
                        cor = Correlator(reader,  upsample=final_corr_length//2, n_phi=360, n_theta=360, waveform_index_range=waveform_index_range,crit_freq_low_pass_MHz=crit_freq_low_pass_MHz, crit_freq_high_pass_MHz=crit_freq_high_pass_MHz, low_pass_filter_order=low_pass_filter_order, high_pass_filter_order=high_pass_filter_order, plot_filter=plot_filter)
                        cor.averagedMap(eventids, pol, plot_map=True, hilbert=False, max_method=None)

                    time_shifts, corrs, pairs = tdc.calculateMultipleTimeDelays(eventids,align_method=align_method,hilbert=hilbert,plot=plot_multiple,hpol_cut=None,vpol_cut=None)
                    #bins = numpy.arange(-1000,1000)#numpy.linspace(min(numpy.min(time_shifts)*.99,numpy.min(time_shifts)*1.01),numpy.max(time_shifts)*1.01,1000)
                    

                    if numpy.logical_or(plot_td,save_time_delays):

                        fit_time_delays = []

                        for pair_index, pair in enumerate(pairs):
                            if event_type == 0 and pair in vpol_pairs:
                                continue
                            fig = plt.figure(pair_index)
                            n, bins, patches = plt.hist(time_shifts[pair_index],bins = 100,label='Event_type %i, pair %i'%(event_type, pair_index))
Example #4
0
                     linestyle='--',
                     alpha=0.5)
            plt.ylabel('Array Elevation Angle (Deg)')
            plt.xlabel('Azimuth Angle (Deg)')

        for key_index, key in enumerate(list(calibrated_trigtime.keys())):
            #Prepare tools and such
            run = int(key.split('-')[0])
            eventids = known_planes[key]['eventids'][:, 1]
            reader = Reader(datapath, run)
            cor = Correlator(reader,
                             upsample=upsample,
                             n_phi=n_phi,
                             n_theta=n_theta,
                             waveform_index_range=waveform_index_range,
                             crit_freq_low_pass_MHz=crit_freq_low_pass_MHz,
                             crit_freq_high_pass_MHz=crit_freq_high_pass_MHz,
                             low_pass_filter_order=low_pass_filter_order,
                             high_pass_filter_order=high_pass_filter_order,
                             plot_filter=plot_filter,
                             apply_phase_response=apply_phase_response)
            tct = TemplateCompareTool(
                reader,
                final_corr_length=final_corr_length,
                crit_freq_low_pass_MHz=crit_freq_low_pass_MHz,
                crit_freq_high_pass_MHz=crit_freq_high_pass_MHz,
                low_pass_filter_order=low_pass_filter_order,
                high_pass_filter_order=high_pass_filter_order,
                waveform_index_range=waveform_index_range,
                plot_filters=False,
                apply_phase_response=apply_phase_response,
                        bbox_inches=0,
                        transparent=True)

        if False:
            run = 1773
            #[1774,178],[1774,381],[1774,1348],[1774,1485][178,381,1348,1485]
            center_dir = 'W'
            apply_phase_response = True
            reader = Reader(datapath, run)
            cor = Correlator(reader,
                             upsample=2**16,
                             n_phi=720,
                             n_theta=720,
                             waveform_index_range=(None, None),
                             crit_freq_low_pass_MHz=crit_freq_low_pass_MHz,
                             crit_freq_high_pass_MHz=crit_freq_high_pass_MHz,
                             low_pass_filter_order=low_pass_filter_order,
                             high_pass_filter_order=high_pass_filter_order,
                             plot_filter=False,
                             apply_phase_response=apply_phase_response,
                             tukey=False,
                             sine_subtract=True)
            for eventid in [14413]:
                mean_corr_values, fig, ax = cor.map(
                    eventid,
                    'hpol',
                    include_baselines=numpy.array([0, 1, 2, 3, 4, 5]),
                    plot_map=True,
                    plot_corr=False,
                    hilbert=False,
                    interactive=False,
Example #6
0
                        plt.minorticks_on()
                        plt.grid(b=True, which='major', color='k', linestyle='-')
                        plt.grid(b=True, which='minor', color='tab:gray', linestyle='--',alpha=0.5)

        if True:

            datapath = os.environ['BEACON_DATA']
            runs = numpy.array([1507])#numpy.arange(1645,1700)
            eventid = 18001
            for run in runs:
                run = int(run)

                reader = Reader(datapath,run)
                upsample = 2**14
                from tools.correlator import Correlator
                cor = Correlator(reader,  upsample=upsample, n_phi=180, n_theta=180, waveform_index_range=(None,None),crit_freq_low_pass_MHz=None, crit_freq_high_pass_MHz=None, low_pass_filter_order=None, high_pass_filter_order=None, plot_filter=True)
                t = cor.t()/1e9
                t = t[-1]*numpy.arange(upsample)/upsample
                goal_freqs = numpy.fft.rfftfreq(len(t),t[1]-t[0])

                loadInterpolatedPhaseResponseMeanPreamp(goal_freqs,  plot=False)
                freqs, phase_response_2nd_stage = loadInterpolatedPhaseResponse2ndStage(goal_freqs, plot=True)
                freqs, phase_response_preamp = loadInterpolatedPhaseResponseMeanPreamp(goal_freqs, plot=True)

                for channel in range(8):
                    wf = cor.wf(eventid,[channel])[0]
                    wf_fft = numpy.fft.rfft(wf)
                    wf_fft = numpy.multiply( wf_fft , numpy.exp(-1j*(phase_response_2nd_stage[channel] + phase_response_preamp)) )
                    wf_dedispered = numpy.fft.irfft(wf_fft)

                    plt.figure()
    n_theta = 720
    upsample = final_corr_length

    max_method = 0

    apply_phase_response = False
    hilbert = False
    use_interpolated_tracks = True

    reader = Reader(datapath, run)
    cor = Correlator(reader,
                     upsample=upsample,
                     n_phi=n_phi,
                     n_theta=n_theta,
                     waveform_index_range=waveform_index_range,
                     crit_freq_low_pass_MHz=crit_freq_low_pass_MHz,
                     crit_freq_high_pass_MHz=crit_freq_high_pass_MHz,
                     low_pass_filter_order=low_pass_filter_order,
                     high_pass_filter_order=high_pass_filter_order,
                     plot_filter=plot_filter,
                     apply_phase_response=apply_phase_response)

    cor.calculateArrayNormalVector(plot_map=False, mollweide=True, pol='both')
    roi_dicts = {}

    ds = dataSlicerSingleRun(reader, impulsivity_dset_key, time_delays_dset_key, map_direction_dset_key,\
                        curve_choice=0, trigger_types=[2],included_antennas=[0,1,2,3,4,5,6,7],include_test_roi=False,\
                        cr_template_n_bins_h=200,cr_template_n_bins_v=200,\
                        impulsivity_n_bins_h=200,impulsivity_n_bins_v=200,\
                        time_delays_n_bins_h=150,time_delays_n_bins_v=150,min_time_delays_val=-200,max_time_delays_val=200,\
                        std_n_bins_h=200,std_n_bins_v=200,max_std_val=9,\
    try:
        if len(runs) == 1 or sum_events == False:
            for run in runs:
                run = int(run)
                reader = Reader(datapath, run)
                if reader.failed_setup == True:
                    print('Error for run %i, skipping.' % run)
                    continue
                cor = Correlator(
                    reader,
                    upsample=2**16,
                    n_phi=720,
                    n_theta=720,
                    waveform_index_range=(None, None),
                    crit_freq_low_pass_MHz=crit_freq_low_pass_MHz,
                    crit_freq_high_pass_MHz=crit_freq_high_pass_MHz,
                    low_pass_filter_order=low_pass_filter_order,
                    high_pass_filter_order=high_pass_filter_order,
                    plot_filter=False,
                    apply_phase_response=True,
                    tukey=False,
                    sine_subtract=True)
                if sine_subtract:
                    cor.prep.addSineSubtract(sine_subtract_min_freq_GHz,
                                             sine_subtract_max_freq_GHz,
                                             sine_subtract_percent,
                                             max_failed_iterations=3,
                                             verbose=False,
                                             plot=False)
                try:
                    print(reader.status())
Example #9
0
                            'vpol_2subtract3', (file.attrs['N'], ),
                            dtype='f',
                            compression='gzip',
                            compression_opts=4,
                            shuffle=True)
                    else:
                        print(
                            'Values in vpol_2subtract3 of %s will be overwritten by this analysis script.'
                            % filename)

                    cor = Correlator(
                        reader,
                        upsample=upsample,
                        n_phi=360,
                        n_theta=360,
                        waveform_index_range=(None, None),
                        crit_freq_low_pass_MHz=crit_freq_low_pass_MHz,
                        crit_freq_high_pass_MHz=crit_freq_high_pass_MHz,
                        low_pass_filter_order=low_pass_filter_order,
                        high_pass_filter_order=high_pass_filter_order,
                        plot_filter=plot_filter)

                    for mode in ['hpol', 'vpol']:
                        print('Performing calculations for %s' % mode)
                        for event_index, eventid in enumerate(eventids):
                            if (event_index + 1) % 1000 == 0:
                                sys.stdout.write(
                                    '(%i/%i)\t\t\t\n' %
                                    (event_index + 1, len(eventids)))
                                sys.stdout.flush()
                            m = cor.map(eventid,
Example #10
0
        tdc.plotEvent(eventid,
                      channels=[0, 1, 2, 3, 4, 5, 6, 7],
                      apply_filter=False,
                      hilbert=False,
                      sine_subtract=True,
                      apply_tukey=None,
                      additional_title_text=None)

        #Create a Correlator object and produce maps for this event.

        cor = Correlator(reader,
                         upsample=final_corr_length,
                         n_phi=720,
                         n_theta=720,
                         crit_freq_low_pass_MHz=crit_freq_low_pass_MHz,
                         crit_freq_high_pass_MHz=crit_freq_high_pass_MHz,
                         low_pass_filter_order=low_pass_filter_order,
                         high_pass_filter_order=high_pass_filter_order,
                         plot_filter=False,
                         apply_phase_response=True,
                         tukey=False,
                         sine_subtract=sine_subtract)

        raw_result = cor.map(
            eventid,
            'hpol',
            center_dir='E',
            plot_map=True,
            plot_corr=False,
            hilbert=hilbert,
            interactive=True,
            max_method=0,
    n_phi = 720
    n_theta = 720

    max_method = 0
    hilbert = False

    for val in [False, True]:

        reader = Reader(datapath, run)
        cor = Correlator(reader,
                         upsample=final_corr_length,
                         n_phi=n_phi,
                         n_theta=n_theta,
                         waveform_index_range=(None, None),
                         crit_freq_low_pass_MHz=crit_freq_low_pass_MHz,
                         crit_freq_high_pass_MHz=crit_freq_high_pass_MHz,
                         low_pass_filter_order=low_pass_filter_order,
                         high_pass_filter_order=high_pass_filter_order,
                         plot_filter=plot_filters,
                         apply_phase_response=apply_phase_response,
                         tukey=False,
                         sine_subtract=True)
        prep = FFTPrepper(reader,
                          final_corr_length=final_corr_length,
                          crit_freq_low_pass_MHz=crit_freq_low_pass_MHz,
                          crit_freq_high_pass_MHz=crit_freq_high_pass_MHz,
                          low_pass_filter_order=low_pass_filter_order,
                          high_pass_filter_order=high_pass_filter_order,
                          waveform_index_range=(None, None),
                          plot_filters=plot_filters)
Example #12
0
        row_index, column_index = numpy.unravel_index(hists['vpol'].argmax(),numpy.shape(hists['vpol']))
        print('vpol az = ',az_centers[column_index])
        print('vpol zen = ',zen_centers[row_index])
        print('This accounts for %0.2f percent of all RF triggers'%(100*hists['vpol'][row_index,column_index]/numpy.sum(hists['vpol'])))


        if highlight_roi:
            all_figs = []
            all_axs = []
            all_corrs = []
            for run in numpy.unique(selected_events['run']).astype(int):
                reader = Reader(datapath,run)
                run_cut = selected_events['run'] == run
                eventids = selected_events['eventid'][run_cut]
                upsample = 2**12
                cor = Correlator(reader,  upsample=upsample, n_phi=420, n_theta=420, waveform_index_range=(None,None),crit_freq_low_pass_MHz=None, crit_freq_high_pass_MHz=None, low_pass_filter_order=None, high_pass_filter_order=None, plot_filter=False)
                for mode in ['hpol','vpol']:
                    mean_corr_values, fig, ax = cor.map(eventids[0], mode, plot_map=True, hilbert=False,interactive=True, max_method=0)
                    all_figs.append(fig)
                    all_axs.append(ax)
                #hpol, vpol = cor.averagedMap(eventids, 'both', plot_map=True, hilbert=False, max_method=0)


    except Exception as e:
        print('\nError in %s'%inspect.stack()[0][3])
        print(e)
        exc_type, exc_obj, exc_tb = sys.exc_info()
        fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
        print(exc_type, fname, exc_tb.tb_lineno)

Example #13
0
         len(prep.t()))
 else:
     dbish = file['cw']['dbish'][
         ...][trigger_type_cut][binary_cw_cut]
 if plot_maps:
     cor = Correlator(
         reader,
         upsample=2**16,
         n_phi=720,
         n_theta=720,
         waveform_index_range=(None, None),
         crit_freq_low_pass_MHz=float(
             file['cw'].attrs['crit_freq_low_pass_MHz']
         ),
         crit_freq_high_pass_MHz=float(
             file['cw'].attrs['crit_freq_high_pass_MHz']
         ),
         low_pass_filter_order=float(
             file['cw'].attrs['low_pass_filter_order']),
         high_pass_filter_order=float(
             file['cw'].attrs['high_pass_filter_order']
         ),
         plot_filter=False,
         apply_phase_response=True,
         tukey=False,
         sine_subtract=True)
     cor.prep.addSineSubtract(
         file['cw'].attrs['sine_subtract_min_freq_GHz'],
         file['cw'].attrs['sine_subtract_max_freq_GHz'],
         file['cw'].attrs['sine_subtract_percent'],
         max_failed_iterations=3,
Example #14
0
                        file['map_direction'].attrs['n_phi'] = n_phi
                        file['map_direction'].attrs['min_phi'] = min_phi
                        file['map_direction'].attrs['max_phi'] = max_phi

                        file['map_direction'].attrs['n_theta'] = n_theta
                        file['map_direction'].attrs['min_theta'] = min_theta
                        file['map_direction'].attrs['max_theta'] = max_theta

                        cor = Correlator(
                            reader,
                            upsample=upsample,
                            n_phi=n_phi,
                            range_phi_deg=(min_phi, max_phi),
                            n_theta=n_theta,
                            range_theta_deg=(min_theta, max_theta),
                            waveform_index_range=(None, None),
                            crit_freq_low_pass_MHz=crit_freq_low_pass_MHz,
                            crit_freq_high_pass_MHz=crit_freq_high_pass_MHz,
                            low_pass_filter_order=low_pass_filter_order,
                            high_pass_filter_order=high_pass_filter_order,
                            plot_filter=plot_filter,
                            sine_subtract=sine_subtract,
                            deploy_index=deploy_index)

                        print('Cor setup to use deploy index %s' %
                              str(cor.deploy_index))

                        if sine_subtract:
                            cor.prep.addSineSubtract(
                                sine_subtract_min_freq_GHz,
                                sine_subtract_max_freq_GHz,