Skip to content

Commit

Permalink
cleaned
Browse files Browse the repository at this point in the history
  • Loading branch information
sronilsson committed Apr 25, 2024
1 parent 501f4a5 commit 3bd67e1
Show file tree
Hide file tree
Showing 23 changed files with 3,429 additions and 1,102 deletions.
260 changes: 201 additions & 59 deletions simba/data_processors/directing_other_animals_calculator.py

Large diffs are not rendered by default.

28 changes: 22 additions & 6 deletions simba/mixins/config_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,12 @@ def read_roi_data(self) -> None:
source=self.__class__.__name__,
)
else:
self.rectangles_df = pd.read_hdf(self.roi_coordinates_path, key=Keys.ROI_RECTANGLES.value)
if ("Center_X" in self.rectangles_df.columns) and (self.rectangles_df["Center_X"].isnull().values.any()):
self.rectangles_df = pd.read_hdf(
self.roi_coordinates_path, key=Keys.ROI_RECTANGLES.value
)
if ("Center_X" in self.rectangles_df.columns) and (
self.rectangles_df["Center_X"].isnull().values.any()
):
for idx, row in self.rectangles_df.iterrows():
self.rectangles_df.loc[idx]["Center_X"] = row["Tags"]["Center tag"][
0
Expand Down Expand Up @@ -264,11 +268,23 @@ def read_roi_data(self) -> None:
self.roi_types_names_lst = list(self.roi_types_names_lst)
for shape_type, shape_data in self.roi_dict.items():
if shape_type == Keys.ROI_CIRCLES.value:
self.roi_dict[Keys.ROI_CIRCLES.value]["Center_X"] = self.roi_dict[ Keys.ROI_CIRCLES.value]["centerX"]
self.roi_dict[Keys.ROI_CIRCLES.value]["Center_Y"] = self.roi_dict[Keys.ROI_CIRCLES.value]["centerY"]
self.roi_dict[Keys.ROI_CIRCLES.value]["Center_X"] = self.roi_dict[
Keys.ROI_CIRCLES.value
]["centerX"]
self.roi_dict[Keys.ROI_CIRCLES.value]["Center_Y"] = self.roi_dict[
Keys.ROI_CIRCLES.value
]["centerY"]
elif shape_type == Keys.ROI_RECTANGLES.value:
self.roi_dict[Keys.ROI_RECTANGLES.value]["Center_X"] = self.roi_dict[Keys.ROI_RECTANGLES.value]["Bottom_right_X"] - (self.roi_dict[Keys.ROI_RECTANGLES.value]["width"] / 2)
self.roi_dict[Keys.ROI_RECTANGLES.value]["Center_Y"] = self.roi_dict[Keys.ROI_RECTANGLES.value]["Bottom_right_Y"] - (self.roi_dict[Keys.ROI_RECTANGLES.value]["height"] / 2)
self.roi_dict[Keys.ROI_RECTANGLES.value][
"Center_X"
] = self.roi_dict[Keys.ROI_RECTANGLES.value]["Bottom_right_X"] - (
self.roi_dict[Keys.ROI_RECTANGLES.value]["width"] / 2
)
self.roi_dict[Keys.ROI_RECTANGLES.value][
"Center_Y"
] = self.roi_dict[Keys.ROI_RECTANGLES.value]["Bottom_right_Y"] - (
self.roi_dict[Keys.ROI_RECTANGLES.value]["height"] / 2
)
elif shape_type == Keys.ROI_POLYGONS.value:
try:
self.roi_dict[Keys.ROI_POLYGONS.value]["Center_X"] = (
Expand Down
32 changes: 25 additions & 7 deletions simba/mixins/feature_extraction_supplement_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -740,14 +740,31 @@ def distance_and_velocity(
>>> sum_movement, avg_velocity = FeatureExtractionSupplemental.distance_and_velocity(x=x, fps=10, pixels_per_mm=10, centimeters=True)
"""

check_valid_array(data=x, source=FeatureExtractionSupplemental.distance_and_velocity.__name__, accepted_ndims=(1, 2), accepted_dtypes=(np.float32, np.float64, np.int32, np.int64, int, float))
check_float(name=f"{FeatureExtractionSupplemental.distance_and_velocity.__name__} fps",value=fps,min_value=1)
check_float(name=f"{FeatureExtractionSupplemental.distance_and_velocity.__name__} pixels_per_mm",value=pixels_per_mm,min_value=10e-6)
check_valid_array(
data=x,
source=FeatureExtractionSupplemental.distance_and_velocity.__name__,
accepted_ndims=(1, 2),
accepted_dtypes=(np.float32, np.float64, np.int32, np.int64, int, float),
)
check_float(
name=f"{FeatureExtractionSupplemental.distance_and_velocity.__name__} fps",
value=fps,
min_value=1,
)
check_float(
name=f"{FeatureExtractionSupplemental.distance_and_velocity.__name__} pixels_per_mm",
value=pixels_per_mm,
min_value=10e-6,
)
if x.ndim == 2:
check_valid_array(data=x, source=FeatureExtractionSupplemental.distance_and_velocity.__name__, accepted_axis_1_shape=(2,))
check_valid_array(
data=x,
source=FeatureExtractionSupplemental.distance_and_velocity.__name__,
accepted_axis_1_shape=(2,),
)
t = np.full((x.shape[0]), 0.0)
for i in range(1, x.shape[0]):
t[i] = np.linalg.norm(x[i] - x[i-1])
t[i] = np.linalg.norm(x[i] - x[i - 1])
x = np.copy(t) / pixels_per_mm
movement = np.sum(x) / pixels_per_mm
v = []
Expand All @@ -761,11 +778,12 @@ def distance_and_velocity(


x = np.random.randint(0, 100, (100, 2))
FeatureExtractionSupplemental.distance_and_velocity(x=x, fps=10, pixels_per_mm=10, centimeters=True)
FeatureExtractionSupplemental.distance_and_velocity(
x=x, fps=10, pixels_per_mm=10, centimeters=True
)
# # sum_movement, avg_velocity =



# df = read_df(file_path='/Users/simon/Desktop/envs/simba/troubleshooting/two_black_animals_14bp/project_folder/csv/targets_inserted/Together_1.csv', file_type='csv')
#
# df = pd.DataFrame(np.random.randint(0, 2, (100, 2)), columns=['Attack', 'Sniffing'])
Expand Down
Loading

0 comments on commit 3bd67e1

Please sign in to comment.