import cv2 as cv import numpy as np from hdf5manager import hdf5manager as h5 import matplotlib.cm as cm pMatrix = h5("Outputs/P5_MatrixData_full_interp.hdf5").load()['pMatrix'] cv.namedWindow('image') def callback(x): cutoff = x / 1000 print("Cutoff:", cutoff) img = np.zeros((pMatrix.shape[0], pMatrix.shape[1], 3), dtype="uint8") mult = 2 # preMatrix = np.zeros_like(pMatrix, dtype=bool) # preMatrix[pMatrix < cutoff] = True # preMatrix[pMatrix > 1 - cutoff] = True # fullImg = np.empty((preMatrix.shape[0] * 2, preMatrix.shape[1] * 3), dtype='uint8') # btmX = 0 # btmY = 0 # topY = preMatrix.shape[0] # for i in range(1, 4): # topX = btmX + preMatrix.shape[1] # fullImg[btmY:topY, btmX:topX] = preMatrix[:,:,i] # btmX = topX # btmY = topY # topY = btmY + preMatrix.shape[0]
from hdf5manager import hdf5manager as h5 import numpy as np import cv2 as cv import time import math f = h5("mouse_vectors.hdf5").load() contour_data = f["contour_data"].astype("int32") n_contours = f["n_contours"] mv = np.empty((contour_data.shape[0], 480, 640, 3), dtype='uint8') prev_frame = contour_data[0, :n_contours[0]] for i in range(contour_data.shape[0]): n = n_contours[i] for x, y in contour_data[i, :n]: min_v = (0, 0) min_dist = (1000**2) * 2 min_pos = (0, 0) for x2, y2 in prev_frame: dx = x2 - x dy = y2 - y dist = dx * dx + dy * dy if (dist < min_dist): min_dist = dist min_v = (dx, dy) min_pos = (x2, y2) cv.line(mv[i], (x, y), (x + min_v[0], y + min_v[1]), (0, 255, 0)) cv.circle(mv[i], min_pos, 3, (0, 0, 255), -1)
import time import numpy as np from matplotlib import pyplot as plt from hdf5manager import hdf5manager as h5 from derivativeEventDetection import detectSpikes from eventCharacterization import eventCharacterization f = h5("P2_timecourses.hdf5").load() brain_data = f["brain"] numRows = brain_data.shape[0] batches = 10000 na = 140 nb = 115 all_start_spikes = [] all_end_spikes = [] total_start_events = 0 total_end_events = 0 for i in range(numRows): print("Doing timecourse number " + str(i)) dataRow = brain_data[i] start_spikes, end_spikes, vals = detectSpikes(dataRow, -0.3) total_start_events += start_spikes.shape[0] total_end_events += end_spikes.shape[0] all_start_spikes.append(start_spikes) all_end_spikes.append(end_spikes) t = time.clock()
ap.add_argument( '-f', '--data_filename', nargs=1, required=True, help= 'name of hdf5 input file with ICA-filtered timecourses and domain map') ap.add_argument('-t', '--trigger', action="store_true", required=False, help='generate the lookup table') args = vars(ap.parse_args()) f = h5(args['coincidence_filename'][0]) data = f.load() eventMatrix = data['eventMatrix'] maxRates = np.ones(eventMatrix.shape[0]) minRates = np.zeros(eventMatrix.shape[0]) pMatrix = data['pMatrix'] f2 = h5(args['data_filename'][0]) data2 = f2.load() domain_map = data2['domainmap'] if (args['trigger']): trigger = True
from hdf5manager import hdf5manager as h5 import numpy as np import cv2 as cv import time import math f = h5("new_mouse_vectors.hdf5").load() f_bl = f["bl"].astype("int64") f_br = f["br"].astype("int64") f_fl = f["fl"].astype("int64") f_fr = f["fr"].astype("int64") feet = [f_bl, f_br, f_fl, f_fr] mv = np.empty((f_bl.shape[0], 480, 640, 3), dtype='uint8') for f in feet: for i in range(f.shape[0]): x, y = f[i] cv.circle(mv[i], (x, y), 3, (255, 0, 0), -1) print("Playing Movie") print("Blue means new, Red means old") cv.namedWindow("Dots") fps = 30 frame_dt = 1.0 / fps mv_i = 0 pause = False while True: if mv_i >= mv.shape[0]: mv_i = 0
from hdf5manager import hdf5manager as h5 import cv2 as cv2 import numpy as np domain_map = h5("P2_timecourses.hdf5").load()["domainmap"] def interpAxis(contour, interp_x): contour = contour[:, 0] if interp_x: xs = contour[:, 0] ys = contour[:, 1] else: xs = contour[:, 1] ys = contour[:, 0] xs_interp = xs.tolist() ys_interp = ys.tolist() sz = xs.shape[0] i = 1 while i < sz: dif = xs_interp[i] - xs_interp[i - 1] new_x = 0 if dif < -1: new_x = xs_interp[i - 1] - 1 elif dif > 1: new_x = xs_interp[i - 1] + 1 else:
for path in pathlist: print('\n\n\tWorking on ' + path) #find the average movtion vectors if path.endswith('videodata.hdf5'): print('Input found:') print('\t' + path) assert os.path.exists(path), 'Videodata file was not found!' print('Processing file:', path) # # assert path.endswith('videodata.hdf5'), "Path did not end in 'videodata.hdf5'" print( '\nLoading videodata to create classifier metrics\n------------------------------------------------' ) f = h5(path) print('\t loading dfof mean') dfof = f.load('dfof_mean') if path.endswith('OpticFlow.hdf5'): assert os.path.exists(path), 'opticFlow file was not found!' assert path.endswith( '.hdf5'), 'Unknown data type. Please load .hdf5 only' print('Input found:') print('\t' + path) print('Processing file:', path) if path.endswith('.hdf5'): # assert path.endswith('opticFlow.hdf5'), "Path did not end in 'opticFlow.hdf5'" savepath = path.replace('.hdf5', '_metrics.csv') base = os.path.basename(path)
import time, math, sys try: path_file = open("path.txt", "r") sys.path.append(path_file.read()) path_file.close() except: print("Can't import, path.txt doesn't exist") pass import fileManager as fm experimentName = "180807_01" vid_name = experimentName + "_result" f = h5("mouse_vectors_" + experimentName + ".hdf5").load() f_write = h5("new_mouse_vectors_" + experimentName + ".hdf5") contour_data = f["contour_data"].astype("int32") n_contours = f["n_contours"] names = ["bl", "br", "fl", "fr", "t"] write_dict = { "bl": np.empty((contour_data.shape[0], 2)), "br": np.empty((contour_data.shape[0], 2)), "fl": np.empty((contour_data.shape[0], 2)), "fr": np.empty((contour_data.shape[0], 2)), "t": np.empty((contour_data.shape[0], 2)) } stds = f["stds"] max_std = np.max(stds)