Skip to content
Snippets Groups Projects
Commit cb2263d8 authored by Sharon Yates's avatar Sharon Yates
Browse files

Whole series - add area_fraction and sort by idx in label file

Slice reports and whole series reports now correct
parent a4f77df0
No related branches found
No related tags found
No related merge requests found
...@@ -232,14 +232,15 @@ class PyNutil: ...@@ -232,14 +232,15 @@ class PyNutil:
#(left means use only keys from left frame, preserve key order) #(left means use only keys from left frame, preserve key order)
""" """
current_df = ra.merge(current_df, on='idx', how='left') Merge region areas and object areas onto the atlas label file.
current_df_new = current_df.merge(self.atlas_labels, on= 'idx', how='left') Remove duplicate columns
Calculate and add area_fraction to new column in the df.
""" """
all_region_df = self.atlas_labels.merge(ra, on = 'idx', how='left')
all_region_df = self.atlas_labels.merge(ra, on = 'idx', how='left')
current_df_new = all_region_df.merge(current_df, on= 'idx', how= 'left', suffixes= (None,"_y")).drop(columns=["a","VIS", "MSH", "name_y","r_y","g_y","b_y"]) current_df_new = all_region_df.merge(current_df, on= 'idx', how= 'left', suffixes= (None,"_y")).drop(columns=["a","VIS", "MSH", "name_y","r_y","g_y","b_y"])
current_df_new["area_fraction"] = current_df_new["pixel_count"] / current_df_new["region_area"] current_df_new["area_fraction"] = current_df_new["pixel_count"] / current_df_new["region_area"]
# Several alternatives for the merge code above
""" """
new_rows = [] new_rows = []
for index, row in all_region_df.iterrows(): for index, row in all_region_df.iterrows():
...@@ -256,8 +257,6 @@ class PyNutil: ...@@ -256,8 +257,6 @@ class PyNutil:
current_df_new = pd.DataFrame(new_rows) current_df_new = pd.DataFrame(new_rows)
""" """
""" """
new_rows = [] new_rows = []
for index, row in current_df.iterrows(): for index, row in current_df.iterrows():
...@@ -283,10 +282,19 @@ class PyNutil: ...@@ -283,10 +282,19 @@ class PyNutil:
prev_cl += cl prev_cl += cl
##Sharon. and then here you should group on r,g,b,idx, and name since you dont want any of these summed ##combine all the slice reports, groupby idx, name, rgb and sum region and object pixels. Remove area_fraction column and recalculate.
#Currently, it takes sum of area_fraction. This is incorrect. self.label_df = pd.concat(per_section_df).groupby(['idx','name','r','g','b']).sum().reset_index().drop(columns=['area_fraction'])
self.label_df = pd.concat(per_section_df).groupby(['idx','name','r','g','b']).sum().reset_index() self.label_df["area_fraction"] = self.label_df["pixel_count"] / self.label_df["region_area"]
#self.label_df = pd.concat(per_section_df).groupby(['idx','name','r','g','b']).sum().reset_index()
"""
Potential source of error:
If there are duplicates in the label file, regional results will be duplicated and summed leading to incorrect results
"""
#reorder the df to match the order of idx column in self.atlas_labels
self.label_df = self.label_df.set_index('idx')
self.label_df = self.label_df.reindex(index=self.atlas_labels['idx'])
self.label_df = self.label_df.reset_index()
self.labeled_points = labeled_points self.labeled_points = labeled_points
self.labeled_points_centroids = labeled_points_centroids self.labeled_points_centroids = labeled_points_centroids
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment