|
@@ -2,7 +2,7 @@
|
|
|
"cells": [
|
|
|
{
|
|
|
"cell_type": "code",
|
|
|
- "execution_count": 136,
|
|
|
+ "execution_count": 31,
|
|
|
"metadata": {},
|
|
|
"outputs": [],
|
|
|
"source": [
|
|
@@ -50,16 +50,16 @@
|
|
|
},
|
|
|
{
|
|
|
"cell_type": "code",
|
|
|
- "execution_count": 137,
|
|
|
+ "execution_count": 32,
|
|
|
"metadata": {},
|
|
|
"outputs": [],
|
|
|
"source": [
|
|
|
- "cfg_filename = os.path.join('profiles', 'andrey_hippoSIT_008228_continuous.json')"
|
|
|
+ "cfg_filename = os.path.join('profiles', 'andrey_hippoSIT_008229_multiple.json')"
|
|
|
]
|
|
|
},
|
|
|
{
|
|
|
"cell_type": "code",
|
|
|
- "execution_count": 138,
|
|
|
+ "execution_count": 33,
|
|
|
"metadata": {
|
|
|
"scrolled": false
|
|
|
},
|
|
@@ -75,7 +75,7 @@
|
|
|
},
|
|
|
{
|
|
|
"cell_type": "code",
|
|
|
- "execution_count": 139,
|
|
|
+ "execution_count": 34,
|
|
|
"metadata": {},
|
|
|
"outputs": [],
|
|
|
"source": [
|
|
@@ -97,7 +97,7 @@
|
|
|
},
|
|
|
{
|
|
|
"cell_type": "code",
|
|
|
- "execution_count": 140,
|
|
|
+ "execution_count": 35,
|
|
|
"metadata": {},
|
|
|
"outputs": [],
|
|
|
"source": [
|
|
@@ -137,7 +137,7 @@
|
|
|
},
|
|
|
{
|
|
|
"cell_type": "code",
|
|
|
- "execution_count": 141,
|
|
|
+ "execution_count": 36,
|
|
|
"metadata": {},
|
|
|
"outputs": [],
|
|
|
"source": [
|
|
@@ -155,7 +155,7 @@
|
|
|
},
|
|
|
{
|
|
|
"cell_type": "code",
|
|
|
- "execution_count": 142,
|
|
|
+ "execution_count": 37,
|
|
|
"metadata": {},
|
|
|
"outputs": [],
|
|
|
"source": [
|
|
@@ -194,7 +194,7 @@
|
|
|
},
|
|
|
{
|
|
|
"cell_type": "code",
|
|
|
- "execution_count": 143,
|
|
|
+ "execution_count": 38,
|
|
|
"metadata": {},
|
|
|
"outputs": [],
|
|
|
"source": [
|
|
@@ -224,7 +224,7 @@
|
|
|
},
|
|
|
{
|
|
|
"cell_type": "code",
|
|
|
- "execution_count": 144,
|
|
|
+ "execution_count": 39,
|
|
|
"metadata": {},
|
|
|
"outputs": [],
|
|
|
"source": [
|
|
@@ -234,7 +234,7 @@
|
|
|
},
|
|
|
{
|
|
|
"cell_type": "code",
|
|
|
- "execution_count": 145,
|
|
|
+ "execution_count": 40,
|
|
|
"metadata": {},
|
|
|
"outputs": [],
|
|
|
"source": [
|
|
@@ -245,7 +245,7 @@
|
|
|
},
|
|
|
{
|
|
|
"cell_type": "code",
|
|
|
- "execution_count": 146,
|
|
|
+ "execution_count": 41,
|
|
|
"metadata": {},
|
|
|
"outputs": [],
|
|
|
"source": [
|
|
@@ -260,7 +260,7 @@
|
|
|
},
|
|
|
{
|
|
|
"cell_type": "code",
|
|
|
- "execution_count": 147,
|
|
|
+ "execution_count": 42,
|
|
|
"metadata": {},
|
|
|
"outputs": [],
|
|
|
"source": [
|
|
@@ -286,17 +286,18 @@
|
|
|
},
|
|
|
{
|
|
|
"cell_type": "code",
|
|
|
- "execution_count": null,
|
|
|
+ "execution_count": 43,
|
|
|
"metadata": {
|
|
|
- "scrolled": false
|
|
|
+ "scrolled": true
|
|
|
},
|
|
|
"outputs": [
|
|
|
{
|
|
|
"name": "stdout",
|
|
|
"output_type": "stream",
|
|
|
"text": [
|
|
|
- "Continuous sound stream started at 48000 Hz\n",
|
|
|
- "Webcam stream 1024.0:768.0 at 25.00 FPS started\n",
|
|
|
+ "Webcam stream 1024.0:768.0 at 30.00 FPS started\n",
|
|
|
+ "Position tracker - background reloaded\n",
|
|
|
+ "Position tracker - background reloaded\n",
|
|
|
"Position tracker stopped\n",
|
|
|
"Video writer stopped\n",
|
|
|
"Camera released\n"
|
|
@@ -304,8 +305,10 @@
|
|
|
}
|
|
|
],
|
|
|
"source": [
|
|
|
- "# actual sound selector: 0 - silence, 1 - foraging, 2 - target, 3 - distractor\n",
|
|
|
+ "# actual sound selector: -1 - noise, 0 - silence, 1 - foraging, 2 - target, 3 - distractor\n",
|
|
|
"sound = mp.Value('i', 1)\n",
|
|
|
+ "if 'noise_when_idle' in cfg_exp and cfg_exp['noise_when_idle']:\n",
|
|
|
+ " sound.value = -1\n",
|
|
|
"\n",
|
|
|
"# experiment status: 1 - idle, 2 - running (recording, logging), 0 - stopped\n",
|
|
|
"status = mp.Value('i', 1)\n",
|
|
@@ -401,7 +404,7 @@
|
|
|
" #frame = cv2.absdiff(frame, pt.background)\n",
|
|
|
" #frame = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)\n",
|
|
|
" frame = cv2.bitwise_and(src1=frame, src2=pt.mask)\n",
|
|
|
- " #frame_copy = frame.copy()\n",
|
|
|
+ " frame_copy = frame.copy()\n",
|
|
|
"\n",
|
|
|
" # draw position center and contours\n",
|
|
|
" if pt.x_in_px is not None:\n",
|
|
@@ -581,13 +584,24 @@
|
|
|
" \n",
|
|
|
" k = cv2.waitKey(33)\n",
|
|
|
" \n",
|
|
|
+ " # light on/off\n",
|
|
|
" if k == ord('l'):\n",
|
|
|
" switch_light(pt, board)\n",
|
|
|
" \n",
|
|
|
+ " # motors\n",
|
|
|
" if k == ord('d'):\n",
|
|
|
" if cfg['experiment']['enable_motors']:\n",
|
|
|
" motor_board.switch_diodes()\n",
|
|
|
" \n",
|
|
|
+ " if k == ord('t'):\n",
|
|
|
+ " tm = threading.Timer(20, motor_board.rotate, args=(False, 90, 30))\n",
|
|
|
+ " tm.start()\n",
|
|
|
+ " #motor_board.rotate(False, 90, 30)\n",
|
|
|
+ " if k == ord('r'):\n",
|
|
|
+ " tm = threading.Timer(20, motor_board.rotate, args=(True, 90, 30))\n",
|
|
|
+ " tm.start()\n",
|
|
|
+ " \n",
|
|
|
+ " # ephys cable on top\n",
|
|
|
" if k == ord('i') and 'cable_motor_port' in cfg['experiment']:\n",
|
|
|
" tf = threading.Timer(0, cable_board.turn_CCW, args=[])\n",
|
|
|
" tf.start()\n",
|
|
@@ -595,20 +609,29 @@
|
|
|
" tf = threading.Timer(0, cable_board.turn_CW, args=[])\n",
|
|
|
" tf.start()\n",
|
|
|
" \n",
|
|
|
+ " # feeding\n",
|
|
|
" if k == ord('f'):\n",
|
|
|
" tf = threading.Timer(0, board.feed, args=[])\n",
|
|
|
" tf.start()\n",
|
|
|
"\n",
|
|
|
" if k == ord('c'):\n",
|
|
|
" f_name = cfg_pos['background_light'] if pt.is_light else cfg_pos['background_dark']\n",
|
|
|
- " cv2.imwrite(os.path.join('assets', f_name), frame_copy)\n",
|
|
|
+ " cv2.imwrite(f_name, frame_copy)\n",
|
|
|
+ " tf = threading.Timer(0.2, pt.reload_background, args=[])\n",
|
|
|
+ " tf.start() \n",
|
|
|
"\n",
|
|
|
+ " # quit the session\n",
|
|
|
" if k == ord('q'):\n",
|
|
|
" break\n",
|
|
|
"\n",
|
|
|
+ " # start the experiment\n",
|
|
|
" if k == ord('s'):\n",
|
|
|
" board.start_or_stop() # start/stop data acquisition\n",
|
|
|
" c_time = time.time() # more accurate time\n",
|
|
|
+ " \n",
|
|
|
+ " if cfg['experiment']['enable_motors']:\n",
|
|
|
+ " if not motor_board.diodes_on:\n",
|
|
|
+ " motor_board.switch_diodes()\n",
|
|
|
"\n",
|
|
|
" if status.value == 1: # start the session\n",
|
|
|
" if t_start is None:\n",
|
|
@@ -639,12 +662,12 @@
|
|
|
" timers.append(threading.Timer(event_t, switch_light, args=(pt, board)))\n",
|
|
|
" \n",
|
|
|
" if cfg['experiment']['enable_motors']:\n",
|
|
|
- " motor_board.switch_diodes()\n",
|
|
|
- " if cfg['experiment']['phi_max'] > 0:\n",
|
|
|
+ " if not cfg['experiment']['phi_max'] == 0:\n",
|
|
|
+ " direction = False if cfg['experiment']['phi_max'] > 0 else True\n",
|
|
|
" t0, t1 = cfg['experiment']['timepoints'][0], cfg['experiment']['timepoints'][1]\n",
|
|
|
- " timers.append(threading.Timer(t0, motor_board.rotate, args=(False, cfg['experiment']['phi_max'], t1-t0)))\n",
|
|
|
+ " timers.append(threading.Timer(t0, motor_board.rotate, args=(direction, abs(cfg['experiment']['phi_max']), t1-t0)))\n",
|
|
|
" t0, t1 = cfg['experiment']['timepoints'][2], cfg['experiment']['timepoints'][3]\n",
|
|
|
- " timers.append(threading.Timer(t0, motor_board.rotate, args=(True, cfg['experiment']['phi_max'], t1-t0)))\n",
|
|
|
+ " timers.append(threading.Timer(t0, motor_board.rotate, args=(not direction, abs(cfg['experiment']['phi_max']), t1-t0)))\n",
|
|
|
" \n",
|
|
|
" for t in timers:\n",
|
|
|
" t.start()\n",
|
|
@@ -657,6 +680,8 @@
|
|
|
" x, y, r = 0, 0, 0\n",
|
|
|
" log_event(c_time, x, y, r, trial, -1) # log experiment break\n",
|
|
|
" \n",
|
|
|
+ " if 'noise_when_idle' in cfg_exp and cfg_exp['noise_when_idle']:\n",
|
|
|
+ " sound.value = -1\n",
|
|
|
" status.value = 1\n",
|
|
|
" phase = 0\n",
|
|
|
" islands = []\n",
|
|
@@ -664,7 +689,8 @@
|
|
|
" t.cancel()\n",
|
|
|
" \n",
|
|
|
" if k == ord('a'):\n",
|
|
|
- " sound.value = 0 if sound.value == 1 else 1\n",
|
|
|
+ " sound.value = -1 if sound.value >= 0 else 0\n",
|
|
|
+ " switch_light(pt, board) # turn lights off \n",
|
|
|
"\n",
|
|
|
"finally:\n",
|
|
|
" if status.value == 2: # stop data acquisition, in case exited via timeout\n",
|
|
@@ -712,7 +738,7 @@
|
|
|
},
|
|
|
{
|
|
|
"cell_type": "code",
|
|
|
- "execution_count": null,
|
|
|
+ "execution_count": 44,
|
|
|
"metadata": {},
|
|
|
"outputs": [],
|
|
|
"source": [
|
|
@@ -723,9 +749,19 @@
|
|
|
},
|
|
|
{
|
|
|
"cell_type": "code",
|
|
|
- "execution_count": null,
|
|
|
+ "execution_count": 45,
|
|
|
"metadata": {},
|
|
|
- "outputs": [],
|
|
|
+ "outputs": [
|
|
|
+ {
|
|
|
+ "ename": "SystemExit",
|
|
|
+ "evalue": "Nothing recorded. No sense to continue.",
|
|
|
+ "output_type": "error",
|
|
|
+ "traceback": [
|
|
|
+ "An exception has occurred, use %tb to see the full traceback.\n",
|
|
|
+ "\u001b[1;31mSystemExit\u001b[0m\u001b[1;31m:\u001b[0m Nothing recorded. No sense to continue.\n"
|
|
|
+ ]
|
|
|
+ }
|
|
|
+ ],
|
|
|
"source": [
|
|
|
"if not trial > 0:\n",
|
|
|
" raise SystemExit('Nothing recorded. No sense to continue.')\n",
|