Пример #1
0
    def test_mixed(self):

        t = np.arange(15, dtype="<f8")

        s1 = Signal(
            np.frombuffer(b"\x00\x00\x00\x02" * 15, dtype=">u4"), t, name="Motorola"
        )

        s2 = Signal(
            np.frombuffer(b"\x04\x00\x00\x00" * 15, dtype="<u4"), t, name="Intel"
        )

        for version in ("3.30", "4.10"):
            mdf = MDF(version=version)
            mdf.append([s1, s2], common_timebase=True)
            outfile = mdf.save(
                Path(TestEndianess.tempdir.name) / f"out", overwrite=True
            )
            mdf.close()

            with MDF(outfile) as mdf:
                self.assertTrue(np.array_equal(mdf.get("Motorola").samples, [2] * 15))
                self.assertTrue(np.array_equal(mdf.get("Intel").samples, [4] * 15))

        for version in ("3.30", "4.10"):
            mdf = MDF(version=version)
            mdf.append([s2, s1], common_timebase=True)
            outfile = mdf.save(
                Path(TestEndianess.tempdir.name) / f"out", overwrite=True
            )
            mdf.close()

            with MDF(outfile) as mdf:
                self.assertTrue(np.array_equal(mdf.get("Motorola").samples, [2] * 15))
                self.assertTrue(np.array_equal(mdf.get("Intel").samples, [4] * 15))
Пример #2
0
    def test_mixed(self):

        t = np.arange(15, dtype='<f8')

        s1 = Signal(
            np.frombuffer(b'\x00\x00\x00\x02' * 15, dtype='>u4'),
            t,
            name='Motorola'
        )

        s2 = Signal(
            np.frombuffer(b'\x04\x00\x00\x00' * 15, dtype='<u4'),
            t,
            name='Intel'
        )

        for version in ('3.30', '4.10'):
            mdf = MDF(version=version)
            mdf.append([s1, s2], common_timebase=True)
            outfile = mdf.save(
                Path(TestEndianess.tempdir.name) / f"out",
                overwrite=True,
            )
            mdf.close()

            with MDF(outfile) as mdf:
                self.assertTrue(
                    np.array_equal(
                        mdf.get('Motorola').samples, [2,] * 15
                    )
                )
                self.assertTrue(
                    np.array_equal(
                        mdf.get('Intel').samples, [4,] * 15
                    )
                )

        for version in ('3.30', '4.10'):
            mdf = MDF(version=version)
            mdf.append([s2, s1], common_timebase=True)
            outfile = mdf.save(
                Path(TestEndianess.tempdir.name) / f"out",
                overwrite=True,
            )
            mdf.close()

            with MDF(outfile) as mdf:
                self.assertTrue(
                    np.array_equal(
                        mdf.get('Motorola').samples, [2,] * 15
                    )
                )
                self.assertTrue(
                    np.array_equal(
                        mdf.get('Intel').samples, [4,] * 15
                    )
                )
Пример #3
0
    def test_attachment_blocks_wo_filename(self):
        original_data = b"Testing attachemnt block\nTest line 1"
        mdf = MDF()
        mdf.attach(
            original_data,
            file_name=None,
            comment=None,
            compression=True,
            mime=r"text/plain",
            embedded=True,
        )
        outfile = mdf.save(
            Path(TestMDF4.tempdir.name) / "attachment.mf4", overwrite=True,
        )

        with MDF(outfile) as attachment_mdf:
            data, filename, md5_sum = attachment_mdf.extract_attachment(index=0)
            self.assertEqual(data, original_data)
            self.assertEqual(filename, Path("bin.bin"))

        mdf.close()
Пример #4
0
#               keep_arrays=False,
            use_display_names=True,
            time_as_date=True,
            reduce_memory_usage=True,
            raw=False,
            ignore_value2text_conversions=False)
    #remove \CCP from column names of dataframe
    df.columns = [col.split('\\')[0] for col in df.columns]
    #resampling the data to 1 second
    df = df.resample('S').mean()
    
    n_i = list(range(1,len(df['egr_b_operate_valve'])+1))
    df['Sl.no'] = n_i
    df.set_index('Sl.no',inplace=True)

    mdf.close()
    

#%%
def exh_pressure_sampling():
    
    RPM = [3400,3200,3000,2800,2600,2400,2200,2000,1800,1600,1400,1200]
    mean_pres = []
    for i in RPM:
        df_i = df[(df['cps_n_engine'] > i-50) & (df['cps_n_engine'] < i+50)]
        a = df_i['egr_P_exhaustp'].mean()
        mean_pres.append(a)
    pres_dict = {'Engine Speed':RPM,'Mean Pressure':mean_pres}
    df_mean_pres = pd.DataFrame(pres_dict)
    df_mean_pres.set_index(df_mean_pres['Engine Speed'])
    df_mean_pres.plot(x='Engine Speed',y='Mean Pressure',xticks= RPM,kind = 'line',grid=True)
