Commit d5b86bb4 authored by Cecilia Nievas's avatar Cecilia Nievas
Browse files

Fixed bug in transform_dict_into_dataframe when sum in row is zero

parent aab93a84
......@@ -775,9 +775,17 @@ def transform_dict_into_dataframe(dict_of_subclasses, bdg_classes):
collect_values[b,col]= dict_of_subclasses[bdgclass]['Proportions'][which[0]]
elif len(which)>1:
print('ERROR!! SOMETHING WENT WRONG IN transform_dict_into_dataframe, length='+str(len(which)))
if np.any(np.logical_or(collect_values.sum(axis=1)>1.0001,collect_values.sum(axis=1)<0.9999)):
print('WARNING IN transform_dict_into_dataframe: THE SUM PER ROW IS NOT 1.0 IN AT LEAST ONE ROW!!!')
errors_found= True
sum_per_row = collect_values.sum(axis=1)
for row in range(0,collect_values.shape[0]):
# The row does not add up to 1 but it also does not add up to zero (measured as < 1E-5):
if np.logical_or(sum_per_row[row] > 1.0001, sum_per_row[row] < 0.9999) and (sum_per_row[row] < 1E-5):
print('WARNING IN transform_dict_into_dataframe: THE SUM PER ROW IS NOT 1.0 IN AT LEAST ONE ROW!!!')
errors_found= True
elif sum_per_row[row] < 1E-5:
# If the row sums up to zero (because there are zero buildings in these admin units), replace the
# zeroes with a uniform distribution:
collect_values[row, :] = (1.0/float(len(unique_involved_ids))) * np.ones([len(unique_involved_ids)])
return bdg_classes, unique_involved_ids, collect_values, errors_found
......
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