def get_files(sample_length, root, InputType, task): data = [] fault_mode = os.listdir(os.path.join(root)) # 列出6种健康状态 (listdir返回值是一个列表,列表里面存储该path下面的子目录的名称) for i in tqdm(range(len(label))): path = os.path.join(root, fault_mode[i]) data1 = data_load(sample_length, filename=path, label=label[i], InputType=InputType, task=task) data += data1 return data这段代码什么意思

时间: 2024-03-31 18:38:35 浏览: 10
这段代码的作用是读取指定路径下的数据,并将其加载到内存中。具体来说,它接受4个参数:`sample_length`表示每个样本的长度;`root`表示数据所在的根目录;`InputType`表示数据的输入类型;`task`表示数据的任务类型。该函数首先获取`root`目录下的子目录列表,然后遍历该列表,分别读取每个子目录下的数据并使用`data_load`函数进行加载。最后将所有加载好的数据存储在`data`列表中,并返回该列表。
相关问题

PermissionError: [Errno 13] Permission denied: 'fault_data.xls'

PermissionError: [Errno 13] Permission denied: 'fault_data.xls' 是一个常见的错误,它表示在尝试访问或操作文件时,由于权限不足而导致被拒绝。这通常发生在以下情况下: 1. 文件所在的目录没有读写权限:如果你没有足够的权限来读取或写入该目录中的文件,就会出现这个错误。你可以尝试更改文件所在目录的权限或联系管理员来获取适当的权限。 2. 文件正在被其他程序占用:如果另一个程序正在使用该文件,例如另一个应用程序正在写入或打开该文件,你可能无法访问它。你可以尝试关闭其他程序或等待其释放该文件。 3. 文件被设置为只读:如果文件的属性被设置为只读,你将无法对其进行写入操作。你可以尝试更改文件属性或联系文件所有者来获取写入权限。 4. 文件不存在:如果指定的文件不存在,你将无法访问它并且会出现该错误。请确保文件路径正确,并检查文件是否存在。

优化代码 def fault_classification_wrapper(vin, main_path, data_path, log_path, done_path): start_time = time.time() isc_path = os.path.join(done_path, vin, 'isc_cal_result', f'{vin}_report.xlsx') if not os.path.exists(isc_path): print('No isc detection input!') else: isc_input = isc_produce_alarm(isc_path, vin) ica_path = os.path.join(done_path, vin, 'ica_cal_result', f'ica_detection_alarm_{vin}.csv') if not os.path.exists(ica_path): print('No ica detection input!') else: ica_input = ica_produce_alarm(ica_path) soh_path = os.path.join(done_path, vin, 'SOH_cal_result', f'{vin}_sohAno.csv') if not os.path.exists(soh_path): print('No soh detection input!') else: soh_input = soh_produce_alarm(soh_path, vin) alarm_df = pd.concat([isc_input, ica_input, soh_input]) alarm_df.reset_index(drop=True, inplace=True) alarm_df['alarm_cell'] = alarm_df['alarm_cell'].apply(lambda _: str(_)) print(vin) module = AutoAnalysisMain(alarm_df, main_path, data_path, done_path) module.analysis_process() flags = os.O_WRONLY | os.O_CREAT modes = stat.S_IWUSR | stat.S_IRUSR with os.fdopen(os.open(os.path.join(log_path, 'log.txt'), flags, modes), 'w') as txt_file: for k, v in module.output.items(): txt_file.write(k + ':' + str(v)) txt_file.write('\n') for x, y in module.output_sub.items(): txt_file.write(x + ':' + str(y)) txt_file.write('\n\n') fc_result_path = os.path.join(done_path, vin, 'fc_result') if not os.path.exists(fc_result_path): os.makedirs(fc_result_path) pd.DataFrame(module.output).to_csv( os.path.join(fc_result_path, 'main_structure.csv')) df2 = pd.DataFrame() for subs in module.output_sub.keys(): sub_s = pd.Series(module.output_sub[subs]) df2 = df2.append(sub_s, ignore_index=True) df2.to_csv(os.path.join(fc_result_path, 'sub_structure.csv')) end_time = time.time() print("time cost of fault classification:", float(end_time - start_time) * 1000.0, "ms") return

Here are some suggestions to optimize the code: 1. Use list comprehension to simplify the code: ``` alarm_df = pd.concat([isc_input, ica_input, soh_input]).reset_index(drop=True) alarm_df['alarm_cell'] = alarm_df['alarm_cell'].apply(str) ``` 2. Use context manager to simplify file operation: ``` with open(os.path.join(log_path, 'log.txt'), 'w') as txt_file: for k, v in module.output.items(): txt_file.write(f"{k}:{v}\n") for x, y in module.output_sub.items(): txt_file.write(f"{x}:{y}\n\n") ``` 3. Use `Pathlib` to simplify path operation: ``` fc_result_path = Path(done_path) / vin / 'fc_result' fc_result_path.mkdir(parents=True, exist_ok=True) pd.DataFrame(module.output).to_csv(fc_result_path / 'main_structure.csv') pd.DataFrame(module.output_sub).to_csv(fc_result_path / 'sub_structure.csv') ``` 4. Use f-string to simplify string formatting: ``` print(f"time cost of fault classification: {(end_time - start_time) * 1000.0} ms") ``` Here's the optimized code: ``` def fault_classification_wrapper(vin, main_path, data_path, log_path, done_path): start_time = time.time() isc_path = Path(done_path) / vin / 'isc_cal_result' / f'{vin}_report.xlsx' if not isc_path.exists(): print('No isc detection input!') isc_input = pd.DataFrame() else: isc_input = isc_produce_alarm(isc_path, vin) ica_path = Path(done_path) / vin / 'ica_cal_result' / f'ica_detection_alarm_{vin}.csv' if not ica_path.exists(): print('No ica detection input!') ica_input = pd.DataFrame() else: ica_input = ica_produce_alarm(ica_path) soh_path = Path(done_path) / vin / 'SOH_cal_result' / f'{vin}_sohAno.csv' if not soh_path.exists(): print('No soh detection input!') soh_input = pd.DataFrame() else: soh_input = soh_produce_alarm(soh_path, vin) alarm_df = pd.concat([isc_input, ica_input, soh_input]).reset_index(drop=True) alarm_df['alarm_cell'] = alarm_df['alarm_cell'].apply(str) print(vin) module = AutoAnalysisMain(alarm_df, main_path, data_path, done_path) module.analysis_process() with open(Path(log_path) / 'log.txt', 'w') as txt_file: for k, v in module.output.items(): txt_file.write(f"{k}:{v}\n") for x, y in module.output_sub.items(): txt_file.write(f"{x}:{y}\n\n") fc_result_path = Path(done_path) / vin / 'fc_result' fc_result_path.mkdir(parents=True, exist_ok=True) pd.DataFrame(module.output).to_csv(fc_result_path / 'main_structure.csv') pd.DataFrame(module.output_sub).to_csv(fc_result_path / 'sub_structure.csv') end_time = time.time() print(f"time cost of fault classification: {(end_time - start_time) * 1000.0} ms") return ```

相关推荐

BEGIN REGION Servo Power //Servo Power IF "AlwaysTRUE" AND "Control Voltage On" THEN "Robot1 Power for Servo 1-2" := "Robot2 Power for Servo 3-4" := "Robot3 Power for Servo 5-6" := "Robot4 Power for Travelling Servo 7-8" := "Robot5 Power for Travelling Servo 9-10" := true; ELSE "Robot1 Power for Servo 1-2" := "Robot2 Power for Servo 3-4" := "Robot3 Power for Servo 5-6" := "Robot4 Power for Travelling Servo 7-8" := "Robot5 Power for Travelling Servo 9-10" := FALSE; END_IF; //Servo Limit Sensor - 启用硬限位 IF "AlwaysTRUE" AND NOT "Buzzer Stop Button" THEN "DB1002_Control Status Epos".Robot1.X.CamAct := "DB1002_Control Status Epos".Robot1.Z.CamAct := "DB1002_Control Status Epos".Robot2.X.CamAct := "DB1002_Control Status Epos".Robot2.Z.CamAct := "DB1002_Control Status Epos".Robot3.X.CamAct := "DB1002_Control Status Epos".Robot3.Z.CamAct := "DB1002_Control Status Epos".Robot4.X.CamAct := "DB1002_Control Status Epos".Robot4.Z.CamAct := "DB1002_Control Status Epos".Robot5.X.CamAct := "DB1002_Control Status Epos".Robot5.Z.CamAct := "DB1002_Control Status Epos".Load.X.CamAct := "DB1002_Control Status Epos".UnLoad.X.CamAct := TRUE; ELSE "DB1002_Control Status Epos".Robot1.X.CamAct := "DB1002_Control Status Epos".Robot1.Z.CamAct := "DB1002_Control Status Epos".Robot2.X.CamAct := "DB1002_Control Status Epos".Robot2.Z.CamAct := "DB1002_Control Status Epos".Robot3.X.CamAct := "DB1002_Control Status Epos".Robot3.Z.CamAct := "DB1002_Control Status Epos".Robot4.X.CamAct := "DB1002_Control Status Epos".Robot4.Z.CamAct := "DB1002_Control Status Epos".Robot5.X.CamAct := "DB1002_Control Status Epos".Robot5.Z.CamAct := "DB1002_Control Status Epos".Load.X.CamAct := "DB1002_Control Status Epos".UnLoad.X.CamAct := false; END_IF; //Robot1 X Power And Reset "FC192_Robot_Power"("E-Stop" := "DB1002_Control Status Epos".Robot1.X."E-Stop", Fault := "DB1001_Actual Status Epos".Robot1.X.Fault, Ready := "DB1001_Actual Status Epos".Robot1.X.OFF1_Ready, "Alarm Reset" := "Alarm Reset", Off1 => "DB1002_Control Status Epos".Robot1.X.Off1, "Enable Temp" := "DB1003_Servo Button"."Robot1 X"."Servo enabled Temp", "Enable Reset" := "DB1003_Servo Button"."Robot1 X"."Servo enabled Reset", "Time" := "DB3_Time".Robot1.T65);

