Skip to content

Commit

Permalink
Output as df
Browse files Browse the repository at this point in the history
Signed-off-by: aapozd <[email protected]>
  • Loading branch information
aaletov committed May 25, 2024
1 parent e0676dc commit 58e3fe9
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions open_pcc_metric/metric.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import typing
import abc
import numpy as np
import pandas as pd
import open3d as o3d

# Metrics to calculate:
Expand Down Expand Up @@ -149,7 +150,7 @@ def _get_existing(cls, **kwargs) -> typing.Optional['AbstractMetric']:
return None

def _key(self) -> str:
return "{label}"
return self.label

def __str__(self) -> str:
return "{key}: {value}".format(key=self._key(), value=str(self.value))
Expand Down Expand Up @@ -327,6 +328,7 @@ def calculate(
)
if not dists.is_calculated:
dists.calculate(cloud_pair)

n = dists.value.shape[0]
sse = np.sum(dists.value, axis=0)
self.value = sse / n
Expand Down Expand Up @@ -524,8 +526,31 @@ def as_dict(self) -> typing.Dict[str, typing.Any]:
d[metric._key()] = metric.value
return d

def as_df(self) -> pd.DataFrame:
# metrics = [str(metric) for metric in self._metrics]
metric_dict = {
"label": [],
"is_left": [],
"point-to-plane": [],
"value": [],
}

for metric in self._metrics:
metric_dict["label"].append(metric.label)
is_left = ""
if hasattr(metric, "is_left"):
is_left = metric.is_left
metric_dict["is_left"].append(is_left)
point_to_plane = ""
if hasattr(metric, "point_to_plane"):
point_to_plane = metric.point_to_plane
metric_dict["point-to-plane"].append(point_to_plane)
metric_dict["value"].append(str(metric.value))

return pd.DataFrame(metric_dict)

def __str__(self) -> str:
return "\n".join([str(metric) for metric in self._metrics])
return str(self.as_df())

class MetricCalculator:
def calculate(
Expand Down

0 comments on commit 58e3fe9

Please sign in to comment.