From 7973cedaae9a95936dff6450649b958138f9a8d1 Mon Sep 17 00:00:00 2001 From: Csaba Date: Fri, 8 Sep 2023 17:30:05 +0200 Subject: [PATCH] Leaf region will only trigger if the region exists --- ...nhibitory_neuron_densities_optimization.py | 28 +++++++++++++++---- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/atlas_densities/densities/inhibitory_neuron_densities_optimization.py b/atlas_densities/densities/inhibitory_neuron_densities_optimization.py index 450a3f9..8b13037 100644 --- a/atlas_densities/densities/inhibitory_neuron_densities_optimization.py +++ b/atlas_densities/densities/inhibitory_neuron_densities_optimization.py @@ -491,11 +491,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]) & + (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( + f"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} " + f"is not certain. Cell count estimate for this region is thus set " + f"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 " + ) neuron_count = neuron_counts.loc[id_, "cell_count"] if ( not np.isnan(x_result.loc[id_, cell_type])