Source code for sardine.operations.operation

DISTANCE_APPROX = 1e-2


[docs] class Operation: def __init__(self, start_pos, end_pos, downtime=0, line_names=None, standby=0): ''' Initializes the Operation class ''' self._validate_downtime(downtime) self._validate_standby(standby) self._start_pos = start_pos self._end_pos = end_pos self._line_names = line_names self._downtime = downtime self._standby = standby self._name = None self._category = None @property def downtime(self): ''' Returns the downtime of the operation ''' return self._downtime @property def standby(self): ''' Returns the standby of the operation ''' return self._standby @property def line_names(self): ''' Returns the line names of the operation ''' return self._line_names @property def source_lines_shot(self): ''' Returns None ''' return None @property def receiver_lines_deployed(self): ''' Returns None ''' return None @property def receiver_lines_recovered(self): ''' Returns None ''' return None @property def duration(self): ''' Calculates the duration as the duration without downtime and standby / (1 - downtime - standby) Returns the duration ''' duration = self._duration_no_downtime() / (1 - (self._downtime + self._standby)) return duration def _duration_no_downtime(self): ''' Raises NotImpementedError ''' raise NotImplementedError @property def downtime_duration(self): ''' Calculates the duration as the duration without downtime and standby / (1 - downtime - standby) Returns the duration ''' duration = self.duration - self._duration_no_downtime() / (1 - (self._standby)) return duration @property def standby_duration(self): ''' Calculates the duration as the duration without downtime and standby / (1 - downtime - standby) Returns the duration ''' duration = self.duration - self._duration_no_downtime() / (1 - (self._downtime)) return duration @property def name(self): ''' Returns the name of the operation ''' return self._name @property def category(self): ''' Returns the category of the operation ''' return self._category @property def start_pos(self): ''' Returns the start postition of the operation ''' return self._start_pos @property def end_pos(self): ''' Returns the end postition of the operation ''' return self._end_pos
[docs] def position_at(self, time): ''' Raises NotImpementedError ''' raise NotImplementedError
[docs] def is_wait(self): ''' Returns False ''' return False
[docs] def clip(self, start_time, end_time): ''' Raises NotImpementedError ''' raise NotImplementedError(self.__class__)
@staticmethod def _validate_downtime(downtime): ''' If the downtime is less than 0 or greater than 1, raises InvalidParameter of the downtime ''' if downtime < 0 or downtime > 1: raise InvalidParameter('downtime', downtime) @staticmethod def _validate_standby(standby): ''' If the downtime is less than 0 or greater than 1, raises InvalidParameter of the downtime ''' if standby < 0 or standby > 1: raise InvalidParameter('standby', standby) def _validate_time(self, time): ''' If the time is not between 0 and the duration of the operation (with room for unprecision), raises InvalidParameter of the time ''' if not 0 <= time <= self.duration + 1e-4: raise InvalidParameter('time', time)
[docs] class InvalidParameter(Exception): def __init__(self, param_name, param_value): ''' Initializes the InvalidParameter class (Exception class) ''' self.param = param_name self.value = param_value super().__init__('{}: {}'.format(param_name, param_value))