Exemplo n.º 1
0
    def Delay(self, delayProf):
        """
        Compute the delayed profile composed of *self* profile and *delayProf*,
        received by a node for which this *self* profile is the output profile on the sender side.
        The delay profile describes the delay as a function of time for the link.

        This function implements the operation: 

        .. math::
            o[t + \delta[t]] = l[t]

        Where

        * :math:`\delta[t]` is the delay profile
        * :math:`l[t]` is the profile transmitted into the link (*self*)
        * :math:`o[t]` is the output profile received at the other end of the link

        :rtype: :class:`Profile`, :math:`o[t]`

        :param in delayProf: :class:`Profile` describing the delay
        """
        delays = delayProf.entries['latency']
        all0 = True
        for time, delay in delays:
            if delay != 0:
                all0 = False
        if all0: return copy.deepcopy(self)
        datas = self.entries['data']
        endTime = datas[-1][0]
        times = [ x[0] for x in delays ]
        times.extend( [ x[0] for x in datas ] )
        times = sorted(list(set(times)))
        newDatas = []
        for t in times:
            d = utils.get_value_at_time(datas, t)
            delay = utils.get_value_at_time(delays, t, interpolate = 'latency' in self.interpolated_profiles)
            newDatas.append([ t + delay, d ])
        newDatas = utils.remove_degenerates(newDatas)
        newDatas, remainder = utils.split(newDatas, endTime)
        if remainder:
            t = -remainder[0][0]
            utils.shift(remainder, t)
            r_slopes = utils.derive(remainder)
            d_slopes = utils.derive(newDatas)
            d_slopes = utils.add_values(d_slopes,r_slopes)
            newDatas = utils.integrate(d_slopes, endTime)

        retProf = Profile()
        retProf.entries['data'] = newDatas
        retProf.Derive()
        return retProf
Exemplo n.º 2
0
    def AddProfile(self,profile):
        """
        Compose this profile with an input profile by adding their slopes together.

        :rtype: :class:`Profile`
        """
        new_slopes = utils.add_values(
            self.entries['slope'],
            profile.entries['slope'],
            interpolate = 'slope' in self.interpolated_profiles
        )
        retProf = copy.deepcopy(self)
        retProf.entries['slope'] = new_slopes
        return retProf