55import pandas as pd
66import napari
77
8+ from skimage .measure import label
9+
810from tqdm import tqdm
911
1012val_table = "/home/pape/Desktop/sfb1286/mboc_synapse/qualitative-stem-eval.xlsx"
1113val_table = pd .read_excel (val_table )
1214
1315
16+ def _get_n_azs (path ):
17+ access = np .s_ [::2 , ::2 , ::2 ]
18+ with h5py .File (path , "r" ) as f :
19+ az = f ["labels/active_zone" ][access ]
20+ az = label (az )
21+ ids , sizes = np .unique (az , return_counts = True )
22+ ids , sizes = ids [1 :], sizes [1 :]
23+ n_azs = np .sum (sizes > 10000 )
24+ return n_azs , n_azs
25+
26+
1427def eval_az ():
15- az_found = []
16- az_total = []
28+ azs_found = []
29+ azs_total = []
1730
18- # TODO for the "all" tomograms load the prediction, measure number components,
31+ # for the "all" tomograms load the prediction, measure number components,
1932 # size filter and count these as found and as total
20- for i , row in val_table .iterrows ():
21- pass
33+ for i , row in tqdm (val_table .iterrows (), total = len (val_table )):
34+ az_found = row ["AZ Found" ]
35+ if az_found == "all" :
36+ path = os .path .join ("04_full_reconstruction" , row .dataset , row .tomogram )
37+ assert os .path .exists (path )
38+ az_found , az_total = _get_n_azs (path )
39+ else :
40+ az_total = row ["AZ Total" ]
41+
42+ azs_found .append (az_found )
43+ azs_total .append (az_total )
2244
45+ n_found = np .sum (azs_found )
46+ n_azs = np .sum (azs_total )
2347
24- # TODO measure in how many pieces each compartment was split
48+ print ("AZ Evaluation:" )
49+ print ("Number of correctly identified AZs:" , n_found , "/" , n_azs , f"({ float (n_found )/ n_azs } %)" )
50+
51+
52+ # measure in how many pieces each compartment was split
2553def eval_compartments ():
26- pass
54+ pieces_per_compartment = []
55+ for i , row in val_table .iterrows ():
56+ for comp in [
57+ "Compartment 1" ,
58+ "Compartment 2" ,
59+ "Compartment 3" ,
60+ "Compartment 4" ,
61+ ]:
62+ n_pieces = row [comp ]
63+ if isinstance (n_pieces , str ):
64+ n_pieces = len (n_pieces .split ("," ))
65+ elif np .isnan (n_pieces ):
66+ continue
67+ else :
68+ assert isinstance (n_pieces , (float , int ))
69+ n_pieces = 1
70+ pieces_per_compartment .append (n_pieces )
71+
72+ avg = np .mean (pieces_per_compartment )
73+ std = np .std (pieces_per_compartment )
74+ max_ = np .max (pieces_per_compartment )
75+ print ("Compartment Evaluation:" )
76+ print ("Avergage pieces per compartment:" , avg , "+-" , std )
77+ print ("Max pieces per compartment:" , max_ )
2778
2879
2980def eval_mitos ():
3081 mito_correct = []
3182 mito_split = []
3283 mito_merged = []
3384 mito_total = []
34-
35- # TODO measure % of mito correct, mito split and mito merged
36- for i , row in val_table .iterrows ():
37- pass
85+ wrong_object = []
86+
87+ mito_table = val_table .fillna (0 )
88+ # measure % of mito correct, mito split and mito merged
89+ for i , row in mito_table .iterrows ():
90+ mito_correct .append (row ["Mito Correct" ])
91+ mito_split .append (row ["Mito Split" ])
92+ mito_merged .append (row ["Mito Merged" ])
93+ mito_total .append (row ["Mito Total" ])
94+ wrong_object .append (row ["Wrong Object" ])
95+
96+ n_mitos = np .sum (mito_total )
97+ n_correct = np .sum (mito_correct )
98+ print ("Mito Evaluation:" )
99+ print ("Number of correctly identified mitos:" , n_correct , "/" , n_mitos , f"({ float (n_correct )/ n_mitos } %)" )
100+ print ("Number of merged mitos:" , np .sum (mito_merged ))
101+ print ("Number of split mitos:" , np .sum (mito_split ))
102+ print ("Number of wrongly identified objects:" , np .sum (wrong_object ))
38103
39104
40105def check_mitos ():
@@ -57,7 +122,13 @@ def check_mitos():
57122
58123
59124def main ():
60- check_mitos ()
125+ # check_mitos()
126+
127+ eval_mitos ()
128+ print ()
129+ eval_compartments ()
130+ print ()
131+ eval_az ()
61132
62133
63134main ()
0 commit comments