Modules
Arcos4py top level module.
This package is a python implementation of the Arcos algorithm for the detection and tracking of collective events intime-series data.
ARCOS(data, position_columns=['x'], frame_column='time', obj_id_column='id', measurement_column='meas', clid_column='clTrackID', n_jobs=1, **kwargs)
¶
Detects and tracks collective events in a tracked time-series dataset.
Requires binarized measurement column, that can be generated with the bin_measurements method. Tracking makes use of the dbscan algorithm, which is applied to every frame and subsequently connects collective events between frames located within eps distance of each other.
Attributes:
Name | Type | Description |
---|---|---|
data |
DataFrame
|
Data of tracked time-series in "long format". Can be used to acess modified dataframe at any point. |
position_columns |
list
|
List containing position column names strings inside data e.g. At least one dimension is required. |
frame_column |
str
|
Indicating the frame column in input_data. |
obj_id_column |
str
|
Indicating the track id/id column in input_data. |
measurement_column |
str
|
Indicating the measurement column in input_data. |
clid_column |
str
|
Indicating the column name containing the collective event ids. |
binarized_measurement_column |
str | None
|
Name of the binary column. This is generated based on the name of the measurement_column after binarization. Optionally can be set in order to provide a already binarized column to skip ARCOS binarization. |
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
DataFrame
|
Input Data of tracked time-series in "long format" containing position columns, a measurement and an object ID column. |
required |
position_columns |
list
|
List ontaining position column names strings inside data e.g. At least one dimension is required. |
['x']
|
frame_column |
str
|
Indicating the frame column in input_data. |
'time'
|
obj_id_column |
str
|
Indicating the track id/object id column in input_data. If None, the data is assumed to not have a tracking column. Binarization can only be performed without detrending. |
'id'
|
measurement_column |
str
|
Indicating the measurement column in input_data. |
'meas'
|
clid_column |
str
|
Indicating the column name containing the collective event ids. |
'clTrackID'
|
n_jobs |
str
|
Number of workers to spawn, -1 uses all available cpus. |
1
|
kwargs |
Any
|
Additional keyword arguments. Includes old parameter names for backwards compatibility. - posCols: List containing position column names strings inside data e.g. |
{}
|
Source code in arcos4py/_arcos4py.py
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
|
bin_col: str | None
property
writable
¶
Return the name of the binarized measurement column.
id_column: str | None
property
writable
¶
Return the name of the id column.
posCols: list
property
writable
¶
Return the position columns.
bin_measurements(smooth_k=3, bias_k=51, peak_threshold=0.2, binarization_threshold=0.1, polynomial_degree=1, bias_method='runmed', **kwargs)
¶
Smooth, de-trend, and binarise the input data.
First a short-term median filter with size smoothK is applied to remove fast noise from the time series. If the de-trending method is set to "none", smoothing is applied on globally rescaled time series. The subsequent de-trending can be performed with a long-term median filter with the size biasK {biasMet = "runmed"} or by fitting a polynomial of degree polyDeg {biasMet = "lm"}.
After de-trending, if the global difference between min/max is greater than the threshold the signal is rescaled to the (0,1) range. The final signal is binarised using the binThr threshold
Parameters:
Name | Type | Description | Default |
---|---|---|---|
smooth_k |
int
|
Size of the short-term median smoothing filter. |
3
|
bias_k |
int
|
Size of the long-term de-trending median filter |
51
|
peak_threshold |
float
|
Threshold for rescaling of the de-trended signal. |
0.2
|
binarization_threshold |
float
|
Threshold for binary classification. |
0.1
|
polynomial_degree |
int
|
Sets the degree of the polynomial for lm fitting. |
1
|
bias_method |
str
|
De-trending method, one of ['runmed', 'lm', 'none']. If no id_column is provided, only 'none' is allowed. |
'runmed'
|
**kwargs |
Any
|
Additional keyword arguments. Includes old parameter names for backwards compatibility. - smoothK: Size of the short-term median smoothing filter. - biasK: Size of the long-term de-trending median filter - peakThr: Threshold for rescaling of the de-trended signal. - binThr: Threshold for binary classification. - polyDeg: Sets the degree of the polynomial for lm fitting. - biasMet: De-trending method, one of ['runmed', 'lm', 'none']. |
{}
|
Returns:
Type | Description |
---|---|
DataFrame
|
DataFrame with detrended/smoothed and binarized measurement column. |
Source code in arcos4py/_arcos4py.py
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 |
|
clip_meas(clip_low=0.001, clip_high=0.999)
¶
Clip measurement column to upper and lower quantiles defined in clip_low and clip_high.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
clip_low |
float
|
Lower clipping boundary (quantile). |
0.001
|
clip_high |
float
|
Upper clipping boundary (quantile). |
0.999
|
Returns:
Type | Description |
---|---|
DataFrame
|
Dataframe with in place clipped measurement column. |
Source code in arcos4py/_arcos4py.py
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 |
|
clip_measurements(clip_low=0.001, clip_high=0.999)
¶
Clip measurement column to upper and lower quantiles defined in clip_low and clip_high.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
clip_low |
float
|
Lower clipping boundary (quantile). |
0.001
|
clip_high |
float
|
Upper clipping boundary (quantile). |
0.999
|
Returns:
Type | Description |
---|---|
DataFrame
|
Dataframe with in place clipped measurement column. |
Source code in arcos4py/_arcos4py.py
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 |
|
interpolate_measurements()
¶
Interpolates NaN's in place in measurement column.
Returns:
Type | Description |
---|---|
DataFrame
|
Dataframe with interpolated measurement column. |
Source code in arcos4py/_arcos4py.py
131 132 133 134 135 136 137 138 139 |
|
trackCollev(eps=1, eps_prev=None, min_clustersize=1, n_prev=1, clustering_method='dbscan', linking_method='nearest', min_samples=None, **kwargs)
¶
Detects and tracks collective events in a tracked time-series dataset.
Makes use of the dbscan algorithm, applies this to every timeframe and subsequently connects collective events between frames located within eps distance of each other.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
eps |
float
|
The maximum distance between two samples for one to be considered as in the neighbourhood of the other. This is not a maximum bound on the distances of points within a cluster. |
1
|
eps_prev |
float | None
|
Frame to frame distance, value is used to connect collective events across multiple frames.If "None", same value as eps is used. |
None
|
min_clustersize |
int
|
The minimum size for a cluster to be identified as a collective event |
1
|
n_prev |
int
|
Number of previous frames the tracking algorithm looks back to connect collective events |
1
|
clustering_method |
str
|
Clustering method, one of ['dbscan', 'hdbscan']. |
'dbscan'
|
min_samples |
int | None
|
The number of samples (or total weight) in a neighbourhood for a point to be considered as a core point. This includes the point itself. Only used if clustering_method is 'hdbscan'. If None, min_samples = min_clustersize. |
None
|
linking_method |
str
|
Linking method, one of ['nearest', 'transportation']. |
'nearest'
|
**kwargs |
Any
|
Additional keyword arguments. Includes old parameter names for backwards compatibility. - epsPrev: Frame to frame distance, value is used to connect collective events across multiple frames. - minClsz: The minimum size for a cluster to be identified as a collective event - nPrev: Number of previous frames the tracking algorithm looks back to connect collective events - clusteringMethod: Clustering method, one of ['dbscan', 'hdbscan']. - minSamples: The number of samples (or total weight) in a neighbourhood for a point to be considered as a core point. This includes the point itself. Only used if clustering_method is 'hdbscan'. If None, min_samples = min_clustersize. - linkingMethod: Linking method, one of ['nearest', 'transportation']. |
{}
|
Returns:
Type | Description |
---|---|
DataFrame
|
DataFrame with detected collective events across time. |
Source code in arcos4py/_arcos4py.py
261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 |
|
track_collective_events(eps=1, eps_prev=None, min_clustersize=1, n_prev=1, clustering_method='dbscan', linking_method='nearest', min_samples=None, **kwargs)
¶
Detects and tracks collective events in a tracked time-series dataset.
Makes use of the dbscan algorithm, applies this to every timeframe and subsequently connects collective events between frames located within eps distance of each other.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
eps |
float
|
The maximum distance between two samples for one to be considered as in the neighbourhood of the other. This is not a maximum bound on the distances of points within a cluster. |
1
|
eps_prev |
float | None
|
Frame to frame distance, value is used to connect collective events across multiple frames.If "None", same value as eps is used. |
None
|
min_clustersize |
int
|
The minimum size for a cluster to be identified as a collective event |
1
|
n_prev |
int
|
Number of previous frames the tracking algorithm looks back to connect collective events |
1
|
clustering_method |
str
|
Clustering method, one of ['dbscan', 'hdbscan']. |
'dbscan'
|
min_samples |
int | None
|
The number of samples (or total weight) in a neighbourhood for a point to be considered as a core point. This includes the point itself. Only used if clustering_method is 'hdbscan'. If None, min_samples = min_clustersize. |
None
|
linking_method |
str
|
Linking method, one of ['nearest', 'transportation']. |
'nearest'
|
**kwargs |
Any
|
Additional keyword arguments. Includes old parameter names for backwards compatibility. - epsPrev: Frame to frame distance, value is used to connect collective events across multiple frames. - minClsz: The minimum size for a cluster to be identified as a collective event - nPrev: Number of previous frames the tracking algorithm looks back to connect collective events - clusteringMethod: Clustering method, one of ['dbscan', 'hdbscan']. - minSamples: The number of samples (or total weight) in a neighbourhood for a point to be considered as a core point. This includes the point itself. Only used if clustering_method is 'hdbscan'. If None, min_samples = min_clustersize. - linkingMethod: Linking method, one of ['nearest', 'transportation']. |
{}
|
Returns:
Type | Description |
---|---|
DataFrame
|
DataFrame with detected collective events across time. |
Source code in arcos4py/_arcos4py.py
317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 |
|
plotting
¶
Tools for plotting collective events.
NoodlePlot(df, clid_column='collid', obj_id_column='obj_id', frame_column='frame', posx='x', posy='y', posz=None, **kwargs)
¶
Create Noodle Plot of cell tracks, colored by collective event id.
Attributes:
Name | Type | Description |
---|---|---|
df |
DataFrame
|
DataFrame containing collective events from arcos. |
colev |
str
|
Name of the collective event column in df. |
trackid |
str
|
Name of the track column in df. |
frame |
str
|
Name of the frame column in df. |
posx |
str
|
Name of the X coordinate column in df. |
posy |
str
|
Name of the Y coordinate column in df. |
posz |
str
|
Name of the Z coordinate column in df, or None if no z column. |
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df |
DataFrame
|
DataFrame containing collective events from arcos. |
required |
clid_column |
str
|
Name of the collective event column in df. |
'collid'
|
obj_id_column |
str
|
Name of the track column in df. |
'obj_id'
|
frame_column |
str
|
Name of the frame column in df. |
'frame'
|
posx |
str
|
Name of the X coordinate column in df. |
'x'
|
posy |
str
|
Name of the Y coordinate column in df. |
'y'
|
posz |
str | None
|
Name of the Z coordinate column in df, or None if no z column. |
None
|
**kwargs |
Any
|
Additional keyword arguments for plot. Includes deprecated parameters. - colev (str): Deprecated. Use clid_column instead. - trackid (str): Deprecated. Use obj_id_column instead. - frame (str): Deprecated. Use frame_column instead. |
{}
|
Source code in arcos4py/plotting/_plotting.py
437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 |
|
plot(projection_axis, color_cylce=TAB20)
¶
Create Noodle Plot of cell tracks, colored by collective event id.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
projection_axis |
str
|
Specify with witch coordinate the noodle plot should be drawn. Has to be one of the posx, posy or posz arguments passed in during the class instantiation process. |
required |
color_cylce |
list[str]
|
List of hex color values or string names (i.e. ['red', 'yellow']) used to color collecitve events. Cycles through list. |
TAB20
|
Returns:
Name | Type | Description |
---|---|---|
fig |
Figure
|
Matplotlib figure object for the noodle plot. |
axes |
Axes
|
Matplotlib axes for the nooble plot. |
Source code in arcos4py/plotting/_plotting.py
588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 |
|
dataPlots(data, frame_column='frame', measurement_column='m', obj_id_column='obj_id', **kwargs)
¶
Plot different metrics of input data.
Attributes:
Name | Type | Description |
---|---|---|
data |
Dataframe
|
containing ARCOS data. |
frame_column |
str
|
name of frame column in data. |
measurement_column |
str
|
name of measurement column in data. |
obj_id_column |
str
|
name of track id column. |
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
Dataframe
|
containing ARCOS data. |
required |
frame_column |
str
|
name of frame column in data. |
'frame'
|
measurement_column |
str
|
name of measurement column in data. |
'm'
|
obj_id_column |
str
|
name of track id column. |
'obj_id'
|
**kwargs |
Any
|
Additional keyword arguments. Includes deprecated parameters. - id (str): Deprecated. Use obj_id_column instead. - frame (str): Deprecated. Use frame_column instead. - measurement (str): Deprecated. Use measurement_column instead. |
{}
|
Source code in arcos4py/plotting/_plotting.py
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
|
density_plot(*args, **kwargs)
¶
Density plot of measurement.
Uses Seaborn distplot to plot measurement density.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
*args |
Any
|
arguments passed on to seaborn histplot function. |
()
|
**kwargs |
Any
|
keyword arguments passed on to seaborn histplot function. |
{}
|
Returns:
Name | Type | Description |
---|---|---|
FacetGrid |
FacetGrid
|
Seaborn FacetGrid of density density plot. |
Source code in arcos4py/plotting/_plotting.py
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 |
|
histogram(bins='auto', *args, **kwargs)
¶
Histogram of tracklenght.
Uses seaborn histplot function to plot tracklenght histogram.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
bins |
str
|
number or width of bins in histogram |
'auto'
|
*args |
Any
|
arguments passed on to seaborn histplot function. |
()
|
**kwargs |
Any
|
keyword arguments passed on to seaborn histplot function. |
{}
|
Returns:
Name | Type | Description |
---|---|---|
AxesSubplot |
Axes
|
Matplotlib AxesSubplot of histogram. |
Source code in arcos4py/plotting/_plotting.py
187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 |
|
position_t_plot(position_columns={'x'}, n=20, **kwargs)
¶
Plots X and Y over T to visualize tracklength.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
position_columns |
set
|
containing names of position columns in data. |
{'x'}
|
n |
int
|
number of samples to plot. |
20
|
**kwargs |
Any
|
Additional keyword arguments. Includes deprecated parameters. - posCol (set): Deprecated. Use position_columns instead. |
{}
|
Returns:
Name | Type | Description |
---|---|---|
fig |
Figure
|
Matplotlib figure object of density plot. |
axes |
Axes
|
Matplotlib axes of density plot. |
Source code in arcos4py/plotting/_plotting.py
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
|
plotOriginalDetrended(data, frame_column='frame', measurement_column='m', detrended_column='m_detrended', obj_id_column='obj_id', seed=42, **kwargs)
¶
Plot original and detrended data.
Attributes:
Name | Type | Description |
---|---|---|
data |
DataFrame
|
containing ARCOS data. |
frame_column |
str
|
name of frame column in data. |
measurement_column |
str
|
name of measurement column in data. |
detrended_column |
str
|
name of detrended column in data. |
obj_id_column |
str
|
name of track id column. |
seed |
int
|
seed for random number generator. |
Methods:
Name | Description |
---|---|
plot_detrended |
plot detrended data. |
plot_original |
plot original data. |
plot_original_and_detrended |
plot original and detrended data. |
Source code in arcos4py/plotting/_plotting.py
227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 |
|
plot_detrended(n_samples=25, subplots=(5, 5), plotsize=(20, 10), add_binary_segments=False)
¶
Plots detrended data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
n_samples |
int
|
number of samples to plot. |
25
|
subplots |
tuple
|
number of subplots in x and y direction. |
(5, 5)
|
plotsize |
tuple
|
size of the plot. |
(20, 10)
|
add_binary_segments |
bool
|
if True, binary segments are added to the plot. |
False
|
Returns:
Name | Type | Description |
---|---|---|
fig |
Figure
|
Matplotlib figure object of plot. |
axes |
Axes
|
Matplotlib axes of plot. |
Source code in arcos4py/plotting/_plotting.py
304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 |
|
plot_original(n_samples=25, subplots=(5, 5), plotsize=(20, 10), add_binary_segments=False)
¶
Plots original data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
n_samples |
int
|
number of samples to plot. |
25
|
subplots |
tuple
|
number of subplots in x and y direction. |
(5, 5)
|
plotsize |
tuple
|
size of the plot. |
(20, 10)
|
add_binary_segments |
bool
|
if True, binary segments are added to the plot. |
False
|
Returns:
Name | Type | Description |
---|---|---|
fig |
Figure
|
Matplotlib figure object of plot. |
axes |
Axes
|
Matplotlib axes of plot. |
Source code in arcos4py/plotting/_plotting.py
328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 |
|
plot_original_and_detrended(n_samples=25, subplots=(5, 5), plotsize=(20, 10), add_binary_segments=False)
¶
Plots original and detrended data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
n_samples |
int
|
number of samples to plot. |
25
|
subplots |
tuple
|
number of subplots in x and y direction. |
(5, 5)
|
plotsize |
tuple
|
size of the plot. |
(20, 10)
|
add_binary_segments |
bool
|
if True, binary segments are added to the plot. |
False
|
Returns:
Name | Type | Description |
---|---|---|
fig |
Figure
|
Matplotlib figure object of plot. |
axes |
Axes
|
Matplotlib axes of plot. |
Source code in arcos4py/plotting/_plotting.py
358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 |
|
statsPlots(data)
¶
Plot data generated by the stats module.
Attributes:
Name | Type | Description |
---|---|---|
data |
DataFrame
|
containing ARCOS stats data. |
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
DataFrame
|
containing ARCOS stats data. |
required |
Source code in arcos4py/plotting/_plotting.py
396 397 398 399 400 401 402 |
|
plot_events_duration(total_size, duration, point_size=40, *args, **kwargs)
¶
Scatterplot of collective event duration.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
total_size |
str
|
name of total size column. |
required |
duration |
str
|
, name of column with collective event duration. |
required |
point_size |
int
|
scatterplot point size. |
40
|
*args |
Any
|
Arguments passed on to seaborn scatterplot function. |
()
|
**kwargs |
Any
|
Keyword arguments passed on to seaborn scatterplot function. |
{}
|
Returns:
Name | Type | Description |
---|---|---|
Axes |
Axes
|
Matplotlib Axes object of scatterplot |
Source code in arcos4py/plotting/_plotting.py
404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 |
|
tools
¶
Tools for detecting collective events.
DataFrameTracker(linker, position_columns=['x'], frame_column='frame', obj_id_column=None, binarized_measurement_column=None, clid_column='clTrackID', **kwargs)
¶
Bases: BaseTracker
Tracker class for data frames that works in conjunction with the Linker class.
Methods:
Name | Description |
---|---|
track_iteration |
pd.DataFrame): Tracks events in a single frame. |
track |
pd.DataFrame) -> Generator: Main method for tracking events through the dataframe. Yields the tracked data frame for each iteration. |
Parameters:
Name | Type | Description | Default |
---|---|---|---|
linker |
Linker
|
The Linker object used for linking events. |
required |
position_columns |
list[str]
|
List of strings representing the coordinate columns. |
['x']
|
frame_column |
str
|
String representing the frame/timepoint column in the dataframe. |
'frame'
|
obj_id_column |
str | None
|
String representing the ID column, or None if not present. Defaults to None. |
None
|
binarized_measurement_column |
str | None
|
String representing the binary measurement column, or None if not present. Defaults to None. |
None
|
clid_column |
str
|
String representing the collision track ID column. Defaults to 'clTrackID'. |
'clTrackID'
|
kwargs |
Any
|
Additional keyword arguments. Includes deprecated parameters for backwards compatibility. - coordinates_column: Deprecated parameter for position_columns. Use position_columns instead. - collid_column: Deprecated parameter, use clid_column instead. - id_column: Deprecated parameter, use obj_id_column instead. - bin_meas_column: Deprecated parameter, use binarized_measurement_column instead. |
{}
|
Source code in arcos4py/tools/_detect_events.py
788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 |
|
track(x)
¶
Main method for tracking events through the dataframe. Yields the tracked dataframe for each iteration.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x |
DataFrame
|
Dataframe to track. |
required |
Yields:
Name | Type | Description |
---|---|---|
Generator |
Generator
|
Tracked dataframe. |
Source code in arcos4py/tools/_detect_events.py
936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 |
|
track_iteration(x)
¶
Tracks events in a single frame. Returns dataframe with event ids.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x |
DataFrame
|
Dataframe to track. |
required |
Returns:
Type | Description |
---|---|
DataFrame
|
pd.DataFrame: Dataframe with event ids. |
Source code in arcos4py/tools/_detect_events.py
906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 |
|
ImageTracker(linker, downsample=1)
¶
Bases: BaseTracker
Tracker class for image data that works in conjunction with the Linker class.
Methods:
Name | Description |
---|---|
track_iteration |
np.ndarray): Tracks events in a single frame. Returns the tracked labels. |
track |
np.ndarray, dims: str = "TXY") -> Generator: Main method for tracking events through the image series. Yields the tracked image for each iteration. |
Parameters:
Name | Type | Description | Default |
---|---|---|---|
linker |
Linker
|
The Linker object used for linking events. |
required |
downsample |
int
|
Downsampling factor for the images. Defaults to 1, meaning no downsampling. |
1
|
Source code in arcos4py/tools/_detect_events.py
965 966 967 968 969 970 971 972 973 |
|
track(x, dims='TXY')
¶
Method for tracking events through the image series. Yields the tracked image for each iteration.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x |
ndarray
|
Image to track. |
required |
dims |
str
|
String of dimensions in order. Default is "TXY". Possible values are "T", "X", "Y", and "Z". |
'TXY'
|
Returns:
Name | Type | Description |
---|---|---|
Generator |
Generator
|
Generator that yields the tracked image for each iteration. |
Source code in arcos4py/tools/_detect_events.py
1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 |
|
track_iteration(x)
¶
Tracks events in a single frame. Returns the tracked labels.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x |
ndarray
|
Image to track. |
required |
Returns:
Type | Description |
---|---|
ndarray
|
np.ndarray: Tracked labels. |
Source code in arcos4py/tools/_detect_events.py
1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 |
|
Linker(eps=1, eps_prev=None, min_clustersize=1, min_samples=None, clustering_method='dbscan', linking_method='nearest', predictor=True, n_prev=1, cost_threshold=0, reg=1, reg_m=10, n_jobs=1, **kwargs)
¶
Linker class for linking collective events across multiple frames.
Attributes:
Name | Type | Description |
---|---|---|
event_ids |
ndarray
|
Array to store event IDs, for each coordinate in the current frame. |
Methods:
Name | Description |
---|---|
link |
Links clusters from the previous frame to the current frame. |
Parameters:
Name | Type | Description | Default |
---|---|---|---|
eps |
float
|
The maximum distance between two samples for one to be considered as in the neighbourhood of the other. |
1
|
eps_prev |
float | None
|
Frame to frame distance, value is used to connect collective events across multiple frames. If "None", same value as eps is used. |
None
|
min_clustersize |
int
|
The minimum size for a cluster to be identified as a collective event. |
1
|
min_samples |
int | None
|
The number of samples (or total weight) in a neighbourhood for a point to be considered as a core point. This includes the point itself. Only used if clusteringMethod is 'hdbscan'. If None, minSamples = minClsz. |
None
|
clustering_method |
str | Callable
|
The clustering method to be used. One of ['dbscan', 'hdbscan']
or a callable that takes a 2d array of coordinates and returns a list of cluster labels.
Arguments |
'dbscan'
|
linking_method |
str
|
The linking method to be used. |
'nearest'
|
predictor |
bool | Callable
|
The predictor method to be used. |
True
|
n_prev |
int
|
Number of previous frames the tracking algorithm looks back to connect collective events. |
1
|
n_jobs |
int
|
Number of jobs to run in parallel (only for clustering algorithm). |
1
|
cost_threshold |
int
|
Threshold for filtering low-probability matches (only for transportation linking). |
0
|
reg |
float
|
Entropy regularization parameter for unbalanced OT algorithm (only for transportation linking). |
1
|
reg_m |
float
|
Marginal relaxation parameter for unbalanced OT (only for transportation linking). |
10
|
kwargs |
Any
|
Additional keyword arguments. Includes deprecated parameters for backwards compatibility. - epsPrev: Deprecated parameter for eps_prev. Use eps_prev instead. - minClSz: Deprecated parameter for min_clustersize. Use min_clustersize instead. - minSamples: Deprecated parameter for min_samples. Use min_samples instead. - clusteringMethod: Deprecated parameter for clustering_method. Use clustering_method instead. - nPrev: Deprecated parameter for n_prev. Use n_prev instead. - nJobs: Deprecated parameter for n_jobs. Use n_jobs instead. |
{}
|
Source code in arcos4py/tools/_detect_events.py
509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 |
|
link(input_coordinates)
¶
Links clusters from the previous frame to the current frame.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input_coordinates |
ndarray
|
The coordinates of the current frame. |
required |
Returns:
Type | Description |
---|---|
None
|
None, modifies internal state with new linked clusters. New event ids are stored in self.event_ids. |
Source code in arcos4py/tools/_detect_events.py
689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 |
|
binData(smooth_k=3, bias_k=51, peak_threshold=0.2, binarization_threshold=0.1, polynomial_degree=1, bias_method='runmed', n_jobs=1, **kwargs)
¶
Bases: detrender
Smooth, de-trend, and binarise the input data.
First a short-term median filter with size smoothK is applied to remove fast noise from the time series. If the de-trending method is set to "none", smoothing is applied on globally rescaled time series. The subsequent de-trending can be performed with a long-term median filter with the size biasK {biasMet = "runmed"} or by fitting a polynomial of degree polyDeg {biasMet = "lm"}.
After de-trending, if the global difference between min/max is greater than the threshold the signal is rescaled to the (0,1) range. The final signal is binarised using the binThr threshold.
Attributes:
Name | Type | Description |
---|---|---|
smoothK |
int
|
Size of the short-term median smoothing filter. |
biasK |
int
|
Size of the long-term de-trending median filter. |
peakThr |
float
|
Threshold for rescaling of the de-trended signal. |
binThr |
float
|
Threshold for binarizing the de-trended signal. |
polyDeg |
int
|
Sets the degree of the polynomial for lm fitting. |
biasMet |
str
|
De-trending method, one of ['runmed', 'lm', 'none']. |
Parameters:
Name | Type | Description | Default |
---|---|---|---|
smooth_k |
int
|
Size of the short-term median smoothing filter. |
3
|
bias_k |
int
|
Size of the long-term de-trending median filter. |
51
|
peak_threshold |
float
|
Threshold for rescaling of the de-trended signal. |
0.2
|
binarization_threshold |
float
|
Threshold for binarizing the de-trended signal. |
0.1
|
polynomial_degree |
int
|
Sets the degree of the polynomial for lm fitting. |
1
|
bias_method |
str
|
De-trending method, one of ['runmed', 'lm', 'none']. |
'runmed'
|
n_jobs |
int
|
Number of jobs to run in parallel. |
1
|
Source code in arcos4py/tools/_binarize_detrend.py
194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 |
|
run(x, group_column, measurement_column, frame_column, **kwargs)
¶
Runs binarization and detrending.
If the bias_method is 'none', first it rescales the data to between [0,1], then local smoothing is applied to the measurement by groups, followed by binarization.
If bias_method is one of ['lm', 'runmed'], first the data is detrended locally with a median filter and then detrended globally, for 'lm' with a linear model and for 'runmed' with a median filter. Followed by binarization of the data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x |
DataFrame
|
The time-series data for smoothing, detrending and binarization. |
required |
group_column |
str | None
|
Object id column in x. Detrending and rescaling is performed on a per-object basis. If None, no detrending is performed, only rescaling and bias method is ignored. |
required |
measurement_column |
str
|
Measurement column in x on which detrending and rescaling is performed. |
required |
frame_column |
str
|
Frame column in Time-series data. Used for sorting. |
required |
**kwargs |
Any
|
Additional keyword arguments. Includes old parameters for backwards compatibility. - GroupCol (str): Object id column in x. Detrending and rescaling is performed on a per-object basis. - colMeas (str): Measurement column in x on which detrending and rescaling is performed. - colFrame (str): Frame column in Time-series data. Used for sorting. |
{}
|
Returns:
Name | Type | Description |
---|---|---|
DataFrame |
DataFrame
|
Dataframe containing binarized data, rescaled data and the original columns. |
Source code in arcos4py/tools/_binarize_detrend.py
230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 |
|
calcCollevStats()
¶
Class to calculate statistics of collective events.
Source code in arcos4py/tools/_stats.py
337 338 339 340 341 342 343 |
|
calculate(data, frame_column, collid_column, obj_id_column, posCol=None)
¶
Calculate summary statistics for collective events based on the entire duration of each event.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
DataFrame
|
Input data containing information on the collective events. |
required |
frame_column |
str
|
The column name representing the frame numbers. |
required |
collid_column |
str
|
The column name representing the collective event IDs. |
required |
obj_id_column |
str
|
The column name representing the object IDs. Defaults to None. |
required |
posCol |
list
|
List of column names representing the position coordinates. Defaults to None. |
None
|
Returns:
Type | Description |
---|---|
DataFrame
|
pd.DataFrame: A DataFrame containing the summary statistics of the collective events. |
Deprecated
Source code in arcos4py/tools/_stats.py
345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 |
|
clipMeas(data)
¶
Clip input array.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
ndarray
|
To be clipped. |
required |
Source code in arcos4py/tools/_cleandata.py
54 55 56 57 58 59 60 |
|
clip(clip_low=0.001, clip_high=0.999)
¶
Clip input array to upper and lower quantiles defined in clip_low and clip_high.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
clip_low |
float
|
Lower clipping boundary (quantile). |
0.001
|
clip_high |
float
|
Upper clipping boundry (quantille). |
0.999
|
Returns:
Type | Description |
---|---|
ndarray
|
np.ndarray (np.ndarray): A clipped array of the input data. |
Source code in arcos4py/tools/_cleandata.py
80 81 82 83 84 85 86 87 88 89 90 91 92 |
|
detectCollev(input_data, eps=1, epsPrev=None, minClSz=1, nPrev=1, posCols=['x'], frame_column='time', id_column=None, bin_meas_column='meas', clid_column='clTrackID', dims='TXY', method='dbscan', min_samples=None, linkingMethod='nearest', n_jobs=1, predictor=False, show_progress=True)
¶
Class to detect collective events.
Attributes:
Name | Type | Description |
---|---|---|
input_data |
Union[DataFrame, ndarray]
|
The input data to track. |
eps |
float
|
Maximum distance for clustering, default is 1. |
epsPrev |
Union[float, None]
|
Maximum distance for linking previous clusters, if None, eps is used. Default is None. |
minClSz |
int
|
Minimum cluster size. Default is 3. |
nPrev |
int
|
Number of previous frames to consider. Default is 1. |
posCols |
list
|
List of column names for the position columns. Default is ["x"]. |
frame_column |
str
|
Name of the column containing the frame number. Default is 'time'. |
id_column |
Union[str, None]
|
Name of the column containing the id. Default is None. |
bin_meas_column |
Union[str, None]
|
Name of the column containing the binary measurement. Default is 'meas'. |
clid_column |
str
|
Name of the column containing the cluster id. Default is 'clTrackID'. |
dims |
str
|
String of dimensions in order, such as. Default is "TXY". Possible values are "T", "X", "Y", "Z". |
method |
str
|
The method used for clustering, one of [dbscan, hdbscan]. Default is "dbscan". |
min_samples |
int | None
|
The number of samples (or total weight) in a neighbourhood for a point to be considered as a core point. This includes the point itself. Only used if clusteringMethod is 'hdbscan'. If None, minSamples = minClsz. |
linkingMethod |
str
|
The method used for linking. Default is 'nearest'. |
n_jobs |
int
|
Number of jobs to run in parallel. Default is 1. |
predictor |
bool | Callable
|
Whether or not to use a predictor. Default is False. True uses the default predictor. A callable can be passed to use a custom predictor. See default predictor method for details. |
show_progress |
bool
|
Whether or not to show progress bar. Default is True. |
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input_data |
DataFrame
|
Input data to be processed. Must contain a binarized measurement column. |
required |
eps |
float
|
The maximum distance between two samples for one to be considered as in the neighbourhood of the other. This is not a maximum bound on the distances of points within a cluster. |
1
|
epsPrev |
float | None
|
Frame to frame distance, value is used to connect collective events across multiple frames.If "None", same value as eps is used. |
None
|
minClSz |
int
|
Minimum size for a cluster to be identified as a collective event. |
1
|
nPrev |
int
|
Number of previous frames the tracking algorithm looks back to connect collective events. |
1
|
posCols |
list
|
List of position columns contained in the data. Must at least contain one. |
['x']
|
frame_column |
str
|
Indicating the frame column in input_data. |
'time'
|
id_column |
str | None
|
Indicating the track id/id column in input_data, optional. |
None
|
bin_meas_column |
str
|
Indicating the bin_meas_column in input_data or None. |
'meas'
|
clid_column |
str
|
Indicating the column name containing the ids of collective events. |
'clTrackID'
|
dims |
str
|
String of dimensions in order, used if input_data is a numpy array. Default is "TXY". Possible values are "T", "X", "Y", "Z". |
'TXY'
|
method |
str
|
The method used for clustering, one of [dbscan, hdbscan]. Default is "dbscan". |
'dbscan'
|
min_samples |
int | None
|
The number of samples (or total weight) in a neighbourhood for a point to be considered as a core point. This includes the point itself. Only used if clusteringMethod is 'hdbscan'. If None, minSamples = minClsz. |
None
|
linkingMethod |
str
|
The method used for linking. Default is 'nearest'. |
'nearest'
|
n_jobs |
int
|
Number of paralell workers to spawn, -1 uses all available cpus. |
1
|
predictor |
bool | Callable
|
Whether or not to use a predictor. Default is False. True uses the default predictor. A callable can be passed to use a custom predictor. See default predictor method for details. |
False
|
show_progress |
bool
|
Whether or not to show progress bar. Default is True. |
True
|
Source code in arcos4py/tools/_detect_events.py
1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 |
|
run(copy=True)
¶
Runs the collective event detection algorithm.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
copy |
bool
|
Whether or not to copy the input data. Default is True. |
True
|
Returns:
Name | Type | Description |
---|---|---|
DataFrame |
DataFrame
|
Input data with added collective event ids. |
Source code in arcos4py/tools/_detect_events.py
1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 |
|
filterCollev(data, frame_column='time', clid_column='collid', obj_id_column='trackID', **kwargs)
¶
Select Collective events that last longer than coll_duration and have a larger total size than coll_total_size.
Attributes:
Name | Type | Description |
---|---|---|
data |
Dataframe
|
With detected collective events. |
frame_column |
str
|
Indicating the frame column in data. |
collid_column |
str
|
Indicating the collective event id column in data. |
obj_id_column |
str
|
Inidicating the object identifier column such as cell track id. |
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
Dataframe
|
With detected collective events. |
required |
frame_column |
str
|
Indicating the frame column in data. |
'time'
|
clid_column |
str
|
Indicating the collective event id column in data. |
'collid'
|
obj_id_column |
str
|
Inidicating the object identifier column such as cell track id. |
'trackID'
|
**kwargs |
Any
|
Additional keyword arguments. Includes deprecated parameters. - collid_column (str): Deprecated. Use clid_column instead. |
{}
|
Source code in arcos4py/tools/_filter_events.py
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
|
filter(min_duration=9, min_total_size=10, **kwargs)
¶
Filter collective events.
Method to filter collective events according to the parameters specified in the object instance.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
min_duration |
int
|
Minimal duration of collective events to be selected. |
9
|
min_total_size |
int
|
Minimal total size of collective events to be selected. |
10
|
**kwargs |
Any
|
Additional keyword arguments. Includes deprecated parameters. - coll_duration (int): Deprecated. Use min_duration instead. - coll_total_size (int): Deprecated. Use min_total_size instead. |
{}
|
Returns:
Type | Description |
---|---|
DataFrame
|
Returns pandas dataframe containing filtered collective events |
Source code in arcos4py/tools/_filter_events.py
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
|
interpolation(data)
¶
Interpolate nan values in a numpy array.
Attributes:
Name | Type | Description |
---|---|---|
data |
DataFrame
|
Where NaN should be replaced with interpolated values. |
Uses pandas.interpolate with liner interpolation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
DataFrame
|
Where NaN should be replaced with interpolated values. |
required |
Source code in arcos4py/tools/_cleandata.py
30 31 32 33 34 35 36 37 38 |
|
interpolate()
¶
Interpolate nan and missing values.
Returns:
Name | Type | Description |
---|---|---|
DataFrame |
DataFrame
|
Interpolated input data. |
Source code in arcos4py/tools/_cleandata.py
40 41 42 43 44 45 46 47 48 |
|
calculate_statistics(data, frame_column='frame', clid_column='collid', obj_id_column=None, position_columns=None, **kwargs)
¶
Calculate summary statistics for collective events based on the entire duration of each event.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
DataFrame
|
Input data containing information on the collective events. |
required |
frame_column |
str
|
The column name representing the frame numbers. |
'frame'
|
clid_column |
str
|
The column name representing the collective event IDs. |
'collid'
|
obj_id_column |
str
|
The column name representing the object IDs. Defaults to None. |
None
|
position_columns |
List[str]
|
List of column names representing the position coordinates. Defaults to None. |
None
|
**kwargs |
Any
|
Additional keyword arguments. Includes deprecated parameters. - collid_column (str): Deprecated. Use clid_column instead. - pos_columns (List[str], optional): Deprecated. Use position_columns instead. |
{}
|
Returns:
Type | Description |
---|---|
DataFrame
|
pd.DataFrame: A DataFrame containing the summary statistics of the collective events. |
Statistics Calculated
- collid: The unique ID representing each collective event.
- duration: The duration of each event, calculated as the difference between the maximum and minimum frame values plus one.
- first_timepoint, last_timepoint: The first and last frames in which each event occurs.
- total_size: The total number of unique objects involved in each event (calculated if obj_id_column is provided).
- min_size, max_size: The minimum and maximum size of each event, defined as the number of objects in the event's smallest and largest frames, respectively.
- first_frame_centroid_x, first_frame_centroid_y, last_frame_centroid_x, last_frame_centroid_y: The x and y coordinates of the centroid of all objects in the first and last frames of each event (calculated if posCol is provided).
- centroid_speed: The speed of the centroid, calculated as the distance between the first and last frame centroids divided by the duration (calculated if posCol is provided).
- direction: The direction of motion of the centroid, calculated as the arctangent of the change in y divided the change in x (calculated if posCol is provided).
- first_frame_spatial_extent, last_frame_spatial_extent: The maximum distance between any pair of objects in the first and last frames (calculated if posCol is provided).
- first_frame_convex_hull_area, last_frame_convex_hull_area: The areas of the convex hulls enclosing all objects in the first and last frames (calculated if posCol is provided).
- size_variability: The standard deviation of the event size over all frames, providing a measure of the variability in the size of the event over time (calculated if obj_id_column is provided).
Source code in arcos4py/tools/_stats.py
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 |
|
calculate_statistics_per_frame(data, frame_column='frame', clid_column='collid', position_columns=None, **kwargs)
¶
Calculate summary statistics for collective events based on the entire duration of each event.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
DataFrame
|
Input data containing information on the collective events. |
required |
frame_column |
str
|
The column name representing the frame numbers. |
'frame'
|
clid_column |
str
|
The column name representing the collective event IDs. |
'collid'
|
position_columns |
List[str]
|
List of column names representing the position coordinates. Defaults to None. |
None
|
**kwargs |
Any
|
Additional keyword arguments. Includes deprecated parameters. - collid_column (str): Deprecated. Use clid_column instead. - pos_columns (List[str], optional): Deprecated. Use position_columns instead. |
{}
|
Returns:
Type | Description |
---|---|
DataFrame
|
pd.DataFrame: A DataFrame containing the summary statistics of the collective events. |
Statistics Calculated
- collid: The unique ID representing each collective event.
- frame: The frame number.
- size: The number of objects in the collective event
- centroid_x, centroid_y: The x and y coordinates of the centroid of all objects in the collective event (calculated if pos_columns is provided).
- spatial_extent: The maximum distance between any pair of objects in the collective event (calculated if pos_columns is provided).
- convex_hull_area: The area of the convex hull enclosing all objects in the collective event (calculated if pos_columns is provided).
- direction: The direction of motion of the centroid, calculated as the arctangent of the change in y divided the change in x (calculated if pos_columns is provided).
- centroid_speed: The speed of the centroid, calculated as the norm of the change in x and y divided by the duration (calculated if pos_columns is provided).
Source code in arcos4py/tools/_stats.py
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
|
estimate_eps(data, method='kneepoint', position_columns=['x,y'], frame_column='t', n_neighbors=5, plot=True, plt_size=(5, 5), max_samples=50000, **kwargs)
¶
Estimates eps parameter in DBSCAN.
Estimates the eps parameter for the DBSCAN clustering method, as used by ARCOS, by calculating the nearest neighbour distances for each point in the data. N_neighbours should be chosen to match the minimum point size in DBSCAN or the minimum clustersize in detect_events respectively. The method argument determines how the eps parameter is estimated. 'kneepoint' estimates the knee of the nearest neighbour distribution. 'mean' and 'median' return (by default) 1.5 times the mean or median of the nearest neighbour distances respectively.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
DataFrame
|
DataFrame containing the data. |
required |
method |
str
|
Method to use for estimating eps. Defaults to 'kneepoint'. Can be one of ['kneepoint', 'mean', 'median'].'kneepoint' estimates the knee of the nearest neighbour distribution to to estimate eps. 'mean' and 'median' use the 1.5 times the mean or median of the nearest neighbour distances respectively. |
'kneepoint'
|
position_columns |
list[str]
|
List of column names containing the position data. |
['x,y']
|
frame_column |
str
|
Name of the column containing the frame number. Defaults to 't'. |
't'
|
n_neighbors |
int
|
Number of nearest neighbours to consider. Defaults to 5. |
5
|
plot |
bool
|
Whether to plot the results. Defaults to True. |
True
|
plt_size |
tuple[int, int]
|
Size of the plot. Defaults to (5, 5). |
(5, 5)
|
kwargs |
Any
|
Keyword arguments for the method. Modify behaviour of respecitve method. For kneepoint: [S online, curve, direction, interp_method,polynomial_degree; For mean: [mean_multiplier] For median [median_multiplier] |
{}
|
Returns:
Name | Type | Description |
---|---|---|
Eps |
float
|
eps parameter for DBSCAN. |
Source code in arcos4py/tools/_detect_events.py
1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 |
|
remove_image_background(image, filter_type='gaussian', size=(10, 1, 1), dims='TXY', crop_time_axis=False)
¶
Removes background from images. Assumes axis order (t, y, x) for 2d images and (t, z, y, x) for 3d images.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
image |
ndarray
|
Image to remove background from. |
required |
filter_type |
Union[str, function]
|
Filter to use to remove background. Can be one of ['median', 'gaussian']. |
'gaussian'
|
size |
(int, Tuple)
|
Size of filter to use. For median filter, this is the size of the window. For gaussian filter, this is the standard deviation. If a single int is passed in, it is assumed to be the same for all dimensions. If a tuple is passed in, it is assumed to correspond to the size of the filter in each dimension. Default is (10, 1, 1). |
(10, 1, 1)
|
dims |
str
|
Dimensions to apply filter over. Can be one of ['TXY', 'TZXY']. Default is 'TXY'. |
'TXY'
|
crop_time_axis |
bool
|
Whether to crop the time axis. Default is True. |
False
|
Returns (np.ndarray): Image with background removed. Along the first axis (t) half of the filter size is removed from the beginning and end respectively.
Source code in arcos4py/tools/_cleandata.py
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
|
track_events_dataframe(X, position_columns, frame_column, id_column, binarized_measurement_column=None, clid_column='collid', eps=1.0, eps_prev=None, min_clustersize=3, min_samples=None, clustering_method='dbscan', linking_method='nearest', n_prev=1, predictor=False, n_jobs=1, show_progress=True, **kwargs)
¶
Function to track collective events in a dataframe.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
X |
DataFrame
|
The input dataframe containing the data to track. |
required |
position_columns |
List[str]
|
The names of the columns representing coordinates. |
required |
frame_column |
str
|
The name of the column containing frame ids. |
required |
id_column |
str | None
|
The name of the column representing IDs. None if no such column. |
required |
binarized_measurement_column |
str | None
|
The name of the column representing binarized measurements, if None all measurements are used. |
None
|
clid_column |
str
|
The name of the output column representing collective events, will be generated. |
'collid'
|
eps |
float
|
Maximum distance for clustering, default is 1. |
1.0
|
eps_prev |
float | None
|
Maximum distance for linking previous clusters, if None, eps is used. Default is None. |
None
|
min_clustersize |
int
|
Minimum cluster size. Default is 3. |
3
|
min_samples |
int
|
The number of samples (or total weight) in a neighbourhood for a point to be considered as a core point. This includes the point itself. Only used if clusteringMethod is 'hdbscan'. If None, minSamples = minClsz. |
None
|
clustering_method |
str
|
The method used for clustering, one of [dbscan, hdbscan]. Default is "dbscan". |
'dbscan'
|
linking_method |
str
|
The method used for linking, one of ['nearest', 'transportsolver']. Default is 'nearest'. |
'nearest'
|
n_prev |
int
|
Number of previous frames to consider. Default is 1. |
1
|
predictor |
bool | Callable
|
Whether or not to use a predictor. Default is False. True uses the default predictor. A callable can be passed to use a custom predictor. See default predictor method for details. |
False
|
n_jobs |
int
|
Number of jobs to run in parallel. Default is 1. |
1
|
show_progress |
bool
|
Whether or not to show progress bar. Default is True. |
True
|
**kwargs |
Any
|
Additional keyword arguments. Includes deprecated parameters for backwards compatibility. - epsPrev: Deprecated parameter for eps_prev. Use eps_prev instead. - minClSz: Deprecated parameter for min_clustersize. Use min_clustersize instead. - minSamples: Deprecated parameter for min_samples. Use min_samples instead. - clusteringMethod: Deprecated parameter for clustering_method. Use clustering_method instead. - linkingMethod: Deprecated parameter for linking_method. Use linking_method instead. - nPrev: Deprecated parameter for n_prev. Use n_prev instead. - nJobs: Deprecated parameter for n_jobs. Use n_jobs instead. - showProgress: Deprecated parameter for show_progress. Use show_progress instead. |
{}
|
Returns:
Type | Description |
---|---|
DataFrame
|
pd.DataFrame: Dataframe with tracked events. |
Source code in arcos4py/tools/_detect_events.py
1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 |
|
track_events_image(X, eps=1, eps_prev=None, min_clustersize=1, min_samples=None, clustering_method='dbscan', n_prev=1, predictor=False, linking_method='nearest', reg=1, reg_m=10, cost_threshold=0, dims='TXY', downsample=1, n_jobs=1, show_progress=True, **kwargs)
¶
Function to track events in an image using specified linking and clustering methods.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
X |
ndarray
|
The input array containing the images to track. |
required |
eps |
float
|
Distance for clustering. Default is 1. |
1
|
eps_prev |
float | None
|
Maximum distance for linking previous clusters, if None, eps is used. Default is None. |
None
|
min_clustersize |
int
|
Minimum cluster size. Default is 1. |
1
|
min_samples |
int | None
|
The number of samples (or total weight) in a neighbourhood for a point to be considered as a core point. This includes the point itself. Only used if clusteringMethod is 'hdbscan'. If None, minSamples = minClsz. |
None
|
clustering_method |
str
|
The method used for clustering, one of [dbscan, hdbscan]. Default is "dbscan". |
'dbscan'
|
n_prev |
int
|
Number of previous frames to consider. Default is 1. |
1
|
predictor |
bool | Callable
|
Whether or not to use a predictor. Default is False. True uses the default predictor. A callable can be passed to use a custom predictor. See default predictor method for details. |
False
|
linking_method |
str
|
The method used for linking. Default is 'nearest'. |
'nearest'
|
reg |
float
|
Entropy regularization parameter for unbalanced OT algorithm (only for transportation linking). |
1
|
reg_m |
float
|
Marginal relaxation parameter for unbalanced OT (only for transportation linking). |
10
|
cost_threshold |
float
|
Threshold for filtering low-probability matches (only for transportation linking). |
0
|
dims |
str
|
String of dimensions in order, such as. Default is "TXY". Possible values are "T", "X", "Y", "Z". |
'TXY'
|
downsample |
int
|
Factor by which to downsample the image. Default is 1. |
1
|
n_jobs |
int
|
Number of jobs to run in parallel. Default is 1. |
1
|
show_progress |
bool
|
Whether or not to show progress bar. Default is True. |
True
|
**kwargs |
Any
|
Additional keyword arguments. Includes deprecated parameters for backwards compatibility. - epsPrev: Deprecated parameter for eps_prev. Use eps_prev instead. - minClSz: Deprecated parameter for min_clustersize. Use min_clustersize instead. - minSamples: Deprecated parameter for min_samples. Use min_samples instead. - clusteringMethod: Deprecated parameter for clustering_method. Use clustering_method instead. - linkingMethod: Deprecated parameter for linking_method. Use linking_method instead. - nPrev: Deprecated parameter for n_prev. Use n_prev instead. - nJobs: Deprecated parameter for n_jobs. Use n_jobs instead. - showProgress: Deprecated parameter for show_progress. Use show_progress instead. |
{}
|
Returns:
Type | Description |
---|---|
ndarray
|
np.ndarray: Array of images with tracked events. |
Source code in arcos4py/tools/_detect_events.py
1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 |
|
validation
¶
Tools for validating detected collective events.
bootstrap_arcos(df, position_columns=['x'], frame_column='frame', obj_id_column='obj_id', measurement_column='m', method='shuffle_tracks', smooth_k=3, bias_k=51, peak_threshold=0.2, binarization_threshold=0.1, polynomial_degree=1, bias_method='runmed', eps=2, eps_prev=None, min_clustersize=1, n_prev=1, min_duration=1, min_total_size=1, stats_metric=['total_size', 'duration'], pval_alternative='greater', finite_correction=True, n=100, seed=42, allow_duplicates=False, max_tries=100, show_progress=True, verbose=False, parallel_processing=True, plot=True, **kwargs)
¶
Bootstrap data using the ARCOS algorithm.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df |
DataFrame
|
DataFrame containing the data to be bootstrapped. |
required |
position_columns |
list
|
List of column names containing the x and y coordinates. |
['x']
|
frame_column |
str
|
Name of the column containing the frame number. |
'frame'
|
obj_id_column |
str
|
Name of the column containing the track id. |
'obj_id'
|
measurement_column |
str
|
Name of the column containing the measurement. |
'm'
|
method |
str | list[str]
|
Method used for bootstrapping. Can be "shuffle_tracks", 'shuffle_timepoints', 'shift_timepoints', 'shuffle_binary_blocks', 'shuffle_coordinates_timepoint or a list of methods, which will be applied in order of index. |
'shuffle_tracks'
|
smooth_k |
int
|
Smoothing kernel size. |
3
|
bias_k |
int
|
Bias kernel size. |
51
|
peak_threshold |
float
|
Threshold for peak detection. |
0.2
|
binarization_threshold |
float
|
Threshold for binarization. |
0.1
|
polynomial_degree |
int
|
Degree of the polynomial used for bias correction. |
1
|
bias_method |
str
|
Bias correction method. Can be 'none', 'runmed', 'lm' |
'runmed'
|
eps |
float
|
Epsilon parameter for DBSCAN. |
2
|
eps_prev |
int | None
|
Parameter for linking tracks. If None, eps is used. |
None
|
min_clustersize |
int
|
Minimum cluster size. |
1
|
n_prev |
int
|
Number of previous frames to consider for linking. |
1
|
min_duration |
int
|
Minimum duration of a track. |
1
|
min_total_size |
int
|
Minimum size of a track. |
1
|
stats_metric |
str | list[str]
|
Metric to calculate. Can be "duration", "total_size", "min_size", "max_size" or a list of metrics. Default is ["duration", "total_size"]. |
['total_size', 'duration']
|
pval_alternative |
str
|
Alternative hypothesis for the p-value calculation. Can be "less" or "greater". |
'greater'
|
finite_correction |
bool
|
Correct p-values for finite sampling. Default is True. |
True
|
n |
int
|
Number of bootstraps. |
100
|
seed |
int
|
Seed for the random number generator. |
42
|
allow_duplicates |
bool
|
If False, resampling will check if the resampled data contains duplicates. If True, duplicates will be allowed. |
False
|
max_tries |
int
|
Maximum number of tries to resample data without duplicates. |
100
|
show_progress |
bool
|
Show a progress bar. |
True
|
verbose |
bool
|
Print additional information. |
False
|
parallel_processing |
bool
|
Use parallel processing. |
True
|
plot |
bool
|
Plot the distribution of the bootstrapped data. |
True
|
**kwargs |
Any
|
Additional keyword arguments. Includes deprecated parameters. - id_column: Deprecated. Use obj_id_column instead. - meas_column: Deprecated. Use measurement_column instead. - smoothK: Deprecated. Use smooth_k instead. - biasK: Deprecated. Use bias_k instead. - peakThr: Deprecated. Use peak_threshold instead. - binThr: Deprecated. Use binarization_threshold instead. - polyDeg: Deprecated. Use polynomial_degree instead. - biasMet: Deprecated. Use bias_method instead. - epsPrev: Deprecated. Use eps_prev instead. - minClsz: Deprecated. Use min_clustersize instead. - min_size: Deprecated. Use min_total_size instead. - paralell_processing: Deprecated. Use parallel_processing instead. |
{}
|
Returns:
Type | Description |
---|---|
DataFrame
|
DataFrame containing the bootstrapped data. |
Source code in arcos4py/validation/_bootstrapping.py
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 |
|
calculate_arcos_stats(df_resampled, iterations, position_columns=['x'], frame_column='frame', obj_id_column='obj_id', measurement_column='m', smooth_k=3, bias_k=51, peak_threshold=0.2, binarization_threshold=0.1, polynomial_degree=1, bias_method='runmed', eps=2, eps_prev=None, min_clustersize=1, n_prev=1, min_duration=1, min_total_size=1, stats_metric=['duration', 'total_size'], show_progress=True, parallel_processing=True, clid_column='clid', **kwargs)
¶
Calculate the bootstrapped statistics.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df_resampled |
DataFrame
|
Dataframe with resampled data. |
required |
iterations |
list[int]
|
List of iteration names, or range. |
required |
position_columns |
list
|
List of position columns.. |
['x']
|
frame_column |
str
|
Name of the frame column. |
'frame'
|
obj_id_column |
str
|
Name of the id column. |
'obj_id'
|
measurement_column |
str
|
Name of the measurement column. |
'm'
|
smooth_k |
int
|
Smoothing kernel size for local detrending. Defaults to 3. |
3
|
bias_k |
int
|
Bias kernel size for large scale detrending (used with biasMet='runmed'). Defaults to 51. |
51
|
peak_threshold |
float
|
Peak threshold used for rescaling (used with biasMet='runmed'). Defaults to 0.2. |
0.2
|
binarization_threshold |
float
|
Threshold for binarizing measurements after detrending. Defaults to 0.1. |
0.1
|
polynomial_degree |
int
|
Polynomial degree used for detrending (used with biasMet='lm'). Defaults to 1. |
1
|
bias_method |
str
|
Bias method, can be 'none', 'runmed', 'lm'. Defaults to "runmed". |
'runmed'
|
eps |
float
|
Epsilon used for culstering active entities. Defaults to 2. |
2
|
eps_prev |
int
|
Epsilon used for linking together culsters across time. Defaults to None. |
None
|
min_clustersize |
int
|
Minimum cluster size. Defaults to 1. |
1
|
n_prev |
int
|
Number of previous frames to consider when tracking clusters. Defaults to 1. |
1
|
min_duration |
int
|
Minimum duration of detected event. Defaults to 1. |
1
|
min_total_size |
int
|
Minimum size, minimum size of detected event. Defaults to 1. |
1
|
stats_metric |
list[str]
|
List of metrics to calculate. Defaults to ['duration', 'total_size']. |
['duration', 'total_size']
|
show_progress |
bool
|
Show progress bar. Defaults to True. |
True
|
parallel_processing |
bool
|
Use paralell processing, uses the joblib package. Defaults to True. |
True
|
clid_column |
str
|
Name of the cluster id column. Defaults to 'clid'. |
'clid'
|
**kwargs |
Any
|
Additional keyword arguments. Includes deprecated parameters. - posCols: Deprecated. Use position_columns instead. - id_column: Deprecated. Use obj_id_column instead. - meas_column: Deprecated. Use measurement_column instead. - smoothK: Deprecated. Use smooth_k instead. - biasK: Deprecated. Use bias_k instead. - peakThr: Deprecated. Use peak_threshold instead. - binThr: Deprecated. Use binarization_threshold instead. - polyDeg: Deprecated. Use polynomial_degree instead. - biasMet: Deprecated. Use bias_method instead. - epsPrev: Deprecated. Use eps_prev instead. - minClsz: Deprecated. Use min_clustersize instead. - min_size: Deprecated. Use min_total_size instead. - nPrev: Deprecated. Use n_prev instead. - paralell_processing: Deprecated. Use parallel_processing instead. |
{}
|
Returns:
Name | Type | Description |
---|---|---|
DataFrame |
DataFrame
|
Dataframe with the bootstrapped statistics. |
DataFrame |
DataFrame
|
Dataframe with mean statistics. |
Source code in arcos4py/validation/_bootstrapping.py
280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 |
|
calculate_pvalue(stats_df_mean, stats_metric, pval_alternative, finite_correction, plot, **plot_kwargs)
¶
Calculates the p-value with the given alternative hypothesis.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
stats_df_mean |
DataFrame
|
DataFrame containing the bootstrapped data. |
required |
stats_metric |
str | list[str]
|
Metric to calculate. Can be "duration", "total_size", "min_size", "max_size" or a list of metrics. Default is ["duration", "total_size"]. |
required |
pval_alternative |
str
|
Alternative hypothesis for the p-value calculation. Can be "less", "greater" or both which will return p values for both alternatives. |
required |
finite_correction |
bool
|
Correct p-values for finite sampling. Default is True. |
required |
plot |
bool
|
Plot the distribution of the bootstrapped data. |
required |
Returns:
Name | Type | Description |
---|---|---|
DataFrame |
DataFrame
|
containing the p-values. |
Source code in arcos4py/validation/_bootstrapping.py
211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 |
|
resample_data(data, position_columns=['x'], frame_column='frame', obj_id_column='obj_id', measurement_column=None, method='shuffle_tracks', n=100, seed=42, allow_duplicates=False, max_tries=100, show_progress=True, verbose=False, parallel_processing=True, **kwargs)
¶
Resamples data in order to perform bootstrapping analysis.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
Dataframe
|
The data to resample. |
required |
position_columns |
list
|
The columns to use for the position. |
['x']
|
frame_column |
str
|
The column to use for the frame. |
'frame'
|
obj_id_column |
str
|
The column to use for the object ID. |
'obj_id'
|
measurement_column |
str
|
The column to use for the measurement. Only needed for 'activity_blocks_shuffle'. Defaults to None. |
None
|
method |
str
|
The method to use for resampling. Defaults to 'shuffle_tracks'. Available methods are: "shuffle_tracks", 'shuffle_timepoints', 'shift_timepoints', 'shuffle_binary_blocks', 'shuffle_coordinates_timepoint' |
'shuffle_tracks'
|
n |
int
|
The number of resample iterations. Defaults to 100. |
100
|
seed |
int
|
The random seed. Defaults to 42. |
42
|
allow_duplicates |
bool
|
Whether to allow resampling to randomly generate the same data twice. Defaults to False. |
False
|
max_tries |
int
|
The maximum number of tries to try ot generate unique data when allow_duplicates is set to True. Defaults to 100. |
100
|
verbose |
bool
|
Whether to print progress. Defaults to False. |
False
|
parallel_processing |
bool
|
Whether to use parallel processing. Defaults to True. |
True
|
**kwargs |
Any
|
Additional keyword arguments. Includes deprecated parameters. - posCols (list): Deprecated. Use position_columns instead. - id_column (str): Deprecated. Use obj_id_column instead. - meas_column (str): Deprecated. Use measurement_column instead. - paralell_processing (bool): Deprecated. Use parallel_processing instead. |
{}
|
Returns:
Type | Description |
---|---|
DataFrame
|
pd.DataFrame: The resampled data. |
Source code in arcos4py/validation/_resampling.py
265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 |
|