Пример #5
0
class openMDF:
    def __init__(self, path, roadtype=0):
        self.filename = path.split('/')[-1].split('.')[0]
        self.roadType = roadtype
        if self.filename not in loser_file_data:
            self.open_file(path)
            self.task_1()
    def open_file(self, path):
        print('开启mf4文件')
        self.mf = MDF(path)
    def close_file(self):
        print('关闭mf4文件')
        self.mf.close()

    # 统计转向灯开启时间
    def task_1(self):
        signal_left = '_g_PL_AD_fw_PL_AD_FCT_RunnableSppHmi_RunnableSppHmi_m_sppHmiInput_out_local.TChangeableMemPool._._._m_arrayPool._0_._elem._m_dirIndL'
        signal_right = '_g_PL_AD_fw_PL_AD_FCT_RunnableSppHmi_RunnableSppHmi_m_sppHmiInput_out_local.TChangeableMemPool._._._m_arrayPool._0_._elem._m_dirIndR'
        signal_speed = '_g_PL_AD_fw_PL_AD_FCT_RunnableFsm_RunnableFsm._m_fsmController._m_fip._m_displayedSpeedCalculator._m_displaySpeed._m_value'
        # 轮端转角
        signal_RoadWheelAngle = '_g_PL_AD_fw_VMC_VMC_FW_MvpVse_VseSes_VseSes_m_portVehicleStateEstimation_local.TChangeableMemPool._._._m_arrayPool._0_._elem._m_estimation_RoadWheelAngle_Front._m_value'
        # 左航向角
        Left_heading_angle_signal = '_g_GAC_A18_NET_net_apl_g_netRunnable_rbCanRxLD_serializer_m_CNetVFC_Line_SenderPort_1_local.TChangeableMemPool._._._m_arrayPool._0_._elem._m_vfc_lineInformation._0_._VFC_Line_HeadingAngle'
        # 左侧车道线
        Left_lane_line_signal = '_g_GAC_A18_NET_net_apl_g_netRunnable_rbCanRxLD_serializer_m_CNetVFC_Line_SenderPort_1_local.TChangeableMemPool._._._m_arrayPool._0_._elem._m_vfc_lineInformation._0_._VFC_Line_Dy'
        # 右航向角
        Right_heading_angle_signal = '_g_GAC_A18_NET_net_apl_g_netRunnable_rbCanRxLD_serializer_m_CNetVFC_Line_SenderPort_1_local.TChangeableMemPool._._._m_arrayPool._0_._elem._m_vfc_lineInformation._1_._VFC_Line_HeadingAngle'
        # 右侧车道线
        Right_lane_line_signal = '_g_GAC_A18_NET_net_apl_g_netRunnable_rbCanRxLD_serializer_m_CNetVFC_Line_SenderPort_1_local.TChangeableMemPool._._._m_arrayPool._0_._elem._m_vfc_lineInformation._1_._VFC_Line_Dy'
        # vxvRef
        vxvRef_signal = '_g_PL_AD_fw_DACoreCyclic_HV_PerPmeRunnable_PerPmeRunnable_m_pmePort_out_local.TChangeableMemPool._._._m_arrayPool._0_._elem._vxvRef_sw'
        odometer_signal = 'ICM_TotalOdometer'


        # Line ID    255
        left_line_signal = 'VFC_Line01_LineID'
        right_line_signal = 'VFC_Line02_LineID'

        if self.mf:
            try:
                left = self.mf.get(signal_left)
                right = self.mf.get(signal_right)
                speed = self.mf.get(signal_speed)
                RoadWheelAngle = self.mf.get(signal_RoadWheelAngle).samples.tolist()
                Left_heading_angle = self.mf.get(Left_heading_angle_signal).samples.tolist()
                Left_lane_line = self.mf.get(Left_lane_line_signal).samples.tolist()
                print(len(Left_lane_line))
                print(len(left.samples.tolist()))
                Right_heading_angle = self.mf.get(Right_heading_angle_signal).samples.tolist()
                Right_lane_line = self.mf.get(Right_lane_line_signal).samples.tolist()
                vxvRef = self.mf.get(vxvRef_signal)
                odometer = self.mf.get(odometer_signal)
                left_line = self.mf.get(left_line_signal).samples.tolist()
                right_line = self.mf.get(right_line_signal).samples.tolist()
            except Exception as e:
                print(e)
                loser_file_data.append(self.filename)
            else:
                def func(data):
                    num = data.samples.tolist()[0]
                    index_list = [0]
                    for index in range(len(data.samples.tolist())):
                        if num != data.samples.tolist()[index]:
                            num = data.samples.tolist()[index]
                            index_list.append(index)
                    if len(data.samples.tolist())-1 not in index_list:
                        index_list.append(len(data.samples.tolist())-1)
                    return index_list
                # 处理数据长度问题  speed, vxvRef
                st = speed.timestamps.tolist()
                start_time = 0
                stop_time = -2
                # 计算差值
                left_data = []
                left_time = left.timestamps.tolist()

                old_spd = speed.samples.tolist()
                old_vxv = vxvRef.samples.tolist()
                old_spd_time = speed.timestamps.tolist()
                old_vxvRef = vxvRef.samples.tolist()
                new_spd = ['' for x in left_time]
                new_vxvRef = ['' for x in left_time]
                for tt in range(len(old_spd_time)):
                    this_index = index_number(left_time, old_spd_time[tt])
                    new_spd[this_index] = old_spd[tt]
                    new_vxvRef[this_index] = old_vxvRef[tt]
                for i in range(len(new_spd)):
                    if new_spd[i] == '':
                        if i==0:
                            if new_spd[i+1] != 0:
                                new_spd[i] = new_spd[i+1]
                            else:
                                new_spd[i] = 0
                        else:
                            new_spd[i] = new_spd[i-1]
                    if new_vxvRef[i] == '':
                        if i==0:
                            if new_vxvRef[i+1] != 0:
                                new_vxvRef[i] = new_vxvRef[i+1]
                            else:
                                new_vxvRef[i] = 0
                        else:
                            new_vxvRef[i] = new_vxvRef[i-1]
                left_index_list = func(left)
                right_index_list = func(right)
                if left_index_list == [] and right_index_list == []:
                    self.close_file()
                    return False
                new_data = {
                    'left': [],
                    'left_time': [],
                    'right': [],
                    'right_time': [],
                    'spd': [],
                    'wheel': [],
                    'Left_heading_angle': [],
                    'left_lane': [],
                    'Right_heading_angle': [],
                    'right_lane': [],
                    'vxvRef': [],
                    'left_line': [],
                    'right_line': []
                }
                # 
                for index in range(len(left_index_list)-1):
                    new_data['left'].append(left.samples.tolist()[left_index_list[index]:left_index_list[index+1]])
                    new_data['left_time'].append(left.timestamps.tolist()[left_index_list[index]:left_index_list[index+1]])
                    new_data['right'].append([])
                    new_data['right_time'].append([])
                    new_data['spd'].append(new_spd[left_index_list[index]:left_index_list[index+1]])
                    new_data['wheel'].append(RoadWheelAngle[left_index_list[index]:left_index_list[index+1]])

                    new_data['Left_heading_angle'].append(Left_heading_angle[left_index_list[index]:left_index_list[index+1]])
                    new_data['left_lane'].append(Left_lane_line[left_index_list[index]:left_index_list[index+1]])
                    new_data['Right_heading_angle'].append(Right_heading_angle[left_index_list[index]:left_index_list[index+1]])
                    new_data['right_lane'].append(Right_lane_line[left_index_list[index]:left_index_list[index+1]])
                    new_data['vxvRef'].append(new_vxvRef[left_index_list[index]:left_index_list[index+1]])
                    new_data['left_line'].append(left_line[left_index_list[index]:left_index_list[index+1]])
                    new_data['right_line'].append([])
                for index in range(len(right_index_list)-1):
                    new_data['left'].append([])
                    new_data['left_time'].append([])
                    new_data['right'].append(right.samples.tolist()[right_index_list[index]:right_index_list[index+1]])
                    new_data['right_time'].append(right.timestamps.tolist()[right_index_list[index]:right_index_list[index+1]])
                    new_data['spd'].append(new_spd[right_index_list[index]:right_index_list[index+1]])
                    new_data['wheel'].append(RoadWheelAngle[right_index_list[index]:right_index_list[index+1]])

                    new_data['Left_heading_angle'].append(Left_heading_angle[right_index_list[index]:right_index_list[index+1]])
                    new_data['left_lane'].append(Left_lane_line[right_index_list[index]:right_index_list[index+1]])
                    new_data['Right_heading_angle'].append(Right_heading_angle[right_index_list[index]:right_index_list[index+1]])
                    new_data['right_lane'].append(Right_lane_line[right_index_list[index]:right_index_list[index+1]])
                    new_data['vxvRef'].append(new_vxvRef[right_index_list[index]:right_index_list[index+1]])
                    new_data['left_line'].append([])
                    new_data['right_line'].append(right_line[right_index_list[index]:right_index_list[index+1]])
                # for key,value in new_data.items():
                #     print(len(value))
                # 车道线判断逻辑函数
                def func2(i,direction,speed,max_spd,min_spd):
                    print(direction)
                    return_data = 0
                    lane_list = []
                    overrun = []
                    for lane_line in range(len(new_data[f'{direction}_lane'][i])-1):
                        if new_data[f'{direction}_lane'][i][lane_line] == 2048:
                            print('无信号')
                            continue
                        this_num = new_data[f'{direction}_lane'][i][lane_line] * 0.015625 - 32
                        next_num = new_data[f'{direction}_lane'][i][lane_line + 1] * 0.015625 - 32
                        print(next_num - this_num)
                        if abs(next_num - this_num) >= 2.4:
                            lane_list.append(lane_line)
                    print(lane_list)
                    if lane_list != []:
                        if len(lane_list) > 1:
                            print('多次变道, 不做计算')
                        else:
                            print(f'单次变道{direction}')
                            new_lane = new_data[f'{direction}_lane'][i][lane_list[0]+1:]
                            this_len = int(len(new_lane)/5)
                            new_list = [sum(new_lane[:this_len])/len(new_lane[:this_len]),sum(new_lane[this_len:this_len*2])/len(new_lane[this_len:this_len*2]),sum(new_lane[this_len*2:this_len*3])/len(new_lane[this_len*2:this_len*3]),sum(new_lane[this_len*3:this_len*4])/len(new_lane[this_len*3:this_len*4]),sum(new_lane[this_len*4:])/len(new_lane[this_len*4:])]
                            if new_list[0] > new_list[1] > new_list[2] > new_list[3] > new_list[4]:
                                # 变道到车轮压线时间
                                Time_from_lighting_to_pressing_line = new_data[f'{direction}_time'][i][lane_list[0]] - new_data[f'{direction}_time'][i][0]
                                Line_pressing_data = [self.filename,speed,max_spd,min_spd,Time_from_lighting_to_pressing_line, self.roadType]
                                if Line_pressing_data not in Line_pressing:
                                    Line_pressing.append(Line_pressing_data)
                                    return_data = 1
                    else:
                        this_len = int(len(new_data[f'{direction}_lane'][i])/5)
                        new_list = [
                            sum(new_data[f'{direction}_lane'][i][:this_len])/len(new_data[f'{direction}_lane'][i][:this_len]),
                            sum(new_data[f'{direction}_lane'][i][this_len:this_len*2])/len(new_data[f'{direction}_lane'][i][this_len:this_len*2]),
                            sum(new_data[f'{direction}_lane'][i][this_len*2:this_len*3])/len(new_data[f'{direction}_lane'][i][this_len*2:this_len*3]),
                            sum(new_data[f'{direction}_lane'][i][this_len*3:this_len*4])/len(new_data[f'{direction}_lane'][i][this_len*3:this_len*4]),
                            sum(new_data[f'{direction}_lane'][i][this_len*4:])/len(new_data[f'{direction}_lane'][i][this_len*4:])]
                        if min(new_list) == new_list[-1] and new_data[f'{direction}_lane'][i] != new_data[f'{direction}_lane'][-1]:
                            this_lane_list = new_data[f'{direction}_lane'][i][this_len*4:]
                            if len(new_data[f'{direction}_lane'][i+1]) >= 200:
                                this_lane_list.extend(new_data[f'{direction}_lane'][i+1][:200])
                            else:
                                this_lane_list.extend(new_data[f'{direction}_lane'][i+1])
                            for lane_line in range(len(this_lane_list)-1):
                                if this_lane_list[lane_line] == 2048:
                                    print('无信号')
                                    continue
                                this_num = this_lane_list[lane_line] * 0.015625 - 32
                                next_num = this_lane_list[lane_line + 1] * 0.015625 - 32
                                print(next_num - this_num)
                                if abs(next_num - this_num) >= 2.4:
                                    lane_list.append(lane_line)
                            if lane_list != []:
                                if len(lane_list) > 1:
                                    print('多次变道, 不做计算')
                                else:
                                    print(f'单次变道{direction}')
                                    new_lane = new_data[f'{direction}_lane'][i][lane_list[0]+1:]
                                    this_len = int(len(new_lane)/5)
                                    new_list = [sum(new_lane[:this_len])/len(new_lane[:this_len]),sum(new_lane[this_len:this_len*2])/len(new_lane[this_len:this_len*2]),sum(new_lane[this_len*2:this_len*3])/len(new_lane[this_len*2:this_len*3]),sum(new_lane[this_len*3:this_len*4])/len(new_lane[this_len*3:this_len*4]),sum(new_lane[this_len*4:])/len(new_lane[this_len*4:])]
                                    if new_list[0] > new_list[1] > new_list[2] > new_list[3] > new_list[4]:
                                        # 变道到车轮压线时间
                                        Time_from_lighting_to_pressing_line = new_data[f'{direction}_time'][i][lane_list[0]] - new_data[f'{direction}_time'][i][0]
                                        Line_pressing_data = [self.filename,speed,max_spd,min_spd,Time_from_lighting_to_pressing_line, self.roadType]
                                        if Line_pressing_data not in Line_pressing:
                                            Line_pressing.append(Line_pressing_data)
                                            return_data = 1
                    return return_data
                    
                    
                def func3(key,i,speed,max_spd,min_spd,direction):
                    result_dict[key][direction][0] += 1
                    this_time = new_data['{}_time'.format(direction)][i][-1] - new_data['{}_time'.format(direction)][i][0]
                    #################################
                    this_index = index_number(time_1,this_time)
                    new_result_dict[key][this_index] += 1
                    #################################
                    mysql_data_sql = [self.filename,direction, speed,max_spd,min_spd, this_time, self.roadType]
                    if mysql_data_sql not in mysql_data:
                        mysql_data.append(mysql_data_sql)
                    #################################
                    result_dict[key][direction][1].append(this_time)
                # 数据规整完成, 长度一致,无变化
                for i in range(len(new_data['spd'])):
                    judgment_basis = 0
                    for j in new_data['wheel'][i]:
                        if j > 0.1:
                            judgment_basis = 1
                            break
                    if judgment_basis == 0:
                        try:
                            # 车速计算
                            speed = int(sum(new_data['spd'][i]))/len(new_data['spd'][i]) * 3.6
                            # 最大车速留档
                            max_spd = int(max(new_data['spd'][i])) * 3.6
                            # 最小车速留档
                            min_spd = int(min(new_data['spd'][i])) * 3.6
                        except IndexError:
                            break
                        else:
                            if speed >=80:
                                if 1 in new_data['left'][i] and 1 not in new_data['right'][i]:
                                    # 判断车道线情况
                                    # Time_from_lighting_to_pressing_line 为开启变道灯到压线的时间
                                    # 这里的判断逻辑需要重新计算, 考虑变道中跳变仅存在一次,并且确实变道完成
                                    # 如:
                                    # 1.跨过车道线完成跳变之后, 继续变动完成变道操作
                                    # 2.跨过车到线之后的数据迅速达到正常车位, 即车道线扣除车身之后最大值应该为60公分,否则视为未变道成功, 需要继续查看后续数据来判断
                                    lane = func2(i,'left',speed,max_spd,min_spd)
                                    # 车道线检测
                                    if lane == 1:
                                        func3('80-100',i,speed,max_spd,min_spd,'left')
                                elif 1 not in new_data['left'][i] and 1 in new_data['right'][i]:
                                    lane = func2(i,'right',speed,max_spd,min_spd)
                                    if lane == 1:
                                        
                                        func3('80-100',i,speed,max_spd,min_spd,'right')
                                else:
                                    continue
                            elif speed >=60:
                                if 1 in new_data['left'][i] and 1 not in new_data['right'][i]:
                                    # 判断车道线情况
                                    lane = func2(i,'left',speed,max_spd,min_spd)
                                    if lane == 1:
                                        func3('60-80',i,speed,max_spd,min_spd,'left')
                                elif 1 not in new_data['left'][i] and 1 in new_data['right'][i]:
                                    # 判断车道线情况
                                    lane = func2(i,'right',speed,max_spd,min_spd)
                                    if lane == 1:
                                        func3('60-80',i,speed,max_spd,min_spd,'right')
                                else:
                                    continue
                            elif speed >=40:
                                if 1 in new_data['left'][i] and 1 not in new_data['right'][i]:
                                    # 判断车道线情况
                                    lane = func2(i,'left',speed,max_spd,min_spd)
                                    if lane == 1:
                                        func3('40-60',i,speed,max_spd,min_spd,'left')
                                elif 1 not in new_data['left'][i] and 1 in new_data['right'][i]:
                                    # 判断车道线情况
                                    lane = func2(i,'right',speed,max_spd,min_spd)
                                    if lane == 1:
                                        func3('40-60',i,speed,max_spd,min_spd,'right')
                                else:
                                    continue
                            elif speed > 0:
                                if 1 in new_data['left'][i] and 1 not in new_data['right'][i]:
                                    # 判断车道线情况
                                    lane = func2(i,'left',speed,max_spd,min_spd)
                                    if lane == 1:
                                        func3('0~40',i,speed,max_spd,min_spd,'left')
                                elif 1 not in new_data['left'][i] and 1 in new_data['right'][i]:
                                    # 判断车道线情况
                                    lane = func2(i,'right',speed,max_spd,min_spd)
                                    if lane == 1:
                                        func3('0~40',i,speed,max_spd,min_spd,'right')
                                        # result_dict['0~40']['right'][1].append(this_time)
                                else:
                                    continue
                            else:
                                continue
                            
                            this_odometer = odometer.samples.tolist()
                            this_time = odometer.timestamps.tolist()
                            odo = this_odometer[-1] - this_odometer[0]
                            t = this_time[-1] - this_time[0]
                            global all_odometer
                            all_odometer += odo
                            global all_time
                            all_time += t
                self.close_file()
                return new_result_dict
            finally:
                self.close_file()
