Skip to content

New folder structure #36

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 29 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
a352f37
Restructured, some path issues still
pankajkgupta Mar 9, 2020
419ec00
Fixed menu 2 this deserves a commit
pankajkgupta Mar 10, 2020
4aae7fe
fixed class/module issue in AHF_Task
pankajkgupta Mar 10, 2020
d1bcfe6
Changing class menu works, fixed mouse config path
Alice-Xiong Mar 11, 2020
22e1281
fixed inheritance broken by path
Alice-Xiong Mar 12, 2020
f99f3b9
started camera stream
pankajkgupta Mar 13, 2020
bc7f703
Camera setup for closed_loop
pankajkgupta Mar 24, 2020
ed86014
updated documentation site with new structure
Alice-Xiong Apr 6, 2020
cff1d21
modified web paths for hosting
Alice-Xiong Apr 6, 2020
c58c620
configs video
Alice-Xiong Apr 6, 2020
aa72d42
Added closed loop stimulator
Alice-Xiong Apr 14, 2020
1dca53e
updated documentation
Alice-Xiong Apr 16, 2020
0afdebf
fixed video path issues
Alice-Xiong Apr 17, 2020
93578cc
tested closed_loop structure
Alice-Xiong Apr 15, 2020
92e976b
Fixed saving mice and --temp bugs
Judge24601 Apr 16, 2020
2294a0d
Clean up configs and fixed return to trials
Alice-Xiong Apr 16, 2020
1e85b57
fixed return menu
Judge24601 Apr 17, 2020
79018da
Merge pull request #35 from Alice-Xiong/master
Alice-Xiong Apr 17, 2020
dc187ed
merged master changes
Alice-Xiong Apr 18, 2020
5f3d4fa
clean up bugs
Alice-Xiong Apr 18, 2020
d44ba87
Added config instructions
Alice-Xiong Apr 21, 2020
9f7b4d2
Updated camera stream class, untested
Alice-Xiong Apr 23, 2020
c12cb31
small camera stream changes
Alice-Xiong Apr 24, 2020
812d8f0
camera paths and config settings
Alice-Xiong Apr 25, 2020
6dc5de5
Merge branch 'closed_loop' of https://github.com/ubcbraincircuits/Aut…
Alice-Xiong Apr 25, 2020
edb9acd
Added laser documentation
Alice-Xiong May 1, 2020
515ab50
More laser documents and small menu fix
Alice-Xiong May 2, 2020
6c100e9
generated html from docs
Alice-Xiong May 2, 2020
2dd71b7
moved html files for git hosting
Alice-Xiong May 2, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
15 changes: 15 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Run main",
"type": "python",
"request": "launch",
"program": "${workspaceFolder}/__main__2.py",
"console": "integratedTerminal"
}
]
}
7 changes: 5 additions & 2 deletions AHF_BrainLight.py → AHF_BrainLight/AHF_BrainLight.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
#! /usr/bin/python3
#-*-coding: utf-8 -*-

import sys
sys.path.append("../..")

from abc import ABCMeta, abstractmethod
from time import sleep
from AHF_Base import AHF_Base
from AutoHeadFix.AHF_Base import AHF_Base

class AHF_BrainLight(AHF_Base, metaclass = ABCMeta):

Expand All @@ -21,7 +24,7 @@ def config_user_get(starterDict = {}):


@abstractmethod
def onForStim(self):
def onForStim(self):
"""
Runs when headFixing starts, illuminating the brain or whatever needs illuminating
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import RPi.GPIO as GPIO
from time import sleep
from _thread import start_new_thread
from AHF_BrainLight import AHF_BrainLight
from AHF_BrainLight.AHF_BrainLight import AHF_BrainLight

class AHF_BrainLight_1GPIO(AHF_BrainLight):

Expand Down Expand Up @@ -60,7 +60,7 @@ def offForStim(self):
super().offForStim()
if self.ledDelay > 0:
sleep(self.ledDelay)
GPIO.output(self.ledPin, GPIO.LOW)
GPIO.output(self.ledPin, GPIO.LOW)



Empty file added AHF_BrainLight/__init__.py
Empty file.
6 changes: 5 additions & 1 deletion AHF_Camera.py → AHF_Camera/AHF_Camera.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
#! /usr/bin/python3
#-*-coding: utf-8 -*-

import sys
sys.path.append("../..")

from abc import ABCMeta, abstractmethod
import os
import inspect
from AHF_Base import AHF_Base
from AutoHeadFix.AHF_Base import AHF_Base

class AHF_Camera(AHF_Base, metaclass = ABCMeta):
"""
Expand Down
15 changes: 7 additions & 8 deletions AHF_Camera_PiCam.py → AHF_Camera/AHF_Camera_PiCam.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#! /usr/bin/python3
#-*-coding: utf-8 -*-

