In [39]:
%run nb_init.py
import IPython.core.display as disp
import hdfgraph
import re
from skimage.io import imread
In [11]:
def load_img_list(directory, suffix='.png'):
    '''Loads a list of images from `directory`.

    Parameter
    ---------
    diretory: str, a path to an existing directory

    Returns
    -------
    img_list: list of strings: the file paths to the images,
        with the file names appended to the included directory,
        and exically sorted
    '''
    img_list = os.listdir(directory)
    img_list = [os.path.join(directory, imname)
                for imname in img_list if imname.endswith(suffix)]
    img_list.sort(key=_alphanum_key)
    print('First file: {}\n'
          'Last file: {}'.format(img_list[0], img_list[-1]))
    return img_list


def _alphanum_key(s):
    """ Turn a string into a list of string and number chunks.
        "z23a" -> ["z", 23, "a"]
    """
    return [_tryint(c) for c in re.split('([0-9]+)', s) ]

def _tryint(s):
    try:
        return int(s)
    except ValueError:
        return s



    
    
In [61]:
legend_keys = {'vol_reduction': 'Volume reduction during apoptosis',
               'radial_tension': 'Tension increase (per step) during apoptosis',
               'contractility': 'Apical contractility increase during apoptosis',
               'num_cells':'Number of apoptotic cells',
               'random': 'Random with ventral bias or regular apoptotic pattern\n (True if random)',
               'rate_ci': 'Contractility increase rate after apoptosis',
               'span_ci': 'Span  neighbour cell seeing contractility increase',
               'max_ci': 'Maximum increase in contractility'}

def legend_string(kwargs):
    legend = [r'Conditions:']
    for sub_dic in kwargs.values():
        for key, val in sub_dic.items():
            try:
                legend.append(legend_keys[key]+':'+' {}'.format(val))
            except KeyError:
                continue
    return '\n'.join(legend)
In [66]:
dir_list = os.listdir('../saved_graphs/')
dir_list = [d for d in dir_list if ('03-24' in d)]
dir_list.sort()
png_dir_list = [os.path.join('../saved_graphs/', d, 'png') for d in dir_list]
svg_list = [os.path.join('../saved_graphs/', d, 'svg', 'avg_rho_%s.svg' % d) for d in dir_list]
json_list = [os.path.join('../saved_graphs/', d, 'params_%s.json' %d) for d in dir_list]
h5_list = [os.path.join('../saved_graphs/', d, 'eptm_%s.h5' %d) for d in dir_list]

profiles_list = []

for svg_name in svg_list:
    png_name = '.'.join(svg_name.split('.')[:-1])+'.png'
    profiles_list.append(png_name)
    command = ['convert', '-size 400x600', svg_name, png_name]
    call(command)

