In [2]:
# import multi tracker analysis
import multi_tracker_analysis as mta
In [35]:
# load hdf5 data as a pandas dataframe, and load the configuration
# change the argument to match your data path!
pd, config = mta.read_hdf5_file_to_pandas.load_and_preprocess_data('/home/caveman/demo/demo_1/test_data/')
File is not a trackedobjects file, looking for a trackedobjects file in this directory
Found: /home/caveman/demo/demo_1/test_data/20160531_160855_N1_trackedobjects.hdf5
Preprocessing data - see config file for details!
No delete cut join instructions found in path!
In [18]:
# pandas dataframe structure: each row is a measurement corresponding to one of the objects for each frame
pd.keys()
Out[18]:
Index([u'angle', u'area', u'frames', u'measurement_x', u'measurement_y',
u'objid', u'position_x', u'position_y', u'time_epoch_nsecs',
u'time_epoch_secs', u'velocity_x', u'velocity_y', u'time_epoch',
u'speed'],
dtype='object')
In [20]:
# show the object id's
import numpy as np
np.unique(pd.objid)
Out[20]:
array([ 0, 1, 2, 3, 6, 7, 9, 10, 11, 12, 22, 23, 25])
In [32]:
position_for_10 = pd[pd.objid==10].position_x.values
position_for_10
Out[32]:
array([ 460. , 460. , 460. , 460. ,
460. , 460. , 460. , 459.59732957,
459.32276829, 458.780908 , 458.05604803, 457.19996275,
456.24708056, 455.22269337, 453.84097436, 452.4836458 ,
450.85526968, 449.0175411 , 447.3278121 , 445.47370204,
444.40825339, 443.69783843, 443.27223568, 443.06735073,
443.33076778, 443.6550623 , 444.00456115, 444.35314175,
444.98653475, 445.53370638, 445.68817924, 446.11598315,
446.46046274, 446.42495643, 446.37781251, 446.02125322,
445.71912437, 445.47083336, 444.96932584, 444.26522295,
443.70825987, 442.97932574, 441.81255981, 440.60080664,
439.36890793, 438.13522151, 436.60882113, 435.15744252,
433.78211372, 432.47953723, 431.85118054, 431.77814509,
431.84454775, 432.30832412, 432.77324752, 433.21443494,
433.00821302, 432.56040696, 431.91527039, 431.41782721,
431.04945864, 430.79039089, 430.62108955, 430.21941651,
430.23199455, 429.97747871, 429.49767236, 429.137369 ,
428.57547592, 428.1539181 , 427.54850641, 426.794273 ,
425.9234607 , 424.96466893, 424.24625255, 423.4292957 ,
422.83787689, 422.13088605, 421.32797167, 420.75167619,
420.36356431, 419.82314553, 419.45623944, 419.22949474,
418.5046934 , 417.97345432, 417.30120596, 416.51349127,
415.63418652, 414.68474764, 413.68381331, 412.34327601,
411.33910932, 410.92591569, 410.69493146, 410.29918929,
409.75685545, 409.08831311, 408.61821435, 408.00727822,
407.58156115, 407.00345773, 406.60080036, 406.34153701,
406.19578604, 406.13675368, 405.83740874, 405.63758527,
405.21379226, 404.60366481, 404.14703872, 403.51757557,
402.74822983, 402.47692849, 402.31565192, 402.2394852 ,
402.53039248, 402.81047466, 403.37204138, 404.15271391,
405.40130303, 406.71150672, 407.7444354 , 408.5298167 ,
409.10141033, 409.19020039, 409.18920767, 409.12576067,
409.02218125, 408.59232649, 408.20903321, 407.5745816 ,
406.74598346, 405.77317565, 405.0023355 , 403.8051807 ,
402.87646149, 401.8798352 , 401.13955525, 399.09780274,
397.81666366, 397.79304349, 397.58926161, 397.52183521,
396.64149389, 398.12135737, 397.58628095, 397.18282266,
396.28468532, 396.19921125, 396.18196286, 396.21312332,
396.27634159, 396.66234357, 397.00166736, 396.98678614,
396.97712317, 396.97160305, 396.9692585 , 396.96924848,
396.97086431, 397.27732797, 396.92122143, 396.92848777,
396.63351917, 396.69853205, 396.45590154, 395.35152042,
391.72434832, 391.22190228, 389.39415506, 388.90674092,
389.53649993, 389.85390911, 390.1881407 , 388.99744023,
389.58207478, 390.11669336, 390.58827845, 390.9910936 ,
391.32477419, 391.59271466, 391.80074741, 391.95609435,
392.06656366, 392.13995961, 392.18367196, 392.20441186,
392.2080639 , 392.19962668, 392.18321816, 392.16212594,
392.13888598, 392.11537718, 392.09292179, 392.07238479,
392.05426712, 392.03878988, 392.02596766, 391.7118693 ,
391.45562823, 390.94938828, 390.2430431 , 389.38188842,
388.4056285 , 387.95558209, 387.6446043 , 387.14305537,
386.78632842, 386.54925124, 386.40798493, 386.34087681,
385.72133651, 384.94814633, 384.35981748, 383.62743445,
382.78063862, 382.14990518, 381.70287865, 381.40733875,
381.53666085, 382.00771805, 382.44080253, 382.82459609,
383.45762132, 383.97972584, 384.39705543, 384.71941787,
384.95865286, 385.12738991, 385.23814192, 385.30268032,
385.63544028, 385.88634561, 386.06702327, 386.18927394,
386.26439651, 385.99894304, 385.76141927, 385.85967573,
385.93548684, 385.99167087, 385.72742446, 385.5050694 ,
385.32361298, 384.8764046 , 384.51880977, 384.2424745 ,
383.73349335, 383.64423519, 383.29706669, 383.34349304,
383.10665845, 382.63234479, 382.26875863, 382.00144768,
381.81526972, 381.39160007, 380.77217538, 379.99638287,
379.09989557, 378.41771943, 377.92074568, 377.8827367 ,
377.91523417, 377.69130202, 377.55169108, 377.47815189,
377.45449252, 377.46680796, 377.50351912, 377.25147605,
377.06273328, 376.32041788, 375.43013761, 374.73485554,
373.90822061, 372.98098932, 372.28368406, 371.47944944,
370.59043996, 369.94035443, 369.49091323, 369.20487791,
368.74389877, 368.1326792 , 367.70014724, 367.11104139,
366.39124561, 365.86947818, 364.9055097 , 363.88281 ,
363.1242208 , 362.58953663, 361.93514958, 360.87538593,
360.09138462, 359.23694018, 358.32577218, 357.37042553,
356.07816415, 355.12159736, 354.44921988, 354.0101768 ,
353.75674964, 353.34212052, 352.78437209, 352.40744723,
351.56869989, 350.95475405, 350.52971338, 350.25861814,
349.80520434, 349.19601659, 348.45775558, 347.61582166,
346.69336945, 346.01456943, 345.23741962, 344.38003874,
343.76307612, 343.04224904, 342.23437935, 341.35577177,
340.72531175, 339.99708065, 339.49024109, 338.86047937,
338.42940268, 337.85559749, 337.15993409, 336.66717416,
336.34167889, 335.84600864, 335.50904992, 335.60416886,
335.44024898, 335.65946807, 335.88282956, 335.48968553,
335.79774027, 335.77185104, 336.06966788, 336.32610231,
336.54019401, 336.71350889, 336.84928897, 336.95177209,
337.32946697, 337.62780249, 337.85514461, 338.32486532,
338.38371074, 338.40442999, 338.70131368, 338.92376576,
339.38646081, 339.74096572, 340.00144115, 340.18270778,
340.29926369, 340.66841848, 340.94292155, 341.13704235,
341.26495713, 341.34002915, 341.37435047, 341.37849003,
341.05759742, 340.47458053, 339.68706834, 339.04977476,
338.5506939 , 338.47797485, 338.45489581, 338.46759399,
338.50453013, 338.55639155, 338.31210593, 338.12556439,
337.98906821, 337.89461662, 337.83442074, 338.10505145,
338.3406917 , 338.53953662, 338.7022714 , 338.52747744,
338.3779505 , 338.25390514, 338.15414604, 338.0765594 ,
338.01850356, 337.97710869, 337.94949764, 337.93293992,
337.9249513 , 337.92335004, 338.23008135, 338.18045562,
338.44018459, 338.3467485 , 338.26340008, 338.19147309,
338.13129334, 338.08246777, 337.74032235, 337.46305345,
337.24558331, 337.08122114, 337.26630747, 337.73768335,
337.82866739, 338.20485298, 338.20491257, 338.49794179,
338.42464136, 338.35120088, 337.97773722, 337.96993715,
337.9660932 , 337.96520635, 337.66262382, 337.72080001,
337.77603591, 337.82630992, 337.87047645, 338.21186145,
338.49112425, 339.01620185, 339.43367641, 339.45040605,
339.43828475, 339.40671712, 339.36327685, 339.31386324,
339.26289862, 339.21354364, 339.16791382, 339.4310866 ,
339.34052818, 339.25951145, 339.18941298, 339.43441617,
339.93863482, 340.3456807 , 340.66359474, 340.90267861,
341.37806548, 341.74184945, 342.00873832, 342.27877798])
In [33]:
# wrap pandas dataframe into a dataset object for intuitive processing
# note: using copy=True creates a copy of the data
# this allows you to add attributes to trajecties and pickle the dataset structure for future use
dataset = mta.read_hdf5_file_to_pandas.Dataset(pd, config=config)
dataset.load_keys() # load the object ids
trajec = dataset.trajec(dataset.keys[7]) # load the 7th trajectory
trajec.position_x # show the position x data
Out[33]:
array([ 460. , 460. , 460. , 460. ,
460. , 460. , 460. , 459.59732957,
459.32276829, 458.780908 , 458.05604803, 457.19996275,
456.24708056, 455.22269337, 453.84097436, 452.4836458 ,
450.85526968, 449.0175411 , 447.3278121 , 445.47370204,
444.40825339, 443.69783843, 443.27223568, 443.06735073,
443.33076778, 443.6550623 , 444.00456115, 444.35314175,
444.98653475, 445.53370638, 445.68817924, 446.11598315,
446.46046274, 446.42495643, 446.37781251, 446.02125322,
445.71912437, 445.47083336, 444.96932584, 444.26522295,
443.70825987, 442.97932574, 441.81255981, 440.60080664,
439.36890793, 438.13522151, 436.60882113, 435.15744252,
433.78211372, 432.47953723, 431.85118054, 431.77814509,
431.84454775, 432.30832412, 432.77324752, 433.21443494,
433.00821302, 432.56040696, 431.91527039, 431.41782721,
431.04945864, 430.79039089, 430.62108955, 430.21941651,
430.23199455, 429.97747871, 429.49767236, 429.137369 ,
428.57547592, 428.1539181 , 427.54850641, 426.794273 ,
425.9234607 , 424.96466893, 424.24625255, 423.4292957 ,
422.83787689, 422.13088605, 421.32797167, 420.75167619,
420.36356431, 419.82314553, 419.45623944, 419.22949474,
418.5046934 , 417.97345432, 417.30120596, 416.51349127,
415.63418652, 414.68474764, 413.68381331, 412.34327601,
411.33910932, 410.92591569, 410.69493146, 410.29918929,
409.75685545, 409.08831311, 408.61821435, 408.00727822,
407.58156115, 407.00345773, 406.60080036, 406.34153701,
406.19578604, 406.13675368, 405.83740874, 405.63758527,
405.21379226, 404.60366481, 404.14703872, 403.51757557,
402.74822983, 402.47692849, 402.31565192, 402.2394852 ,
402.53039248, 402.81047466, 403.37204138, 404.15271391,
405.40130303, 406.71150672, 407.7444354 , 408.5298167 ,
409.10141033, 409.19020039, 409.18920767, 409.12576067,
409.02218125, 408.59232649, 408.20903321, 407.5745816 ,
406.74598346, 405.77317565, 405.0023355 , 403.8051807 ,
402.87646149, 401.8798352 , 401.13955525, 399.09780274,
397.81666366, 397.79304349, 397.58926161, 397.52183521,
396.64149389, 398.12135737, 397.58628095, 397.18282266,
396.28468532, 396.19921125, 396.18196286, 396.21312332,
396.27634159, 396.66234357, 397.00166736, 396.98678614,
396.97712317, 396.97160305, 396.9692585 , 396.96924848,
396.97086431, 397.27732797, 396.92122143, 396.92848777,
396.63351917, 396.69853205, 396.45590154, 395.35152042,
391.72434832, 391.22190228, 389.39415506, 388.90674092,
389.53649993, 389.85390911, 390.1881407 , 388.99744023,
389.58207478, 390.11669336, 390.58827845, 390.9910936 ,
391.32477419, 391.59271466, 391.80074741, 391.95609435,
392.06656366, 392.13995961, 392.18367196, 392.20441186,
392.2080639 , 392.19962668, 392.18321816, 392.16212594,
392.13888598, 392.11537718, 392.09292179, 392.07238479,
392.05426712, 392.03878988, 392.02596766, 391.7118693 ,
391.45562823, 390.94938828, 390.2430431 , 389.38188842,
388.4056285 , 387.95558209, 387.6446043 , 387.14305537,
386.78632842, 386.54925124, 386.40798493, 386.34087681,
385.72133651, 384.94814633, 384.35981748, 383.62743445,
382.78063862, 382.14990518, 381.70287865, 381.40733875,
381.53666085, 382.00771805, 382.44080253, 382.82459609,
383.45762132, 383.97972584, 384.39705543, 384.71941787,
384.95865286, 385.12738991, 385.23814192, 385.30268032,
385.63544028, 385.88634561, 386.06702327, 386.18927394,
386.26439651, 385.99894304, 385.76141927, 385.85967573,
385.93548684, 385.99167087, 385.72742446, 385.5050694 ,
385.32361298, 384.8764046 , 384.51880977, 384.2424745 ,
383.73349335, 383.64423519, 383.29706669, 383.34349304,
383.10665845, 382.63234479, 382.26875863, 382.00144768,
381.81526972, 381.39160007, 380.77217538, 379.99638287,
379.09989557, 378.41771943, 377.92074568, 377.8827367 ,
377.91523417, 377.69130202, 377.55169108, 377.47815189,
377.45449252, 377.46680796, 377.50351912, 377.25147605,
377.06273328, 376.32041788, 375.43013761, 374.73485554,
373.90822061, 372.98098932, 372.28368406, 371.47944944,
370.59043996, 369.94035443, 369.49091323, 369.20487791,
368.74389877, 368.1326792 , 367.70014724, 367.11104139,
366.39124561, 365.86947818, 364.9055097 , 363.88281 ,
363.1242208 , 362.58953663, 361.93514958, 360.87538593,
360.09138462, 359.23694018, 358.32577218, 357.37042553,
356.07816415, 355.12159736, 354.44921988, 354.0101768 ,
353.75674964, 353.34212052, 352.78437209, 352.40744723,
351.56869989, 350.95475405, 350.52971338, 350.25861814,
349.80520434, 349.19601659, 348.45775558, 347.61582166,
346.69336945, 346.01456943, 345.23741962, 344.38003874,
343.76307612, 343.04224904, 342.23437935, 341.35577177,
340.72531175, 339.99708065, 339.49024109, 338.86047937,
338.42940268, 337.85559749, 337.15993409, 336.66717416,
336.34167889, 335.84600864, 335.50904992, 335.60416886,
335.44024898, 335.65946807, 335.88282956, 335.48968553,
335.79774027, 335.77185104, 336.06966788, 336.32610231,
336.54019401, 336.71350889, 336.84928897, 336.95177209,
337.32946697, 337.62780249, 337.85514461, 338.32486532,
338.38371074, 338.40442999, 338.70131368, 338.92376576,
339.38646081, 339.74096572, 340.00144115, 340.18270778,
340.29926369, 340.66841848, 340.94292155, 341.13704235,
341.26495713, 341.34002915, 341.37435047, 341.37849003,
341.05759742, 340.47458053, 339.68706834, 339.04977476,
338.5506939 , 338.47797485, 338.45489581, 338.46759399,
338.50453013, 338.55639155, 338.31210593, 338.12556439,
337.98906821, 337.89461662, 337.83442074, 338.10505145,
338.3406917 , 338.53953662, 338.7022714 , 338.52747744,
338.3779505 , 338.25390514, 338.15414604, 338.0765594 ,
338.01850356, 337.97710869, 337.94949764, 337.93293992,
337.9249513 , 337.92335004, 338.23008135, 338.18045562,
338.44018459, 338.3467485 , 338.26340008, 338.19147309,
338.13129334, 338.08246777, 337.74032235, 337.46305345,
337.24558331, 337.08122114, 337.26630747, 337.73768335,
337.82866739, 338.20485298, 338.20491257, 338.49794179,
338.42464136, 338.35120088, 337.97773722, 337.96993715,
337.9660932 , 337.96520635, 337.66262382, 337.72080001,
337.77603591, 337.82630992, 337.87047645, 338.21186145,
338.49112425, 339.01620185, 339.43367641, 339.45040605,
339.43828475, 339.40671712, 339.36327685, 339.31386324,
339.26289862, 339.21354364, 339.16791382, 339.4310866 ,
339.34052818, 339.25951145, 339.18941298, 339.43441617,
339.93863482, 340.3456807 , 340.66359474, 340.90267861,
341.37806548, 341.74184945, 342.00873832, 342.27877798])
In [34]:
import matplotlib.pyplot as plt
%matplotlib inline
In [15]:
# plot the trajectory; this requires downloading my plotting library: https://github.com/florisvb/FlyPlotLib
mta.plot.plot_trajectories(dataset, dataset.keys)
In [14]:
# make a heatmap of the trajectories
bgimg = mta.plot.get_filename(config.path, 'bgimg')
binsx, binsy = mta.plot.get_bins_from_backgroundimage(bgimg)
mta.plot.plot_heatmap(pd, binsx, binsy)
Out[14]:
<matplotlib.axes.AxesSubplot at 0x7f5867ad6690>
In [ ]:
Content source: florisvb/multi_tracker
Similar notebooks: