|
| 1 | +# from aind_dynamic_foraging_multisession_analysis import multisession_plot as ms_plot |
| 2 | +# from aind_dynamic_foraging_data_utils import nwb_utils as nu |
| 3 | +### Notes |
| 4 | +# Make a function that adds trial vector of decision points in autoport |
| 5 | +# Then we can just pass into normal plotting functions |
| 6 | + |
| 7 | + |
| 8 | +def annotate_autolickport(nwb): |
| 9 | + """ |
| 10 | + annotates decision points, and decisions to move |
| 11 | + """ |
| 12 | + |
| 13 | + # TODO Add input option for this |
| 14 | + params = { |
| 15 | + "max_water_reward_attempts": 10, |
| 16 | + "trial_interval": 50, |
| 17 | + "bias_upper_threshold": 0.7, |
| 18 | + "bias_lower_threshold": 0.3, |
| 19 | + "lick_spout_movement": {"range_um": 300.0, "step_size_um": 50.0}, |
| 20 | + } |
| 21 | + |
| 22 | + # TODO add check for df_trials exisitence |
| 23 | + df = nwb.df_trials.copy() |
| 24 | + |
| 25 | + last_bias_intervention = 0 |
| 26 | + water_reward_attempts = 0 |
| 27 | + autoport_check =[] |
| 28 | + autoport_water = [] |
| 29 | + autoport_movement = [] |
| 30 | + for trial_number in range(len(df)): |
| 31 | + this_check=False |
| 32 | + this_water=False |
| 33 | + this_movement=False |
| 34 | + if params["trial_interval"] <= trial_number - last_bias_intervention: |
| 35 | + this_check=True |
| 36 | + if abs(df.loc[trial_number]["side_bias"]) > params["bias_upper_threshold"]: |
| 37 | + last_bias_intervention = trial_number |
| 38 | + |
| 39 | + # first try water intervention |
| 40 | + if water_reward_attempts < params["max_water_reward_attempts"]: |
| 41 | + print(f"Bias over threshold. Attempting water intervention.") |
| 42 | + this_water = True |
| 43 | + else: |
| 44 | + print(f"Maximum watering attempts exceeded. Moving lickspouts for bias. ") |
| 45 | + water_reward_attempts = 0 |
| 46 | + this_movement=True |
| 47 | + autoport_check.append(this_check) |
| 48 | + autoport_water.append(this_water) |
| 49 | + autoport_movement.append(this_movement) |
| 50 | + df['autoport_check'] = autoport_check |
| 51 | + df['autoport_water'] = autoport_water |
| 52 | + df['autoport_movement'] = autoport_movement |
| 53 | + return df |
0 commit comments