'''
for i, json_fname in enumerate(json_list):
    with open(json_fname) as json_file:
        kwargs = json.load(json_file)
    print('index: {} => \n'.format(i)) 
    for key, val in kwargs['post_kwargs'].items():
        print('\t {}: {}'.format(key, val))
    print('\t radial_tension : {}'.format(
          kwargs['apopto_kwargs']['radial_tension']))
    print('\n')
''';
In [71]:
def draw_report(index, axes):
    
    with open(json_list[index]) as json_file:
        kwargs = json.load(json_file)
        legend = legend_string(kwargs)


    lgd_ax, profile_ax = axes[0, :]
    lgd_ax.text(0, 0.5, legend)
    lgd_ax.set_xticks([])
    lgd_ax.set_yticks([])
    lgd_ax.axis('off')

    profile_ax.imshow(imread(profile_list[index]))
    profile_ax.set_xticks([])
    profile_ax.set_yticks([])
    profile_ax.axis('off')


    ax0, ax1 = axes[1, :]
    png_list = load_img_list(png_dir_list[index])
    latest_3d = png_list[-1]
    latest_2d = png_list[len(png_list)//2 - 1]
    ax0.imshow(imread(latest_3d))
    ax0.set_title('3D View')
    ax0.set_xticks([])
    ax0.set_yticks([])
    vspace = 30
    hspace = 50
    ax0.set_xlabel('Proximal'+' '*hspace+'Distal')
    ax0.set_ylabel('Dorsal'+' '*vspace+'Ventral')


    ax1.imshow(imread(latest_2d))
    ax1.set_title('2D View')
    ax1.set_xticks([])
    ax1.set_yticks([])
    ax1.set_xlabel('Proximal'+' '*hspace+'Distal')
    vspace //=2
    ax1.set_ylabel('Dorsal'+' '*vspace+'Ventral'+' '*vspace+'Dorsal')
    return axes
In [77]:
for index in range(len(dir_list)):
    print('treating index %i' % index)
    fig, axes = plt.subplots(2, 2, figsize=(15, 10))
    axes = draw_report(index, axes)
    
    plt.savefig('../doc/imgs/report_sims_03-24_%02i.pdf' % index)
    plt.clf()
treating index 0
First file: ../saved_graphs/0000_2014-03-24T16_00_14/png/eptm2d_0001.png
Last file: ../saved_graphs/0000_2014-03-24T16_00_14/png/eptm3d_51523.png
treating index 1
First file: ../saved_graphs/0001_2014-03-24T16_00_14/png/eptm2d_0001.png
Last file: ../saved_graphs/0001_2014-03-24T16_00_14/png/eptm3d_51523.png
treating index 2
First file: ../saved_graphs/0002_2014-03-24T16_00_14/png/eptm2d_0001.png
Last file: ../saved_graphs/0002_2014-03-24T16_00_14/png/eptm3d_51523.png
treating index 3
First file: ../saved_graphs/0003_2014-03-24T16_00_14/png/eptm2d_0001.png
Last file: ../saved_graphs/0003_2014-03-24T16_00_14/png/eptm3d_51528.png
treating index 4
First file: ../saved_graphs/0004_2014-03-24T16_00_14/png/eptm2d_0001.png
Last file: ../saved_graphs/0004_2014-03-24T16_00_14/png/eptm3d_51523.png
treating index 5
First file: ../saved_graphs/0005_2014-03-24T16_00_14/png/eptm2d_0001.png
Last file: ../saved_graphs/0005_2014-03-24T16_00_14/png/eptm3d_51524.png
treating index 6
First file: ../saved_graphs/0006_2014-03-24T16_00_14/png/eptm2d_0001.png
Last file: ../saved_graphs/0006_2014-03-24T16_00_14/png/eptm3d_51524.png
treating index 7
First file: ../saved_graphs/0007_2014-03-24T16_00_14/png/eptm2d_0001.png
Last file: ../saved_graphs/0007_2014-03-24T16_00_14/png/eptm3d_51526.png
treating index 8
First file: ../saved_graphs/0008_2014-03-24T16_00_14/png/eptm2d_0001.png
Last file: ../saved_graphs/0008_2014-03-24T16_00_14/png/eptm3d_51524.png
treating index 9
First file: ../saved_graphs/0009_2014-03-24T16_00_14/png/eptm2d_0001.png
Last file: ../saved_graphs/0009_2014-03-24T16_00_14/png/eptm3d_51524.png
treating index 10
First file: ../saved_graphs/0010_2014-03-24T16_00_14/png/eptm2d_0001.png
Last file: ../saved_graphs/0010_2014-03-24T16_00_14/png/eptm3d_51523.png
treating index 11
First file: ../saved_graphs/0011_2014-03-24T16_00_14/png/eptm2d_0001.png
Last file: ../saved_graphs/0011_2014-03-24T16_00_14/png/eptm3d_51526.png

With radial tension, max. contractility = 3, contractility induction span = 3 cells

In [144]:
latest_3d = os.path.join(png_dir_list[index], 'eptm3d_41687.png')
latest_2d = os.path.join(png_dir_list[index], 'eptm2d_41687.png')
In [29]:
from subprocess import call
In [38]:
 

With radial tension, max. contractility = 3, contractility induction span = 2 cells

In [105]:
index = 6
In [106]:
png_list = os.listdir(png_dir_list[index])
png_list.sort()
latest_3d = os.path.join(png_dir_list[index], png_list[-1])
latest_2d = os.path.join(png_dir_list[index], png_list[len(png_list)//2-1])
with open(json_list[index]) as json_file:
    kwargs = json.load(json_file)
    for key, sub_kwarg in kwargs.items():
        print(key)
        for sub_key, val in sub_kwarg.items():
            print('\t %s : %.2f' % (sub_key, val))
        print('\n')

disp.Image(latest_3d)
seq_kwargs
	 ventral_bias : 1.00
	 num_cells : 30.00
	 width_apopto : 2.00
	 p0 : 1.00
	 seed : 1.00
	 num_steps : 10.00
	 gamma : 1.00
	 amp : 0.30
	 random : 1.00


apopto_kwargs
	 radial_tension : 0.20
	 contractility : 1.00
	 vol_reduction : 0.50


post_kwargs
	 span_ci : 2.00
	 max_ci : 3.00
	 rate_ci : 1.40


Out[106]:
In [107]:
disp.Image(latest_2d)
Out[107]:
In [108]:
disp.SVG(svg_list[index])
Out[108]:

With radial tension, without contractility

In [109]:
index = 5
In [110]:
png_list = os.listdir(png_dir_list[index])
png_list.sort()
latest_3d = os.path.join(png_dir_list[index], png_list[-1])
latest_2d = os.path.join(png_dir_list[index], png_list[len(png_list)//2-1])
with open(json_list[index]) as json_file:
    kwargs = json.load(json_file)
    for key, sub_kwarg in kwargs.items():
        print(key)
        for sub_key, val in sub_kwarg.items():
            print('\t %s : %.2f' % (sub_key, val))
        print('\n')

disp.Image(latest_3d)
seq_kwargs
	 ventral_bias : 1.00
	 num_cells : 30.00
	 width_apopto : 2.00
	 p0 : 1.00
	 seed : 1.00
	 num_steps : 10.00
	 gamma : 1.00
	 amp : 0.30
	 random : 1.00


apopto_kwargs
	 radial_tension : 0.20
	 contractility : 1.00
	 vol_reduction : 0.50


post_kwargs
	 span_ci : 3.00
	 max_ci : 3.00
	 rate_ci : 1.00


Out[110]: