database/TablePopulateFuncsV4.py
def make_commoncoordinatematrices_table(table, key):
	# Ignore wrong entries
	# split = key['session_name'].split("_")
	# if len(split) > 2: raise ValueError
	# else:
	# 	mouse = split[-1]
	# if key['mouse_id'] != mouse: return

	from database.TablesDefinitionsV4 import Recording, Session

	"""make_commoncoordinatematrices_table [Allows user to align frame to model
	and stores transform matrix for future use]

	"""
	# Get the maze model template according to the experiment being processed
	if int(key["uid"]<248) or int(key["uid"]>301):
		old_mode = True
		maze_model = cv2.imread('Utilities\\video_and_plotting\\mazemodel_old.png')
	else:
		old_mode = False
		maze_model = cv2.imread('Utilities\\video_and_plotting\\mazemodel_old.png')

	maze_model = cv2.resize(maze_model, (1000, 1000))
	maze_model = cv2.cvtColor(maze_model, cv2.COLOR_RGB2GRAY)

	# Get path to video of first recording
	try:
		videopath = (Recording.FilePaths & key).fetch("overview_video")[0]
	except:
		print("While populating CCM, could not find video, make sure to run recording.make_paths\n ", key)
		warnings.warn("did not pupulate CCM for : {}".format(key))
		return
		
	if not videopath: 
		print("While populating CCM, could not find video, make sure to run recording.make_paths   \n", videopath)
		return

	# Apply the transorm [Call function that prepares data to feed to Philip's function]
	""" 
		The correction code is from here: https://github.com/BrancoLab/Common-Coordinate-Behaviour
	"""

	matrix, points, top_pad, side_pad = get_matrix(videopath, maze_model=maze_model, old_mode=old_mode)
	if matrix is None:   # somenthing went wrong and we didn't get the matrix
		# Maybe the videofile wasn't there
		print('Did not extract matrix for video: ', videopath)
		return

	# Return the updated key
	key['maze_model'] 			= maze_model
	key['correction_matrix'] 	= matrix
	key['alignment_points'] 	= points
	key['top_pad'] 				= top_pad
	key['side_pad'] 			= side_pad
	key['camera'] 				= "overview" # TODO make this work
	table.insert1(key)
make_commoncoordinatematrices_table [Allows user to align frame to model
	and stores transform matrix for future use]

	
make_commoncoordinatematrices_table [Allows user to align frame to model
and stores transform matrix for future use]
make_commoncoordinatematrices_table [ Allows user to align frame to model and stores transform matrix for future use ]
def make_commoncoordinatematrices_table(table, key):
	from database.TablesDefinitionsV4 import Recording, Session
	if int(key["uid"]<248) or int(key["uid"]>301):
		old_mode = True
		maze_model = cv2.imread('Utilities\\video_and_plotting\\mazemodel_old.png')
	else:
		old_mode = False
		maze_model = cv2.imread('Utilities\\video_and_plotting\\mazemodel_old.png')
	maze_model = cv2.resize(maze_model, (1000, 1000))
	maze_model = cv2.cvtColor(maze_model, cv2.COLOR_RGB2GRAY)
	try:
		videopath = (Recording.FilePaths & key).fetch("overview_video")[0]
	except:
		print("While populating CCM, could not find video, make sure to run recording.make_paths\n ", key)
		warnings.warn("did not pupulate CCM for : {}".format(key))
		return
	if not videopath: 
		print("While populating CCM, could not find video, make sure to run recording.make_paths   \n", videopath)
		return
	matrix, points, top_pad, side_pad = get_matrix(videopath, maze_model=maze_model, old_mode=old_mode)
	if matrix is None:   
		print('Did not extract matrix for video: ', videopath)
		return
	key['maze_model'] 			= maze_model
	key['correction_matrix'] 	= matrix
	key['alignment_points'] 	= points
	key['top_pad'] 				= top_pad
	key['side_pad'] 			= side_pad
	key['camera'] 				= "overview" 
	table.insert1(key)
def make_commoncoordinatematrices_table ( table , key ) : from database . TablesDefinitionsV4 import Recording , Session if int ( key [ "uid" ] < 248 ) or int ( key [ "uid" ] > 301 ) : old_mode = True maze_model = cv2 . imread ( 'Utilities\\video_and_plotting\\mazemodel_old.png' ) else : old_mode = False maze_model = cv2 . imread ( 'Utilities\\video_and_plotting\\mazemodel_old.png' ) maze_model = cv2 . resize ( maze_model , ( 1000 , 1000 ) ) maze_model = cv2 . cvtColor ( maze_model , cv2 . COLOR_RGB2GRAY ) try : videopath = ( Recording . FilePaths & key ) . fetch ( "overview_video" ) [ 0 ] except : print ( "While populating CCM, could not find video, make sure to run recording.make_paths\n " , key ) warnings . warn ( "did not pupulate CCM for : {}" . format ( key ) ) return if not videopath : print ( "While populating CCM, could not find video, make sure to run recording.make_paths   \n" , videopath ) return """ 
		The correction code is from here: https://github.com/BrancoLab/Common-Coordinate-Behaviour
	""" matrix , points , top_pad , side_pad = get_matrix ( videopath , maze_model = maze_model , old_mode = old_mode ) if matrix is None : print ( 'Did not extract matrix for video: ' , videopath ) return key [ 'maze_model' ] = maze_model key [ 'correction_matrix' ] = matrix key [ 'alignment_points' ] = points key [ 'top_pad' ] = top_pad key [ 'side_pad' ] = side_pad key [ 'camera' ] = "overview" table . insert1 ( key )
make_commoncoordinatematrices_table [Allows user to align frame to model
and stores transform matrix for future use]
make_commoncoordinatematrices_table [ Allows user to align frame to model and stores transform matrix for future use ]
# Ignore wrong entries # split = key['session_name'].split("_") # if len(split) > 2: raise ValueError # else: # 	mouse = split[-1] # if key['mouse_id'] != mouse: return """make_commoncoordinatematrices_table [Allows user to align frame to model
	and stores transform matrix for future use]

	""" # Get the maze model template according to the experiment being processed # Get path to video of first recording # Apply the transorm [Call function that prepares data to feed to Philip's function] """ 
		The correction code is from here: https://github.com/BrancoLab/Common-Coordinate-Behaviour
	""" # somenthing went wrong and we didn't get the matrix # Maybe the videofile wasn't there # Return the updated key # TODO make this work
table
key