Simulate FOV drift in a single colony

Finally, we can also visualize how FOV drift can affect solutions in a single colony image

[1]:
import os
import pylab
import matplotlib.pyplot as plt
import seaborn as sns
import numpy as np
from DLITE.SurfaceEvolver import SurfaceEvolver
from DLITE.PlottingFunctions import PlottingFunctions

Let’s use a single time-point of a the synthetic data time-series in Fig 2

[2]:
os.chdir(r'../Notebooks/data/Synthetic_data/Fig_2')
number = 5
name_first = 'surface_dec_edge_groups_80_150_numbers_'
name_end = '.fe.txt'

First, we instantiate the class

[3]:
SurfaceEvolverInstance = SurfaceEvolver(name_first, name_end)

Now, we call the FOV drift method of the SurfaceEvolver class

We do this for both solvers so that we can compare results

[4]:
colonies = SurfaceEvolverInstance.FOV_Drift(number, solver = 'CellFIT')
Number of fit edges: 122
Number of cells 25 25
Solver is CellFIT
First colony {'0': <DLITE.cell_describe.colony object at 0x122769f60>}
Next colony number 1
Next colony number 2
Next colony number 3
Next colony number 4
Next colony number 5
Next colony number 6
Next colony number 7
Next colony number 8
[5]:
colonies2 = SurfaceEvolverInstance.FOV_Drift(number, solver = 'DLITE')
Number of fit edges: 122
Number of cells 25 25
guess tension is [0.06, 0.69, 0.64, 0.72, 0.34, 0.42, 0.84, 0.65, 0.04, 0.37, 0.6, 0.96, 0.08, 0.9, 0.84, 0.4, 0.45, 0.84, 0.23, 0.76, 0.62, 0.42, 0.49, 0.29, 0.69, 0.25, 0.98, 0.24, 0.64, 0.53, 0.85, 0.0, 0.03, 0.49, 0.15, 0.99, 0.47]
Function value 0.34998262077341724
Solution [0.83385487 0.80320334 0.80636861 0.82559555 0.53866841 0.60855716
 0.53419777 1.03381848 0.52527066 0.64210733 0.51207691 0.62698961
 0.59742749 0.76159962 0.61913783 0.77291789 0.79993934 0.81216099
 0.78652269 0.75461855 0.74362185 0.6340102  0.57507614 0.5875849
 0.58440136 0.32428979 0.40498624 0.46491279 0.47079836 0.396249
 0.05374398 0.43580012 0.46564129 0.22948324 0.19824762 0.21959093
 0.47      ]


-----------------------------
guess pressure is [0.0029803842144703135, 0.0029803842144703135, 0.0029803842144703135, 0.0029803842144703135, 0.0029803842144703135]
Function value 1.6799070578442595e-05
Solution [0.00178126 0.00265289 0.00556598 0.00192237 0.0029793 ]


-----------------------------
Solver is DLITE
First colony {'0': <DLITE.cell_describe.colony object at 0x126822f60>}
guess tension is [0.11, 0.36, 0.1, 0.92, 0.32, 0.44, 0.04, 0.55, 0.82, 0.13, 0.87, 0.41, 0.34, 0.78, 0.13, 0.5, 0.92, 0.39, 0.17, 0.41, 1.01, 0.63, 0.64, 0.05, 0.37, 0.18, 0.72, 0.31, 0.47, 0.51, 0.09, 0.75, 0.38, 0.25, 0.33, 0.78, 0.08, 0.01, 0.43, 0.16, 0.99, 0.77, 0.46, 0.84, 0.25, 1.01, 0.53, 0.87, 0.54, 0.09, 0.2, 0.76, 1.0, 0.63, 0.48, 0.08, 0.37]
Function value 1.79173330062279
Solution [0.78549929 0.75662752 0.75961829 0.5783843  0.49415713 0.97460709
 0.48531235 0.53081894 0.6328051  0.50457654 0.50701493 0.61895982
 0.60380056 0.55647684 0.75303675 0.57205289 0.71413555 0.73911006
 0.78945541 0.72672837 0.61845419 0.63006785 0.74630915 0.73566181
 0.56428619 0.57097991 0.59506728 0.38008028 0.39627618 0.39760416
 0.567659   0.61472271 0.71288836 0.40656447 0.06617958 0.36454676
 0.7150433  0.26896696 0.23235649 0.22748481 0.2047552  0.36928329
 0.33351362 0.16156704 0.44445307 1.01       0.67833244 0.60198372
 0.59885709 0.1698708  0.36900626 0.7335496  0.61401634 0.77120249
 0.44779879 0.55557461 0.57818188]


-----------------------------
guess pressure is [0.0026528878782804736, 0.005565981129018292, 0.005565981129018292, 0.0019223702612491793, 0.004272641986592783, 0.0029793028441672744, 0.0019223702612491793, 0.002450836552708227, 0.0029793028441672744]
Function value 1.6019765750765833e-06
Solution [0.00352214 0.00556598 0.00490291 0.00196981 0.00427264 0.00272562
 0.00192237 0.00245084 0.0029793 ]


-----------------------------
Next colony number 1
guess tension is [0.06, 0.84, 0.2, 0.31, 0.21, 0.89, 0.59, 0.36, 0.79, 0.64, 0.16, 0.8, 0.69, 0.28, 0.98, 0.83, 0.29, 0.75, 0.19, 0.06, 0.36, 0.39, 0.26, 0.58, 0.99, 0.4, 0.88, 0.21, 0.9, 0.96, 0.45, 0.12, 0.15, 0.68, 0.68, 1.01, 0.6, 0.67, 0.61, 0.18, 0.88, 0.44, 0.51, 0.46, 0.91, 1.01, 0.93, 0.59, 0.09, 0.62, 0.32, 0.82, 0.08, 0.15, 0.5, 0.57, 0.87]
Function value 2.180763993439494
Solution [0.54931918 0.67119758 0.61849708 0.57596578 0.84870878 0.55747546
 0.65717505 0.82031154 0.84934187 0.889635   0.83457475 0.69345295
 0.69285771 0.7063204  0.72155486 0.92086839 0.8410424  0.82888615
 0.6412468  0.6325281  0.64368167 0.42263602 0.65975416 0.87904898
 0.51915586 0.35157879 0.65333563 0.70394104 0.20688143 0.72125332
 0.48697804 0.05844246 0.32153935 0.73885335 0.29932287 0.25878497
 0.29627137 0.19079519 0.21105015 0.26306359 0.480636   0.4322413
 0.58001787 0.67643235 0.63799619 0.47488998 0.77032798 0.58236393
 0.77667459 0.64749138 0.81728968 0.47461763 0.58833755 0.60210277
 0.61948484 0.5094335  0.71274561]


-----------------------------
guess pressure is [0.004902909879542242, 0.00196981367430257, 0.004272641986592783, 0.004272641986592783, 0.002725619734345398, 0.003625972415380029, 0.0019223702612491793, 0.002450836552708227, 0.0029793028441672744, 0.002715069698437751]
Function value 1.1112016742497311e-06
Solution [0.00492055 0.00201338 0.00427264 0.00427264 0.00266441 0.00362597
 0.00192237 0.00245084 0.0029793  0.00271507]


-----------------------------
Next colony number 2
guess tension is [0.48, 0.0, 0.3, 0.04, 0.55, 0.34, 0.87, 0.63, 0.05, 0.01, 0.05, 0.02, 0.66, 0.37, 0.22, 0.56, 0.91, 0.44, 0.5, 0.31, 0.35, 0.74, 0.58, 0.71, 0.29, 0.98, 0.23, 1.01, 0.54, 0.72, 0.79, 0.63, 0.39, 0.02, 0.3, 0.64, 0.14, 0.99, 0.59, 0.43, 0.18, 0.23, 0.63, 0.31, 0.38, 0.45, 0.77, 0.02, 0.84, 0.39, 0.12, 0.31, 0.42, 0.08, 0.65, 0.42, 0.99]
Function value 1.1387637933711499
Solution [0.64483434 0.86309641 0.87626366 0.83393924 0.84862016 0.62305665
 0.63357814 0.81446487 0.42374173 0.5379995  0.38559878 0.51375407
 0.45605247 0.46053591 0.50009767 0.09990386 0.52474311 0.41464576
 0.05131911 0.51813939 0.29986216 0.2590424  0.16280451 0.53921858
 0.09211741 0.50594066 0.10197237 0.53777037 0.54662569 0.14674592
 0.26428836 0.23868723 0.31853112 0.26382633 0.42218841 0.34437765
 0.3186744  0.4919091  0.41019327 0.40419114 0.51780752 0.30068499
 0.37386926 0.32468235 0.36442065 0.32945677 0.33414594 0.27466998
 0.3873772  0.81168885 0.77328182 0.61131784 0.95362862 0.9716717
 0.97874998 0.92916562 0.91502234]


-----------------------------
guess pressure is [0.002664409141823034, 0.003625972415380029, 0.002450836552708227, 0.0029793028441672744, 0.002715069698437751, 0.002715069698437751, 0.002715069698437751, 0.002450836552708227]
Function value 0
Solution [0.00266441 0.00362597 0.00245084 0.0029793  0.00271507 0.00271507
 0.00271507 0.00245084]


-----------------------------
Next colony number 3
guess tension is [0.35, 0.38, 0.19, 0.71, 0.81, 0.37, 0.52, 0.43, 0.33, 0.19, 0.37, 0.91, 0.22, 0.48, 0.01, 0.36, 0.3, 0.77, 0.25, 0.58, 0.28, 0.92, 0.83, 0.6, 0.34, 0.44, 0.16, 0.33, 0.36, 0.67, 0.52, 0.04, 0.25, 0.69, 0.07, 0.8, 0.48, 0.11, 0.18, 0.11, 0.46, 0.05, 0.17, 0.14, 0.18, 0.66, 0.03, 0.68, 0.06, 0.13, 0.35, 0.21, 0.02, 0.04, 0.66, 0.64, 0.35]
Function value 1.1242320899086096
Solution [0.53353381 0.59873015 0.57173489 0.52174263 0.52779688 0.5726661
 0.72619116 0.58507732 0.49251659 0.05660742 0.57794639 0.66937076
 0.47307794 0.40887795 0.13207511 0.08991496 0.5407497  0.09761248
 0.09937051 0.35990944 0.51171353 0.50679741 0.44220647 0.11929231
 0.21531271 0.19408467 0.26465328 0.21446743 0.35302061 0.24605517
 0.26023835 0.54900123 0.45790223 0.26645643 0.2594581  0.23443873
 0.27233442 0.22342374 0.31343876 0.65262224 0.60361065 0.32731535
 0.47577801 0.64998647 0.66204738 0.29439854 0.49946287 0.66689965
 0.614971   0.62419093 0.65957239 0.70392453 0.71533488 0.73465219
 0.72114514 0.67310551 0.66273507]


-----------------------------
guess pressure is [0.002450836552708227, 0.0029793028441672744, 0.002715069698437751, 0.002715069698437751, 0.002715069698437751, 0.002450836552708227]
Function value 0
Solution [0.00245084 0.0029793  0.00271507 0.00271507 0.00271507 0.00245084]


-----------------------------
Next colony number 4
guess tension is [0.23, 0.98, 0.22, 0.21, 0.99, 0.17, 1.01, 0.41, 0.02, 0.54, 0.22, 0.26, 0.43, 0.98, 0.64, 0.33, 0.48, 0.63, 0.91, 0.43, 0.73, 0.16, 0.22, 0.15, 0.75, 0.09, 0.61, 0.6, 0.16, 0.76, 0.88, 0.65, 0.05, 0.47, 0.58, 0.56, 0.85, 0.24, 0.5, 0.91, 0.24, 0.01, 0.19, 0.83, 0.07, 0.08]
Function value 0.6754504462427882
Solution [0.41753854 0.36565033 0.39908156 0.56868386 0.10178005 0.53357923
 0.11069309 0.11298559 0.56807989 0.56272523 0.57705207 0.1611199
 0.28272937 0.14296282 0.15951856 0.25865367 0.23357052 0.31133699
 0.25798989 0.44483911 0.31695621 0.32508011 0.44410037 0.33226837
 0.33471491 0.30182989 0.341254   0.2812618  0.39486269 0.84449791
 0.80523637 0.83466462 0.85650832 0.37818267 0.6386288  0.86347309
 0.82086234 0.80691546 0.88108979 0.86692065 0.55344385 0.95885973
 0.96516649 0.8701023  0.85629097 0.83877884]


