import matplotlib.pyplot as plt
import numpy.linalg as LA
import scipy.io as scio
import numpy as np
import xlrd
import os,time,sys
import warnings
warnings.filterwarnings('ignore')
from feature_extraction import get_xlsxlist,print_progress,sample_num,feature_extr
def get_xlsxlist(xlsx_path, mode):return [os.path.join(xlsx_path, f) for f in os.listdir(xlsx_path) if f.endswith(mode)]
xlls = get_xlsxlist('./拖网/', 'xlsx')
NAME = xlls[:]
Name=NAME
L = []
for name in Name:excel_trawl = xlrd.open_workbook(name)sheet = excel_trawl.sheet_by_index(0)x = sheet.col_values(1)[1:]L.append(len(x))
S = np.array(L, dtype=np.float32)
num_bin = 100
max_speed = 25
len(Name)
start_time = time.time()
gill_net_sample, speed_feature_g = feature_extr(Name)
end_time = time.time()
def feature_extr(NAME_list, feature_dim=1000, feature_speed=100, max_speed=25):print('Start to extract the features:')init_m = np.zeros(feature_dim) init_n = np.zeros(feature_speed) for num, name in enumerate(Name):max_num = len(Name)print_progress(num + 1, max_num)excel_trawl = xlrd.open_workbook(name)sheet = excel_trawl.sheet_by_index(0)x = sheet.col_values(1)[1:]y = sheet.col_values(2)[1:]data_position = np.vstack([np.array(x).reshape(1, -1), np.array(y).reshape(1, -1)])data_cov = np.cov(data_position)w, v = LA.eig(data_cov)data_pca = np.dot(v[:, 0].T, data_position).flatten()sample_data = sample_num(data_pca, 1000)init_m = np.vstack([init_m, sample_data]) z = sheet.col_values(3)[1:]z_lim = [i for i in z if i <= max_speed] fig, ax = plt.subplots(nrows=1, ncols=1, figsize=(8, 6))n, bins, patches = plt.hist(z_lim, 100, normed=True, rwidth=0.8)n, bins = np.histogram(z_lim, num_bin, normed=True)init_n = np.vstack([init_n, n]) gill_net_sample = init_m[1:] speed_feature = init_n[1:]speed_feature_g = speed_feature / speed_feature.max() print('Feature extraction completed.')return (gill_net_sample, speed_feature_g)
本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!