aind-dynamic-foraging-basic-analysis 0.1.0__tar.gz → 0.2.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. {aind_dynamic_foraging_basic_analysis-0.1.0/src/aind_dynamic_foraging_basic_analysis.egg-info → aind_dynamic_foraging_basic_analysis-0.2.1}/PKG-INFO +9 -1
  2. {aind_dynamic_foraging_basic_analysis-0.1.0 → aind_dynamic_foraging_basic_analysis-0.2.1}/pyproject.toml +9 -1
  3. aind_dynamic_foraging_basic_analysis-0.2.1/src/aind_dynamic_foraging_basic_analysis/__init__.py +6 -0
  4. aind_dynamic_foraging_basic_analysis-0.2.1/src/aind_dynamic_foraging_basic_analysis/data_model/foraging_session.py +107 -0
  5. {aind_dynamic_foraging_basic_analysis-0.1.0 → aind_dynamic_foraging_basic_analysis-0.2.1}/src/aind_dynamic_foraging_basic_analysis/foraging_efficiency.py +14 -28
  6. aind_dynamic_foraging_basic_analysis-0.2.1/src/aind_dynamic_foraging_basic_analysis/lick_analysis.py +622 -0
  7. aind_dynamic_foraging_basic_analysis-0.2.1/src/aind_dynamic_foraging_basic_analysis/plot/plot_foraging_session.py +315 -0
  8. {aind_dynamic_foraging_basic_analysis-0.1.0 → aind_dynamic_foraging_basic_analysis-0.2.1/src/aind_dynamic_foraging_basic_analysis.egg-info}/PKG-INFO +9 -1
  9. {aind_dynamic_foraging_basic_analysis-0.1.0 → aind_dynamic_foraging_basic_analysis-0.2.1}/src/aind_dynamic_foraging_basic_analysis.egg-info/SOURCES.txt +9 -0
  10. {aind_dynamic_foraging_basic_analysis-0.1.0 → aind_dynamic_foraging_basic_analysis-0.2.1}/src/aind_dynamic_foraging_basic_analysis.egg-info/requires.txt +8 -0
  11. aind_dynamic_foraging_basic_analysis-0.2.1/tests/data/689514_2024-02-01_18-06-43.nwb +0 -0
  12. aind_dynamic_foraging_basic_analysis-0.2.1/tests/data/689514_2024-02-01_18-06-43.png +0 -0
  13. aind_dynamic_foraging_basic_analysis-0.2.1/tests/data/689514_2024-02-01_18-06-43qc.png +0 -0
  14. {aind_dynamic_foraging_basic_analysis-0.1.0 → aind_dynamic_foraging_basic_analysis-0.2.1}/tests/nwb_io.py +1 -1
  15. aind_dynamic_foraging_basic_analysis-0.2.1/tests/test_Events.nwb +0 -0
  16. {aind_dynamic_foraging_basic_analysis-0.1.0 → aind_dynamic_foraging_basic_analysis-0.2.1}/tests/test_foraging_efficiency.py +4 -10
  17. aind_dynamic_foraging_basic_analysis-0.2.1/tests/test_lickAnalysis.py +44 -0
  18. aind_dynamic_foraging_basic_analysis-0.2.1/tests/test_plot_foraging_session.py +136 -0
  19. aind_dynamic_foraging_basic_analysis-0.1.0/src/aind_dynamic_foraging_basic_analysis/__init__.py +0 -5
  20. {aind_dynamic_foraging_basic_analysis-0.1.0 → aind_dynamic_foraging_basic_analysis-0.2.1}/.flake8 +0 -0
  21. {aind_dynamic_foraging_basic_analysis-0.1.0 → aind_dynamic_foraging_basic_analysis-0.2.1}/.github/ISSUE_TEMPLATE/bug_report.md +0 -0
  22. {aind_dynamic_foraging_basic_analysis-0.1.0 → aind_dynamic_foraging_basic_analysis-0.2.1}/.github/ISSUE_TEMPLATE/feature_request.md +0 -0
  23. {aind_dynamic_foraging_basic_analysis-0.1.0 → aind_dynamic_foraging_basic_analysis-0.2.1}/.github/ISSUE_TEMPLATE/user-story.md +0 -0
  24. {aind_dynamic_foraging_basic_analysis-0.1.0 → aind_dynamic_foraging_basic_analysis-0.2.1}/.github/workflows/init.yml +0 -0
  25. {aind_dynamic_foraging_basic_analysis-0.1.0 → aind_dynamic_foraging_basic_analysis-0.2.1}/.github/workflows/tag_and_publish.yml +0 -0
  26. {aind_dynamic_foraging_basic_analysis-0.1.0 → aind_dynamic_foraging_basic_analysis-0.2.1}/.github/workflows/test_and_lint.yml +0 -0
  27. {aind_dynamic_foraging_basic_analysis-0.1.0 → aind_dynamic_foraging_basic_analysis-0.2.1}/.gitignore +0 -0
  28. {aind_dynamic_foraging_basic_analysis-0.1.0 → aind_dynamic_foraging_basic_analysis-0.2.1}/LICENSE +0 -0
  29. {aind_dynamic_foraging_basic_analysis-0.1.0 → aind_dynamic_foraging_basic_analysis-0.2.1}/README.md +0 -0
  30. {aind_dynamic_foraging_basic_analysis-0.1.0 → aind_dynamic_foraging_basic_analysis-0.2.1}/doc_template/Makefile +0 -0
  31. {aind_dynamic_foraging_basic_analysis-0.1.0 → aind_dynamic_foraging_basic_analysis-0.2.1}/doc_template/make.bat +0 -0
  32. {aind_dynamic_foraging_basic_analysis-0.1.0 → aind_dynamic_foraging_basic_analysis-0.2.1}/doc_template/source/_static/dark-logo.svg +0 -0
  33. {aind_dynamic_foraging_basic_analysis-0.1.0 → aind_dynamic_foraging_basic_analysis-0.2.1}/doc_template/source/_static/favicon.ico +0 -0
  34. {aind_dynamic_foraging_basic_analysis-0.1.0 → aind_dynamic_foraging_basic_analysis-0.2.1}/doc_template/source/_static/light-logo.svg +0 -0
  35. {aind_dynamic_foraging_basic_analysis-0.1.0 → aind_dynamic_foraging_basic_analysis-0.2.1}/doc_template/source/conf.py +0 -0
  36. {aind_dynamic_foraging_basic_analysis-0.1.0 → aind_dynamic_foraging_basic_analysis-0.2.1}/doc_template/source/index.rst +0 -0
  37. {aind_dynamic_foraging_basic_analysis-0.1.0 → aind_dynamic_foraging_basic_analysis-0.2.1}/setup.cfg +0 -0
  38. {aind_dynamic_foraging_basic_analysis-0.1.0 → aind_dynamic_foraging_basic_analysis-0.2.1}/setup.py +0 -0
  39. {aind_dynamic_foraging_basic_analysis-0.1.0 → aind_dynamic_foraging_basic_analysis-0.2.1}/src/aind_dynamic_foraging_basic_analysis.egg-info/dependency_links.txt +0 -0
  40. {aind_dynamic_foraging_basic_analysis-0.1.0 → aind_dynamic_foraging_basic_analysis-0.2.1}/src/aind_dynamic_foraging_basic_analysis.egg-info/top_level.txt +0 -0
  41. {aind_dynamic_foraging_basic_analysis-0.1.0 → aind_dynamic_foraging_basic_analysis-0.2.1}/tests/__init__.py +0 -0
  42. {aind_dynamic_foraging_basic_analysis-0.1.0 → aind_dynamic_foraging_basic_analysis-0.2.1}/tests/data/697929_2024-02-22_08-38-30.nwb +0 -0
  43. {aind_dynamic_foraging_basic_analysis-0.1.0 → aind_dynamic_foraging_basic_analysis-0.2.1}/tests/data/703548_2024-03-01_08-51-32.nwb +0 -0
  44. {aind_dynamic_foraging_basic_analysis-0.1.0 → aind_dynamic_foraging_basic_analysis-0.2.1}/tests/data/727456_2024-06-12_11-10-53.nwb +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: aind-dynamic-foraging-basic-analysis
3
- Version: 0.1.0
3
+ Version: 0.2.1
4
4
  Summary: Generated from aind-library-template
5
5
  Author: Allen Institute for Neural Dynamics
6
6
  License: MIT
@@ -9,6 +9,14 @@ Requires-Python: >=3.7
9
9
  Description-Content-Type: text/markdown
10
10
  License-File: LICENSE
11
11
  Requires-Dist: numpy
12
+ Requires-Dist: scipy
13
+ Requires-Dist: matplotlib
14
+ Requires-Dist: pandas
15
+ Requires-Dist: pynwb
16
+ Requires-Dist: aind_ephys_utils
17
+ Requires-Dist: pathlib
18
+ Requires-Dist: numpy
19
+ Requires-Dist: pydantic
12
20
  Provides-Extra: dev
13
21
  Requires-Dist: aind-dynamic-foraging-basic-analysis; extra == "dev"
14
22
  Requires-Dist: black; extra == "dev"
@@ -17,7 +17,15 @@ readme = "README.md"
17
17
  dynamic = ["version"]
18
18
 
19
19
  dependencies = [
20
- 'numpy'
20
+ 'numpy',
21
+ 'scipy',
22
+ 'matplotlib',
23
+ 'pandas',
24
+ 'pynwb',
25
+ 'aind_ephys_utils',
26
+ 'pathlib',
27
+ 'numpy',
28
+ 'pydantic'
21
29
  ]
22
30
 
23
31
  [project.optional-dependencies]
@@ -0,0 +1,6 @@
1
+ """Init package"""
2
+
3
+ __version__ = "0.2.1"
4
+
5
+ from .foraging_efficiency import compute_foraging_efficiency # noqa: F401
6
+ from .plot.plot_foraging_session import plot_foraging_session # noqa: F401
@@ -0,0 +1,107 @@
1
+ """
2
+ Pydantic data model of foraging session data for shared validation.
3
+
4
+ Maybe this is an overkill...
5
+ """
6
+
7
+ from typing import List, Optional
8
+
9
+ import numpy as np
10
+ from pydantic import BaseModel, field_validator, model_validator
11
+
12
+
13
+ class PhotostimData(BaseModel):
14
+ """Photostimulation data"""
15
+
16
+ trial: List[int]
17
+ power: List[float]
18
+ stim_epoch: Optional[List[str]] = None
19
+
20
+ class Config:
21
+ """Allow np.ndarray as input"""
22
+
23
+ arbitrary_types_allowed = True
24
+
25
+
26
+ class ForagingSessionData(BaseModel):
27
+ """Shared validation for foraging session data"""
28
+
29
+ choice_history: np.ndarray
30
+ reward_history: np.ndarray
31
+ p_reward: Optional[np.ndarray] = None
32
+ random_number: Optional[np.ndarray] = None
33
+ autowater_offered: Optional[np.ndarray] = None
34
+ fitted_data: Optional[np.ndarray] = None
35
+ photostim: Optional[PhotostimData] = None
36
+
37
+ class Config:
38
+ """Allow np.ndarray as input"""
39
+
40
+ arbitrary_types_allowed = True
41
+
42
+ @field_validator(
43
+ "choice_history",
44
+ "reward_history",
45
+ "p_reward",
46
+ "random_number",
47
+ "autowater_offered",
48
+ "fitted_data",
49
+ mode="before",
50
+ )
51
+ @classmethod
52
+ def convert_to_ndarray(cls, v, info):
53
+ """Always convert to numpy array"""
54
+ return (
55
+ np.array(
56
+ v,
57
+ dtype=(
58
+ "bool"
59
+ if info.field_name in ["reward_history", "autowater_offered"] # Turn to bool
60
+ else None
61
+ ),
62
+ )
63
+ if v is not None
64
+ else None
65
+ )
66
+
67
+ @model_validator(mode="after")
68
+ def check_all_fields(cls, values): # noqa: C901
69
+ """Check consistency of all fields"""
70
+
71
+ choice_history = values.choice_history
72
+ reward_history = values.reward_history
73
+ p_reward = values.p_reward
74
+ random_number = values.random_number
75
+ autowater_offered = values.autowater_offered
76
+ fitted_data = values.fitted_data
77
+ photostim = values.photostim
78
+
79
+ if not np.all(np.isin(choice_history, [0.0, 1.0]) | np.isnan(choice_history)):
80
+ raise ValueError("choice_history must contain only 0, 1, or np.nan.")
81
+
82
+ if choice_history.shape != reward_history.shape:
83
+ raise ValueError("choice_history and reward_history must have the same shape.")
84
+
85
+ if p_reward.shape != (2, len(choice_history)):
86
+ raise ValueError("reward_probability must have the shape (2, n_trials)")
87
+
88
+ if random_number is not None and random_number.shape != p_reward.shape:
89
+ raise ValueError("random_number must have the same shape as reward_probability.")
90
+
91
+ if autowater_offered is not None and autowater_offered.shape != choice_history.shape:
92
+ raise ValueError("autowater_offered must have the same shape as choice_history.")
93
+
94
+ if fitted_data is not None and fitted_data.shape[0] != choice_history.shape[0]:
95
+ raise ValueError("fitted_data must have the same length as choice_history.")
96
+
97
+ if photostim is not None:
98
+ if len(photostim.trial) != len(photostim.power):
99
+ raise ValueError("photostim.trial must have the same length as photostim.power.")
100
+ if photostim.stim_epoch is not None and len(photostim.stim_epoch) != len(
101
+ photostim.power
102
+ ):
103
+ raise ValueError(
104
+ "photostim.stim_epoch must have the same length as photostim.power."
105
+ )
106
+
107
+ return values
@@ -4,6 +4,8 @@ from typing import List, Tuple, Union
4
4
 
