Skip to content

Commit

Permalink
WIP: tests for centoid, model, orietation
Browse files Browse the repository at this point in the history
  • Loading branch information
CBroz1 committed May 18, 2024
1 parent 55222e5 commit 944de85
Show file tree
Hide file tree
Showing 11 changed files with 624 additions and 425 deletions.
11 changes: 10 additions & 1 deletion src/spyglass/position/v1/position_dlc_centroid.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ def make(self, key):
for point in required_points:
bodypart = points[point]
if bodypart not in bodyparts_avail:
raise ValueError(
raise ValueError( # TODO: migrate to input validation
"Bodypart in points not in model."
f"\tBodypart {bodypart}"
f"\tIn Model {bodyparts_avail}"
Expand Down Expand Up @@ -222,6 +222,7 @@ def make(self, key):
"smoothing_duration"
)
if not smoothing_duration:
# TODO: remove - validated with `validate_smooth_params`
raise KeyError(
"smoothing_duration needs to be passed within smoothing_params"
)
Expand Down Expand Up @@ -368,6 +369,7 @@ def four_led_centroid(pos_df: pd.DataFrame, **params):
"""Determines the centroid of 4 LEDS on an implant LED ring.
Assumed to be the Green LED, and 3 red LEDs called: redLED_C, redLED_L, redLED_R
By default, uses (greenled + redLED_C) / 2 to calculate centroid
If Green LED is NaN, but red center LED is not,
then the red center LED is called the centroid
If green and red center LEDs are NaN, but red left and red right LEDs are not,
Expand Down Expand Up @@ -397,6 +399,9 @@ def four_led_centroid(pos_df: pd.DataFrame, **params):
numpy array with shape (n_time, 2)
centroid[0] is the x coord and centroid[1] is the y coord
"""
if not (params.get("max_LED_separation") and params.get("points")):
raise KeyError("max_LED_separation/points need to be passed in params")

centroid = np.zeros(shape=(len(pos_df), 2))
idx = pd.IndexSlice
# TODO: this feels messy, clean-up
Expand Down Expand Up @@ -722,6 +727,8 @@ def two_pt_centroid(pos_df: pd.DataFrame, **params):
numpy array with shape (n_time, 2)
centroid[0] is the x coord and centroid[1] is the y coord
"""
if not (params.get("max_LED_separation") and params.get("points")):
raise KeyError("max_LED_separation/points need to be passed in params")

idx = pd.IndexSlice
centroid = np.zeros(shape=(len(pos_df), 2))
Expand Down Expand Up @@ -797,6 +804,8 @@ def one_pt_centroid(pos_df: pd.DataFrame, **params):
numpy array with shape (n_time, 2)
centroid[0] is the x coord and centroid[1] is the y coord
"""
if not params.get("points"):
raise KeyError("points need to be passed in params")
idx = pd.IndexSlice
PT1 = params["points"].pop("point1", None)
centroid = pos_df.loc[:, idx[PT1, ("x", "y")]].to_numpy()
Expand Down
2 changes: 1 addition & 1 deletion src/spyglass/position/v1/position_dlc_position.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ def make(self, key):

bp_key = key.copy()
if test_mode: # during testing, analysis_file not in BodyPart table
bp_key.pop("analysis_file_name")
bp_key.pop("analysis_file_name", None)

dlc_df = (DLCPoseEstimation.BodyPart() & bp_key).fetch1_dataframe()
dt = np.median(np.diff(dlc_df.index.to_numpy()))
Expand Down
Loading

0 comments on commit 944de85

Please sign in to comment.