points_spacing=1, restrict_extremities=False, apply_extra_spacing=False, ) # %% # load and clean complete bouts _bouts = pd.read_hdf(paths.analysis_folder / "behavior" / "saved_data" / f"complete_bouts.h5") _bouts = _bouts.loc[(_bouts.start_roi == 0) & (_bouts.duration < 8)] _bouts = _bouts.sort_values("duration") # .iloc[:5] print(f"Kept {len(_bouts)} bouts") bouts = [] for i, bout in track(_bouts.iterrows()): bouts.append(LocomotionBout(bout, linearize_to=center_line)) # %% f = plt.figure(figsize=(12, 12)) axes = f.subplot_mosaic(""" AAADDD AAAEEE AAAFFF BBBGGG CCCHHI """) f.tight_layout() _ = draw.Hairpin(ax=axes["A"]) for n, bout in enumerate(bouts): # draw 2d and linearized tracking
) recorder.start(base_folder=folder.parent, folder_name=folder.name, timestamp=False) # %% # load and clean complete bouts _bouts = pd.read_hdf(paths.analysis_folder / "behavior" / "saved_data" / f"complete_bouts.h5") _bouts = _bouts.loc[_bouts.start_roi == 0] _bouts = _bouts.sort_values("duration").iloc[:10] print(f"Kept {len(_bouts)} bouts") bouts = [] for i, bout in _bouts.iterrows(): bouts.append(LocomotionBout(bout)) # %% ( left_line, center_line, right_line, left_to_track, center_to_track, right_to_track, control_points, ) = track.extract_track_from_image( points_spacing=1, restrict_extremities=False, apply_extra_spacing=False, )
# %% ROI = "T2" bouts = pd.read_hdf( paths.analysis_folder / "behavior" / "saved_data" / f"{ROI}_crossings.h5" ).sort_values("duration") bouts = bouts.loc[bouts.duration < 1.5].iloc[:200] print(f"Kept {len(bouts)} bouts") # %% # get clean paths crosses = [] for i, cross in bouts.iterrows(): crosses.append(LocomotionBout(cross)) # %% f = plt.figure(figsize=(20, 10)) axes = f.subplot_mosaic( """ AAABBDDFFF AAACCEEFFF """ ) draw.ROI( ROI, ax=axes["A"], set_ax=True,
# load and clean roi crossings ROI = "T2" MIN_DUR = 1.5 USE = 100 _bouts = pd.read_hdf(paths.analysis_folder / "behavior" / "saved_data" / f"{ROI}_crossings.h5").sort_values("duration") _l = len(_bouts) _bouts = _bouts.loc[_bouts.duration <= MIN_DUR] _bouts = _bouts.iloc[:USE] print(f"Kept {len(_bouts)}/{_l} bouts") crosses = [] for i, bout in _bouts.iterrows(): crosses.append(LocomotionBout(bout)) # %% # ---------------------------------------------------------------------------- # # first plot - sanity checks # # ---------------------------------------------------------------------------- # """ Plot tracking over threshold crossings for sanity checks """ colors = dict(velocity=blue_dark, acceleration=pink) f, axes = plt.subplots(figsize=(16, 10), ncols=2) for ax in axes: draw.ROI(ROI, set_ax=True, ax=ax) f._save_name = f"vector_field_{ROI}"
& 'is_recording=1').fetch('name') logger.info(f'Found {len(sessions)} recordings') # filter bouts in recordings for session in sessions: bouts = _bouts.loc[_bouts['name'] == session] if not bouts.empty: print(f'{session} - Found: ', len(bouts), ' ROI crossings') else: print(f'{session} ---- EMPTY') # select a session session = 'FC_210721_AAA1110750_hairpin' bouts = _bouts.loc[_bouts['name'] == session] bouts = [LocomotionBout(bout) for i, bout in bouts.iterrows()] # %% # ----------------------------- load probe/units ----------------------------- # logger.info('fetching units') recording = (db_tables.Recording & f'name="{session}"').fetch(as_dict=True)[0] cf = recording['recording_probe_configuration'] logger.info("Fetching ephys data") units = db_tables.Unit.get_session_units( session, cf, spikes=True, firing_rate=True, frate_window=100, ) units['probe_configuration'] = [cf] * len(units)