-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMeasurement.py
73 lines (64 loc) · 1.83 KB
/
Measurement.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
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
from base import Treadmill
import numpy as np
from time import time
import os
channel = 'Dev1/ai0'
bit_size = 10000
"""Experiment"""
t = Treadmill(light_channel = channel)
t.calibrate()
input("Press Enter to continue...")
n = 100
pos = t.get_position()
prog = int(pos*(n+1) / t.belt_length)
print('\r |' + ('#'*prog) + ('-'*(n-prog)) + '| ' + f'{round(pos, 1)}'.zfill(6), end='')
print("Starting...")
print("Press Ctrl+C/Ctrl+F2 to stop")
data = np.zeros(bit_size)
timecode = np.zeros(bit_size)
"""File Names"""
pr = "B01-3" #project
exp = "1.1" #experiment
gr = "Ta1" #group
an = "MT-04.1" #animal
folder = f"{pr}_{exp}_{gr}_{an}" #folder name
he = "r" #hemisphere
he = "left" if he == "l" else "right" if he == "r" else None #writing out hemisphere name
path = f"D:\Liliia\Treadmill Recordings\{folder}" #path with folder
sub = f"{path}\{he}" #subdirectory within folder
if os.path.isdir(sub):
print(f"subdirectory {sub} already exists")
else:
if os.path.isdir(path):
print(f"path {path} already exists")
else:
os.mkdir(path)
print(f"path {path} is created")
os.mkdir(sub)
print(f"subdirectory {sub} is created")
os.chdir(sub)
#try:
# os.chdir(folder)
#except:
# os.mkdir(folder)
# os.chdir(folder)
#try:
# os.chdir(he)
#except:
# os.mkdir(he)
# os.chdir(he)
"""Saving Measurements"""
try:
chunk = 0
while True:
for i in range(bit_size):
timecode[i] = time()
data[i] = t.get_position(total=True)
file=f"{sub}\Treadmill-data_{chunk}_(belt-length {round(t.belt_length)} mm)"
np.savez(file, data=data, timecode=timecode)
print(f"{chunk} - saving chunk {chunk} to {file}")
chunk += 1
except KeyboardInterrupt:
print("Exiting")
finally:
np.savez(f"{sub}\Treadmill-data_{chunk}_(belt-length {round(t.belt_length)} mm", position=data[:i], timecode=timecode[:i])