-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #25 from AllenNeuralDynamics/rel-0.7.0
Release 0.7.0
- Loading branch information
Showing
45 changed files
with
1,665 additions
and
437 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,12 +17,15 @@ dependencies = [ | |
'harp-python>=0.2', | ||
'gitpython>=3.1, <4.0', | ||
'scikit-learn', | ||
'semver' | ||
'semver', | ||
'aind-behavior-curriculum@git+https://github.com/AllenNeuralDynamics/[email protected]', | ||
|
||
] | ||
|
||
[project.optional-dependencies] | ||
dev = [ | ||
'aind_behavior_services[linters]' | ||
|
||
aind-data-schema-mapper = [ | ||
'aind-data-schema==0.33.9' | ||
] | ||
|
||
linters = [ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
Write-Host "Installing dependencies..." -ForegroundColor White | ||
$autoaccept = @("--accept-package-agreements", "--accept-source-agreements") | ||
|
||
winget install -e --id 7zip.7zip @autoaccept | ||
winget install ffmpeg -v 7.0 @autoaccept | ||
winget install -e --id Git.Git @autoaccept | ||
winget install -e --id Python.Python.3.11 --scope user @autoaccept | ||
winget install -e --id Microsoft.VisualStudioCode --scope user @autoaccept --override '/SILENT /mergetasks="!runcode,addcontextmenufiles,addcontextmenufolders"' | ||
winget install -e --id Microsoft.DotNet.Framework.DeveloperPack_4 @autoaccept | ||
Winget install "Microsoft Visual C++ 2012 Redistributable (x64)" --force @autoaccept | ||
winget install -e --id Nvidia.GeForceExperience -v 3.26.0.160 @autoaccept | ||
winget install -e --id Notepad++.Notepad++ @autoaccept | ||
winget install -e --id dotPDNLLC.paintdotnet @autoaccept | ||
|
||
## Install vscode extensions | ||
$extensions = | ||
"eamodio.gitlens", | ||
"donjayamanne.python-extension-pack" | ||
"redhat.vscode-yaml" | ||
|
||
$cmd = "code --list-extensions" | ||
Invoke-Expression $cmd -OutVariable output | Out-Null | ||
$installed = $output -split "\s" | ||
|
||
foreach ($ext in $extensions) { | ||
if ($installed.Contains($ext)) { | ||
Write-Host $ext "already installed." -ForegroundColor Gray | ||
} else { | ||
Write-Host "Installing" $ext "..." -ForegroundColor White | ||
code --install-extension $ext | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
from setuptools import setup | ||
|
||
if __name__ == "__main__": | ||
setup() | ||
setup() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
src/DataSchemas/aind_behavior_services/aind_data_schema_mapper/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
try: | ||
import aind_data_schema | ||
except ImportError as e: | ||
e.add_note( | ||
"The 'aind-data-schema' package is required to use this module. Install the optional dependencies defined in `project.toml' by running `pip install .[aind-data-schema-mapper]`" | ||
) | ||
raise |
129 changes: 129 additions & 0 deletions
129
src/DataSchemas/aind_behavior_services/aind_data_schema_mapper/mapper.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
import json | ||
import os | ||
from pathlib import Path | ||
from typing import Any, Dict, Optional, Type, TypeVar, Union | ||
|
||
from aind_behavior_services import AindBehaviorRigModel, AindBehaviorSessionModel, AindBehaviorTaskLogicModel | ||
from aind_data_schema.core.session import Modality, Session, Software, StimulusEpoch, Stream | ||
|
||
TSession = TypeVar("TSession", bound=AindBehaviorSessionModel) | ||
TRig = TypeVar("TRig", bound=AindBehaviorRigModel) | ||
TTaskLogic = TypeVar("TTaskLogic", bound=AindBehaviorTaskLogicModel) | ||
TSchema = TypeVar("TSchema", bound=Union[AindBehaviorSessionModel, AindBehaviorRigModel, AindBehaviorTaskLogicModel]) | ||
|
||
|
||
def map_to_aind_data_schema( | ||
session_root: Path, | ||
session: Type[TSession] = AindBehaviorSessionModel, | ||
rig: Type[TRig] = AindBehaviorRigModel, | ||
task_logic: Optional[type[TTaskLogic]] = None, | ||
) -> Session: | ||
""" | ||
Maps the input session found in `session_root` to the aind-data-schema Session object. | ||
Args: | ||
session_root (Path): The root path of the session. | ||
session (Type[TSession]): The session class. | ||
rig (Type[TRig]): The rig class. | ||
task_logic (Type[TTaskLogic]): The task logic class. | ||
Returns: | ||
Session: The mapped aind-data-schema session object. | ||
""" | ||
|
||
session_path = session_root / "Config" / "session_input.json" | ||
task_logic_path = session_root / "Config" / "tasklogic_input.json" | ||
rig_path = session_root / "Config" / "rig_input.json" | ||
|
||
if task_logic is None: | ||
return mapper( | ||
model_from_json_file(session_path, session), | ||
model_from_json_file(rig_path, rig), | ||
json.loads((task_logic_path.read_text())), | ||
) | ||
else: | ||
return mapper( | ||
model_from_json_file(session_path, session), | ||
model_from_json_file(rig_path, rig), | ||
model_from_json_file(task_logic_path, task_logic), | ||
) | ||
|
||
|
||
def mapper( | ||
session: TSession, | ||
rig: TRig, | ||
task_logic: TTaskLogic | Dict[str, Any], | ||
) -> Session: | ||
""" | ||
Maps the input session, rig, and task logic to an aind-data-schema Session object. | ||
Args: | ||
session (TSession): The input session object. | ||
rig (TRig): The input rig object. | ||
task_logic (TTaskLogic): The input task logic object. | ||
Returns: | ||
Session: The mapped aind-data-schema Session object. | ||
""" | ||
|
||
if isinstance(task_logic, dict): | ||
pass | ||
elif isinstance(task_logic, AindBehaviorTaskLogicModel): | ||
task_logic = task_logic.model_dump() | ||
else: | ||
raise ValueError("task_logic must be a dict or AindBehaviorTaskLogicModel") | ||
|
||
ads_session = Session( | ||
experimenter_full_name=session.experimenter, | ||
session_start_time=session.date, | ||
session_type=session.experiment, | ||
rig_id=rig.rig_name, | ||
subject_id=session.subject, | ||
notes=session.notes, | ||
data_streams=[ | ||
Stream( | ||
stream_modalities=[Modality.BEHAVIOR, Modality.BEHAVIOR_VIDEOS], | ||
stream_start_time=session.date, | ||
stream_end_time=session.date, | ||
camera_names=["NULL"], | ||
), | ||
], | ||
mouse_platform_name="Mouse platform", | ||
active_mouse_platform=True, | ||
stimulus_epochs=[ | ||
StimulusEpoch( | ||
stimulus_name="vr-foraging task", | ||
stimulus_start_time=session.date, | ||
stimulus_end_time=session.date, | ||
stimulus_modalities=["None"], | ||
software=[ | ||
Software( | ||
name="Bonsai", | ||
version=session.commit_hash, | ||
url="https://github.com/AllenNeuralDynamics/Aind.Behavior.VrForaging/blob/{sha}/bonsai/Bonsai.config".format( | ||
sha=session.commit_hash | ||
), | ||
) | ||
], | ||
script=Software( | ||
name="vr-foraging.bonsai", | ||
version=session.commit_hash, | ||
url="https://github.com/AllenNeuralDynamics/Aind.Behavior.VrForaging/blob/{sha}/src/vr-foraging.bonsai".format( | ||
sha=session.commit_hash | ||
), | ||
parameters=task_logic, | ||
), | ||
) | ||
], | ||
) | ||
return ads_session | ||
|
||
|
||
def model_from_json_file(json_path: os.PathLike | str, model_class: Type[TSchema]) -> TSchema: | ||
with open(json_path, encoding="utf-8") as f: | ||
return model_class.model_validate_json(f.read()) | ||
|
||
|
||
def model_to_json_file(json_path: os.PathLike | str, model: TSchema) -> None: | ||
with open(json_path, "w", encoding="utf-8") as f: | ||
f.write(model.model_dump_json(indent=4)) |
Oops, something went wrong.