Skip to content

Commit

Permalink
[WIP] Fix: Attempt to fix grain_number double index issue
Browse files Browse the repository at this point in the history
  • Loading branch information
SylviaWhittle committed Dec 10, 2024
1 parent 7781c86 commit 80b711c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
3 changes: 2 additions & 1 deletion topostats/grainstats.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,8 @@ def calculate_stats(self) -> tuple(pd.DataFrame, dict):
# Create a dataframe from the list of dictionaries
grainstats_df = pd.DataFrame(grainstats_rows)

grainstats_df.index.name = "grain_number"
# Change the index column from the arbitrary one to the grain number
grainstats_df.set_index("grain_number", inplace=True)
grainstats_df["image"] = self.image_name

return grainstats_df, all_height_profiles
Expand Down
3 changes: 2 additions & 1 deletion topostats/tracing/disordered_tracing.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,6 @@ def trace_image_disordered( # pylint: disable=too-many-arguments,too-many-local
conv_pruned_skeleton = convolve_skeleton(disordered_trace_images["pruned_skeleton"])
grainstats_additions[grain_number] = {
"image": filename,
"grain_number": grain_number,
"grain_endpoints": np.int64((conv_pruned_skeleton == 2).sum()),
"grain_junctions": np.int64((conv_pruned_skeleton == 3).sum()),
"total_branch_lengths": total_branch_length,
Expand All @@ -396,6 +395,8 @@ def trace_image_disordered( # pylint: disable=too-many-arguments,too-many-local

# convert stats dict to dataframe
grainstats_additions_df = pd.DataFrame.from_dict(grainstats_additions, orient="index")
# Set the name of the index column to be the grain number
grainstats_additions_df.index.name = "grain_number"

# return disordered_trace_crop_data, grainstats_additions_df, all_images, disordered_tracing_stats
return disordered_trace_crop_data, grainstats_additions_df, disordered_tracing_stats
Expand Down

0 comments on commit 80b711c

Please sign in to comment.