# Path: helpers/loader.py
# class Loader(object):
#     def __init__(self):
#         
#         self.dirRoot = None 
#         
#     
#     
#     def create_new_dir(self, prefix="./", root="Data"):
#         """
#             Create the directory where to put the simulation
#         """
#         self.dirRoot = os.path.join(prefix, root)
#         
#         today = datetime.date.today()
#         free = False
#         index = 0
#         
#         dirDate = today.strftime("%d-%m-%Y")
#         
#         dirComp = os.path.join(self.dirRoot, dirDate)
#         dir = os.path.join(dirComp, "Sim_" + str(index))
#         while not free :
#             if os.path.exists(dir):
#                 index = index + 1
#                 simNum = "Sim_" + str(index)
#                 dir = os.path.join(dirComp, simNum )
#             else:
#                 free = True
#                 os.makedirs(dir)
#         return dir
#     
#     def save(self, obj, dir, name):
#         """ Save The object in binary form with the given name
#         
#         params:
#         obj - The python object
#         name - the name to give to the saved object"""
#         
#         filepath = os.path.join (dir, name)
#         FILE = open(filepath, 'w')
#         cPickle.dump(obj, FILE, 1)
#         FILE.close()
#         print "Python object saved in %s" %os.path.abspath(filepath)
#     
#     def load(self, filename):
#         """Load the python object into memory from the filename
#         
#         params:
#         filename - path to the binary python object"""
#         try:
#             FILE = open(filename, 'r')
#             obj = cPickle.load(FILE)
#             FILE.close()
#             print "loaded file %s" %os.path.abspath(filename)
#             return obj
#         except IOError:
#             print "impossible to load the file: %s" %filename
#     
#     def convert_to_numpy(self, vecDict):
#         """Convert a dictionary of Hoc Vectors into one of Numpy Vecs"""
#         vecsNu = {}
#         for k,v in vecDict.iteritems():
#             vecsNu[k] = numpy.array(v)
#         return vecsNu


import sys
import os
import numpy as np
import matplotlib.pyplot as plt
    import ecellControl.ecellManager as eC
         import matplotlib.pyplot as plt
        import matplotlib.pyplot as plt
from helpers.loader import Loader
        ax1.set_ylabel('v [mV]')
        ax2.set_ylabel('# molecule')
        
        ax1.yaxis.label.set_color(l1.get_color())	
        ax2.yaxis.label.set_color(l2.get_color())
        tkw = dict(size=4, width=1.5)
    	ax1.tick_params(axis='y', colors=l1.get_color(), **tkw)
    	ax2.tick_params(axis='y', colors=l2.get_color(), **tkw)

        lines = [l1,l2]
        ax1.legend(lines, [l.get_label() for l in lines], loc='best')
        ax1.set_xlabel('Time [ms]')
        ax1.set_xlim(0, 20000)
        return (ax1, ax2)
    
    def plot_bio_and_ele_calcium(self, manager, spine, dir=None):
        """Plot Calcium from bio and ele with the same scale in 
        two graphs.
        Param:
            spine: Spine which Calcium should be plotted. 
            manager: classic Neuronvisio manager.
        Example:
            dp.plot_bio_and_ele_calcium(controls.manager, "spine1")"""
        timeSeries = "timeSeries_%s" %spine
        ecell_time_equilibrium = 300 #s
        t_bio = manager.groups[timeSeries]
        t_bio_ms = (t_bio.read() - ecell_time_equilibrium) * 1e3 #s_to_ms
        
        ca_conc = manager.get_vector(spine, 'ca_conc', group=timeSeries)
        label = "bio_ca_%s" %spine

# Path: helpers/loader.py
# class Loader(object):
#     def __init__(self):
#         
#         self.dirRoot = None 
#         
#     
#     
#     def create_new_dir(self, prefix="./", root="Data"):
#         """
#             Create the directory where to put the simulation
#         """
#         self.dirRoot = os.path.join(prefix, root)
#         
#         today = datetime.date.today()
#         free = False
#         index = 0
#         
#         dirDate = today.strftime("%d-%m-%Y")
#         
#         dirComp = os.path.join(self.dirRoot, dirDate)
#         dir = os.path.join(dirComp, "Sim_" + str(index))
#         while not free :
#             if os.path.exists(dir):
#                 index = index + 1
#                 simNum = "Sim_" + str(index)
#                 dir = os.path.join(dirComp, simNum )
#             else:
#                 free = True
#                 os.makedirs(dir)
#         return dir
#     
#     def save(self, obj, dir, name):
#         """ Save The object in binary form with the given name
#         
#         params:
#         obj - The python object
#         name - the name to give to the saved object"""
#         
#         filepath = os.path.join (dir, name)
#         FILE = open(filepath, 'w')
#         cPickle.dump(obj, FILE, 1)
#         FILE.close()
#         print "Python object saved in %s" %os.path.abspath(filepath)
#     
#     def load(self, filename):
#         """Load the python object into memory from the filename
#         
#         params:
#         filename - path to the binary python object"""
#         try:
#             FILE = open(filename, 'r')
#             obj = cPickle.load(FILE)
#             FILE.close()
#             print "loaded file %s" %os.path.abspath(filename)
#             return obj
#         except IOError:
#             print "impossible to load the file: %s" %filename
#     
#     def convert_to_numpy(self, vecDict):
#         """Convert a dictionary of Hoc Vectors into one of Numpy Vecs"""
#         vecsNu = {}
#         for k,v in vecDict.iteritems():
#             vecsNu[k] = numpy.array(v)
#         return vecsNu


# Path: helpers/plotter.py
import sys
import os
import numpy as np
import matplotlib.pyplot as plt
    import ecellControl.ecellManager as eC
         import matplotlib.pyplot as plt
        import matplotlib.pyplot as plt
from helpers.loader import Loader

        ax1.set_ylabel('v [mV]')
        ax2.set_ylabel('# molecule')
        
        ax1.yaxis.label.set_color(l1.get_color())	
        ax2.yaxis.label.set_color(l2.get_color())
        tkw = dict(size=4, width=1.5)
    	ax1.tick_params(axis='y', colors=l1.get_color(), **tkw)
    	ax2.tick_params(axis='y', colors=l2.get_color(), **tkw)

        lines = [l1,l2]
        ax1.legend(lines, [l.get_label() for l in lines], loc='best')
        ax1.set_xlabel('Time [ms]')
        ax1.set_xlim(0, 20000)
        return (ax1, ax2)
    
    def plot_bio_and_ele_calcium(self, manager, spine, dir=None):
        """Plot Calcium from bio and ele with the same scale in 
        two graphs.
        Param:
            spine: Spine which Calcium should be plotted. 
            manager: classic Neuronvisio manager.
        Example:
            dp.plot_bio_and_ele_calcium(controls.manager, "spine1")"""
        timeSeries = "timeSeries_%s" %spine
        ecell_time_equilibrium = 300 #s
        t_bio = manager.groups[timeSeries]
        t_bio_ms = (t_bio.read() - ecell_time_equilibrium) * 1e3 #s_to_ms
        
        ca_conc = manager.get_vector(spine, 'ca_conc', group=timeSeries)
        label = "bio_ca_%s" %spine

        plt.plot(t_bio_ms, ca_conc.read()*1e6, #M_to_uM 