Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Faster _compute_region_cell_counts #72

Merged
merged 3 commits into from
Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
from atlas_commons.typing import AnnotationT, FloatArray
from scipy.optimize import linprog
from tqdm import tqdm
from voxcell import RegionMap
from voxcell import RegionMap, voxel_data

from atlas_densities.densities import utils
from atlas_densities.densities.inhibitory_neuron_densities_helper import (
Expand Down Expand Up @@ -199,16 +199,18 @@ def _compute_region_cell_counts(
... ...
The index is the sorted list of all region identifiers.
"""
vtiv = voxel_data.ValueToIndexVoxels(annotation)
density = vtiv.ravel(density)

id_counts = []
for id_ in tqdm(hierarchy_info.index):
mask = annotation == id_
id_counts.append(np.sum(density[mask]) * voxel_volume)
for id_ in hierarchy_info.index:
indices = vtiv.value_to_1d_indices(id_)
id_counts.append(np.sum(density[indices]) * voxel_volume)

result = pd.DataFrame(
{"brain_region": hierarchy_info["brain_region"], "cell_count": id_counts},
index=hierarchy_info.index,
)

return result


Expand Down Expand Up @@ -736,17 +738,17 @@ def create_inhibitory_neuron_densities( # pylint: disable=too-many-locals
hierarchy_info = utils.get_hierarchy_info(RegionMap.from_dict(hierarchy), root=region_name)
average_densities = _resize_average_densities(average_densities, hierarchy_info)

L.info("Initialization of the linear program: started")
region_counts, id_counts = _compute_initial_cell_counts(
annotation, voxel_volume, average_densities, hierarchy_info
)

L.info("Retrieving overall neuron counts in atomic 3D regions ...")
neuron_counts = _compute_region_cell_counts(
annotation, neuron_density, voxel_volume, hierarchy_info
)
assert np.all(neuron_counts["cell_count"] >= 0.0)

L.info("Initialization of the linear program: started")
region_counts, id_counts = _compute_initial_cell_counts(
annotation, voxel_volume, average_densities, hierarchy_info
)

L.info("Setting the known values ...")
x_result, deltas = set_known_values(region_counts, id_counts, hierarchy_info)
# We assume that if the cell count of `cell_type` in `region_name` is known with certainty
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
# from the HiGHS library. We use the "highs" method in the densities module.
"scipy>=1.6.0",
"tqdm>=4.44.1",
"voxcell>=3.0.0",
"voxcell>=3.1.7",
],
extras_require={
"tests": [
Expand Down
Loading