95 lines
3.2 KiB
Python
95 lines
3.2 KiB
Python
import numpy as np
|
|
import pandas as pd
|
|
import os
|
|
from sklearn import datasets, linear_model
|
|
import argparse
|
|
|
|
|
|
class GasAnalyzer():
|
|
def __init__(self, folderPath):
|
|
self.folderPath = folderPath
|
|
|
|
def read_data(self):
|
|
path_list = os.listdir(self.folderPath)
|
|
self.validFiles = []
|
|
for filename in path_list:
|
|
if os.path.splitext(filename)[1] == '.txt':
|
|
self.validFiles.append(filename)
|
|
|
|
# 这两个循环可以合并优化,但不确定是否可以提高性能
|
|
names = locals()
|
|
self.rowCountsBackup = []
|
|
for i, filename in enumerate(self.validFiles):
|
|
names[f'df_{i}'] = pd.read_csv(self.folderPath + "\\" + filename, skiprows=1, sep=',')
|
|
self.rowCountsBackup.append(names[f'df_{i}'].shape[0])
|
|
|
|
for x in range(len(self.rowCountsBackup)):
|
|
if(x==0):
|
|
self.df_total = names[f'df_{0}']
|
|
else:
|
|
self.df_total = pd.concat([self.df_total, names[f'df_{x}']])
|
|
|
|
if(sum(self.rowCountsBackup) != self.df_total.shape[0]):
|
|
print("拼接气体分析仪数据失败!拼接前后行数不一致!")
|
|
return 1
|
|
|
|
return 0
|
|
|
|
def write_data(self):
|
|
a = 1
|
|
|
|
def merge_data(self, MeteorologicalStation):
|
|
a = 1
|
|
|
|
|
|
class MeteorologicalStation():
|
|
def __init__(self, folderPath):
|
|
self.folderPath = folderPath
|
|
|
|
def read_data(self):
|
|
path_list = os.listdir(self.folderPath)
|
|
self.validFiles = []
|
|
for filename in path_list:
|
|
if os.path.splitext(filename)[1] == '.dat':
|
|
self.validFiles.append(filename)
|
|
|
|
# 这两个循环可以合并优化,但不确定是否可以提高性能
|
|
names = locals()
|
|
self.rowCountsBackup = []
|
|
for i, filename in enumerate(self.validFiles):
|
|
names[f'df_{i}'] = pd.read_csv(self.folderPath + "\\" + filename, header=None, sep=',')
|
|
self.rowCountsBackup.append(names[f'df_{i}'].shape[0])
|
|
|
|
for x in range(len(self.rowCountsBackup)):
|
|
if(x==0):
|
|
self.df_total = names[f'df_{0}']
|
|
else:
|
|
self.df_total = pd.concat([self.df_total, names[f'df_{x}']])
|
|
|
|
if(sum(self.rowCountsBackup) != self.df_total.shape[0]):
|
|
print("拼接气体分析仪数据失败!拼接前后行数不一致!")
|
|
return 1
|
|
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
# parser = argparse.ArgumentParser()
|
|
# parser.add_argument("csv_path", help="Path of csv file which contains wavelength.")
|
|
# parser.add_argument("start_row", help="Start row of coning 410 sensor.")
|
|
# args = parser.parse_args()
|
|
|
|
# row_bin1, wave_bin1, row_bin2, wave_bin2 = read_data(args.csv_path, int(args.start_row))
|
|
|
|
GasAnalyzer_folderPath = r"D:\PycharmProjects\weatherInstrument\2022neimengdata\气体分析仪\2022-08-13"
|
|
|
|
MeteorologicalStation_folderPath = r"D:\PycharmProjects\weatherInstrument\2022neimengdata\气象站\2022_08_13"
|
|
|
|
tmp1 = GasAnalyzer(GasAnalyzer_folderPath)
|
|
tmp1.read_data()
|
|
|
|
tmp2 = MeteorologicalStation(MeteorologicalStation_folderPath)
|
|
tmp2.read_data()
|
|
|
|
print("completed!!")
|