Skip to content

Commit

Permalink
swapped dashes to underscores in my additions to skan df
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxGamill-Sheffield committed Sep 16, 2024
1 parent a98c65e commit a72f9a7
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions topostats/tracing/disordered_tracing.py
Original file line number Diff line number Diff line change
Expand Up @@ -401,9 +401,9 @@ def compile_skan_stats(
skan_df["image"] = filename
skan_df["grain_number"] = grain_number
skan_df["connected_segments"] = skan_df.apply(find_connections, axis=1, skan_df=skan_df)
skan_df["min-value"] = skan_df.apply(lambda x: segment_heights(x, skan_skeleton, image).min(), axis=1)
skan_df["median-value"] = skan_df.apply(lambda x: np.median(segment_heights(x, skan_skeleton, image)), axis=1)
skan_df["mid-value"] = skan_df.apply(segment_middles, skan_skeleton=skan_skeleton, image=image, axis=1)
skan_df["min_value"] = skan_df.apply(lambda x: segment_heights(x, skan_skeleton, image).min(), axis=1)
skan_df["median_value"] = skan_df.apply(lambda x: np.median(segment_heights(x, skan_skeleton, image)), axis=1)
skan_df["mid_value"] = skan_df.apply(segment_middles, skan_skeleton=skan_skeleton, image=image, axis=1)

# remove unused skan columns
return skan_df[
Expand All @@ -415,9 +415,9 @@ def compile_skan_stats(
"connected_segments",
"mean-pixel-value",
"stdev-pixel-value",
"min-value",
"median-value",
"mid-value",
"min_value",
"median_value",
"mid_value",
]
]

Expand Down

1 comment on commit a72f9a7

@ns-rse
Copy link
Collaborator

@ns-rse ns-rse commented on a72f9a7 Sep 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is something I dealt with upstream in skan (see pull request) about a year ago and will ultimately be in new release is made as its already in the main branch, although here the names are explicitly declared for skan_df rather than coming from the output of skan so these changes would have been needed anyway.

The reason for avoiding - in Pandas data frames is it means you can't use the "dot notation" to refer to columns of the data frame as they interpreted as a subtraction^[1]. Thus if you have a DataFrame df with columns a, a-1, a-2 you can not use df.a-1 to get the array. If you use a, a_1, a_2 as the column names you can use df.a_1 to get the array/column.

^[1]: Personally I prefer the bracket notation but Skan used dot notation and it was easier/more general to use _ rather than - as it was felt it would cause less problems upstream.

Please sign in to comment.