Skip to content

Commit

Permalink
use array.sum() instead of sum(array)
Browse files Browse the repository at this point in the history
  • Loading branch information
d-v-b committed Aug 15, 2024
1 parent a5f2241 commit f6154ff
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/cellmap_schemas/annotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,18 +273,21 @@ def from_array(
complement_counts: None | dict[Possibility, int] | Literal["auto"],
) -> Self:
if complement_counts == "auto":
num_unknown = sum(array == annotation_type.encoding["unknown"])
num_absent = sum(array == annotation_type.encoding["absent"])
num_unknown = (array == annotation_type.encoding["unknown"]).sum()
num_absent = (array == annotation_type.encoding["absent"]).sum()
num_present = array.size - (num_unknown + num_absent)

if isinstance(annotation_type, SemanticSegmentation):
complement_counts_parsed = {"unknown": num_unknown, "absent": num_absent}
elif isinstance(annotation_type, InstanceSegmentation):
complement_counts_parsed = {
"unknown": num_unknown,
"absent": num_absent,
"present": num_present,
}
elif isinstance(annotation_type, InstanceSegmentation):
complement_counts_parsed = {
"unknown": num_unknown,
"absent": num_absent,
}
else:
complement_counts_parsed = complement_counts

Expand Down Expand Up @@ -406,7 +409,7 @@ def from_array_infer_attrs(
array, class_name, annotation_type, complement_counts
)
annotation_attrs_wrapped = wrap_attributes(annotation_attrs)
return super().from_array(array, attributes=annotation_attrs_wrapped, **kwargs)
return super().from_array(array, attributes=annotation_attrs_wrapped.model_dump(), **kwargs)


class AnnotationGroup(GroupSpec):
Expand Down

0 comments on commit f6154ff

Please sign in to comment.