-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathradar_data_augmentation.py
119 lines (86 loc) · 4.45 KB
/
radar_data_augmentation.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
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
108
109
110
111
112
113
114
115
116
117
118
import glob
import os
import numpy as np
import matplotlib.pyplot as plt
from tqdm import tqdm
import argparse
import random
def range_angle_map(data, fft_size=256):
data = np.fft.fft(data, axis=1) # Range FFT
data -= np.mean(data, 2, keepdims=True)
data = np.fft.fft(data, fft_size, axis=0) # Angle FFT
# data = np.fft.fftshift(data, axes=0)
data = np.abs(data).sum(axis=2) # Sum over velocity
return data.T
def range_velocity_map(data, fft_size=256):
data = np.fft.fft(data, axis=1) # Range FFT
# data -= np.mean(data, 2, keepdims=True)
data = np.fft.fft(data, fft_size, axis=2) # Velocity FFT
# data = np.fft.fftshift(data, axes=2)
data = np.abs(data).sum(axis=0) # Sum over antennas
# data = np.log(1 + data)
return data
def radar_cube_map(data, fft_size = 4):
data = np.fft.fft(data, axis=1) # Range FFT
data = np.fft.fft(data, axis=2) # Velocity FFT
data = np.fft.fft(data, n=fft_size, axis=0) # Angle FFT
data = np.abs(data)
return data
def minmax(arr):
return (arr - arr.min()) / (arr.max() - arr.min())
path_root=["/efs/data/Adaptation_dataset_multi_modal/scenario31","/efs/data/Adaptation_dataset_multi_modal/scenario32",
"/efs/data/Adaptation_dataset_multi_modal/scenario33"]
path_aug_root=["/efs/data/radar_data_augmentation/Adaptation_dataset_multi_modal/scenario31/",
"/efs/data/radar_data_augmentation/Adaptation_dataset_multi_modal/scenario32/",
"/efs/data/radar_data_augmentation/Adaptation_dataset_multi_modal/scenario33/"]
for path_idx in range(len(path_root)):
path= path_root[path_idx] + "/unit1/radar_data/"
path_aug_ang = path_aug_root[path_idx] + "/radar_data_ang/"
path_aug_vel= path_aug_root[path_idx] + "/radar_data_vel/"
#path_aug_cube= path_aug_root[path_idx] + "/radar_data_cube/"
radarfiles=os.listdir(path)
if not os.path.isdir(path_aug_ang):
os.mkdir(path_aug_ang)
if not os.path.isdir(path_aug_vel):
os.mkdir(path_aug_vel)
#if not os.path.isdir(path_aug_cube):
# os.mkdir(path_aug_cube)
for filename in tqdm(radarfiles):
if ".npy" in filename:
data=np.load(path+filename)
radar_range_ang_data = range_angle_map(data)
radar_range_vel_data = range_velocity_map(data)
##################### Shift disturbance ########################
#range_ang_max=np.amax(radar_range_ang_data)*0.1
#range_vel_max=np.amax(radar_range_vel_data)*0.1
#range_ang_shift=random.uniform(range_ang_max*0.25,range_ang_max)
#range_vel_shift=random.uniform(range_vel_max*0.25,range_vel_max)
#################### Radar range angle augmentation ############
radar_range_ang_data_aug=[]
for x_idx in range(len(radar_range_ang_data)):
row_aug=[]
for y_idx in range(len(radar_range_ang_data[x_idx])):
random_shift=radar_range_ang_data[x_idx][y_idx]*0.1
row_aug.append(radar_range_ang_data[x_idx][y_idx]+random.uniform(random_shift*0.25,random_shift))
#row_aug.append(radar_range_ang_data[x_idx][y_idx]+range_ang_shift)
radar_range_ang_data_aug.append(row_aug)
#################### Radar range velocity augmentation ############
radar_range_vel_data_aug=[]
for x_idx in range(len(radar_range_vel_data)):
row_aug=[]
for y_idx in range(len(radar_range_vel_data[x_idx])):
random_shift=radar_range_vel_data[x_idx][y_idx]*0.1
row_aug.append(radar_range_vel_data[x_idx][y_idx]+random.uniform(random_shift*0.25,random_shift))
#row_aug.append(radar_range_vel_data[x_idx][y_idx]+range_vel_shift)
radar_range_vel_data_aug.append(row_aug)
np.save(path_aug_ang+filename,minmax(np.asarray(radar_range_ang_data_aug)))
np.save(path_aug_vel+filename, minmax(np.asarray(radar_range_vel_data_aug)))
#deb1=minmax(radar_range_ang_data)
#deb2=minmax(np.asarray(radar_range_ang_data_aug))
#deb11=minmax(radar_range_vel_data)
#deb22=minmax(np.asarray(radar_range_vel_data_aug))
#print(deb1[200][120])
#print(deb2[200][120])
#print(deb11[200][120])
#print(deb22[200][120])
#a=1