def read_kwa_clusters(self): # Read KWA JSON string. # Read the cluster info. clusters = self.clusters_table.col('cluster') cluster_groups = self.clusters_table.col('group') groups = self.groups_table.col('group') group_names = self.groups_table.col('name') # Getting the colors from the KWA file, or creating them. # kwa = load_kwa_json(self.kwa_json) if self.kwa: cluster_colors = self.kwa['shanks'][self.shank]['cluster_colors'] group_colors = self.kwa['shanks'][self.shank]['group_colors'] else: cluster_colors = generate_colors(len(clusters)) group_colors = generate_colors(len(groups)) # Create the cluster_info DataFrame. self.cluster_info = pd.DataFrame(dict( color=cluster_colors, group=cluster_groups, ), index=clusters) self.cluster_colors = self.cluster_info['color'].astype(np.int32) self.cluster_groups = self.cluster_info['group'].astype(np.int32) # Create the group_info DataFrame. self.group_info = pd.DataFrame(dict( color=group_colors, name=group_names, ), index=groups) self.group_colors = self.group_info['color'].astype(np.int32) self.group_names = self.group_info['name']
def set_data(self, trace=None, freq=None, channel_height=None, channel_names=None, ignored_channels=None, channel_colors=None): # default settings self.max_size = 1000 self.duration_initial = 10. self.default_channel_height = 0.25 self.channel_height_limits = (0.01, 20.) self.nticks = 10 # these variables will be overwritten after initialization (used to check if init is complete) self.slice_ref = (-1, -1) # slice paging self.paintinitialized = False # to stop first slice from being loaded until correctly-shaped data drawn self.real_data = True # hides grid and painting if we've made up false data of zeros self.size = 1 if trace is None: # make up some data to keep the GPU happy, warm, and feeling loved trace = np.zeros((self.duration_initial * 2, 32)) freq = 1 # don't worry, we won't tell the GPU that it's not actually rendering any useful data, but we need to keep track self.real_data = False if channel_colors is None: channel_colors = pd.Series(generate_colors(trace.shape[1])) # load initial variables self.trace = trace self.channel_colors = channel_colors self.ignored_channels = ignored_channels self.freq = freq self.totalduration = (self.trace.shape[0] - 1) / self.freq self.totalsamples, self.nchannels = self.trace.shape self.channels = np.arange(self.nchannels) if channel_height is None: channel_height = self.default_channel_height else: self.default_channel_height = channel_height self.channel_height = channel_height if channel_names is None: channel_names = pd.Series(['ch{0:d}'.format(i) for i in xrange(self.nchannels)]) self.channel_names = channel_names x = np.tile(np.linspace(0., self.totalduration, 2), (self.nchannels, 1)) y = np.zeros_like(x)+ np.linspace(-1, 1, self.nchannels).reshape((-1, 1)) self.position, self.shape = process_coordinates(x=x, y=y) # activate the grid if self.real_data == True: self.interaction_manager.get_processor('viewport').update_viewbox() self.interaction_manager.activate_grid() # register the updater threads self.slice_retriever = inthread(SliceRetriever)(impatient=True) self.slice_retriever.sliceLoaded.connect(self.slice_loaded)
def default_group_info(): group_info = np.zeros((4, 3), dtype=object) group_info[:, 0] = np.arange(4) group_info[:, 1] = generate_colors(group_info.shape[0]) group_info[:, 2] = np.array(["Noise", "MUA", "Good", "Unsorted"], dtype=object) group_info = pd.DataFrame( {"color": group_info[:, 1].astype(np.int32), "name": group_info[:, 2]}, index=group_info[:, 0].astype(np.int32) ) return group_info
def default_group_info(): group_info = np.zeros((4, 3), dtype=object) group_info[:, 0] = np.arange(4) group_info[:, 1] = generate_colors(group_info.shape[0]) group_info[:, 2] = np.array(['Noise', 'MUA', 'Good', 'Unsorted'], dtype=object) group_info = pd.DataFrame( {'color': group_info[:, 1].astype(np.int32), 'name': group_info[:, 2]}, index=group_info[:, 0].astype(np.int32)) return group_info
def default_cluster_info(clusters_unique): n = len(clusters_unique) cluster_info = pd.DataFrame( {"color": generate_colors(n), "group": 3 * np.ones(n)}, dtype=np.int32, index=clusters_unique ) # Put cluster 0 in group 0 (=noise), cluster 1 in group 1 (=MUA) if 0 in clusters_unique: cluster_info["group"][0] = 0 if 1 in clusters_unique: cluster_info["group"][1] = 1 return cluster_info
def default_cluster_info(clusters_unique): n = len(clusters_unique) cluster_info = pd.DataFrame({ 'color': generate_colors(n), 'group': 3 * np.ones(n)}, dtype=np.int32, index=clusters_unique) # Put cluster 0 in group 0 (=noise), cluster 1 in group 1 (=MUA) if 0 in clusters_unique: cluster_info['group'][0] = 0 if 1 in clusters_unique: cluster_info['group'][1] = 1 return cluster_info
def set_data(self, trace=None, freq=None, channel_height=None, channel_names=None, ignored_channels=None, channel_colors=None): # default settings self.max_size = 1000 self.duration_initial = 10. self.default_channel_height = 0.25 self.channel_height_limits = (0.01, 20.) self.nticks = 10 # these variables will be overwritten after initialization (used to check if init is complete) self.slice_ref = (-1, -1) # slice paging self.paintinitialized = False # to stop first slice from being loaded until correctly-shaped data drawn self.real_data = True # hides grid and painting if we've made up false data of zeros self.size = 1 if trace is None: # make up some data to keep the GPU happy, warm, and feeling loved trace = np.zeros((self.duration_initial * 2, 32)) freq = 1 # don't worry, we won't tell the GPU that it's not actually rendering any useful data, but we need to keep track self.real_data = False if channel_colors is None: channel_colors = pd.Series(generate_colors(trace.shape[1])) # load initial variables self.trace = trace self.channel_colors = channel_colors self.ignored_channels = ignored_channels self.freq = freq self.totalduration = (self.trace.shape[0] - 1) / self.freq self.totalsamples, self.nchannels = self.trace.shape self.channels = np.arange(self.nchannels) if channel_height is None: channel_height = self.default_channel_height else: self.default_channel_height = channel_height self.channel_height = channel_height if channel_names is None: channel_names = pd.Series( ['ch{0:d}'.format(i) for i in xrange(self.nchannels)]) self.channel_names = channel_names x = np.tile(np.linspace(0., self.totalduration, 2), (self.nchannels, 1)) y = np.zeros_like(x) + np.linspace(-1, 1, self.nchannels).reshape( (-1, 1)) self.position, self.shape = process_coordinates(x=x, y=y) # activate the grid if self.real_data == True: self.interaction_manager.get_processor('viewport').update_viewbox() self.interaction_manager.activate_grid() # register the updater threads self.slice_retriever = inthread(SliceRetriever)(impatient=True) self.slice_retriever.sliceLoaded.connect(self.slice_loaded)