Commit f6dea406 authored by Thomas Vincent's avatar Thomas Vincent

Perform division while ignoring division by zero warnings

parent 7e7f49be
......@@ -85,26 +85,25 @@ def project(data, hits=None):
:rtype: List[numpy.ndarray]
"""
if hits is not None:
with warnings.catch_warnings():
warnings.simplefilter('ignore', RuntimeWarning)
tmp = hits.sum(2)
hits0_sum = tmp.sum(1)
hits1_sum = tmp.sum(0)
hits2_sum = hits.sum((0,1))
hits2_sum = hits.sum((0, 1))
else:
hits0_sum = hits1_sum = hits2_sum = 1
tmp = data.sum(2)
dim0_sum = tmp.sum(1) / hits0_sum
dim1_sum = tmp.sum(0) / hits1_sum
dim2_sum = data.sum((0,1)) / hits2_sum
with warnings.catch_warnings():
warnings.simplefilter('ignore', RuntimeWarning)
dim0_sum = tmp.sum(1) / hits0_sum
dim1_sum = tmp.sum(0) / hits1_sum
dim2_sum = data.sum((0, 1)) / hits2_sum
# to get smth that resembles the sum rather than the mean,
# one can here multiply element wise by the summed 2D area
if hits is not None:
dim0_sum[hits0_sum<=0] = 0
dim1_sum[hits1_sum<=0] = 0
dim2_sum[hits2_sum<=0] = 0
dim0_sum[hits0_sum <= 0] = 0
dim1_sum[hits1_sum <= 0] = 0
dim2_sum[hits2_sum <= 0] = 0
return dim0_sum, dim1_sum, dim2_sum
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment