Skip to content

More fib plus pav updates #293

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 42 commits into from
May 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
d470fa4
Updated exposure time in fip example
dougollerenshaw May 5, 2025
d3b1a0a
Added behavior cameras to example session
dougollerenshaw May 5, 2025
dd35b31
Add special case for reward units conflict
dougollerenshaw May 5, 2025
bccd5da
Added logic to pass through stimulus epoch params
dougollerenshaw May 5, 2025
fbbb80f
Radically simplify the joint session creation script
dougollerenshaw May 5, 2025
6395ba0
Reverting cmos exposure time change
dougollerenshaw May 6, 2025
6e091dd
Updated logic in merge_sessions to deal with empty strings, updated d…
dougollerenshaw May 6, 2025
999b892
Improved default handling in scripts/example_create_fiber_and_pav_ses…
dougollerenshaw May 6, 2025
b83929f
Removed unnecessary args
dougollerenshaw May 6, 2025
7fecdb4
Linting and refactoring to avoid function complexity
dougollerenshaw May 6, 2025
fc57874
Test fixes to include session_type arg
dougollerenshaw May 6, 2025
13580f0
Docstring updates in utils/merge_sessions.py
dougollerenshaw May 6, 2025
f2683ef
More lint fixes
dougollerenshaw May 6, 2025
8b363ca
Added missing docstring in scripts/example_create_fiber_and_pav_sessi…
dougollerenshaw May 6, 2025
3f3e5e6
Added params to pass through
dougollerenshaw May 6, 2025
a8ed008
refactoring suggestion for the example code to make it a python function
hagikent May 7, 2025
d0463de
restoring help args for CLI
hagikent May 7, 2025
48ec268
Added a script for downloading data to local folder
dougollerenshaw May 7, 2025
17e5fbd
Added reward_delivery
dougollerenshaw May 7, 2025
4c90696
linting
dougollerenshaw May 7, 2025
86f595f
Merge pull request #294 from AllenNeuralDynamics/more_fib_plus_pav_up…
dougollerenshaw May 7, 2025
5dc8761
Docstring updates
dougollerenshaw May 7, 2025
41b1e9a
Merge branch 'more_fib_plus_pav_updates' of https://github.com/AllenN…
dougollerenshaw May 7, 2025
155af9c
Lint fixes
dougollerenshaw May 7, 2025
19cc50e
Added s3fs to pyproject.toml
dougollerenshaw May 7, 2025
85a6d37
Added missing docstrings
dougollerenshaw May 7, 2025
e2cefcb
Added missing comma in pyproject.toml
dougollerenshaw May 7, 2025
0d7cc9f
Timezone format fixes - use local tz with offset, not utc
dougollerenshaw May 21, 2025
2cb8317
Updated timing logic and combine data streams
dougollerenshaw May 21, 2025
60dc6fa
Cleanup:
dougollerenshaw May 23, 2025
2ec68e7
Test fixes
dougollerenshaw May 23, 2025
a9ae381
linting, including reducing func complexity w some refactoring
dougollerenshaw May 23, 2025
c396dfd
Small post-review changes
dougollerenshaw May 23, 2025
2ed512b
Another lint fix
dougollerenshaw May 23, 2025
606a781
Add a note to merge sessions docstring
dougollerenshaw May 23, 2025
0058f0f
Removed script for downloading data
dougollerenshaw May 23, 2025
bcd8199
Removed trailing comma in pyproject.toml, reverting to main
dougollerenshaw May 23, 2025
5dbce34
Replace tempfile with mock in tests
dougollerenshaw May 27, 2025
d813fc0
Fixed timezone default in pav session.py
dougollerenshaw May 27, 2025
c0ca5f4
Fixed trailing whitespace
dougollerenshaw May 27, 2025
2327d8b
Added missed docstrings in test_merge_sessions
dougollerenshaw May 27, 2025
4523bfb
Adjusted spout location from -5 mm to -1.5 mm per feedback from Kenta
dougollerenshaw May 27, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
510 changes: 231 additions & 279 deletions scripts/example_create_fiber_and_pav_sessions.py

Large diffs are not rendered by default.

53 changes: 43 additions & 10 deletions src/aind_metadata_mapper/fip/example_create_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
# Optional parameters with defaults:
experimenter_full_name=["test_experimenter_1", "test_experimenter_2"],
rig_id="428_9_B_20240617",
task_version="1.0.0",
iacuc_protocol="2115",
mouse_platform_name="mouse_tube_foraging",
active_mouse_platform=False,
Expand Down Expand Up @@ -62,13 +61,14 @@ def create_metadata(
"test_experimenter_2",
],
rig_id: str = "428_9_0_20240617",
task_version: str = "1.0.0",
iacuc_protocol: str = "2115",
mouse_platform_name: str = "mouse_tube_foraging",
active_mouse_platform: bool = False,
session_type: str = "Foraging_Photometry",
task_name: str = "Fiber Photometry",
notes: str = "Example configuration for fiber photometry rig",
session_type: str = "FIB",
notes: str = "",
anaesthesia: Optional[str] = None,
animal_weight_post: Optional[float] = None,
animal_weight_prior: Optional[float] = None,
) -> bool:
"""Create fiber photometry metadata with default settings.

Expand All @@ -79,13 +79,14 @@ def create_metadata(
output_filename: Name of the output JSON file
experimenter_full_name: List of experimenter names
rig_id: Identifier for the experimental rig
task_version: Version of the experimental task
iacuc_protocol: Protocol identifier
mouse_platform_name: Name of the mouse platform
active_mouse_platform: Whether platform is active
session_type: Type of experimental session
task_name: Name of the experimental task
notes: Additional notes about the session
anaesthesia: Anaesthesia used
animal_weight_post: Animal weight after session
animal_weight_prior: Animal weight before session

Returns:
bool: True if metadata was successfully
Expand All @@ -99,13 +100,14 @@ def create_metadata(
"output_directory": str(output_directory),
"output_filename": output_filename,
"rig_id": rig_id,
"task_version": task_version,
"iacuc_protocol": iacuc_protocol,
"mouse_platform_name": mouse_platform_name,
"active_mouse_platform": active_mouse_platform,
"session_type": session_type,
"task_name": task_name,
"notes": notes,
"anaesthesia": anaesthesia,
"animal_weight_post": animal_weight_post,
"animal_weight_prior": animal_weight_prior,
"data_streams": [
{
"stream_start_time": None,
Expand Down Expand Up @@ -184,7 +186,7 @@ def create_metadata(
{
"name": "Bonsai",
"parameters": {},
"url": "",
"url": "https://github.com/AllenNeuralDynamics/PavlovianCond_Bonsai/tree/dafd7dfe0f347f781e91466b3d16b83cf32f8b6d", # noqa E501
"version": "",
}
],
Expand Down Expand Up @@ -232,6 +234,32 @@ def create_metadata(
default="session_fip.json",
help="Name of the output JSON file (default: session_fip.json)",
)
parser.add_argument(
"--active-mouse-platform",
action="store_true",
help="Whether the mouse platform was active",
)
parser.add_argument(
"--anaesthesia", type=str, default=None, help="Anaesthesia used"
)
parser.add_argument(
"--animal-weight-post",
type=float,
default=None,
help="Animal weight after session",
)
parser.add_argument(
"--animal-weight-prior",
type=float,
default=None,
help="Animal weight before session",
)
parser.add_argument(
"--mouse-platform-name",
type=str,
default="mouse_tube_foraging",
help="Name of the mouse platform",
)

args = parser.parse_args()

Expand All @@ -240,6 +268,11 @@ def create_metadata(
data_directory=args.data_directory,
output_directory=args.output_directory,
output_filename=args.output_filename,
active_mouse_platform=args.active_mouse_platform,
anaesthesia=args.anaesthesia,
animal_weight_post=args.animal_weight_post,
animal_weight_prior=args.animal_weight_prior,
mouse_platform_name=args.mouse_platform_name,
)

output_path = args.output_directory / args.output_filename
Expand Down
9 changes: 9 additions & 0 deletions src/aind_metadata_mapper/fip/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ class JobSettings(BaseJobSettings):
IACUC protocol identifier
notes : str
Session notes
anaesthesia : Optional[str]
Anaesthesia used
animal_weight_post : Optional[float]
Animal weight after session
animal_weight_prior : Optional[float]
Animal weight before session
protocol_id : List[str], optional
List of protocol identifiers, defaults to empty list
data_directory : Optional[Union[str, Path]], optional
Expand All @@ -60,6 +66,9 @@ class JobSettings(BaseJobSettings):
session_type: str = "FIB"
iacuc_protocol: str
notes: str
anaesthesia: Optional[str] = None
animal_weight_post: Optional[float] = None
animal_weight_prior: Optional[float] = None

# Optional Session fields with defaults
protocol_id: List[str] = []
Expand Down
59 changes: 57 additions & 2 deletions src/aind_metadata_mapper/fip/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,51 @@

@dataclass
class FiberData:
"""Intermediate data model for fiber photometry data."""
"""Intermediate data model for fiber photometry data.

This model holds the extracted and processed data before final
transformation into a Session object. It serves as a structured
intermediate representation of the fiber photometry session data.

Parameters
----------
start_time : datetime
Session start time from fiber photometry files
end_time : Optional[datetime]
Session end time from fiber photometry files
data_files : List[Path]
List of paths to fiber photometry data files
timestamps : List[float]
List of timestamps from fiber photometry recordings
light_source_configs : List[dict]
List of light source configuration dictionaries
detector_configs : List[dict]
List of detector configuration dictionaries
fiber_configs : List[dict]
List of fiber configuration dictionaries
subject_id : str
Subject identifier
experimenter_full_name : List[str]
List of experimenter names
rig_id : str
Identifier for the experimental rig
iacuc_protocol : str
IACUC protocol number
notes : str
Additional notes about the session
mouse_platform_name : str
Name of the mouse platform used
active_mouse_platform : bool
Whether the mouse platform was active
session_type : str
Type of session (e.g. "FIB")
anaesthesia : Optional[str]
Anaesthesia used, if any
animal_weight_post : Optional[float]
Animal weight after session
animal_weight_prior : Optional[float]
Animal weight before session
"""

start_time: datetime
end_time: Optional[datetime]
Expand All @@ -56,6 +100,10 @@ class FiberData:
notes: str
mouse_platform_name: str
active_mouse_platform: bool
session_type: str
anaesthesia: Optional[str]
animal_weight_post: Optional[float]
animal_weight_prior: Optional[float]


class FIBEtl(GenericEtl[JobSettings]):
Expand Down Expand Up @@ -141,6 +189,10 @@ def _extract(self) -> FiberData:
notes=settings.notes,
mouse_platform_name=settings.mouse_platform_name,
active_mouse_platform=settings.active_mouse_platform,
session_type=settings.session_type,
anaesthesia=settings.anaesthesia,
animal_weight_post=settings.animal_weight_post,
animal_weight_prior=settings.animal_weight_prior,
)

def _transform(self, fiber_data: FiberData) -> Session:
Expand Down Expand Up @@ -177,14 +229,17 @@ def _transform(self, fiber_data: FiberData) -> Session:
experimenter_full_name=fiber_data.experimenter_full_name,
session_start_time=fiber_data.start_time,
session_end_time=fiber_data.end_time,
session_type="FIB",
session_type=fiber_data.session_type,
rig_id=fiber_data.rig_id,
subject_id=fiber_data.subject_id,
iacuc_protocol=fiber_data.iacuc_protocol,
notes=fiber_data.notes,
data_streams=[stream],
mouse_platform_name=fiber_data.mouse_platform_name,
active_mouse_platform=fiber_data.active_mouse_platform,
anaesthesia=fiber_data.anaesthesia,
animal_weight_post=fiber_data.animal_weight_post,
animal_weight_prior=fiber_data.animal_weight_prior,
)

return session
Expand Down
Loading