def test_spectrum_streamer(): hyp_inst = hyperion.Hyperion(instrument_ip) loop = asyncio.get_event_loop() queue = asyncio.Queue(maxsize=5, loop=loop) stream_active = True serial_numbers = [] spectrum_streamer = hyperion.HCommTCPSpectrumStreamer( instrument_ip, loop, queue, hyp_inst.power_cal) async def get_data(): while True: spectrum_data = await queue.get() queue.task_done() if spectrum_data['data']: serial_numbers.append( spectrum_data['data'].header.serial_number) else: break loop.create_task(get_data()) streaming_time = 5 # seconds loop.call_later(streaming_time, spectrum_streamer.stop_streaming) loop.run_until_complete(spectrum_streamer.stream_data())
def canales_activos(): h1 = hyperion.Hyperion('10.0.0.55') canales =[] for canal in range(1,5): try: peaks = h1.peaks[canal] print(f"picos canal {canal}:{peaks}") if len(peaks)>0: self.canales.append(canal) self.numero_sensores[canal]=len(peaks) except: print(f"canal {canal} sin sensores") return canales
def test_sensor_streamer(test_sensors): hyp_inst = hyperion.Hyperion(instrument_ip) hyp_inst.remove_sensors() for sensor in test_sensors: hyp_inst.add_sensor(*sensor) sensors = hyp_inst.get_sensor_names() logger.debug('Sensors added: {0}'.format(sensors)) loop = asyncio.get_event_loop() queue = asyncio.Queue(maxsize=5, loop=loop) stream_active = True serial_numbers = [] timestamps = [] sensor_streamer = hyperion.HCommTCPSensorStreamer(instrument_ip, loop, queue) async def get_data(): while True: sensor_data = await queue.get() queue.task_done() if sensor_data['data']: serial_numbers.append(sensor_data['data'].header.serial_number) else: break loop.create_task(get_data()) streaming_time = 5 # seconds loop.call_later(streaming_time, sensor_streamer.stop_streaming) loop.run_until_complete(sensor_streamer.stream_data()) hyp_inst.remove_sensors() assert (np.diff(np.array(serial_numbers)) == 1).all()
def test_sensors_api(): test_sensors = [ ['sensor_1', 'os7510', 1, 1510.0, 66.0], ['sensor_2', 'os7510', 1, 1530.0, 66.0], ['sensor_3', 'os7510', 2, 1550.0, 66.0], ['sensor_4', 'os7510', 2, 1570.0, 66.0] ] hyp_inst = hyperion.Hyperion(instrument_ip) hyp_inst.remove_sensors() for sensor in test_sensors: hyp_inst.add_sensor(*sensor) sensor_names = hyp_inst.get_sensor_names() test_sensor_names = [sensor_config[0] for sensor_config in test_sensors] assert sensor_names == test_sensor_names hyp_inst.save_sensors() hyp_inst.remove_sensors() #checking for problem with re-adding sensors for sensor in test_sensors: hyp_inst.add_sensor(*sensor) sensors = hyp_inst.export_sensors() for sensor, test_sensor in zip(sensors, test_sensors): assert [sensor['name'], sensor['model'], sensor['channel'], sensor['wavelength'], sensor['calibration_factor']] == test_sensor hyp_inst.remove_sensors()
def test_detection_settings_api(): hyp_inst = hyperion.Hyperion(instrument_ip) detection_setting = hyp_inst.get_detection_setting(128) detection_setting.setting_id = 1 hyp_inst.add_or_update_detection_setting(detection_setting) detection_setting.name = 'Test update detection setting' hyp_inst.add_or_update_detection_setting(detection_setting) new_setting = hyp_inst.get_detection_setting(detection_setting.setting_id) assert new_setting.name == detection_setting.name hyp_inst.remove_detection_setting(detection_setting.setting_id) with pytest.raises(hyperion.HyperionError): hyp_inst.get_detection_setting(detection_setting.setting_id)
def connect_config(self, new_static_address='10.0.41.3', netmask='255.255.0.0', gateway='10.0.0.1'): ''' network setting config ''' try: current_ip_mode = self.h.network_ip_mode current_static_settings = self.h.static_network_settings print("Current IP mode: " + current_ip_mode) print("Old Static settings: " + repr(current_static_settings) ) # repr makes it readable to interpretor # Set the desired static settings here # Only run the following if you are certain you can connect to the instrument on the new static address self.h.static_network_settings = hyperion.NetworkSettings( new_static_address, netmask, gateway) if current_ip_mode == 'DHCP': self.h.network_ip_mode = 'STATIC' sleep(5) self.h = hyperion.Hyperion(new_static_address) print( f"\033[1;31;45m Connected with new network settings: {self.h.active_network_settings}\033[0m" ) except: # Error handler print("\033[1;32;42m[WARN] Hyperion connection failed!\033[0m") sys.exit()
"""This example will plot a spectrum and the corresponding peaks. This requires numpy, scilab, and matplotlib packages. """ import matplotlib matplotlib.use('tkagg') import numpy as np import matplotlib.pyplot as plt from scipy.interpolate import interp1d import sys import hyperion channel = 1 h1 = hyperion.Hyperion('10.0.10.71') peaks = h1.peaks[channel] spectra = h1.spectra spectrum = spectra[channel] wavelengths = spectra.wavelengths #We will interpolate the peak data so that the indicators appear on the #plot in line with the spectrum. interpSpectrum = interp1d(wavelengths, spectrum) plt.plot(wavelengths, spectrum ,peaks,interpSpectrum(peaks),'o')
def test_hyperion_properties(): hyp_inst = hyperion.Hyperion(instrument_ip) serial_number = hyp_inst.serial_number assert len(serial_number) == 6 library_version = hyp_inst.library_version firmware_version = hyp_inst.firmware_version fpga_version = hyp_inst.fpga_version original_name = hyp_inst.instrument_name test_name = 'testname' hyp_inst.instrument_name = test_name assert hyp_inst.instrument_name == test_name hyp_inst.instrument_name = original_name.replace(' ', '_'); assert hyp_inst.instrument_name == original_name assert hyp_inst.is_ready assert hyp_inst.channel_count in [1,4,8,16] max_peak_counts = hyp_inst.max_peak_count_per_channel peak_detection_settings = hyp_inst.available_detection_settings assert peak_detection_settings[128].name == '0.25 nm Peak' channel_detection_settings = hyp_inst.channel_detection_setting_ids active_channels = hyp_inst.active_full_spectrum_channel_numbers test_active_channels = range(1, hyp_inst.channel_count + 1) hyp_inst.active_full_spectrum_channel_numbers = test_active_channels assert (hyp_inst.active_full_spectrum_channel_numbers == test_active_channels).all() hyp_inst.active_full_spectrum_channel_numbers = [1] assert (hyp_inst.active_full_spectrum_channel_numbers == [1]).all() hyp_inst.active_full_spectrum_channel_numbers = active_channels available_laser_scan_speeds = hyp_inst.available_laser_scan_speeds current_speed = hyp_inst.laser_scan_speed hyp_inst.laser_scan_speed = available_laser_scan_speeds[0] assert hyp_inst.laser_scan_speed == available_laser_scan_speeds[0] hyp_inst.laser_scan_speed = available_laser_scan_speeds[-1] assert hyp_inst.laser_scan_speed == available_laser_scan_speeds[-1] hyp_inst.laser_scan_speed = current_speed active_net_settings = hyp_inst.active_network_settings static_net_settings = hyp_inst.static_network_settings ip_mode = hyp_inst.network_ip_mode if ip_mode == 'STATIC': assert active_net_settings == static_net_settings test_static_net_settings = hyperion.NetworkSettings('10.0.53.53','255.255.0.0','10.0.0.1') hyp_inst.static_network_settings = test_static_net_settings sleep(2) hyp_inst.network_ip_mode = 'static' sleep(2) assert hyp_inst.static_network_settings == test_static_net_settings hyp_inst.static_network_settings = static_net_settings sleep(2) hyp_inst.instrument_utc_date_time = hyp_inst.instrument_utc_date_time hyp_inst.ntp_enabled = not hyp_inst.ntp_enabled hyp_inst.ntp_enabled = not hyp_inst.ntp_enabled hyp_inst.ntp_server = hyp_inst.ntp_server peaks = hyp_inst.peaks channel_peaks = hyp_inst.peaks[1] spectra = hyp_inst.spectra channel_spectra = hyp_inst.spectra[active_channels[0]] assert channel_spectra.size == spectra.spectra_header['num_points']
def __init__(self, current_address='10.0.10.71', ref_wavelen=1550): self.current_address = current_address self.ref_wavelen = ref_wavelen self.h = hyperion.Hyperion(current_address)
#! /usr/bin/env python # #sensor_streaming.py # #Copyright (c) 2018 by Micron Optics, Inc. All Rights Reserved # import hyperion import asyncio import numpy as np instrument_ip = '10.0.10.42' hyp_inst = hyperion.Hyperion(instrument_ip) hyp_inst.remove_sensors() test_sensors = [ # edit this to define your own sensors # Name Model chan. wl cal ['sensor_1', 'os7520', 1, 1590.0, 2300.0], ['sensor_2', 'os7520', 1, 1610.0, 2300.0], ['sensor_3', 'os7510', 2, 1550.0, 66.0], ['sensor_4', 'os7510', 2, 1570.0, 66.0] ] for sensor in test_sensors: hyp_inst.add_sensor(*sensor) sensors = hyp_inst.get_sensor_names() loop = asyncio.get_event_loop()
"""This file illustrates how to configure the network settings """ from time import sleep import sys import hyperion """This example will change the static IP address, and attempt to connect to the new address. If the instrument was originally in DHCP mode, it will be returned to that mode upon completion. """ current_address = '10.0.10.71' new_static_address = '10.0.41.3' netmask = '255.255.0.0' gateway = '10.0.0.1' h1 = hyperion.Hyperion(current_address) current_ip_mode = h1.network_ip_mode current_static_settings = h1.static_network_settings print("Current IP mode: " + current_ip_mode) print("Old Static settings: " + repr(current_static_settings)) #Set the desired static settings here # Only run the following if you are certain you can connect to the instrument on the new static address h1.static_network_settings = hyperion.NetworkSettings(new_static_address, netmask, gateway) if current_ip_mode == 'DHCP':
import hyperion import numpy as np # instrumant ip # ip = '217.74.248.42' ip = '10.0.0.50' # Index of Refraction n = 1.4682 h1 = hyperion.Hyperion(ip) wl_start = 1566 wl_finish = 1626 wls = list() distances = list() shifts = list() for wl in range(wl_start, wl_finish, 2): wls.append(wl) for distance in [50000]: num_of_attempts = 10 cur_shifts = list() for _ in range(num_of_attempts): time_of_flight = int(2 * distance / 299792458 * n * 1e+9) wl_shifted = h1.shift_wavelength_by_offset(wl, time_of_flight) shift = (wl_shifted - wl) cur_shifts.append(shift) shift = np.mean(cur_shifts) shift_std = np.std(cur_shifts)
#Copyright (c) 2018 by Micron Optics, Inc. All Rights Reserved # """This example will plot a spectrum and the corresponding peaks. This requires numpy, and matplotlib packages. """ import matplotlib matplotlib.use('tkagg') import numpy as np import matplotlib.pyplot as plt from scipy.interpolate import interp1d import sys import hyperion h1 = hyperion.Hyperion('10.0.10.87') #Get the spectrum h1.active_full_spectrum_channel_numbers = range(1, h1.channel_count + 1) fig = plt.figure() ax = plt.subplot(111) spectra = h1.spectra wavelengths = spectra.wavelengths for channel in h1.active_full_spectrum_channel_numbers: ax.plot(wavelengths, spectra[channel], label=str(channel)) ax.legend() ax.set_xlabel('Wavelength (nm)')