# 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
# class Figure(object):
#     defaults = {
#         'w':             6.5,
#         'h':             5.5,
#         'rect':          [0.12, 0.12, 0.8, 0.8],
#         'thickness':     0.7,
#         'ticksize':      3.5,
#         'axislabelsize': 10,
#         'ticklabelsize': 9,
#         'ticklabelpad':  2.5,
#         'labelpadx':     7.5,
#         'labelpady':     8.5,
#         'labelpadz':     7.5,
#         'format':        'pdf'
#         }
# 
#     @staticmethod
#     def colors(name):
#         if name in colors:
#             return colors[name]
#         return name
# 
#     #/////////////////////////////////////////////////////////////////////////////////////
# 
#     def __getattr__(self, name):
#         if hasattr(self.fig, name):
#             return getattr(self.fig, name)
#         raise NotImplementedError("Figure." + name)
# 
#     def __init__(self, **kwargs):
#         self.p = kwargs.copy()
#         for k in Figure.defaults:
#             self.p.setdefault(k, Figure.defaults[k])
# 
#         if 'r' in kwargs:
#             self.p['h'] = kwargs['r']*self.p['w']
# 
#         self.fig   = plt.figure(figsize=(self.p['w'], self.p['h']))
#         self.plots = OrderedDict()
# 
#     #/////////////////////////////////////////////////////////////////////////////////////
# 
#     def add(self, name=None, rect=None, style='bottomleft', projection=None, **kwargs):
#         if rect is None:
#             rect = self.p['rect']
# 
#         # Override figure defaults for this subplot
#         p = self.p.copy()
#         for k, v in kwargs.items():
#             if k in p:
#                 p[k] = v
# 
#         # 3D subplot
#         if projection == '3d':
#             return Subplot3D(self.fig, p, rect)
# 
#         plot = Subplot(self.fig, p, rect)
#         if style is not None:
#             plot.format(style, p)
# 
#         # List of plots in this figure
#         if name is None:
#             name = len(self.plots)
#         self.plots[name] = plot
# 
#         return plot
# 
#     #/////////////////////////////////////////////////////////////////////////////////////
# 
#     def __getitem__(self, k):
#         if isinstance(k, int):
#             k = self.plots.keys()[k]
# 
#         return self.plots[k]
# 
#     #/////////////////////////////////////////////////////////////////////////////////////
# 
#     def plotlabels(self, labels, **kwargs):
#         plot = self.plots.values()[0]
#         for label, (x, y) in labels.items():
#             plot.text(x, y, label, ha='left', va='bottom',
#                       transform=self.transFigure, **kwargs)
# 
#     #/////////////////////////////////////////////////////////////////////////////////////
# 
#     def shared_lim(self, plots, axis, data, **kwargs):
#         """
#         Make the axis scale the same in all the plots.
# 
#         """
#         try:
#             data = np.concatenate(data)
#         except:
#             pass
#         data = np.ravel(data)
# 
#         for plot in plots:
#             lim = plot.lim(axis, data, **kwargs)
# 
#         return lim
# 
#     #/////////////////////////////////////////////////////////////////////////////////////
# 
#     def save(self, name=None, path=None, fmt=None, transparent=True, **kwargs):
#         if name is None:
#             name = os.path.splitext(sys.argv[0].split(os.path.sep)[-1])[0]
#         if not name.startswith('/') and path is None:
#             path = os.path.dirname(os.path.realpath(sys.argv[0]))
#             path = os.path.join(path, 'work', 'figs')
#             utils.mkdir_p(path)
# 
#         fname = join(path, name + '.' + self.p['format'])
#         plt.figure(self.fig.number)
#         plt.savefig(fname, transparent=transparent, **kwargs)
#         print("[ Figure.save ] " + fname)
# 
#         # Copy to clipboard if possible
#         utils.copy_to_clipboard(fname)
# 
#     def close(self):
#         plt.close(self.fig)


import imp
import os
import sys
import numpy as np
from pyrl          import utils
from pyrl.figtools import Figure
display_actions(np.mean(durations['fixation']), y_stimulus+shift, rewards, colors)

rewards = ['0', '-1', '-1', '-1']
colors  = ['k', None, None, None]
display_actions(np.mean(durations['stimulus']), y_stimulus+shift, rewards, colors)

rewards = ['0', '-1', '-1', '-1']
colors  = ['k', None, None, None]
display_actions(np.mean(durations['delay']), y_stimulus+shift, rewards, colors)

#-----------------------------------------------------------------------------------------
# Display actions (Ts)
#-----------------------------------------------------------------------------------------

shift = 0.5

rewards = ['0', '0', '1', '0.7']
colors  = [None, None, Figure.colors('darkblue'), Figure.colors('blue')]
display_actions(np.mean(durations['decision']), y_sure_Ts+shift, rewards, colors)

plot.text(durations['sure'][0], y_sure_Ts+shift, 'Sure bet offered',
          ha='left', va='center', fontsize=fontsize+0.5)

#-----------------------------------------------------------------------------------------
# Display actions (no Ts)
#-----------------------------------------------------------------------------------------

shift = 0.3

rewards = ['0', '0', '1', '-1']

# 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
# class Figure(object):
#     defaults = {
#         'w':             6.5,
#         'h':             5.5,
#         'rect':          [0.12, 0.12, 0.8, 0.8],
#         'thickness':     0.7,
#         'ticksize':      3.5,
#         'axislabelsize': 10,
#         'ticklabelsize': 9,
#         'ticklabelpad':  2.5,
#         'labelpadx':     7.5,
#         'labelpady':     8.5,
#         'labelpadz':     7.5,
#         'format':        'pdf'
#         }
# 
#     @staticmethod
#     def colors(name):
#         if name in colors:
#             return colors[name]
#         return name
# 
#     #/////////////////////////////////////////////////////////////////////////////////////
# 
#     def __getattr__(self, name):
#         if hasattr(self.fig, name):
#             return getattr(self.fig, name)
#         raise NotImplementedError("Figure." + name)
# 
#     def __init__(self, **kwargs):
#         self.p = kwargs.copy()
#         for k in Figure.defaults:
#             self.p.setdefault(k, Figure.defaults[k])
# 
#         if 'r' in kwargs:
#             self.p['h'] = kwargs['r']*self.p['w']
# 
#         self.fig   = plt.figure(figsize=(self.p['w'], self.p['h']))
#         self.plots = OrderedDict()
# 
#     #/////////////////////////////////////////////////////////////////////////////////////
# 
#     def add(self, name=None, rect=None, style='bottomleft', projection=None, **kwargs):
#         if rect is None:
#             rect = self.p['rect']
# 
#         # Override figure defaults for this subplot
#         p = self.p.copy()
#         for k, v in kwargs.items():
#             if k in p:
#                 p[k] = v
# 
#         # 3D subplot
#         if projection == '3d':
#             return Subplot3D(self.fig, p, rect)
# 
#         plot = Subplot(self.fig, p, rect)
#         if style is not None:
#             plot.format(style, p)
# 
#         # List of plots in this figure
#         if name is None:
#             name = len(self.plots)
#         self.plots[name] = plot
# 
#         return plot
# 
#     #/////////////////////////////////////////////////////////////////////////////////////
# 
#     def __getitem__(self, k):
#         if isinstance(k, int):
#             k = self.plots.keys()[k]
# 
#         return self.plots[k]
# 
#     #/////////////////////////////////////////////////////////////////////////////////////
# 
#     def plotlabels(self, labels, **kwargs):
#         plot = self.plots.values()[0]
#         for label, (x, y) in labels.items():
#             plot.text(x, y, label, ha='left', va='bottom',
#                       transform=self.transFigure, **kwargs)
# 
#     #/////////////////////////////////////////////////////////////////////////////////////
# 
#     def shared_lim(self, plots, axis, data, **kwargs):
#         """
#         Make the axis scale the same in all the plots.
# 
#         """
#         try:
#             data = np.concatenate(data)
#         except:
#             pass
#         data = np.ravel(data)
# 
#         for plot in plots:
#             lim = plot.lim(axis, data, **kwargs)
# 
#         return lim
# 
#     #/////////////////////////////////////////////////////////////////////////////////////
# 
#     def save(self, name=None, path=None, fmt=None, transparent=True, **kwargs):
#         if name is None:
#             name = os.path.splitext(sys.argv[0].split(os.path.sep)[-1])[0]
#         if not name.startswith('/') and path is None:
#             path = os.path.dirname(os.path.realpath(sys.argv[0]))
#             path = os.path.join(path, 'work', 'figs')
#             utils.mkdir_p(path)
# 
#         fname = join(path, name + '.' + self.p['format'])
#         plt.figure(self.fig.number)
#         plt.savefig(fname, transparent=transparent, **kwargs)
#         print("[ Figure.save ] " + fname)
# 
#         # Copy to clipboard if possible
#         utils.copy_to_clipboard(fname)
# 
#     def close(self):
#         plt.close(self.fig)


# Path: paper/fig_postdecisionwager.py
import imp
import os
import sys
import numpy as np
from pyrl          import utils
from pyrl.figtools import Figure

display_actions(np.mean(durations['fixation']), y_stimulus+shift, rewards, colors)

rewards = ['0', '-1', '-1', '-1']
colors  = ['k', None, None, None]
display_actions(np.mean(durations['stimulus']), y_stimulus+shift, rewards, colors)

rewards = ['0', '-1', '-1', '-1']
colors  = ['k', None, None, None]
display_actions(np.mean(durations['delay']), y_stimulus+shift, rewards, colors)

#-----------------------------------------------------------------------------------------
# Display actions (Ts)
#-----------------------------------------------------------------------------------------

shift = 0.5

rewards = ['0', '0', '1', '0.7']
colors  = [None, None, Figure.colors('darkblue'), Figure.colors('blue')]
display_actions(np.mean(durations['decision']), y_sure_Ts+shift, rewards, colors)

plot.text(durations['sure'][0], y_sure_Ts+shift, 'Sure bet offered',
          ha='left', va='center', fontsize=fontsize+0.5)

#-----------------------------------------------------------------------------------------
# Display actions (no Ts)
#-----------------------------------------------------------------------------------------

shift = 0.3

rewards = ['0', '0', '1', '-1']

colors  = [None, None, Figure.colors('darkblue'), None]