def open_detector( n_clicks, time_n_clicks, event_n_clicks, filename, detector_type, default_station, default_channel, detector_time, i_event, antenna_options ): """ Opens the detector. After the detector has been opened, it returns an output for a dummy object to trigger a redraw of all plots Parameters: ----------------- n_clicks: int Technically, the number of times the reload button was clicked, practically only used to trigger this function time_n_clicks: int Similar use as n_clicks, but for the """ if filename is None: return '' detector_provider = NuRadioReco.detector.detector_browser.detector_provider.DetectorProvider() context = dash.callback_context if context.triggered[0]['prop_id'] == 'update-detector-time-button.n_clicks': detector_provider.get_detector().update(astropy.time.Time(detector_time, format='unix')) return n_clicks if context.triggered[0]['prop_id'] == 'update-detector-event-button.n_clicks': detector_provider.set_event(i_event) return n_clicks assume_inf = antenna_options.count('assume_inf') > 0 antenna_by_depth = antenna_options.count('antenna_by_depth') > 0 if detector_type == 'detector': detector_provider.set_detector(filename, assume_inf=assume_inf, antenna_by_depth=antenna_by_depth) detector = detector_provider.get_detector() unix_times = [] datetimes = [] for station_id in detector.get_station_ids(): for dt in detector.get_unique_time_periods(station_id): if dt.unix not in unix_times: unix_times.append(dt.unix) datetimes.append(dt) detector_provider.set_time_periods(unix_times, datetimes) detector.update(np.array(datetimes)[np.argmin(unix_times)]) elif detector_type == 'generic_detector': detector_provider.set_generic_detector(filename, default_station, default_channel, assume_inf=assume_inf, antenna_by_depth=antenna_by_depth) elif detector_type == 'event_file': detector_provider.set_event_file(filename) return n_clicks
def update_channel_info_table(station_id, channel_id): """ Controls the content of the channel properties table Parameters: --------------------- station_id: int ID of the station whose properties are displayed channel_id: int ID of the channel whose properties are displayed """ detector_provider = NuRadioReco.detector.detector_browser.detector_provider.DetectorProvider() detector = detector_provider.get_detector() if station_id is None or channel_id is None: return '' if detector is None: return '' if channel_id not in detector.get_channel_ids(station_id): print('channel not in station', channel_id) return '' channel_info = detector.get_channel(station_id, channel_id) table_rows = [ html.Div( 'Station {}, Channel {}'.format(station_id, channel_id), className='custom-table-header' ) ] for key, value in channel_info.items(): table_rows.append(html.Div([ html.Div(key, className='custom-table-title'), html.Div(value, className='custom-table-cell') ], className='custom-table-row')) return table_rows
def draw_station_position_map(dummy): """ Controls the map with station positions Parameters: --------------- dummy: any Is only used to trigger a redrawing of the map. Any action that requires the map to be redrawn changes the content of the dummy element to trigger a redraw, but the dummy does not actually contain any relevant information. """ detector_provider = NuRadioReco.detector.detector_browser.detector_provider.DetectorProvider( ) detector = detector_provider.get_detector() if detector is None: return go.Figure([]) xx = [] yy = [] labels = [] for station_id in detector.get_station_ids(): try: pos = detector.get_absolute_position(station_id) xx.append(pos[0] / units.km) yy.append(pos[1] / units.km) labels.append(station_id) except: continue data = [ go.Scatter(x=xx, y=yy, ids=labels, text=labels, mode='markers+text', textposition='middle right') ] fig = go.Figure(data) fig.update_layout(xaxis=dict(title='Easting [km]'), yaxis=dict(title='Northing [km]', scaleanchor='x', scaleratio=1), margin=dict(l=10, r=10, t=30, b=10)) return fig
def set_detector_event_slider(load_detector_click, detector_type): """ Sets the value and maximum of the event select slider Parameters: ----------------- load_detector_click: dict Holds information on the click event. Practically this parameter is only used to trigger this function detector_type: string Holds the value of the detector type dropdown """ detector_provider = NuRadioReco.detector.detector_browser.detector_provider.DetectorProvider() detector = detector_provider.get_detector() if detector is None: return 0, 0 if detector_type != 'event_file': return 0, 0 return detector_provider.get_current_event_i(), detector_provider.get_n_events() - 1
def set_detector_time_slider(load_detector_click, detector_type): """ Sets the value, minimum, maximum and markings of the date selection slider Parameters: --------------------- load_detector_click: dict Contains information in the click event on the load detector button. Practically it is only used to trigger this function detector_type: string Value of the detector type dropdown """ detector_provider = NuRadioReco.detector.detector_browser.detector_provider.DetectorProvider() detector = detector_provider.get_detector() if detector is None: return None, 0, 1, {} if detector_type != 'detector': return None, 0, 1, {} unix_times, datetimes = detector_provider.get_time_periods() marks = {} for i_time, unix_time in enumerate(unix_times): datetimes[i_time].format = 'iso' marks[unix_time] = {'label': str(datetimes[i_time].value)} return detector.get_detector_time().unix, np.min(unix_times), np.max(unix_times), marks
def draw_station_view(station_id, checklist): """ Draws the 3D view of the selected station Parameters: ----------------------- station_id: int ID of the selected station checklist: array Array containing state of the station view options checkboxes """ if station_id is None: return go.Figure([]) detector_provider = NuRadioReco.detector.detector_browser.detector_provider.DetectorProvider( ) detector = detector_provider.get_detector() channel_positions = [] channel_ids = detector.get_channel_ids(station_id) antenna_types = [] antenna_orientations = [] antenna_rotations = [] data = [] for channel_id in channel_ids: channel_position = detector.get_relative_position( station_id, channel_id) channel_positions.append(channel_position) antenna_types.append(detector.get_antenna_type(station_id, channel_id)) orientation = detector.get_antenna_orientation(station_id, channel_id) ant_ori = hp.spherical_to_cartesian(orientation[0], orientation[1]) antenna_orientations.append(channel_position) antenna_orientations.append(channel_position + ant_ori) antenna_orientations.append([None, None, None]) ant_rot = hp.spherical_to_cartesian(orientation[2], orientation[3]) antenna_rotations.append(channel_position) antenna_rotations.append(channel_position + ant_rot) antenna_rotations.append([None, None, None]) if 'createLPDA' in detector.get_antenna_type( station_id, channel_id) and 'sketch' in checklist: antenna_tip = channel_position + ant_ori antenna_tine_1 = channel_position + np.cross(ant_ori, ant_rot) antenna_tine_2 = channel_position - np.cross(ant_ori, ant_rot) data.append( go.Mesh3d( x=[antenna_tip[0], antenna_tine_1[0], antenna_tine_2[0]], y=[antenna_tip[1], antenna_tine_1[1], antenna_tine_2[1]], z=[antenna_tip[2], antenna_tine_1[2], antenna_tine_2[2]], opacity=.5, color='black', delaunayaxis='x', hoverinfo='skip')) channel_positions = np.array(channel_positions) antenna_types = np.array(antenna_types) antenna_orientations = np.array(antenna_orientations) antenna_rotations = np.array(antenna_rotations) channel_ids = np.array(channel_ids) lpda_mask = (np.char.find(antenna_types, 'createLPDA') >= 0) vpol_mask = (np.char.find(antenna_types, 'bicone_v8') >= 0) | (np.char.find(antenna_types, 'greenland_vpol') >= 0) hpol_mask = (np.char.find(antenna_types, 'fourslot') >= 0) | (np.char.find( antenna_types, 'trislot') >= 0) if len(channel_positions[:, 0][lpda_mask]) > 0: data.append( go.Scatter3d(x=channel_positions[:, 0][lpda_mask], y=channel_positions[:, 1][lpda_mask], z=channel_positions[:, 2][lpda_mask], ids=channel_ids[lpda_mask], text=channel_ids[lpda_mask], mode='markers+text', name='LPDAs', textposition='middle right', marker_symbol='diamond-open', marker=dict(size=4))) if len(channel_positions[:, 0][vpol_mask]) > 0: data.append( go.Scatter3d(x=channel_positions[:, 0][vpol_mask], y=channel_positions[:, 1][vpol_mask], z=channel_positions[:, 2][vpol_mask], ids=channel_ids[vpol_mask], text=channel_ids[vpol_mask], mode='markers+text', name='V-pol', textposition='middle right', marker_symbol='x', marker=dict(size=4))) if len(channel_positions[:, 0][hpol_mask]) > 0: data.append( go.Scatter3d(x=channel_positions[:, 0][hpol_mask], y=channel_positions[:, 1][hpol_mask], z=channel_positions[:, 2][hpol_mask], ids=channel_ids[hpol_mask], text=channel_ids[hpol_mask], mode='markers+text', name='H-pol', textposition='middle right', marker_symbol='cross', marker=dict(size=4))) if len(channel_positions[:, 0][(~lpda_mask) & (~vpol_mask) & (~hpol_mask)]) > 0: data.append( go.Scatter3d( x=channel_positions[:, 0][(~lpda_mask) & (~vpol_mask) & (~hpol_mask)], y=channel_positions[:, 1][(~lpda_mask) & (~vpol_mask) & (~hpol_mask)], z=channel_positions[:, 2][(~lpda_mask) & (~vpol_mask) & (~hpol_mask)], ids=channel_ids[(~lpda_mask) & (~vpol_mask) & (~hpol_mask)], text=channel_ids[(~lpda_mask) & (~vpol_mask) & (~hpol_mask)], mode='markers+text', name='other', textposition='middle right', marker=dict(size=3))) if len(channel_positions[:, 0]) > 0: data.append( go.Scatter3d(x=antenna_orientations[:, 0], y=antenna_orientations[:, 1], z=antenna_orientations[:, 2], mode='lines', name='Orientations', marker_color='red', hoverinfo='skip')) data.append( go.Scatter3d(x=antenna_rotations[:, 0], y=antenna_rotations[:, 1], z=antenna_rotations[:, 2], mode='lines', name='Rotations', marker_color='blue', hoverinfo='skip')) fig = go.Figure(data) fig.update_layout(scene=dict(aspectmode='data'), legend_orientation='h', legend=dict(x=.0, y=1.), height=600, margin=dict(l=10, r=10, t=30, b=10)) return fig
def draw_hardware_response(response_type, zenith, azimuth, station_id, channel_id, log_checklist): """ Draws plot for antenna and amplifier response Parameters: ----------------------- response_type: array of strings Contains state of the radio buttons that allow to select if response of only amps, only antennas or amps + antennas should be drawn zenith: number Value of the slider to select the zenith angle of the incoming signal (relevant for antenna response) azimuth: number Value of the slider to select the azimuth angle of the incoming signal (relevant for antenna response) station_id: int ID of the selected station channel_id: int ID of the selected channel log_checklist: array of strings Contains state of the checklist to select logarithmic plotting of amplitude and detrending of phase """ if station_id is None or channel_id is None: return go.Figure([]), go.Figure([]) zenith *= units.deg azimuth *= units.deg if 'log' in log_checklist: y_axis_type = 'log' else: y_axis_type = 'linear' frequencies = np.arange(0, 1000, 5) * units.MHz response = np.ones((2, frequencies.shape[0]), dtype=complex) detector_provider = NuRadioReco.detector.detector_browser.detector_provider.DetectorProvider() detector = detector_provider.get_detector() if 'amp' in response_type: amp_type = detector.get_amplifier_type(station_id, channel_id) if amp_type in ['100', '200', '300']: amp_response_provider = NuRadioReco.detector.ARIANNA.analog_components.load_amplifier_response(amp_type) amp_response = amp_response_provider['gain'](frequencies) * amp_response_provider['phase'](frequencies) elif amp_type in ['rno_surface', 'iglu']: amp_response_provider = NuRadioReco.detector.RNO_G.analog_components.load_amp_response(amp_type) amp_response = amp_response_provider['gain'](frequencies) * amp_response_provider['phase'](frequencies) else: print('Warning: the specified amplifier was not found') amp_response = 1 response[0] *= amp_response response[1] *= amp_response if 'antenna' in response_type: antenna_model = detector.get_antenna_model(station_id, channel_id, zenith) antenna_pattern = antenna_pattern_provider.load_antenna_pattern(antenna_model) orientation = detector.get_antenna_orientation(station_id, channel_id) VEL = antenna_pattern.get_antenna_response_vectorized(frequencies, zenith, azimuth, *orientation) response[0] *= VEL['theta'] response[1] *= VEL['phi'] data = [ go.Scatter( x=frequencies / units.MHz, y=np.abs(response[0]), mode='lines', name='Theta component' ), go.Scatter( x=frequencies / units.MHz, y=np.abs(response[1]), mode='lines', name='Phi component' ) ] if 'detrend' in log_checklist: phase = [scipy.signal.detrend(np.unwrap(np.angle(response[0]))), scipy.signal.detrend(np.unwrap(np.angle(response[1])))] else: phase = [np.unwrap(np.angle(response[0])), np.unwrap(np.angle(response[1]))] phase_data = [ go.Scatter( x=frequencies / units.MHz, y=phase[0], mode='lines', name='Theta component' ), go.Scatter( x=frequencies / units.MHz, y=phase[1], mode='lines', name='Phi component' ) ] y_label = 'VEL [m]' else: data = [go.Scatter( x=frequencies / units.MHz, y=np.abs(response[1]), mode='lines', showlegend=False )] if 'detrend' in log_checklist: phase = scipy.signal.detrend(np.unwrap(np.angle(response[1]))) else: phase = np.unwrap(np.angle(response[1])) phase_data = [go.Scatter( x=frequencies / units.MHz, y=phase, mode='lines', showlegend=False ) ] y_label = 'gain' fig = go.Figure(data) fig.update_layout( legend_orientation='h', legend=dict(x=.0, y=1.15), yaxis_type=y_axis_type, xaxis_title='f [MHz]', yaxis_title=y_label ) phase_fig = go.Figure(phase_data) phase_fig.update_layout( legend_orientation='h', legend=dict(x=.0, y=1.15), xaxis_title='f [MHz]', yaxis_title='Phase' ) return fig, phase_fig
def show_detector_time_slider(load_detector_click, detector_type): if detector_type == 'detector': detector_provider = NuRadioReco.detector.detector_browser.detector_provider.DetectorProvider() if detector_provider.get_detector() is not None: return {'z-index': '0'} return {'display': 'none'}