Source code for allensdk.brain_observatory.behavior.data_objects.stimuli.util

import warnings
from pathlib import Path

from allensdk.brain_observatory.behavior.data_files import SyncFile
from allensdk.brain_observatory.behavior.data_objects.metadata \
    .behavior_metadata.equipment import \
    Equipment
from allensdk.internal.brain_observatory.time_sync import OphysTimeAligner


[docs] def convert_filepath_caseinsensitive(filename_in): return filename_in.replace('TRAINING', 'training')
[docs] def get_image_set_name(image_set_path: str) -> str: """ Strips the stem from the image_set filename """ return Path(image_set_path).stem
[docs] def calculate_monitor_delay(sync_file: SyncFile, equipment: Equipment) -> float: """Calculates monitor delay using sync file. If that fails, looks up monitor delay from known values for equipment. Raises -------- RuntimeError If input equipment is unknown """ aligner = OphysTimeAligner(sync_file=sync_file.filepath) try: delay = aligner.monitor_delay except ValueError as ee: equipment_name = equipment.value warning_msg = 'Monitory delay calculation failed ' warning_msg += 'with ValueError\n' warning_msg += f' "{ee}"' warning_msg += '\nlooking monitor delay up from table ' warning_msg += f'for rig: {equipment_name} ' # see # https://github.com/AllenInstitute/AllenSDK/issues/1318 # https://github.com/AllenInstitute/AllenSDK/issues/1916 delay_lookup = {'CAM2P.1': 0.020842, 'CAM2P.2': 0.037566, 'CAM2P.3': 0.021390, 'CAM2P.4': 0.021102, 'CAM2P.5': 0.021192, 'MESO.1': 0.03613, # TODO update with actual monitor delay once calculated 'MESO.2': 0.03613} if equipment_name not in delay_lookup: msg = warning_msg msg += f'\nequipment_name {equipment_name} not in lookup table' raise RuntimeError(msg) delay = delay_lookup[equipment_name] warning_msg += f'\ndelay: {delay} seconds' warnings.warn(warning_msg) return delay