Exemple #1
0
    def testCompareDownscaleMethodWithSpecs(self):
        from matplotlib import pyplot as plt
        '''Compare downcalings with the both methods: simplified (scale by multiply) and by_the_spec (iterativelly scale accelerations).'''

        dtp = np.float64

        wltc = model._get_wltc_data()
        wclasses = wltc['classes']
        for wclass in wclasses.keys():
            for f_downscale in np.arange(0, 4, 0.1):
                class_data = wclasses[wclass]
                cycle = np.asarray(class_data['cycle'], dtype=dtp)
                phases = class_data['downscale']['phases']
                V1 = downscaleCycle(cycle, f_downscale, phases)
                V2 = downscaleCycle_bySpecs(cycle, f_downscale, phases)

                err = np.abs(V1 - V2).max()
                print('Class(%s), f_dnscl(%s): %s' %
                      (wclass, f_downscale, err))
                if (not np.allclose(V1, V2)):
                    print('Class(%s), f_dnscl(%s)' % (wclass, f_downscale))
                    plt.plot(cycle, 'r')
                    plt.plot(V1, 'b')
                    plt.plot(V2, 'g')
                    plt.show()
                    raise AssertionError('Class(%s), f_dnscl(%s)' %
                                         (wclass, f_downscale))
Exemple #2
0
def wltp_velocities(downscale_factor, class_velocities, downscale_phases,
                    times):
    """
    Returns the downscaled velocity profile [km/h].

    :param downscale_factor:
        Velocity downscale factor [-].
    :type downscale_factor: float

    :param class_velocities:
        Class velocity vector [km/h].
    :type class_velocities: numpy.array

    :param downscale_phases:
        Downscale phases [s].
    :type downscale_phases: list

    :param times:
        Time vector [s].
    :type times: numpy.array

    :return:
        Velocity vector [km/h].
    :rtype: numpy.array
    """

    if downscale_factor > 0:
        downscale_phases = np.searchsorted(times, downscale_phases)
        v = wltp_exp.downscaleCycle(class_velocities, downscale_factor,
                                    downscale_phases)
    else:
        v = class_velocities
    return v
    def testCompareDownscaleMethodWithSpecs(self):
        from matplotlib import pyplot as plt

        """Compare downcalings with the both methods: simplified (scale by multiply) and by_the_spec (iterativelly scale accelerations)."""

        dtp = np.float64

        wltc = model._get_wltc_data()
        wclasses = wltc["classes"]
        for wclass in wclasses.keys():
            for f_downscale in np.arange(0, 4, 0.1):
                class_data = wclasses[wclass]
                cycle = np.asarray(class_data["cycle"], dtype=dtp)
                phases = class_data["downscale"]["phases"]
                V1 = downscaleCycle(cycle, f_downscale, phases)
                V2 = downscaleCycle_bySpecs(cycle, f_downscale, phases)

                err = np.abs(V1 - V2).max()
                print("Class(%s), f_dnscl(%s): %s" % (wclass, f_downscale, err))
                if not np.allclose(V1, V2):
                    print("Class(%s), f_dnscl(%s)" % (wclass, f_downscale))
                    plt.plot(cycle, "r")
                    plt.plot(V1, "b")
                    plt.plot(V2, "g")
                    plt.show()
                    raise AssertionError("Class(%s), f_dnscl(%s)" % (wclass, f_downscale))
    def testFull_manually(self):
        logging.getLogger().setLevel(logging.DEBUG)

        dtp = np.float64

        mass = 1577.3106
        p_rated = 78.6340
        v_max = 186.4861
        f0 = 152.5813
        f1 = 307.5789
        f2 = 0.0486
        f_inertial = 1.1  # constant
        ## Decide WLTC-class.
        #
        wltc = model._get_wltc_data()
        wltc_class = decideClass(wltc, p_rated / mass, v_max)
        class_data = wltc["classes"][wltc_class]
        cycle = np.asarray(class_data["cycle"], dtype=dtp)

        A = np.diff(cycle)
        A = np.append(A, 0)  # Restore element lost by diff().
        A = A / 3.6
        P_REQ = calcPower_required(cycle, A, None, mass, f0, f1, f2, f_inertial)

        f_downscale_threshold = 0.01
        dsc_data = class_data["downscale"]
        phases = dsc_data["phases"]
        p_max_values = dsc_data["p_max_values"]
        downsc_coeffs = dsc_data["factor_coeffs"]
        dsc_v_split = dsc_data.get("v_max_split", None)
        f_downscale = calcDownscaleFactor(
            P_REQ, p_max_values, downsc_coeffs, dsc_v_split, p_rated, v_max, f_downscale_threshold
        )
        if f_downscale > 0:
            cycle = downscaleCycle(cycle, f_downscale, phases)
    def testCompareDownscaleMethodWithSpecs(self):
        from matplotlib import pyplot as plt
        '''Compare downcalings with the both methods: simplified (scale by multiply) and by_the_spec (iterativelly scale accelerations).'''

        dtp                     = np.float64

        wltc    = model._get_wltc_data()
        wclasses = wltc['classes']
        for wclass in wclasses.keys():
            for f_downscale in np.arange(0, 4, 0.1):
                class_data      = wclasses[wclass]
                cycle           = np.asarray(class_data['cycle'], dtype=dtp)
                phases          = class_data['downscale']['phases']
                V1              = downscaleCycle(cycle, f_downscale, phases)
                V2              = downscaleCycle_bySpecs(cycle, f_downscale, phases)

                err = np.abs(V1 - V2).max()
                print('Class(%s), f_dnscl(%s): %s'%(wclass, f_downscale, err))
                if (not np.allclose(V1, V2)):
                    print('Class(%s), f_dnscl(%s)'%(wclass, f_downscale))
                    plt.plot(cycle, 'r')
                    plt.plot(V1, 'b')
                    plt.plot(V2, 'g')
                    plt.show()
                    raise AssertionError('Class(%s), f_dnscl(%s)'%(wclass, f_downscale))
Exemple #6
0
def wltp_velocities(downscale_factor, class_times, class_velocities,
                    downscale_phases, times):
    """
    Returns the downscaled velocity profile [km/h].

    :param downscale_factor:
        Velocity downscale factor [-].
    :type downscale_factor: float

    :param class_times:
        Class time vector [s].
    :type class_times: numpy.array

    :param class_velocities:
        Class velocity vector [km/h].
    :type class_velocities: numpy.array

    :param downscale_phases:
        Downscale phases [s].
    :type downscale_phases: list

    :param times:
        Time vector [s].
    :type times: numpy.array

    :return:
        Theoretical velocity vector [km/h].
    :rtype: numpy.array
    """

    if downscale_factor > 0:
        from wltp.experiment import downscaleCycle
        downscale_phases = np.searchsorted(times, downscale_phases)
        v = downscaleCycle(class_velocities, downscale_factor,
                           downscale_phases)
    else:
        v = class_velocities

    n = int(np.ceil(times[-1] / class_times[-1]))
    t = np.cumsum(np.tile(np.ediff1d(class_times, to_begin=[0]), (n, )))
    t += class_times[0]
    return np.interp(times, t, np.tile(v, (n, )))
Exemple #7
0
    def testFull_manually(self):
        logging.getLogger().setLevel(logging.DEBUG)

        dtp = np.float64

        mass = 1577.3106
        p_rated = 78.6340
        v_max = 186.4861
        f0 = 152.5813
        f1 = 307.5789
        f2 = 0.0486
        f_inertial = 1.1  #constant
        ## Decide WLTC-class.
        #
        wltc = model._get_wltc_data()
        wltc_class = decideClass(wltc, p_rated / mass, v_max)
        class_data = wltc['classes'][wltc_class]
        cycle = np.asarray(class_data['cycle'], dtype=dtp)

        A = np.diff(cycle)
        A = np.append(A, 0)  # Restore element lost by diff().
        A = A / 3.6
        P_REQ = calcPower_required(cycle, A, None, mass, f0, f1, f2,
                                   f_inertial)

        f_downscale_threshold = 0.01
        dsc_data = class_data['downscale']
        phases = dsc_data['phases']
        p_max_values = dsc_data['p_max_values']
        downsc_coeffs = dsc_data['factor_coeffs']
        dsc_v_split = dsc_data.get('v_max_split', None)
        f_downscale = calcDownscaleFactor(P_REQ, p_max_values, downsc_coeffs,
                                          dsc_v_split, p_rated, v_max,
                                          f_downscale_threshold)
        if (f_downscale > 0):
            cycle = downscaleCycle(cycle, f_downscale, phases)