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

Leaf region will only trigger if the region exists #48

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,8 @@ def _check_variables_consistency(
AtlasDensitiesError if on the the following assumptions is violated:
- if cell count estimate of a region is known with certainty for a given cell type,
then the cell count of every descendant region is also known with certainty.
- a cell count estimate which is given for certain does not
- a neuron subtype count estimate which is given for certain is greater than
its total neuron count estimate counterpart.
"""
cell_count_tolerance = 1e-2 # absolute tolerance to rule out round-off errors
for region_name, id_, id_set in zip(
Expand All @@ -491,11 +492,29 @@ def _check_variables_consistency(
if np.isfinite(deltas.loc[region_name, cell_type]):
for desc_id in id_set:
if np.isnan(x_result.loc[desc_id, cell_type]):
raise AtlasDensitiesError(
f"Cell count estimate of region named '{region_name}' for cell type "
f"{cell_type} was given for certain whereas the cell count of "
f"descendant id {desc_id} is not certain."
)
if ((deltas.loc[region_name, cell_type] in [0.0, np.inf]) and
cveraszto marked this conversation as resolved.
Show resolved Hide resolved
(x_result.loc[id_, cell_type] == 0.0) or (np.isnan(x_result.loc[id_, cell_type]))
):
# If the region's cell count value was set to 0 because the region does
# not exist we don't have to raise an error. Instead of x_result
# volumes.loc[id_, 'volume'] == 0.0 would be a better condition..
deltas.loc[region_name, cell_type] = np.inf
x_result.loc[id_, cell_type] = np.nan
warnings.warn(
"Cell count estimate of region named "
f"'{region_name}' for cell type {cell_type} was given 0 for "
f"its volume is 0 whereas the cell count of descendant id {desc_id} "
"is not certain. Cell count estimate for this region is thus set "
"to np.nan to avoid inconsistency.",
AtlasDensitiesWarning,
)

else:
raise AtlasDensitiesError(
f"Cell count estimate of region named '{region_name}' for cell type "
f"{cell_type} was given for certain whereas the cell count of "
f"descendant id {desc_id} is not certain."
)
lecriste marked this conversation as resolved.
Show resolved Hide resolved
neuron_count = neuron_counts.loc[id_, "cell_count"]
if (
not np.isnan(x_result.loc[id_, cell_type])
Expand Down