def check_imminent_injection(hwinj_list, imminent_wait_time): """ Find the most imminent hardware injection, this is the injection in the future that is soonest to the current GPS time. The injection must be within imminent_wait_time for it to be considered imminent. Parameters ---------- hwinj_list: list A list of HardwareInjection instances. imminent_wait_time: float Seconds to check from current time to determine if a hardware injection is imminent. Retuns ---------- imminent_hwinj: HardwareInjection A HardwareInjection instance is return if there is an imminent injection found. """ # get the current GPS time current_gps_time = gpstime.utcnow().gps() # find the injection in the future and soonest to the present if len(hwinj_list): imminent_hwinj = min(hwinj_list, key=lambda hwinj: hwinj.schedule_time-current_gps_time \ if hwinj.schedule_time-current_gps_time > 0 else float("inf")) if imminent_hwinj.schedule_time-current_gps_time < imminent_wait_time \ and imminent_hwinj.schedule_time-current_gps_time > 0: return imminent_hwinj return None
def get_last_injection(hwinj_list): """ Find the most recent hardware injection, this is the injection that is in the past and closest to the current GPS time. The injection must be within look_back_seconds for it to be returned. Parameters ---------- hwinj_list: list A list of HardwareInjection instances. Retuns ---------- recent_hwinj: HardwareInjection A HardwareInjection instance is return if there is a recent injection found. """ # get the current GPS time current_gps_time = gpstime.utcnow().gps() # find the injection in the past and most recent if len(hwinj_list): recent_hwinj = min(hwinj_list, key=lambda hwinj: abs(hwinj.schedule_time-current_gps_time) \ if hwinj.schedule_time-current_gps_time < 0 else float("inf")) if recent_hwinj.schedule_time - current_gps_time < 0: return recent_hwinj return None
def check_exttrig_alert(exttrig_channel_name, exttrig_wait_time): """ Check if there is an external trigger alert. Parameters ---------- exttrig_channel_name: str Name of the EPICs record channel to check for most recent alert time. exttrig_wait_time: float Amount of time to wait for an external alert. Retuns ---------- exttrig_alert_time: float If external alert within wait period then return the GPS time of the alert. """ # get the current GPS time current_gps_time = gpstime.utcnow().gps() # read EPICs record for most recent external trigger alert GPS time exttrig_alert_time = ezca.read(exttrig_channel_name) # if alert is within wait period then return the GPS time if abs(current_gps_time - exttrig_alert_time) < exttrig_wait_time: return exttrig_alert_time else: return None
def main(self): """ Execute method once. """ # set legacy TINJ_OUTCOME value for failed injection ezca[outcome_channel_name] = -4 # legacy of the old setup to set TINJ_END_TIME current_gps_time = gpstime.utcnow().gps() ezca[end_channel_name] = current_gps_time return False
def main(self): """ Execute method once. """ # set legacy TINJ_OUTCOME value for successful injection ezca[outcome_channel_name] = 1 # legacy of the old setup to set TINJ_END_TIME current_gps_time = gpstime.utcnow().gps() ezca[end_channel_name] = current_gps_time return "WAIT_FOR_NEXT_INJECT"
def run(self): """ Execute method in a loop. """ # notify operator notify("INJECTION IMMINENT: %f" % self.hwinj.schedule_time) # check if its time to jump to the corresponding _INJECT_STATE_ACTIVE subclass current_gps_time = gpstime.utcnow().gps() if current_gps_time > self.hwinj.schedule_time - jump_to_inj_seconds: return self.hwinj.schedule_state elif current_gps_time > self.hwinj.schedule_time: return "FAILURE_INJECT_IN_PAST" return False
def run(self): """ Execute method in a loop. """ # notify operator notify("INJECTION IMMINENT: %f"%self.hwinj.schedule_time) # check if its time to jump to the corresponding _INJECT_STATE_ACTIVE subclass current_gps_time = gpstime.utcnow().gps() if current_gps_time > self.hwinj.schedule_time - jump_to_inj_seconds: return self.hwinj.schedule_state elif current_gps_time > self.hwinj.schedule_time: return "FAILURE_INJECT_IN_PAST" return False
def run(self): """ Execute method in a loop. """ # get hardware injection in the future that is soonest self.hwinj = injtools.check_imminent_injection(hwinj_list, imminent_seconds) # if there is no imminent hardware injection then recheck injections if not self.hwinj: return False # in dev mode ignore if detector is locked # otherwise check if detector is locked if ezca[lock_channel_name] == 1 or dev_mode: # check if detector in desired observing mode and # then make a jump transition to CREATE_GRACEDB_EVENT state latch = ezca[obs_channel_name] & obs_bitmask if ( latch == 1 and self.hwinj.observation_mode == 1 ) or \ ( latch == 0 and self.hwinj.observation_mode == 0 ): # legacy of the old setup to set TINJ_START_TIME current_gps_time = gpstime.utcnow().gps() ezca[start_channel_name] = current_gps_time # set legacy TINJ_OUTCOME value for pending injection ezca[outcome_channel_name] = 0 return True # set legacy TINJ_OUTCOME value for detector not in desired # observation mode else: log("Ignoring hardware injection since detector is not in " \ + "the desired observation mode.") ezca[outcome_channel_name] = -5 # set legacy TINJ_OUTCOME value for detector not locked else: log("Ignoring hardware injection since detector is not locked.") ezca[outcome_channel_name] = -6 return False
def read_schedule(schedule_path): """ Parses schedule file. Schedule file should be a space-delimited file with the following ordered columns: GPS start time, INJECT state, observing mode, scale factor, path to the waveform file, and path to a meta-data file. The INJECT state should be one of the INJECT_*_ACTIVE guardian states that is a subclass of the _INJECT_STATE_ACTIVE state. The observing mode column should be 1 or 0. If there is a 1 the injection will be performed in observation mode and if there is a 0 the injection will be performed in commissioning mode. The scale factor should be a float. This is the overall factor a time series will be multiplied by before it is injected. The path to the waveform file is required and the filename should have the following format: IFO-TAG-GPS_START_TIME-DURATION.EXT Since each detector may have different time series to inject, we allow the user to use the {ifo} substring in the waveform_path column. So that the substring {ifo} is replaced with the IFO, eg. H1 or L1. If there is no meta-data file, then write None. Parameters ---------- schedule_path: str Path to the schedule file. Returns ---------- inj_list: list A list where each element is an HardwareInjection instance. """ # initialize empty list to store HardwareInjection hwinj_list = [] # get the current GPS time current_gps_time = gpstime.utcnow().gps() # read lines of schedule file fp = open(schedule_path, "rb") lines = fp.readlines() fp.close() # loop over lines in schedule file for line in lines: # get line in schedule as a list of strings # assumes its a space-delimited line data = line.split() # parse line elements into variables i = 0 schedule_time = float(data[i]) i += 1 schedule_state = data[i] i += 1 observation_mode = int(data[i]) i += 1 scale_factor = float(data[i]) i += 1 waveform_path = data[i] i += 1 metadata_path = data[i] i += 1 # add a new HardwareInjection to list if its in the future if schedule_time - current_gps_time > 0: hwinj = HardwareInjection(schedule_time, schedule_state, observation_mode, scale_factor, waveform_path, metadata_path) hwinj_list.append(hwinj) return hwinj_list
def read_schedule(schedule_path): """ Parses schedule file. Schedule file should be a space-delimited file with the following ordered columns: GPS start time, INJECT state, observing mode, scale factor, path to the waveform file, and path to a meta-data file. The INJECT state should be one of the INJECT_*_ACTIVE guardian states that is a subclass of the _INJECT_STATE_ACTIVE state. The observing mode column should be 1 or 0. If there is a 1 the injection will be performed in observation mode and if there is a 0 the injection will be performed in commissioning mode. The scale factor should be a float. This is the overall factor a time series will be multiplied by before it is injected. The path to the waveform file is required and the filename should have the following format: IFO-TAG-GPS_START_TIME-DURATION.EXT Since each detector may have different time series to inject, we allow the user to use the {ifo} substring in the waveform_path column. So that the substring {ifo} is replaced with the IFO, eg. H1 or L1. If there is no meta-data file, then write None. Parameters ---------- schedule_path: str Path to the schedule file. Returns ---------- inj_list: list A list where each element is an HardwareInjection instance. """ # initialize empty list to store HardwareInjection hwinj_list = [] # get the current GPS time current_gps_time = gpstime.utcnow().gps() # read lines of schedule file fp = open(schedule_path, "rb") lines = fp.readlines() fp.close() # loop over lines in schedule file for line in lines: # get line in schedule as a list of strings # assumes its a space-delimited line data = line.split() # parse line elements into variables i = 0 schedule_time = float(data[i]); i += 1 schedule_state = data[i]; i += 1 observation_mode = int(data[i]); i+= 1 scale_factor = float(data[i]); i += 1 waveform_path = data[i]; i += 1 metadata_path = data[i]; i += 1 # add a new HardwareInjection to list if its in the future if schedule_time - current_gps_time > 0: hwinj = HardwareInjection(schedule_time, schedule_state, observation_mode, scale_factor, waveform_path, metadata_path) hwinj_list.append(hwinj) return hwinj_list