from AHF_Camera import AHF_Camera
from AHF_Camera.AHF_Camera import AHF_Camera
from picamera import PiCamera
import time
from datetime import datetime
Expand Down Expand Up @@ -182,19 +182,19 @@ def set_gain(self):
def capture(self, path, type, video_port =False):
self.piCam.capture(path, type, use_video_port=video_port)

def start_recording(self, video_name_path):
def start_recording(self, video_name):
"""
Starts a video recording using the saved settings for format, quality, gain, etc.

A preview of the recording is always shown

:param video_name_path: a full path to the file where the video will be stored. Always save to a file, not a PIL, for, example
:param video_name: Name of saved recording. Always save to a file, not a PIL, for, example
"""
video_name = self.video_path+video_name_path
video_name_full = self.video_path+video_name
if self.AHFvideoFormat == 'rgb':
self.piCam.start_recording(output=video_name, format=self.AHFvideoFormat)
self.piCam.start_recording(output=video_name_full, format=self.AHFvideoFormat)
else:
self.piCam.start_recording(output=video_name, format = self.AHFvideoFormat, quality = self.AHFvideoQuality)
self.piCam.start_recording(output=video_name_full, format = self.AHFvideoFormat, quality = self.AHFvideoQuality)
self.piCam.start_preview(fullscreen = False, window= self.AHFpreview)
return

Expand All @@ -220,14 +220,13 @@ def stop_recording(self):
self.piCam.stop_preview()
return

def timed_recording(self, video_name_path, recTime):
def timed_recording(self, recTime):
"""
Does a timed video recording using the PiCamera wait_recording function.

A preview of the recording is always shown

Control does not pass back to the calling function until the recording is finished
:param video_name_path: a full path to the file where the video will be stored.
:param recTime: duration of the recorded video, in seconds
"""
if self.AHFvideoFormat == 'rgb':
Expand Down
235 changes: 235 additions & 0 deletions AHF_Camera/AHF_Camera_PiStream.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,235 @@
#! /usr/bin/python3
#-*-coding: utf-8 -*-

from picamera.array import PiRGBArray
from picamera import PiCamera
import numpy as np
import cv2
import imutils
from imutils.video import FPS
import time
from datetime import datetime
import wiringpi as wpi
import os
import tables
import csv
import io
from AHF_Camera.AHF_Camera import AHF_Camera
from picamera import PiCamera
from time import sleep
from threading import Thread

class AHF_Camera_PiStream(AHF_Camera):

@staticmethod
def about():
return 'uses picamera.PiCamera to run the standard Raspberry Pi camera, recording by frame'

@staticmethod
def config_user_get(starterDict = {}):
defaultFormat = 'hdf5'
defaultRes =(640,480)
defaultQuality = 20
defaultSensorMode = 4
defaultFrameRate = 30
defaultISO = 200
defaultShutterSpeed = 30000
defaultPath = '/home/Pi/Videos/'

# video path
video_path = starterDict.get('video_path', defaultPath)
tempInput = input('Set Video path for recording movies(currently ' + video_path + ') to :')
if tempInput != '':
video_path = tempInput
starterDict.update({'video_path' : video_path})
# videoFormat
videoFormat = starterDict.get('format', defaultFormat)
tempInput = input('Set Video format for recording movies(currently ' + videoFormat + ') to :')
if tempInput != '':
videoFormat = tempInput
starterDict.update({'format' : videoFormat})
# quality
quality = starterDict.get('quality', defaultQuality)
tempInput = input('Set Video quality for h264 movies, best=1, worst =40,0 for auto(currently ' + str(quality) + ') to :')
if tempInput != '':
quality = int(tempInput)
starterDict.update({'quality' : quality})
# resolution
resolution = starterDict.get('resolution', defaultRes)
tempInput = input('set X,Y resolution(currently {0}): '.format(resolution))
if tempInput != '':
resolution = tuple(int(x) for x in tempInput.split(','))
starterDict.update({'resolution' : resolution})
# framerate
frameRate = starterDict.get('framerate', defaultFrameRate)
tempInput = input('Set Frame rate in Hz of recorded movie(currently {0}): '.format(frameRate))
if tempInput != '':
frameRate = float(tempInput)
starterDict.update({'framerate' : frameRate})
# ISO
iso = starterDict.get('iso', defaultISO)
tempInput = input('Set ISO for video, or 0 to auto set gains(currently ' + str(iso) + ') to :')
if tempInput != '':
iso = int(tempInput)
starterDict.update({'iso' : iso})
# shutter speed
shutter_speed = starterDict.get('shutter_speed', defaultShutterSpeed)
tempInput = input('Set Shutter speed(in microseconds) for recorded video(currently ' + str(shutter_speed) + ') to :')
if tempInput != '':
shutter_speed= int(tempInput)
starterDict.update({'shutter_speed' : shutter_speed})
# Sensor mode
sensor_mode = starterDict.get('sensor_mode', defaultSensorMode)
tempInput = input('Set sensor mode for recording (currently ' + str(sensor_mode) + ') to :')
if tempInput != '':
sensor_mode= int(tempInput)
starterDict.update({'sensor_mode' : sensor_mode})
# preview window
previewWin = starterDict.get('previewWin',(0,0,640,480))
tempInput = input('Set video preview window, left, top, right, bottom,(currently ' + str(previewWin) + ') to :')
if tempInput != '':
previewWin = tuple(int(x) for x in tempInput.split(','))
starterDict.update({'previewWin' : previewWin})
# white balance
whiteBalance = starterDict.get('whiteBalance', False)
tempInput = input('Set white balancing for video, 1 for True, or 0 for False(currently ' + str(whiteBalance) + ') to :')
if tempInput !='':
tempInput = bool(int(tempInput))
starterDict.update({'whiteBalance' : whiteBalance})
# return already modified dictionary, needed when making a new dictionary
return starterDict


