Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Dynamic Exposure
Legacy
gde_calculations_prototype
Commits
d5b86bb4
Commit
d5b86bb4
authored
Jul 07, 2021
by
Cecilia Nievas
Browse files
Fixed bug in transform_dict_into_dataframe when sum in row is zero
parent
aab93a84
Changes
1
Hide whitespace changes
Inline
Side-by-side
GDE_TOOLS_read_SERA.py
View file @
d5b86bb4
...
...
@@ -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
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment