Skip to content

Commit 888d173

Browse files
committed
added script_paths and python files
1 parent d55553e commit 888d173

File tree

4 files changed

+151
-1
lines changed

4 files changed

+151
-1
lines changed

DEVELOPER.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Developer instructions
2+
3+
This document is to describe the rules of developing for this repository.
4+
It also discusses the features and changes which will be in pipeline.
5+
6+
# Development plan
7+
- [] Merge the code into main branch after making all changes in the current
8+
model.
9+
- [] Implement AR model process to highlight the choice of coefficients. Get
10+
a plot out of it marked with important parameters.
11+
- [] Write a script to highlight the values of tau and error associated with
12+
the choice.
13+
- [] Do simulation to highlight the relevance of value of pink noise
14+
B parameter, range of taus and tau1 highlighting the error
15+
contribution from each setting.
16+
- [] Simulate the effect of new parameters for each IMU.
17+
- [] Tag the released branch and update documentation.
18+
- [] Then create another branch for packaging the project.
19+
- []

config_files

Submodule config_files updated from 9354285 to 2fbf698

python/numpy_2_mat.py

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
from scipy.io import savemat
2+
import numpy as np
3+
import zarr
4+
import argparse
5+
import os
6+
import sys
7+
import matplotlib.pyplot as plt
8+
9+
SECONDS_IN_HR = 3600
10+
# Save large numpy file as a mat file. Save smaller segments of the numpy file as mat file.
11+
12+
13+
class TUM_npy2mat:
14+
def __init__(self, config):
15+
self.config = config
16+
17+
def slice_accelerometer_data(self, data, offset_time, duration):
18+
rows, col = stationary_acclerometer_data.shape
19+
tot_time = stationary_acclerometer_data[-1,
20+
0] - stationary_acclerometer_data[0, 0]
21+
print("No. of hrs %f" % (tot_time/3600))
22+
self.avg_fs = int(np.round(rows/tot_time))
23+
self.offset_in_hr = offset_time
24+
self.duration_in_hr = duration
25+
sample_num_start = self.offset_in_hr*self.avg_fs*SECONDS_IN_HR
26+
sample_num_end = sample_num_start + self.duration_in_hr*self.avg_fs*SECONDS_IN_HR
27+
return data[sample_num_start:sample_num_end, :]
28+
29+
def visualize_accelerometer_data(self, data):
30+
fig, axes = plt.subplots(nrows=3, ncols=2)
31+
for i, ax in enumerate(axes):
32+
ax[0].plot(data[:, 0]/3600, data[:, i+1])
33+
ax[0].set_xlabel('time(hr)')
34+
ax[0].set_ylabel('rad/s')
35+
ax[0].grid(True)
36+
37+
ax[1].plot(data[:, 0]/3600, data[:, 4+i])
38+
ax[1].set_xlabel('time(hr)')
39+
ax[1].set_ylabel('m/s^2')
40+
ax[1].grid(True)
41+
fig.tight_layout()
42+
plt.show(block=False)
43+
plt.pause(.5)
44+
45+
def save_to_mat(self, acc_data):
46+
47+
acc_data_dict = {"fs_hz": self.avg_fs,
48+
"duration_hr": self.duration_in_hr,
49+
"offset_hr": self.offset_in_hr,
50+
"timestamp": acc_data[:, 0],
51+
"gyro_x": acc_data[:, 1],
52+
"gyro_y": acc_data[:, 2],
53+
"gyro_z": acc_data[:, 3],
54+
"accel_x": acc_data[:, 4],
55+
"accel_y": acc_data[:, 5],
56+
"accel_z": acc_data[:, 6],
57+
"temperature": acc_data[:, 7]}
58+
59+
savemat(os.path.join(self.config.output_directory_path,
60+
self.config.output_file_name + '.mat'), acc_data_dict)
61+
62+
63+
# data = np.load(
64+
# r'E:\Windows\Documents\Northeastern\NEUFRL\IMU_Paper_Part_2\dataset-calib-imu-static2.npy', mmap_mode='r')
65+
66+
67+
def check_config(config):
68+
try:
69+
assert(os.path.exists(config.input_file_path)
70+
), 'Invalid path for input npy file'
71+
_, _, ext = file_path_parts(config.input_file_path)
72+
assert(ext == ".npy"), 'Invalid extention for input file'
73+
if config.output_directory_path == None and config.output_file_name == None:
74+
config.output_directory_path, config.output_file_name, _ = file_path_parts(
75+
config.input_file_path)
76+
77+
elif config.output_directory_path == None:
78+
config.output_directory_path, _, _ = file_path_parts(
79+
config.input_file_path)
80+
81+
elif config.output_file_name == None:
82+
config.output_file_name, _, _ = file_path_parts(
83+
config.input_file_path)
84+
85+
if (not os.path.exists(config.output_directory_path)):
86+
os.path.mkdir(config.output_directory_path)
87+
except AssertionError as msg:
88+
print(msg)
89+
sys.exit()
90+
91+
92+
def file_path_parts(full_file_path):
93+
output_dir, file = os.path.split(full_file_path)
94+
filename, ext = os.path.splitext(file)
95+
return output_dir, filename, ext
96+
97+
# ax[1:0].plot(data[:, 0], data[:, 7])
98+
99+
100+
if __name__ == '__main__':
101+
argument_parser = argparse.ArgumentParser(
102+
prog="numpy 2 mat inputs", usage="converts .npy file to .mat")
103+
argument_parser.add_argument(
104+
'-i', '--input_file_path', type=str, required=True, help='Input numpy file path', default='./dataset-calib-imu-static2.npy')
105+
argument_parser.add_argument(
106+
'-o', '--output_file_name', type=str, help='Output mat file path')
107+
argument_parser.add_argument(
108+
'-d', '--output_directory_path', type=str, help='Output mat file directory')
109+
argument_parser.add_argument(
110+
'--offset', type=int, help='offset of samples', default=1)
111+
argument_parser.add_argument(
112+
'--duration', type=int, help="Duration of samples extracted", default=7)
113+
config = argument_parser.parse_args()
114+
check_config(config)
115+
print(vars(config))
116+
print("----------------")
117+
stationary_acclerometer_data = np.load(
118+
config.input_file_path, mmap_mode='r')
119+
120+
# Slice data
121+
tum_npy2mat = TUM_npy2mat(config)
122+
sliced_data = tum_npy2mat.slice_accelerometer_data(
123+
stationary_acclerometer_data, config.offset, config.duration)
124+
125+
tum_npy2mat.save_to_mat(sliced_data)
126+
tum_npy2mat.visualize_accelerometer_data(
127+
sliced_data)
128+
plt.show(block=True)

script_paths.m

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
addpath( genpath('config_files'),...
2+
genpath('fcns'),...
3+
genpath('scripts'));

0 commit comments

Comments
 (0)