def setup(self):
# Set up text file and paths
self.data_path = self.settingsDict.get('data_path', '/home/Pi/Videos/closed_loop/')
# Create pi camera objecy
try:
self.piCam = PiCamera()
except Exception as anError:
print("Error initializing camera.." + str(anError))
raise anError
# set fields in Picamera
self.piCam.resolution = self.settingsDict.get('resolution',(640, 480))
self.piCam.framerate = self.settingsDict.get('framerate', 30)
self.piCam.iso = self.settingsDict.get('iso', 0)
self.piCam.shutter_speed = self.settingsDict.get('shutter_speed', 30000)
self.piCam.sensor_mode = self.settingsDict.get('sensor_mode', 4)
# turn off LED on camera
self.piCam.led = False

# set fields that are in AHF_Camera class
self.AHFvideoFormat = self.settingsDict.get('format', 'hdf5')
self.AHFvideoQuality = self.settingsDict.get('quality', 20)
self.AHFframerate= self.settingsDict.get('framerate', 30)
self.AHFpreview = self.settingsDict.get('previewWin',(0,0,640,480))
whiteBalance = self.settingsDict.get('whiteBalance', False)

# set gain
self.cfgDict = self.settingsDict.get('cfgDict', '')
if 'dff_history' in self.cfgDict:
while True:
if(self.piCam.analopiCg_gain>=7.0 and
self.piCam.analog_gain<=8.0 and
self.piCam.digital_gain>=1 and
self.piCam.digital_gain<=1.5):
self.piCam.exposure_mode='off'
print("ok")
break
else:
print('analog gain: ' + str(eval(str(self.piCam.analog_gain))))
print('digital gain: ' + str(eval(str(self.piCam.digital_gain))))


self.is_recording = False
self.stopped = False
self.rawCapture = PiRGBArray(self.piCam, size=self.resolution())

# Allow the camera to warmup
time.sleep(0.1)
print("done initializing!")
return

def resolution(self):
return self.piCam.resolution

def setdown(self):
"""
Writes session end and closes log file
"""
self.piCam.close()
pass


def update(self):
if self.data_path:
self.piCam.start_recording(self.data_path, format='rgb')
for f in self.stream:
start = time.time()
# grab the frame from the stream and clear the stream in
# preparation for the next frame
self.frame = f.array
self.rawCapture.seek(0)

# if the thread indicator variable is set, stop the thread
# and resource camera resources
if self.stopped:
self.stream.close()
if self.data_path:
self.piCam.stop_recording()
self.rawCapture.close()
self.piCam.close()
return
time.sleep(max(0.5/(self.piCam.framerate) - (time.time() - start), 0.0))


def start_recording(self):
"""
"""
self.start_preview()
self.is_recording = True
self.frame = None
t = Thread(target=self.update, args=())
t.daemon = True
t.start()
return self

def start_preview(self):
self.piCam.start_preview(fullscreen = False, window= self.AHFpreview)

def stop_preview(self):
self.piCam.stop_preview()

def stop_recording(self):
"""
Stops a video recording previously started with start_recording.
"""
if self.is_recording:
self.stopped = False
return

def hardwareTest(self):
"""
Tests functionality, gives user a chance to change settings
"""
while(True):
inputStr = input('p=display preview, r=record for 10 seconds, t= edit task settings, q= quit: ')
if inputStr == 'p':
print('Now displaying current output')
self.piCam.start_preview(fullscreen = False, window=self.AHFpreview)
result = input('Press any key to stop')
self.piCam.stop_preview()
elif inputStr == 'r':
print("Starting recording for 10 seconds")
self.start_recording()
time.sleep(10)
self.stop_recording()
elif inputStr == 't':
self.setdown()
self.settingsDict = self.config_user_get(self.settingsDict)
self.setup()
elif inputStr == 'q':
break
pass


Empty file added AHF_Camera/__init__.py
Empty file.
Loading