def generate_csv_contrast(self, data_set, x_standard, f_standard): loadfile = load.LoadData(self.filepath) file = loadfile.read_csv() maxlength = len(file) pre = osp.splitext(osp.basename(self.filepath))[0] f_max = max(np.array(file)[:, 1]) print(pre + ' start, max_f = ' + str(f_max)) # split cnt = 0 idx = 0 while maxlength - 200 * cnt > 0: temp = file[idx:idx + 200] data = np.array(temp) x = data[:, 0] f = data[:, 1] idx += 200 cnt += 1 name = pre + '-' + str(cnt) + '.png' if util.zero_data(x, f): continue if name in data_set: x_add, f_add = normalization_each_device(x, f, f_max, False) # standard_name = standard.replace('.png') save_path = 'image2\\plus\\' + pre + '-' + str(cnt) + 'vs.png' process_contrast(x_add, f_add, x_standard, f_standard, save_path)
def generate_excel_map(self, content_list): loadfile = load.LoadData(self.filepath) data = loadfile.read_excel() pre = osp.splitext(osp.basename(self.filepath))[0] for cnt in range(len(data)): # for cnt in range(2): # skip exception if util.nan_data(data[cnt, 0]) | util.nan_data(data[cnt, 1]): continue x = data[cnt, 0].split(',') f = data[cnt, 1].split(',') if not util.match_data(x, f): continue x_array = np.array(x, dtype=float) f_array = np.array(f, dtype=float) if util.zero_data(x_array, f_array): continue # normalization_max x_new, f_new = normalization_each_image(x_array, f_array) image_dict = { "image_name": pre + '-' + str(cnt) + '.png', "x": ','.join( str(x_new.tolist()).replace(']', '').replace('[', '').split(',')), "f": ','.join( str(f_new.tolist()).replace(']', '').replace('[', '').split(',')) } content_list.append(image_dict)
def generate_csv_with_axis(self, base_path): loadfile = load.LoadData(self.filepath) file = loadfile.read_csv() maxlength = len(file) exception_zero = 0 pre = osp.splitext(osp.basename(self.filepath))[0] f_max = max(np.array(file)[:, 1]) print(pre + ' start, max_f = ' + str(f_max)) # split cnt = 0 idx = 0 # image_cnt = 0 while maxlength - 200 * cnt > 0: temp = file[idx:idx + 200] data = np.array(temp) x = data[:, 0] f = data[:, 1] idx += 200 cnt += 1 if cnt == 3: if util.zero_data(x, f): exception_zero += 1 continue # x_new = np.empty([200, 1], dtype=int) # f_new = np.empty([200, 1], dtype=int) # for i in range(200): # x_new[i] = int(x[i]) # f_new[i] = int(f[i]) save_path = osp.join(base_path, pre + '-' + str(cnt) + '.png') process_with_axis(x, f, save_path, f_max)
def generate_csv(self, base_path): loadfile = load.LoadData(self.filepath) file = loadfile.read_csv() maxlength = len(file) exception_zero = 0 pre = osp.splitext(osp.basename(self.filepath))[0] f_max = max(np.array(file)[:, 1]) print(pre + ' start, max_f = ' + str(f_max)) # split cnt = 0 idx = 0 # image_cnt = 0 while maxlength - 200 * cnt > 0: # while cnt < 5: temp = file[idx:idx + 200] data = np.array(temp) x = data[:, 0] f = data[:, 1] idx += 200 cnt += 1 # skip exception if util.zero_data(x, f): exception_zero += 1 # print(pre + '-' + str(cnt) + ':zero') continue # normalization_max # x_new, f_new = self.normalization_each_image(x, f) # normalization_100 x_new, f_new = normalization_each_device(x, f, f_max, False) # draw and save save_path = osp.join(base_path, pre + '-' + str(cnt) + '.png') process(x_new, f_new, save_path)
def augmentation_csv(filepath, data_set, num, base_path): loadfile = load.LoadData(filepath) file = loadfile.read_csv() maxlength = len(file) pre = osp.splitext(osp.basename(filepath))[0] f_max = max(np.array(file)[:, 1]) print(pre + ' start, max_f = ' + str(f_max)) # split cnt = 0 idx = 0 while maxlength - 200 * cnt > 0: # while cnt < 5: temp = file[idx:idx + 200] data = np.array(temp) x = data[:, 0] f = data[:, 1] idx += 200 cnt += 1 name = pre + '-' + str(cnt) + '.png' if util.zero_data(x, f): continue if name in data_set: # print(name) for k in range(num): x_add, f_add = normalization_each_device(x, f, f_max, True) add_path = osp.join( base_path, pre + '-' + str(cnt) + '-' + str(k) + '.png') process(x_add, f_add, add_path)
def generate_csv_map(self, content_list): loadfile = load.LoadData(self.filepath) file = loadfile.read_csv() maxlength = len(file) exception_zero = 0 pre = osp.splitext(osp.basename(self.filepath))[0] f_max = max(np.array(file)[:, 1]) print(pre + ' start, max_f = ' + str(f_max)) # split cnt = 0 idx = 0 while maxlength - 200 * cnt > 0: # while cnt < 5: image_name = pre + '-' + str(cnt) + '.png' temp = file[idx:idx + 200] data = np.array(temp) x = data[:, 0] f = data[:, 1] idx += 200 cnt += 1 # skip exception if util.zero_data(x, f): exception_zero += 1 print(pre + '-' + str(cnt) + ':zero') continue # normalization_max # x_new, f_new = self.normalization_each_image(x, f) # normalization_100 x_new, f_new = normalization_each_device(x, f, f_max, False) image_dict = { "image_name": pre + '-' + str(cnt) + '.png', "x": ','.join( str(x_new.tolist()).replace(']', '').replace('[', '').split(',')), "f": ','.join( str(f_new.tolist()).replace(']', '').replace('[', '').split(',')) } content_list.append(image_dict)
def get_standard_excel(self, standard): loadfile = load.LoadData(self.filepath) data = loadfile.read_excel() pre = osp.splitext(osp.basename(self.filepath))[0] for cnt in range(len(data)): # skip exception if util.nan_data(data[cnt, 0]) | util.nan_data(data[cnt, 1]): continue x = data[cnt, 0].split(',') f = data[cnt, 1].split(',') if not util.match_data(x, f): continue x_array = np.array(x, dtype=float) f_array = np.array(f, dtype=float) if util.zero_data(x_array, f_array): continue name = pre + '-' + str(cnt) + '.png' if name == standard: x_standard, f_standard = normalization_each_image( x_array, f_array) return x_standard, f_standard
def generate_excel(self, base_path): loadfile = load.LoadData(self.filepath) data = loadfile.read_excel() exception_not_match = 0 exception_null = 0 exception_zero = 0 pre = osp.splitext(osp.basename(self.filepath))[0] image_cnt = 0 for cnt in range(len(data)): # for cnt in range(2): # skip exception if util.nan_data(data[cnt, 0]) | util.nan_data(data[cnt, 1]): exception_null += 1 print(pre + '-' + str(cnt) + ':null') continue x = data[cnt, 0].split(',') f = data[cnt, 1].split(',') if not util.match_data(x, f): exception_not_match += 1 print(pre + '-' + str(cnt) + ':not match, x has ' + str(len(x)) + 'points and f has ' + str(len(f)) + 'points') continue x_array = np.array(x, dtype=float) f_array = np.array(f, dtype=float) if util.zero_data(x_array, f_array): exception_zero += 1 print(pre + '-' + str(cnt) + ':zero') continue # normalization_max x_new, f_new = normalization_each_image(x_array, f_array) # normalization_100 # x_new, f_new = self.normalization_each_device(x_array, f_array, 1000, False) # draw and save save_path = osp.join(base_path, pre + '-' + str(cnt) + '.png') process(x_new, f_new, save_path) image_cnt += 1 print(pre + ' num = ' + str(exception_not_match) + ' ; ' + str(exception_null) + ' ; ' + str(exception_zero) + ' ; ' + str(image_cnt))
def generate_excel_contrast(self, data_set, x_standard, f_standard): loadfile = load.LoadData(self.filepath) data = loadfile.read_excel() pre = osp.splitext(osp.basename(self.filepath))[0] for cnt in range(len(data)): # skip exception if util.nan_data(data[cnt, 0]) | util.nan_data(data[cnt, 1]): continue x = data[cnt, 0].split(',') f = data[cnt, 1].split(',') if not util.match_data(x, f): continue x_array = np.array(x, dtype=float) f_array = np.array(f, dtype=float) if util.zero_data(x_array, f_array): continue name = pre + '-' + str(cnt) + '.png' if name in data_set: x_new, f_new = normalization_each_image(x_array, f_array) # standard_name = standard.replace('.png') save_path = 'image2\\plus\\' + pre + '-' + str(cnt) + 'vs.png' process_contrast(x_new, f_new, x_standard, f_standard, save_path)
def get_standard_csv(self, standard): loadfile = load.LoadData(self.filepath) file = loadfile.read_csv() maxlength = len(file) pre = osp.splitext(osp.basename(self.filepath))[0] f_max = max(np.array(file)[:, 1]) # print('standard image source is' + pre + ', max_f is ' + str(f_max)) # split cnt = 0 idx = 0 while maxlength - 200 * cnt > 0: temp = file[idx:idx + 200] data = np.array(temp) x = data[:, 0] f = data[:, 1] idx += 200 cnt += 1 name = pre + '-' + str(cnt) + '.png' if util.zero_data(x, f): continue if name == standard: x_standard, f_standard = normalization_each_device( x, f, f_max, False) return x_standard, f_standard