<jupyter_start><jupyter_text>Notebook to show the validate event pre-processing and formatting<jupyter_code>%matplotlib inline
from importlib import reload
from pathlib import Path

import numpy as np
import pandas as pd
pd.set_option('display.max_rows', None)

import matplotlib.pyplot as plt
import seaborn as sns
sns.set(style='whitegrid', palette='muted')

from types import SimpleNamespace

from TreeMazeAnalyses2.Analyses import subject_info as si
import TreeMazeAnalyses2.Analyses.tree_maze_functions as tmf
import Analyses.spatial_functions as spatial_funcs
import Utils.filter_functions as filter_funcs

from pykalman import KalmanFilter
import warnings
warnings.filterwarnings("ignore", category=DeprecationWarning)
warnings.filterwarnings("ignore", category=UserWarning)

subject = 'Li'
session = 'Li_T3g_070618'
si = reload(si)
overwrite=True
subject_info = si.SubjectInfo(subject, overwrite=overwrite)
# load a session
si = reload(si)
session_info = si.SubjectSessionInfo(subject, session)
tmf = reload(tmf)
b = tmf.BehaviorData(session_info, overwrite=True)
b.trial_table.head(10)
df = b.trial_table
perf = pd.DataFrame(index=[0])
perf['n_trials'] = df.shape[0]
perf['n_sw_trials'] = df.sw.sum()
perf['n_vsw_trials'] = df.vsw.sum()
perf['pct_correct'] = df.correct.mean()
perf['pct_sw_correct'] = (df.sw & df.correct).sum()/perf.n_sw_trials
perf['pct_vsw_correct'] = (df.vsw & df.correct).sum()/perf.n_vsw_trials
perf['n_L_trials'] = (df.cue=='L').sum()
perf['n_R_trials'] = (df.cue=='R').sum()
perf['pct_L_correct'] = ((df.cue=='L') & df.correct).sum() / perf.n_L_trials
perf['pct_R_correct'] = ((df.cue=='R') & df.correct).sum() / perf.n_R_trials
perf
perf = pd.DataFrame(index=[0])
perf['n_trials'] = df.shape[0]
perf
b.trial_table.head()
df = b.trial_table.copy()
df['sw'] = 0
df.loc[1:, 'sw'] = b.trial_table['cue'][:-1].values!=b.trial_table['cue'][1:].values


df['vsw'] = 0
df.loc[1:, 'vsw'] = (df['corr'][:-1].values) & (df['sw'][1:].values)

df = df.astype({'sw':'int', 'vsw':'int'})
df.head(20)
(df.cue=='L')
df['vsw'] = 0
df.loc[1:, 'vsw'] = (df['corr'][:-1].values) & (df['sw'][1:].values)

df.head(10)
b.event_table.head()
a = b.event_durs[b.event_durs.event=='CL'].copy()
a.reset_index(drop='True')
L_trials = b.trial_table[b.trial_table.dec=='L']
L_trials.index.values
a = b.event_durs.loc[b.event_durs.event=='RW2', ['tE', 'trial_num']].copy()
tmf = reload(tmf)
b = tmf.BehaviorData(session_info)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.18518518518518517, 'fraction_numerical': 0.013024013024013023, 'mean_word_length': 6.753943217665615, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '172556', 'license': 'MIT', 'n_tokens_mistral': 1029, 'n_tokens_neox': 977, 'n_words': 171, 'path': 'Notebooks/TM/event_pre-processing.ipynb', 'repo_name': 'alexgonzl/TreeMazeAnalyses2', 'size': '2457'}