def _initialise_spectrometer(self, initialise=False): """ Initialise spectrometer """ # Simulation mode logging if self._simulation_mode: logging.info("Spectrometer will be initialised (initialise={})".format(initialise)) return if self._spectrometer is not None: logging.warning("Spectrometer already initialiased, skipping") return # Create spectrometer instance conf = REACHConfig()['spectrometer'] self._spectrometer = Spectrometer(ip=conf['ip'], port=conf['port'], lmc_ip=conf['lmc_ip'], lmc_port=conf['lmc_port']) bitstream = os.path.join(os.environ['REACH_CONFIG_DIRECTORY'], conf['bitstream']) if initialise: logging.info("Initialising spectrometer") self._spectrometer.program(bitstream) self._spectrometer.initialise(channel_truncation=conf['channel_truncation'], integration_time=conf['integration_time'], channel_scaling=conf['channel_scaling'], ada_gain=conf['ada_gain']) logging.info("Initialised spectrometer")
def _initialise_ucontroller(self): """ Initialise ucontroller """ # Simulation mode logging if self._simulation_mode: logging.info("Microcontroller will be initialsied") return if self._ucontroller is not None: logging.warning("uController already initialiased, skipping") return conf = REACHConfig()['ucontroller'] self._ucontroller = Microcontroller(conf['port'], conf['baudrate']) logging.info("Initialised ucontroller")
def _enable_source(self, source): """ Enable source through microcontroller :param source: Source defined in switches """ # Simulation mode logging if self._simulation_mode: logging.info("Source {} will be enabled".format(source)) return # Get switch info switch_info = REACHConfig()['sources'][source] # Toggle required switches for switch in switch_info: # TODO: Implement properly self._toggle_switch(switch, 1)
def _add_spectrum_to_file(self, spectrum, name, timestamp): """ Add spectrum to data file :param spectrum: The spectrum :param name: The data name :param timestamp: Spectrum timestsamp """ nof_frequency_channels = REACHConfig()['spectrometer']['nof_frequency_channels'] with h5py.File(self._observation_data_file, 'a') as f: # Create dataset names dataset_name = "{}_spectra".format(name) timestamp_name = "{}_timestamps".format(name) lst_name = "{}_lst_time".format(name) # Load observation data group dset = f['observation_data'] # If data sets do not exist, add them if dataset_name not in dset.keys(): dset.create_dataset(dataset_name, (0, nof_frequency_channels), maxshape=(None, nof_frequency_channels), chunks=True, dtype='u8') dset.create_dataset(timestamp_name, (0,), maxshape=(None,), chunks=True, dtype='f8') dset.create_dataset(lst_name, (0,), maxshape=(None,), chunks=True, dtype='f8') logging.info("Added {} dataset to output file".format(dataset_name)) # Add spectrum and timestamp to buffer dset = f['observation_data/{}'.format(dataset_name)] dset.resize((dset.shape[0] + 1, dset.shape[1])) dset[-1, :] = spectrum dset = f['observation_data/{}'.format(timestamp_name)] dset.resize((dset.shape[0] + 1,)) dset[-1] = timestamp dset = f['observation_data/{}'.format(lst_name)] dset.resize((dset.shape[0] + 1,)) dset[-1] = utils.get_sidereal_time(self._longitude, self._latitude, timestamp)
def add_spectrum_to_file(spectrum, timestamp, name="test"): """ Add spectrum to data file :param spectrum: The spectrum :param name: The data name :param timestamp: Spectrum timestsamp :param name: Input source name """ nof_frequency_channels = REACHConfig( )['spectrometer']['nof_frequency_channels'] with h5py.File(data_file_name, 'a') as f: # Create dataset names dataset_name = "{}_spectra".format(name) timestamp_name = "{}_timestamps".format(name) # Load observation data group dset = f['observation_data'] # If data sets do not exist, add them if dataset_name not in dset.keys(): dset.create_dataset(dataset_name, (2, 0, nof_frequency_channels), maxshape=(2, None, nof_frequency_channels), chunks=True, dtype='f8') dset.create_dataset(timestamp_name, (0, ), maxshape=(None, ), chunks=True, dtype='f8') logging.info( "Added {} dataset to output file".format(dataset_name)) # Add spectrum and timestamp to buffer dset = f['observation_data/{}'.format(dataset_name)] dset.resize((dset.shape[0], dset.shape[1] + 1, dset.shape[2])) dset[:, -1, :] = spectrum dset = f['observation_data/{}'.format(timestamp_name)] dset.resize((dset.shape[0] + 1, )) dset[-1] = timestamp
def _initialise_vna(self): """ Initialise VNA """ # Simulation mode logging if self._simulation_mode: logging.info("VNA will be initialised") return if self._vna is not None: logging.warning("VNA already initialiased, skipping") return # Create VNA instance conf = REACHConfig()['vna'] self._vna = VNA() self._vna.initialise(channel=conf['channel'], freqstart=conf['freqstart'], freqstop=conf['freqstop'], ifbw=conf['ifbw'], average=conf['average'], calib_kit=conf['calib_kit'], power_level=conf['power_level']) logging.info("Initialised VNA")
parser.add_option("--config", dest="config_file", default="reach", help="Configuration file (default: reach)") (options, args) = parser.parse_args() # Sanity check on provided config file if not options.config_file.endswith(".yaml"): options.config_file += ".yaml" # Check that REACH_CONFIG_DIRECTORY is defined in the environment if "REACH_CONFIG_DIRECTORY" not in os.environ: print("REACH_CONFIG_DIRECTORY must be defined in the environment") exit() # Check if file exists full_path = os.path.join(os.environ['REACH_CONFIG_DIRECTORY'], options.config_file) if not os.path.exists(full_path) or not os.path.isfile(full_path): print("Provided file ({}, fullpath {}) could not be found or is not a file".format(options.config_file, full_path)) exit() # Load configuration c = REACHConfig(options.config_file) # Create observation instance obs = REACHObservation(c['observation'], c['operations']) # Perform a dry run to test the observation config obs.dry_run_operations() # Run the observation # obs.run_observation()
default=-1, help= "Number of seconds between RMS measurements (default: -1 seconds, do not record)" ) parser.add_option( "--temp-cadence", dest="temp_cadence", type=int, default=-1, help= "Number of seconds between temperature measurements (default: -1 seconds, do not record)" ) (options, args) = parser.parse_args() # Initialise REACH config conf = REACHConfig()['spectrometer'] # Pointer to spectra receiver spectra = None # Initialise spectrometer if options.initialise: spectrometer = Spectrometer(ip=conf['ip'], port=conf['port'], lmc_ip=conf['lmc_ip'], lmc_port=conf['lmc_port']) bitstream = os.path.join(os.environ['REACH_CONFIG_DIRECTORY'], conf['bitstream']) logging.info("Initialising spectrometer")
return int(ret) except Exception: logging.warning('Got invalid value {} from gpio pin {}'.format( ret, pin), exc_info=True) return None else: self.set('gpio {} {}'.format(pin, val)) def gpios(self, pins, vals=None, default=0): if vals == None: ret = [] for p in pins: ret += [self.gpio(p)] return ret else: assert len(pins) == len(vals) logging.debug('Set gpio {} to {}'.format(pins, vals)) for p in pins: self.gpio(p, default) for i in range(len(pins)): self.gpio(pins[i], vals[i]) if __name__ == "__main__": from reach_ctrl.reach_config import REACHConfig conf = REACHConfig()['ucontroller'] ucontroller = Microcontroller(conf['port'], conf['baudrate'])
logging.error("VNA GUI is not running and no path provided. Cannot communicate with VNA") exit() else: # Launch GUI is a new process process = Popen([gui_path]) # Wait for GUI to load time.sleep(10) return process if __name__ == "__main__": from reach_ctrl.reach_config import REACHConfig REACHConfig() conf = REACHConfig()['vna'] vna = VNA(conf['gui_path']) logging.info("Connected VNA") vna.initialise(channel=conf['channel'], freqstart=conf['freqstart'], freqstop=conf['freqstop'], ifbw=conf['ifbw'], average=conf['average'], calib_kit=conf['calib_kit'], power_level=conf['power_level']) logging.info("Initialised VNA") vna.calib("open")