Пример #6
0
def generate_test_file(tmpdir, version="4.10"):
    mdf = MDF(version=version)

    if version <= "3.30":
        filename = Path(tmpdir) / f"big_test_{version}.mdf"
    else:
        filename = Path(tmpdir) / f"big_test_{version}.mf4"

    if filename.exists():
        return filename

    t = np.arange(cycles, dtype=np.float64)

    cls = v4b.ChannelConversion if version >= "4.00" else v3b.ChannelConversion

    # no conversion
    sigs = []
    for i in range(channels_count):
        sig = Signal(
            np.ones(cycles, dtype=np.uint64) * i,
            t,
            name="Channel_{}".format(i),
            unit="unit_{}".format(i),
            conversion=None,
            comment="Unsigned int 16bit channel {}".format(i),
            raw=True,
        )
        sigs.append(sig)
    mdf.append(sigs, common_timebase=True)

    # linear
    sigs = []
    for i in range(channels_count):
        conversion = {
            "conversion_type": v4c.CONVERSION_TYPE_LIN
            if version >= "4.00"
            else v3c.CONVERSION_TYPE_LINEAR,
            "a": float(i),
            "b": -0.5,
        }
        sig = Signal(
            np.ones(cycles, dtype=np.int64),
            t,
            name="Channel_{}".format(i),
            unit="unit_{}".format(i),
            conversion=cls(**conversion),
            comment="Signed 16bit channel {} with linear conversion".format(i),
            raw=True,
        )
        sigs.append(sig)
    mdf.append(sigs, common_timebase=True)

    # algebraic
    sigs = []
    for i in range(channels_count):
        conversion = {
            "conversion_type": v4c.CONVERSION_TYPE_ALG
            if version >= "4.00"
            else v3c.CONVERSION_TYPE_FORMULA,
            "formula": "{} * sin(X)".format(i),
        }
        sig = Signal(
            np.arange(cycles, dtype=np.int32) / 100.0,
            t,
            name="Channel_{}".format(i),
            unit="unit_{}".format(i),
            conversion=cls(**conversion),
            comment="Sinus channel {} with algebraic conversion".format(i),
            raw=True,
        )
        sigs.append(sig)
    mdf.append(sigs, common_timebase=True)

    # rational
    sigs = []
    for i in range(channels_count):
        conversion = {
            "conversion_type": v4c.CONVERSION_TYPE_RAT
            if version >= "4.00"
            else v3c.CONVERSION_TYPE_RAT,
            "P1": 0,
            "P2": i,
            "P3": -0.5,
            "P4": 0,
            "P5": 0,
            "P6": 1,
        }
        sig = Signal(
            np.ones(cycles, dtype=np.int64),
            t,
            name="Channel_{}".format(i),
            unit="unit_{}".format(i),
            conversion=cls(**conversion),
            comment="Channel {} with rational conversion".format(i),
            raw=True,
        )
        sigs.append(sig)
    mdf.append(sigs, common_timebase=True)

    # string
    sigs = []
    encoding = "latin-1" if version < "4.00" else "utf-8"
    for i in range(channels_count):
        sig = [
            "Channel {} sample {}".format(i, j).encode(encoding) for j in range(cycles)
        ]
        sig = Signal(
            np.array(sig),
            t,
            name="Channel_{}".format(i),
            unit="unit_{}".format(i),
            comment="String channel {}".format(i),
            raw=True,
            encoding=encoding,
        )
        sigs.append(sig)
    mdf.append(sigs, common_timebase=True)

    # byte array
    sigs = []
    ones = np.ones(cycles, dtype=np.dtype("(8,)u1"))
    for i in range(channels_count):
        sig = Signal(
            ones * i,
            t,
            name="Channel_{}".format(i),
            unit="unit_{}".format(i),
            comment="Byte array channel {}".format(i),
            raw=True,
        )
        sigs.append(sig)
    mdf.append(sigs, common_timebase=True)

    # value to text
    sigs = []
    ones = np.ones(cycles, dtype=np.uint64)
    conversion = {
        "raw": np.arange(255, dtype=np.float64),
        "phys": np.array(["Value {}".format(i).encode("ascii") for i in range(255)]),
        "conversion_type": v4c.CONVERSION_TYPE_TABX
        if version >= "4.00"
        else v3c.CONVERSION_TYPE_TABX,
        "links_nr": 260,
        "ref_param_nr": 255,
    }

    for i in range(255):
        conversion["val_{}".format(i)] = conversion[
            "param_val_{}".format(i)
        ] = conversion["raw"][i]
        conversion["text_{}".format(i)] = conversion["phys"][i]
    conversion["text_{}".format(255)] = "Default"

    for i in range(channels_count):
        sig = Signal(
            ones * i,
            t,
            name="Channel_{}".format(i),
            unit="unit_{}".format(i),
            comment="Value to text channel {}".format(i),
            conversion=cls(**conversion),
            raw=True,
        )
        sigs.append(sig)
    mdf.append(sigs, common_timebase=True)

    name = mdf.save(filename, overwrite=True)
    mdf.close()
Пример #7
0
def generate_arrays_test_file(tmpdir):
    version = "4.10"
    mdf = MDF(version=version)
    filename = Path(tmpdir) / f"arrays_test_{version}.mf4"

    if filename.exists():
        return filename

    t = np.arange(cycles, dtype=np.float64)

    # lookup tabel with axis
    sigs = []
    for i in range(array_channels_count):
        samples = [
            np.ones((cycles, 2, 3), dtype=np.uint64) * i,
            np.ones((cycles, 2), dtype=np.uint64) * i,
            np.ones((cycles, 3), dtype=np.uint64) * i,
        ]

        types = [
            ("Channel_{}".format(i), "(2, 3)<u8"),
            ("channel_{}_axis_1".format(i), "(2, )<u8"),
            ("channel_{}_axis_2".format(i), "(3, )<u8"),
        ]

        sig = Signal(
            np.core.records.fromarrays(samples, dtype=np.dtype(types)),
            t,
            name="Channel_{}".format(i),
            unit="unit_{}".format(i),
            conversion=None,
            comment="Array channel {}".format(i),
            raw=True,
        )
        sigs.append(sig)
    mdf.append(sigs, common_timebase=True)

    # lookup tabel with default axis
    sigs = []
    for i in range(array_channels_count):
        samples = [np.ones((cycles, 2, 3), dtype=np.uint64) * i]

        types = [("Channel_{}".format(i), "(2, 3)<u8")]

        sig = Signal(
            np.core.records.fromarrays(samples, dtype=np.dtype(types)),
            t,
            name="Channel_{}".format(i),
            unit="unit_{}".format(i),
            conversion=None,
            comment="Array channel {} with default axis".format(i),
            raw=True,
        )
        sigs.append(sig)
    mdf.append(sigs, common_timebase=True)

    # structure channel composition
    sigs = []
    for i in range(array_channels_count):
        samples = [
            np.ones(cycles, dtype=np.uint8) * i,
            np.ones(cycles, dtype=np.uint16) * i,
            np.ones(cycles, dtype=np.uint32) * i,
            np.ones(cycles, dtype=np.uint64) * i,
            np.ones(cycles, dtype=np.int8) * i,
            np.ones(cycles, dtype=np.int16) * i,
            np.ones(cycles, dtype=np.int32) * i,
            np.ones(cycles, dtype=np.int64) * i,
        ]

        types = [
            ("struct_{}_channel_0".format(i), np.uint8),
            ("struct_{}_channel_1".format(i), np.uint16),
            ("struct_{}_channel_2".format(i), np.uint32),
            ("struct_{}_channel_3".format(i), np.uint64),
            ("struct_{}_channel_4".format(i), np.int8),
            ("struct_{}_channel_5".format(i), np.int16),
            ("struct_{}_channel_6".format(i), np.int32),
            ("struct_{}_channel_7".format(i), np.int64),
        ]

        sig = Signal(
            np.core.records.fromarrays(samples, dtype=np.dtype(types)),
            t,
            name="Channel_{}".format(i),
            unit="unit_{}".format(i),
            conversion=None,
            comment="Structure channel composition {}".format(i),
            raw=True,
        )
        sigs.append(sig)

    mdf.append(sigs, common_timebase=True)

    name = mdf.save(filename, overwrite=True)

    mdf.close()
