Skip to content
Snippets Groups Projects
Commit 56aa8455 authored by Nuno Pimpão Santos Martins's avatar Nuno Pimpão Santos Martins
Browse files

script to concatenate iou metrics

parent 60014bc1
No related branches found
No related tags found
No related merge requests found
# -*- coding: utf-8 -*-
import os
import csv
from pathlib import Path
import numpy as np
import datetime
from tqdm import tqdm
def list_find(array, substr):
index = -1
for i in range(len(array)):
if array[i].find(substr) >= 0:
index = i
return index
data_dir = 'w:\\NPC_adult_new\\quantification_data\\iou_quantification\\'
dir_list = os.listdir(data_dir)
dir_list.sort()
dir_list = [x for x in dir_list if os.path.isdir(os.path.join(data_dir, x)) == True]
print("Nb of subdirs in path: ", len(dir_list))
conditions = ['fcenettoinput', 'dlbiasfreetoinput']
for i in range(len(dir_list)-1,0, -1):
# print(dir_list[i])
item_name = dir_list[i][4:dir_list[i].index('_')]
# print(item_name)
if list_find(conditions, item_name) == -1:
dir_list.pop(i)
# print(dir_list)
# stop
for folder in tqdm(dir_list):
condition = folder[4:folder.index('_2023')]
data_path = data_dir+folder
# print(data_path)
file_list = os.listdir(data_path)
# print(len(file_list))
file_list = [name for name in file_list if name.find('.csv') > 0]
# print(len(file_list))
outdata = []
for filename in file_list:
name_no_ext = condition+'_'+filename[filename.index('metrics_')+8:filename.index('_ch')]
data_file = []
with open(os.path.join(data_path, filename), 'r') as infile:
reader = csv.reader(infile)
for line in reader:
try:
zindex_check = float(line[0]) # to remove header line from being passed
pci_check = float(line[1]) # to remove outlier lines where PCI is inf, result of dividing by zero
# removes outliers, last line column is empty space
if pci_check != np.Inf:
data_file.append(line)
except:
continue
# if line[0] == str(15):
# data_file.append(line)
# if line[0] == str(135):
# data_file.append(line)
# if line[0] == str(281):
# data_file.append(line)
for i in range(len(data_file)):
data_file[i].insert(0, condition)
#data_file[i][0] = name_no_ext + '_'+ data_file[i][0]
real_z = str((len(data_file)+1) - float(data_file[i][1]))
data_file[i].insert(2, real_z)
position = ''
if data_file[i][1] == '15':
position = 'Deep'
elif data_file[i][1] == '135':
position = 'Intermediate'
elif data_file[i][1] == '281':
position = 'Surface'
else:
position = 'Undefined'
data_file[i][-1] = position
data_file[i].insert(1, name_no_ext) # I don't like this insertion here
outdata.append(data_file[i])
path = Path(data_path)
parent_path = str(path.parent.absolute())
today_date = str(datetime.date.today())
table_save_name = condition+'_iou_metrics_%s.csv' % today_date
with open(os.path.join(parent_path, table_save_name), 'w') as outfile:
outfile.write('Condition,Name,Z,Real Z,iou x1,thresh x1,iou x2,trehs x2,iou x3,thresh x3,\n')
for item in outdata:
line = ''
for cell in item:
line += cell+','
outfile.write(line+'\n')
outfile.close()
# print('Done')
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment