Newer
Older
# Copyright (C) 2020-2024 Tiago de Paula Peixoto <tiago@skewed.de>
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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
#
# This program is free software: you can redistribute it and/or modify it under
# the terms of the GNU Affero General Public License as published by the Free
# Software Foundation, either version 3 of the License, or (at your option) any
# later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
# details.
#
# You should have received a copy of the GNU Affero General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.
from .. import *
import csv
import datetime
title = "Baboons' interactions (2020)"
description = """Network of interactions between a group of 20 Guinea baboons living in an enclosure of a Primate Center in France, between June 13th 2019 and July 10th 2019. The data set contains observational and wearable sensors data.
The observational data contains all the behavioral events registered by an observer, with 8 columns:
- DateTime: Time stamp of the event, namely the moment the observed behavior was registered. In case of STATE events (events with duration > 0), it refers to the beginning of the behavior
- Actor: The name of the actor
- Recipient: The name of the individual the Actor is acting upon
- Behavior: The behavior the Actor. 14 types of behaviors are registered:’Resting’, ‘Grooming’, ‘Presenting’,’Playing with’, ‘Grunting-Lipsmacking’, ‘Supplanting’,’Threatening’, ‘Submission’, ‘Touching’, ‘Avoiding’, ‘Attacking’,’Carrying’, ‘Embracing’, ‘Mounting’, ‘Copulating’, ‘Chasing’. In addition two other categories were included: ‘Invisible’ and ‘Other’
- Category: The classification of the behavior. It can be ‘Affiliative’, ‘Agonistic’, ‘Other’
- Duration: Duration of the observed behavior. POINT events have no duration
- Localisation: Zone of the enclosure where the observed behavior takes place
- Point: indicates if the event is a POINT event (YES) or a STATE event (NO).
The sensor data contains contacts recorded in the same period by the SocioPatterns infrastructure. The proximity sensors were worn by 13 of the 20 individuals cited above.
The data file consists of 4 columns:
- t: time of the beginning of the contact in Epoch format (Unix timestamps)
- i: Name of the first individual
- j: Name of the second individual
- DateTime
"""
tags = ['Social', 'Animal', 'Offline', 'Unweighted', 'Weighted', 'Temporal', 'Metadata']
url = 'http://www.sociopatterns.org/datasets/baboons-interactions/'
citation = [('V. Gelardi, J. Godard, D. Paleressompoulle, N. Claidière, A. Barrat, "Measuring social networks in primates: wearable sensors vs. direct observations", Proc. R. Soc. A 476:20190737 (2020)', 'https://doi.org/10.1098/rspa.2019.0737')]
icon_hash = None
ustream_license = ("Creative Commons Attribution-NonCommercial-ShareAlike",
"http://creativecommons.org/licenses/by-nc-sa/3.0/")
upstream_prefix = 'http://www.sociopatterns.org/wp-content/uploads/2020/12/'
files = [('OBS_data.txt.gz', 'observational', None),
('RFID_data.txt.gz', 'sensor', None)]
def fetch_upstream(force=False):
return fetch_upstream_files(__name__.split(".")[-1], upstream_prefix, files,
force)
@cache_network()
@coerce_props()
@annotate()
def parse(alts=None):
global files
name = __name__.split(".")[-1]
for fnames, alt, fmt in files:
if alts is not None and alt not in alts:
continue
if isinstance(fnames, str):
fnames = [fnames]
with ExitStack() as stack:
fs = [stack.enter_context(open_upstream_file(name, fn, "r")) for fn in fnames]
reader = csv.reader(fs[0], delimiter="\t")
if alt == "sensor":
def get_edges():
next(reader)
for rows in reader:
t, u, v = rows[:3]
yield u, v, t
g = Graph(directed=False)
g.ep.time = g.new_ep("int")
g.vp.name = g.add_edge_list(get_edges(), hashed=True,
hash_type="string", eprops=[g.ep.time])
elif alt == "observational":
def get_edges():
next(reader)
for rows in reader:
if rows[2] == "":
continue
t = datetime.datetime.strptime(rows[0], "%d/%m/%Y %H:%M").timestamp()
yield rows[1:3] + [t] + rows[3:-1] + [True if rows[-1] == "YES" else False]
g = Graph(directed=True)
g.ep.time = g.new_ep("int")
g.ep.behavior = g.new_ep("string")
g.ep.category = g.new_ep("string")
g.ep.duration = g.new_ep("double")
g.ep.localization = g.new_ep("string")
g.ep.point = g.new_ep("bool")
g.vp.name = g.add_edge_list(get_edges(), hashed=True,
hash_type="string",
eprops=[g.ep.time, g.ep.behavior,
g.ep.category,
g.ep.duration, g.ep.localization,
g.ep.point])
yield alt, g