-----------------------------
guess pressure is [0.002715069698437751, 0.002715069698437751, 0.002715069698437751, 0.002450836552708227, 0.002715069698437751]
Function value 0
Solution [0.00271507 0.00271507 0.00271507 0.00245084 0.00271507]


-----------------------------
Next colony number 5
guess tension is [0.38, 0.59, 0.45, 0.73, 0.76, 0.44, 0.35, 0.31, 0.85, 0.23, 0.6, 1.0, 0.69, 0.0, 0.13, 0.31, 0.14, 0.67, 0.29, 0.34, 0.58, 0.38, 0.25, 0.59, 0.99, 0.22, 0.12, 0.76, 0.08, 0.07, 0.52, 0.42, 0.72, 0.1, 0.88, 0.8, 0.9]
Function value 0.5443025857245052
Solution [0.32799035 0.4662541  0.46169113 0.43866046 0.4739378  0.14579632
 0.23668231 0.21375315 0.10356842 0.28486775 0.13122168 0.23651348
 0.37701979 0.28591209 0.28214291 0.39259286 0.28742636 0.30187096
 0.27220287 0.29579917 0.24315121 0.34277112 0.82056874 0.84990233
 0.37194664 0.6302721  0.86508816 0.82122628 0.8067958  0.80554864
 0.88150038 0.87964896 0.55158331 0.86972221 0.85584031 0.8
 0.8377358 ]


-----------------------------
guess pressure is [0.002715069698437751, 0.002715069698437751, 0.002715069698437751]
Function value 0
Solution [0.00271507 0.00271507 0.00271507]


-----------------------------
Next colony number 6
guess tension is [0.49, 0.2, 0.72, 0.74, 0.5, 0.54, 0.32, 0.5, 0.75, 0.72, 0.21, 0.6, 0.44, 0.99, 0.94, 0.01, 0.55, 0.52, 0.72, 0.41, 0.96, 0.16]
Function value 0.25580095250774376
Solution [0.49       0.47037104 0.39173838 0.26009346 0.2955522  0.29568409
 0.27460606 0.24761073 0.3100353  0.35942828 0.78726429 0.85642907
 0.35680361 0.6047921  0.90811931 0.86212475 0.88258827 0.89049511
 0.60313721 0.95143376 0.9362536  0.91634581]


-----------------------------
guess pressure is [0.002715069698437751, 0.002715069698437751]
Function value 0
Solution [0.00271507 0.00271507]


-----------------------------
Next colony number 7
guess tension is [0.48, 0.12, 0.01, 0.49, 0.25, 0.09, 0.85, 0.78, 0.48, 0.28, 0.13, 0.67, 0.11, 0.43]
Function value 0.11985071497598285
Solution [0.24337511 0.23051304 0.21944993 0.61146223 0.62100321 0.27712197
 0.46974594 0.62552818 0.58480131 0.65038724 0.4011975  0.63129312
 0.62186959 0.60889147]


-----------------------------
guess pressure is [0.002715069698437751]
Function value 0
Solution [0.00271507]


-----------------------------
Next colony number 8

Now that we have the colonies, we can visualize the colony tensions

[6]:
%matplotlib inline
sns.set(style="white")
sns.set_context("paper", font_scale = 2.5)

total = 5
fig, axn = plt.subplots(1, total, figsize = (20,20),sharey=True)
nums= [0,2, 4,6, 8]

for i, ax in enumerate(axn.flat):
    col = colonies[str(nums[i])]
    tensions = [e.ground_truth for e in col.tot_edges]
    mean_ten = np.mean(tensions)
    tensions = [e/mean_ten for e in tensions]

    col.plot_tensions(ax, fig, tensions, min_x=450, max_x=550, min_y=430, max_y=550,
                      min_ten = 0, max_ten = 3, specify_color = 'jet',cbar = 'no', lw = 3)
    plt.setp(ax.get_yticklabels(), visible=False)
    plt.setp(ax.get_xticklabels(), visible=False)
