-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbasic.py
40 lines (31 loc) · 1.19 KB
/
basic.py
1
2
3
4
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
"""
Basic example of OverBoard logging.
Logs several experiments with synthetic data over time.
"""
import math, random, time
from overboard_logger import Logger
print("Open OverBoard in another terminal: python3 -m overboard ./logs")
print("Then press Enter here to start logging.")
input()
# pretend that there are 10 runs/experiments
for run in range(10):
# set output directory
directory = 'logs/sinusoid' + str(run)
# select arguments specific to this run (could have used the argparse module to get from command-line)
# here we just select the arguments of a sinusoid
(phase, amp) = (random.random() * 2 * math.pi, random.random())
args = {'phase': phase, 'amplitude': amp}
print("Starting run", run, args)
# open file for logging
with Logger(directory, meta=args) as logger:
# simulate a few iterations
for iteration in range(100):
# obtain output values
angle = iteration / 100 * (2 * math.pi)
(cos, sin) = (amp * math.cos(angle + phase), amp * math.sin(angle + phase))
outputs = {'sine': sin, 'cosine': cos}
# log them
logger.append(outputs)
logger.print(outputs) # also display in terminal
# wait a bit
time.sleep(0.1)