Skip to content

Commit

Permalink
Add brain hierarchy root parameter.
Browse files Browse the repository at this point in the history
  • Loading branch information
drodarie committed Feb 6, 2024
1 parent 3c429d7 commit b156c96
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
8 changes: 4 additions & 4 deletions atlas_densities/app/cell_densities.py
Original file line number Diff line number Diff line change
Expand Up @@ -742,7 +742,7 @@ def measurements_to_average_densities(
"--region-name",
type=str,
default="root",
help="Name of the region in the hierarchy",
help="Name of the root region in the hierarchy",
)
@click.option(
"--neuron-density-path",
Expand Down Expand Up @@ -912,8 +912,8 @@ def fit_average_densities(
L.info("Loading average densities dataframe ...")
average_densities_df = pd.read_csv(average_densities_path)
homogenous_regions_df = pd.read_csv(homogenous_regions_path)
remove_unknown_regions(average_densities_df, region_map, annotation.raw)
remove_unknown_regions(homogenous_regions_df, region_map, annotation.raw)
remove_unknown_regions(average_densities_df, region_map, annotation.raw, root=region_name)
remove_unknown_regions(homogenous_regions_df, region_map, annotation.raw, root=region_name)

L.info("Fitting of average densities: started")
fitted_densities_df, fitting_maps = linear_fitting(
Expand Down Expand Up @@ -945,7 +945,7 @@ def fit_average_densities(
"--region-name",
type=str,
default="root",
help="Name of the region in the hierarchy",
help="Name of the root region in the hierarchy",
)
@click.option(
"--neuron-density-path",
Expand Down
12 changes: 8 additions & 4 deletions atlas_densities/densities/measurement_to_density.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,10 @@ def cell_count_per_slice_to_density(


def remove_unknown_regions(
measurements: "pd.DataFrame", region_map: RegionMap, annotation: AnnotationT
measurements: "pd.DataFrame",
region_map: RegionMap,
annotation: AnnotationT,
root: str = "root",
):
"""
Drop lines from the measurements dataframe which brain regions are not in the AIBS brain region
Expand All @@ -271,8 +274,9 @@ def remove_unknown_regions(
region_map: RegionMap object to navigate the brain regions hierarchy.
annotation: int array of shape (W, H, D) holding the annotation of the whole AIBS
mouse brain. (The integers W, H and D are the dimensions of the array).
root: name of the root region to consider in the hierarchy.
"""
hierarchy_info = get_hierarchy_info(region_map)
hierarchy_info = get_hierarchy_info(region_map, root)
pd.set_option("display.max_colwidth", None)
indices_ids = measurements.index[
~measurements["brain_region"].isin(hierarchy_info["brain_region"])
Expand All @@ -284,7 +288,7 @@ def remove_unknown_regions(
f"{measurements.loc[indices_ids, 'brain_region'].to_string()}",
AtlasDensitiesWarning,
)
measurements.drop(indices_ids, inplace=True)
measurements.drop(indices_ids, inplace=True)

u_regions = np.unique(annotation)
u_regions = np.delete(u_regions, 0) # don't take 0, i.e: outside of the brain
Expand All @@ -302,7 +306,7 @@ def remove_unknown_regions(
f"annotation volume: \n{measurements.loc[indices_ann, 'brain_region'].to_string()}",
AtlasDensitiesWarning,
)
measurements.drop(indices_ann, inplace=True)
measurements.drop(indices_ann, inplace=True)


def measurement_to_average_density(
Expand Down
4 changes: 3 additions & 1 deletion tests/densities/test_measurement_to_density.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ def test_remove_unknown_regions(region_map, annotations):
"source_title": ["Article 1", "Article 2", "Article 1"],
}
)
tested.remove_unknown_regions(measurements, region_map, annotations)
tested.remove_unknown_regions(
measurements, region_map, annotations, root="Basic cell groups and regions"
)
expected = pd.DataFrame(
{
"brain_region": [
Expand Down

0 comments on commit b156c96

Please sign in to comment.