# -*- coding: utf-8 -*-
"""
script: tutorial.py

This script is a recap of commands used in the 10 minute tutorial of tunacell
documentation.
"""
from __future__ import print_function
from builtins import input  # future package 
import argparse


def press_enter(*figs):
    """Convenient function to print figures and press Enter"""
    # when run from ipython, figure should automatically be plotted
    try:
        __IPYTHON__
    # otherwise call .plot() and wait for pressing Enter
    except NameError:
        for fig in figs:
            fig.show()
        ans = input('Press Enter to proceed...')
    return

# Arguments
argparser = argparse.ArgumentParser()
argparser.add_argument('-e', '--experiment', type=str,
                       help='Path to experiment root folder',
                       default='~/tmptunacell/simutest')

args = argparser.parse_args()



if __name__ == '__main__':
    # %% Loads data from text files (exported from numerical simulations)
    from tunacell import Experiment, Parser

    path_to_exp = args.experiment
    exp = Experiment(path_to_exp)  # this defines the Experiment object
    
    print(exp)
    print('**')
    
    # %% To collect small samples, we use the Parser object
    parser = Parser(path_to_exp)
    
    # Add a random sample
    parser.add_sample(1)
    print(parser)
    print('**')
    
    # %% get cell corresponding to sample index 0
    
    cell = parser.get_cell(0)
    print(cell)
    print('**')
    print(cell.data)
    print(cell.data.dtype.names)
    print('**')
    
    # %% get colony corresponding to sample index 0
    
    colony = parser.get_colony(0)
    print(colony)  # Python 3 compatibility --- treelib
    print('**')
    
    # %% define observable from raw data
    
    from tunacell import Observable
    obs = Observable(name='size', raw='exp_ou_int')
    print(obs)
    print(obs.as_string_table())
    print('**')
    
    # %% plotting timeseries of our colony
    
    from tunacell.plotting.samples import SamplePlot
    myplot = SamplePlot([colony, ], parser=parser)
    myplot.make_plot(obs)
    press_enter(myplot.fig)
    myplot.save(user_bname='tutorial_sample', add_obs=False, extension='.png')
    
    # %% Statistics of the dynamics
    
    # looking at ou observable
    ou = Observable(name='growth-rate', raw='ou')
    
    from tunacell.stats.api import compute_univariate
    univariate = compute_univariate(exp, ou)
    univariate.export_text()
    
    # %% Plotting the statistics
    
    from tunacell.plotting.dynamics import plot_onepoint, plot_twopoints
    fig = plot_onepoint(univariate, show_ci=True, save=True)
    fig2 = plot_twopoints(univariate, save=True)
    press_enter(fig, fig2)
@@ -243,380 +243,20 @@
 rse%0A
-%0A%0Adef press_enter(*figs):%0A    %22%22%22Convenient function to print figures and press Enter%22%22%22%0A    # when run from ipython, figure should automatically be plotted%0A    try:%0A        __IPYTHON__%0A    # otherwise call .plot() and wait for pressing Enter%0A    except NameError:%0A        for fig in figs:%0A            fig.show()%0A        ans = input('Press Enter to proceed...')%0A    return
+import time%0A
 %0A%0A# 
@@ -510,17 +510,16 @@
 rgs()%0A%0A%0A
-%0A
 if __nam
@@ -917,46 +917,191 @@
 d a 
-random sample%0A    parser.add_sample(1)
+known sample%0A    parser.add_sample(('container_079', 4))  # this one works out on default settings%0A    parser.add_sample(1)  # adds 1 random sample default settings have not been used
 %0A   
@@ -1881,36 +1881,8 @@
 bs)%0A
-    press_enter(myplot.fig)%0A
     
@@ -1956,16 +1956,105 @@
 '.png')%0A
+    print('Plotting timeseries')%0A    myplot.fig.show()%0A    time.sleep(2)%0A    print('**')%0A
     %0A   
@@ -2478,24 +2478,139 @@
  save=True)%0A
+    print('Plotting one-point functions')%0A    fig.show()%0A    print('**')%0A    print('Plotting two-point functions')%0A
     fig2 = p
@@ -2654,26 +2654,81 @@
     
-p
+fig2.show()%0A    print('**')%0A    ans = input('P
 ress
-_e
+ E
 nter
-(fig, fig2
+ to close all files'
 )

Update tutorial to display known sample (default)