Skip to contents

Computes summary statistics of movement data grouped by patches for each individual tag. Calculates spatial and temporal summaries within each patch, distances travelled inside patches, distances and time intervals between patches, displacement within patches, and patch duration. Additional user-specified summary variables and functions can also be applied dynamically. If species is a column, it will be kept.

Usage

atl_res_patch_summary(data, summary_variables = c(), summary_functions = c())

Arguments

data

A data.frame or data.table containing movement data. Must include columns: tag (ID), x, y (coords), time (timestamp), and patch (patch ID).

summary_variables

Character vector of variable names in data for additional summaries. Variables should be numeric or compatible with the summary functions.

summary_functions

Character vector of function names to apply to each variable in summary_variables. Functions must work on numeric vectors (e.g., "mean" or "median").

Value

A data.table with one row per tag and patch containing:

  • nfixes: Number of fixes in the patch.

  • x_mean, x_median, x_start, x_end: Summary stats of x.

  • y_mean, y_median, y_start, y_end: Summary stats of y.

  • time_mean, time_median, time_start, time_end: Summary stats of time.

  • Additional summaries from summary_variables and summary_functions.

  • dist_start_end: Straight-line (in m) distance between start and end of patch.

  • dist_in_patch: Total distance (in m) travelled within the patch.

  • dist_bw_patch: Distance (in m) between end of previous and start of current patch.

  • time_bw_patch: Time (in sec) elapsed between end of previous and start of current patch.

  • disp_in_patch: Straight-line (in m) displacement between start and end of patch.

  • duration: Duration spent (in sec) within the patch.

Details

Converts input data to data.table if needed and filters out rows with missing patch assignments. All summaries are calculated by tag and patch.Distance calculations use Euclidean distance in x-y coordinate space.

Author

Johannes Krietsch

Examples

# packages
library(tools4watlas)

# load example data
data <- data_example

# calculate residence patches for one red knot
data <- atl_res_patch(
  data[tag == "3038"],
  max_speed = 3, lim_spat_indep = 75, lim_time_indep = 180,
  min_fixes = 3, min_duration = 120
)

# summary of residence patches
data_summary <- atl_res_patch_summary(data)
data_summary
#>        tag  patch nfixes   x_mean x_median  x_start    x_end  y_mean y_median
#>     <char> <char>  <int>    <num>    <num>    <num>    <num>   <num>    <num>
#>  1:   3038      1    856 650146.6 650148.2 650120.1 650110.4 5902396  5902400
#>  2:   3038      2     51 649933.6 649934.3 649953.4 649921.5 5902356  5902357
#>  3:   3038      3    958 650378.5 650378.6 650369.7 650384.2 5902349  5902368
#>  4:   3038      4    831 650263.3 650251.5 650254.9 650313.1 5902162  5902170
#>  5:   3038      5    354 650472.8 650457.9 650403.8 650534.6 5901982  5901997
#>  6:   3038      6    998 650764.3 650765.6 650722.6 650748.1 5901925  5901912
#>  7:   3038      7    426 650805.2 650798.7 650859.0 650766.6 5901891  5901893
#>  8:   3038      8    163 650739.1 650739.3 650739.5 650738.8 5901747  5901747
#>  9:   3038      9    610 650664.2 650676.0 650696.8 650616.4 5901843  5901844
#> 10:   3038     10   1173 650971.4 650995.1 651071.8 650865.5 5901981  5901988
#> 11:   3038     11   1440 650728.6 650728.2 650773.4 650713.5 5901998  5902007
#> 12:   3038     12     85 650883.8 650881.6 650895.4 650871.3 5902117  5902115
#> 13:   3038     13    248 651540.2 651543.1 651556.2 651488.7 5902139  5902134
#> 14:   3038     14     18 651422.3 651423.4 651428.6 651425.3 5902253  5902254
#> 15:   3038     15    115 651406.1 651402.6 651422.3 651401.5 5902383  5902381
#> 16:   3038     16     34 651425.9 651425.7 651423.4 651429.4 5902519  5902517
#> 17:   3038     17    115 651499.6 651501.2 651457.8 651499.6 5903028  5903027
#> 18:   3038     18      3 650605.3 650605.3 650605.3 650605.3 5903017  5903006
#> 19:   3038     19      4 650681.9 650670.3 650716.7 650670.3 5903107  5903107
#> 20:   3038     20      4 651668.5 651668.5 651668.5 651668.5 5903164  5903148
#> 21:   3038     21      3 651686.5 651686.5 651686.5 651686.5 5902868  5902868
#> 22:   3038     22    294 650211.9 650222.3 650216.9 650211.5 5902178  5902191
#> 23:   3038     23    107 650064.2 650064.0 650073.1 650055.9 5902046  5902044
#> 24:   3038     24   1016 650232.7 650236.5 650201.5 650257.9 5902030  5902023
#> 25:   3038     25     81 650422.0 650421.3 650416.9 650430.5 5901725  5901723
#> 26:   3038     26   3038 650572.6 650547.5 650608.5 650317.2 5902113  5902115
#> 27:   3038     27   1072 650155.0 650155.0 650153.7 650159.1 5902363  5902361
#>        tag  patch nfixes   x_mean x_median  x_start    x_end  y_mean y_median
#>     <char> <char>  <int>    <num>    <num>    <num>    <num>   <num>    <num>
#>     y_start   y_end           time_mean         time_median          time_start
#>       <num>   <num>              <POSc>              <POSc>              <POSc>
#>  1: 5902400 5902355 2023-09-23 01:31:24 2023-09-23 01:30:26 2023-09-23 01:00:03
#>  2: 5902347 5902357 2023-09-23 02:21:31 2023-09-23 02:21:24 2023-09-23 02:19:39
#>  3: 5902387 5902293 2023-09-23 02:56:06 2023-09-23 02:56:39 2023-09-23 02:26:39
#>  4: 5902239 5902078 2023-09-23 03:49:21 2023-09-23 03:49:30 2023-09-23 03:24:03
#>  5: 5902046 5901906 2023-09-23 04:24:05 2023-09-23 04:24:01 2023-09-23 04:14:06
#>  6: 5902017 5901835 2023-09-23 05:03:44 2023-09-23 05:01:34 2023-09-23 04:35:08
#>  7: 5901867 5901884 2023-09-23 05:48:01 2023-09-23 05:47:55 2023-09-23 05:36:17
#>  8: 5901750 5901746 2023-09-23 06:04:21 2023-09-23 06:04:23 2023-09-23 05:59:56
#>  9: 5901821 5901854 2023-09-23 06:26:57 2023-09-23 06:26:54 2023-09-23 06:08:53
#> 10: 5901909 5902008 2023-09-23 07:18:55 2023-09-23 07:18:44 2023-09-23 06:45:11
#> 11: 5901939 5902044 2023-09-23 08:32:55 2023-09-23 08:33:09 2023-09-23 07:52:04
#> 12: 5902104 5902115 2023-09-23 09:16:10 2023-09-23 09:16:10 2023-09-23 09:13:40
#> 13: 5902123 5902184 2023-09-23 09:29:29 2023-09-23 09:29:00 2023-09-23 09:21:43
#> 14: 5902254 5902249 2023-09-23 09:57:05 2023-09-23 09:57:26 2023-09-23 09:53:43
#> 15: 5902354 5902417 2023-09-23 10:03:57 2023-09-23 10:03:58 2023-09-23 10:00:16
#> 16: 5902509 5902530 2023-09-23 10:14:49 2023-09-23 10:14:47 2023-09-23 10:13:40
#> 17: 5903046 5903028 2023-09-23 11:10:51 2023-09-23 11:10:19 2023-09-23 10:26:40
#> 18: 5902993 5903051 2023-09-23 13:38:58 2023-09-23 13:47:06 2023-09-23 13:18:54
#> 19: 5903100 5903115 2023-09-23 14:09:47 2023-09-23 14:14:40 2023-09-23 13:54:57
#> 20: 5903143 5903217 2023-09-23 15:07:37 2023-09-23 15:07:02 2023-09-23 15:03:29
#> 21: 5902868 5902868 2023-09-23 15:20:58 2023-09-23 15:19:53 2023-09-23 15:19:50
#> 22: 5902167 5902185 2023-09-23 15:44:08 2023-09-23 15:43:49 2023-09-23 15:35:35
#> 23: 5902066 5902047 2023-09-23 15:57:24 2023-09-23 15:57:17 2023-09-23 15:54:29
#> 24: 5902047 5902023 2023-09-23 16:39:42 2023-09-23 16:40:54 2023-09-23 16:07:23
#> 25: 5901726 5901741 2023-09-23 17:15:20 2023-09-23 17:15:17 2023-09-23 17:13:08
#> 26: 5901823 5902230 2023-09-23 19:41:13 2023-09-23 19:28:13 2023-09-23 17:17:59
#> 27: 5902362 5902391 2023-09-23 23:30:06 2023-09-23 23:30:15 2023-09-23 22:44:00
#>     y_start   y_end           time_mean         time_median          time_start
#>       <num>   <num>              <POSc>              <POSc>              <POSc>
#>                time_end dist_start_end dist_in_patch dist_bw_patch
#>                  <POSc>          <num>         <num>         <num>
#>  1: 2023-09-23 02:11:30      45.928638    1378.57243            NA
#>  2: 2023-09-23 02:24:18      33.422968      75.19836     157.24233
#>  3: 2023-09-23 03:23:33      95.183981    1172.57976     449.10828
#>  4: 2023-09-23 04:13:51     171.139566     724.39585     140.38571
#>  5: 2023-09-23 04:34:20     191.555615     349.04444      96.27647
#>  6: 2023-09-23 05:33:56     183.077395    1189.36768     218.34299
#>  7: 2023-09-23 05:59:38      94.007329     394.63487     115.41919
#>  8: 2023-09-23 06:08:41       3.606106     116.82332     136.99063
#>  9: 2023-09-23 06:44:26      87.212108     411.85421      85.36514
#> 10: 2023-09-23 07:51:46     228.708415    1032.20247     458.67406
#> 11: 2023-09-23 09:13:13     120.308727    1137.05485     114.83434
#> 12: 2023-09-23 09:18:37      26.517958      98.76813     191.48906
#> 13: 2023-09-23 09:46:04      91.138087     570.45038     684.97307
#> 14: 2023-09-23 09:58:10       6.553215      42.21491      92.45011
#> 15: 2023-09-23 10:07:58      66.914171     212.72252     105.18801
#> 16: 2023-09-23 10:15:52      22.195678      67.50586      94.28270
#> 17: 2023-09-23 11:25:39      45.630289     277.56869     516.25801
#> 18: 2023-09-23 13:50:54      58.628698      58.62870     894.94689
#> 19: 2023-09-23 14:14:51      48.732652      61.24685     121.63455
#> 20: 2023-09-23 15:12:53      74.045195      74.04520     998.55687
#> 21: 2023-09-23 15:23:11       0.000000       0.00000     349.40222
#> 22: 2023-09-23 15:52:50      18.739496     919.86234    1628.57203
#> 23: 2023-09-23 16:00:38      25.900497     110.82065     182.05255
#> 24: 2023-09-23 17:12:38      61.353129     923.60221     145.58326
#> 25: 2023-09-23 17:17:35      20.560332      85.59062     336.92942
#> 26: 2023-09-23 22:24:09     500.761579    3526.21362     195.76701
#> 27: 2023-09-23 23:59:54      29.822003    1197.75829     210.06924
#>                time_end dist_start_end dist_in_patch dist_bw_patch
#>                  <POSc>          <num>         <num>         <num>
#>     time_bw_patch disp_in_patch  duration
#>             <num>         <num>     <num>
#>  1:            NA     45.928638  4286.659
#>  2:       488.961     33.422968   278.978
#>  3:       140.989     95.183981  3413.729
#>  4:        29.997    171.139566  2987.763
#>  5:        14.998    191.555615  1214.904
#>  6:        47.996    183.077395  3527.720
#>  7:       140.989     94.007329  1400.888
#>  8:        17.999      3.606106   524.959
#>  9:        11.999     87.212108  2132.830
#> 10:        44.997    228.708415  3995.684
#> 11:        17.999    120.308727  4868.615
#> 12:        26.998     26.517958   296.977
#> 13:       185.985     91.138087  1460.886
#> 14:       458.964      6.553215   266.979
#> 15:       125.990     66.914171   461.963
#> 16:       341.973     22.195678   131.989
#> 17:       647.949     45.630289  3539.722
#> 18:      6794.467     58.628698  1919.850
#> 19:       242.981     48.732652  1193.906
#> 20:      2918.771     74.045195   563.955
#> 21:       416.967      0.000000   200.984
#> 22:       743.942     18.739496  1034.918
#> 23:        98.992     25.900497   368.970
#> 24:       404.968     61.353129  3914.689
#> 25:        29.998     20.560332   266.979
#> 26:        23.998    500.761579 18370.541
#> 27:      1190.905     29.822003  4553.638
#>     time_bw_patch disp_in_patch  duration
#>             <num>         <num>     <num>