diff --git a/pyproject.toml b/pyproject.toml index 0ddc0be..8b8b28f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "jabs-postprocess" -version = "0.5.0" +version = "0.5.1" description = "A python library for JABS postprocessing utilities." readme = "README.md" license = "LicenseRef-PLATFORM-LICENSE-AGREEMENT-FOR-NON-COMMERCIAL-USE" diff --git a/src/jabs_postprocess/utils/project_utils.py b/src/jabs_postprocess/utils/project_utils.py index e7b77d2..24dd84d 100644 --- a/src/jabs_postprocess/utils/project_utils.py +++ b/src/jabs_postprocess/utils/project_utils.py @@ -1024,12 +1024,10 @@ def bouts_to_bins( # We use a weighted statistic definitions here # Weights are the proportion of bout contained in the bin (percent_bout) if results["bout_behavior"] > 0: - results["avg_bout_duration"] = ( - np.sum( - behavior_bins["duration"].values - * behavior_bins["percent_bout"].values - ) - / results["bout_behavior"] + results["avg_bout_duration"] = np.average( + behavior_bins["duration"].values + / behavior_bins["percent_bout"].values, + weights=behavior_bins["percent_bout"].values, ) results["latency_to_first_prediction"] = behavior_bins["start"].min() results["latency_to_last_prediction"] = ( diff --git a/tests/utils/test_project_utils.py b/tests/utils/test_project_utils.py index 9009370..af6ce54 100644 --- a/tests/utils/test_project_utils.py +++ b/tests/utils/test_project_utils.py @@ -759,15 +759,15 @@ def test_bouts_to_bins_split_bout_weighted_statistics(self): # Both bins should have: # - bout_behavior = 0.5 (half the bout counted) # - time_behavior = 300 (half the frames) - # - avg_bout_duration = 300 (the actual duration in each bin) + # - avg_bout_duration = 600 (duration remains same, average of 1 sample) # - variance = NaN (only one bout, even if split) assert len(result) == 2 for i in range(2): assert abs(result.iloc[i]["bout_behavior"] - 0.5) < 0.01 assert result.iloc[i]["time_behavior"] == 300 - # When a bout is split, the avg_bout_duration is the fractional duration - assert abs(result.iloc[i]["avg_bout_duration"] - 300) < 0.1 + # When a bout is split, the avg_bout_duration is still the total duration + assert abs(result.iloc[i]["avg_bout_duration"] - 600) < 0.1 assert pd.isna(result.iloc[i]["bout_duration_var"]) def test_bouts_to_bins_multiple_split_bouts_variance(self): diff --git a/uv.lock b/uv.lock index 3d517ae..a774e8f 100644 --- a/uv.lock +++ b/uv.lock @@ -340,7 +340,7 @@ wheels = [ [[package]] name = "jabs-postprocess" -version = "0.5.0" +version = "0.5.1" source = { editable = "." } dependencies = [ { name = "black" }, diff --git a/vm/jabs-postprocess.def b/vm/jabs-postprocess.def index be1aa11..7a58cd4 100644 --- a/vm/jabs-postprocess.def +++ b/vm/jabs-postprocess.def @@ -62,5 +62,5 @@ From: ghcr.io/astral-sh/uv:python3.10-bookworm-slim %labels Author "The Kumar Lab" - Version "0.1.0" + Version "0.5.1" Description "JABS post-processing container with Python 3.10"