5
5
  import numpy as np
6
6
 
7
+ from aind_dynamic_foraging_basic_analysis.data_model.foraging_session import ForagingSessionData
8
+
7
9
 
8
10
  def compute_foraging_efficiency(
9
11
  baited: bool,
@@ -74,38 +76,22 @@ def compute_foraging_efficiency(
74
76
  reward_optimal_func = _reward_optimal_forager_no_baiting
75
77
 
76
78
  # Formatting and sanity checks
77
- choice_history = np.array(choice_history, dtype=float) # Convert None to np.nan, if any
78
- reward_history = np.array(reward_history, dtype=float)
79
- p_reward = np.array(p_reward, dtype=float)
80
- random_number = np.array(random_number, dtype=float) if random_number is not None else None
81
- n_trials = len(choice_history)
82
-
83
- if not np.all(np.isin(choice_history, [0.0, 1.0]) | np.isnan(choice_history)):
84
- raise ValueError("choice_history must contain only 0, 1, or np.nan.")
85
-
86
- if not np.all(np.isin(reward_history, [0.0, 1.0])):
87
- raise ValueError("reward_history must contain only 0 (False) or 1 (True).")
88
-
89
- if choice_history.shape != reward_history.shape:
90
- raise ValueError("choice_history and reward_history must have the same shape.")
91
-
92
- if p_reward.shape != (2, n_trials):
93
- raise ValueError("reward_probability must have the shape (2, n_trials)")
94
-
95
- if random_number is not None and random_number.shape != p_reward.shape:
96
- raise ValueError("random_number must have the same shape as reward_probability.")
97
-
98
- if autowater_offered is not None and not autowater_offered.shape == choice_history.shape:
99
- raise ValueError("autowater_offered must have the same shape as choice_history.")
79
+ data = ForagingSessionData(
80
+ choice_history=choice_history,
81
+ reward_history=reward_history,
82
+ p_reward=p_reward,
83
+ random_number=random_number,
84
+ autowater_offered=autowater_offered,
85
+ )
100
86
 
101
87
  # Foraging_efficiency is calculated only on finished AND non-autowater trials
102
- ignored = np.isnan(choice_history)
88
+ ignored = np.isnan(data.choice_history)
103
89
  valid_trials = (~ignored & ~autowater_offered) if autowater_offered is not None else ~ignored
104
90
 
105
- choice_history = choice_history[valid_trials]
106
- reward_history = reward_history[valid_trials]
107
- p_reward = p_reward[:, valid_trials]
108
- random_number = random_number[:, valid_trials] if random_number is not None else None
91
+ choice_history = data.choice_history[valid_trials]
92
+ reward_history = data.reward_history[valid_trials]
93
+ p_reward = data.p_reward[:, valid_trials]
94
+ random_number = data.random_number[:, valid_trials] if data.random_number is not None else None
109
95
 
110
96
  # Compute reward of the optimal forager
111
97
  reward_optimal, reward_optimal_random_seed = reward_optimal_func(