Skip to content

Commit

Permalink
fix: #1632 filter features before adding new ones in extract_tile_sha…
Browse files Browse the repository at this point in the history
…pe_features
  • Loading branch information
raylim committed Oct 16, 2023
1 parent 4e9e24e commit f4c673d
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions src/luna/pathology/cli/extract_tile_shape_features.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,11 +294,22 @@ def extract_tile_shape_features(
agg_funs = STATISTICAL_DESCRIPTOR_MAP[statistical_descriptors]
agg_df = gb.agg(agg_funs)
agg_df.columns = [" ".join(col).strip() for col in agg_df.columns.values]
agg_df["Object Counts"] = gb.size()

agg_df["Normalized Cell Density"] = agg_df["Object Counts"] / slide_area
cell_density = None
if "Cell: Area µm^2 sum" in agg_df.columns:
agg_df["Cell Density"] = agg_df["Cell: Area µm^2 sum"] / (slide_area / 4)
cell_density = agg_df["Cell: Area µm^2 sum"] / (slide_area / 4)

if cellular_features != CellularFeatures.ALL:
agg_df = agg_df.filter(regex=cellular_features)

if property_type != PropertyType.ALL:
property_types = PROPERTY_TYPE_MAP[property_type]
agg_df = agg_df.filter(regex="|".join(property_types))

agg_df["Object Counts"] = gb.size()
agg_df["Normalized Cell Density"] = agg_df["Object Counts"] / slide_area
if cell_density is not None:
agg_df["Cell Density"] = cell_density

logger.info(
"Calculating obj count log ratios between all tile label obj classification groups"
Expand All @@ -320,13 +331,6 @@ def extract_tile_shape_features(
index=agg_df.index[idx0],
)

if cellular_features != CellularFeatures.ALL:
agg_df = agg_df.filter(regex=cellular_features)

if property_type != PropertyType.ALL:
property_types = PROPERTY_TYPE_MAP[property_type]
agg_df = agg_df.filter(regex="|".join(property_types))

mdf = pd.melt(agg_df.reset_index(), id_vars=["Parent", "Class"]).dropna()
mdf = pd.concat([mdf, ratio_df.reset_index(), shape_features_df, entropy_df])

Expand Down

0 comments on commit f4c673d

Please sign in to comment.