Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
77fb28c
NEEDS TESTING. Added features - reloading points from previous sessio…
greggheller Jun 26, 2019
ce7ae6e
was bad about commiting frequently :( fixed and tested functionality …
greggheller Jul 13, 2019
58525a3
slight modifications if any
Aug 15, 2019
09370d6
local config should not be tracked in git
Aug 15, 2019
f04baba
Save figures directly
Jan 13, 2020
42604db
fixed bug with default config when no directory found
Jan 13, 2020
0016bb0
saves csv and files with appropriate name
Feb 20, 2020
c9dead8
new naming conventions
Mar 5, 2020
62e1ebf
updates to the notebook
Mar 5, 2020
afae33c
updated the default config
Apr 3, 2020
f544592
added launch bat
corbennett Jul 28, 2020
fcb372f
added saving of warped image and alignment to day 1 warped image
corbennett Sep 10, 2020
a81ad7d
current NP2 config
corbennett Sep 17, 2020
f7e4144
Merge branch 'gregg_branch' of https://github.com/corbennett/probeLoc…
corbennett Sep 17, 2020
61f0fac
added csv fields for confidence and notes
corbennett Sep 17, 2020
452b4bb
selects correct ISI session (the one we have placed lines on)
corbennett Sep 19, 2020
a23dfee
use a list of mouse numbers so use_day1_insertion_image_as_fiducial =…
corbennett Oct 2, 2020
3c457c9
features: ability to reload points is restored, points can be deleted…
corbennett Nov 24, 2020
7f08813
change launch bat env
corbennett Dec 2, 2020
5299f35
Merge branch 'gregg_branch' of https://github.com/corbennett/probeLoc…
corbennett Dec 2, 2020
bf58233
sometimes points are left out if they are redrawn. added short delay …
corbennett Dec 4, 2020
0dfaf1f
bug fix - weren't able to choose image if it found but did not load p…
corbennett Dec 4, 2020
0c67560
fixed redraw bug, reverted delete last point to old mechanism that do…
greggheller Dec 8, 2020
27512ae
Merge branch 'master' of https://github.com/corbennett/probeLocator i…
corbennett Dec 8, 2020
ee066b0
Merge branch 'gregg_branch' of https://github.com/corbennett/probeLoc…
corbennett Dec 8, 2020
dfe7979
added error handling for missing ISI images
corbennett Dec 21, 2020
9ae7210
save files for hab sessions to SD7
corbennett Feb 7, 2021
a8602b9
stupid pyc files...
corbennett Feb 7, 2021
33feb5f
Merge branch 'gregg_branch' of https://github.com/corbennett/probeLoc…
corbennett Feb 7, 2021
22b2b63
Update probeInsertionLocator.ipynb
Feb 10, 2021
4cab0b2
Update default_config.py
corbennett Feb 15, 2021
487bb30
Merge branch 'gregg_branch' of https://github.com/corbennett/probeLoc…
corbennett Feb 15, 2021
7417521
Update default_config.py
corbennett Apr 13, 2021
fb95d70
Update probeInsertionLocator.ipynb
corbennett Apr 13, 2021
446ec83
pushing to sync
greggheller Sep 27, 2022
7d5cd8e
new notebook for DR annotations
corbennett Sep 28, 2022
93a2038
Merge branch 'gregg_branch' of https://github.com/corbennett/probeLoc…
corbennett Sep 28, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3,577 changes: 3,577 additions & 0 deletions .ipynb_checkpoints/probeInsertionLocator-Copy1-checkpoint.ipynb

Large diffs are not rendered by default.

1,569 changes: 1,415 additions & 154 deletions .ipynb_checkpoints/probeInsertionLocator-checkpoint.ipynb

Large diffs are not rendered by default.

4,801 changes: 4,801 additions & 0 deletions .ipynb_checkpoints/probeInsertionLocator_DR-checkpoint.ipynb

Large diffs are not rendered by default.

3,609 changes: 3,609 additions & 0 deletions backup/probeInsertionLocator.ipynb

Large diffs are not rendered by default.

Binary file added config.pyc
Binary file not shown.
127 changes: 127 additions & 0 deletions default_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
"""Rename this file 'config.py' and make the appropriate changes"""

import os
import logging


directory_list = [r'\\allen\programs\mindscope\workgroups\np-exp', r'\\w10DTSM18306\neuropixels_data', r'\\w10DTSM112719\neuropixels_data', r'10.128.50.20\sd7.2\habituation', r'10.128.54.20\SD8\habituation']# r'\\10.128.50.43\sd6.2', r'\\10.128.50.43\sd6', r'\\10.128.50.43\sd6.3', r'\\10.128.50.43\sd6.3\habituation']#r'Z:', r'\\10.128.50.43\sd6.2', r'\\10.128.50.43\sd6', 112719

save_hab_files = r'\\10.128.54.19\sd9\habituation'

#

desired_image_filenames_contain = ['surface-image1']#, 'surface-image1']


npz_file_suffix = 'ISIregistration.npz'



def get_insertion_image_paths(mouse_number, desired_image_filenames_contain=desired_image_filenames_contain,
directory_list = directory_list):
path_list = []
for directory in directory_list:
#print('###################### '+directory)
try:
sessions = os.listdir(directory)
#print(sessions)
except Exception as E:
log_str = 'Failed to find sessions at {}'.format(directory)
#logging.error(log_str)
sessions = []
for session_dir in sessions:
if mouse_number in session_dir:
session_path = os.path.join(directory, session_dir)
for filename in os.listdir(session_path):
match = False
for sub_string in desired_image_filenames_contain:
if sub_string in filename:
match = True
if (mouse_number in filename) and match:
path_list.append(os.path.join(session_path, filename))
#print(path_list)
return path_list

def get_insertion_image_path_from_session_id(session_id, desired_image_filenames_contain=desired_image_filenames_contain,
directory_list=directory_list):
path_list = []
for directory in directory_list:
#print('###################### '+directory)
try:
sessions = os.listdir(directory)
#print(sessions)
except Exception as E:
log_str = 'Failed to find sessions at {}'.format(directory)
#logging.error(log_str)
sessions = []
for session_dir in sessions:
if session_id in session_dir:
session_path = os.path.join(directory, session_dir)
for filename in os.listdir(session_path):
match = False
for sub_string in desired_image_filenames_contain:
if sub_string in filename:
match = True
if (session_id in filename) and match:
path_list.append(os.path.join(session_path, filename))
break
#print(path_list)
return path_list

def get_save_path(file_path):
if False:#not('surface-image3' in file_path):
saveDirectory = os.path.join(save_hab_files, get_session_name(file_path))
else:
saveDirectory = os.path.dirname(file_path)
npz_filename = get_session_name(file_path)+'.'+npz_file_suffix
save_path = os.path.join(saveDirectory, npz_filename)
return save_path

def get_session_name(insertion_image_path):
session_name = ''
try:
session_path = os.path.split(insertion_image_path)[0]
data_dirname = os.path.split(session_path)[1]
assert(data_dirname.count('_')==2)
session_name = data_dirname
except Exception as E:
logging.warning('Unable to retrieve an acceptable session_name', exc_info=True)
return session_name


def get_warped_image_from_day1(d2_insertion_image_path):

session_dir = os.path.dirname(d2_insertion_image_path)
session_base = os.path.basename(d2_insertion_image_path)

parent_dir = os.path.dirname(session_dir)

try:
mouseID = session_base.split('_')[1]
date = session_base.split('_')[2]

other_dirs = os.listdir(parent_dir)
other_dirs = [o for o in other_dirs if os.path.isdir(os.path.join(parent_dir,o))]

#find putative day 1 directory
day1_dir_candidates = [o for o in other_dirs if (mouseID in o) and (int(o.split('_')[2])<int(date))] # has mouse ID and comes from earlier session
day1_candidate_dates = [int(d.split('_')[2]) for d in day1_dir_candidates]

day1_dir = [d for d in day1_dir_candidates if str(max(day1_candidate_dates)) in d] #take the most recent of these
day1_dir = os.path.join(parent_dir, day1_dir[0])

#look for warped image in day 1 directory
day1_files = os.listdir(day1_dir)
warped_insertion_image_file = [w for w in day1_files if 'warpedInsertionImage' in w]
if len(warped_insertion_image_file)==0:
logging.warning('Could not find day 1 warped insertion image. Please override path to this image if it exists')
return
else:
warped_insertion_image_file = os.path.join(day1_dir, warped_insertion_image_file[0])

except Exception as E:
logging.warning('Could not find day 1 data directory', exc_info=True)
warped_insertion_image_file = ''

return warped_insertion_image_file

Binary file added default_config.pyc
Binary file not shown.
9 changes: 8 additions & 1 deletion launch.bat
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
<<<<<<< HEAD
call C:\ProgramData\Anaconda3\Scripts\activate.bat C:\ProgramData\Anaconda3\
call conda activate probeLocator
call jupyter notebook
cmd \k
=======
call C:\Users\svc_ccg\AppData\Local\Continuum\anaconda3\Scripts\activate.bat C:\Users\svc_ccg\AppData\Local\Continuum\anaconda3\
call conda activate probeLocator
call jupyter notebook
cmd /k
cmd /k
>>>>>>> 3572056a396a78f56a620f7c610d360dc1075ca6
Binary file added mouse_visual_areas.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
193 changes: 148 additions & 45 deletions pointAnnotator.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,17 @@

import numpy as np
from matplotlib import pyplot as plt

import os
import logging
import time
#class to handle annotating the images with points of interest
#USE: left mouse clicks will draw red dots on image and populate a list of x y coordinates for each dot
# right mouse clicks will clear the dots and the x y coordinate list
# key presses will delete only the last point
class pointAnnotator:
def __init__(self, im, ax):
self.ax = ax
self.respond_in_ax = ax
self.ax.set_xlim([0,im.get_array().shape[1]])
self.ax.set_ylim([im.get_array().shape[0],0])

Expand All @@ -23,33 +26,73 @@ def __init__(self, im, ax):
self.ys = []
self.annos = []
self.labels = []
self.marker_str = 'b+'
self.last_click = None
self.cid = im.figure.canvas.mpl_connect('button_press_event', self.onclick)
self.cidrelease = im.figure.canvas.mpl_connect('button_release_event', self.onrelease)

self.kid = im.figure.canvas.mpl_connect('key_press_event', self.keypress)

def onclick(self, event):
if event.inaxes==self.ax:
if event.button == 1:
print('x ' + str(event.xdata) + '\ty ' + str(event.ydata))
self.xs.append(event.xdata)
self.ys.append(event.ydata)
self.last_click = event
print('registered click')
#if event.inaxes==self.respond_in_ax:
# if event.button == 1:

anno, = self.ax.plot(event.xdata, event.ydata, 'ro')
self.annos.append(anno)
lab = self.ax.text(event.xdata+0.2, event.ydata+0.2, str(len(self.annos)))
self.labels.append(lab)
self.im.figure.canvas.draw()
else:
self.resetAnnotations()
#Do this on the release instead else:
# idx = self.clicked_annotation(event)
# if idx:
# self.deleteAnnotation(idx)


def onrelease(self, event):
#check to see if this was a click and drag, in which case, don't draw point
if event.inaxes==self.ax:
distance = ((event.xdata-self.xs[-1])**2 + (event.ydata-self.ys[-1])**2)**0.5
if distance > 10:
self.deleteLastAnnotation()
if event.inaxes==self.respond_in_ax:
distance = ((event.xdata-self.last_click.xdata)**2 + (event.ydata-self.last_click.ydata)**2)**0.5
if event.button == 1:
idx = self.clicked_annotation(self.last_click)
if not(idx is None):
self.update_annotation(idx, event)
else:

if distance < 10:
print('x ' + str(event.xdata) + '\ty ' + str(event.ydata))
self.xs.append(event.xdata)
self.ys.append(event.ydata)

anno, = self.ax.plot(event.xdata, event.ydata, self.marker_str)
self.annos.append(anno)
lab = self.ax.text(event.xdata+6, event.ydata-4, str(len(self.annos)))
self.labels.append(lab)
self.im.figure.canvas.draw()
else:
if (distance < 10) and not(self.clicked_annotation(self.last_click) is None):
self.deleteAnnotation(self.clicked_annotation(self.last_click))
if (distance > 30) and self.clicked_annotation(self.last_click)==None and self.clicked_annotation(event)==None:
self.resetAnnotations()

def update_annotation(self, idx, event):
self.xs[idx] = event.xdata
self.ys[idx] = event.ydata
self.annos[idx].remove()
anno, = self.ax.plot(event.xdata, event.ydata, self.marker_str)
self.annos[idx] = anno
self.labels[idx].remove()
lab = self.ax.text(event.xdata+6, event.ydata-4, str(idx+1))
self.labels[idx] = lab
self.im.figure.canvas.draw()


def clicked_annotation(self, event):
for idx, (x,y) in enumerate(zip(self.xs, self.ys)):
distance = ((event.xdata-x)**2 + (event.ydata-y)**2)**0.5
if distance < 30:
return idx
return None


def keypress(self, event):
if event.inaxes==self.ax:
if event.inaxes==self.respond_in_ax:
self.deleteLastAnnotation()

def resetAnnotations(self):
Expand All @@ -62,7 +105,20 @@ def resetAnnotations(self):
self.annos=[]
self.labels=[]

def deleteAnnotation(self, idx):
self.xs.pop(idx)
xs = self.xs
self.ys.pop(idx)
ys = self.ys
self.resetAnnotations()
self.ys = ys
self.xs = xs
self.drawPoints()



def deleteLastAnnotation(self):
#self.deleteAnnotation(-1)
self.xs = self.xs[:-1]
self.ys = self.ys[:-1]
self.annos[-1].remove()
Expand All @@ -72,42 +128,89 @@ def deleteLastAnnotation(self):
self.im.figure.canvas.draw()

def loadPoints(self, points):
self.xs = list(points[:, 0])
self.ys = list(points[:, 1])
self.drawPoints()
try:
self.xs = list(points[:, 0])
self.ys = list(points[:, 1])
self.drawPoints()
except TypeError as E:
if points is None:
print('No points to load')
else:
raise(E)

def drawPoints(self):
for i, (x,y) in enumerate(zip(self.xs, self.ys)):
anno, = self.ax.plot(x,y, 'ro')
time.sleep(.5)
anno, = self.ax.plot(x,y, self.marker_str)
self.annos.append(anno)
lab = self.ax.text(x,y,str(i+1))
lab = self.ax.text(x+6,y-4,str(i+1))
self.labels.append(lab)
self.im.figure.canvas.draw()

@property
def points(self):
return np.stack((self.xs, self.ys)).astype(np.float32).T

class pointCopier(pointAnnotator):
def __init__(self, im, ax):
def __init__(self, im, ax, copy_ax):
pointAnnotator.__init__(self, im, ax)
self.respond_in_ax = copy_ax

def onclick(self, event):
if event.button == 1:
print('x ' + str(event.xdata) + '\ty ' + str(event.ydata))
self.xs.append(event.xdata)
self.ys.append(event.ydata)

anno, = self.ax.plot(event.xdata, event.ydata, 'ro')
self.annos.append(anno)
lab = self.ax.text(event.xdata+0.2, event.ydata+0.2, str(len(self.annos)))
self.labels.append(lab)
self.im.figure.canvas.draw()
else:
self.resetAnnotations()
#def onclick(self, event):
# if event.inaxes==self.respond_in_ax:
# if event.button == 1:
# print('x ' + str(event.xdata) + '\ty ' + str(event.ydata))
# self.xs.append(event.xdata)
# self.ys.append(event.ydata)
#
# anno, = self.ax.plot(event.xdata, event.ydata, 'ro')
# self.annos.append(anno)
# lab = self.ax.text(event.xdata+0.2, event.ydata+0.2, str(len(self.annos)))
# self.labels.append(lab)
# self.im.figure.canvas.draw()
# else:
# self.resetAnnotations()

def onrelease(self, event):
#check to see if this was a click and drag, in which case, don't draw point
distance = ((event.xdata-self.xs[-1])**2 + (event.ydata-self.ys[-1])**2)**0.5
if distance > 10:
self.deleteLastAnnotation()
#def onrelease(self, event):
# #check to see if this was a click and drag, in which case, don't draw point
# distance = ((event.xdata-self.xs[-1])**2 + (event.ydata-self.ys[-1])**2)**0.5
# if distance > 10:
# self.deleteLastAnnotation()

def keypress(self, event):
self.deleteLastAnnotation()

#def keypress(self, event):
# """we only want to delete points when the key press is in the copy image and a point on the other image will be deleted"""
# if event.inaxes==self.copy_ax:
# self.deleteLastAnnotation()

def points_from_path(path, *args):
log_str = 'Found more than 1 {} in {}, something might be wrong'
npz_count = 0
points = np.stack(([], [])).astype(np.float32).T
if not(os.path.isdir(path)):
path = os.path.split(path)[0]
for filename in os.listdir(path):
if os.path.splitext(filename)[1]=='.npz':
npz_count += 1
match_count = 0
print('found npz '+filename)
try:
npz_file = np.load(os.path.join(path, filename), allow_pickle=True)
stored_points = npz_file#npz_file['imagePairCoordinates'][0]
print(stored_points)
for array_name in stored_points:
match = True
for arg in args:
if not(arg in array_name):
match = False
if match:
match_count += 1
logging.info('Found some points')
points = npz_file[array_name]
logging.info(points)
except Exception as E:
return points
if match_count>1:
logging.warning(log_str.format('array', filename))
if npz_count>1:
logging.warning(log_str.format('npz file', path))
return points
Binary file modified pointAnnotator.pyc
Binary file not shown.
Loading