# Path: pyrl/runtools.py
# def behaviorfile(path):
# def activityfile(path):
# def run(action, trials, pg, scratchpath, dt_save=None):
# 
# Path: pyrl/tasktools.py
# def generate_ei(N, pE=0.8):
# def to_map(*args):
# def get_idx(t, (start, end)):
# def get_epochs_idx(dt, epochs):
# def choice(rng, a):
# def unravel_index(i, dims):
# def uniform(rng, dt, xmin, xmax):
# def truncated_exponential(rng, dt, mean, xmin=0, xmax=np.inf):
# def divide(x, y):
# def correct_2AFC(perf):
#     def __init__(self):
#     EXC = idx[:Nexc]
#     INH = idx[Nexc:]
# class Task(object):
# 
# Path: pyrl/utils.py
# def println(line):
# def mkdir_p(path):
# def savelist(filename, list_):
# def loadlist(filename):
# def print_dict(settings_, indent=2, title=None):
# def copy_to_clipboard(s):
# def div(x, y):
# def divide(x, y):
# def get_here(file):
# def get_parent(dir):
# def save(filename, obj):
# def load(filename):
# def mm_to_inch(mm):
# def elapsed_time(tstart):
# 
# Path: pyrl/figtools.py
# THIS = "pyrl.figtools"
#     FNULL = open(os.devnull, 'w')
# def gradient(cmin, cmax):
# def apply_alpha(color, alpha=0.7):
#     def __getattr__(self, name):
#     def __init__(self, fig, p, rect):
#     def set_thickness(self, thickness):
#     def set_tick_params(self, ticksize, ticklabelsize, ticklabelpad):
#     def format(self, style, p=None):
#     def axis_off(self, axis='left'):
#     def plot(self, *args, **kwargs):
#     def xlabel(self, *args, **kwargs):
#     def ylabel(self, *args, **kwargs):
#     def xticks(self, *args, **kwargs):
#     def yticks(self, *args, **kwargs):
#     def xticklabels(self, *args, **kwargs):
#     def yticklabels(self, *args, **kwargs):
#     def equal(self):
#     def legend(self, *args, **kargs):
#     def text_upper_center(self, s, dx=0, dy=0, fontsize=7.5, color='k', **kwargs):
#     def text_upper_left(self, s, dx=0, dy=0, fontsize=7.5, color='k', **kwargs):
#     def text_upper_right(self, s, dx=0, dy=0, fontsize=7.5, color='k', **kwargs):
#     def text_lower_center(self, s, dx=0, dy=0, fontsize=7.5, color='k', **kwargs):
#     def text_lower_left(self, s, dx=0, dy=0, fontsize=7.5, color='k', **kwargs):
#     def text_lower_right(self, s, dx=0, dy=0, fontsize=7.5, color='k', **kwargs):
#     def hline(self, y, **kwargs):
#     def vline(self, x, **kwargs):
#     def circle(self, center, r, **kwargs):
#     def highlight(self, x1, x2, **kwargs):
#     def lim(self, axis, data, lower=None, upper=None, margin=0.05, relative=True):
#     def sturges(data):
#     def scott(data, ddof=0):
#     def hist(self, data, bins=None, get_binedges=False, lw=0, **kwargs):
#     def __getattr__(self, name):
#     def __init__(self, fig, p, rect):
#     def xlabel(self, *args, **kwargs):
#     def ylabel(self, *args, **kwargs):
#     def zlabel(self, *args, **kwargs):
#     def xticks(self, *args, **kwargs):
#     def yticks(self, *args, **kwargs):
#     def zticks(self, *args, **kwargs):
#     def zcircle(self, center, r, z0, **kwargs):
#     def colors(name):
#     def __getattr__(self, name):
#     def __init__(self, **kwargs):
#     def add(self, name=None, rect=None, style='bottomleft', projection=None, **kwargs):
#     def __getitem__(self, k):
#     def plotlabels(self, labels, **kwargs):
#     def shared_lim(self, plots, axis, data, **kwargs):
#     def save(self, name=None, path=None, fmt=None, transparent=True, **kwargs):
#     def close(self):
# class Subplot(object):
# class Subplot3D(object):
# class Figure(object):


import os
import numpy as np
from pyrl          import runtools, tasktools, utils
from pyrl.figtools import Figure, mpl
#/////////////////////////////////////////////////////////////////////////////////////////

cmap = mpl.cm.jet
norm = mpl.colors.Normalize(vmin=10, vmax=34)
smap = mpl.cm.ScalarMappable(norm, cmap)

#/////////////////////////////////////////////////////////////////////////////////////////

def performance(trialsfile, plot, **kwargs):
    # Load trials
    trials, A, R, M, perf = utils.load(trialsfile)

    correct_by_cond = {}
    for n, trial in enumerate(trials):
        if not perf.decisions[n]:
            continue

        gt_lt = trial['gt_lt']
        fpair = trial['fpair']
        if gt_lt == '>':
            f1, f2 = fpair
        else:
            f2, f1 = fpair
        cond = (f1, f2)

        correct_by_cond.setdefault(cond, []).append(perf.corrects[n])

    pcorrect_by_cond = {}
    for c in correct_by_cond:
        corrects = correct_by_cond[c]

# Path: pyrl/runtools.py
# def behaviorfile(path):
# def activityfile(path):
# def run(action, trials, pg, scratchpath, dt_save=None):
# 
# Path: pyrl/tasktools.py
# def generate_ei(N, pE=0.8):
# def to_map(*args):
# def get_idx(t, (start, end)):
# def get_epochs_idx(dt, epochs):
# def choice(rng, a):
# def unravel_index(i, dims):
# def uniform(rng, dt, xmin, xmax):
# def truncated_exponential(rng, dt, mean, xmin=0, xmax=np.inf):
# def divide(x, y):
# def correct_2AFC(perf):
#     def __init__(self):
#     EXC = idx[:Nexc]
#     INH = idx[Nexc:]
# class Task(object):
# 
# Path: pyrl/utils.py
# def println(line):
# def mkdir_p(path):
# def savelist(filename, list_):
# def loadlist(filename):
# def print_dict(settings_, indent=2, title=None):
# def copy_to_clipboard(s):
# def div(x, y):
# def divide(x, y):
# def get_here(file):
# def get_parent(dir):
# def save(filename, obj):
# def load(filename):
# def mm_to_inch(mm):
# def elapsed_time(tstart):
# 
# Path: pyrl/figtools.py
# THIS = "pyrl.figtools"
#     FNULL = open(os.devnull, 'w')
# def gradient(cmin, cmax):
# def apply_alpha(color, alpha=0.7):
#     def __getattr__(self, name):
#     def __init__(self, fig, p, rect):
#     def set_thickness(self, thickness):
#     def set_tick_params(self, ticksize, ticklabelsize, ticklabelpad):
#     def format(self, style, p=None):
#     def axis_off(self, axis='left'):
#     def plot(self, *args, **kwargs):
#     def xlabel(self, *args, **kwargs):
#     def ylabel(self, *args, **kwargs):
#     def xticks(self, *args, **kwargs):
#     def yticks(self, *args, **kwargs):
#     def xticklabels(self, *args, **kwargs):
#     def yticklabels(self, *args, **kwargs):
#     def equal(self):
#     def legend(self, *args, **kargs):
#     def text_upper_center(self, s, dx=0, dy=0, fontsize=7.5, color='k', **kwargs):
#     def text_upper_left(self, s, dx=0, dy=0, fontsize=7.5, color='k', **kwargs):
#     def text_upper_right(self, s, dx=0, dy=0, fontsize=7.5, color='k', **kwargs):
#     def text_lower_center(self, s, dx=0, dy=0, fontsize=7.5, color='k', **kwargs):
#     def text_lower_left(self, s, dx=0, dy=0, fontsize=7.5, color='k', **kwargs):
#     def text_lower_right(self, s, dx=0, dy=0, fontsize=7.5, color='k', **kwargs):
#     def hline(self, y, **kwargs):
#     def vline(self, x, **kwargs):
#     def circle(self, center, r, **kwargs):
#     def highlight(self, x1, x2, **kwargs):
#     def lim(self, axis, data, lower=None, upper=None, margin=0.05, relative=True):
#     def sturges(data):
#     def scott(data, ddof=0):
#     def hist(self, data, bins=None, get_binedges=False, lw=0, **kwargs):
#     def __getattr__(self, name):
#     def __init__(self, fig, p, rect):
#     def xlabel(self, *args, **kwargs):
#     def ylabel(self, *args, **kwargs):
#     def zlabel(self, *args, **kwargs):
#     def xticks(self, *args, **kwargs):
#     def yticks(self, *args, **kwargs):
#     def zticks(self, *args, **kwargs):
#     def zcircle(self, center, r, z0, **kwargs):
#     def colors(name):
#     def __getattr__(self, name):
#     def __init__(self, **kwargs):
#     def add(self, name=None, rect=None, style='bottomleft', projection=None, **kwargs):
#     def __getitem__(self, k):
#     def plotlabels(self, labels, **kwargs):
#     def shared_lim(self, plots, axis, data, **kwargs):
#     def save(self, name=None, path=None, fmt=None, transparent=True, **kwargs):
#     def close(self):
# class Subplot(object):
# class Subplot3D(object):
# class Figure(object):


# Path: examples/analysis/romo.py
import os
import numpy as np
from pyrl          import runtools, tasktools, utils
from pyrl.figtools import Figure, mpl

#/////////////////////////////////////////////////////////////////////////////////////////

cmap = mpl.cm.jet
norm = mpl.colors.Normalize(vmin=10, vmax=34)
smap = mpl.cm.ScalarMappable(norm, cmap)

#/////////////////////////////////////////////////////////////////////////////////////////

def performance(trialsfile, plot, **kwargs):
    # Load trials
    trials, A, R, M, perf = utils.load(trialsfile)

    correct_by_cond = {}
    for n, trial in enumerate(trials):
        if not perf.decisions[n]:
            continue

        gt_lt = trial['gt_lt']
        fpair = trial['fpair']
        if gt_lt == '>':
            f1, f2 = fpair
        else:
            f2, f1 = fpair
        cond = (f1, f2)

        correct_by_cond.setdefault(cond, []).append(perf.corrects[n])

    pcorrect_by_cond = {}
    for c in correct_by_cond:
        corrects = correct_by_cond[c]

        pcorrect_by_cond[c] = utils.divide(sum(corrects), len(corrects))