Commit e57ec390 authored by amichaut's avatar amichaut
Browse files

added minimal doc

parent 7d1fd772
......@@ -7,6 +7,18 @@
"scrolled": false
},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/opt/miniconda3/lib/python3.8/site-packages/napari/__init__.py:44: UserWarning: \n",
" napari was tested with QT library `>=5.12.3`.\n",
" The version installed is 5.9.7. Please report any issues with this\n",
" specific QT version at https://github.com/Napari/napari/issues.\n",
" \n",
" warn(message=warn_message)\n"
]
},
{
"name": "stdout",
"output_type": "stream",
......@@ -30,26 +42,6 @@
" || ||\n",
" /\\ /\\ \n",
"\n",
"\n",
"\n",
"\n",
" WELCOME TO TRACK ANALYZER \n",
" Developed and maintained by Arthur Michaut: arthur.michaut@gmail.com \n",
" Last release: 11-25-2020\n",
"\n",
"\n",
" _''_\n",
" / o \\\n",
" < |\n",
" \\ /__\n",
" / \\-----\n",
" / \\ \\ \\__\n",
" | \\_____\\ __>\n",
" \\-- ___/ \n",
" \\ /\n",
" || ||\n",
" /\\ /\\\n",
"\n",
"\n"
]
},
......@@ -161,7 +153,7 @@
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "f4203fe260e1428dad7fdfd18d79c3f1",
"model_id": "682e06eed1054a12a2ceb5650eba80a3",
"version_major": 2,
"version_minor": 0
},
......@@ -175,7 +167,7 @@
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "cc1a13d9637e49e69efffa1afaf3aced",
"model_id": "6a91b85351b94f86bb5cd8469e8d3fcc",
"version_major": 2,
"version_minor": 0
},
......@@ -189,7 +181,7 @@
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "afefb4f4bea449758a090903ed34ad9f",
"model_id": "c1422787503d4bb587487234ca0ebd79",
"version_major": 2,
"version_minor": 0
},
......@@ -238,12 +230,12 @@
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "e87fd61ee882436ab15f09d81b412cd3",
"model_id": "f69eafb43fe24e49acb5542fd1ec5c15",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"FileChooser(path='/Users/amichaut/Documents/Work/codes/track-analyzer/p1', filename='', title='HTML(value='<b>…"
"FileChooser(path='/Users/amichaut/Desktop/carolina/tracking/e11-5', filename='', title='HTML(value='<b>Image f…"
]
},
"metadata": {},
......@@ -280,7 +272,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
"You have loaded a 3D image: (129x998) pixels with 141 time steps\n"
"You have loaded a 3D image: (991x989) pixels with 81 time steps\n"
]
},
{
......@@ -310,7 +302,7 @@
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "5074e1e605254481aa4de13d07b028a3",
"model_id": "1f4b85d392c94ae085294e4b44cbacd1",
"version_major": 2,
"version_minor": 0
},
......@@ -336,7 +328,7 @@
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "ede2a8c433d44c4fb5a64a30d42dfd6e",
"model_id": "a743b75fd50243dc94f3cd9fe46aa520",
"version_major": 2,
"version_minor": 0
},
......@@ -586,7 +578,7 @@
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "16e3c4149ae14d04a682c1240200c6b6",
"model_id": "c690240522734c45923999fbf79eb98e",
"version_major": 2,
"version_minor": 0
},
......@@ -600,7 +592,7 @@
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "974ce4f15f7e4288b55590201808aa1c",
"model_id": "3070a061f7044b979be8aaa42318f67e",
"version_major": 2,
"version_minor": 0
},
......@@ -614,7 +606,7 @@
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "d4a070fc21094b20b7507f06397df553",
"model_id": "811ac8e6bdc2469993c17d566d6ec2ab",
"version_major": 2,
"version_minor": 0
},
......@@ -628,7 +620,7 @@
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "982771840c6d4d7f9b77da6959af2f69",
"model_id": "3e2f2fc374b54afbbb9471599f497d96",
"version_major": 2,
"version_minor": 0
},
......@@ -654,7 +646,7 @@
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "db611e8b5d4c4bdb92762e0bccb25c75",
"model_id": "fbe433c49238438daed1dbead7fc51c9",
"version_major": 2,
"version_minor": 0
},
......@@ -680,7 +672,7 @@
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "29ae438f3a984a6b991349a0ebc61d59",
"model_id": "434d00f69789471eb26ffbcef38f039e",
"version_major": 2,
"version_minor": 0
},
......@@ -706,7 +698,7 @@
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "f46aea876b514224b2600e1b2b204345",
"model_id": "e0971cef691d4372ae99b2ff32200252",
"version_major": 2,
"version_minor": 0
},
......@@ -808,7 +800,7 @@
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "fed5e59b7e8543d1bfd4091caf432990",
"model_id": "09e071cb81ab4ebdbd6744db93aec306",
"version_major": 2,
"version_minor": 0
},
......@@ -860,7 +852,7 @@
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "ea2377c040e24d788093ca3df39093b1",
"model_id": "1847fcae9bc24f48bed2356671df8509",
"version_major": 2,
"version_minor": 0
},
......@@ -886,12 +878,12 @@
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "7a8e4f0de3334371b0b9e8153fc717c2",
"model_id": "a546454969234d49bb34631fd8668d6c",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"HBox(children=(FloatRangeSlider(value=(34.686, 188.41299999999998), description='x range (px):', max=188.41299…"
"HBox(children=(FloatRangeSlider(value=(59.0, 891.0), description='x range (px):', max=891.0, min=59.0, step=1.…"
]
},
"metadata": {},
......@@ -912,12 +904,12 @@
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "140d8c8646e3494380530125d565218f",
"model_id": "cf745fe2dfad4fb087e5e6f5789c9166",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"HBox(children=(IntRangeSlider(value=(0, 19), description='Frame subset:', max=19, style=SliderStyle(descriptio…"
"HBox(children=(IntRangeSlider(value=(0, 80), description='Frame subset:', max=80, style=SliderStyle(descriptio…"
]
},
"metadata": {},
......@@ -941,7 +933,7 @@
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "a20daffcec3849ddb746e1e99c605a6a",
"model_id": "b48a8391605c430bbfef38ee930dadf8",
"version_major": 2,
"version_minor": 0
},
......@@ -1079,7 +1071,7 @@
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "4008a397d68f49a5ab0b7530f7677e83",
"model_id": "a2bb110414244abbb84360d3a5169767",
"version_major": 2,
"version_minor": 0
},
......@@ -1108,7 +1100,7 @@
},
{
"cell_type": "code",
"execution_count": 19,
"execution_count": 18,
"metadata": {
"scrolled": false
},
......@@ -1140,7 +1132,7 @@
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "b7f21da365e54c60a3c36efd0d7be35f",
"model_id": "b02e80270a1f437e8032553a62ec91e8",
"version_major": 2,
"version_minor": 0
},
......@@ -1166,7 +1158,7 @@
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "09535c9856204ec987ff4e2462599ec7",
"model_id": "0286eff7f83c404293050322a97b758a",
"version_major": 2,
"version_minor": 0
},
......@@ -1216,7 +1208,7 @@
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "95153af43e1f4068a5305f04efc8bc86",
"model_id": "40b39b6a7e3c4ccf9deaca25dca55a29",
"version_major": 2,
"version_minor": 0
},
......@@ -1242,7 +1234,7 @@
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "ebf2e4b746214ac19022a884c1358332",
"model_id": "a8d38cc221b34e3c8e9f133734cc467d",
"version_major": 2,
"version_minor": 0
},
......@@ -1268,7 +1260,7 @@
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "1b51aa621bd3498a8f4a4a1590af94f9",
"model_id": "447031b156ef4aea81d911c674f17dac",
"version_major": 2,
"version_minor": 0
},
......@@ -1294,7 +1286,7 @@
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "8b4d4ed49cbe43949462b5887529ab8b",
"model_id": "1c133aba1b4e4631a4606f32358eb3a8",
"version_major": 2,
"version_minor": 0
},
......@@ -1344,7 +1336,7 @@
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "b78a5647af53494885e83664033b3f93",
"model_id": "96f4b1cac3334125824a21408493e333",
"version_major": 2,
"version_minor": 0
},
......@@ -1358,7 +1350,7 @@
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "37a1ead76c46453582fc2ab355133adc",
"model_id": "e3f98fd51ea64b489ea023ab3134cacc",
"version_major": 2,
"version_minor": 0
},
......@@ -1372,7 +1364,7 @@
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "9beb1a9e541e4b2992c5006de133e997",
"model_id": "7d91c65d6de14bc6a1bfc858473330f8",
"version_major": 2,
"version_minor": 0
},
......@@ -1422,7 +1414,7 @@
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "1eedb939adce4555853064f9685ffde9",
"model_id": "496ac3141a094b22ba24ab6287619e86",
"version_major": 2,
"version_minor": 0
},
......@@ -1448,7 +1440,7 @@
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "f5ebfb1a9f06484a98e3a46a404fef2f",
"model_id": "45a53da741524bdb8e7e9291f9498b29",
"version_major": 2,
"version_minor": 0
},
......@@ -1474,12 +1466,12 @@
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "d7d6d7effb114d6b93a7c7fa1b4409c8",
"model_id": "d9f49210d75f434dad8f5bd874d20986",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"IntSlider(value=5, description='Maximum lag time (min)', max=19, style=SliderStyle(description_width='initial'…"
"IntSlider(value=60, description='Maximum lag time (min)', max=960, style=SliderStyle(description_width='initia…"
]
},
"metadata": {},
......@@ -1615,26 +1607,11 @@
},
{
"cell_type": "code",
"execution_count": 20,
"execution_count": 19,
"metadata": {
"scrolled": true
},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "832b2558fb4d462388193bacbb111155",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Tab(children=(Accordion(children=(VBox(children=(Dropdown(description='parameter', index=14, options=('track',…"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"outputs": [],
"source": [
"#get MSD parameters\n",
"if not MSD_module_wid.value:\n",
......@@ -1722,7 +1699,7 @@
},
{
"cell_type": "code",
"execution_count": 21,
"execution_count": 20,
"metadata": {
"scrolled": false
},
......@@ -1795,7 +1772,7 @@
},
{
"cell_type": "code",
"execution_count": 22,
"execution_count": 23,
"metadata": {
"scrolled": false
},
......@@ -1804,13 +1781,11 @@
"name": "stdout",
"output_type": "stream",
"text": [
"Analyzing subset #1, named: 21\n",
"Plotting trajectories...\n",
"MSD analysis...g frame 19\n",
"Plotting parameters histograms...\n",
"Plotting whole-track histograms...\n",
"Plotting couples of parameters...\n",
"Plotting couples of whole-track parameters...\n",
"Draw points or rectangles, then press ENTER and close the image viewer\n",
"You have selected 0 point(s) and 1 rectangle(s)\n",
"Is the selection correct? [y]/n: \n",
"Analyzing subset #1, named: 9\n",
"MSD analysis...\n",
"Plotting centered trajectories\n"
]
}
......@@ -3392,7 +3367,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.5"
"version": "3.8.3"
}
},
"nbformat": 4,
......
%% Cell type:code id: tags:
``` python
import os
import os.path as osp
import pickle
import napari
from skimage import io
from skimage.color import rgb2gray
import matplotlib.pyplot as plt
from matplotlib import cm
import numpy as np
import seaborn as sns
import pandas as pd
import warnings
warnings.filterwarnings('ignore')
%matplotlib inline
import ipywidgets as widgets
from ipywidgets import HBox, VBox, interact, interact_manual, TwoByTwoLayout, GridspecLayout, Label, AppLayout
from ipyfilechooser import FileChooser
from IPython.display import HTML, Markdown, display, clear_output
from track_analyzer import prepare as tpr
from track_analyzer import plotting as tpl
from track_analyzer import calculate as tca
from track_analyzer.scripts.analyze_tracks import traj_analysis, make_traj_config
from track_analyzer.scripts.analyze_maps import map_analysis, make_map_config
def printmd(string):
display(Markdown(string))
cwd = os.getcwd()
plot_param = tpl.make_plot_config()
color_list = plot_param['color_list']
HTML('''<script>
code_show=true;
function code_toggle() {
if (code_show){
$('div.input').hide();
} else {
$('div.input').show();
}
code_show = !code_show
}
$( document ).ready(code_toggle);
</script>
<form action="javascript:code_toggle()"><input type="submit" value="Click here to toggle on/off the raw code."></form>''')
```
%%%% Output: stream
/opt/miniconda3/lib/python3.8/site-packages/napari/__init__.py:44: UserWarning:
napari was tested with QT library `>=5.12.3`.
The version installed is 5.9.7. Please report any issues with this
specific QT version at https://github.com/Napari/napari/issues.
WELCOME TO TRACK ANALYZER
Developed and maintained by Arthur Michaut: arthur.michaut@gmail.com
Last release: 11-25-2020
_''_
/ o \
< |
\ /__
/ \-----
/ \ \ \__
| \_____\ __>
\-- ___/
\ /
|| ||
/\ /\
warn(message=warn_message)
%%%% Output: stream
WELCOME TO TRACK ANALYZER
Developed and maintained by Arthur Michaut: arthur.michaut@gmail.com
Last release: 11-25-2020
_''_
/ o \
< |
\ /__
/ \-----
/ \ \ \__
| \_____\ __>
\-- ___/
\ /
|| ||
/\ /\
%%%% Output: execute_result
<IPython.core.display.HTML object>
%% Cell type:markdown id: tags:
# Preparation module
## Loading data
%% Cell type:code id: tags:
``` python
fc_table = FileChooser(cwd)
fc_table.use_dir_icons = True
fc_table.title = '<b>Tracking data file</b>'
sep_wid = widgets.Dropdown(options=[',',';', 'tab', ' '],value=',',description='column separator:',style={'description_width': 'initial'})
header_wid = widgets.Dropdown(options=['yes','no'],value='yes',description='first row = column names?',style={'description_width': 'initial'})
printmd("""**Browse your file system to the table of tracked data (only .txt and .csv are supported)**""")
display(fc_table,sep_wid,header_wid)
```
%%%% Output: display_data
**Browse your file system to the table of tracked data (only .txt and .csv are supported)**
%%%% Output: display_data
%%%% Output: display_data
%%%% Output: display_data
%% Cell type:code id: tags:
``` python
data_dir=fc_table.selected_path
data_file=fc_table.selected
if data_file is None:
raise Exception("**ERROR: no data table has been selected**")
printmd("""**(Optional) Browse your file system to the image file**
You can plot your data on your image. The image can be a single image or a stack (a 2D time series or a 3D time series).
Only tif images are supported. """)
fc_im = FileChooser(data_dir)
fc_im.use_dir_icons = True
fc_im.title = '<b>Image file</b>'
display(fc_im)
```
%%%% Output: display_data
**(Optional) Browse your file system to the image file**
You can plot your data on your image. The image can be a single image or a stack (a 2D time series or a 3D time series).
Only tif images are supported.
%%%% Output: display_data
%% Cell type:code id: tags:
``` python
im_file=fc_im.selected
y_size,x_size = [512,512] #default size of an image to inialize the make info widget
image = tpr.get_image(data_dir,filename=im_file,verbose=True)
if image['image_size'] is not None:
y_size,x_size = image['image_size']
check_swap_wid=False #to retrieve swap_wid value if necessary
if len(image['image_size'])==4: #widget to swap z and t if 4D image
check_swap_wid=True #to retrieve value in next cell
swap_wid=widgets.ToggleButton(value=False,description='Swap z and t')
display(swap_wid)
database_fn=osp.join(data_dir,'data_base.p')
info_fn=osp.join(data_dir,'info.txt')
printmd("---")
if osp.exists(database_fn):
printmd('The database already exists, do you want to refresh it?')
refresh_db_wid=widgets.ToggleButton(value=False,description='Refresh database')
display(refresh_db_wid)
if osp.exists(info_fn):
printmd("The info.txt file already exists, do you want to refresh it?")
refresh_info_wid=widgets.ToggleButton(value=False,description='Refresh info')
display(refresh_info_wid)
```
%%%% Output: stream
You have loaded a 3D image: (129x998) pixels with 141 time steps
You have loaded a 3D image: (991x989) pixels with 81 time steps
%%%% Output: display_data
---
%%%% Output: display_data
The database already exists, do you want to refresh it?
%%%% Output: display_data
%%%% Output: display_data
The info.txt file already exists, do you want to refresh it?
%%%% Output: display_data
%% Cell type:code id: tags:
``` python
#swap z and t
if check_swap_wid:
if swap_wid.value:
image['t_dim']=1
image['z_dim']=0
printmd("**z and t swapped!**")
printmd("4D image with {} time steps and {} z slices".format(im.shape[1],im.shape[0]))
refresh_db=refresh_db_wid.value if osp.exists(database_fn) else True
refresh_info=refresh_info_wid.value if osp.exists(info_fn) else True
if refresh_info:
length_unit_wid=widgets.Dropdown(options=['um', 'mm', 'au'],value='um',description='Length unit:',style={'description_width': 'initial'})
time_unit_wid=widgets.Dropdown(options=['min', 's', 'hr', 'au'],value='min',description='Time unit:',style={'description_width': 'initial'})
length_sc_wid=widgets.BoundedFloatText(value=1.0,min=0,max=1e4,description='Pixel size:',style={'description_width': 'initial'})
z_sc_wid=widgets.BoundedFloatText(value=0,min=0,max=1e4,description='z step:',style={'description_width': 'initial'})
time_sc_wid=widgets.BoundedFloatText(value=1.0,min=0,max=1e4,description='Frame interval:',style={'description_width': 'initial'})
width_wid=widgets.BoundedIntText(value=x_size,min=0,max=1e4,description='Image width (px):',style={'description_width': 'initial'})
height_wid=widgets.BoundedIntText(value=y_size,min=0,max=1e4,description='Image height (px):',style={'description_width': 'initial'})
left_box = VBox([length_unit_wid, time_unit_wid,width_wid])
right_box = VBox([length_sc_wid, time_sc_wid,height_wid])
box = HBox([left_box, right_box])
printmd("**Information about the data**")
display(box)
printmd("In the data table, are the positions given in pixels or in the length unit (given above)?")
table_unit_wid=widgets.Dropdown(options=['px', 'unit'],value='px',description='Data unit:',style={'description_width': 'initial'})
display(table_unit_wid)
printmd("If the lengthscale in z is different from the xy lengthscale, enter the z step (in length unit). If not, leave it to zero.")
display(z_sc_wid)
wid_list = [length_unit_wid,time_unit_wid,length_sc_wid,time_sc_wid,width_wid,height_wid,table_unit_wid,z_sc_wid]
param_names = ['length_unit','time_unit','lengthscale','timescale','image_width','image_height','table_unit','z_step']
```
%% Cell type:code id: tags:
``` python
if refresh_info:
info_dict = {}
with open(info_fn,'w+') as f:
for couple in zip(param_names,wid_list):
info_dict[couple[0]]=couple[1].value
f.write('{}:{}\n'.format(couple[0],couple[1].value))
```
%% Cell type:code id: tags:
``` python
if refresh_db:
sep = sep_wid.value if sep_wid.value !='tab' else '\t'
header = None if header_wid.value=='no' else 0
df = pd.read_csv(data_file,sep=sep,header=header)
printmd("**Here are the first rows of the input data table**")
display(df.head(10))
```
%% Cell type:code id: tags:
``` python
if refresh_db:
wid_list = []
left_list=[]
right_list=[]
param_list = ['x','y','z','frame','track','none']
for i,col in enumerate(df.columns):
wid=widgets.Dropdown(options=param_list,value='none',description='column {}:'.format(col),style={'description_width': 'initial'})
wid_list.append(wid)
if i<len(df.columns)/2:
left_list.append(wid)
else:
right_list.append(wid)
printmd("**Select the columns to be used in the analysis: track,frame,x,y,(z). Leave to 'none' the other ones.**")
left_box = VBox(left_list)
right_box = VBox(right_list)
display(HBox([left_box, right_box]))
printmd("""**Some tracking softwares support to miss objects at some frames. This results in tracks with gaps.
However, this analysis pipeline requires to have continuous tracks. How do you want to handle tracks with gaps:
fill the gaps by linear interpolation or split the track in different tracks?**""")
split_wid=widgets.Dropdown(options=['interpolate','split'],value='interpolate',description='gap resolution:'.format(col),style={'description_width': 'initial'})
display(split_wid)
```
%% Cell type:code id: tags:
``` python
if refresh_db:
col_values = [wid.value for wid in wid_list]
for param_ in ['x','y','frame','track']:
if param_ not in col_values:
print("Warning: you MUST select a column for "+param_)
df.columns=col_values #rename columns
split_traj=True if split_wid.value=='split' else False
col_values=np.array(col_values)
new_cols=col_values[col_values!='none']
df=df[new_cols] #ditch none columns
#get dimension
dim_list = ['x','y','z'] if 'z' in df.columns else ['x','y']
printmd("""**Do you want to set a custom origin to the coordinates?**""")
printmd("""Select a new origin by drawing on the image (you can choose which dimension to reset)""")
ori_onimage_wid=widgets.ToggleButton(value=False,description='Select on image')
reset_dim_wid=widgets.SelectMultiple(options=dim_list,value=['x','y'],description='Dimensions to reset',style={'description_width': 'initial'})
display(HBox([ori_onimage_wid,reset_dim_wid]))
printmd("""Or directly type in the new origin (in px)""")
origin_coord_wid_list=[]
for dim in dim_list:
origin_coord_wid_list.append(widgets.FloatSlider(value=0,min=0,max=df[dim].max(),step=0.1,description=dim,style={'description_width': 'initial'}))
display(HBox(origin_coord_wid_list))
printmd("""**Do you want to invert the axes?**
Default orientation: x: left->right, y: top->bottom, z: slice number""")
invert_axes_wid=widgets.SelectMultiple(options=dim_list,value=[],description='Axes to invert',style={'description_width': 'initial'})
display(invert_axes_wid)
```
%% Cell type:code id: tags:
``` python
if refresh_db:
if not ori_onimage_wid.value:
origin_coord={}
all_zeros=True
for d,wid in enumerate(origin_coord_wid_list):
origin_coord[dim_list[d]]=wid.value
if wid.value>0:
all_zeros=False
if all_zeros: #if no change of origin
origin_coord = False
set_origin_ = origin_coord
else:
set_origin_=True
#remove non-numeric tracks
df=df[df['track']!='None'] #remove
data=tpr.get_data(data_dir,df=df,refresh=refresh_db,split_traj=split_traj,
set_origin_=set_origin_,image=image,reset_dim=reset_dim_wid.value,invert_axes=invert_axes_wid.value)
else:
data = tpr.get_data(data_dir,df=None,refresh=refresh_db)
df = data['df']
lengthscale = data['lengthscale']
timescale = data['timescale']
dim = data['dim']
dimensions = data['dimensions']
```
%% Cell type:code id: tags:
``` python
printmd("## General plotting parameters")
fig_w_wid=widgets.BoundedIntText(value=plot_param['figsize'][0],min=0,max=20,description='Figure width (inches):',style={'description_width': 'initial'})
fig_h_wid=widgets.BoundedIntText(value=plot_param['figsize'][1],min=0,max=20,description='Figure height (inches):',style={'description_width': 'initial'})
fig_dpi_wid=widgets.BoundedIntText(value=plot_param['dpi'],min=50,max=1e4,description='Figure resolution (dpi):',style={'description_width': 'initial'})
fig_format_wid=widgets.Dropdown(options=['.png','.svg'],value='.png',description='Figure format',
style={'description_width': 'initial'})
despine_wid=widgets.ToggleButton(value=plot_param['despine'],description='despine figure')
replace_color_wid=widgets.BoundedIntText(value=0,min=0,max=20,description='Number of colors:',style={'description_width': 'initial'})
add_replace_wid=widgets.Dropdown(options=['add','replace'],value='add',description='add or replace?',
style={'description_width': 'initial'})
invert_yaxis_wid=widgets.ToggleButton(value=True,description='y axis origin: top')
export_data_pts_wid=widgets.ToggleButton(value=True,description='export data points')
display(HBox([fig_w_wid,fig_h_wid]),fig_dpi_wid,fig_format_wid,despine_wid)
printmd('Do you want to add/replace the first default colors used for plotting? Give the number of colors you want to select:')
display(HBox([replace_color_wid,add_replace_wid]))
printmd('How do you want to display the y-axis (standard orientation: origin at top)')
display(invert_yaxis_wid)
printmd('Do you want to export the data points of your plots as .csv files?')
display(export_data_pts_wid)
```
%%%% Output: display_data
## General plotting parameters
%%%% Output: display_data
%%%% Output: display_data
%%%% Output: display_data
%%%% Output: display_data
%%%% Output: display_data
Do you want to add/replace the first default colors used for plotting? Give the number of colors you want to select:
%%%% Output: display_data
%%%% Output: display_data
How do you want to display the y-axis (standard orientation: origin at top)
%%%% Output: display_data
%%%% Output: display_data
Do you want to export the data points of your plots as .csv files?
%%%% Output: display_data
%% Cell type:code id: tags:
``` python
color_wid_list=[]
for i in range(replace_color_wid.value):
color_wid=widgets.ColorPicker(description='Pick color #{}'.format(i),value=color_list[i])
color_wid_list.append(color_wid)
display(*color_wid_list)
```
%% Cell type:code id: tags:
``` python
color_list_=list(color_list)
new_color_list = [color_wid_list[i].value for i in range(replace_color_wid.value)]
if add_replace_wid.value=='replace':
color_list_[:replace_color_wid.value]=new_color_list
else:
color_list_=new_color_list+color_list_
plot_param={'figsize':(fig_w_wid.value,fig_h_wid.value),
'dpi':fig_dpi_wid.value,
'color_list':color_list_,
'format':fig_format_wid.value,
'despine':despine_wid.value,
'invert_yaxis':invert_yaxis_wid.value,
'export_data_pts':export_data_pts_wid.value
}
```
%% Cell type:markdown id: tags:
# Filter data
%% Cell type:code id: tags:
``` python
printmd("Your data can be filtered into subsets. How many subset do you want to analyze?")
subset_num_wid=widgets.BoundedIntText(value=1,min=1,max=20,description='Number of subsets:',style={'description_width': 'initial'})
display(subset_num_wid)
```
%%%% Output: display_data
Your data can be filtered into subsets. How many subset do you want to analyze?
%%%% Output: display_data
%% Cell type:code id: tags:
``` python
xlim=[df['x'].min(),df['x'].max()] #maybe use image dimensions instead
ylim=[df['y'].min(),df['y'].max()]
zlim=[df['z'].min(),df['z'].max()] if 'z' in df.columns else []
frame_list=df['frame'].unique()
frame_min=df['frame'].min()
frame_max=df['frame'].max()
info=tpr.get_info(data_dir)
xlim_wid_list=[]
ylim_wid_list=[]
zlim_wid_list=[]
frame_subset_wid_list=[]
min_length_wid_list=[]
max_length_wid_list=[]
ROI_wid_list=[]
name_wid_list=[]
for i in range(subset_num_wid.value):
printmd("""### Subset #{}""".format(i+1))
printmd("""You can give it a custom name that will be used for saving data""")
name_wid=widgets.Text(value='',placeholder='optional',description='Subset name:',style={'description_width': 'initial'})
name_wid_list.append(name_wid)
display(name_wid)
xlim_wid=widgets.FloatRangeSlider(value=xlim,min=xlim[0],max=xlim[1],step=1,
description='x range (px):',style={'description_width': 'initial'})
ylim_wid=widgets.FloatRangeSlider(value=ylim,min=ylim[0],max=ylim[1],step=1,
description='y range (px):',style={'description_width': 'initial'})
if len(zlim)>0:
zlim_wid=widgets.FloatRangeSlider(value=zlim,min=zlim[0],max=zlim[1],step=1,
description='z range (px):',style={'description_width': 'initial'})
frame_subset_wid=widgets.IntRangeSlider(value=[frame_min,frame_max],min=frame_min,max=frame_max,step=1,
description='Frame subset:',style={'description_width': 'initial'})
min_length_wid=widgets.IntSlider(value=frame_min,min=frame_min,max=frame_max+1,step=1,
description='Minimum traj length:',style={'description_width': 'initial'})
max_length_wid=widgets.IntSlider(value=frame_max+1,min=frame_min,max=frame_max+1,step=1,
description='Maximum traj length:',style={'description_width': 'initial'})
ROI_wid = widgets.Dropdown(options=['no filtering','filter at a given frame','filter at all frames'],value='no filtering',description='ROI filtering?',
style={'description_width': 'initial'})
xlim_wid_list.append(xlim_wid)
ylim_wid_list.append(ylim_wid)
if len(zlim)>0:
zlim_wid_list.append(zlim_wid)
else:
zlim_wid_list.append(None)
frame_subset_wid_list.append(frame_subset_wid)
min_length_wid_list.append(min_length_wid)
max_length_wid_list.append(max_length_wid)
ROI_wid_list.append(ROI_wid)
printmd("**Select a subregion of the dataset (in pixels)**")
if len(zlim)>0:
display(HBox([xlim_wid,ylim_wid,zlim_wid]))
else:
display(HBox([xlim_wid,ylim_wid]))
printmd("**Select trajectories of subset of frames or based on their minimum or maximum lengths (in frames)**")
display(HBox([frame_subset_wid,min_length_wid,max_length_wid]))
printmd("""**Select trajectories by ROIs (an image file is required) <br/>**
Select tracks within ROIs either at: <br/>
- a given frame (this tool is usefull to do some fate mapping for instance)
- or at all frames.""")
display(ROI_wid)
```
%%%% Output: display_data
### Subset #1
%%%% Output: display_data
You can give it a custom name that will be used for saving data
%%%% Output: display_data
%%%% Output: display_data
**Select a subregion of the dataset (in pixels)**
%%%% Output: display_data
%%%% Output: display_data
**Select trajectories of subset of frames or based on their minimum or maximum lengths (in frames)**
%%%% Output: display_data
%%%% Output: display_data
**Select trajectories by ROIs (an image file is required) <br/>**
Select tracks within ROIs either at: <br/>
- a given frame (this tool is usefull to do some fate mapping for instance)
- or at all frames.
%%%% Output: display_data
%% Cell type:code id: tags:
``` python
filters=[]
for i in range(subset_num_wid.value):
if ROI_wid_list[i].value=='no filtering':
ROI=None
elif ROI_wid_list[i].value=='filter at a given frame':
ROI={'filter_all_frames':False}
elif ROI_wid_list[i].value=='filter at all frames':
ROI={'filter_all_frames':True}
if zlim_wid_list[i] is None:
zlim = None
else:
zlim = zlim_wid_list[i].value
filters.append({'xlim':xlim_wid_list[i].value,
'ylim':ylim_wid_list[i].value,
'zlim':zlim,
'frame_subset':frame_subset_wid_list[i].value,
'min_traj_len':min_length_wid_list[i].value,
'max_traj_len':max_length_wid_list[i].value,
'ROI':ROI,
'name':name_wid_list[i].value})
```
%% Cell type:markdown id: tags:
# Trajectory analysis module
%% Cell type:code id: tags:
``` python
info=tpr.get_info(data_dir)
z_step=info['z_step']
if z_step == 0:
z_step = lengthscale
printmd('**View trajectories on a Napari viewer before plotting**')
viewer_wid=widgets.Button(value=True,description='Show viewer!')
viewer_wid.on_click(lambda obj: tpl.view_traj(df,image=image,z_step=info['z_step']))
display(viewer_wid)
```
%%%% Output: display_data
**View trajectories on a Napari viewer before plotting**
%%%% Output: display_data
%% Cell type:code id: tags:
``` python
dim=data['dim']
<