{ "cells": [ { "cell_type": "markdown", "id": "3ad67b01-3887-48b5-a669-222b3c5dcbe8", "metadata": {}, "source": [ "## Analyzing data from Movebank" ] }, { "cell_type": "code", "execution_count": 1, "id": "989214d5-edb0-48f8-8043-8cdc2eb4d61e", "metadata": {}, "outputs": [], "source": [ "import movekit as mkit" ] }, { "cell_type": "markdown", "id": "b982e7c4-51c4-4f29-8b2e-4642adc9f223", "metadata": {}, "source": [ "#### Read data input" ] }, { "cell_type": "code", "execution_count": 2, "id": "24dd7e66-b325-4cf9-932e-14207f40c4d6", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
timeanimal_idxyevent-idvisiblelocation-longlocation-latbehavioural-classificationcommentsstudy-specific-measurementsensor-typeindividual-taxon-canonical-nametag-local-identifierstudy-name
13371972-05-01 05:15:00BT206205.0000461229.9999991215038324True30.3605560.553375?NaNSUBADULTnatural-markLophocebus albigenaBTMangabey monkeys in Uganda (data from Waser 1975)
01972-05-01 05:15:00KT206220.0000461219.9999991215038318True30.3606910.553285?NaNADULTnatural-markLophocebus albigenaKTMangabey monkeys in Uganda (data from Waser 1975)
7101972-05-01 05:15:00LN206210.0000461234.9999991215038323True30.3606010.553420?NaNADULTnatural-markLophocebus albigenaLNMangabey monkeys in Uganda (data from Waser 1975)
96371972-05-01 05:15:00M Group206209.0000461220.4999991099185632True30.3605920.553289NaN9.0NaNnatural-markLophocebus albigenaM GroupMangabey monkeys in Uganda (data from Waser 1975)
21481972-05-01 05:45:00HK206235.0000461574.9999991215038325True30.3608240.556493FEED:DS:FRUITNaNADULTnatural-markLophocebus albigenaHKMangabey monkeys in Uganda (data from Waser 1975)
\n", "
" ], "text/plain": [ " time animal_id x y event-id \\\n", "1337 1972-05-01 05:15:00 BT 206205.00004 61229.999999 1215038324 \n", "0 1972-05-01 05:15:00 KT 206220.00004 61219.999999 1215038318 \n", "710 1972-05-01 05:15:00 LN 206210.00004 61234.999999 1215038323 \n", "9637 1972-05-01 05:15:00 M Group 206209.00004 61220.499999 1099185632 \n", "2148 1972-05-01 05:45:00 HK 206235.00004 61574.999999 1215038325 \n", "\n", " visible location-long location-lat behavioural-classification \\\n", "1337 True 30.360556 0.553375 ? \n", "0 True 30.360691 0.553285 ? \n", "710 True 30.360601 0.553420 ? \n", "9637 True 30.360592 0.553289 NaN \n", "2148 True 30.360824 0.556493 FEED:DS:FRUIT \n", "\n", " comments study-specific-measurement sensor-type \\\n", "1337 NaN SUBADULT natural-mark \n", "0 NaN ADULT natural-mark \n", "710 NaN ADULT natural-mark \n", "9637 9.0 NaN natural-mark \n", "2148 NaN ADULT natural-mark \n", "\n", " individual-taxon-canonical-name tag-local-identifier \\\n", "1337 Lophocebus albigena BT \n", "0 Lophocebus albigena KT \n", "710 Lophocebus albigena LN \n", "9637 Lophocebus albigena M Group \n", "2148 Lophocebus albigena HK \n", "\n", " study-name \n", "1337 Mangabey monkeys in Uganda (data from Waser 1975) \n", "0 Mangabey monkeys in Uganda (data from Waser 1975) \n", "710 Mangabey monkeys in Uganda (data from Waser 1975) \n", "9637 Mangabey monkeys in Uganda (data from Waser 1975) \n", "2148 Mangabey monkeys in Uganda (data from Waser 1975) " ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "data = mkit.read_movebank('datasets/Mangabey_monkeys_in_Uganda.csv')\n", "data.head()" ] }, { "cell_type": "markdown", "id": "abf47dac-ca3a-4c46-8fbc-608cb21a9595", "metadata": {}, "source": [ "#### Basic Data Analysis" ] }, { "cell_type": "markdown", "id": "85dfd5d1-c188-4a5b-a893-aea4e6dbac06", "metadata": {}, "source": [ "For further data analysis functions of `movekit` please refer to the other example notebooks or the documentation.\n", "It is important to preprocess the data from Movebank, as the data often contains duplicates which can lead to problems in further analysis steps." ] }, { "cell_type": "code", "execution_count": 10, "id": "45507e0e-e847-4922-a3e9-db2d1cf4c518", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Total number of missing values = 14437\n", "comments 9637\n", "behavioural-classification 2400\n", "study-specific-measurement 2400\n", "time 0\n", "animal_id 0\n", "x 0\n", "y 0\n", "event-id 0\n", "visible 0\n", "location-long 0\n", "location-lat 0\n", "sensor-type 0\n", "individual-taxon-canonical-name 0\n", "tag-local-identifier 0\n", "study-name 0\n", "dtype: int64\n" ] }, { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
timeanimal_idxyevent-idvisiblelocation-longlocation-latbehavioural-classificationcommentsstudy-specific-measurementsensor-typeindividual-taxon-canonical-nametag-local-identifierstudy-name
13371972-05-01 05:15:00BT206205.0000461229.9999991215038324True30.3605560.553375?NaNSUBADULTnatural-markLophocebus albigenaBTMangabey monkeys in Uganda (data from Waser 1975)
01972-05-01 05:15:00KT206220.0000461219.9999991215038318True30.3606910.553285?NaNADULTnatural-markLophocebus albigenaKTMangabey monkeys in Uganda (data from Waser 1975)
7101972-05-01 05:15:00LN206210.0000461234.9999991215038323True30.3606010.553420?NaNADULTnatural-markLophocebus albigenaLNMangabey monkeys in Uganda (data from Waser 1975)
96371972-05-01 05:15:00M Group206209.0000461220.4999991099185632True30.3605920.553289NaN9.0NaNnatural-markLophocebus albigenaM GroupMangabey monkeys in Uganda (data from Waser 1975)
21481972-05-01 05:45:00HK206235.0000461574.9999991215038325True30.3608240.556493FEED:DS:FRUIT10.0ADULTnatural-markLophocebus albigenaHKMangabey monkeys in Uganda (data from Waser 1975)
\n", "
" ], "text/plain": [ " time animal_id x y event-id \\\n", "1337 1972-05-01 05:15:00 BT 206205.00004 61229.999999 1215038324 \n", "0 1972-05-01 05:15:00 KT 206220.00004 61219.999999 1215038318 \n", "710 1972-05-01 05:15:00 LN 206210.00004 61234.999999 1215038323 \n", "9637 1972-05-01 05:15:00 M Group 206209.00004 61220.499999 1099185632 \n", "2148 1972-05-01 05:45:00 HK 206235.00004 61574.999999 1215038325 \n", "\n", " visible location-long location-lat behavioural-classification \\\n", "1337 True 30.360556 0.553375 ? \n", "0 True 30.360691 0.553285 ? \n", "710 True 30.360601 0.553420 ? \n", "9637 True 30.360592 0.553289 NaN \n", "2148 True 30.360824 0.556493 FEED:DS:FRUIT \n", "\n", " comments study-specific-measurement sensor-type \\\n", "1337 NaN SUBADULT natural-mark \n", "0 NaN ADULT natural-mark \n", "710 NaN ADULT natural-mark \n", "9637 9.0 NaN natural-mark \n", "2148 10.0 ADULT natural-mark \n", "\n", " individual-taxon-canonical-name tag-local-identifier \\\n", "1337 Lophocebus albigena BT \n", "0 Lophocebus albigena KT \n", "710 Lophocebus albigena LN \n", "9637 Lophocebus albigena M Group \n", "2148 Lophocebus albigena HK \n", "\n", " study-name \n", "1337 Mangabey monkeys in Uganda (data from Waser 1975) \n", "0 Mangabey monkeys in Uganda (data from Waser 1975) \n", "710 Mangabey monkeys in Uganda (data from Waser 1975) \n", "9637 Mangabey monkeys in Uganda (data from Waser 1975) \n", "2148 Mangabey monkeys in Uganda (data from Waser 1975) " ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "data = mkit.preprocess(data, interpolation = True, date_format = True) # important to indicate the date format of time by setting date_format=True when applying interpolation\n", "data.head()" ] }, { "cell_type": "code", "execution_count": 13, "id": "347c7311-29eb-413c-ba18-edaa2a9df975", "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "Extracting all absolute features: 100%|██████████| 100.0/100 [00:03<00:00, 32.24it/s]\n" ] }, { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
timeanimal_idxydistancedirectionturningaverage_speedaverage_accelerationstopped...visiblelocation-longlocation-latbehavioural-classificationcommentsstudy-specific-measurementsensor-typeindividual-taxon-canonical-nametag-local-identifierstudy-name
01972-05-01 05:15:00BT206205.0000461229.9999990.0(0.0, 0.0)0.0144.909354-6.7500610...True30.3605560.553375?0.0SUBADULTnatural-markLophocebus albigenaBTMangabey monkeys in Uganda (data from Waser 1975)
11972-05-01 05:15:00KT206220.0000461219.9999990.0(0.0, 0.0)0.089.7572408.4917640...True30.3606910.553285?0.0ADULTnatural-markLophocebus albigenaKTMangabey monkeys in Uganda (data from Waser 1975)
21972-05-01 05:15:00LN206210.0000461234.9999990.0(0.0, 0.0)0.0280.4989113.7024600...True30.3606010.553420?0.0ADULTnatural-markLophocebus albigenaLNMangabey monkeys in Uganda (data from Waser 1975)
31972-05-01 05:15:00M Group206209.0000461220.4999990.0(0.0, 0.0)0.041.606821-0.1498400...True30.3605920.55328909.00natural-markLophocebus albigenaM GroupMangabey monkeys in Uganda (data from Waser 1975)
41972-05-01 05:45:00HK206235.0000461574.9999990.0(0.0, 0.0)0.0243.150166-7.6125150...True30.3608240.556493FEED:DS:FRUIT10.0ADULTnatural-markLophocebus albigenaHKMangabey monkeys in Uganda (data from Waser 1975)
\n", "

5 rows × 21 columns

\n", "
" ], "text/plain": [ " time animal_id x y distance \\\n", "0 1972-05-01 05:15:00 BT 206205.00004 61229.999999 0.0 \n", "1 1972-05-01 05:15:00 KT 206220.00004 61219.999999 0.0 \n", "2 1972-05-01 05:15:00 LN 206210.00004 61234.999999 0.0 \n", "3 1972-05-01 05:15:00 M Group 206209.00004 61220.499999 0.0 \n", "4 1972-05-01 05:45:00 HK 206235.00004 61574.999999 0.0 \n", "\n", " direction turning average_speed average_acceleration stopped ... \\\n", "0 (0.0, 0.0) 0.0 144.909354 -6.750061 0 ... \n", "1 (0.0, 0.0) 0.0 89.757240 8.491764 0 ... \n", "2 (0.0, 0.0) 0.0 280.498911 3.702460 0 ... \n", "3 (0.0, 0.0) 0.0 41.606821 -0.149840 0 ... \n", "4 (0.0, 0.0) 0.0 243.150166 -7.612515 0 ... \n", "\n", " visible location-long location-lat behavioural-classification comments \\\n", "0 True 30.360556 0.553375 ? 0.0 \n", "1 True 30.360691 0.553285 ? 0.0 \n", "2 True 30.360601 0.553420 ? 0.0 \n", "3 True 30.360592 0.553289 0 9.0 \n", "4 True 30.360824 0.556493 FEED:DS:FRUIT 10.0 \n", "\n", " study-specific-measurement sensor-type individual-taxon-canonical-name \\\n", "0 SUBADULT natural-mark Lophocebus albigena \n", "1 ADULT natural-mark Lophocebus albigena \n", "2 ADULT natural-mark Lophocebus albigena \n", "3 0 natural-mark Lophocebus albigena \n", "4 ADULT natural-mark Lophocebus albigena \n", "\n", " tag-local-identifier study-name \n", "0 BT Mangabey monkeys in Uganda (data from Waser 1975) \n", "1 KT Mangabey monkeys in Uganda (data from Waser 1975) \n", "2 LN Mangabey monkeys in Uganda (data from Waser 1975) \n", "3 M Group Mangabey monkeys in Uganda (data from Waser 1975) \n", "4 HK Mangabey monkeys in Uganda (data from Waser 1975) \n", "\n", "[5 rows x 21 columns]" ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "data = mkit.extract_features(data)\n", "data.head()" ] }, { "cell_type": "code", "execution_count": 7, "id": "9b35da87-220d-4eca-89f3-bfa1fa5d087d", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
animal_iddistance
0BB29292.196235
1BC32339.850273
2BR25428.128415
3BT56379.253280
4CH0.000000
5FB0.000000
6HK44779.676823
7JA0.000000
8JE42121.957235
9KT44881.459185
10LN36373.411270
11M Group69659.023543
12O48254.273757
13PB16140.353833
14RF55879.886570
15S17618.932566
16SK22967.788494
17TK49030.622798
\n", "
" ], "text/plain": [ " animal_id distance\n", "0 BB 29292.196235\n", "1 BC 32339.850273\n", "2 BR 25428.128415\n", "3 BT 56379.253280\n", "4 CH 0.000000\n", "5 FB 0.000000\n", "6 HK 44779.676823\n", "7 JA 0.000000\n", "8 JE 42121.957235\n", "9 KT 44881.459185\n", "10 LN 36373.411270\n", "11 M Group 69659.023543\n", "12 O 48254.273757\n", "13 PB 16140.353833\n", "14 RF 55879.886570\n", "15 S 17618.932566\n", "16 SK 22967.788494\n", "17 TK 49030.622798" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "#calculate for each animal the distance covered between 1972-5-1 and 1972-10-1 12:00:00\n", "mkit.distance_by_time(data, '1972-5-1','1972-10-1 12:00:00')" ] }, { "cell_type": "markdown", "id": "6cfa25be-26e4-427e-8f3a-f443aae92539", "metadata": { "tags": [] }, "source": [ "#### Create interactive maps with the geodata" ] }, { "cell_type": "markdown", "id": "8f712754-3808-4e34-9441-0fd3541db8b9", "metadata": {}, "source": [ "Using the geodata interactive maps can be created. By clicking on the marker points the animal_id and the time of each marker is displayed." ] }, { "cell_type": "code", "execution_count": 3, "id": "e9028dd9-9e9f-46d5-8683-b777221d9a57", "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "Plotting geo data for specified animals: 100%|██████████| 2/2 [00:00<00:00, 4.34it/s]\n" ] }, { "data": { "text/html": [ "
Make this Notebook Trusted to load map: File -> Trust Notebook
" ], "text/plain": [ "" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# as the creation of the map is very time-confusing it is recommended to select a subsample of animals for which the map is created.\n", "mkit.plot_geodata(data, animal_list=[\"BT\", \"KT\"])" ] }, { "cell_type": "markdown", "id": "918acaa2-8fcc-4e19-b588-ce2ad11d488d", "metadata": {}, "source": [ "Additionally the movement of individual animals can be retraced by including movement lines in between the different markers." ] }, { "cell_type": "code", "execution_count": 4, "id": "77e075fa-1755-40a5-b6f4-e42bb8b1b10b", "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "Plotting geo data for specified animals: 100%|██████████| 1/1 [00:00<00:00, 8.70it/s]\n" ] }, { "data": { "text/html": [ "
Make this Notebook Trusted to load map: File -> Trust Notebook
" ], "text/plain": [ "" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# each movement line has a tooltip to follow the sequence of movement (here animal \"JA\" for example starts in south west)\n", "movement_map = mkit.plot_geodata(data, animal_list=[\"JA\"], movement_lines=True)\n", "movement_map" ] }, { "cell_type": "markdown", "id": "7ffe43d6-2441-43e0-86e7-c5c7db202a16", "metadata": {}, "source": [ "The created maps can also be saved locally." ] }, { "cell_type": "code", "execution_count": 10, "id": "e38af578-c500-4c10-98c5-e75b711a7bef", "metadata": {}, "outputs": [], "source": [ "#mkit.save_geodata_map(movement_map, \"mymap.html\")" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.9.7" } }, "nbformat": 4, "nbformat_minor": 5 }