#     ax.set(xlim = [400,580], ylim = [400,580], aspect = 1)
    ax.set(xlim = [200,800], ylim = [200,800], aspect = 1)

../_images/synthetic_data_Simulate_FOV_Drift_12_0.png

We can also plot heatmaps using the same functions described before

[7]:
PlottingFunctionsInstance = PlottingFunctions()
[8]:
# We first find labels of edges that are present in all the colonies
common_edge_labels = PlottingFunctionsInstance.get_repeat_edge(colonies)
common_cell_labels = PlottingFunctionsInstance.get_repeat_cell(colonies)

common_edge_labels2 = PlottingFunctionsInstance.get_repeat_edge(colonies2)
common_cell_labels2 = PlottingFunctionsInstance.get_repeat_cell(colonies2)
[9]:
# Make the dataframes
edges_dataframe, cells_dataframe = PlottingFunctionsInstance.seaborn_plot(None, colonies,
                                                                                  common_edge_labels,
                                                                                  common_cell_labels,
                                                                                  ground_truth = True)

# Make the dataframes
edges_dataframe2, cells_dataframe2 = PlottingFunctionsInstance.seaborn_plot(None, colonies2,
                                                                                  common_edge_labels2,
                                                                                  common_cell_labels2,
                                                                                  ground_truth = True)
/Users/ritvikvasan/Documents/repos/DLITE/DLITE/PlottingFunctions.py:1352: RuntimeWarning: invalid value encountered in true_divide
  cell_data['Pressures'].append([2*((c.pressure - min_pres) / float(max_pres - min_pres)) - 1 for c in v.cells if c.label == cell_lab][0])
/Users/ritvikvasan/Documents/repos/DLITE/DLITE/PlottingFunctions.py:1360: RuntimeWarning: invalid value encountered in true_divide
  - min_pres) / float(max_pres - min_pres))
/Users/ritvikvasan/Documents/repos/DLITE/DLITE/PlottingFunctions.py:1352: RuntimeWarning: invalid value encountered in double_scalars
  cell_data['Pressures'].append([2*((c.pressure - min_pres) / float(max_pres - min_pres)) - 1 for c in v.cells if c.label == cell_lab][0])
/Users/ritvikvasan/Documents/repos/DLITE/DLITE/PlottingFunctions.py:1355: RuntimeWarning: invalid value encountered in double_scalars
  if c.label == cell_lab][0])
/Users/ritvikvasan/Documents/repos/DLITE/DLITE/PlottingFunctions.py:1360: RuntimeWarning: invalid value encountered in double_scalars
  - min_pres) / float(max_pres - min_pres))
[10]:
tension_table = edges_dataframe.pivot_table(
        values='Local_normalized_tensions',
        index=['Edge_Labels'],
        columns='Time')

ground_truth_tension_table = edges_dataframe.pivot_table(
        values='Ground_truth',
        index=['Edge_Labels'],
        columns='Time')

tension_table2 = edges_dataframe2.pivot_table(
        values='Local_normalized_tensions',
        index=['Edge_Labels'],
        columns='Time')
[11]:
import seaborn as sns

sns.set_context('poster')
fig, axn = plt.subplots(1, 3, figsize = (8,4),sharey=True)
cbar_ax = fig.add_axes([1.1, .15, .01, .7], title = 'Tension')

for i, ax in enumerate(axn.flat):
    if i == 0:
        df = ground_truth_tension_table
        title = 'Ground_truth'
    elif i == 1:
        df = tension_table
        title = 'CellFIT'
    elif i == 2:
        df = tension_table2
        title = 'DLITE'
    ax.set_title(title)
    sns.heatmap(df, ax=ax,
                cbar=i == 0, vmin=0, vmax=3, cmap = 'jet',
                cbar_ax=None if i else cbar_ax)
../_images/synthetic_data_Simulate_FOV_Drift_18_0.png