Пример #8
0
class openMDF:
    def __init__(self, path, roadtype=0):
        self.filename = path.split('/')[-1].split('.')[0]
        self.roadType = roadtype
        if self.filename not in loser_file_data:
            self.open_file(path)
            self.task_1()

    def open_file(self, path):
        print('开启mf4文件')
        self.mf = MDF(path)

    def close_file(self):
        print('关闭mf4文件')
        self.mf.close()

    # 统计转向灯开启时间
    def task_1(self):
        signal_left = '_g_PL_AD_fw_PL_AD_FCT_RunnableSppHmi_RunnableSppHmi_m_sppHmiInput_out_local.TChangeableMemPool._._._m_arrayPool._0_._elem._m_dirIndL'
        signal_right = '_g_PL_AD_fw_PL_AD_FCT_RunnableSppHmi_RunnableSppHmi_m_sppHmiInput_out_local.TChangeableMemPool._._._m_arrayPool._0_._elem._m_dirIndR'
        signal_speed = '_g_PL_AD_fw_PL_AD_FCT_RunnableFsm_RunnableFsm._m_fsmController._m_fip._m_displayedSpeedCalculator._m_displaySpeed._m_value'
        # 轮端转角
        signal_RoadWheelAngle = '_g_PL_AD_fw_VMC_VMC_FW_MvpVse_VseSes_VseSes_m_portVehicleStateEstimation_local.TChangeableMemPool._._._m_arrayPool._0_._elem._m_estimation_RoadWheelAngle_Front._m_value'
        # 左航向角
        Left_heading_angle_signal = '_g_GAC_A18_NET_net_apl_g_netRunnable_rbCanRxLD_serializer_m_CNetVFC_Line_SenderPort_1_local.TChangeableMemPool._._._m_arrayPool._0_._elem._m_vfc_lineInformation._0_._VFC_Line_HeadingAngle'
        # 左侧车道线
        Left_lane_line_signal = '_g_GAC_A18_NET_net_apl_g_netRunnable_rbCanRxLD_serializer_m_CNetVFC_Line_SenderPort_1_local.TChangeableMemPool._._._m_arrayPool._0_._elem._m_vfc_lineInformation._0_._VFC_Line_Dy'
        # 右航向角
        Right_heading_angle_signal = '_g_GAC_A18_NET_net_apl_g_netRunnable_rbCanRxLD_serializer_m_CNetVFC_Line_SenderPort_1_local.TChangeableMemPool._._._m_arrayPool._0_._elem._m_vfc_lineInformation._1_._VFC_Line_HeadingAngle'
        # 右侧车道线
        Right_lane_line_signal = '_g_GAC_A18_NET_net_apl_g_netRunnable_rbCanRxLD_serializer_m_CNetVFC_Line_SenderPort_1_local.TChangeableMemPool._._._m_arrayPool._0_._elem._m_vfc_lineInformation._1_._VFC_Line_Dy'
        # vxvRef
        vxvRef_signal = '_g_PL_AD_fw_DACoreCyclic_HV_PerPmeRunnable_PerPmeRunnable_m_pmePort_out_local.TChangeableMemPool._._._m_arrayPool._0_._elem._vxvRef_sw'
        odometer_signal = 'ICM_TotalOdometer'

        # Line ID    255
        left_line_signal = 'VFC_Line01_LineID'
        right_line_signal = 'VFC_Line02_LineID'

        if self.mf:
            try:
                left = self.mf.get(signal_left)
                right = self.mf.get(signal_right)
                speed = self.mf.get(signal_speed)
                RoadWheelAngle = self.mf.get(
                    signal_RoadWheelAngle).samples.tolist()
                Left_heading_angle = self.mf.get(
                    Left_heading_angle_signal).samples.tolist()
                Left_lane_line = self.mf.get(
                    Left_lane_line_signal).samples.tolist()
                Right_heading_angle = self.mf.get(
                    Right_heading_angle_signal).samples.tolist()
                Right_lane_line = self.mf.get(
                    Right_lane_line_signal).samples.tolist()
                vxvRef = self.mf.get(vxvRef_signal)
                odometer = self.mf.get(odometer_signal)
                left_line = self.mf.get(left_line_signal).samples.tolist()
                right_line = self.mf.get(right_line_signal).samples.tolist()
            except Exception as e:
                print(e)
                loser_file_data.append(self.filename)
            else:
                lane = 0
                for i in range(len(Left_lane_line) - 1):
                    if abs((Left_lane_line[i] - Left_lane_line[i + 1]) *
                           0.015625 - 32) >= 2.4:
                        lane = 1
                        break
                if lane == 0:
                    return
                else:

                    def func(data):
                        num = data.samples.tolist()[0]
                        index_list = [0]
                        for index in range(len(data.samples.tolist())):
                            if num != data.samples.tolist()[index]:
                                num = data.samples.tolist()[index]
                                index_list.append(index)
                        if len(data.samples.tolist()) - 1 not in index_list:
                            index_list.append(len(data.samples.tolist()) - 1)
                        return index_list