-
Notifications
You must be signed in to change notification settings - Fork 6
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 #451 from ttngu207/dev_queriable_in_roi_time
Table to compute/store InROI times AND subject-experiment mapping from Pyrat
- Loading branch information
Showing
4 changed files
with
159 additions
and
28 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
""" | ||
Script to fix the anchor part of the fullpose SLEAP entries. | ||
See this commit: https://github.com/SainsburyWellcomeCentre/aeon_mecha/commit/8358ce4b6923918920efb77d09adc769721dbb9b | ||
Last run: --- | ||
""" | ||
import pandas as pd | ||
from tqdm import tqdm | ||
from aeon.dj_pipeline import acquisition, tracking, streams | ||
|
||
aeon_schemas = acquisition.aeon_schemas | ||
logger = acquisition.logger | ||
io_api = acquisition.io_api | ||
|
||
|
||
def update_anchor_part(key): | ||
chunk_start, chunk_end = (acquisition.Chunk & key).fetch1("chunk_start", "chunk_end") | ||
|
||
data_dirs = acquisition.Experiment.get_data_directories(key) | ||
|
||
device_name = (streams.SpinnakerVideoSource & key).fetch1("spinnaker_video_source_name") | ||
|
||
devices_schema = getattr( | ||
aeon_schemas, | ||
(acquisition.Experiment.DevicesSchema & {"experiment_name": key["experiment_name"]}).fetch1( | ||
"devices_schema_name" | ||
), | ||
) | ||
|
||
stream_reader = getattr(getattr(devices_schema, device_name), "Pose") | ||
|
||
# special ingestion case for social0.2 full-pose data (using Pose reader from social03) | ||
# fullpose for social0.2 has a different "pattern" for non-fullpose, hence the Pose03 reader | ||
if key["experiment_name"].startswith("social0.2"): | ||
from aeon.io import reader as io_reader | ||
stream_reader = getattr(getattr(devices_schema, device_name), "Pose03") | ||
assert isinstance(stream_reader, io_reader.Pose), "Pose03 is not a Pose reader" | ||
data_dirs = [acquisition.Experiment.get_data_directory(key, "processed")] | ||
|
||
pose_data = io_api.load( | ||
root=data_dirs, | ||
reader=stream_reader, | ||
start=pd.Timestamp(chunk_start), | ||
end=pd.Timestamp(chunk_end), | ||
) | ||
|
||
if not len(pose_data): | ||
raise ValueError(f"No SLEAP data found for {key['experiment_name']} - {device_name}") | ||
|
||
# get anchor part | ||
anchor_part = next(v.replace("_x", "") for v in stream_reader.columns if v.endswith("_x")) | ||
|
||
# update anchor part | ||
for entry in tracking.SLEAPTracking.PoseIdentity.fetch("KEY"): | ||
entry["anchor_part"] = anchor_part | ||
tracking.SLEAPTracking.PoseIdentity.update1(entry) | ||
|
||
logger.info(f"Anchor part updated to {anchor_part} for {key}") | ||
|
||
|
||
def main(): | ||
keys = tracking.SLEAPTracking.fetch("KEY") | ||
for key in tqdm(keys): | ||
update_anchor_part(key) |
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