def main(): parser = OptionParser(usage=description) parser.add_option("--db", default='flydra_db', help="FlydraDB directory") (options, args) = parser.parse_args() #@UnusedVariable if options.db is None: logger.error('Please specify a directory using --db.') sys.exit(-1) db = FlydraDB(options.db) for sample in db.list_samples(): if not db.has_rows(sample): continue rows = db.get_rows(sample) v = rows[:]['linear_velocity_modulus'] perc = [1, 5, 95, 99] print "Sample %s" % sample print " linear_velocity_modulus" for p in perc: s = scipy.stats.scoreatpercentile(v, p) print ' - %2d%% %.3f m/s' % (p, s) db.release_table(rows)
def main(): parser = OptionParser(usage=description) parser.add_option("--out", help="Output data directory", default="flydra2ros") parser.add_option("--db", help="Location of input Flydra db.") (options, args) = parser.parse_args() # @UnusedVariable if not options.db: raise Exception("Please define FlydraDB directory using `--db`.") verbose = True def printv(s): if verbose: print(s) db = FlydraDB(options.db, create=False) configuration = "use_for_report" for sample in db.list_samples(): if not db.has_table(sample, table=SACCADES_TABLE, version=configuration): continue group = guess_group(db, sample) magno = {} table = db.get_table(sample, SACCADES_TABLE, configuration) species = db.get_attr(sample, "species", "Dmelanogaster") magno["species"] = species magno["sample"] = sample # _name if db.has_table(sample, EXP_DATA_TABLE): exp_data = db.get_table(sample, EXP_DATA_TABLE) print(exp_data.dtype) timestamp = exp_data[:]["timestamp"] else: timestamp = None magno["use_for_report"] = convert_saccades_to_ros(table, timestamp) db.release_table(table) if timestamp is not None: db.release_table(exp_data) output_dir = os.path.join(options.out, group) filename = os.path.join(output_dir, "magno_%s.mat" % sample) printv("writing to %s" % filename) if not os.path.exists(output_dir): os.makedirs(output_dir) scipy.io.savemat(filename, {"magno": magno}, oned_as="row") # put species and sample print("closing") db.close()
def main(): parser = OptionParser() parser.add_option("--db", default='flydra_db', help="FlydraDB directory") parser.add_option("--nocache", help="Ignores already computed results.", default=False, action="store_true") parser.add_option("--sigma", help="Kernel spread (degrees)", type="float", default=6) parser.add_option("--source", default='luminance', help="Source table") parser.add_option("--target", default='contrast', help="Destination table") (options, args) = parser.parse_args() kernel = get_contrast_kernel(sigma_deg=options.sigma, eyes_interact=False) kernel = kernel.astype('float32').copy('C') db = FlydraDB(options.db, False) if args: do_samples = args else: do_samples = db.list_samples() do_samples = filter(lambda x: db.has_table(x, options.source), do_samples) if not do_samples: raise Exception('No samples with table "%s" found. ' % options.source) for i, sample_id in enumerate(do_samples): logger.info('Sample %s/%s: %s' % (i + 1, len(do_samples), sample_id)) if not db.has_sample(sample_id): raise Exception('Sample %s not found in db.' % sample_id) if not db.has_table(sample_id, options.source): raise Exception('Sample %s does not have table %s; skipping.' \ % (sample_id, options.source)) if db.has_table(sample_id, options.target) and not options.nocache: logger.info('Already computed "%s" for %s; skipping' % \ (options.target, sample_id)) continue luminance = db.get_table(sample_id, options.source) contrast = compute_contrast_for_table(luminance, kernel) db.set_table(sample_id, options.target, contrast) db.release_table(luminance) db.close()
def main(): parser = OptionParser() parser.add_option("--db", help="FlydraDB directory") (options, args) = parser.parse_args() #@UnusedVariable if not options.db: raise Exception('Please define the FlydraDB directory using `--db`.') db = FlydraDB(options.db) choose = { 'andrea_detector': { 'Dpseudoobscura': 'threshold16', 'Dananassae': 'threshold10', 'Dhydei': 'threshold7', 'Dmelanogaster': 'threshold1', 'Darizonae': 'threshold9', 'Dmojavensis': 'threshold7', 'peter': 'peters_conf', 'mamaramaposts': 'use_for_report', 'mamaramanoposts': 'use_for_report' }, 'ros_detector': { 'Dpseudoobscura': 'filt_kalman-amp_th_10-th_4', 'Dananassae': 'filt_kalman-amp_th_10-th_4', 'Dhydei': 'filt_kalman-amp_th_10-th_4', 'Dmelanogaster': 'filt_kalman-amp_th_10-th_4', 'Darizonae': 'filt_kalman-amp_th_10-th_4', 'Dmojavensis': 'filt_kalman-amp_th_10-th_4' } } for official, choices in choose.items(): for group, version in choices.items(): print("Group %r: %r -> %r" % (group, version, official)) samples = db.list_samples_for_group(group) for sample in samples: print(" sample %r" % sample) table = db.get_table(sample, SACCADES_TABLE, version=version) copy = numpy.array(table, dtype=table.dtype) db.set_table(sample=sample, table=SACCADES_TABLE, version=official, data=copy) db.release_table(table) db.close()
def compute_environment_autocorrelation(db, samples, image, maxlag=50): nsensors = 1398 results = numpy.ndarray(shape=(nsensors, 2 * maxlag + 1)) db = FlydraDB(db, create=False) block_size = 50 num_blocks = int(numpy.ceil(nsensors * 1.0 / block_size)) for b in range(num_blocks): start = block_size * b stop = min(start + block_size, nsensors) progress('Computing autocorrelation', (b, num_blocks)) data = [[] for i in range(nsensors)] for k, sample in enumerate(samples): progress('getting data', (k, len(samples)), sample) table = db.get_table(sample, image) chunk = (table[:]['value'][:, start:stop]).copy() for j, i in enumerate(range(start, stop)): data[i].append(chunk[:, j]) db.release_table(table) for j, i in enumerate(range(start, stop)): progress('Computing correlation', (j, stop - start)) x = numpy.concatenate(data[i]) corr, lags = xcorr(x, maxlag=maxlag) assert(len(lags) == 2 * maxlag + 1) results[i, :] = corr db.close() data = { 'results': results, 'lags': lags } return data
def get_all_data_for_signal(db, samples, interval_function, signal, signal_component): db = FlydraDB(db, False) all = [] for id in samples: if not db.has_rows(id): logger.warning('Could not find rows table for %s; skipping.' % (id)) continue rows_table = db.get_rows(id) try: interval = interval_function(db, id, rows_table) except Exception as e: logger.warning('Cannot compute interval for sample %s: %s '\ % (id, e)) db.release_table(rows_table) continue rows = rows_table[interval] s = extract_signal(rows, signal, signal_component) all.append(s) db.release_table(rows_table) db.close() return numpy.concatenate(all)
def compute_mean_generic(db, samples, image, operator): ''' db: FlydraDB directory samples: list of IDs ''' db = FlydraDB(db, False) results = { 'samples': {} } ex = Expectation() for i, id in enumerate(samples): progress('Computing mean %s' % image, (i, len(samples)), "Sample %s" % id) if not (db.has_sample(id) and db.has_table(id, image)): raise ValueError('No table "%s" for id %s' % (image, id)) data = db.get_table(id, image) values = data[:]['value'] this = operator(values) # print "id: %s len: %d %d" % (id, len(data), len(values)) ex.update(this, len(data)) results['samples'][id] = this db.release_table(data) results['all'] = ex.get_value() db.close() return results
def create_and_write_report(flydra_db, sample, image_name): view_start = 'saccades_view_start_%s' % image_name view_stop = 'saccades_view_stop_%s' % image_name view_rstop = 'saccades_view_rstop_%s' % image_name db = FlydraDB(flydra_db, False) saccades = db.get_saccades(sample) values_start = db.get_table(sample, view_start) values_stop = db.get_table(sample, view_stop) values_rstop = db.get_table(sample, view_rstop) r = Report(sample) for i in range(len(saccades)): ri = r.node("saccade-%04d" % i) ri.data_rgb('start', plot_luminance(values_start[i]['value'])) ri.data_rgb('stop', plot_luminance(values_stop[i]['value'])) ri.data_rgb('rstop', plot_luminance(values_rstop[i]['value'])) f = ri.figure(shape=(1, 3)) f.sub('start', 'At saccade start') f.sub('stop', 'At saccade stop') #f.sub('rstop', '(random stop)') db.release_table(saccades) db.release_table(values_start) db.release_table(values_stop) db.release_table(values_rstop) filename = "%s/out/saccade_view_show/%s_%s.html" % (flydra_db, image_name, sample) print "Writing to %s" % filename r.to_html(filename)
def main(): parser = OptionParser() parser.add_option("--db", default='flydra_db', help="FlydraDB directory") parser.add_option("--nocache", help="Ignores already computed results.", default=False, action="store_true") parser.add_option("--compute_mu", help="Computes mu and optic flow.", default=False, action="store_true") parser.add_option("--white", help="Computes luminance_w, with the arena" " painted white.", default=False, action="store_true") parser.add_option("--host", help="Use a remote rfsee. Otherwise, use local process.", default=None) (options, args) = parser.parse_args() #@UnusedVariable db = FlydraDB(options.db, False) # look for samples with the rows table do_samples = db.list_samples() do_samples = filter(lambda x: db.has_rows(x) and db.get_attr(x, 'stimulus') == 'nopost', do_samples) if not do_samples: raise Exception('Cannot find samples to hallucinate about.') print "Summary, including nopost." for s in sorted(get_db_stimulus_stats(db, include_nopost=True), key=(lambda x:-x.total_length)): print "stimulus: {s.stimulus:>10} samples: {s.total_number:>5} "\ " total length: {len:>5} minutes".format(s=s, len=s.total_length / (60 * 60)) stimulus_to_use = list(get_stimulus_to_use(db, len(do_samples))) for i, sample in enumerate(do_samples): stimulus = stimulus_to_use[i][0] print sample, stimulus if options.white: target = 'hluminance_w' else: target = 'hluminance' for i, sample_id in enumerate(do_samples): stimulus = stimulus_to_use[i][0] stimulus_xml = stimulus_to_use[i][1] print 'Sample %s/%s: %s' % (i + 1, len(do_samples), sample_id) if not db.has_sample(sample_id): raise Exception('Sample %s not found in db.' % sample_id) if not db.has_rows(sample_id): raise Exception('Sample %s does not have rows table.' % sample_id) if options.compute_mu: if db.has_table(sample_id, 'nearness') and not options.nocache: logger.info('Already computed nearness for %s; skipping' % sample_id) continue else: if db.has_table(sample_id, target) and not options.nocache: logger.info('Already computed luminance for %s; skipping' % sample_id) continue rows = db.get_rows(sample_id) results = render(rows, stimulus_xml, host=options.host, compute_mu=options.compute_mu, white=options.white) db.set_table(sample_id, target, results['luminance']) if options.compute_mu: db.set_table(sample_id, 'hnearness', results['nearness']) db.set_table(sample_id, 'hretinal_velocities', results['retinal_velocities']) db.release_table(rows) db.close()
def main(): parser = OptionParser(usage=description) parser.add_option("--db", default='flydra_db', help="FlydraDB directory") parser.add_option("--nocache", help="Ignores already computed results.", default=False, action="store_true") parser.add_option("--white", help="Computes luminance_w, with the arena" " painted white.", default=False, action="store_true") parser.add_option("--host", help="Use a remote rfsee. Otherwise," "use local process.", default=None) (options, args) = parser.parse_args() if options.db is None: logger.error('Please specify a directory using --db.') sys.exit(-1) db = FlydraDB(options.db) if args: do_samples = args else: # look for samples with the rows table all_samples = db.list_samples() do_samples = filter(lambda x: db.has_saccades(x) and db.has_attr(x, 'stimulus_xml'), all_samples) logger.info('Found %d/%d samples with saccades and stimulus info.' % (len(do_samples), len(all_samples))) image = 'luminance_w' if options.white else 'luminance' target_start = 'saccades_view_start_%s' % image target_stop = 'saccades_view_stop_%s' % image target_rstop = 'saccades_view_rstop_%s' % image target_sstop = 'saccades_view_sstop_%s' % image target_random = 'saccades_view_random_%s' % image for i, sample_id in enumerate(do_samples): logger.info('Sample %s/%s: %s' % (i + 1, len(do_samples), sample_id)) if not db.has_sample(sample_id): raise Exception('Sample %s not found in db.' % sample_id) if not db.has_saccades(sample_id): raise Exception('Sample %s does not have saccades table.' % sample_id) if not db.has_attr(sample_id, 'stimulus_xml'): raise Exception('Sample %s does not have the stimulus' ' information ("stimulus_xml")' % sample_id) # todo: check stale dependencies if db.has_table(sample_id, target_start) and \ db.has_table(sample_id, target_stop) and \ db.has_table(sample_id, target_rstop) and \ db.has_table(sample_id, target_sstop) and \ db.has_table(sample_id, target_random) and \ not options.nocache: logger.info('Targets already computed for %s; skipping' % sample_id) continue # Get the stimulus description stimulus_xml = db.get_attr(sample_id, 'stimulus_xml') saccades = db.get_saccades(sample_id) view_start, view_stop, view_rstop, view_random, view_sstop = \ render_saccades_view( saccades=saccades, stimulus_xml=stimulus_xml, host=options.host, white=options.white) db.set_table(sample_id, target_start, view_start) db.set_table(sample_id, target_stop, view_stop) db.set_table(sample_id, target_rstop, view_rstop) db.set_table(sample_id, target_random, view_random) db.set_table(sample_id, target_sstop, view_sstop) db.release_table(saccades) db.close()
def main(): parser = OptionParser() parser.add_option("--db", default='flydra_db', help="FlydraDB directory") parser.add_option("--nocache", help="Ignores already computed results.", default=False, action="store_true") parser.add_option("--compute_mu", help="Computes mu and optic flow.", default=False, action="store_true") parser.add_option("--white", help="Computes luminance_w, with the arena" " painted white.", default=False, action="store_true") parser.add_option("--host", help="Use a remote rfsee. Otherwise, use local process.", default=None) (options, args) = parser.parse_args() db = FlydraDB(options.db, False) if args: do_samples = args else: # look for samples with the rows table do_samples = db.list_samples() do_samples = filter(lambda x: db.has_rows(x), do_samples) if options.white: target = 'luminance_w' else: target = 'luminance' for i, sample_id in enumerate(do_samples): print 'Sample %s/%s: %s' % (i + 1, len(do_samples), sample_id) if not db.has_sample(sample_id): raise Exception('Sample %r not found in db.' % sample_id) if not db.has_rows(sample_id): raise Exception('Sample %r does not have rows table.' % sample_id) if not db.has_attr(sample_id, 'stimulus_xml'): raise Exception('Sample %r does not have the "stimulus_xml" attribute.' %sample_id) if options.compute_mu: if db.has_table(sample_id, 'nearness') and not options.nocache: logger.info('Already computed nearness for %r; skipping' % sample_id) continue else: if db.has_table(sample_id, target) and not options.nocache: logger.info('Already computed luminance for %r; skipping' % sample_id) continue rows = db.get_rows(sample_id) stimulus_xml = db.get_attr(sample_id, 'stimulus_xml') results = render(rows, stimulus_xml, host=options.host, compute_mu=options.compute_mu, white=options.white) db.set_table(sample_id, target, results['luminance']) if options.compute_mu: db.set_table(sample_id, 'nearness', results['nearness']) db.set_table(sample_id, 'retinal_velocities', results['retinal_velocities']) db.release_table(rows) db.close()