catalystneuro / leifer_lab_to_nwb

Conversion scripts for the Leifer lab. Includes the publication Neural signal propagation atlas of Caenorhabditis elegans (Nature, 2023).
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

Motion tracking ID matches #20

Open CodyCBakerPhD opened 3 days ago

CodyCBakerPhD commented 3 days ago

Though the brains.json for the pumpprobe indeed as XYZ coordinates for ROIs tracked over the entire functional imaging, it only has data for the number (and thus local IDs) seen on the 30th frame, and though it tracked (via nInVolume) the number of such ROIs in each volume, it does not track which local IDs (which could correspond to the 30th frame) each coordinate corresponds to in each volume

A helper script...

import json
import pathlib
import pickle

import numpy

BASE_FOLDER_PATH = pathlib.Path("D:/Leifer")
SESSION_FOLDER_PATH = BASE_FOLDER_PATH / "20211104"
# LOGBOOK_FILE_PATH = SESSION_FOLDER_PATH / "logbook.txt"

PUMPPROBE_FOLDER_PATH = SESSION_FOLDER_PATH / "pumpprobe_20211104_163944"
MULTICOLOR_FOLDER_PATH = SESSION_FOLDER_PATH / "multicolorworm_20211104_162630"

multicolor_brains_file_path = MULTICOLOR_FOLDER_PATH / "brains.json"
with open(file=multicolor_brains_file_path, mode="r") as io:
    multicolor_brains_info = json.load(fp=io)

pumpprobe_brains_file_path = PUMPPROBE_FOLDER_PATH / "brains.json"
with open(file=pumpprobe_brains_file_path, mode="r") as io:
    pumpprobe_brains_info = json.load(fp=io)

matches_file_path = PUMPPROBE_FOLDER_PATH / "matches.pickle"
with open(file=matches_file_path, mode="rb") as io:
    matches_info = pickle.load(file=io)

red_signal_file_path = PUMPPROBE_FOLDER_PATH / "red.pickle"
with open(file=red_signal_file_path, mode="rb") as io:
    red_signal_info = pickle.load(file=io)

green_signal_file_path = PUMPPROBE_FOLDER_PATH / "green.pickle"
with open(file=green_signal_file_path, mode="rb") as io:
    green_signal_info = pickle.load(file=io)

print(f"PumpProbe brains 'nInVolume' for volume 0: {pumpprobe_brains_info['nInVolume'][0]}")
print(f"Number of non-nan masked indices in PumpProbe greed signal: {sum(green_signal_info.nan_mask[0,:] == False)}")
print(f"Number of non-nan masked indices in PumpProbe red signal: {sum(red_signal_info.nan_mask[0,:] == False)}")
print(f"Number of non-'-1' values in 'MMatch': {sum(matches_info['MMatch'][0,:] != -1)}")

print(f"Maximum number of 'nInVolume' over all volumes: {max(pumpprobe_brains_info['nInVolume'])}")
print(f"Length of all second axes of data objects (red/green signals and matches): {green_signal_info.data.shape[1]}")
print(f"Number of ROIs in the 30th frame (used to coregister): {pumpprobe_brains_info['nInVolume'][30]}")

# Conclusion: the 'coordZYX' of the signal pickle files do correspond to the 'nInVolume', but this does not
# itself match the ROI IDs used for data extraction (particular to 30th frame) and since no IDs are stored per coord
# They would have to be recomputed...