detail_num = 0 for id_0 in range(0, len(list_0)): path = os.path.join(rootdir0, list_0[id_0]) if os.path.isfile(path): print(path) train_data = np.load(path) train_data = add_noise(train_data) train_len = int((len(train_data) - 5120) / 5120 + 1) for sub_id in range(0, train_len): sub_train_data = train_data[sub_id * 5120:sub_id * 5120 + 5120] str_num_train = str(num_train) np.save("../GB_data/" + Fault + "/noise_data/" + snr_str + "/train_data/" + str_num_train + "_train.npy", sub_train_data) np.save("../GB_data/" + Fault + "/noise_data/" + snr_str + "/train_lab/" + str_num_train + "_lab.npy", lab0) num_train += 1 for id_0 in range(0, len(T_list_0)): path = os.path.join(T_rootdir0, T_list_0[id_0]) if os.path.isfile(path): print(path) test_data = np.load(path) train_data = add_noise(train_data) test_len = int((len(test_data) - 5120) / 5120 + 1) for sub_id in range(0, test_len): sub_test_data = test_data[sub_id * 5120:sub_id * 5120 + 5120] str_num_test = str(num_test) np.save("../GB_data/" + Fault + "/noise_data/" + snr_str + "/test_data/" + str_num_test + "_test.npy", sub_test_data) np.save("../GB_data/" + Fault + "/noise_data/" + snr_str + "/test_lab/" + str_num_test + "_lab.npy", lab0) str_detail_num = str(detail_num) np.save("../GB_data/" + Fault + "/noise_data/" + snr_str + "/test_detail/0/" + str_detail_num + "_test.npy", sub_test_data) np.save( "../GB_data/" + Fault + "/noise_data/" + snr_str + "/test_lab_detail/0/" + str_detail_num + "_lab.npy", lab0) detail_num += 1 num_test += 1

最新推荐

recommend-type

关于STM32的flash读写数据和HardFault_Handler的问题

今天调试程序的时候需要把掉电前的数据存储到flash中之后等待下次初始化的时候把数据读进来。刚刚开始的时候去找了一些stm32的flash的操作,真的是废话连篇的真正能用到的没几句话,这里我把自己调试好的flash读写...
recommend-type

用AIDA模型,分析知乎、小红书和Facebook的广告效果.docx

用AIDA模型,分析知乎、小红书和Facebook的广告效果.docx
recommend-type

zigbee-cluster-library-specification

最新的zigbee-cluster-library-specification说明文档。
recommend-type

管理建模和仿真的文件

管理Boualem Benatallah引用此版本:布阿利姆·贝纳塔拉。管理建模和仿真。约瑟夫-傅立叶大学-格勒诺布尔第一大学,1996年。法语。NNT:电话:00345357HAL ID:电话:00345357https://theses.hal.science/tel-003453572008年12月9日提交HAL是一个多学科的开放存取档案馆,用于存放和传播科学研究论文,无论它们是否被公开。论文可以来自法国或国外的教学和研究机构,也可以来自公共或私人研究中心。L’archive ouverte pluridisciplinaire
recommend-type

