def gui(ctx, data_path, **kwargs): """Launch the NEO GUI on a NEO readable file.""" # Create a `phy.log` log file with DEBUG level. _add_log_file(op.join(op.dirname(data_path), 'phy.log')) create_app() _run_cmd('_run(data_path, **kwargs)', ctx, globals(), locals())
def cluster_manual(ctx, path, channel_group=None, clustering=None): """Launch the Kwik GUI on a Kwik file.""" # Create a `phy.log` log file with DEBUG level. _add_log_file(op.join(op.dirname(path), 'phy.log')) create_app() _run_cmd('_run(path, channel_group, clustering)', ctx, globals(), locals())
def kwik_gui(path, channel_group=None, clustering=None, **kwargs): # pragma: no cover """Launch the Kwik GUI.""" assert path create_app() controller = KwikController( path, channel_group=channel_group, clustering=clustering, **kwargs) gui = controller.create_gui() gui.show() run_app() gui.close()
def cluster_manual(ctx, params_path): """Launch the Template GUI on a params.py file.""" # Create a `phy.log` log file with DEBUG level. _add_log_file(op.join(op.dirname(params_path), 'phy.log')) create_app() params = _read_python(params_path) params['dtype'] = np.dtype(params['dtype']) _run_cmd('_run(params)', ctx, globals(), locals())
def kilosort(dat_path, **kwargs): """Launch the trace GUI on a raw data file.""" create_app() with capture_exceptions(): kwargs['n_channels_dat'] = kwargs.pop('n_channels') kwargs['order'] = 'F' if kwargs.pop('fortran', None) else None creator = KilosortGUICreator(dat_path, **kwargs) gui = creator.create_gui() gui.show() run_app() gui.close()
def gui(ctx, params_path): """Launch the Template GUI on a params.py file.""" # Create a `phy.log` log file with DEBUG level. _add_log_file(op.join(op.dirname(params_path), 'phy.log')) create_app() params = _read_python(params_path) params['dtype'] = np.dtype(params['dtype']) _run_cmd('_run(params)', ctx, globals(), locals())
def create_trace_gui(obj, **kwargs): """Create the Trace GUI. Parameters ---------- obj : str or Path Path to the raw data file. sample_rate : float The data sampling rate, in Hz. n_channels_dat : int The number of columns in the raw data file. dtype : str The NumPy data type of the raw binary file. offset : int The header offset in bytes. """ gui_name = 'TraceGUI' # Support passing a params.py file. if str(obj).endswith('.py'): params = get_template_params(str(obj)) return create_trace_gui(next(iter(params.pop('dat_path'))), **params) kwargs = { k: v for k, v in kwargs.items() if k in ('sample_rate', 'n_channels_dat', 'dtype', 'offset') } traces = get_ephys_reader(obj, **kwargs) create_app() gui = GUI(name=gui_name, subtitle=obj.resolve(), enable_threading=False) gui.set_default_actions() def _get_traces(interval): return Bunch(data=select_traces( traces, interval, sample_rate=traces.sample_rate)) # TODO: load channel information view = TraceView( traces=_get_traces, n_channels=traces.n_channels, sample_rate=traces.sample_rate, duration=traces.duration, enable_threading=False, ) view.attach(gui) return gui
def template_gui(params_path, **kwargs): # pragma: no cover """Launch the Template GUI.""" # Create a `phy.log` log file with DEBUG level. _add_log_file(Path(params_path).parent / 'phy.log') create_app() controller = TemplateController(**get_template_params(params_path), **kwargs) gui = controller.create_gui() gui.show() run_app() gui.close() controller.model.close()
def cluster_manual(path, channel_group=None, clustering=None): """Launch the Kwik GUI on a Kwik file.""" # Create the Qt application. create_app() controller = KwikController(path, channel_group=channel_group, clustering=clustering, ) gui = controller.create_gui() gui.show() run_app() gui.close() del gui
def template_gui(params_path, **kwargs): # pragma: no cover """Launch the Template GUI.""" # Create a `phy.log` log file with DEBUG level. p = Path(params_path) dir_path = p.parent _add_log_file(dir_path / 'phy.log') create_app() controller = TemplateController(model=load_model(params_path), dir_path=dir_path, **kwargs) gui = controller.create_gui() gui.show() run_app() gui.close() controller.model.close()
def cluster_manual(ctx, params_path): """Launch the Template GUI on a params.py file.""" # Create the Qt application. create_app() params = _read_python(params_path) params['dtype'] = np.dtype(params['dtype']) controller = TemplateController(**params) gui = controller.create_gui() gui.show() _run_cmd('run_app()', ctx, globals(), locals()) gui.close() del gui
def template_gui(params_path, **kwargs): # pragma: no cover """Launch the Template GUI.""" # Create a `phy.log` log file with DEBUG level. p = Path(params_path) dir_path = p.parent _add_log_file(dir_path / 'phy.log') model = load_model(params_path) # Automatically export spike waveforms when using compressed raw ephys. if model.spike_waveforms is None and isinstance(model.traces, MtscompEphysReader): # TODO: customizable values below. model.save_spikes_subset_waveforms( max_n_spikes_per_template=500, max_n_channels=16) create_app() controller = TemplateController(model=model, dir_path=dir_path, **kwargs) gui = controller.create_gui() gui.show() run_app() gui.close() controller.model.close()
def main(argv=None): if argv is None: argv = sys.argv[1:] gheader = Fore.GREEN + get_header() header = gheader + Fore.RESET parser = argparse.ArgumentParser(description=header, formatter_class=argparse.RawTextHelpFormatter) parser.add_argument('datafile', help='data file') parser.add_argument('-e', '--extension', help='extension to consider for visualization', default='') if len(argv) == 0: parser.print_help() sys.exit() args = parser.parse_args(argv) filename = os.path.abspath(args.datafile) extension = args.extension params = circus.shared.utils.io.load_parameters(filename) mytest = StrictVersion(phycontrib.__version__) >= StrictVersion("1.0.12") if not mytest: print_and_log(['You need to update phy-contrib to the latest git version'], 'error', params) sys.exit(0) sampling_rate = float(params.getint('data', 'sampling_rate')) data_dtype = params.get('data', 'data_dtype') file_out_suff = params.get('data', 'file_out_suff') data_offset = params.getint('data', 'data_offset') probe = read_probe(params) if extension != '': extension = '-' + extension output_path = params.get('data', 'file_out_suff') + extension + '.GUI' if not os.path.exists(output_path): print_and_log(['Data should be first exported with the converting method!'], 'error', params) else: print_and_log(["Launching the phy GUI..."], 'info', params) gui_params = {} gui_params['dat_path'] = params.get('data', 'data_file') gui_params['n_channels_dat'] = params.getint('data', 'N_total') gui_params['n_features_per_channel'] = 5 gui_params['dtype'] = params.get('data', 'data_dtype') gui_params['offset'] = params.getint('data', 'data_offset') gui_params['sample_rate'] = params.getint('data', 'sampling_rate') gui_params['hp_filtered'] = True os.chdir(output_path) create_app() controller = TemplateController(**gui_params) gui = controller.create_gui() gui.show() run_app() gui.close() del gui
def main(argv=None): if argv is None: argv = sys.argv[1:] header = get_colored_header() header += '''Utility to launch the phy GUI and visualize the results. [data must be first converted with the converting mode] ''' parser = argparse.ArgumentParser( description=header, formatter_class=argparse.RawTextHelpFormatter) parser.add_argument('datafile', help='data file') parser.add_argument('-e', '--extension', help='extension to consider for visualization', default='') if len(argv) == 0: parser.print_help() sys.exit() args = parser.parse_args(argv) filename = os.path.abspath(args.datafile) extension = args.extension params = CircusParser(filename) if os.path.exists(params.logfile): os.remove(params.logfile) logger = init_logging(params.logfile) logger = logging.getLogger(__name__) if extension != '': extension = '-' + extension try: import traitlets except ImportError: print_and_log( ['The package traitlets required by phy is not installed'], 'error', logger) sys.exit(1) try: import click except ImportError: print_and_log(['The package click required by phy is not installed'], 'error', logger) sys.exit(1) try: import joblib except ImportError: print_and_log(['The package joblib required by phy is not installed'], 'error', logger) sys.exit(1) if HAVE_PHYCONTRIB: mytest = StrictVersion( phycontrib.__version__) >= StrictVersion("1.0.12") if not mytest: print_and_log( ['You need to update phy-contrib to the latest git version'], 'error', logger) sys.exit(1) print_and_log([ 'phy-contrib is deprecated, you should upgrade to phy 2.0 and phylib' ], 'info', logger) if HAVE_PHYLIB: try: import colorcet except ImportError: print_and_log( ['The package colorcet required by phy is not installed'], 'error', logger) sys.exit(1) try: import qtconsole except ImportError: print_and_log( ['The package qtconsole required by phy is not installed'], 'error', logger) sys.exit(1) if not test_patch_for_similarities(params, extension): print_and_log( ['You should re-export the data because of a fix in 0.6'], 'error', logger) continue_anyway = query_yes_no( Fore.WHITE + "Continue anyway (results may not be fully correct)?", default=None) if not continue_anyway: sys.exit(1) data_file = params.get_data_file() data_dtype = data_file.data_dtype if data_file.params.has_key('data_offset'): data_offset = data_file.data_offset else: data_offset = 0 file_format = data_file.description file_out_suff = params.get('data', 'file_out_suff') if file_format not in supported_by_phy: print_and_log([ "File format %s is not supported by phy. TraceView disabled" % file_format ], 'info', logger) if numpy.iterable(data_file.gain): print_and_log( ['Multiple gains are not supported, using a default value of 1'], 'info', logger) gain = 1 else: if data_file.gain != 1: print_and_log([ "Gain of %g is not supported by phy. Expecting a scaling mismatch" % data_file.gain ], 'info', logger) gain = data_file.gain probe = params.probe output_path = params.get('data', 'file_out_suff') + extension + '.GUI' if not os.path.exists(output_path): print_and_log( ['Data should be first exported with the converting method!'], 'error', logger) else: print_and_log(["Launching the phy GUI..."], 'info', logger) gui_params = {} if file_format in supported_by_phy: if not params.getboolean('data', 'overwrite'): gui_params['dat_path'] = r"%s" % params.get( 'data', 'data_file_no_overwrite') else: if params.get('data', 'stream_mode') == 'multi-files': data_file = params.get_data_file(source=True, has_been_created=False) gui_params['dat_path'] = [ r"%s" % f for f in data_file.get_file_names() ] else: gui_params['dat_path'] = r"%s" % params.get( 'data', 'data_file') else: gui_params['dat_path'] = 'giverandomname.dat' gui_params['n_channels_dat'] = params.nb_channels gui_params['n_features_per_channel'] = 5 gui_params['dtype'] = data_dtype gui_params['offset'] = data_offset gui_params['sample_rate'] = params.rate gui_params['dir_path'] = output_path gui_params['hp_filtered'] = True os.chdir(output_path) create_app() controller = TemplateController(**gui_params) gui = controller.create_gui() gui.show() run_app() gui.close() del gui
def main(argv=None): if argv is None: argv = sys.argv[1:] header = get_colored_header() parser = argparse.ArgumentParser( description=header, formatter_class=argparse.RawTextHelpFormatter) parser.add_argument('datafile', help='data file') parser.add_argument('-e', '--extension', help='extension to consider for visualization', default='') if len(argv) == 0: parser.print_help() sys.exit() args = parser.parse_args(argv) filename = os.path.abspath(args.datafile) extension = args.extension params = CircusParser(filename) if os.path.exists(params.logfile): os.remove(params.logfile) logger = init_logging(params.logfile) logger = logging.getLogger(__name__) mytest = StrictVersion(phycontrib.__version__) >= StrictVersion("1.0.12") if not mytest: print_and_log( ['You need to update phy-contrib to the latest git version'], 'error', logger) sys.exit(1) data_file = params.get_data_file() data_dtype = data_file.data_dtype if hasattr(data_file, 'data_offset'): data_offset = data_file.data_offset else: data_offset = 0 file_format = data_file.description file_out_suff = params.get('data', 'file_out_suff') if file_format not in supported_by_phy: print_and_log([ "File format %s is not supported by phy. TraceView disabled" % file_format ], 'info', logger) if numpy.iterable(data_file.gain): print_and_log( ['Multiple gains are not supported, using a default value of 1'], 'info', logger) gain = 1 else: if data_file.gain != 1: print_and_log([ "Gain of %g is not supported by phy. Expecting a scaling mismatch" % gain ], 'info', logger) gain = data_file.gain probe = params.probe if extension != '': extension = '-' + extension output_path = params.get('data', 'file_out_suff') + extension + '.GUI' if not os.path.exists(output_path): print_and_log( ['Data should be first exported with the converting method!'], 'error', logger) else: print_and_log(["Launching the phy GUI..."], 'info', logger) gui_params = {} if file_format in supported_by_phy: gui_params['dat_path'] = params.get('data', 'data_file') else: gui_params['dat_path'] = '' gui_params['n_channels_dat'] = params.nb_channels gui_params['n_features_per_channel'] = 5 gui_params['dtype'] = data_dtype gui_params['offset'] = data_offset gui_params['sample_rate'] = params.rate gui_params['hp_filtered'] = True os.chdir(output_path) create_app() controller = TemplateController(**gui_params) gui = controller.create_gui() gui.show() run_app() gui.close() del gui
def create_trace_gui(dat_path, **kwargs): """Create the Trace GUI. Parameters ---------- dat_path : str or Path Path to the raw data file. sample_rate : float The data sampling rate, in Hz. n_channels_dat : int The number of columns in the raw data file. dtype : str The NumPy data type of the raw binary file. """ gui_name = 'TraceGUI' dat_path = Path(dat_path) # Support passing a params.py file. if dat_path.suffix == '.py': params = get_template_params(str(dat_path)) return create_trace_gui(next(iter(params.pop('dat_path'))), **params) if dat_path.suffix == '.cbin': # pragma: no cover data = load_raw_data(path=dat_path) sample_rate = data.sample_rate n_channels_dat = data.shape[1] else: sample_rate = float(kwargs['sample_rate']) assert sample_rate > 0. n_channels_dat = int(kwargs['n_channels_dat']) dtype = np.dtype(kwargs['dtype']) offset = int(kwargs['offset'] or 0) order = kwargs.get('order', None) # Memmap the raw data file. data = load_raw_data( path=dat_path, n_channels_dat=n_channels_dat, dtype=dtype, offset=offset, order=order, ) duration = data.shape[0] / sample_rate create_app() gui = GUI(name=gui_name, subtitle=dat_path.resolve(), enable_threading=False) gui.set_default_actions() def _get_traces(interval): return Bunch( data=select_traces(data, interval, sample_rate=sample_rate)) # TODO: load channel information view = TraceView( traces=_get_traces, n_channels=n_channels_dat, sample_rate=sample_rate, duration=duration, enable_threading=False, ) view.attach(gui) return gui
def main(argv=None): if argv is None: argv = sys.argv[1:] header = get_colored_header() parser = argparse.ArgumentParser( description=header, formatter_class=argparse.RawTextHelpFormatter) parser.add_argument('datafile', help='data file') parser.add_argument('-e', '--extension', help='extension to consider for visualization', default='') if len(argv) == 0: parser.print_help() sys.exit() args = parser.parse_args(argv) filename = os.path.abspath(args.datafile) extension = args.extension params = CircusParser(filename) if os.path.exists(params.logfile): os.remove(params.logfile) logger = init_logging(params.logfile) logger = logging.getLogger(__name__) mytest = StrictVersion(phycontrib.__version__) >= StrictVersion("1.0.12") if not mytest: print_and_log( ['You need to update phy-contrib to the latest git version'], 'error', logger) sys.exit(1) if not test_patch_for_similarities(params, extension): print_and_log( ['You should re-export the data because of a fix in 0.6'], 'error', logger) continue_anyway = query_yes_no( Fore.WHITE + "Continue anyway (results may not be fully correct)?", default=None) if not continue_anyway: sys.exit(1) data_file = params.get_data_file() data_dtype = data_file.data_dtype if data_file.params.has_key('data_offset'): data_offset = data_file.data_offset else: data_offset = 0 file_format = data_file.description file_out_suff = params.get('data', 'file_out_suff') if file_format not in supported_by_phy: print_and_log([ "File format %s is not supported by phy. TraceView disabled" % file_format ], 'info', logger) if numpy.iterable(data_file.gain): print_and_log( ['Multiple gains are not supported, using a default value of 1'], 'info', logger) gain = 1 else: if data_file.gain != 1: print_and_log([ "Gain of %g is not supported by phy. Expecting a scaling mismatch" % data_file.gain ], 'info', logger) gain = data_file.gain probe = params.probe if extension != '': extension = '-' + extension output_path = params.get('data', 'file_out_suff') + extension + '.GUI' if not os.path.exists(output_path): print_and_log( ['Data should be first exported with the converting method!'], 'error', logger) else: print_and_log(["Launching the phy GUI..."], 'info', logger) gui_params = {} if file_format in supported_by_phy: if not params.getboolean('data', 'overwrite'): gui_params['dat_path'] = params.get('data', 'data_file_no_overwrite') else: if params.get('data', 'stream_mode') == 'multi-files': data_file = params.get_data_file(source=True, has_been_created=False) gui_params['dat_path'] = ' '.join( data_file.get_file_names()) else: gui_params['dat_path'] = params.get('data', 'data_file') else: gui_params['dat_path'] = 'giverandomname.dat' gui_params['n_channels_dat'] = params.nb_channels gui_params['n_features_per_channel'] = 5 gui_params['dtype'] = data_dtype gui_params['offset'] = data_offset gui_params['sample_rate'] = params.rate gui_params['dir_path'] = output_path gui_params['hp_filtered'] = True f = open(os.path.join(output_path, 'params.py'), 'w') for key, value in gui_params.items(): if key in ['dir_path', 'dat_path', 'dtype']: f.write('%s = "%s"\n' % (key, value)) else: f.write("%s = %s\n" % (key, value)) f.close() os.chdir(output_path) create_app() controller = TemplateController(**gui_params) gui = controller.create_gui() gui.show() run_app() gui.close() del gui
modifiers = event.modifiers if 1 in event.buttons and modifiers is not (): p1 = event.press_event.pos p2 = event.last_event.pos if modifiers[0].name == 'Shift': self.cross.ref_enable(p2) elif self.cross.cross_state: if event.press_event is None: self.cross.moveto(event.pos) self.cross.ref_disable() if __name__ == '__main__': from phy.gui import GUI, create_app, run_app create_app() gui = GUI(position=(0, 0), size=(600, 400), name='GUI') ############################################## ### Test scatter_view from sklearn.preprocessing import normalize n = 1000000 fet = np.random.randn(n,3) fet = normalize(fet,axis=1) print fet.shape clu = np.random.randint(3,size=(n,1)) scatter_view = view_scatter_3d() scatter_view.attach(gui) scatter_view.set_data(fet, clu) ############################################################################################# from Binload import Binload ### Set Parameters ###