MATLAB柱状图在信号处理中的应用:可视化信号特征和频谱分析

![matlab画柱状图](https://img-blog.csdnimg.cn/3f32348f1c9c4481a6f5931993732f97.png) # 1. MATLAB柱状图概述** MATLAB柱状图是一种图形化工具,用于可视化数据中不同类别或组的分布情况。它通过绘制垂直条形来表示每个类别或组中的数据值。柱状图在信号处理中广泛用于可视化信号特征和进行频谱分析。 柱状图的优点在于其简单易懂,能够直观地展示数据分布。在信号处理中,柱状图可以帮助工程师识别信号中的模式、趋势和异常情况,从而为信号分析和处理提供有价值的见解。 # 2. 柱状图在信号处理中的应用 柱状图在信号处理
recommend-type

hive中 的Metastore

Hive中的Metastore是一个关键的组件,它用于存储和管理Hive中的元数据。这些元数据包括表名、列名、表的数据类型、分区信息、表的存储位置等信息。Hive的查询和分析都需要Metastore来管理和访问这些元数据。 Metastore可以使用不同的后端存储来存储元数据,例如MySQL、PostgreSQL、Oracle等关系型数据库,或者Hadoop分布式文件系统中的HDFS。Metastore还提供了API,使得开发人员可以通过编程方式访问元数据。 Metastore的另一个重要功能是跟踪表的版本和历史。当用户对表进行更改时,Metastore会记录这些更改,并且可以让用户回滚到
recommend-type

JSBSim Reference Manual

JSBSim参考手册,其中包含JSBSim简介,JSBSim配置文件xml的编写语法,编程手册以及一些应用实例等。其中有部分内容还没有写完,估计有生之年很难看到完整版了,但是内容还是很有参考价值的。
recommend-type

"互动学习:行动中的多样性与论文攻读经历"

多样性她- 事实上SCI NCES你的时间表ECOLEDO C Tora SC和NCESPOUR l’Ingén学习互动,互动学习以行动为中心的强化学习学会互动,互动学习,以行动为中心的强化学习计算机科学博士论文于2021年9月28日在Villeneuve d'Asq公开支持马修·瑟林评审团主席法布里斯·勒菲弗尔阿维尼翁大学教授论文指导奥利维尔·皮耶昆谷歌研究教授:智囊团论文联合主任菲利普·普雷教授,大学。里尔/CRISTAL/因里亚报告员奥利维耶·西格德索邦大学报告员卢多维奇·德诺耶教授,Facebook /索邦大学审查员越南圣迈IMT Atlantic高级讲师邀请弗洛里安·斯特鲁布博士,Deepmind对于那些及时看到自己错误的人...3谢谢你首先,我要感谢我的两位博士生导师Olivier和Philippe。奥利维尔,"站在巨人的肩膀上"这句话对你来说完全有意义了。从科学上讲,你知道在这篇论文的(许多)错误中,你是我可以依
recommend-type

MATLAB柱状图在数据分析中的作用:从可视化到洞察

![MATLAB柱状图在数据分析中的作用:从可视化到洞察](https://img-blog.csdnimg.cn/img_convert/1a36558cefc0339f7836cca7680c0aef.png) # 1. MATLAB柱状图概述** 柱状图是一种广泛用于数据可视化的图表类型,它使用垂直条形来表示数据中不同类别或组别的值。在MATLAB中,柱状图通过`bar`函数创建,该函数接受数据向量或矩阵作为输入,并生成相应的高度条形。 柱状图的优点在于其简单性和易于理解性。它们可以快速有效地传达数据分布和组别之间的比较。此外,MATLAB提供了广泛的定制选项,允许用户调整条形颜色、
recommend-type

软件工程每个学期的生活及学习目标

软件工程每个学期的生活及学习目标可能包括以下内容: 1. 学习软件开发的基本理论和实践知识,掌握常用的编程语言和开发工具。 2. 熟悉软件开发的流程和方法,了解软件工程的标准和规范。 3. 掌握软件需求分析、设计、开发、测试、部署和维护的技能,能够独立完成简单的软件开发任务。 4. 培养团队合作的能力,学会与他人进行有效的沟通和协作,共同完成软件开发项目。 5. 提高自己的计算机技术水平,了解最新的软件开发技术和趋势,积极参与开源社区和技术交流活动。 6. 注重学习方法和习惯的培养,养成良好的学习和生活习惯,保持健康的身心状态。 7. 积极参加校内外的实践活动和比赛,拓展自己的视